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_category( CAT_SOUT );
44 set_subcategory( SUBCAT_SOUT_STREAM );
45 set_callbacks( Open, Close );
48 /*****************************************************************************
50 *****************************************************************************/
51 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
52 static int Del ( sout_stream_t *, sout_stream_id_t * );
53 static int Send( sout_stream_t *, sout_stream_id_t *,
56 struct sout_stream_id_t
64 struct sout_stream_sys_t
69 sout_stream_id_t **id;
72 /*****************************************************************************
74 *****************************************************************************/
75 static int Open( vlc_object_t *p_this )
77 sout_stream_t *p_stream = (sout_stream_t*)p_this;
78 sout_stream_sys_t *p_sys;
80 p_stream->p_sys = p_sys = malloc( sizeof( sout_stream_sys_t ) );
81 p_sys->p_out = sout_StreamNew( p_stream->p_sout, p_stream->psz_next );
82 if( p_sys->p_out == NULL )
90 p_stream->pf_add = Add;
91 p_stream->pf_del = Del;
92 p_stream->pf_send = Send;
97 /*****************************************************************************
99 *****************************************************************************/
100 static void Close( vlc_object_t * p_this )
102 sout_stream_t *p_stream = (sout_stream_t*)p_this;
103 sout_stream_sys_t *p_sys = p_stream->p_sys;
106 for( i = 0; i < p_sys->i_id; i++ )
108 p_sys->p_out->pf_del( p_sys->p_out, p_sys->id[i]->id );
109 free( p_sys->id[i] );
113 sout_StreamDelete( p_sys->p_out );
117 /*****************************************************************************
119 *****************************************************************************/
120 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
122 sout_stream_sys_t *p_sys = p_stream->p_sys;
123 sout_stream_id_t *id;
126 /* search a output compatible */
127 for( i = 0; i < p_sys->i_id; i++ )
131 id->fmt.i_cat == p_fmt->i_cat &&
132 id->fmt.i_codec == p_fmt->i_codec &&
133 ( ( id->fmt.i_cat == AUDIO_ES &&
134 id->fmt.audio.i_rate == p_fmt->audio.i_rate &&
135 id->fmt.audio.i_channels == p_fmt->audio.i_channels &&
136 id->fmt.audio.i_blockalign == p_fmt->audio.i_blockalign ) ||
137 ( id->fmt.i_cat == VIDEO_ES &&
138 id->fmt.video.i_width == p_fmt->video.i_width &&
139 id->fmt.video.i_height == p_fmt->video.i_height ) ) )
141 msg_Dbg( p_stream, "reusing already opened output" );
142 id->b_used = VLC_TRUE;
147 /* destroy all output of the same categorie */
148 for( i = 0; i < p_sys->i_id; i++ )
151 if( !id->b_used && id->fmt.i_cat == p_fmt->i_cat )
153 TAB_REMOVE( p_sys->i_id, p_sys->id, id );
154 p_sys->p_out->pf_del( p_sys->p_out, id );
162 id = malloc( sizeof( sout_stream_id_t ) );
163 msg_Dbg( p_stream, "creating new output" );
164 memcpy( &id->fmt, p_fmt, sizeof( es_format_t ) );
166 id->fmt.p_extra = NULL;
167 id->b_used = VLC_TRUE;
168 id->id = p_sys->p_out->pf_add( p_sys->p_out, p_fmt );
174 TAB_APPEND( p_sys->i_id, p_sys->id, id );
179 /*****************************************************************************
181 *****************************************************************************/
182 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
184 id->b_used = VLC_FALSE;
188 /*****************************************************************************
190 *****************************************************************************/
191 static int Send( sout_stream_t *p_stream,
192 sout_stream_id_t *id, block_t *p_buffer )
194 sout_stream_sys_t *p_sys = p_stream->p_sys;
196 return p_sys->p_out->pf_send( p_sys->p_out, id->id, p_buffer );