Commit 0880b6a6 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Add a setlang submodule to setid

Work based on Christophe Massiot setlang module, merged by /me
parent d4e913a6
/***************************************************************************** /*****************************************************************************
* 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@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -46,45 +46,69 @@ ...@@ -46,45 +46,69 @@
#define NEWID_LONGTEXT N_( \ #define NEWID_LONGTEXT N_( \
"Specify an new identifier integer for this elementary stream" ) "Specify an new identifier integer for this elementary stream" )
static int Open ( vlc_object_t * ); #define LANG_TEXT N_("Language")
#define LANG_LONGTEXT N_( \
"Specify an ISO-639 code (three characters) for this elementary stream" )
static int OpenId ( vlc_object_t * );
static int OpenLang ( vlc_object_t * );
static void Close ( vlc_object_t * ); static void Close ( vlc_object_t * );
#define SOUT_CFG_PREFIX "sout-setid-" #define SOUT_CFG_PREFIX_ID "sout-setid-"
#define SOUT_CFG_PREFIX_LANG "sout-setlang-"
vlc_module_begin() vlc_module_begin()
set_shortname( _("setid")) set_shortname( _("setid"))
set_description( _("Automatically add/delete input streams")) set_description( _("Automatically add/delete input streams"))
set_capability( "sout stream", 50 ) set_capability( "sout stream", 50 )
add_shortcut( "setid" ) add_shortcut( "setid" )
set_callbacks( Open, Close ) set_callbacks( OpenId, Close )
add_integer( SOUT_CFG_PREFIX "id", 0, ID_TEXT, ID_LONGTEXT, add_integer( SOUT_CFG_PREFIX_ID "id", 0, ID_TEXT, ID_LONGTEXT, false )
false ) add_integer( SOUT_CFG_PREFIX_ID "new-id", 0, NEWID_TEXT, NEWID_LONGTEXT,
add_integer( SOUT_CFG_PREFIX "new-id", 0, NEWID_TEXT, NEWID_LONGTEXT,
false ) 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() vlc_module_end()
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
static const char *ppsz_sout_options[] = { static const char *ppsz_sout_options_id[] = {
"id", "new-id", NULL "id", "new-id", NULL
}; };
static sout_stream_id_t *Add ( sout_stream_t *, es_format_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 Del ( sout_stream_t *, sout_stream_id_t * );
static int Send ( sout_stream_t *, sout_stream_id_t *, block_t * ); static int Send ( sout_stream_t *, sout_stream_id_t *, block_t * );
struct sout_stream_sys_t struct sout_stream_sys_t
{ {
sout_stream_t *p_out; sout_stream_t *p_out;
int i_id, i_new_id; int i_id;
int i_new_id;
char *psz_language;
}; };
/***************************************************************************** /*****************************************************************************
* Open: * 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_t *p_stream = (sout_stream_t*)p_this;
sout_stream_sys_t *p_sys; sout_stream_sys_t *p_sys;
...@@ -100,13 +124,6 @@ static int Open( vlc_object_t *p_this ) ...@@ -100,13 +124,6 @@ static int Open( vlc_object_t *p_this )
return VLC_EGENERIC; 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_del = Del;
p_stream->pf_send = Send; p_stream->pf_send = Send;
...@@ -115,6 +132,46 @@ static int Open( vlc_object_t *p_this ) ...@@ -115,6 +132,46 @@ static int Open( vlc_object_t *p_this )
return VLC_SUCCESS; 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: * Close:
*****************************************************************************/ *****************************************************************************/
...@@ -123,10 +180,11 @@ static void Close( vlc_object_t * p_this ) ...@@ -123,10 +180,11 @@ static void Close( vlc_object_t * p_this )
sout_stream_t *p_stream = (sout_stream_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; sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys;
free( p_sys->psz_language );
free( p_sys ); 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; 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 ) ...@@ -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; 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 ); return p_sys->p_out->pf_add( p_sys->p_out, p_fmt );
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment