[vlc-commits] [Git][videolan/vlc][master] 3 commits: es_out: cache the "captions" variable

Thomas Guillem gitlab at videolan.org
Sat Jun 5 13:20:45 UTC 2021



Thomas Guillem pushed to branch master at VideoLAN / VLC


Commits:
1afefbc0 by Thomas Guillem at 2021-06-05T13:04:17+00:00
es_out: cache the "captions" variable

- - - - -
4afa2867 by Thomas Guillem at 2021-06-05T13:04:17+00:00
decoder: merge format and desc functions

In order to merge the usage of the same lock and avoid locking it twice
in a row. This new status struct be used to get the status of sub ES
tracks created by decoder modules.

- - - - -
fcb71821 by Thomas Guillem at 2021-06-05T13:04:17+00:00
decoder: remove atomic usage

Not needed anymore since this variable is always locked by the owner->lock.

- - - - -


3 changed files:

- src/input/decoder.c
- src/input/decoder.h
- src/input/es_out.c


Changes:

=====================================
src/input/decoder.c
=====================================
@@ -89,7 +89,7 @@ struct vlc_input_decoder_t
     vlc_video_context *vctx;
 
     /* */
-    atomic_bool    b_fmt_description;
+    bool           b_fmt_description;
     vlc_meta_t     *p_description;
     atomic_int     reload;
 
@@ -287,8 +287,7 @@ static void DecoderUpdateFormatLocked( vlc_input_decoder_t *p_owner )
         p_dec->p_description = NULL;
     }
 
-    atomic_store_explicit( &p_owner->b_fmt_description, true,
-                           memory_order_release );
+    p_owner->b_fmt_description = true;
 }
 
 static void MouseEvent( const vlc_mouse_t *newmouse, void *user_data )
@@ -1817,7 +1816,7 @@ CreateDecoder( vlc_object_t *p_parent,
     p_owner->p_sout_input = NULL;
     p_owner->p_packetizer = NULL;
 
-    atomic_init( &p_owner->b_fmt_description, false );
+    p_owner->b_fmt_description = false;
     p_owner->p_description = NULL;
 
     p_owner->reset_out_state = false;
@@ -2351,14 +2350,6 @@ void vlc_input_decoder_Flush( vlc_input_decoder_t *p_owner )
     }
 }
 
-void vlc_input_decoder_GetCcDesc( vlc_input_decoder_t *p_owner,
-                                  decoder_cc_desc_t *p_desc )
-{
-    vlc_mutex_lock( &p_owner->lock );
-    *p_desc = p_owner->cc.desc;
-    vlc_mutex_unlock( &p_owner->lock );
-}
-
 static bool vlc_input_decoder_HasCCChanFlag( vlc_input_decoder_t *p_owner,
                                              vlc_fourcc_t codec, int i_channel )
 {
@@ -2541,37 +2532,35 @@ void vlc_input_decoder_FrameNext( vlc_input_decoder_t *p_owner,
     vlc_mutex_unlock( &p_owner->lock );
 }
 
-bool vlc_input_decoder_HasFormatChanged( vlc_input_decoder_t *p_owner,
-                                         es_format_t *p_fmt, vlc_meta_t **pp_meta )
+void vlc_input_decoder_GetStatus( vlc_input_decoder_t *p_owner,
+                                  struct vlc_input_decoder_status *status )
 {
-    if( !atomic_exchange_explicit( &p_owner->b_fmt_description, false,
-                                   memory_order_acquire ) )
-        return false;
-
     vlc_mutex_lock( &p_owner->lock );
 
-    if( p_owner->fmt.i_cat == UNKNOWN_ES )
+    status->format.changed = p_owner->b_fmt_description;
+    p_owner->b_fmt_description = false;
+
+    if( status->format.changed && p_owner->fmt.i_cat == UNKNOWN_ES )
     {
         /* The format changed but the output creation failed */
-        vlc_mutex_unlock( &p_owner->lock );
-        return false;
+        status->format.changed = false;
     }
 
-    if( p_fmt != NULL )
-        es_format_Copy( p_fmt, &p_owner->fmt );
-
-    if( pp_meta )
+    if( status->format.changed )
     {
-        *pp_meta = NULL;
+        es_format_Copy( &status->format.fmt, &p_owner->fmt );
+        status->format.meta = NULL;
+
         if( p_owner->p_description )
         {
-            *pp_meta = vlc_meta_New();
-            if( *pp_meta )
-                vlc_meta_Merge( *pp_meta, p_owner->p_description );
+            status->format.meta  = vlc_meta_New();
+            if( status->format.meta  )
+                vlc_meta_Merge( status->format.meta, p_owner->p_description );
         }
     }
+    status->cc.desc = p_owner->cc.desc;
+
     vlc_mutex_unlock( &p_owner->lock );
-    return true;
 }
 
 size_t vlc_input_decoder_GetFifoSize( vlc_input_decoder_t *p_owner )


=====================================
src/input/decoder.h
=====================================
@@ -119,15 +119,30 @@ void vlc_input_decoder_GetCcDesc( vlc_input_decoder_t *, decoder_cc_desc_t * );
  */
 void vlc_input_decoder_FrameNext( vlc_input_decoder_t *p_dec, vlc_tick_t *pi_duration );
 
+struct vlc_input_decoder_status
+{
+    struct {
+        /* True if the ES format or meta data have changed since the last call.
+         * */
+        bool changed;
+        /* If changed is true, a copy of the current es_format_t, MUST be freed
+         * with es_format_Clean() */
+        es_format_t fmt;
+        /* If changed is true, a copy of the current description, can be NULL,
+         * MUST be freed with vlc_meta_Delete.() */
+        vlc_meta_t *meta;
+    } format;
+
+    struct {
+        decoder_cc_desc_t desc;
+    } cc;
+};
+
 /**
- * This function will return true if the ES format or meta data have changed since
- * the last call. In which case, it will do a copy of the current es_format_t if p_fmt
- * is not NULL and will do a copy of the current description if pp_meta is non NULL.
- * The es_format_t MUST be freed by es_format_Clean and *pp_meta MUST be freed by
- * vlc_meta_Delete.
- * Otherwise it will return false and will not initialize p_fmt and *pp_meta.
+ * Get the last status of the decoder.
  */
-bool vlc_input_decoder_HasFormatChanged( vlc_input_decoder_t *p_dec, es_format_t *p_fmt, vlc_meta_t **pp_meta );
+void vlc_input_decoder_GetStatus( vlc_input_decoder_t *p_dec,
+                                  struct vlc_input_decoder_status *status );
 
 /**
  * This function returns the current size in bytes of the decoder fifo


=====================================
src/input/es_out.c
=====================================
@@ -228,6 +228,8 @@ typedef struct
     /* Used only to limit debugging output */
     int         i_prev_stream_level;
 
+    unsigned    cc_decoder;
+
     es_out_t out;
 } es_out_sys_t;
 
