1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VideoLAN
5 * $Id: gather.c,v 1.1 2003/09/07 20:12:44 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 *****************************************************************************/
30 #include <vlc/input.h>
33 /*****************************************************************************
35 *****************************************************************************/
36 static int Open ( vlc_object_t * );
37 static void Close ( vlc_object_t * );
40 set_description( _("Gather stream") );
41 set_capability( "sout stream", 50 );
42 add_shortcut( "gather" );
43 set_callbacks( Open, Close );
46 /*****************************************************************************
48 *****************************************************************************/
49 static sout_stream_id_t *Add ( sout_stream_t *, sout_format_t * );
50 static int Del ( sout_stream_t *, sout_stream_id_t * );
51 static int Send( sout_stream_t *, sout_stream_id_t *, sout_buffer_t* );
53 struct sout_stream_id_t
61 struct sout_stream_sys_t
66 sout_stream_id_t **id;
69 /*****************************************************************************
71 *****************************************************************************/
72 static int Open( vlc_object_t *p_this )
74 sout_stream_t *p_stream = (sout_stream_t*)p_this;
75 sout_stream_sys_t *p_sys;
77 p_stream->p_sys = p_sys = malloc( sizeof( sout_stream_sys_t ) );
78 p_sys->p_out = sout_stream_new( p_stream->p_sout, p_stream->psz_next );
79 if( p_sys->p_out == NULL )
87 p_stream->pf_add = Add;
88 p_stream->pf_del = Del;
89 p_stream->pf_send = Send;
94 /*****************************************************************************
96 *****************************************************************************/
97 static void Close( vlc_object_t * p_this )
99 sout_stream_t *p_stream = (sout_stream_t*)p_this;
100 sout_stream_sys_t *p_sys = p_stream->p_sys;
103 for( i = 0; i < p_sys->i_id; i++ )
105 p_sys->p_out->pf_del( p_sys->p_out, p_sys->id[i]->id );
106 free( p_sys->id[i] );
110 sout_stream_delete( p_sys->p_out );
114 /*****************************************************************************
116 *****************************************************************************/
117 static sout_stream_id_t * Add( sout_stream_t *p_stream, sout_format_t *p_fmt )
119 sout_stream_sys_t *p_sys = p_stream->p_sys;
120 sout_stream_id_t *id;
123 /* search a output compatible */
124 for( i = 0; i < p_sys->i_id; i++ )
128 id->fmt.i_cat == p_fmt->i_cat &&
129 id->fmt.i_fourcc == p_fmt->i_fourcc &&
130 ( ( id->fmt.i_cat == AUDIO_ES &&
131 id->fmt.i_sample_rate == p_fmt->i_sample_rate &&
132 id->fmt.i_channels == p_fmt->i_channels &&
133 id->fmt.i_block_align == p_fmt->i_block_align ) ||
134 ( id->fmt.i_cat == VIDEO_ES &&
135 id->fmt.i_width == p_fmt->i_width &&
136 id->fmt.i_height == p_fmt->i_height ) ) )
138 msg_Dbg( p_stream, "reusing already opened output" );
139 id->b_used = VLC_TRUE;
144 /* destroy all output of the same categorie */
145 for( i = 0; i < p_sys->i_id; i++ )
148 if( !id->b_used && id->fmt.i_cat == p_fmt->i_cat )
150 TAB_REMOVE( p_sys->i_id, p_sys->id, id );
151 p_sys->p_out->pf_del( p_sys->p_out, id );
159 id = malloc( sizeof( sout_stream_id_t ) );
160 msg_Dbg( p_stream, "creating new output" );
161 memcpy( &id->fmt, p_fmt, sizeof( sout_format_t ) );
162 id->fmt.i_extra_data = 0;
163 id->fmt.p_extra_data = NULL;
164 id->b_used = VLC_TRUE;
165 id->id = p_sys->p_out->pf_add( p_sys->p_out, p_fmt );
171 TAB_APPEND( p_sys->i_id, p_sys->id, id );
176 /*****************************************************************************
178 *****************************************************************************/
179 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
181 id->b_used = VLC_FALSE;
185 /*****************************************************************************
187 *****************************************************************************/
188 static int Send( sout_stream_t *p_stream,
189 sout_stream_id_t *id, sout_buffer_t *p_buffer )
191 sout_stream_sys_t *p_sys = p_stream->p_sys;
193 return p_sys->p_out->pf_send( p_sys->p_out, id->id, p_buffer );