1 /*****************************************************************************
2 * setid.c: set ID/lang on a stream
3 *****************************************************************************
4 * Copyright (C) 2009-2011 VideoLAN and AUTHORS
6 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
38 /*****************************************************************************
40 *****************************************************************************/
41 #define ID_TEXT N_("Elementary Stream ID")
42 #define ID_LONGTEXT N_( \
43 "Specify an identifier integer for this elementary stream" )
45 #define NEWID_TEXT N_("New ES ID")
46 #define NEWID_LONGTEXT N_( \
47 "Specify an new identifier integer for this elementary stream" )
49 #define LANG_TEXT N_("Language")
50 #define LANG_LONGTEXT N_( \
51 "Specify an ISO-639 code (three characters) for this elementary stream" )
53 static int OpenId ( vlc_object_t * );
54 static int OpenLang ( vlc_object_t * );
55 static void Close ( vlc_object_t * );
57 #define SOUT_CFG_PREFIX_ID "sout-setid-"
58 #define SOUT_CFG_PREFIX_LANG "sout-setlang-"
61 set_shortname( N_("Set ID"))
62 set_section( N_("Set ES id"), NULL )
63 set_description( N_("Change the id of an elementary stream"))
64 set_capability( "sout stream", 50 )
65 add_shortcut( "setid" )
66 set_category( CAT_SOUT )
67 set_subcategory( SUBCAT_SOUT_STREAM )
68 set_callbacks( OpenId, Close )
69 add_integer( SOUT_CFG_PREFIX_ID "id", 0, ID_TEXT, ID_LONGTEXT, false )
70 add_integer( SOUT_CFG_PREFIX_ID "new-id", 0, NEWID_TEXT, NEWID_LONGTEXT,
74 set_section( N_("Set ES Lang"), NULL )
75 set_shortname( N_("Set Lang"))
76 set_description( N_("Change the language of an elementary stream"))
77 set_capability( "sout stream", 50 )
78 add_shortcut( "setlang" );
79 set_callbacks( OpenLang, Close )
80 add_integer( SOUT_CFG_PREFIX_LANG "id", 0, ID_TEXT, ID_LONGTEXT, false )
81 add_string( SOUT_CFG_PREFIX_LANG "lang", "eng", LANG_TEXT, LANG_LONGTEXT,
87 /*****************************************************************************
89 *****************************************************************************/
90 static const char *ppsz_sout_options_id[] = {
94 static const char *ppsz_sout_options_lang[] = {
98 static sout_stream_id_t *AddId ( sout_stream_t *, es_format_t * );
99 static sout_stream_id_t *AddLang ( sout_stream_t *, es_format_t * );
100 static int Del ( sout_stream_t *, sout_stream_id_t * );
101 static int Send ( sout_stream_t *, sout_stream_id_t *, block_t * );
103 struct sout_stream_sys_t
105 sout_stream_t *p_out;
111 /*****************************************************************************
113 *****************************************************************************/
114 static int OpenCommon( vlc_object_t *p_this )
116 sout_stream_t *p_stream = (sout_stream_t*)p_this;
117 sout_stream_sys_t *p_sys;
119 p_sys = malloc( sizeof( sout_stream_sys_t ) );
120 if( unlikely( !p_sys ) )
123 if( !p_stream->p_next )
125 msg_Err( p_stream, "cannot create chain" );
130 p_stream->pf_del = Del;
131 p_stream->pf_send = Send;
133 p_stream->p_sys = p_sys;
138 static int OpenId( vlc_object_t *p_this )
140 int i_ret = OpenCommon( p_this );
141 if( i_ret != VLC_SUCCESS )
144 sout_stream_t *p_stream = (sout_stream_t*)p_this;
146 config_ChainParse( p_stream, SOUT_CFG_PREFIX_ID, ppsz_sout_options_id,
149 p_stream->p_sys->i_id = var_GetInteger( p_stream, SOUT_CFG_PREFIX_ID "id" );
150 p_stream->p_sys->i_new_id = var_GetInteger( p_stream, SOUT_CFG_PREFIX_ID "new-id" );
151 p_stream->p_sys->psz_language = NULL;
153 p_stream->pf_add = AddId;
158 static int OpenLang( vlc_object_t *p_this )
160 int i_ret = OpenCommon( p_this );
161 if( i_ret != VLC_SUCCESS )
164 sout_stream_t *p_stream = (sout_stream_t*)p_this;
166 config_ChainParse( p_stream, SOUT_CFG_PREFIX_LANG, ppsz_sout_options_lang,
169 p_stream->p_sys->i_id = var_GetInteger( p_stream, SOUT_CFG_PREFIX_LANG "id" );
170 p_stream->p_sys->i_new_id = -1;
171 p_stream->p_sys->psz_language = var_GetString( p_stream, SOUT_CFG_PREFIX_LANG "lang" );
173 p_stream->pf_add = AddLang;
178 /*****************************************************************************
180 *****************************************************************************/
181 static void Close( vlc_object_t * p_this )
183 sout_stream_t *p_stream = (sout_stream_t*)p_this;
184 sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys;
186 free( p_sys->psz_language );
190 static sout_stream_id_t * AddId( sout_stream_t *p_stream, es_format_t *p_fmt )
192 sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys;
194 if ( p_fmt->i_id == p_sys->i_id )
196 msg_Dbg( p_stream, "turning ID %d to %d",
197 p_sys->i_id, p_sys->i_new_id );
198 p_fmt->i_id = p_sys->i_new_id;
201 return p_sys->p_out->pf_add( p_sys->p_out, p_fmt );
204 static sout_stream_id_t * AddLang( sout_stream_t *p_stream, es_format_t *p_fmt )
206 sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys;
208 if ( p_fmt->i_id == p_sys->i_id )
210 msg_Dbg( p_stream, "turning language %s of ID %d to %s",
211 p_fmt->psz_language ? p_fmt->psz_language : "unk",
212 p_sys->i_id, p_sys->psz_language );
213 p_fmt->psz_language = strdup( p_sys->psz_language );
216 return p_sys->p_out->pf_add( p_sys->p_out, p_fmt );
219 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
221 sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys;
223 return p_sys->p_out->pf_del( p_sys->p_out, id );
226 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
229 sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys;
231 return p_sys->p_out->pf_send( p_sys->p_out, id, p_buffer );