1 /*****************************************************************************
2 * setid.c: set ID on a stream
3 *****************************************************************************
4 * Copyright (C) 2009 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_("ID")
42 #define ID_LONGTEXT N_( \
43 "Specify an identifier integer for this elementary stream" )
45 #define NEWID_TEXT N_("New ID")
46 #define NEWID_LONGTEXT N_( \
47 "Specify an new identifier integer for this elementary stream" )
49 static int Open ( vlc_object_t * );
50 static void Close ( vlc_object_t * );
52 #define SOUT_CFG_PREFIX "sout-setid-"
55 set_shortname( _("setid"))
56 set_description( _("Automatically add/delete input streams"))
57 set_capability( "sout stream", 50 )
58 add_shortcut( "setid" )
59 set_callbacks( Open, Close )
60 add_integer( SOUT_CFG_PREFIX "id", 0, ID_TEXT, ID_LONGTEXT,
62 add_integer( SOUT_CFG_PREFIX "new-id", 0, NEWID_TEXT, NEWID_LONGTEXT,
67 /*****************************************************************************
69 *****************************************************************************/
70 static const char *ppsz_sout_options[] = {
74 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
75 static int Del ( sout_stream_t *, sout_stream_id_t * );
76 static int Send ( sout_stream_t *, sout_stream_id_t *, block_t * );
78 struct sout_stream_sys_t
84 /*****************************************************************************
86 *****************************************************************************/
87 static int Open( vlc_object_t *p_this )
89 sout_stream_t *p_stream = (sout_stream_t*)p_this;
90 sout_stream_sys_t *p_sys;
93 p_sys = malloc( sizeof( sout_stream_sys_t ) );
95 if( !p_stream->p_next )
97 msg_Err( p_stream, "cannot create chain" );
102 config_ChainParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options,
105 var_Get( p_stream, SOUT_CFG_PREFIX "id", &val );
106 p_sys->i_id = val.i_int;
107 var_Get( p_stream, SOUT_CFG_PREFIX "new-id", &val );
108 p_sys->i_new_id = val.i_int;
110 p_stream->pf_add = Add;
111 p_stream->pf_del = Del;
112 p_stream->pf_send = Send;
114 p_stream->p_sys = p_sys;
119 /*****************************************************************************
121 *****************************************************************************/
122 static void Close( vlc_object_t * p_this )
124 sout_stream_t *p_stream = (sout_stream_t*)p_this;
125 sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys;
130 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
132 sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys;
134 if ( p_fmt->i_id == p_sys->i_id )
136 msg_Dbg( p_stream, "turning ID %d to %d",
137 p_sys->i_id, p_sys->i_new_id );
138 p_fmt->i_id = p_sys->i_new_id;
142 return p_sys->p_out->pf_add( p_sys->p_out, p_fmt );
145 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
147 sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys;
149 return p_sys->p_out->pf_del( p_sys->p_out, id );
152 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
155 sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys;
157 return p_sys->p_out->pf_send( p_sys->p_out, id, p_buffer );