]> git.sesse.net Git - vlc/commitdiff
Drain audio output before we claim the buffers are empty
authorRémi Denis-Courmont <remi@remlab.net>
Thu, 13 Oct 2011 15:41:01 +0000 (18:41 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Sat, 15 Oct 2011 08:25:54 +0000 (11:25 +0300)
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

index 4a47ed1b19dd9ef57a5edc601a20468f98774460..85b0c15b9cfd99b5d7011bef67dd815e502aed94 100644 (file)
@@ -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;
 }
 
 /**