[vlc-commits] [Git][videolan/vlc][master] 7 commits: decoder: remove unused function declaration

Steve Lhomme (@robUx4) gitlab at videolan.org
Wed Oct 11 13:04:03 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
39b2ce2b by Thomas Guillem at 2023-10-11T12:33:04+00:00
decoder: remove unused function declaration

- - - - -
7923bc7a by Thomas Guillem at 2023-10-11T12:33:04+00:00
decoder: remove documented debug

- - - - -
dd63377c by Thomas Guillem at 2023-10-11T12:33:04+00:00
decoder: refactor and add DeleteCcDecoder()

- - - - -
b6fdb4a1 by Thomas Guillem at 2023-10-11T12:33:04+00:00
decoder: pass the selected CC decoder

For now, it is only used for optimizations: avoid to allocate blocks for
unselected decoders.

- - - - -
419e2b08 by Thomas Guillem at 2023-10-11T12:33:04+00:00
decoder: use the internal CC codec

It must be the same as the one given in arguments.

- - - - -
04315133 by Thomas Guillem at 2023-10-11T12:33:04+00:00
decoder: refactor and add GetCcChannels()

And replace a dynamic check with an assert().

- - - - -
1a4208f9 by Thomas Guillem at 2023-10-11T12:33:04+00:00
decoder: optimize locking when deleting CCs dec

This can avoid 3 extra lock/unlock when deleting the decoder in a
normal scenario.

The 4-64 CCs decoder where not cleaned (leaking) due to the
VLC_CODEC_CEA608 hardcoding.

- - - - -


3 changed files:

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


Changes:

=====================================
src/input/decoder.c
=====================================
@@ -216,6 +216,7 @@ struct vlc_input_decoder_t
 #define MAX_CC_DECODERS 64 /* The es_out only creates one type of es */
     struct
     {
+        vlc_fourcc_t selected_codec;
         vlc_mutex_t lock;
         bool b_supported;
         decoder_cc_desc_t desc;
@@ -1170,6 +1171,28 @@ static void DecoderThread_ProcessSout( vlc_input_decoder_t *p_owner, vlc_frame_t
     }
 }
 
