[vlc-devel] [PATCH 03/12] decoder: sent state to a listener

Thomas Guillem thomas at gllm.fr
Thu Jun 9 11:51:55 CEST 2016


---
 src/input/decoder.c | 35 ++++++++++++++++++++++++++++-------
 src/input/decoder.h |  5 ++++-
 src/input/es_out.c  |  9 ++++++---
 3 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/src/input/decoder.c b/src/input/decoder.c
index 3509643..1d5e184 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -68,6 +68,10 @@ struct decoder_owner_sys_t
     sout_instance_t         *p_sout;
     sout_packetizer_input_t *p_sout_input;
 
+    decoder_state_cb         pf_on_state;
+    void                    *p_state_ctx;
+    int                      i_last_state;
+
     vlc_thread_t     thread;
 
     /* Some decoders require already packetized data (ie. not truncated) */
@@ -1506,6 +1510,16 @@ static void *DecoderThread( void *p_data )
          * sufficient. TODO? Wait for draining instead of polling. */
         atomic_store( &p_owner->drained, (p_block == NULL) );
 
+        if( p_owner->pf_on_state != NULL )
+        {
+            int i_state = atomic_load( &p_dec->state );
+            if( i_state != p_owner->i_last_state )
+            {
+                p_owner->pf_on_state( p_dec, p_owner->p_state_ctx, i_state );
+                p_owner->i_last_state = i_state;
+            }
+        }
+
         vlc_mutex_lock( &p_owner->lock );
         vlc_fifo_Lock( p_owner->p_fifo );
         vlc_cond_signal( &p_owner->wait_acknowledge );
