[vlc-devel] [RFC PATCH 4/8] decoder: notify the input_thread in case of error

Thomas Guillem thomas at gllm.fr
Thu Apr 21 18:24:34 CEST 2016


---
 src/input/decoder.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/src/input/decoder.c b/src/input/decoder.c
index 28f53f8..32d656d 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -69,6 +69,7 @@ struct decoder_owner_sys_t
     sout_packetizer_input_t *p_sout_input;
 
     bool                     b_notify_input;
+    enum decoder_state       current_state; /* protected with lock */
 
     vlc_thread_t     thread;
 
@@ -137,6 +138,36 @@ struct decoder_owner_sys_t
 /* */
 #define DECODER_SPU_VOUT_WAIT_DURATION ((int)(0.200*CLOCK_FREQ))
 
+static void UpdateStatus( decoder_t *p_dec, enum decoder_state new_state )
+{
+    decoder_owner_sys_t *p_owner = p_dec->p_owner;
+    if( p_owner->current_state != new_state )
+    {
+        /* Don't override the first error set */
+        if( new_state >= DECODER_ERROR_GENERIC
+         && p_owner->current_state >= DECODER_ERROR_GENERIC )
+            return;
+
+        p_owner->current_state = new_state;
+
+        if( !p_owner->b_notify_input )
+            return;
+
+        struct decoder_state_control *p_ctrl = malloc( sizeof(*p_ctrl) );
+        if( p_ctrl != NULL )
+        {
+            vlc_value_t val;
+            p_ctrl->i_es_id = p_owner->i_es_id;
+            p_ctrl->i_cat = p_dec->fmt_in.i_cat;
+            p_ctrl->psz_module_name = module_get_name( p_dec->p_module, false );
+            p_ctrl->state = p_owner->current_state;
+            val.p_address = p_ctrl;
+            input_ControlPush( p_owner->p_input,
+                               INPUT_CONTROL_DECODER_STATE, &val );
+        }
+    }
+}
+
 /**
  * Load a decoder module
  */
@@ -296,6 +327,8 @@ static int aout_update_format( decoder_t *p_dec )
 
         DecoderUpdateFormatLocked( p_dec );
         aout_FormatPrepare( &p_owner->fmt.audio );
+        if( p_aout == NULL )
+            UpdateStatus( p_dec, DECODER_ERROR_OUTPUT );
         vlc_mutex_unlock( &p_owner->lock );
 
         if( p_owner->b_notify_input )
@@ -432,6 +465,8 @@ static int vout_update_format( decoder_t *p_dec )
 
         DecoderUpdateFormatLocked( p_dec );
         p_owner->fmt.video.i_chroma = p_dec->fmt_out.i_codec;
+        if( p_vout == NULL )
+            UpdateStatus( p_dec, DECODER_ERROR_OUTPUT );
         vlc_mutex_unlock( &p_owner->lock );
 
         if( p_owner->b_notify_input )
@@ -1363,6 +1398,14 @@ static void DecoderProcess( decoder_t *p_dec, block_t *p_block )
             p_dec->b_error = true;
         }
     }
+
+    /* Update the status if an error is set while processing */
+    if( p_dec->b_error )
+    {
+        vlc_mutex_lock( &p_owner->lock );
+        UpdateStatus( p_dec, DECODER_ERROR_GENERIC );
+        vlc_mutex_unlock( &p_owner->lock );
+    }
 }
 
 static void DecoderProcessFlush( decoder_t *p_dec )
@@ -1567,6 +1610,7 @@ static decoder_t * CreateDecoder( vlc_object_t *p_parent,
     p_owner->p_packetizer = NULL;
     p_owner->b_notify_input = b_notify_input && p_input != NULL;
     p_owner->i_es_id = fmt->i_id;
+    p_owner->current_state = DECODER_INIT;
 
     p_owner->b_fmt_description = false;
     p_owner->p_description = NULL;
-- 
2.8.0.rc3



More information about the vlc-devel mailing list