1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VideoLAN
5 * $Id: duplicate.c,v 1.1 2003/04/13 20:00:21 fenrir Exp $
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
33 /*****************************************************************************
35 *****************************************************************************/
36 static int Open ( vlc_object_t * );
37 static void Close ( vlc_object_t * );
39 static sout_stream_id_t *Add ( sout_stream_t *, sout_format_t * );
40 static int Del ( sout_stream_t *, sout_stream_id_t * );
41 static int Send( sout_stream_t *, sout_stream_id_t *, sout_buffer_t* );
43 /*****************************************************************************
45 *****************************************************************************/
47 set_description( _("Duplicate stream") );
48 set_capability( "sout stream", 50 );
49 add_shortcut( "duplicate" );
50 add_shortcut( "dup" );
51 set_callbacks( Open, Close );
55 struct sout_stream_sys_t
58 sout_stream_t **pp_streams;
61 struct sout_stream_id_t
67 /*****************************************************************************
69 *****************************************************************************/
70 static int Open( vlc_object_t *p_this )
72 sout_stream_t *p_stream = (sout_stream_t*)p_this;
73 sout_stream_sys_t *p_sys;
76 msg_Dbg( p_stream, "creating a duplication" );
78 p_sys = malloc( sizeof( sout_stream_sys_t ) );
79 p_sys->i_nb_streams = 0;
80 p_sys->pp_streams = NULL;
82 for( p_cfg = p_stream->p_cfg; p_cfg != NULL; p_cfg = p_cfg->p_next )
84 if( !strncmp( p_cfg->psz_name, "dst", strlen( "dst" ) ) )
88 msg_Dbg( p_stream, " * adding `%s'", p_cfg->psz_value );
89 s = sout_stream_new( p_stream->p_sout, p_cfg->psz_value );
91 TAB_APPEND( p_sys->i_nb_streams, p_sys->pp_streams, s );
95 if( p_sys->i_nb_streams == 0 )
97 msg_Err( p_stream, "no destination given" );
103 p_stream->pf_add = Add;
104 p_stream->pf_del = Del;
105 p_stream->pf_send = Send;
107 p_stream->p_sys = p_sys;
112 /*****************************************************************************
114 *****************************************************************************/
116 static void Close( vlc_object_t * p_this )
118 sout_stream_t *p_stream = (sout_stream_t*)p_this;
119 sout_stream_sys_t *p_sys = p_stream->p_sys;
123 msg_Dbg( p_stream, "closing a duplication" );
124 for( i = 0; i < p_sys->i_nb_streams; i++ )
126 sout_stream_delete( p_sys->pp_streams[i] );
128 free( p_sys->pp_streams );
135 static sout_stream_id_t * Add ( sout_stream_t *p_stream, sout_format_t *p_fmt )
137 sout_stream_sys_t *p_sys = p_stream->p_sys;
138 sout_stream_id_t *id;
141 id = malloc( sizeof( sout_stream_id_t ) );
145 for( i_stream = 0; i_stream < p_sys->i_nb_streams; i_stream++ )
149 /* XXX not the same sout_stream_id_t definition ... */
150 id_new = (void*)p_sys->pp_streams[i_stream]->pf_add( p_sys->pp_streams[i_stream], p_fmt );
151 TAB_APPEND( id->i_nb_ids, id->pp_ids, id_new );
154 if( id->i_nb_ids <= 0 )
163 static int Del ( sout_stream_t *p_stream, sout_stream_id_t *id )
165 sout_stream_sys_t *p_sys = p_stream->p_sys;
168 for( i_stream = 0; i_stream < p_sys->i_nb_streams; i_stream++ )
170 if( id->pp_ids[i_stream] )
172 p_sys->pp_streams[i_stream]->pf_del( p_sys->pp_streams[i_stream],
173 id->pp_ids[i_stream] );
182 static int Send ( sout_stream_t *p_stream, sout_stream_id_t *id, sout_buffer_t *p_buffer )
184 sout_stream_sys_t *p_sys = p_stream->p_sys;
187 for( i_stream = 0; i_stream < p_sys->i_nb_streams - 1; i_stream++ )
189 sout_buffer_t *p_dup;
191 if( id->pp_ids[i_stream] )
193 p_dup = sout_BufferDuplicate( p_stream->p_sout, p_buffer );
195 p_sys->pp_streams[i_stream]->pf_send( p_sys->pp_streams[i_stream],
196 id->pp_ids[i_stream],
201 i_stream = p_sys->i_nb_streams - 1;
202 if( id->pp_ids[i_stream] )
204 p_sys->pp_streams[i_stream]->pf_send( p_sys->pp_streams[i_stream],
205 id->pp_ids[i_stream],