1 /*****************************************************************************
2 * gather.c: gathering stream output module
3 *****************************************************************************
4 * Copyright (C) 2003-2004 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_input.h>
37 /*****************************************************************************
39 *****************************************************************************/
40 static int Open ( vlc_object_t * );
41 static void Close ( vlc_object_t * );
44 set_description( N_("Gathering stream output") );
45 set_capability( "sout stream", 50 );
46 add_shortcut( "gather" );
47 set_callbacks( Open, Close );
50 /*****************************************************************************
52 *****************************************************************************/
53 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
54 static int Del ( sout_stream_t *, sout_stream_id_t * );
55 static int Send( sout_stream_t *, sout_stream_id_t *, block_t* );
57 struct sout_stream_id_t
65 struct sout_stream_sys_t
70 sout_stream_id_t **id;
73 /*****************************************************************************
75 *****************************************************************************/
76 static int Open( vlc_object_t *p_this )
78 sout_stream_t *p_stream = (sout_stream_t*)p_this;
79 sout_stream_sys_t *p_sys;
81 p_stream->p_sys = p_sys = malloc( sizeof( sout_stream_sys_t ) );
85 p_sys->p_out = sout_StreamNew( p_stream->p_sout, p_stream->psz_next );
86 if( p_sys->p_out == NULL )
91 p_stream->pf_add = Add;
92 p_stream->pf_del = Del;
93 p_stream->pf_send = Send;
95 TAB_INIT( p_sys->i_id, p_sys->id );
100 /*****************************************************************************
102 *****************************************************************************/
103 static void Close( vlc_object_t * p_this )
105 sout_stream_t *p_stream = (sout_stream_t*)p_this;
106 sout_stream_sys_t *p_sys = p_stream->p_sys;
109 for( i = 0; i < p_sys->i_id; i++ )
111 sout_stream_id_t *id = p_sys->id[i];
113 sout_StreamIdDel( p_sys->p_out, id->id );
114 es_format_Clean( &id->fmt );
117 TAB_CLEAN( p_sys->i_id, p_sys->id );
119 sout_StreamDelete( p_sys->p_out );
123 /*****************************************************************************
125 *****************************************************************************/
126 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
128 sout_stream_sys_t *p_sys = p_stream->p_sys;
129 sout_stream_id_t *id;
132 /* search a compatible output */
133 for( i = 0; i < p_sys->i_id; i++ )
139 if( id->fmt.i_cat != p_fmt->i_cat || id->fmt.i_codec != p_fmt->i_codec )
142 if( id->fmt.i_cat == AUDIO_ES )
144 audio_format_t *p_a = &id->fmt.audio;
145 if( p_a->i_rate != p_fmt->audio.i_rate ||
146 p_a->i_channels != p_fmt->audio.i_channels ||
147 p_a->i_blockalign != p_fmt->audio.i_blockalign )
150 else if( id->fmt.i_cat == VIDEO_ES )
152 video_format_t *p_v = &id->fmt.video;
153 if( p_v->i_width != p_fmt->video.i_width ||
154 p_v->i_height != p_fmt->video.i_height )
159 msg_Dbg( p_stream, "reusing already opened output" );
164 /* destroy all outputs from the same category */
165 for( i = 0; i < p_sys->i_id; i++ )
168 if( !id->b_used && id->fmt.i_cat == p_fmt->i_cat )
170 TAB_REMOVE( p_sys->i_id, p_sys->id, id );
171 sout_StreamIdDel( p_sys->p_out, id->id );
172 es_format_Clean( &id->fmt );
180 msg_Dbg( p_stream, "creating new output" );
181 id = malloc( sizeof( sout_stream_id_t ) );
184 es_format_Copy( &id->fmt, p_fmt );
186 id->id = sout_StreamIdAdd( p_sys->p_out, &id->fmt );
192 TAB_APPEND( p_sys->i_id, p_sys->id, id );
197 /*****************************************************************************
199 *****************************************************************************/
200 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
202 VLC_UNUSED(p_stream);
207 /*****************************************************************************
209 *****************************************************************************/
210 static int Send( sout_stream_t *p_stream,
211 sout_stream_id_t *id, block_t *p_buffer )
213 sout_stream_sys_t *p_sys = p_stream->p_sys;
215 return sout_StreamIdSend( p_sys->p_out, id->id, p_buffer );