X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fstream_out%2Fduplicate.c;h=d1939fcb7f86e87ce6ecdb3fce8385075e8dd249;hb=55bd6c18babd47583ba4a1a3d64834c5d1f38565;hp=a402299b1c38e6744b908e1b10f2c512ed91c675;hpb=27d483e9ef7a451397d7857251c8d67097661f1d;p=vlc diff --git a/modules/stream_out/duplicate.c b/modules/stream_out/duplicate.c index a402299b1c..d1939fcb7f 100644 --- a/modules/stream_out/duplicate.c +++ b/modules/stream_out/duplicate.c @@ -29,7 +29,7 @@ # include "config.h" #endif -#include +#include #include #include #include @@ -40,15 +40,15 @@ static int Open ( vlc_object_t * ); static void Close ( vlc_object_t * ); -vlc_module_begin(); - set_description( _("Duplicate stream output") ); - set_capability( "sout stream", 50 ); - add_shortcut( "duplicate" ); - add_shortcut( "dup" ); - set_category( CAT_SOUT ); - set_subcategory( SUBCAT_SOUT_STREAM ); - set_callbacks( Open, Close ); -vlc_module_end(); +vlc_module_begin () + set_description( N_("Duplicate stream output") ) + set_capability( "sout stream", 50 ) + add_shortcut( "duplicate" ) + add_shortcut( "dup" ) + set_category( CAT_SOUT ) + set_subcategory( SUBCAT_SOUT_STREAM ) + set_callbacks( Open, Close ) +vlc_module_end () /***************************************************************************** @@ -88,11 +88,11 @@ static int Open( vlc_object_t *p_this ) msg_Dbg( p_stream, "creating 'duplicate'" ); p_sys = malloc( sizeof( sout_stream_sys_t ) ); + if( !p_sys ) + return VLC_ENOMEM; - p_sys->i_nb_streams = 0; - p_sys->pp_streams = NULL; - p_sys->i_nb_select = 0; - p_sys->ppsz_select = NULL; + TAB_INIT( p_sys->i_nb_streams, p_sys->pp_streams ); + TAB_INIT( p_sys->i_nb_select, p_sys->ppsz_select ); for( p_cfg = p_stream->p_cfg; p_cfg != NULL; p_cfg = p_cfg->p_next ) { @@ -114,10 +114,24 @@ static int Open( vlc_object_t *p_this ) char *psz = p_cfg->psz_value; if( p_sys->i_nb_select > 0 && psz && *psz ) { - msg_Dbg( p_stream, " * apply selection %s", psz ); - p_sys->ppsz_select[p_sys->i_nb_select - 1] = strdup( psz ); + char **ppsz_select = &p_sys->ppsz_select[p_sys->i_nb_select - 1]; + + if( *ppsz_select ) + { + msg_Err( p_stream, " * ignore selection `%s' (it already has `%s')", + psz, *ppsz_select ); + } + else + { + msg_Dbg( p_stream, " * apply selection `%s'", psz ); + *ppsz_select = strdup( psz ); + } } } + else + { + msg_Err( p_stream, " * ignore unknown option `%s'", p_cfg->psz_name ); + } } if( p_sys->i_nb_streams == 0 ) @@ -169,8 +183,10 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt ) int i_stream, i_valid_streams = 0; id = malloc( sizeof( sout_stream_id_t ) ); - id->i_nb_ids = 0; - id->pp_ids = NULL; + if( !id ) + return NULL; + + TAB_INIT( id->i_nb_ids, id->pp_ids ); msg_Dbg( p_stream, "duplicated a new stream codec=%4.4s (es=%d group=%d)", (char*)&p_fmt->i_codec, p_fmt->i_id, p_fmt->i_group ); @@ -183,7 +199,7 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt ) { sout_stream_t *out = p_sys->pp_streams[i_stream]; - id_new = (void*)out->pf_add( out, p_fmt ); + id_new = (void*)sout_StreamIdAdd( out, p_fmt ); if( id_new ) { msg_Dbg( p_stream, " - added for output %d", i_stream ); @@ -226,7 +242,7 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id ) if( id->pp_ids[i_stream] ) { sout_stream_t *out = p_sys->pp_streams[i_stream]; - out->pf_del( out, id->pp_ids[i_stream] ); + sout_StreamIdDel( out, id->pp_ids[i_stream] ); } } @@ -254,23 +270,21 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_t *id, for( i_stream = 0; i_stream < p_sys->i_nb_streams - 1; i_stream++ ) { - block_t *p_dup; p_dup_stream = p_sys->pp_streams[i_stream]; if( id->pp_ids[i_stream] ) { - p_dup = block_Duplicate( p_buffer ); + block_t *p_dup = block_Duplicate( p_buffer ); - p_dup_stream->pf_send( p_dup_stream, id->pp_ids[i_stream], - p_dup ); + if( p_dup ) + sout_StreamIdSend( p_dup_stream, id->pp_ids[i_stream], p_dup ); } } if( i_stream < p_sys->i_nb_streams && id->pp_ids[i_stream] ) { p_dup_stream = p_sys->pp_streams[i_stream]; - p_dup_stream->pf_send( p_dup_stream, id->pp_ids[i_stream], - p_buffer ); + sout_StreamIdSend( p_dup_stream, id->pp_ids[i_stream], p_buffer ); } else { @@ -323,7 +337,9 @@ static bool ESSelected( es_format_t *fmt, char *psz_select ) return true; } psz_dup = strdup( psz_select ); - psz = psz_dup; + if( !psz_dup ) + return false; + psz = psz_dup; /* If non empty, parse the selection: * We have selection[,selection[,..]] where following selection are recognized: