From: Andre Noll Date: Fri, 15 Jan 2010 19:19:30 +0000 (+0100) Subject: alsa: Replace check for pending frames on eof by a barrier. X-Git-Tag: v0.4.2~89 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=9366a7ddafa4738db0528050ff9080a5f15a3ad7;p=paraslash.git alsa: Replace check for pending frames on eof by a barrier. The old code could lead to a an endless loop where the alsa writer would never be unscheduled. --- diff --git a/alsa_write.c b/alsa_write.c index 8bc12a90..3c8d063f 100644 --- a/alsa_write.c +++ b/alsa_write.c @@ -54,6 +54,7 @@ struct private_alsa_write_data { * decoder of the writer node group. */ unsigned channels; + struct timeval drain_barrier; }; /* 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; - snd_pcm_sframes_t frames, avail; + snd_pcm_sframes_t frames; int ret; again: @@ -233,10 +234,14 @@ again: 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; - PARA_DEBUG_LOG("waiting for device to drain\n"); return; } if (!pad->handle) {