[vlc-commits] avformat (mux/demux): implement private options

Rafaël Carré git at videolan.org
Tue Apr 17 14:36:15 CEST 2012


vlc | branch: master | Rafaël Carré <funman at videolan.org> | Sun Apr 15 17:46:53 2012 -0400| [08fb37c05dd28ca6e774b87b63ea3eac0cc54e51] | committer: Rafaël Carré

avformat (mux/demux): implement private options

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

 modules/codec/avcodec/avcommon.h  |    2 +-
 modules/demux/avformat/avformat.c |    3 +++
 modules/demux/avformat/demux.c    |   24 +++++++++++++++++++++---
 modules/demux/avformat/mux.c      |   14 ++++++++++++--
 4 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/modules/codec/avcodec/avcommon.h b/modules/codec/avcodec/avcommon.h
index d65bd4d..24b132a 100644
--- a/modules/codec/avcodec/avcommon.h
+++ b/modules/codec/avcodec/avcommon.h
@@ -67,7 +67,7 @@ static inline void vlc_init_avcodec(void)
 static inline AVDictionary *vlc_av_get_options(const char *psz_opts)
 {
     AVDictionary *options = NULL;
-    config_chain_t *cfg;
+    config_chain_t *cfg = NULL;
     config_ChainParseOptions(&cfg, psz_opts);
     while (cfg) {
         config_chain_t *next = cfg->p_next;
diff --git a/modules/demux/avformat/avformat.c b/modules/demux/avformat/avformat.c
index 6d3e172..de3e9b2 100644
--- a/modules/demux/avformat/avformat.c
+++ b/modules/demux/avformat/avformat.c
@@ -31,6 +31,7 @@
 #include <vlc_plugin.h>
 
 #include "avformat.h"
+#include "../../codec/avcodec/avcommon.h"
 
 vlc_module_begin ()
 #endif /* MERGE_FFMPEG */
@@ -43,6 +44,7 @@ vlc_module_begin ()
     set_callbacks( OpenDemux, CloseDemux )
     add_string( "avformat-format", NULL, FORMAT_TEXT, FORMAT_LONGTEXT, true )
     add_obsolete_string("ffmpeg-format") /* removed since 2.1.0 */
+    add_string( "avformat-options", NULL, AV_OPTIONS_TEXT, AV_OPTIONS_LONGTEXT, true )
 
 #ifdef ENABLE_SOUT
     /* mux submodule */
@@ -52,6 +54,7 @@ vlc_module_begin ()
     set_capability( "sout mux", 2 )
     add_string( "sout-avformat-mux", NULL, MUX_TEXT, MUX_LONGTEXT, true )
     add_obsolete_string("ffmpeg-mux") /* removed since 2.1.0 */
+    add_string( "sout-avformat-options", NULL, AV_OPTIONS_TEXT, AV_OPTIONS_LONGTEXT, true )
     set_callbacks( OpenMux, CloseMux )
 #endif
 #ifndef MERGE_FFMPEG
diff --git a/modules/demux/avformat/demux.c b/modules/demux/avformat/demux.c
index 4596583..785bf33 100644
--- a/modules/demux/avformat/demux.c
+++ b/modules/demux/avformat/demux.c
@@ -250,13 +250,31 @@ int OpenDemux( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
-    vlc_avcodec_lock(); /* avformat calls avcodec behind our back!!! */
 #if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(26<<8)+0)
-    error = avformat_find_stream_info( p_sys->ic, NULL /* options */ );
+    char *psz_opts = var_InheritString( p_demux, "avformat-options" );
+    AVDictionary *options[p_sys->ic->nb_streams];
+    if (psz_opts && *psz_opts) {
+        options[0] = vlc_av_get_options(psz_opts);
+        for (unsigned i = 1; i < p_sys->ic->nb_streams; i++) {
+            options[i] = NULL;
+            av_dict_copy(&options[i], options[0], 0);
+        }
+    }
+    free(psz_opts);
+    vlc_avcodec_lock(); /* avformat calls avcodec behind our back!!! */
+    error = avformat_find_stream_info( p_sys->ic, options );
+    vlc_avcodec_unlock();
+    AVDictionaryEntry *t = NULL;
+    while ((t = av_dict_get(options, "", t, AV_DICT_IGNORE_SUFFIX))) {
+        msg_Err( p_demux, "Unknown option \"%s\"", t->key );
+    }
+    av_dict_free(&options);
 #else
+    vlc_avcodec_lock(); /* avformat calls avcodec behind our back!!! */
     error = av_find_stream_info( p_sys->ic );
-#endif
     vlc_avcodec_unlock();
+#endif
+
     if( error < 0 )
     {
         errno = AVUNERROR(error);
diff --git a/modules/demux/avformat/mux.c b/modules/demux/avformat/mux.c
index 625b652..5d06059 100644
--- a/modules/demux/avformat/mux.c
+++ b/modules/demux/avformat/mux.c
@@ -47,7 +47,7 @@
 //#define AVFORMAT_DEBUG 1
 
 static const char *const ppsz_mux_options[] = {
-    "mux", NULL
+    "mux", "options", NULL
 };
 
 /*****************************************************************************
@@ -381,7 +381,17 @@ static int Mux( sout_mux_t *p_mux )
         msg_Dbg( p_mux, "writing header" );
 
 #if (LIBAVFORMAT_VERSION_INT >= ((53<<16)+(2<<8)+0))
-        error = avformat_write_header( p_sys->oc, NULL /* options */ );
+        char *psz_opts = var_GetNonEmptyString( p_mux, "sout-avformat-options" );
+        AVDictionary *options = NULL;
+        if (psz_opts && *psz_opts)
+            options = vlc_av_get_options(psz_opts);
+        free(psz_opts);
+        error = avformat_write_header( p_sys->oc, options ? &options : NULL);
+        AVDictionaryEntry *t = NULL;
+        while ((t = av_dict_get(options, "", t, AV_DICT_IGNORE_SUFFIX))) {
+            msg_Err( p_mux, "Unknown option \"%s\"", t->key );
+        }
+        av_dict_free(&options);
 #else
         error = av_write_header( p_sys->oc );
 #endif



More information about the vlc-commits mailing list