[vlc-devel] [PATCH] Drain audio output before we claim the buffers are empty

Rémi Denis-Courmont remi at remlab.net
Thu Oct 13 17:43:02 CEST 2011


This fixes the last bits of audio loss at end of stream... for the
audio output implementing drain (ALSA and PulseAudio so far).
---
 src/audio_output/dec.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/audio_output/dec.c b/src/audio_output/dec.c
index 4a47ed1..85b0c15 100644
--- a/src/audio_output/dec.c
+++ b/src/audio_output/dec.c
@@ -367,13 +367,19 @@ void aout_DecFlush (audio_output_t *aout)
 bool aout_DecIsEmpty (audio_output_t *aout)
 {
     aout_owner_t *owner = aout_owner (aout);
-    mtime_t end_date;
+    mtime_t end_date, now = mdate ();
+    bool empty;
 
     aout_lock (aout);
-    /* FIXME: tell output to drain */
     end_date = date_Get (&owner->sync.date);
+    empty = end_date == VLC_TS_INVALID || end_date <= now;
+    if (empty)
+        /* The last PTS has elapsed already. So the underlying audio output
+         * buffer should be empty or almost. Thus draining should be fast
+         * and will not block the caller too long. */
+        aout_OutputFlush (aout, true);
     aout_unlock (aout);
-    return end_date == VLC_TS_INVALID || end_date <= mdate();
+    return empty;
 }
 
 /**
-- 
1.7.7




More information about the vlc-devel mailing list