]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Fixed poll() behaviour for direct plugins, also added snd_pcm_hwsync() call to start...
authorJaroslav Kysela <perex@perex.cz>
Wed, 21 Jan 2004 19:21:11 +0000 (19:21 +0000)
committerJaroslav Kysela <perex@perex.cz>
Wed, 21 Jan 2004 19:21:11 +0000 (19:21 +0000)
src/pcm/pcm_direct.c
src/pcm/pcm_dmix.c
src/pcm/pcm_dshare.c
src/pcm/pcm_dsnoop.c

index 6f8ef6861eea30a1d7478f103e5c4937fcdfbca7..82b9cbfe966ba28eab33a75dc3cdb3ecf66c98b8 100644 (file)
@@ -410,15 +410,23 @@ int snd_pcm_direct_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds, unsigned in
 {
        snd_pcm_direct_t *dmix = pcm->private_data;
        unsigned short events;
-       static snd_timer_read_t rbuf[5];        /* can be overwriten by multiple plugins, we don't need the value */
+       /* rbuf might be overwriten by multiple plugins */
+       /* we don't need the value */
+       static snd_timer_read_t rbuf[5];
 
        assert(pfds && nfds == 1 && revents);
        events = pfds[0].revents;
        if (events & POLLIN) {
-               events |= POLLOUT;
-               events &= ~POLLIN;
+               int empty = 0;
+               if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
+                       events |= POLLOUT;
+                       events &= ~POLLIN;
+                       empty = snd_pcm_mmap_playback_avail(pcm) < pcm->avail_min;
+               } else {
+                       empty = snd_pcm_mmap_capture_avail(pcm) < pcm->avail_min;
+               }
                /* empty the timer read queue */
-               while (snd_timer_read(dmix->timer, &rbuf, sizeof(rbuf)) == sizeof(rbuf)) ;
+               while (empty && snd_timer_read(dmix->timer, &rbuf, sizeof(rbuf)) == sizeof(rbuf)) ;
        }
        *revents = events;
        return 0;
index 4b1c37b75842ae5a4f0451d1d87cb5e152c16b30..fa121f46857b6b03aa879da762f08fb7d57c8a16 100644 (file)
@@ -407,7 +407,6 @@ static int snd_pcm_dmix_sync_ptr(snd_pcm_t *pcm)
        }
        dmix->hw_ptr += diff;
        dmix->hw_ptr %= pcm->boundary;
-       // printf("sync ptr diff = %li\n", diff);
        if (pcm->stop_threshold >= pcm->boundary)       /* don't care */
                return 0;
        if ((avail = snd_pcm_mmap_playback_avail(pcm)) >= pcm->stop_threshold) {
@@ -545,6 +544,7 @@ static int snd_pcm_dmix_start(snd_pcm_t *pcm)
        if (err < 0)
                return err;
        dmix->state = SND_PCM_STATE_RUNNING;
+       snd_pcm_hwsync(dmix->spcm);
        dmix->slave_appl_ptr = dmix->slave_hw_ptr = *dmix->spcm->hw.ptr;
        avail = snd_pcm_mmap_playback_hw_avail(pcm);
        if (avail < 0)
index a7f5d22278f40880a5b56ce2bd989314784e0bbe..cf1293f54a54fa4ede1a92f04c30fc9fac3b18d2 100644 (file)
@@ -292,6 +292,7 @@ static int snd_pcm_dshare_start(snd_pcm_t *pcm)
        if (err < 0)
                return err;
        dshare->state = SND_PCM_STATE_RUNNING;
+       snd_pcm_hwsync(dshare->spcm);
        dshare->slave_appl_ptr = dshare->slave_hw_ptr = *dshare->spcm->hw.ptr;
        avail = snd_pcm_mmap_playback_hw_avail(pcm);
        if (avail < 0)
index a8d29d93ec012d4f8d24dc5320cc81b6ea4593cd..7bc036e16f2d74646ac6d8fd3715867b17d12c7a 100644 (file)
@@ -274,6 +274,7 @@ static int snd_pcm_dsnoop_start(snd_pcm_t *pcm)
        if (err < 0)
                return err;
        dsnoop->state = SND_PCM_STATE_RUNNING;
+       snd_pcm_hwsync(dsnoop->spcm);
        dsnoop->slave_appl_ptr = dsnoop->slave_hw_ptr = *dsnoop->spcm->hw.ptr;
        gettimeofday(&tv, 0);
        dsnoop->trigger_tstamp.tv_sec = tv.tv_sec;