]> git.alsa-project.org Git - alsa-lib.git/commitdiff
A next try to fix the snd_pcm_wait() behaviour with direct plugins
authorJaroslav Kysela <perex@perex.cz>
Wed, 24 Mar 2004 08:50:01 +0000 (08:50 +0000)
committerJaroslav Kysela <perex@perex.cz>
Wed, 24 Mar 2004 08:50:01 +0000 (08:50 +0000)
src/pcm/pcm.c
src/pcm/pcm_direct.c

index 724a97c2c3c6b7cc482bd1aaf612e5a1c0e70310..ecdac72852a2831c89c5223bb92f40ab7d0e156e 100644 (file)
@@ -2082,20 +2082,10 @@ int snd_pcm_wait(snd_pcm_t *pcm, int timeout)
        }
        err = snd_pcm_poll_descriptors(pcm, &pfd, 1);
        assert(err == 1);
+      __retry:
        err_poll = poll(&pfd, 1, timeout);
        if (err_poll < 0)
                return -errno;
-#if 0 /* very useful code to test poll related problems */
-       {
-               snd_pcm_sframes_t delay, avail_update;
-               snd_pcm_hwsync(pcm);
-               avail_update = snd_pcm_avail_update(pcm);
-               if (avail_update < pcm->avail_min) {
-                       printf("*** snd_pcm_wait() FATAL ERROR!!!\n");
-                       printf("avail_min = %li, avail_update = %li\n", pcm->avail_min, avail_update);
-               }
-       }
-#endif
        err = snd_pcm_poll_descriptors_revents(pcm, &pfd, 1, &revents);
        if (err < 0)
                return err;
@@ -2112,6 +2102,19 @@ int snd_pcm_wait(snd_pcm_t *pcm, int timeout)
                        return -EIO;
                }
        }
+       if ((revents & (POLLIN | POLLOUT)) == 0)
+               goto __retry;
+#if 0 /* very useful code to test poll related problems */
+       {
+               snd_pcm_sframes_t avail_update;
+               snd_pcm_hwsync(pcm);
+               avail_update = snd_pcm_avail_update(pcm);
+               if (avail_update < (snd_pcm_sframes_t)pcm->avail_min) {
+                       printf("*** snd_pcm_wait() FATAL ERROR!!!\n");
+                       printf("avail_min = %li, avail_update = %li\n", pcm->avail_min, avail_update);
+               }
+       }
+#endif
        return err_poll > 0 ? 1 : 0;
 }
 
index a3e40e5fa32d11902c1b05dee2ad1ba94dc11d54..0c7f4f0b4fe6c168ada193b234b3af471eb97a27 100644 (file)
@@ -427,6 +427,7 @@ int snd_pcm_direct_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds, unsigned in
        events = pfds[0].revents;
        if (events & POLLIN) {
                int empty = 0;
+               snd_pcm_avail_update(pcm);
                if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
                        events |= POLLOUT;
                        events &= ~POLLIN;
@@ -436,6 +437,8 @@ int snd_pcm_direct_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds, unsigned in
                }
                /* empty the timer read queue */
                while (empty && snd_timer_read(dmix->timer, &rbuf, sizeof(rbuf)) == sizeof(rbuf)) ;
+               if (empty)
+                       events &= ~(POLLOUT|POLLIN);
        }
        *revents = events;
        return 0;