[vlc-devel] [PATCH 6/6] input: rename members and functions previously related to decoder buffering.

Felix Abecassis felix.abecassis at gmail.com
Wed Dec 11 11:46:14 CET 2013


Even without data buffering, it is still necessary to wait until each decoder has processed one block before updating the system clock.
---
 src/input/decoder.c | 101 ++++++++++++++++++++++++----------------------------
 src/input/decoder.h |  12 +++----
 src/input/es_out.c  |  20 +++++------
 3 files changed, 62 insertions(+), 71 deletions(-)

diff --git a/src/input/decoder.c b/src/input/decoder.c
index 56ce9e2..57ad129 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -62,7 +62,7 @@ static void      *DecoderThread( void * );
 static void       DecoderProcess( decoder_t *, block_t * );
 static void       DecoderOutputChangePause( decoder_t *, bool b_paused, mtime_t i_date );
 static void       DecoderFlush( decoder_t * );
-static void       DecoderSignalBuffering( decoder_t *, bool );
+static void       DecoderSignalWait( decoder_t *, bool );
 
 static void       DecoderUnsupportedCodec( decoder_t *, vlc_fourcc_t );
 
@@ -131,14 +131,10 @@ struct decoder_owner_sys_t
         int     i_ignore;
     } pause;
 
-    /* Buffering */
-    bool b_buffering;
-    struct
-    {
-        bool b_first;
-        bool b_full;
-        int  i_count;
-    } buffer;
+    /* Waiting */
+    bool b_waiting;
+    bool b_first;
+    bool b_has_data;
 
     /* Flushing */
     bool b_flushing;
@@ -335,11 +331,11 @@ void input_DecoderDelete( decoder_t *p_dec )
 
     vlc_cancel( p_owner->thread );
 
-    /* Make sure we aren't paused/buffering/waiting/decoding anymore */
+    /* Make sure we aren't paused/waiting/decoding anymore */
     vlc_mutex_lock( &p_owner->lock );
     const bool b_was_paused = p_owner->b_paused;
     p_owner->b_paused = false;
-    p_owner->b_buffering = false;
+    p_owner->b_waiting = false;
     p_owner->b_flushing = true;
     p_owner->b_exit = true;
     vlc_cond_signal( &p_owner->wait_request );
@@ -375,11 +371,11 @@ void input_DecoderDecode( decoder_t *p_dec, block_t *p_block, bool b_do_pace )
 
     if( b_do_pace )
     {
-        /* The fifo is not consummed when buffering and so will
+        /* The fifo is not consumed when waiting and so will
          * deadlock vlc.
-         * There is no need to lock as b_buffering is never modify
+         * There is no need to lock as b_waiting is never modified
          * inside decoder thread. */
-        if( !p_owner->b_buffering )
+        if( !p_owner->b_waiting )
             block_FifoPace( p_owner->p_fifo, 10, SIZE_MAX );
     }
 #ifdef __arm__
