[vlc-commits] decoder: simplify audio path

Rémi Denis-Courmont git at videolan.org
Sat Mar 21 18:48:23 CET 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Mar 21 19:29:55 2015 +0200| [498f442c35ff4ab95b4ddecd42874f2892fc371c] | committer: Rémi Denis-Courmont

decoder: simplify audio path

DecoderPlayAudio() has no effects with a NULL block.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=498f442c35ff4ab95b4ddecd42874f2892fc371c
---

 src/input/decoder.c |   82 ++++++++++++++++++++++-----------------------------
 1 file changed, 35 insertions(+), 47 deletions(-)

diff --git a/src/input/decoder.c b/src/input/decoder.c
index 65dc511..ce072a3 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -1073,7 +1073,7 @@ static void DecoderPlayAudio( decoder_t *p_dec, block_t *p_audio,
     audio_output_t *p_aout = p_owner->p_aout;
 
     /* */
-    if( p_audio && p_audio->i_pts <= VLC_TS_INVALID ) // FIXME --VLC_TS_INVALID verify audio_output/*
+    if( p_audio->i_pts <= VLC_TS_INVALID ) // FIXME --VLC_TS_INVALID verify audio_output/*
     {
         msg_Warn( p_dec, "non-dated audio buffer received" );
         *pi_lost_sum += 1;
@@ -1083,58 +1083,47 @@ static void DecoderPlayAudio( decoder_t *p_dec, block_t *p_audio,
 
     /* */
     vlc_mutex_lock( &p_owner->lock );
-
-    if( p_audio && p_owner->b_waiting )
+race:
+    if( p_owner->b_waiting )
     {
         p_owner->b_has_data = true;
         vlc_cond_signal( &p_owner->wait_acknowledge );
     }
 
-    for( ;; )
-    {
-        bool b_paused;
-
-        bool b_reject = DecoderWaitUnblock( p_dec );
-
-        b_paused = p_owner->b_paused;
-
-        if (!p_audio)
-            break;
-
-        /* */
-        int i_rate = INPUT_RATE_DEFAULT;
+    bool b_reject = DecoderWaitUnblock( p_dec );
+    bool b_paused = p_owner->b_paused;
 
-        DecoderFixTs( p_dec, &p_audio->i_pts, NULL, &p_audio->i_length,
-                      &i_rate, AOUT_MAX_ADVANCE_TIME );
+    /* */
+    int i_rate = INPUT_RATE_DEFAULT;
 
-        if( p_audio->i_pts <= VLC_TS_INVALID
-         || i_rate < INPUT_RATE_DEFAULT/AOUT_MAX_INPUT_RATE
-         || i_rate > INPUT_RATE_DEFAULT*AOUT_MAX_INPUT_RATE )
-            b_reject = true;
+    DecoderFixTs( p_dec, &p_audio->i_pts, NULL, &p_audio->i_length,
+                  &i_rate, AOUT_MAX_ADVANCE_TIME );
 
-        DecoderWaitDate( p_dec, &b_reject,
-                         p_audio->i_pts - AOUT_MAX_PREPARE_TIME );
+    if( p_audio->i_pts <= VLC_TS_INVALID
+     || i_rate < INPUT_RATE_DEFAULT/AOUT_MAX_INPUT_RATE
+     || i_rate > INPUT_RATE_DEFAULT*AOUT_MAX_INPUT_RATE )
+        b_reject = true;
 
-        if( unlikely(p_owner->b_paused != b_paused) )
-            continue; /* race with input thread? retry... */
-        if( p_aout == NULL )
-            b_reject = true;
+    DecoderWaitDate( p_dec, &b_reject,
+                     p_audio->i_pts - AOUT_MAX_PREPARE_TIME );
 
-        if( !b_reject )
-        {
-            assert( !p_owner->b_paused );
-            if( !aout_DecPlay( p_aout, p_audio, i_rate ) )
-                *pi_played_sum += 1;
-            *pi_lost_sum += aout_DecGetResetLost( p_aout );
-        }
-        else
-        {
-            msg_Dbg( p_dec, "discarded audio buffer" );
-            *pi_lost_sum += 1;
-            block_Release( p_audio );
-        }
+    if( unlikely(p_owner->b_paused != b_paused) )
+        goto race; /* race with input thread? retry... */
+    if( p_aout == NULL )
+        b_reject = true;
 
-        break;
+    if( !b_reject )
+    {
+        assert( !p_owner->b_paused );
+        if( !aout_DecPlay( p_aout, p_audio, i_rate ) )
+            *pi_played_sum += 1;
+        *pi_lost_sum += aout_DecGetResetLost( p_aout );
+    }
+    else
+    {
+        msg_Dbg( p_dec, "discarded audio buffer" );
+        *pi_lost_sum += 1;
+        block_Release( p_audio );
     }
     vlc_mutex_unlock( &p_owner->lock );
 }
@@ -1147,11 +1136,10 @@ static void DecoderDecodeAudio( decoder_t *p_dec, block_t *p_block )
     int i_lost = 0;
     int i_played = 0;
 
-    if (!p_block) {
-        /* Play a NULL block to output buffered frames */
-        DecoderPlayAudio( p_dec, NULL, &i_played, &i_lost );
-    }
-    else while( (p_aout_buf = p_dec->pf_decode_audio( p_dec, &p_block )) )
+    if( p_block == NULL )
+        return; /* TODO: remove this check, drain audio decoders properly */
+
+    while( (p_aout_buf = p_dec->pf_decode_audio( p_dec, &p_block )) )
     {
         if( DecoderIsFlushing( p_dec ) )
         {



More information about the vlc-commits mailing list