[vlc-commits] demux: avformat: refactor options handling

Francois Cartegnie git at videolan.org
Thu Sep 26 18:02:29 CEST 2019


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Sep 26 17:15:12 2019 +0200| [d65bc86381f0c9be715d3c35c9246f7ffd2d630b] | committer: Francois Cartegnie

demux: avformat: refactor options handling

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d65bc86381f0c9be715d3c35c9246f7ffd2d630b
---

 modules/demux/avformat/demux.c | 58 +++++++++++++++++++++++++++---------------
 1 file changed, 37 insertions(+), 21 deletions(-)

diff --git a/modules/demux/avformat/demux.c b/modules/demux/avformat/demux.c
index ce59cc7ccc..2ec841d9b4 100644
--- a/modules/demux/avformat/demux.c
+++ b/modules/demux/avformat/demux.c
@@ -167,33 +167,49 @@ static void get_rotation(es_format_t *fmt, AVStream *s)
     }
 }
 
-static void FindStreamInfo( demux_t *p_demux )
+static AVDictionary * BuildAVOptions( demux_t *p_demux )
+{
+    char *psz_opts = var_InheritString( p_demux, "avformat-options" );
+    AVDictionary *options = NULL;
+    if( psz_opts )
+    {
+        vlc_av_get_options( psz_opts, &options );
+        free( psz_opts );
+    }
+    return options;
+}
+
+static void FreeUnclaimedOptions( demux_t *p_demux, AVDictionary **pp_dict )
+{
+    AVDictionaryEntry *t = NULL;
+    while ((t = av_dict_get(*pp_dict, "", t, AV_DICT_IGNORE_SUFFIX))) {
+        msg_Err( p_demux, "Unknown option \"%s\"", t->key );
+    }
+    av_dict_free(pp_dict);
+}
+
+static void FindStreamInfo( demux_t *p_demux, AVDictionary *options )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
     unsigned nb_streams = p_sys->ic->nb_streams;
 
-    char *psz_opts = var_InheritString( p_demux, "avformat-options" );
-    AVDictionary *options[nb_streams ? nb_streams : 1];
-    options[0] = NULL;
-    for (unsigned i = 1; i < nb_streams; i++)
-        options[i] = NULL;
-    if (psz_opts) {
-        vlc_av_get_options(psz_opts, &options[0]);
-        for (unsigned i = 1; i < nb_streams; i++) {
-            av_dict_copy(&options[i], options[0], 0);
-        }
-        free(psz_opts);
+    AVDictionary *streamsoptions[nb_streams ? nb_streams : 1];
+
+    streamsoptions[0] = options;
+    for ( unsigned i = 1; i < nb_streams; i++ )
+    {
+        streamsoptions[i] = NULL;
+        if( streamsoptions[0] )
+            av_dict_copy( &streamsoptions[i], streamsoptions[0], 0 );
     }
+
     vlc_avcodec_lock(); /* avformat calls avcodec behind our back!!! */
-    int error = avformat_find_stream_info( p_sys->ic, options );
+    int error = avformat_find_stream_info( p_sys->ic, streamsoptions );
     vlc_avcodec_unlock();
-    AVDictionaryEntry *t = NULL;
-    while ((t = av_dict_get(options[0], "", t, AV_DICT_IGNORE_SUFFIX))) {
-        msg_Err( p_demux, "Unknown option \"%s\"", t->key );
-    }
-    av_dict_free(&options[0]);
-    for (unsigned i = 1; i < nb_streams; i++) {
-        av_dict_free(&options[i]);
+
+    FreeUnclaimedOptions( p_demux, &streamsoptions[0] );
+    for ( unsigned i = 1; i < nb_streams; i++ ) {
+        av_dict_free( &streamsoptions[i] );
     }
 
     if( error < 0 )
@@ -373,7 +389,7 @@ int avformat_OpenDemux( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
-    FindStreamInfo( p_demux );
+    FindStreamInfo( p_demux, BuildAVOptions( p_demux ) );
 
     unsigned nb_streams = p_sys->ic->nb_streams; /* it may have changed */
     if( !nb_streams )



More information about the vlc-commits mailing list