@@ -556,6 +558,8 @@ es_out_t *input_EsOutNew( input_thread_t *p_input, input_source_t *main_source,
     EsOutPropsInit( &p_sys->sub,  false, p_input, ES_OUT_ES_POLICY_AUTO,
                     "sub-track-id", "sub-track", "sub-language", "sub" );
 
+    p_sys->cc_decoder = var_InheritInteger( p_input, "captions" );
+
     p_sys->i_group_id = var_GetInteger( p_input, "program" );
 
     p_sys->clock_source = clock_source_Inherit( VLC_OBJECT(p_input) );
@@ -2917,28 +2921,26 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
     vlc_input_decoder_Decode( es->p_dec, p_block,
                               input_priv(p_input)->b_out_pace_control );
 
-    es_format_t fmt_dsc;
-    vlc_meta_t  *p_meta_dsc;
-    if( vlc_input_decoder_HasFormatChanged( es->p_dec, &fmt_dsc, &p_meta_dsc ) )
+    struct vlc_input_decoder_status status;
+    vlc_input_decoder_GetStatus( es->p_dec, &status );
+
+    if( status.format.changed )
     {
-        if (EsOutEsUpdateFmt( out, es, &fmt_dsc) == VLC_SUCCESS)
+        if (EsOutEsUpdateFmt( out, es, &status.format.fmt ) == VLC_SUCCESS)
             EsOutSendEsEvent(out, es, VLC_INPUT_ES_UPDATED, false);
 
-        EsOutUpdateInfo(out, es, p_meta_dsc);
+        EsOutUpdateInfo(out, es, status.format.meta);
 
-        es_format_Clean( &fmt_dsc );
-        if( p_meta_dsc )
-            vlc_meta_Delete( p_meta_dsc );
+        es_format_Clean( &status.format.fmt );
+        if( status.format.meta )
+            vlc_meta_Delete( status.format.meta );
     }
 
     /* Check CC status */
-    decoder_cc_desc_t desc;
-
-    vlc_input_decoder_GetCcDesc( es->p_dec, &desc );
-    if( var_InheritInteger( p_input, "captions" ) == 708 )
-        EsOutCreateCCChannels( out, VLC_CODEC_CEA708, desc.i_708_channels,
+    if( p_sys->cc_decoder == 708 )
+        EsOutCreateCCChannels( out, VLC_CODEC_CEA708, status.cc.desc.i_708_channels,
                                _("DTVCC Closed captions %u"), es );
-    EsOutCreateCCChannels( out, VLC_CODEC_CEA608, desc.i_608_channels,
+    EsOutCreateCCChannels( out, VLC_CODEC_CEA608, status.cc.desc.i_608_channels,
                            _("Closed captions %u"), es );
 
     vlc_mutex_unlock( &p_sys->lock );



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/73f0f9f10c164f1242cb8ec626242835560e3c0a...fcb718217029a058a9633b9035c0a880129f4d14

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/73f0f9f10c164f1242cb8ec626242835560e3c0a...fcb718217029a058a9633b9035c0a880129f4d14
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list