1 /*****************************************************************************
2 * gather.c: gathering stream output module
3 *****************************************************************************
4 * Copyright (C) 2003-2004 VideoLAN
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( _("Gathering stream output") );
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 *, es_format_t * );
50 static int Del ( sout_stream_t *, sout_stream_id_t * );
51 static int Send( sout_stream_t *, sout_stream_id_t *,
54 struct sout_stream_id_t
62 struct sout_stream_sys_t
67 sout_stream_id_t **id;
70 /*****************************************************************************
72 *****************************************************************************/
73 static int Open( vlc_object_t *p_this )
75 sout_stream_t *p_stream = (sout_stream_t*)p_this;
76 sout_stream_sys_t *p_sys;
78 p_stream->p_sys = p_sys = malloc( sizeof( sout_stream_sys_t ) );
79 p_sys->p_out = sout_StreamNew( p_stream->p_sout, p_stream->psz_next );
80 if( p_sys->p_out == NULL )
88 p_stream->pf_add = Add;
89 p_stream->pf_del = Del;
90 p_stream->pf_send = Send;
95 /*****************************************************************************
97 *****************************************************************************/
98 static void Close( vlc_object_t * p_this )
100 sout_stream_t *p_stream = (sout_stream_t*)p_this;
101 sout_stream_sys_t *p_sys = p_stream->p_sys;
104 for( i = 0; i < p_sys->i_id; i++ )
106 p_sys->p_out->pf_del( p_sys->p_out, p_sys->id[i]->id );
107 free( p_sys->id[i] );
111 sout_StreamDelete( p_sys->p_out );
115 /*****************************************************************************
117 *****************************************************************************/
118 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
120 sout_stream_sys_t *p_sys = p_stream->p_sys;
121 sout_stream_id_t *id;
124 /* search a output compatible */
125 for( i = 0; i < p_sys->i_id; i++ )
129 id->fmt.i_cat == p_fmt->i_cat &&
130 id->fmt.i_codec == p_fmt->i_codec &&
131 ( ( id->fmt.i_cat == AUDIO_ES &&
132 id->fmt.audio.i_rate == p_fmt->audio.i_rate &&
133 id->fmt.audio.i_channels == p_fmt->audio.i_channels &&
134 id->fmt.audio.i_blockalign == p_fmt->audio.i_blockalign ) ||
135 ( id->fmt.i_cat == VIDEO_ES &&
136 id->fmt.video.i_width == p_fmt->video.i_width &&
137 id->fmt.video.i_height == p_fmt->video.i_height ) ) )
139 msg_Dbg( p_stream, "reusing already opened output" );
140 id->b_used = VLC_TRUE;
145 /* destroy all output of the same categorie */
146 for( i = 0; i < p_sys->i_id; i++ )
149 if( !id->b_used && id->fmt.i_cat == p_fmt->i_cat )
151 TAB_REMOVE( p_sys->i_id, p_sys->id, id );
152 p_sys->p_out->pf_del( p_sys->p_out, id );
160 id = malloc( sizeof( sout_stream_id_t ) );
161 msg_Dbg( p_stream, "creating new output" );
162 memcpy( &id->fmt, p_fmt, sizeof( es_format_t ) );
164 id->fmt.p_extra = NULL;
165 id->b_used = VLC_TRUE;
166 id->id = p_sys->p_out->pf_add( p_sys->p_out, p_fmt );
172 TAB_APPEND( p_sys->i_id, p_sys->id, id );
177 /*****************************************************************************
179 *****************************************************************************/
180 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
182 id->b_used = VLC_FALSE;
186 /*****************************************************************************
188 *****************************************************************************/
189 static int Send( sout_stream_t *p_stream,
190 sout_stream_id_t *id, block_t *p_buffer )
192 sout_stream_sys_t *p_sys = p_stream->p_sys;
194 return p_sys->p_out->pf_send( p_sys->p_out, id->id, p_buffer );