@@ -401,11 +397,9 @@ void input_DecoderDecode( decoder_t *p_dec, block_t *p_block, bool b_do_pace )
 bool input_DecoderIsEmpty( decoder_t * p_dec )
 {
     decoder_owner_sys_t *p_owner = p_dec->p_owner;
-    assert( !p_owner->b_buffering );
+    assert( !p_owner->b_waiting );
 
     bool b_empty = block_FifoCount( p_dec->p_owner->p_fifo ) <= 0;
-    if (p_owner->buffer.i_count) /* buffered frames */
-        b_empty = false;
 
     if( b_empty )
     {
@@ -528,7 +522,7 @@ void input_DecoderChangeDelay( decoder_t *p_dec, mtime_t i_delay )
     vlc_mutex_unlock( &p_owner->lock );
 }
 
-void input_DecoderStartBuffering( decoder_t *p_dec )
+void input_DecoderStartWait( decoder_t *p_dec )
 {
     decoder_owner_sys_t *p_owner = p_dec->p_owner;
 
@@ -536,37 +530,36 @@ void input_DecoderStartBuffering( decoder_t *p_dec )
 
     DecoderFlush( p_dec );
 
-    p_owner->buffer.b_first = true;
-    p_owner->buffer.b_full = false;
-    p_owner->buffer.i_count = 0;
+    p_owner->b_first = true;
+    p_owner->b_has_data = false;
 
-    p_owner->b_buffering = true;
+    p_owner->b_waiting = true;
 
     vlc_cond_signal( &p_owner->wait_request );
 
     vlc_mutex_unlock( &p_owner->lock );
 }
 
-void input_DecoderStopBuffering( decoder_t *p_dec )
+void input_DecoderStopWait( decoder_t *p_dec )
 {
     decoder_owner_sys_t *p_owner = p_dec->p_owner;
 
     vlc_mutex_lock( &p_owner->lock );
 
-    p_owner->b_buffering = false;
+    p_owner->b_waiting = false;
 
     vlc_cond_signal( &p_owner->wait_request );
 
     vlc_mutex_unlock( &p_owner->lock );
 }
 
-void input_DecoderWaitBuffering( decoder_t *p_dec )
+void input_DecoderWait( decoder_t *p_dec )
 {
     decoder_owner_sys_t *p_owner = p_dec->p_owner;
 
     vlc_mutex_lock( &p_owner->lock );
 
-    while( p_owner->b_buffering && !p_owner->buffer.b_full )
+    while( p_owner->b_waiting && !p_owner->b_has_data )
     {
         block_FifoWake( p_owner->p_fifo );
         vlc_cond_wait( &p_owner->wait_acknowledge, &p_owner->lock );
@@ -666,7 +659,7 @@ static mtime_t DecoderGetDisplayDate( decoder_t *p_dec, mtime_t i_ts )
     decoder_owner_sys_t *p_owner = p_dec->p_owner;
 
     vlc_mutex_lock( &p_owner->lock );
-    if( p_owner->b_buffering || p_owner->b_paused )
+    if( p_owner->b_waiting || p_owner->b_paused )
         i_ts = VLC_TS_INVALID;
     vlc_mutex_unlock( &p_owner->lock );
 
@@ -845,10 +838,9 @@ static decoder_t * CreateDecoder( vlc_object_t *p_parent,
     p_owner->pause.i_date = VLC_TS_INVALID;
     p_owner->pause.i_ignore = 0;
 
-    p_owner->b_buffering = false;
-    p_owner->buffer.b_first = true;
-    p_owner->buffer.b_full = false;
-    p_owner->buffer.i_count = 0;
+    p_owner->b_waiting = false;
+    p_owner->b_first = true;
+    p_owner->b_has_data = false;
 
     p_owner->b_flushing = false;
 
@@ -888,10 +880,10 @@ static void *DecoderThread( void *p_data )
 
         /* Make sure there is no cancellation point other than this one^^.
          * If you need one, be sure to push cleanup of p_block. */
-        bool end_buffering = !p_block || p_block->i_flags & BLOCK_FLAG_CORE_EOS;
-        DecoderSignalBuffering( p_dec, end_buffering );
-        if (end_buffering)
-            input_DecoderStopBuffering( p_dec );
+        bool end_wait = !p_block || p_block->i_flags & BLOCK_FLAG_CORE_EOS;
+        DecoderSignalWait( p_dec, end_wait );
+        if (end_wait)
+            input_DecoderStopWait( p_dec );
 
         if( p_block )
         {
@@ -951,16 +943,16 @@ static void DecoderFlush( decoder_t *p_dec )
         vlc_cond_wait( &p_owner->wait_acknowledge, &p_owner->lock );
 }
 
-static void DecoderSignalBuffering( decoder_t *p_dec, bool b_full )
+static void DecoderSignalWait( decoder_t *p_dec, bool b_has_data )
 {
     decoder_owner_sys_t *p_owner = p_dec->p_owner;
 
     vlc_mutex_lock( &p_owner->lock );
 
-    if( p_owner->b_buffering )
+    if( p_owner->b_waiting )
     {
-        if( b_full )
-            p_owner->buffer.b_full = true;
+        if( b_has_data )
+            p_owner->b_has_data = true;
         vlc_cond_signal( &p_owner->wait_acknowledge );
     }
 
@@ -993,7 +985,7 @@ static bool DecoderWaitUnblock( decoder_t *p_dec )
             break;
         if( p_owner->b_paused )
         {
-            if( p_owner->b_buffering && !p_owner->buffer.b_full )
+            if( p_owner->b_waiting && !p_owner->b_has_data )
                 break;
             if( p_owner->pause.i_ignore > 0 )
             {
@@ -1003,7 +995,7 @@ static bool DecoderWaitUnblock( decoder_t *p_dec )
         }
         else
         {
-            if( !p_owner->b_buffering || !p_owner->buffer.b_full )
+            if( !p_owner->b_waiting || !p_owner->b_has_data )
                 break;
         }
         vlc_cond_wait( &p_owner->wait_request, &p_owner->lock );
@@ -1139,9 +1131,9 @@ static void DecoderPlayAudio( decoder_t *p_dec, block_t *p_audio,
     /* */
     vlc_mutex_lock( &p_owner->lock );
 
-    if( p_audio && p_owner->b_buffering )
+    if( p_audio && p_owner->b_waiting )
     {
-        p_owner->buffer.b_full = true;
+        p_owner->b_has_data = true;
         vlc_cond_signal( &p_owner->wait_acknowledge );
     }
 
@@ -1310,21 +1302,20 @@ static void DecoderPlayVideo( decoder_t *p_dec, picture_t *p_picture,
     /* */
     vlc_mutex_lock( &p_owner->lock );
 
-    if( p_owner->b_buffering && !p_owner->buffer.b_first )
+    if( p_owner->b_waiting && !p_owner->b_first )
     {
-        p_owner->buffer.b_full = true;
+        p_owner->b_has_data = true;
         vlc_cond_signal( &p_owner->wait_acknowledge );
     }
-    bool b_first_after_wait = p_owner->b_buffering && p_owner->buffer.b_full;
+    bool b_first_after_wait = p_owner->b_waiting && p_owner->b_has_data;
 
     bool b_reject = DecoderWaitUnblock( p_dec );
 
-    if( p_owner->b_buffering )
+    if( p_owner->b_waiting )
     {
-        assert( p_owner->buffer.b_first );
-        assert( !p_owner->buffer.i_count );
+        assert( p_owner->b_first );
         msg_Dbg( p_dec, "Received first picture" );
-        p_owner->buffer.b_first = false;
+        p_owner->b_first = false;
         p_picture->b_force = true;
     }
 
@@ -1441,9 +1432,9 @@ static void DecoderPlaySpu( decoder_t *p_dec, subpicture_t *p_subpic )
     /* */
     vlc_mutex_lock( &p_owner->lock );
 
-    if( p_owner->b_buffering )
+    if( p_owner->b_waiting )
     {
-        p_owner->buffer.b_full = true;
+        p_owner->b_has_data = true;
         vlc_cond_signal( &p_owner->wait_acknowledge );
     }
 
@@ -1475,9 +1466,9 @@ static void DecoderPlaySout( decoder_t *p_dec, block_t *p_sout_block )
 
     vlc_mutex_lock( &p_owner->lock );
 
-    if( p_owner->b_buffering )
+    if( p_owner->b_waiting )
     {
-        p_owner->buffer.b_full = true;
+        p_owner->b_has_data = true;
         vlc_cond_signal( &p_owner->wait_acknowledge );
     }
 
@@ -2148,7 +2139,7 @@ static picture_t *vout_new_buffer( decoder_t *p_dec )
             return NULL;
 
         /* */
-        DecoderSignalBuffering( p_dec, true );
+        DecoderSignalWait( p_dec, true );
 
         /* Check the decoder doesn't leak pictures */
         vout_FixLeaks( p_owner->p_vout );
diff --git a/src/input/decoder.h b/src/input/decoder.h
index 1c9e1b6..bc3499b 100644
--- a/src/input/decoder.h
+++ b/src/input/decoder.h
@@ -47,19 +47,19 @@ void input_DecoderChangePause( decoder_t *, bool b_paused, mtime_t i_date );
 void input_DecoderChangeDelay( decoder_t *, mtime_t i_delay );
 
 /**
- * This function starts the buffering mode.
+ * This function makes the decoder start waiting for a valid data block from its fifo.
  */
-void input_DecoderStartBuffering( decoder_t * );
+void input_DecoderStartWait( decoder_t * );
 
 /**
- * This function waits for the decoder to have buffered sufficient data.
+ * This function waits for the decoder to actually receive data.
  */
-void input_DecoderWaitBuffering( decoder_t * );
+void input_DecoderWait( decoder_t * );
 
 /**
- * This function stops the buffering mode.
+ * This function exits the waiting mode of the decoder.
  */
-void input_DecoderStopBuffering( decoder_t * );
+void input_DecoderStopWait( decoder_t * );
 
 /**
  * This function returns true if the decoder fifo is empty and false otherwise.
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 97e6b65..7ec2ecb 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -491,7 +491,7 @@ static int EsOutSetRecord(  es_out_t *out, bool b_record )
 
             p_es->p_dec_record = input_DecoderNew( p_input, &p_es->fmt, p_es->p_pgrm->p_clock, p_sys->p_sout_record );
             if( p_es->p_dec_record && p_sys->b_buffering )
-                input_DecoderStartBuffering( p_es->p_dec_record );
+                input_DecoderStartWait( p_es->p_dec_record );
         }
     }
     else
@@ -576,10 +576,10 @@ static void EsOutChangePosition( es_out_t *out )
         if( !p_es->p_dec )
             continue;
 
-        input_DecoderStartBuffering( p_es->p_dec );
+        input_DecoderStartWait( p_es->p_dec );
 
         if( p_es->p_dec_record )
-            input_DecoderStartBuffering( p_es->p_dec_record );
+            input_DecoderStartWait( p_es->p_dec_record );
     }
 
     for( int i = 0; i < p_sys->i_pgrm; i++ )
@@ -646,12 +646,12 @@ static void EsOutDecodersStopBuffering( es_out_t *out, bool b_forced )
 
         if( !p_es->p_dec || p_es->fmt.i_cat == SPU_ES )
             continue;
-        input_DecoderWaitBuffering( p_es->p_dec );
+        input_DecoderWait( p_es->p_dec );
         if( p_es->p_dec_record )
-            input_DecoderWaitBuffering( p_es->p_dec_record );
+            input_DecoderWait( p_es->p_dec_record );
     }
 
-    msg_Dbg( p_sys->p_input, "Decoder buffering done in %d ms",
+    msg_Dbg( p_sys->p_input, "Decoder wait done in %d ms",
               (int)(mdate() - i_decoder_buffering_start)/1000 );
 
     /* Here is a good place to destroy unused vout with every demuxer */
@@ -671,9 +671,9 @@ static void EsOutDecodersStopBuffering( es_out_t *out, bool b_forced )
         if( !p_es->p_dec )
             continue;
 
-        input_DecoderStopBuffering( p_es->p_dec );
+        input_DecoderStopWait( p_es->p_dec );
         if( p_es->p_dec_record )
-            input_DecoderStopBuffering( p_es->p_dec_record );
+            input_DecoderStopWait( p_es->p_dec_record );
     }
 }
 static void EsOutDecodersChangePause( es_out_t *out, bool b_paused, mtime_t i_date )
@@ -1558,13 +1558,13 @@ static void EsCreateDecoder( es_out_t *out, es_out_id_t *p_es )
     if( p_es->p_dec )
     {
         if( p_sys->b_buffering )
-            input_DecoderStartBuffering( p_es->p_dec );
+            input_DecoderStartWait( p_es->p_dec );
 
         if( !p_es->p_master && p_sys->p_sout_record )
         {
             p_es->p_dec_record = input_DecoderNew( p_input, &p_es->fmt, p_es->p_pgrm->p_clock, p_sys->p_sout_record );
             if( p_es->p_dec_record && p_sys->b_buffering )
-                input_DecoderStartBuffering( p_es->p_dec_record );
+                input_DecoderStartWait( p_es->p_dec_record );
         }
     }
 
-- 
1.8.3.2




More information about the vlc-devel mailing list