X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fstream_out%2Fduplicate.c;h=e51d9c169313e9f4f14e4f1cd17586f7d5115156;hb=3682cdd28fed93c43d36116ae443fb50224d27cf;hp=a6c39e3bfc92a1f3ee04c36bbaf09e1734dbead2;hpb=2cb472dba008f7d877ffe6bae9c5575253365282;p=vlc diff --git a/modules/stream_out/duplicate.c b/modules/stream_out/duplicate.c index a6c39e3bfc..e51d9c1693 100644 --- a/modules/stream_out/duplicate.c +++ b/modules/stream_out/duplicate.c @@ -6,29 +6,33 @@ * * Author: Laurent Aimar * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** * Preamble *****************************************************************************/ -#include -#include -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include /***************************************************************************** * Module descriptor @@ -36,23 +40,22 @@ 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", "dup" ) + set_category( CAT_SOUT ) + set_subcategory( SUBCAT_SOUT_STREAM ) + 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 *, +static sout_stream_id_sys_t *Add( sout_stream_t *, const es_format_t * ); +static void Del ( sout_stream_t *, sout_stream_id_sys_t * ); +static int Send( sout_stream_t *, sout_stream_id_sys_t *, block_t* ); struct sout_stream_sys_t @@ -60,17 +63,20 @@ struct sout_stream_sys_t int i_nb_streams; sout_stream_t **pp_streams; + int i_nb_last_streams; + sout_stream_t **pp_last_streams; + int i_nb_select; char **ppsz_select; }; -struct sout_stream_id_t +struct sout_stream_id_sys_t { int i_nb_ids; void **pp_ids; }; -static vlc_bool_t ESSelected( es_format_t *fmt, char *psz_select ); +static bool ESSelected( const es_format_t *fmt, char *psz_select ); /***************************************************************************** * Open: @@ -79,29 +85,33 @@ static int Open( vlc_object_t *p_this ) { sout_stream_t *p_stream = (sout_stream_t*)p_this; sout_stream_sys_t *p_sys; - sout_cfg_t *p_cfg; + config_chain_t *p_cfg; 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_last_streams, p_sys->pp_last_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 ) { if( !strncmp( p_cfg->psz_name, "dst", strlen( "dst" ) ) ) { - sout_stream_t *s; + sout_stream_t *s, *p_last; msg_Dbg( p_stream, " * adding `%s'", p_cfg->psz_value ); - s = sout_StreamNew( p_stream->p_sout, p_cfg->psz_value ); + s = sout_StreamChainNew( p_stream->p_sout, p_cfg->psz_value, + p_stream->p_next, &p_last ); if( s ) { TAB_APPEND( p_sys->i_nb_streams, p_sys->pp_streams, s ); + TAB_APPEND( p_sys->i_nb_last_streams, p_sys->pp_last_streams, + p_last ); TAB_APPEND( p_sys->i_nb_select, p_sys->ppsz_select, NULL ); } } @@ -110,10 +120,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 ) @@ -146,20 +170,12 @@ static void Close( vlc_object_t * p_this ) msg_Dbg( p_stream, "closing a duplication" ); for( i = 0; i < p_sys->i_nb_streams; i++ ) { - sout_StreamDelete( p_sys->pp_streams[i] ); - if( p_sys->ppsz_select[i] ) - { - free( p_sys->ppsz_select[i] ); - } - } - if( p_sys->pp_streams ) - { - free( p_sys->pp_streams ); - } - if( p_sys->ppsz_select ) - { - free( p_sys->ppsz_select ); + sout_StreamChainDelete(p_sys->pp_streams[i], p_sys->pp_last_streams[i]); + free( p_sys->ppsz_select[i] ); } + free( p_sys->pp_streams ); + free( p_sys->pp_last_streams ); + free( p_sys->ppsz_select ); free( p_sys ); } @@ -167,15 +183,17 @@ static void Close( vlc_object_t * p_this ) /***************************************************************************** * Add: *****************************************************************************/ -static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt ) +static sout_stream_id_sys_t * Add( sout_stream_t *p_stream, const es_format_t *p_fmt ) { sout_stream_sys_t *p_sys = p_stream->p_sys; - sout_stream_id_t *id; + sout_stream_id_sys_t *id; int i_stream, i_valid_streams = 0; - id = malloc( sizeof( sout_stream_id_t ) ); - id->i_nb_ids = 0; - id->pp_ids = NULL; + id = malloc( sizeof( sout_stream_id_sys_t ) ); + 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 ); @@ -188,7 +206,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 ); @@ -221,7 +239,7 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt ) /***************************************************************************** * Del: *****************************************************************************/ -static int Del( sout_stream_t *p_stream, sout_stream_id_t *id ) +static void Del( sout_stream_t *p_stream, sout_stream_id_sys_t *id ) { sout_stream_sys_t *p_sys = p_stream->p_sys; int i_stream; @@ -231,19 +249,18 @@ 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] ); } } free( id->pp_ids ); free( id ); - return VLC_SUCCESS; } /***************************************************************************** * Send: *****************************************************************************/ -static int Send( sout_stream_t *p_stream, sout_stream_id_t *id, +static int Send( sout_stream_t *p_stream, sout_stream_id_sys_t *id, block_t *p_buffer ) { sout_stream_sys_t *p_sys = p_stream->p_sys; @@ -259,23 +276,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 { @@ -290,34 +305,24 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_t *id, /***************************************************************************** * Divers *****************************************************************************/ -static vlc_bool_t NumInRange( char *psz_range, int i_num ) +static bool NumInRange( const char *psz_range, int i_num ) { - char *psz = strchr( psz_range, '-' ); - char *end; - int i_start, i_stop; - - if( psz ) - { - i_start = strtol( psz_range, &end, 0 ); - if( end == psz_range ) i_start = i_num; - - i_stop = strtol( psz, &end, 0 ); - if( end == psz_range ) i_stop = i_num; - } - else - { - i_start = i_stop = strtol( psz_range, NULL, 0 ); - } - - return i_start <= i_num && i_num <= i_stop ? VLC_TRUE : VLC_FALSE; + int beginRange, endRange; + int res = sscanf(psz_range, "%d-%d", &beginRange, &endRange); + if (res == 0) + return false; + else if (res == 1) + return beginRange == i_num; + return (i_num >= beginRange && i_num <= endRange) + || (beginRange > endRange && (i_num <= beginRange && i_num >= endRange)); } -static vlc_bool_t ESSelected( es_format_t *fmt, char *psz_select ) +static bool ESSelected( const es_format_t *fmt, char *psz_select ) { char *psz_dup; char *psz; - /* We have tree state variable : no tested (-1), failed(0), succeed(1) */ + /* We have tri-state variable : no tested (-1), failed(0), succeed(1) */ int i_cat = -1; int i_es = -1; int i_prgm= -1; @@ -325,10 +330,12 @@ static vlc_bool_t ESSelected( es_format_t *fmt, char *psz_select ) /* If empty all es are selected */ if( psz_select == NULL || *psz_select == '\0' ) { - return VLC_TRUE; + 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: @@ -451,7 +458,7 @@ static vlc_bool_t ESSelected( es_format_t *fmt, char *psz_select ) if( i_cat == 1 || i_es == 1 || i_prgm == 1 ) { - return VLC_TRUE; + return true; } - return VLC_FALSE; + return false; }