X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fstream_out%2Fgather.c;h=1a266551f9d0ee7796f9027602770b703c41977d;hb=6fad8bffb1cdfe90c495eb19cc680f4120ecc657;hp=0c8db105fdada1f46d9a3700f45e285bc6250174;hpb=58888942c16299047f0e3022cb57bcd7842bff82;p=vlc diff --git a/modules/stream_out/gather.c b/modules/stream_out/gather.c index 0c8db105fd..1a266551f9 100644 --- a/modules/stream_out/gather.c +++ b/modules/stream_out/gather.c @@ -24,9 +24,13 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include #include #include @@ -36,24 +40,23 @@ static int Open ( vlc_object_t * ); static void Close ( vlc_object_t * ); -vlc_module_begin(); - set_description( _("Gathering stream output") ); - set_capability( "sout stream", 50 ); - add_shortcut( "gather" ); - set_callbacks( Open, Close ); -vlc_module_end(); +vlc_module_begin () + set_description( N_("Gathering stream output") ) + set_capability( "sout stream", 50 ) + add_shortcut( "gather" ) + set_callbacks( Open, Close ) +vlc_module_end () /***************************************************************************** * Exported prototypes *****************************************************************************/ static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * ); static int Del ( sout_stream_t *, sout_stream_id_t * ); -static int Send( sout_stream_t *, sout_stream_id_t *, - block_t* ); +static int Send( sout_stream_t *, sout_stream_id_t *, block_t* ); struct sout_stream_id_t { - vlc_bool_t b_used; + bool b_used; es_format_t fmt; void *id; @@ -61,8 +64,6 @@ struct sout_stream_id_t struct sout_stream_sys_t { - sout_stream_t *p_out; - int i_id; sout_stream_id_t **id; }; @@ -76,19 +77,20 @@ static int Open( vlc_object_t *p_this ) sout_stream_sys_t *p_sys; p_stream->p_sys = p_sys = malloc( sizeof( sout_stream_sys_t ) ); - p_sys->p_out = sout_StreamNew( p_stream->p_sout, p_stream->psz_next ); - if( p_sys->p_out == NULL ) + if( p_sys == NULL ) + return VLC_EGENERIC; + + if( !p_stream->p_next ) { free( p_sys ); return VLC_EGENERIC; } - p_sys->i_id = 0; - p_sys->id = NULL; - p_stream->pf_add = Add; p_stream->pf_del = Del; p_stream->pf_send = Send; + TAB_INIT( p_sys->i_id, p_sys->id ); + return VLC_SUCCESS; } @@ -103,12 +105,14 @@ static void Close( vlc_object_t * p_this ) for( i = 0; i < p_sys->i_id; i++ ) { - p_sys->p_out->pf_del( p_sys->p_out, p_sys->id[i]->id ); - free( p_sys->id[i] ); + sout_stream_id_t *id = p_sys->id[i]; + + sout_StreamIdDel( p_stream->p_next, id->id ); + es_format_Clean( &id->fmt ); + free( id ); } - free( p_sys->id ); + TAB_CLEAN( p_sys->i_id, p_sys->id ); - sout_StreamDelete( p_sys->p_out ); free( p_sys ); } @@ -125,21 +129,32 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt ) for( i = 0; i < p_sys->i_id; i++ ) { id = p_sys->id[i]; - if( !id->b_used && - id->fmt.i_cat == p_fmt->i_cat && - id->fmt.i_codec == p_fmt->i_codec && - ( ( id->fmt.i_cat == AUDIO_ES && - id->fmt.audio.i_rate == p_fmt->audio.i_rate && - id->fmt.audio.i_channels == p_fmt->audio.i_channels && - id->fmt.audio.i_blockalign == p_fmt->audio.i_blockalign ) || - ( id->fmt.i_cat == VIDEO_ES && - id->fmt.video.i_width == p_fmt->video.i_width && - id->fmt.video.i_height == p_fmt->video.i_height ) ) ) + if( id->b_used ) + continue; + + if( id->fmt.i_cat != p_fmt->i_cat || id->fmt.i_codec != p_fmt->i_codec ) + continue; + + if( id->fmt.i_cat == AUDIO_ES ) { - msg_Dbg( p_stream, "reusing already opened output" ); - id->b_used = VLC_TRUE; - return id; + audio_format_t *p_a = &id->fmt.audio; + if( p_a->i_rate != p_fmt->audio.i_rate || + p_a->i_channels != p_fmt->audio.i_channels || + p_a->i_blockalign != p_fmt->audio.i_blockalign ) + continue; } + else if( id->fmt.i_cat == VIDEO_ES ) + { + video_format_t *p_v = &id->fmt.video; + if( p_v->i_width != p_fmt->video.i_width || + p_v->i_height != p_fmt->video.i_height ) + continue; + } + + /* */ + msg_Dbg( p_stream, "reusing already opened output" ); + id->b_used = true; + return id; } /* destroy all outputs from the same category */ @@ -149,7 +164,8 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt ) if( !id->b_used && id->fmt.i_cat == p_fmt->i_cat ) { TAB_REMOVE( p_sys->i_id, p_sys->id, id ); - p_sys->p_out->pf_del( p_sys->p_out, id ); + sout_StreamIdDel( p_stream->p_next, id->id ); + es_format_Clean( &id->fmt ); free( id ); i = 0; @@ -157,13 +173,13 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt ) } } - id = malloc( sizeof( sout_stream_id_t ) ); msg_Dbg( p_stream, "creating new output" ); - memcpy( &id->fmt, p_fmt, sizeof( es_format_t ) ); - id->fmt.i_extra = 0; - id->fmt.p_extra = NULL; - id->b_used = VLC_TRUE; - id->id = p_sys->p_out->pf_add( p_sys->p_out, p_fmt ); + id = malloc( sizeof( sout_stream_id_t ) ); + if( id == NULL ) + return NULL; + es_format_Copy( &id->fmt, p_fmt ); + id->b_used = true; + id->id = sout_StreamIdAdd( p_stream->p_next, &id->fmt ); if( id->id == NULL ) { free( id ); @@ -179,7 +195,8 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt ) *****************************************************************************/ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id ) { - id->b_used = VLC_FALSE; + VLC_UNUSED(p_stream); + id->b_used = false; return VLC_SUCCESS; } @@ -189,7 +206,5 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id ) static int Send( sout_stream_t *p_stream, sout_stream_id_t *id, block_t *p_buffer ) { - sout_stream_sys_t *p_sys = p_stream->p_sys; - - return p_sys->p_out->pf_send( p_sys->p_out, id->id, p_buffer ); + return sout_StreamIdSend( p_stream->p_next, id->id, p_buffer ); }