[vlc-commits] Add a setlang submodule to setid
Jean-Baptiste Kempf
git at videolan.org
Thu Jan 20 16:09:54 CET 2011
vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Thu Jan 20 12:00:40 2011 +0100| [0880b6a67660783ff2fca29778c896f17d3545fa] | committer: Jean-Baptiste Kempf
Add a setlang submodule to setid
Work based on Christophe Massiot setlang module, merged by /me
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0880b6a67660783ff2fca29778c896f17d3545fa
---
modules/stream_out/setid.c | 120 +++++++++++++++++++++++++++++++++++---------
1 files changed, 96 insertions(+), 24 deletions(-)
diff --git a/modules/stream_out/setid.c b/modules/stream_out/setid.c
index b02bab3..7a3ef7a 100644
--- a/modules/stream_out/setid.c
+++ b/modules/stream_out/setid.c
@@ -1,7 +1,7 @@
/*****************************************************************************
- * setid.c: set ID on a stream
+ * setid.c: set ID/lang on a stream
*****************************************************************************
- * Copyright (C) 2009 VideoLAN and AUTHORS
+ * Copyright (C) 2009-2011 VideoLAN and AUTHORS
*
* Authors: Christophe Massiot <massiot at via.ecp.fr>
*
@@ -46,45 +46,69 @@
#define NEWID_LONGTEXT N_( \
"Specify an new identifier integer for this elementary stream" )
-static int Open ( vlc_object_t * );
-static void Close ( vlc_object_t * );
+#define LANG_TEXT N_("Language")
+#define LANG_LONGTEXT N_( \
+ "Specify an ISO-639 code (three characters) for this elementary stream" )
-#define SOUT_CFG_PREFIX "sout-setid-"
+static int OpenId ( vlc_object_t * );
+static int OpenLang ( vlc_object_t * );
+static void Close ( vlc_object_t * );
+
+#define SOUT_CFG_PREFIX_ID "sout-setid-"
+#define SOUT_CFG_PREFIX_LANG "sout-setlang-"
vlc_module_begin()
set_shortname( _("setid"))
set_description( _("Automatically add/delete input streams"))
set_capability( "sout stream", 50 )
add_shortcut( "setid" )
- set_callbacks( Open, Close )
- add_integer( SOUT_CFG_PREFIX "id", 0, ID_TEXT, ID_LONGTEXT,
- false )
- add_integer( SOUT_CFG_PREFIX "new-id", 0, NEWID_TEXT, NEWID_LONGTEXT,
+ set_callbacks( OpenId, Close )
+ add_integer( SOUT_CFG_PREFIX_ID "id", 0, ID_TEXT, ID_LONGTEXT, false )
+ add_integer( SOUT_CFG_PREFIX_ID "new-id", 0, NEWID_TEXT, NEWID_LONGTEXT,
false )
+
+ add_submodule ()
+ set_section( N_("setlang"), NULL )
+ set_shortname( _("setlang"))
+ set_description( _("Automatically add/delete input streams"))
+ set_capability( "sout stream", 50 )
+ add_shortcut( "setlang" );
+ set_callbacks( OpenLang, Close )
+ add_integer( SOUT_CFG_PREFIX_LANG "id", 0, ID_TEXT, ID_LONGTEXT, false )
+ add_string( SOUT_CFG_PREFIX_LANG "lang", "eng", LANG_TEXT, LANG_LONGTEXT,
+ false );
+
vlc_module_end()
/*****************************************************************************
* Local prototypes
*****************************************************************************/
-static const char *ppsz_sout_options[] = {
+static const char *ppsz_sout_options_id[] = {
"id", "new-id", NULL
};
-static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
-static int Del ( sout_stream_t *, sout_stream_id_t * );
-static int Send ( sout_stream_t *, sout_stream_id_t *, block_t * );
+static const char *ppsz_sout_options_lang[] = {
+ "id", "lang", NULL
+};
+
+static sout_stream_id_t *AddId ( sout_stream_t *, es_format_t * );
+static sout_stream_id_t *AddLang ( sout_stream_t *, es_format_t * );
+static int Del ( sout_stream_t *, sout_stream_id_t * );
+static int Send ( sout_stream_t *, sout_stream_id_t *, block_t * );
struct sout_stream_sys_t
{
- sout_stream_t *p_out;
- int i_id, i_new_id;
+ sout_stream_t *p_out;
+ int i_id;
+ int i_new_id;
+ char *psz_language;
};
/*****************************************************************************
* Open:
*****************************************************************************/
-static int Open( vlc_object_t *p_this )
+static int OpenCommon( vlc_object_t *p_this )
{
sout_stream_t *p_stream = (sout_stream_t*)p_this;
sout_stream_sys_t *p_sys;
@@ -100,13 +124,6 @@ static int Open( vlc_object_t *p_this )
return VLC_EGENERIC;
}
- config_ChainParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options,
- p_stream->p_cfg );
-
- p_sys->i_id = var_GetInteger( p_stream, SOUT_CFG_PREFIX "id" );
- p_sys->i_new_id = var_GetInteger( p_stream, SOUT_CFG_PREFIX "new-id" );
-
- p_stream->pf_add = Add;
p_stream->pf_del = Del;
p_stream->pf_send = Send;
@@ -115,6 +132,46 @@ static int Open( vlc_object_t *p_this )
return VLC_SUCCESS;
}
+static int OpenId( vlc_object_t *p_this )
+{
+ int i_ret = OpenCommon( p_this );
+ if( i_ret != VLC_SUCCESS )
+ return i_ret;
+
+ sout_stream_t *p_stream = (sout_stream_t*)p_this;
+
+ p_stream->p_sys->i_id = var_GetInteger( p_stream, SOUT_CFG_PREFIX_ID "id" );
+ p_stream->p_sys->i_new_id = var_GetInteger( p_stream, SOUT_CFG_PREFIX_ID "new-id" );
+ p_stream->p_sys->psz_language = NULL;
+
+ config_ChainParse( p_stream, SOUT_CFG_PREFIX_ID, ppsz_sout_options_id,
+ p_stream->p_cfg );
+
+ p_stream->pf_add = AddId;
+
+ return VLC_SUCCESS;
+}
+
+static int OpenLang( vlc_object_t *p_this )
+{
+ int i_ret = OpenCommon( p_this );
+ if( i_ret != VLC_SUCCESS )
+ return i_ret;
+
+ sout_stream_t *p_stream = (sout_stream_t*)p_this;
+
+ p_stream->p_sys->i_id = var_GetInteger( p_stream, SOUT_CFG_PREFIX_LANG "id" );
+ p_stream->p_sys->i_new_id = -1;
+ p_stream->p_sys->psz_language = var_GetString( p_stream, SOUT_CFG_PREFIX_LANG "lang" );
+
+ config_ChainParse( p_stream, SOUT_CFG_PREFIX_LANG, ppsz_sout_options_lang,
+ p_stream->p_cfg );
+
+ p_stream->pf_add = AddLang;
+
+ return VLC_SUCCESS;
+}
+
/*****************************************************************************
* Close:
*****************************************************************************/
@@ -123,10 +180,11 @@ static void Close( vlc_object_t * p_this )
sout_stream_t *p_stream = (sout_stream_t*)p_this;
sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys;
+ free( p_sys->psz_language );
free( p_sys );
}
-static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
+static sout_stream_id_t * AddId( sout_stream_t *p_stream, es_format_t *p_fmt )
{
sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys;
@@ -137,6 +195,20 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
p_fmt->i_id = p_sys->i_new_id;
}
+ return p_sys->p_out->pf_add( p_sys->p_out, p_fmt );
+}
+
+static sout_stream_id_t * AddLang( sout_stream_t *p_stream, es_format_t *p_fmt )
+{
+ sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys;
+
+ if ( p_fmt->i_id == p_sys->i_id )
+ {
+ msg_Dbg( p_stream, "turning language %s of ID %d to %s",
+ p_fmt->psz_language ? p_fmt->psz_language : "unk",
+ p_sys->i_id, p_sys->psz_language );
+ p_fmt->psz_language = strdup( p_sys->psz_language );
+ }
return p_sys->p_out->pf_add( p_sys->p_out, p_fmt );
}
More information about the vlc-commits
mailing list