1 /*****************************************************************************
2 * gather.c: gathering stream output module
3 *****************************************************************************
4 * Copyright (C) 2003-2004 VLC authors and VideoLAN
6 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
34 #include <vlc_block.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 filter", 50 )
46 add_shortcut( "gather" )
47 set_callbacks( Open
, Close
)
50 /*****************************************************************************
52 *****************************************************************************/
53 static void *Add( sout_stream_t
*, const es_format_t
* );
54 static void Del( sout_stream_t
*, void * );
55 static int Send( sout_stream_t
*, void *, block_t
* );
65 } sout_stream_id_sys_t
;
72 static const struct sout_stream_operations ops
= {
73 Add
, Del
, Send
, NULL
, NULL
,
76 /*****************************************************************************
78 *****************************************************************************/
79 static int Open( vlc_object_t
*p_this
)
81 sout_stream_t
*p_stream
= (sout_stream_t
*)p_this
;
82 sout_stream_sys_t
*p_sys
;
84 p_stream
->p_sys
= p_sys
= malloc( sizeof( sout_stream_sys_t
) );
88 vlc_list_init(&p_sys
->ids
);
93 /*****************************************************************************
95 *****************************************************************************/
96 static void Close( vlc_object_t
* p_this
)
98 sout_stream_t
*p_stream
= (sout_stream_t
*)p_this
;
99 sout_stream_sys_t
*p_sys
= p_stream
->p_sys
;
100 sout_stream_id_sys_t
*id
;
102 vlc_list_foreach (id
, &p_sys
->ids
, node
)
104 sout_StreamIdDel( p_stream
->p_next
, id
->id
);
105 es_format_Clean( &id
->fmt
);
112 /*****************************************************************************
114 *****************************************************************************/
115 static void *Add( sout_stream_t
*p_stream
, const es_format_t
*p_fmt
)
117 sout_stream_sys_t
*p_sys
= p_stream
->p_sys
;
118 sout_stream_id_sys_t
*id
;
120 /* search a compatible output */
121 vlc_list_foreach (id
, &p_sys
->ids
, node
)
126 if( id
->fmt
.i_cat
!= p_fmt
->i_cat
|| id
->fmt
.i_codec
!= p_fmt
->i_codec
)
129 if( id
->fmt
.i_cat
== AUDIO_ES
)
131 audio_format_t
*p_a
= &id
->fmt
.audio
;
132 if( p_a
->i_rate
!= p_fmt
->audio
.i_rate
||
133 p_a
->i_channels
!= p_fmt
->audio
.i_channels
||
134 p_a
->i_blockalign
!= p_fmt
->audio
.i_blockalign
)
137 else if( id
->fmt
.i_cat
== VIDEO_ES
)
139 video_format_t
*p_v
= &id
->fmt
.video
;
140 if( p_v
->i_width
!= p_fmt
->video
.i_width
||
141 p_v
->i_height
!= p_fmt
->video
.i_height
)
146 msg_Dbg( p_stream
, "reusing already opened output" );
148 id
->b_streamswap
= true;
152 /* destroy all outputs from the same category */
153 vlc_list_foreach (id
, &p_sys
->ids
, node
)
154 if( !id
->b_used
&& id
->fmt
.i_cat
== p_fmt
->i_cat
)
156 sout_StreamIdDel( p_stream
->p_next
, id
->id
);
157 es_format_Clean( &id
->fmt
);
161 msg_Dbg( p_stream
, "creating new output" );
162 id
= malloc( sizeof( sout_stream_id_sys_t
) );
165 es_format_Copy( &id
->fmt
, p_fmt
);
166 id
->b_streamswap
= false;
168 id
->id
= sout_StreamIdAdd( p_stream
->p_next
, &id
->fmt
);
175 vlc_list_append(&id
->node
, &p_sys
->ids
);
179 /*****************************************************************************
181 *****************************************************************************/
182 static void Del( sout_stream_t
*p_stream
, void *_id
)
184 VLC_UNUSED(p_stream
);
185 sout_stream_id_sys_t
*id
= (sout_stream_id_sys_t
*)_id
;
189 /*****************************************************************************
191 *****************************************************************************/
192 static int Send( sout_stream_t
*p_stream
, void *_id
, block_t
*p_buffer
)
194 sout_stream_id_sys_t
*id
= (sout_stream_id_sys_t
*)_id
;
195 if ( id
->b_streamswap
)
197 id
->b_streamswap
= false;
198 p_buffer
->i_flags
|= BLOCK_FLAG_DISCONTINUITY
;
200 return sout_StreamIdSend( p_stream
->p_next
, id
->id
, p_buffer
);