1 /*****************************************************************************
2 * stream_output.c : stream output module
3 *****************************************************************************
4 * Copyright (C) 2002-2004 the VideoLAN team
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * Laurent Aimar <fenrir@via.ecp.fr>
9 * Eric Petit <titer@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
29 #include <stdlib.h> /* free() */
30 #include <stdio.h> /* sprintf() */
31 #include <string.h> /* strerror() */
35 #include <vlc/input.h>
40 /*****************************************************************************
42 *****************************************************************************/
43 static void sout_CfgDestroy( sout_cfg_t * );
45 #define sout_stream_url_to_chain( p, s ) \
46 _sout_stream_url_to_chain( VLC_OBJECT(p), s )
47 static char *_sout_stream_url_to_chain( vlc_object_t *, char * );
61 /* mrl_Parse: parse psz_mrl and fill p_mrl */
62 static int mrl_Parse( mrl_t *p_mrl, char *psz_mrl );
63 /* mrl_Clean: clean p_mrl after a call to mrl_Parse */
64 static void mrl_Clean( mrl_t *p_mrl );
66 #define FREE( p ) if( p ) { free( p ); (p) = NULL; }
68 /*****************************************************************************
69 * sout_NewInstance: creates a new stream output instance
70 *****************************************************************************/
71 sout_instance_t *__sout_NewInstance( vlc_object_t *p_parent, char * psz_dest )
73 sout_instance_t *p_sout;
77 if( var_Get( p_parent, "sout-keep", &keep ) < 0 )
79 msg_Warn( p_parent, "cannot get sout-keep value" );
80 keep.b_bool = VLC_FALSE;
84 if( ( p_sout = vlc_object_find( p_parent, VLC_OBJECT_SOUT,
85 FIND_ANYWHERE ) ) != NULL )
87 if( !strcmp( p_sout->psz_sout, psz_dest ) )
89 msg_Dbg( p_parent, "sout keep : reusing sout" );
90 msg_Dbg( p_parent, "sout keep : you probably want to use "
91 "gather stream_out" );
92 vlc_object_detach( p_sout );
93 vlc_object_attach( p_sout, p_parent );
94 vlc_object_release( p_sout );
99 msg_Dbg( p_parent, "sout keep : destroying unusable sout" );
100 vlc_object_release( p_sout );
101 sout_DeleteInstance( p_sout );
105 else if( !keep.b_bool )
107 while( ( p_sout = vlc_object_find( p_parent, VLC_OBJECT_SOUT,
108 FIND_PARENT ) ) != NULL )
110 msg_Dbg( p_parent, "sout keep : destroying old sout" );
111 vlc_object_release( p_sout );
112 sout_DeleteInstance( p_sout );
116 /* *** Allocate descriptor *** */
117 p_sout = vlc_object_create( p_parent, VLC_OBJECT_SOUT );
120 msg_Err( p_parent, "out of memory" );
124 /* *** init descriptor *** */
125 p_sout->psz_sout = strdup( psz_dest );
126 p_sout->p_meta = NULL;
127 p_sout->i_out_pace_nocontrol = 0;
128 p_sout->p_sys = NULL;
130 vlc_mutex_init( p_sout, &p_sout->lock );
131 if( psz_dest && psz_dest[0] == '#' )
133 p_sout->psz_chain = strdup( &psz_dest[1] );
137 p_sout->psz_chain = sout_stream_url_to_chain( p_sout, psz_dest );
138 msg_Dbg( p_sout, "using sout chain=`%s'", p_sout->psz_chain );
140 p_sout->p_stream = NULL;
142 /* attach it for inherit */
143 vlc_object_attach( p_sout, p_parent );
145 /* Create statistics */
146 stats_Create( p_parent, "sout_sent_packets", STATS_SOUT_SENT_PACKETS,
147 VLC_VAR_INTEGER, STATS_COUNTER );
148 stats_Create( p_parent, "sout_sent_bytes", STATS_SOUT_SENT_BYTES,
149 VLC_VAR_INTEGER, STATS_COUNTER );
150 stats_Create( p_parent, "sout_send_bitrate", STATS_SOUT_SEND_BITRATE,
151 VLC_VAR_FLOAT, STATS_DERIVATIVE );
152 p_counter = stats_CounterGet( p_parent, p_parent->i_object_id,
153 STATS_SOUT_SEND_BITRATE );
154 if( p_counter) p_counter->update_interval = 1000000;
156 p_sout->p_stream = sout_StreamNew( p_sout, p_sout->psz_chain );
158 if( p_sout->p_stream == NULL )
160 msg_Err( p_sout, "stream chained failed for `%s'", p_sout->psz_chain );
162 FREE( p_sout->psz_sout );
163 FREE( p_sout->psz_chain );
165 vlc_object_detach( p_sout );
166 vlc_object_destroy( p_sout );
172 /*****************************************************************************
173 * sout_DeleteInstance: delete a previously allocated instance
174 *****************************************************************************/
175 void sout_DeleteInstance( sout_instance_t * p_sout )
178 vlc_object_detach( p_sout );
180 /* remove the stream out chain */
181 sout_StreamDelete( p_sout->p_stream );
183 /* *** free all string *** */
184 FREE( p_sout->psz_sout );
185 FREE( p_sout->psz_chain );
190 vlc_meta_Delete( p_sout->p_meta );
193 vlc_mutex_destroy( &p_sout->lock );
195 /* *** free structure *** */
196 vlc_object_destroy( p_sout );
199 /*****************************************************************************
201 *****************************************************************************/
202 sout_packetizer_input_t *sout_InputNew( sout_instance_t *p_sout,
205 sout_packetizer_input_t *p_input;
207 msg_Dbg( p_sout, "adding a new input" );
209 /* *** create a packetizer input *** */
210 p_input = malloc( sizeof( sout_packetizer_input_t ) );
211 p_input->p_sout = p_sout;
212 p_input->p_fmt = p_fmt;
214 if( p_fmt->i_codec == VLC_FOURCC( 'n', 'u', 'l', 'l' ) )
216 vlc_object_release( p_sout );
220 /* *** add it to the stream chain */
221 vlc_mutex_lock( &p_sout->lock );
222 p_input->id = p_sout->p_stream->pf_add( p_sout->p_stream, p_fmt );
223 vlc_mutex_unlock( &p_sout->lock );
225 if( p_input->id == NULL )
234 /*****************************************************************************
236 *****************************************************************************/
237 int sout_InputDelete( sout_packetizer_input_t *p_input )
239 sout_instance_t *p_sout = p_input->p_sout;
241 msg_Dbg( p_sout, "removing an input" );
243 if( p_input->p_fmt->i_codec != VLC_FOURCC( 'n', 'u', 'l', 'l' ) )
245 vlc_mutex_lock( &p_sout->lock );
246 p_sout->p_stream->pf_del( p_sout->p_stream, p_input->id );
247 vlc_mutex_unlock( &p_sout->lock );
252 return( VLC_SUCCESS);
255 /*****************************************************************************
257 *****************************************************************************/
258 int sout_InputSendBuffer( sout_packetizer_input_t *p_input,
261 sout_instance_t *p_sout = p_input->p_sout;
264 if( p_input->p_fmt->i_codec == VLC_FOURCC( 'n', 'u', 'l', 'l' ) )
266 block_Release( p_buffer );
269 if( p_buffer->i_dts <= 0 )
271 msg_Warn( p_sout, "trying to send non-dated packet to stream output!");
272 block_Release( p_buffer );
276 vlc_mutex_lock( &p_sout->lock );
277 i_ret = p_sout->p_stream->pf_send( p_sout->p_stream,
278 p_input->id, p_buffer );
279 vlc_mutex_unlock( &p_sout->lock );
284 /*****************************************************************************
285 * sout_AccessOutNew: allocate a new access out
286 *****************************************************************************/
287 sout_access_out_t *sout_AccessOutNew( sout_instance_t *p_sout,
288 char *psz_access, char *psz_name )
290 sout_access_out_t *p_access;
293 if( !( p_access = vlc_object_create( p_sout,
294 sizeof( sout_access_out_t ) ) ) )
296 msg_Err( p_sout, "out of memory" );
300 psz_next = sout_CfgCreate( &p_access->psz_access, &p_access->p_cfg,
306 p_access->psz_name = strdup( psz_name ? psz_name : "" );
307 p_access->p_sout = p_sout;
308 p_access->p_sys = NULL;
309 p_access->pf_seek = NULL;
310 p_access->pf_read = NULL;
311 p_access->pf_write = NULL;
312 p_access->p_module = NULL;
314 p_access->i_writes = 0;
315 p_access->i_sent_bytes = 0;
317 vlc_object_attach( p_access, p_sout );
320 module_Need( p_access, "sout access", p_access->psz_access, VLC_TRUE );
322 if( !p_access->p_module )
324 free( p_access->psz_access );
325 free( p_access->psz_name );
326 vlc_object_detach( p_access );
327 vlc_object_destroy( p_access );
333 /*****************************************************************************
334 * sout_AccessDelete: delete an access out
335 *****************************************************************************/
336 void sout_AccessOutDelete( sout_access_out_t *p_access )
338 vlc_object_detach( p_access );
339 if( p_access->p_module )
341 module_Unneed( p_access, p_access->p_module );
343 free( p_access->psz_access );
345 sout_CfgDestroy( p_access->p_cfg );
347 free( p_access->psz_name );
349 vlc_object_destroy( p_access );
352 /*****************************************************************************
354 *****************************************************************************/
355 int sout_AccessOutSeek( sout_access_out_t *p_access, off_t i_pos )
357 return p_access->pf_seek( p_access, i_pos );
360 /*****************************************************************************
362 *****************************************************************************/
363 int sout_AccessOutRead( sout_access_out_t *p_access, block_t *p_buffer )
365 return( p_access->pf_read ?
366 p_access->pf_read( p_access, p_buffer ) : VLC_EGENERIC );
369 /*****************************************************************************
371 *****************************************************************************/
372 int sout_AccessOutWrite( sout_access_out_t *p_access, block_t *p_buffer )
375 p_access->i_writes++;
376 p_access->i_sent_bytes += p_buffer->i_buffer;
377 if( p_access->p_libvlc->b_stats && p_access->i_writes % 30 == 0 )
379 /* Access_out -> sout_instance -> input_thread_t */
380 input_thread_t *p_input =
381 (input_thread_t *)vlc_object_find( p_access, VLC_OBJECT_INPUT,
385 stats_UpdateInteger( p_input, STATS_SOUT_SENT_PACKETS, 30, NULL );
386 stats_UpdateInteger( p_input, STATS_SOUT_SENT_BYTES,
387 p_access->i_sent_bytes, &i_total );
388 stats_UpdateFloat( p_input, STATS_SOUT_SEND_BITRATE, (float)i_total,
390 p_access->i_sent_bytes = 0;
391 vlc_object_release( p_input );
394 return p_access->pf_write( p_access, p_buffer );
397 /*****************************************************************************
398 * sout_MuxNew: create a new mux
399 *****************************************************************************/
400 sout_mux_t * sout_MuxNew( sout_instance_t *p_sout, char *psz_mux,
401 sout_access_out_t *p_access )
406 p_mux = vlc_object_create( p_sout, sizeof( sout_mux_t ) );
409 msg_Err( p_sout, "out of memory" );
413 p_mux->p_sout = p_sout;
414 psz_next = sout_CfgCreate( &p_mux->psz_mux, &p_mux->p_cfg, psz_mux );
415 if( psz_next ) free( psz_next );
417 p_mux->p_access = p_access;
418 p_mux->pf_control = NULL;
419 p_mux->pf_addstream = NULL;
420 p_mux->pf_delstream = NULL;
421 p_mux->pf_mux = NULL;
422 p_mux->i_nb_inputs = 0;
423 p_mux->pp_inputs = NULL;
426 p_mux->p_module = NULL;
428 p_mux->b_add_stream_any_time = VLC_FALSE;
429 p_mux->b_waiting_stream = VLC_TRUE;
430 p_mux->i_add_stream_start = -1;
432 vlc_object_attach( p_mux, p_sout );
435 module_Need( p_mux, "sout mux", p_mux->psz_mux, VLC_TRUE );
437 if( p_mux->p_module == NULL )
439 FREE( p_mux->psz_mux );
441 vlc_object_detach( p_mux );
442 vlc_object_destroy( p_mux );
446 /* *** probe mux capacity *** */
447 if( p_mux->pf_control )
449 int b_answer = VLC_FALSE;
451 if( sout_MuxControl( p_mux, MUX_CAN_ADD_STREAM_WHILE_MUXING,
454 b_answer = VLC_FALSE;
459 msg_Dbg( p_sout, "muxer support adding stream at any time" );
460 p_mux->b_add_stream_any_time = VLC_TRUE;
461 p_mux->b_waiting_stream = VLC_FALSE;
463 /* If we control the output pace then it's better to wait before
464 * starting muxing (generates better streams/files). */
465 if( !p_sout->i_out_pace_nocontrol )
469 else if( sout_MuxControl( p_mux, MUX_GET_ADD_STREAM_WAIT,
472 b_answer = VLC_FALSE;
477 msg_Dbg( p_sout, "muxer prefers waiting for all ES before "
479 p_mux->b_waiting_stream = VLC_TRUE;
487 /*****************************************************************************
489 *****************************************************************************/
490 void sout_MuxDelete( sout_mux_t *p_mux )
492 vlc_object_detach( p_mux );
493 if( p_mux->p_module )
495 module_Unneed( p_mux, p_mux->p_module );
497 free( p_mux->psz_mux );
499 sout_CfgDestroy( p_mux->p_cfg );
501 vlc_object_destroy( p_mux );
504 /*****************************************************************************
506 *****************************************************************************/
507 sout_input_t *sout_MuxAddStream( sout_mux_t *p_mux, es_format_t *p_fmt )
509 sout_input_t *p_input;
511 if( !p_mux->b_add_stream_any_time && !p_mux->b_waiting_stream )
513 msg_Err( p_mux, "cannot add a new stream (unsupported while muxing "
514 "for this format)" );
518 msg_Dbg( p_mux, "adding a new input" );
520 /* create a new sout input */
521 p_input = malloc( sizeof( sout_input_t ) );
522 p_input->p_sout = p_mux->p_sout;
523 p_input->p_fmt = p_fmt;
524 p_input->p_fifo = block_FifoNew( p_mux->p_sout );
525 p_input->p_sys = NULL;
527 TAB_APPEND( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input );
528 if( p_mux->pf_addstream( p_mux, p_input ) < 0 )
530 msg_Err( p_mux, "cannot add this stream" );
531 TAB_REMOVE( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input );
532 block_FifoRelease( p_input->p_fifo );
540 /*****************************************************************************
541 * sout_MuxDeleteStream:
542 *****************************************************************************/
543 void sout_MuxDeleteStream( sout_mux_t *p_mux, sout_input_t *p_input )
547 if( p_mux->b_waiting_stream && p_input->p_fifo->i_depth > 0 )
549 /* We stop waiting, and call the muxer for taking care of the data
550 * before we remove this es */
551 p_mux->b_waiting_stream = VLC_FALSE;
552 p_mux->pf_mux( p_mux );
555 TAB_FIND( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input, i_index );
558 if( p_mux->pf_delstream( p_mux, p_input ) < 0 )
560 msg_Err( p_mux, "cannot del this stream from mux" );
563 /* remove the entry */
564 TAB_REMOVE( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input );
566 if( p_mux->i_nb_inputs == 0 )
568 msg_Warn( p_mux, "no more input stream for this mux" );
571 block_FifoRelease( p_input->p_fifo );
576 /*****************************************************************************
577 * sout_MuxSendBuffer:
578 *****************************************************************************/
579 void sout_MuxSendBuffer( sout_mux_t *p_mux, sout_input_t *p_input,
582 block_FifoPut( p_input->p_fifo, p_buffer );
584 if( p_mux->p_sout->i_out_pace_nocontrol )
586 mtime_t current_date = mdate();
587 if ( current_date > p_buffer->i_dts )
588 msg_Warn( p_mux, "late buffer for mux input ("I64Fd")",
589 current_date - p_buffer->i_dts );
592 if( p_mux->b_waiting_stream )
594 if( p_mux->i_add_stream_start < 0 )
596 p_mux->i_add_stream_start = p_buffer->i_dts;
599 if( p_mux->i_add_stream_start >= 0 &&
600 p_mux->i_add_stream_start + I64C(1500000) < p_buffer->i_dts )
602 /* Wait until we have more than 1.5 seconds worth of data
603 * before start muxing */
604 p_mux->b_waiting_stream = VLC_FALSE;
611 p_mux->pf_mux( p_mux );
614 /*****************************************************************************
616 *****************************************************************************/
617 static int mrl_Parse( mrl_t *p_mrl, char *psz_mrl )
619 char * psz_dup = strdup( psz_mrl );
620 char * psz_parser = psz_dup;
621 char * psz_access = "";
623 char * psz_name = "";
625 /* *** first parse psz_dest */
626 while( *psz_parser && *psz_parser != ':' )
628 if( *psz_parser == '{' )
630 while( *psz_parser && *psz_parser != '}' )
644 #if defined( WIN32 ) || defined( UNDER_CE )
645 if( psz_parser - psz_dup == 1 )
647 /* msg_Warn( p_sout, "drive letter %c: found in source string",
655 psz_access = psz_way = "";
660 *psz_parser++ = '\0';
662 /* let's skip '//' */
663 if( psz_parser[0] == '/' && psz_parser[1] == '/' )
668 psz_name = psz_parser ;
670 /* Come back to parse the access and mux plug-ins */
671 psz_parser = psz_dup;
678 else if( *psz_parser == '/' )
686 psz_access = psz_parser;
688 while( *psz_parser && *psz_parser != '/' )
690 if( *psz_parser == '{' )
692 while( *psz_parser && *psz_parser != '}' )
707 if( *psz_parser == '/' )
709 *psz_parser++ = '\0';
720 psz_way = psz_parser;
724 p_mrl->psz_access = strdup( psz_access );
725 p_mrl->psz_way = strdup( psz_way );
726 p_mrl->psz_name = strdup( psz_name );
729 return( VLC_SUCCESS );
733 /* mrl_Clean: clean p_mrl after a call to mrl_Parse */
734 static void mrl_Clean( mrl_t *p_mrl )
736 FREE( p_mrl->psz_access );
737 FREE( p_mrl->psz_way );
738 FREE( p_mrl->psz_name );
742 /****************************************************************************
743 ****************************************************************************
747 ****************************************************************************
748 ****************************************************************************/
750 /* create a complete chain */
752 module{option=*:option=*}[:module{option=*:...}]
756 * parse module{options=str, option="str "}:
757 * return a pointer on the rest
758 * XXX: psz_chain is modified
760 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
761 #define SKIPTRAILINGSPACE( p, e ) \
762 { while( e > p && ( *(e-1) == ' ' || *(e-1) == '\t' ) ) e--; }
764 /* go accross " " and { } */
765 static char *_get_chain_end( char *str )
773 if( !*p || *p == ',' || *p == '}' ) return p;
775 if( *p != '{' && *p != '"' && *p != '\'' )
781 if( *p == '{' ) c = '}';
789 if( *p == c ) return ++p;
790 else if( *p == '{' && c == '}' ) p = _get_chain_end( p );
796 char *sout_CfgCreate( char **ppsz_name, sout_cfg_t **pp_cfg, char *psz_chain )
798 sout_cfg_t *p_cfg = NULL;
804 if( !p ) return NULL;
808 while( *p && *p != '{' && *p != ':' && *p != ' ' && *p != '\t' ) p++;
810 if( p == psz_chain ) return NULL;
812 *ppsz_name = strndup( psz_chain, p - psz_chain );
830 while( *p && *p != '=' && *p != ',' && *p != '{' && *p != '}' &&
831 *p != ' ' && *p != '\t' ) p++;
833 /* fprintf( stderr, "name=%s - rest=%s\n", psz_name, p ); */
836 fprintf( stderr, "invalid options (empty)" );
840 cfg.psz_name = strndup( psz_name, p - psz_name );
844 if( *p == '=' || *p == '{' )
847 vlc_bool_t b_keep_brackets = (*p == '{');
851 end = _get_chain_end( p );
854 cfg.psz_value = NULL;
858 /* Skip heading and trailing spaces.
859 * This ain't necessary but will avoid simple
866 cfg.psz_value = NULL;
870 if( *p == '\'' || *p == '"' ||
871 ( !b_keep_brackets && *p == '{' ) )
875 if( *(end-1) != '\'' && *(end-1) == '"' )
876 SKIPTRAILINGSPACE( p, end );
878 if( end - 1 <= p ) cfg.psz_value = NULL;
879 else cfg.psz_value = strndup( p, end -1 - p );
883 SKIPTRAILINGSPACE( p, end );
884 if( end <= p ) cfg.psz_value = NULL;
885 else cfg.psz_value = strndup( p, end - p );
894 cfg.psz_value = NULL;
900 p_cfg->p_next = malloc( sizeof( sout_cfg_t ) );
901 memcpy( p_cfg->p_next, &cfg, sizeof( sout_cfg_t ) );
903 p_cfg = p_cfg->p_next;
907 p_cfg = malloc( sizeof( sout_cfg_t ) );
908 memcpy( p_cfg, &cfg, sizeof( sout_cfg_t ) );
923 if( *p == ':' ) return( strdup( p + 1 ) );
928 static void sout_CfgDestroy( sout_cfg_t *p_cfg )
930 while( p_cfg != NULL )
934 p_next = p_cfg->p_next;
936 FREE( p_cfg->psz_name );
937 FREE( p_cfg->psz_value );
944 void __sout_CfgParse( vlc_object_t *p_this, char *psz_prefix,
945 const char **ppsz_options, sout_cfg_t *cfg )
951 /* First, var_Create all variables */
952 for( i = 0; ppsz_options[i] != NULL; i++ )
954 asprintf( &psz_name, "%s%s", psz_prefix,
955 *ppsz_options[i] == '*' ? &ppsz_options[i][1] : ppsz_options[i] );
957 i_type = config_GetType( p_this, psz_name );
959 var_Create( p_this, psz_name, i_type | VLC_VAR_DOINHERIT );
963 /* Now parse options and set value */
964 if( psz_prefix == NULL ) psz_prefix = "";
969 vlc_bool_t b_yes = VLC_TRUE;
970 vlc_bool_t b_once = VLC_FALSE;
971 module_config_t *p_conf;
973 if( cfg->psz_name == NULL || *cfg->psz_name == '\0' )
978 for( i = 0; ppsz_options[i] != NULL; i++ )
980 if( !strcmp( ppsz_options[i], cfg->psz_name ) )
984 if( ( !strncmp( cfg->psz_name, "no-", 3 ) &&
985 !strcmp( ppsz_options[i], cfg->psz_name + 3 ) ) ||
986 ( !strncmp( cfg->psz_name, "no", 2 ) &&
987 !strcmp( ppsz_options[i], cfg->psz_name + 2 ) ) )
993 if( *ppsz_options[i] == '*' &&
994 !strcmp( &ppsz_options[i][1], cfg->psz_name ) )
1001 if( ppsz_options[i] == NULL )
1003 msg_Warn( p_this, "option %s is unknown", cfg->psz_name );
1009 asprintf( &psz_name, "%s%s", psz_prefix, b_once ? &ppsz_options[i][1] : ppsz_options[i] );
1012 /* Check if the option is deprecated */
1014 p_conf = config_FindConfig( p_this, psz_name );
1016 /* This is basically cut and paste from src/misc/configuration.c
1017 * with slight changes */
1018 if( p_conf && p_conf->psz_current )
1020 if( !strcmp( p_conf->psz_current, "SUPPRESSED" ) )
1022 msg_Err( p_this, "Option %s is no longer used.",
1026 else if( p_conf->b_strict )
1028 msg_Err( p_this, "Option %s is deprecated. Use %s instead.",
1029 p_conf->psz_name, p_conf->psz_current );
1030 /* TODO: this should return an error and end option parsing
1031 * ... but doing this would change the VLC API and all the
1032 * modules so i'll do it later */
1037 msg_Warn( p_this, "Option %s is deprecated. You should use "
1038 "%s instead.", p_conf->psz_name, p_conf->psz_current );
1039 i_type = config_GetType( p_this, psz_name );
1041 psz_name = strdup( p_conf->psz_current );
1042 var_Create( p_this, psz_name, i_type | VLC_VAR_DOINHERIT );
1045 /* </Check if the option is deprecated> */
1047 /* get the type of the variable */
1048 i_type = config_GetType( p_this, psz_name );
1051 msg_Warn( p_this, "unknown option %s (value=%s)",
1052 cfg->psz_name, cfg->psz_value );
1055 if( i_type != VLC_VAR_BOOL && cfg->psz_value == NULL )
1057 msg_Warn( p_this, "missing value for option %s", cfg->psz_name );
1060 if( i_type != VLC_VAR_STRING && b_once )
1062 msg_Warn( p_this, "*option_name need to be a string option" );
1071 case VLC_VAR_INTEGER:
1072 val.i_int = strtol( cfg->psz_value ? cfg->psz_value : "0",
1076 val.f_float = atof( cfg->psz_value ? cfg->psz_value : "0" );
1078 case VLC_VAR_STRING:
1079 case VLC_VAR_MODULE:
1080 val.psz_string = cfg->psz_value;
1083 msg_Warn( p_this, "unhandled config var type" );
1084 memset( &val, 0, sizeof( vlc_value_t ) );
1091 var_Get( p_this, psz_name, &val2 );
1092 if( *val2.psz_string )
1094 free( val2.psz_string );
1095 msg_Dbg( p_this, "ignoring option %s (not first occurrence)", psz_name );
1098 free( val2.psz_string );
1100 var_Set( p_this, psz_name, val );
1101 msg_Dbg( p_this, "set sout option: %s to %s", psz_name, cfg->psz_value );
1111 * XXX name and p_cfg are used (-> do NOT free them)
1113 sout_stream_t *sout_StreamNew( sout_instance_t *p_sout, char *psz_chain )
1115 sout_stream_t *p_stream;
1119 msg_Err( p_sout, "invalid chain" );
1123 p_stream = vlc_object_create( p_sout, sizeof( sout_stream_t ) );
1127 msg_Err( p_sout, "out of memory" );
1131 p_stream->p_sout = p_sout;
1132 p_stream->p_sys = NULL;
1134 p_stream->psz_next =
1135 sout_CfgCreate( &p_stream->psz_name, &p_stream->p_cfg, psz_chain);
1137 msg_Dbg( p_sout, "stream=`%s'", p_stream->psz_name );
1139 vlc_object_attach( p_stream, p_sout );
1141 p_stream->p_module =
1142 module_Need( p_stream, "sout stream", p_stream->psz_name, VLC_TRUE );
1144 if( !p_stream->p_module )
1146 sout_StreamDelete( p_stream );
1153 void sout_StreamDelete( sout_stream_t *p_stream )
1155 msg_Dbg( p_stream, "destroying chain... (name=%s)", p_stream->psz_name );
1157 vlc_object_detach( p_stream );
1158 if( p_stream->p_module ) module_Unneed( p_stream, p_stream->p_module );
1160 FREE( p_stream->psz_name );
1161 FREE( p_stream->psz_next );
1163 sout_CfgDestroy( p_stream->p_cfg );
1165 msg_Dbg( p_stream, "destroying chain done" );
1166 vlc_object_destroy( p_stream );
1169 static char *_sout_stream_url_to_chain( vlc_object_t *p_this, char *psz_url )
1172 char *psz_chain, *p;
1174 mrl_Parse( &mrl, psz_url );
1175 p = psz_chain = malloc( 500 + strlen( mrl.psz_way ) +
1176 strlen( mrl.psz_access ) +
1177 strlen( mrl.psz_name ) );
1180 if( config_GetInt( p_this, "sout-display" ) )
1182 p += sprintf( p, "duplicate{dst=display,dst=std{mux=\"%s\","
1183 "access=\"%s\",url=\"%s\"}}",
1184 mrl.psz_way, mrl.psz_access, mrl.psz_name );
1188 p += sprintf( p, "std{mux=\"%s\",access=\"%s\",url=\"%s\"}",
1189 mrl.psz_way, mrl.psz_access, mrl.psz_name );
1193 return( psz_chain );