alsa: Replace check for pending frames on eof by a barrier.
authorAndre Noll <maan@systemlinux.org>
Fri, 15 Jan 2010 19:19:30 +0000 (20:19 +0100)
committerAndre Noll <maan@systemlinux.org>
Fri, 15 Jan 2010 19:19:30 +0000 (20:19 +0100)
The old code could lead to a an endless loop where the alsa writer
would never be unscheduled.

alsa_write.c

index 8bc12a90fa89fc6ec532fe3d61721a6369d8aee1..3c8d063fdd323f304db237c5ad72349f7df33c45 100644 (file)
@@ -54,6 +54,7 @@ struct private_alsa_write_data {
         * decoder of the writer node group.
         */
        unsigned channels;
         * decoder of the writer node group.
         */
        unsigned channels;
+       struct timeval drain_barrier;
 };
 
 /* Install PCM software and hardware configuration. */
 };
 
 /* Install PCM software and hardware configuration. */
@@ -217,7 +218,7 @@ static void alsa_write_post_select(__a_unused struct sched *s,
        struct btr_node *btrn = wn->btrn;
        char *data;
        size_t bytes;
        struct btr_node *btrn = wn->btrn;
        char *data;
        size_t bytes;
-       snd_pcm_sframes_t frames, avail;
+       snd_pcm_sframes_t frames;
        int ret;
 
 again:
        int ret;
 
 again:
@@ -233,10 +234,14 @@ again:
                if (!pad->handle)
                        goto err;
                /* wait until pending frames are played */
                if (!pad->handle)
                        goto err;
                /* wait until pending frames are played */
-               avail = snd_pcm_avail_update(pad->handle);
-               if (avail + 1000 > pad->buffer_frames)
+               if (pad->drain_barrier.tv_sec == 0) {
+                       PARA_DEBUG_LOG("waiting for device to drain\n");
+                       tv_add(now, &(struct timeval)EMBRACE(0, 200 * 1000),
+                               &pad->drain_barrier);
+                       return;
+               }
+               if (tv_diff(now, &pad->drain_barrier, NULL) > 0)
                        goto err;
                        goto err;
-               PARA_DEBUG_LOG("waiting for device to drain\n");
                return;
        }
        if (!pad->handle) {
                return;
        }
        if (!pad->handle) {