[vlc-devel] [PATCH 01/12] decoder: add decoder_OnOutputReady

Thomas Guillem thomas at gllm.fr
Thu Aug 27 14:20:53 CEST 2015


---

This new patch wakes up the decoder thread without messing with the drain
state.

 include/vlc_codec.h |  7 +++++++
 src/input/decoder.c | 26 +++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/include/vlc_codec.h b/include/vlc_codec.h
index 0c43978..cc8deef 100644
--- a/include/vlc_codec.h
+++ b/include/vlc_codec.h
@@ -241,6 +241,13 @@ VLC_API mtime_t decoder_GetDisplayDate( decoder_t *, mtime_t ) VLC_USED;
  */
 VLC_API int decoder_GetDisplayRate( decoder_t * ) VLC_USED;
 
+/**
+ * This function wakes up the DecoderThread that will call pf_decode with a
+ * NULL pp_block. This allow asynchronous decoder modules to queue an output
+ * buffer immediatly from the DecoderThread.
+ */
+VLC_API void decoder_OnOutputReady( decoder_t * );
+
 /** @} */
 /** @} */
 #endif /* _VLC_CODEC_H */
diff --git a/src/input/decoder.c b/src/input/decoder.c
index 25eac79..b0248ba 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -115,6 +115,7 @@ struct decoder_owner_sys_t
     bool b_draining;
     bool b_drained;
     bool b_idle;
+    bool b_output_ready;
 
     /* CC */
     struct
@@ -594,6 +595,19 @@ int decoder_GetDisplayRate( decoder_t *p_dec )
 
     return p_dec->pf_get_display_rate( p_dec );
 }
+/* decoder_OnOutputReady
+ */
+void decoder_OnOutputReady( decoder_t *p_dec )
+{
+    decoder_owner_sys_t *p_owner = p_dec->p_owner;
+
+    vlc_mutex_lock( &p_owner->lock );
+    vlc_fifo_Lock( p_owner->p_fifo );
+    p_owner->b_output_ready = true;
+    vlc_fifo_Signal( p_owner->p_fifo );
+    vlc_fifo_Unlock( p_owner->p_fifo );
+    vlc_mutex_unlock( &p_owner->lock );
+}
 
 static bool DecoderWaitUnblock( decoder_t *p_dec )
 {
@@ -1411,6 +1425,7 @@ static void *DecoderThread( void *p_data )
     for( ;; )
     {
         block_t *p_block;
+        bool b_was_draining = false;
 
         vlc_fifo_Lock( p_owner->p_fifo );
         vlc_cond_signal( &p_owner->wait_acknowledge );
@@ -1424,9 +1439,16 @@ static void *DecoderThread( void *p_data )
             if( p_owner->b_draining )
             {   /* We have emptied the FIFO and there is a pending request to
                  * drain. Pass p_block = NULL to decoder just once. */
+                b_was_draining = true;
                 p_owner->b_draining = false;
                 break;
             }
+            if( p_owner->b_output_ready )
+            {
+                /* There is a pending request from the decoder. Pass p_block =
+                 * NULL to decoder in order to dequeue a new output buffer. */
+                break;
+            }
 
             p_owner->b_idle = true;
             vlc_fifo_Wait( p_owner->p_fifo );
@@ -1435,6 +1457,7 @@ static void *DecoderThread( void *p_data )
             p_owner->b_idle = false;
         }
 
+        p_owner->b_output_ready = false;
         p_block = vlc_fifo_DequeueUnlocked( p_owner->p_fifo );
         vlc_cleanup_pop();
         vlc_fifo_Unlock( p_owner->p_fifo );
@@ -1449,7 +1472,7 @@ static void *DecoderThread( void *p_data )
             if( p_owner->p_aout != NULL )
                 aout_DecFlush( p_owner->p_aout, true );
         }
-        p_owner->b_drained = (p_block == NULL);
+        p_owner->b_drained = b_was_draining;
 
         vlc_restorecancel( canc );
     }
@@ -1530,6 +1553,7 @@ static decoder_t * CreateDecoder( vlc_object_t *p_parent,
     p_owner->b_draining = false;
     p_owner->b_drained = false;
     p_owner->b_idle = false;
+    p_owner->b_output_ready = false;
 
     es_format_Init( &p_owner->fmt, UNKNOWN_ES, 0 );
 
-- 
2.1.4



More information about the vlc-devel mailing list