1 /*****************************************************************************
2 * setid.c: set ID/lang on a stream
3 *****************************************************************************
4 * Copyright © 2009-2011 VLC authors and VideoLAN
6 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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_sys_t
*AddId ( sout_stream_t
*, const es_format_t
* );
99 static sout_stream_id_sys_t
*AddLang( sout_stream_t
*, const es_format_t
* );
100 static void Del ( sout_stream_t
*, sout_stream_id_sys_t
* );
101 static int Send ( sout_stream_t
*, sout_stream_id_sys_t
*, block_t
* );
103 struct sout_stream_sys_t
110 /*****************************************************************************
112 *****************************************************************************/
113 static int OpenCommon( vlc_object_t
*p_this
)
115 sout_stream_t
*p_stream
= (sout_stream_t
*)p_this
;
116 sout_stream_sys_t
*p_sys
;
118 if( !p_stream
->p_next
)
120 msg_Err( p_stream
, "cannot create chain" );
124 p_sys
= malloc( sizeof( sout_stream_sys_t
) );
125 if( unlikely( !p_sys
) )
128 p_stream
->pf_del
= Del
;
129 p_stream
->pf_send
= Send
;
131 p_stream
->p_sys
= p_sys
;
136 static int OpenId( vlc_object_t
*p_this
)
138 int i_ret
= OpenCommon( p_this
);
139 if( i_ret
!= VLC_SUCCESS
)
142 sout_stream_t
*p_stream
= (sout_stream_t
*)p_this
;
144 config_ChainParse( p_stream
, SOUT_CFG_PREFIX_ID
, ppsz_sout_options_id
,
147 p_stream
->p_sys
->i_id
= var_GetInteger( p_stream
, SOUT_CFG_PREFIX_ID
"id" );
148 p_stream
->p_sys
->i_new_id
= var_GetInteger( p_stream
, SOUT_CFG_PREFIX_ID
"new-id" );
149 p_stream
->p_sys
->psz_language
= NULL
;
151 p_stream
->pf_add
= AddId
;
156 static int OpenLang( vlc_object_t
*p_this
)
158 int i_ret
= OpenCommon( p_this
);
159 if( i_ret
!= VLC_SUCCESS
)
162 sout_stream_t
*p_stream
= (sout_stream_t
*)p_this
;
164 config_ChainParse( p_stream
, SOUT_CFG_PREFIX_LANG
, ppsz_sout_options_lang
,
167 p_stream
->p_sys
->i_id
= var_GetInteger( p_stream
, SOUT_CFG_PREFIX_LANG
"id" );
168 p_stream
->p_sys
->i_new_id
= -1;
169 p_stream
->p_sys
->psz_language
= var_GetString( p_stream
, SOUT_CFG_PREFIX_LANG
"lang" );
171 p_stream
->pf_add
= AddLang
;
176 /*****************************************************************************
178 *****************************************************************************/
179 static void Close( vlc_object_t
* p_this
)
181 sout_stream_t
*p_stream
= (sout_stream_t
*)p_this
;
182 sout_stream_sys_t
*p_sys
= (sout_stream_sys_t
*)p_stream
->p_sys
;
184 free( p_sys
->psz_language
);
188 static sout_stream_id_sys_t
* AddId( sout_stream_t
*p_stream
, const es_format_t
*p_fmt
)
190 sout_stream_sys_t
*p_sys
= (sout_stream_sys_t
*)p_stream
->p_sys
;
193 if( p_fmt
->i_id
== p_sys
->i_id
)
195 msg_Dbg( p_stream
, "turning ID %d to %d", p_sys
->i_id
,
199 fmt
.i_id
= p_sys
->i_new_id
;
203 return sout_StreamIdAdd( p_stream
->p_next
, p_fmt
);
206 static sout_stream_id_sys_t
* AddLang( sout_stream_t
*p_stream
, const es_format_t
*p_fmt
)
208 sout_stream_sys_t
*p_sys
= (sout_stream_sys_t
*)p_stream
->p_sys
;
211 if ( p_fmt
->i_id
== p_sys
->i_id
)
213 msg_Dbg( p_stream
, "turning language %s of ID %d to %s",
214 p_fmt
->psz_language
? p_fmt
->psz_language
: "unk",
215 p_sys
->i_id
, p_sys
->psz_language
);
218 fmt
.psz_language
= p_sys
->psz_language
;
222 return sout_StreamIdAdd( p_stream
->p_next
, p_fmt
);
225 static void Del( sout_stream_t
*p_stream
, sout_stream_id_sys_t
*id
)
227 p_stream
->p_next
->pf_del( p_stream
->p_next
, id
);
230 static int Send( sout_stream_t
*p_stream
, sout_stream_id_sys_t
*id
,
233 return p_stream
->p_next
->pf_send( p_stream
->p_next
, id
, p_buffer
);