@@ -1527,7 +1541,8 @@ static decoder_t * CreateDecoder( vlc_object_t *p_parent,
                                   input_thread_t *p_input,
                                   const es_format_t *fmt,
                                   input_resource_t *p_resource,
-                                  sout_instance_t *p_sout )
+                                  sout_instance_t *p_sout,
+                                  decoder_state_cb pf_on_state, void *p_state_ctx )
 {
     decoder_t *p_dec;
     decoder_owner_sys_t *p_owner;
@@ -1555,6 +1570,8 @@ static decoder_t * CreateDecoder( vlc_object_t *p_parent,
     p_owner->p_sout = p_sout;
     p_owner->p_sout_input = NULL;
     p_owner->p_packetizer = NULL;
+    p_owner->pf_on_state = pf_on_state;
+    p_owner->p_state_ctx = p_state_ctx;
 
     p_owner->b_fmt_description = false;
     p_owner->p_description = NULL;
@@ -1769,14 +1786,16 @@ static void DecoderUnsupportedCodec( decoder_t *p_dec, const es_format_t *fmt )
 static decoder_t *decoder_New( vlc_object_t *p_parent, input_thread_t *p_input,
                                const es_format_t *fmt, input_clock_t *p_clock,
                                input_resource_t *p_resource,
-                               sout_instance_t *p_sout  )
+                               sout_instance_t *p_sout,
+                               decoder_state_cb pf_on_state, void *p_state_ctx )
 {
     decoder_t *p_dec = NULL;
     const char *psz_type = p_sout ? N_("packetizer") : N_("decoder");
     int i_priority;
 
     /* Create the decoder configuration structure */
-    p_dec = CreateDecoder( p_parent, p_input, fmt, p_resource, p_sout );
+    p_dec = CreateDecoder( p_parent, p_input, fmt, p_resource, p_sout,
+                           pf_on_state, p_state_ctx );
     if( p_dec == NULL )
     {
         msg_Err( p_parent, "could not create %s", psz_type );
@@ -1822,10 +1841,11 @@ static decoder_t *decoder_New( vlc_object_t *p_parent, input_thread_t *p_input,
  */
 decoder_t *input_DecoderNew( input_thread_t *p_input,
                              es_format_t *fmt, input_clock_t *p_clock,
-                             sout_instance_t *p_sout  )
+                             sout_instance_t *p_sout,
+                             decoder_state_cb pf_on_state, void *p_state_ctx )
 {
     return decoder_New( VLC_OBJECT(p_input), p_input, fmt, p_clock,
-                        p_input->p->p_resource, p_sout );
+                        p_input->p->p_resource, p_sout, pf_on_state, p_state_ctx );
 }
 
 /**
@@ -1834,7 +1854,7 @@ decoder_t *input_DecoderNew( input_thread_t *p_input,
 decoder_t *input_DecoderCreate( vlc_object_t *p_parent, const es_format_t *fmt,
                                 input_resource_t *p_resource )
 {
-    return decoder_New( p_parent, NULL, fmt, NULL, p_resource, NULL );
+    return decoder_New( p_parent, NULL, fmt, NULL, p_resource, NULL, NULL, NULL );
 }
 
 
@@ -2034,7 +2054,8 @@ int input_DecoderSetCcState( decoder_t *p_dec, bool b_decode, int i_channel )
 
         es_format_Init( &fmt, SPU_ES, fcc[i_channel] );
         p_cc = input_DecoderNew( p_owner->p_input, &fmt,
-                              p_dec->p_owner->p_clock, p_owner->p_sout );
+                                 p_dec->p_owner->p_clock, p_owner->p_sout,
+                                 NULL, NULL );
         if( !p_cc )
         {
             msg_Err( p_dec, "could not create decoder" );
diff --git a/src/input/decoder.h b/src/input/decoder.h
index 226ecde..3e51b99 100644
--- a/src/input/decoder.h
+++ b/src/input/decoder.h
@@ -28,8 +28,11 @@
 #include <vlc_common.h>
 #include <vlc_codec.h>
 
+typedef void (*decoder_state_cb)( decoder_t *, void *p_state_ctx, int i_state );
+
 decoder_t *input_DecoderNew( input_thread_t *, es_format_t *, input_clock_t *,
-                             sout_instance_t * ) VLC_USED;
+                             sout_instance_t *, decoder_state_cb pf_on_state,
+                             void *p_state_ctx ) VLC_USED;
 
 /**
  * This function changes the pause state.
diff --git a/src/input/es_out.c b/src/input/es_out.c
index bd01c3e..a45189a 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -493,7 +493,8 @@ static int EsOutSetRecord(  es_out_t *out, bool b_record )
             if( !p_es->p_dec || p_es->p_master )
                 continue;
 
-            p_es->p_dec_record = input_DecoderNew( p_input, &p_es->fmt, p_es->p_pgrm->p_clock, 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, NULL, NULL );
             if( p_es->p_dec_record && p_sys->b_buffering )
                 input_DecoderStartWait( p_es->p_dec_record );
         }
@@ -1566,7 +1567,8 @@ static void EsCreateDecoder( es_out_t *out, es_out_id_t *p_es )
     es_out_sys_t   *p_sys = out->p_sys;
     input_thread_t *p_input = p_sys->p_input;
 
-    p_es->p_dec = input_DecoderNew( p_input, &p_es->fmt, p_es->p_pgrm->p_clock, p_input->p->p_sout );
+    p_es->p_dec = input_DecoderNew( p_input, &p_es->fmt, p_es->p_pgrm->p_clock,
+                                    p_input->p->p_sout, NULL, NULL );
     if( p_es->p_dec )
     {
         if( p_sys->b_buffering )
@@ -1574,7 +1576,8 @@ static void EsCreateDecoder( es_out_t *out, es_out_id_t *p_es )
 
         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 );
+            p_es->p_dec_record = input_DecoderNew( p_input, &p_es->fmt, p_es->p_pgrm->p_clock,
+                                                   p_sys->p_sout_record, NULL, NULL );
             if( p_es->p_dec_record && p_sys->b_buffering )
                 input_DecoderStartWait( p_es->p_dec_record );
         }
-- 
2.8.1



More information about the vlc-devel mailing list