]> git.alsa-project.org Git - alsa-lib.git/commitdiff
pcm: hw: do not reset tstamp_type in SND_PCM_APPEND mode (#2)
authorJaroslav Kysela <perex@perex.cz>
Tue, 8 Apr 2025 09:18:16 +0000 (11:18 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 8 Apr 2025 09:20:04 +0000 (11:20 +0200)
This is basically redo of all changed and add appropriate conditions
to disable only ioctl calls, but preserve tstamp_type assignments.

Fixes: 15f2b276 ("pcm: hw: fix default timestamp type for O_APPPEND")
Fixes: 7e01443e ("pcm: hw: do not reset tstamp_type in SND_PCM_APPEND mode")
Link: https://github.com/alsa-project/alsa-lib/pull/450
Suggested-by: Signed-off-by: Kevin Groeneveld <kgroeneveld@lenbrook.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
src/pcm/pcm_hw.c

index ab5e45eee4546ad310b284f62e0687c3b846cd1d..833cad027507af20f8b2c5c3c5370a0b90fadc7e 100644 (file)
@@ -1665,36 +1665,30 @@ int snd_pcm_hw_open_fd(snd_pcm_t **pcmp, const char *name, int fd,
                }
        }
 
-       if (!(mode & SND_PCM_APPEND)) {
 #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
-               if (SNDRV_PROTOCOL_VERSION(2, 0, 9) <= ver) {
-                       struct timespec timespec;
-                       if (clock_gettime(CLOCK_MONOTONIC, &timespec) == 0) {
+       if (SNDRV_PROTOCOL_VERSION(2, 0, 9) <= ver) {
+               struct timespec timespec;
+               if (clock_gettime(CLOCK_MONOTONIC, &timespec) == 0) {
+                       if (!(mode & SND_PCM_APPEND)) {
                                int on = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC;
                                if (ioctl(fd, SNDRV_PCM_IOCTL_TTSTAMP, &on) < 0) {
                                        ret = -errno;
                                        SNDMSG("TTSTAMP failed");
                                        return ret;
                                }
-                               tstamp_type = SND_PCM_TSTAMP_TYPE_MONOTONIC;
                        }
-               } else
+                       tstamp_type = SND_PCM_TSTAMP_TYPE_MONOTONIC;
+               }
+       } else
 #endif
-               if (SNDRV_PROTOCOL_VERSION(2, 0, 5) <= ver) {
-                       int on = 1;
-                       if (ioctl(fd, SNDRV_PCM_IOCTL_TSTAMP, &on) < 0) {
-                               ret = -errno;
-                               SNDMSG("TSTAMP failed");
-                               return ret;
-                       }
+         if (SNDRV_PROTOCOL_VERSION(2, 0, 5) <= ver && !(mode & SND_PCM_APPEND)) {
+               int on = 1;
+               if (ioctl(fd, SNDRV_PCM_IOCTL_TSTAMP, &on) < 0) {
+                       ret = -errno;
+                       SNDMSG("TSTAMP failed");
+                       return ret;
                }
        }
-#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
-       else {
-               /* the first stream already sets this */
-               tstamp_type = SND_PCM_TSTAMP_TYPE_MONOTONIC;
-       }
-#endif
        
        hw = calloc(1, sizeof(snd_pcm_hw_t));
        if (!hw) {