+static void GetCcChannels(vlc_input_decoder_t *owner, size_t *max_channels,
+                          uint64_t *bitmap)
+{
+    switch (owner->cc.selected_codec)
+    {
+        case VLC_CODEC_CEA608:
+            if (max_channels != NULL)
+                *max_channels = 4;
+            if (bitmap != NULL)
+                *bitmap = owner->cc.desc.i_608_channels;
+            break;
+        case VLC_CODEC_CEA708:
+            if (max_channels != NULL)
+                *max_channels = 64;
+            if (bitmap != NULL)
+                *bitmap = owner->cc.desc.i_708_channels;
+            break;
+        default: vlc_assert_unreachable();
+    }
+}
+
+/* */
 static void DecoderPlayCcLocked( vlc_input_decoder_t *p_owner, vlc_frame_t *p_cc,
                                  const decoder_cc_desc_t *p_desc )
 {
@@ -1183,10 +1206,8 @@ static void DecoderPlayCcLocked( vlc_input_decoder_t *p_owner, vlc_frame_t *p_cc
     vlc_mutex_lock(&p_owner->cc.lock);
     p_owner->cc.desc = *p_desc;
 
-    /* Fanout data to all decoders. We do not know if es_out
-       selected 608 or 708. */
-    uint64_t i_bitmap = p_owner->cc.desc.i_608_channels |
-                        p_owner->cc.desc.i_708_channels;
+    uint64_t i_bitmap;
+    GetCcChannels(p_owner, NULL, &i_bitmap);
 
     for( int i=0; i_bitmap > 0; i_bitmap >>= 1, i++ )
     {
@@ -2011,6 +2032,8 @@ CreateDecoder( vlc_object_t *p_parent, const struct vlc_input_decoder_cfg *cfg )
 
     /* */
     vlc_mutex_init(&p_owner->cc.lock);
+    p_owner->cc.selected_codec = cfg->cc_decoder == 708 ?
+                                 VLC_CODEC_CEA708 : VLC_CODEC_CEA608;
     p_owner->cc.b_supported = ( cfg->sout == NULL );
 
     p_owner->cc.desc.i_608_channels = 0;
@@ -2119,6 +2142,20 @@ static void DeleteDecoder( vlc_input_decoder_t *p_owner, enum es_format_category
     decoder_Destroy( &p_owner->dec );
 }
 
+static void DeleteCcDecoder(vlc_input_decoder_t *owner, size_t index)
+{
+    assert(vlc_mutex_held(&owner->cc.lock));
+
+    vlc_input_decoder_t *cc = owner->cc.pp_decoder[index];
+    owner->cc.pp_decoder[index] = NULL;
+
+    if (cc != NULL)
+    {
+        vlc_input_decoder_Flush(cc);
+        vlc_input_decoder_Delete(cc);
+    }
+}
+
 /* */
 static void DecoderUnsupportedCodec( decoder_t *p_dec, const es_format_t *fmt, bool b_decoding )
 {
@@ -2238,8 +2275,12 @@ void vlc_input_decoder_Delete( vlc_input_decoder_t *p_owner )
     /* */
     if( p_owner->cc.b_supported )
     {
-        for( int i = 0; i < MAX_CC_DECODERS; i++ )
-            vlc_input_decoder_SetCcState( p_owner, VLC_CODEC_CEA608, i, false );
+        size_t max_channels;
+        GetCcChannels(p_owner, &max_channels, NULL);
+        vlc_mutex_lock(&p_owner->cc.lock);
+        for (size_t i = 0; i < max_channels; i++)
+            DeleteCcDecoder(p_owner, i);
+        vlc_mutex_unlock(&p_owner->cc.lock);
     }
 
     /* Delete decoder */
@@ -2429,34 +2470,23 @@ void vlc_input_decoder_Flush( vlc_input_decoder_t *p_owner )
 }
 
 static bool vlc_input_decoder_HasCCChanFlag( vlc_input_decoder_t *p_owner,
-                                             vlc_fourcc_t codec, int i_channel )
+                                             int i_channel )
 {
-    int i_max_channels;
+    size_t i_max_channels;
     uint64_t i_bitmap;
-    if( codec == VLC_CODEC_CEA608 )
-    {
-        i_max_channels = 4;
-        i_bitmap = p_owner->cc.desc.i_608_channels;
-    }
-    else if( codec == VLC_CODEC_CEA708 )
-    {
-        i_max_channels = 64;
-        i_bitmap = p_owner->cc.desc.i_708_channels;
-    }
-    else return false;
+    GetCcChannels(p_owner, &i_max_channels, &i_bitmap);
 
-    return ( i_channel >= 0 && i_channel < i_max_channels &&
+    return ( i_channel >= 0 && (size_t) i_channel < i_max_channels &&
              ( i_bitmap & ((uint64_t)1 << i_channel) ) );
 }
 
-int vlc_input_decoder_SetCcState( vlc_input_decoder_t *p_owner, vlc_fourcc_t codec,
+int vlc_input_decoder_SetCcState( vlc_input_decoder_t *p_owner,
                                   int i_channel, bool b_decode )
 {
     decoder_t *p_dec = &p_owner->dec;
-    //msg_Warn( p_dec, "vlc_input_decoder_SetCcState: %d @%x", b_decode, i_channel );
 
     vlc_mutex_lock(&p_owner->cc.lock);
-    if( !vlc_input_decoder_HasCCChanFlag( p_owner, codec, i_channel ) )
+    if( !vlc_input_decoder_HasCCChanFlag( p_owner, i_channel ) )
     {
         vlc_mutex_unlock(&p_owner->cc.lock);
         return VLC_EGENERIC;
@@ -2467,7 +2497,7 @@ int vlc_input_decoder_SetCcState( vlc_input_decoder_t *p_owner, vlc_fourcc_t cod
         vlc_input_decoder_t *p_ccowner;
         es_format_t fmt;
 
-        es_format_Init( &fmt, SPU_ES, codec );
+        es_format_Init( &fmt, SPU_ES, p_owner->cc.selected_codec );
         fmt.subs.cc.i_channel = i_channel;
         fmt.subs.cc.i_reorder_depth = p_owner->cc.desc.i_reorder_depth;
 
@@ -2504,28 +2534,17 @@ int vlc_input_decoder_SetCcState( vlc_input_decoder_t *p_owner, vlc_fourcc_t cod
         p_owner->cc.pp_decoder[i_channel] = p_ccowner;
     }
     else
-    {
-        vlc_input_decoder_t *p_cc;
-
-        p_cc = p_owner->cc.pp_decoder[i_channel];
-        p_owner->cc.pp_decoder[i_channel] = NULL;
-
-        if( p_cc )
-        {
+        DeleteCcDecoder(p_owner, i_channel);
 
-            vlc_input_decoder_Flush(p_cc);
-            vlc_input_decoder_Delete(p_cc);
-        }
-    }
     vlc_mutex_unlock(&p_owner->cc.lock);
     return VLC_SUCCESS;
 }
 
-int vlc_input_decoder_GetCcState( vlc_input_decoder_t *p_owner, vlc_fourcc_t codec,
+int vlc_input_decoder_GetCcState( vlc_input_decoder_t *p_owner,
                                   int i_channel, bool *pb_decode )
 {
     vlc_mutex_lock(&p_owner->cc.lock);
-    if( !vlc_input_decoder_HasCCChanFlag( p_owner, codec, i_channel ) )
+    if( !vlc_input_decoder_HasCCChanFlag( p_owner, i_channel ) )
     {
         vlc_mutex_unlock(&p_owner->cc.lock);
         return VLC_EGENERIC;


=====================================
src/input/decoder.h
=====================================
@@ -58,6 +58,7 @@ struct vlc_input_decoder_cfg
     input_resource_t *resource;
     sout_stream_t *sout;
     enum input_type input_type;
+    unsigned cc_decoder;
     const struct vlc_input_decoder_callbacks *cbs;
     void *cbs_data;
 };
@@ -105,18 +106,13 @@ bool vlc_input_decoder_IsEmpty( vlc_input_decoder_t * );
 /**
  * This function activates the request closed caption channel.
  */
-int vlc_input_decoder_SetCcState( vlc_input_decoder_t *, vlc_fourcc_t, int i_channel, bool b_decode );
+int vlc_input_decoder_SetCcState( vlc_input_decoder_t *, int i_channel, bool b_decode );
 
 /**
  * This function returns an error if the requested channel does not exist and
  * set pb_decode to the channel status(active or not) otherwise.
  */
-int vlc_input_decoder_GetCcState( vlc_input_decoder_t *, vlc_fourcc_t, int i_channel, bool *pb_decode );
-
-/**
- * This function get cc channels descriptions
- */
-void vlc_input_decoder_GetCcDesc( vlc_input_decoder_t *, decoder_cc_desc_t * );
+int vlc_input_decoder_GetCcState( vlc_input_decoder_t *, int i_channel, bool *pb_decode );
 
 /**
  * This function forces the display of the next picture


=====================================
src/input/es_out.c
=====================================
@@ -822,6 +822,7 @@ static int EsOutSetRecord(  es_out_t *out, bool b_record, const char *dir_path )
             .resource = input_priv(p_input)->p_resource,
             .sout = p_sys->p_sout_record,
             .input_type = INPUT_TYPE_NONE,
+            .cc_decoder = p_sys->cc_decoder,
             .cbs = &decoder_cbs,
             .cbs_data = p_es,
         };
@@ -2200,8 +2201,7 @@ static bool EsIsSelected( es_out_id_t *es )
     if( es->p_master->p_dec )
     {
         int i_channel = EsOutGetClosedCaptionsChannel( &es->fmt );
-        vlc_input_decoder_GetCcState( es->p_master->p_dec, es->fmt.i_codec,
-                                      i_channel, &b_decode );
+        vlc_input_decoder_GetCcState( es->p_master->p_dec, i_channel, &b_decode );
     }
     return b_decode;
 }
@@ -2277,6 +2277,7 @@ static void EsOutCreateDecoder( es_out_t *out, es_out_id_t *p_es )
         .resource = priv->p_resource,
         .sout = priv->p_sout,
         .input_type = p_sys->input_type,
+        .cc_decoder = p_sys->cc_decoder,
         .cbs = &decoder_cbs,
         .cbs_data = p_es,
     };
@@ -2300,6 +2301,7 @@ static void EsOutCreateDecoder( es_out_t *out, es_out_id_t *p_es )
                 .resource = priv->p_resource,
                 .sout = p_sys->p_sout_record,
                 .input_type = INPUT_TYPE_NONE,
+                .cc_decoder = p_sys->cc_decoder,
                 .cbs = &decoder_cbs,
                 .cbs_data = p_es,
             };
@@ -2380,8 +2382,7 @@ static void EsOutSelectEs( es_out_t *out, es_out_id_t *es, bool b_force )
         i_channel = EsOutGetClosedCaptionsChannel( &es->fmt );
 
         if( i_channel == -1 ||
-            vlc_input_decoder_SetCcState( es->p_master->p_dec, es->fmt.i_codec,
-                                          i_channel, true ) )
+            vlc_input_decoder_SetCcState( es->p_master->p_dec, i_channel, true ) )
             return;
     }
     else
@@ -2505,7 +2506,7 @@ static void EsOutUnselectEs( es_out_t *out, es_out_id_t *es, bool b_update )
         {
             int i_channel = EsOutGetClosedCaptionsChannel( &es->fmt );
             if( i_channel != -1 )
-                vlc_input_decoder_SetCcState( es->p_master->p_dec, es->fmt.i_codec,
+                vlc_input_decoder_SetCcState( es->p_master->p_dec,
                                               i_channel, false );
         }
     }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/59894f24f431e717444bb49331f35624eedc64f7...1a4208f9c88e34f12dbae4830b6918fbd202c395

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/59894f24f431e717444bb49331f35624eedc64f7...1a4208f9c88e34f12dbae4830b6918fbd202c395
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list