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",
147 VLC_VAR_INTEGER, STATS_COUNTER );
148 stats_Create( p_parent, "sout_sent_bytes", VLC_VAR_INTEGER, STATS_COUNTER );
149 stats_Create( p_parent, "sout_send_bitrate",
150 VLC_VAR_FLOAT, STATS_DERIVATIVE );
151 p_counter = stats_CounterGet( p_parent, p_parent->i_object_id,
152 "sout_send_bitrate" );
153 if( p_counter) p_counter->update_interval = 1000000;
155 p_sout->p_stream = sout_StreamNew( p_sout, p_sout->psz_chain );
157 if( p_sout->p_stream == NULL )
159 msg_Err( p_sout, "stream chained failed for `%s'", p_sout->psz_chain );
161 FREE( p_sout->psz_sout );
162 FREE( p_sout->psz_chain );
164 vlc_object_detach( p_sout );
165 vlc_object_destroy( p_sout );
171 /*****************************************************************************
172 * sout_DeleteInstance: delete a previously allocated instance
173 *****************************************************************************/
174 void sout_DeleteInstance( sout_instance_t * p_sout )
177 vlc_object_detach( p_sout );
179 /* remove the stream out chain */
180 sout_StreamDelete( p_sout->p_stream );
182 /* *** free all string *** */
183 FREE( p_sout->psz_sout );
184 FREE( p_sout->psz_chain );
189 vlc_meta_Delete( p_sout->p_meta );
192 vlc_mutex_destroy( &p_sout->lock );
194 /* *** free structure *** */
195 vlc_object_destroy( p_sout );
198 /*****************************************************************************
200 *****************************************************************************/
201 sout_packetizer_input_t *sout_InputNew( sout_instance_t *p_sout,
204 sout_packetizer_input_t *p_input;
206 msg_Dbg( p_sout, "adding a new input" );
208 /* *** create a packetizer input *** */
209 p_input = malloc( sizeof( sout_packetizer_input_t ) );
210 p_input->p_sout = p_sout;
211 p_input->p_fmt = p_fmt;
213 if( p_fmt->i_codec == VLC_FOURCC( 'n', 'u', 'l', 'l' ) )
215 vlc_object_release( p_sout );
219 /* *** add it to the stream chain */
220 vlc_mutex_lock( &p_sout->lock );
221 p_input->id = p_sout->p_stream->pf_add( p_sout->p_stream, p_fmt );
222 vlc_mutex_unlock( &p_sout->lock );
224 if( p_input->id == NULL )
233 /*****************************************************************************
235 *****************************************************************************/
236 int sout_InputDelete( sout_packetizer_input_t *p_input )
238 sout_instance_t *p_sout = p_input->p_sout;
240 msg_Dbg( p_sout, "removing an input" );
242 if( p_input->p_fmt->i_codec != VLC_FOURCC( 'n', 'u', 'l', 'l' ) )
244 vlc_mutex_lock( &p_sout->lock );
245 p_sout->p_stream->pf_del( p_sout->p_stream, p_input->id );
246 vlc_mutex_unlock( &p_sout->lock );
251 return( VLC_SUCCESS);
254 /*****************************************************************************
256 *****************************************************************************/
257 int sout_InputSendBuffer( sout_packetizer_input_t *p_input,
260 sout_instance_t *p_sout = p_input->p_sout;
263 if( p_input->p_fmt->i_codec == VLC_FOURCC( 'n', 'u', 'l', 'l' ) )
265 block_Release( p_buffer );
268 if( p_buffer->i_dts <= 0 )
270 msg_Warn( p_sout, "trying to send non-dated packet to stream output!");
271 block_Release( p_buffer );
275 vlc_mutex_lock( &p_sout->lock );
276 i_ret = p_sout->p_stream->pf_send( p_sout->p_stream,
277 p_input->id, p_buffer );
278 vlc_mutex_unlock( &p_sout->lock );
283 /*****************************************************************************
284 * sout_AccessOutNew: allocate a new access out
285 *****************************************************************************/
286 sout_access_out_t *sout_AccessOutNew( sout_instance_t *p_sout,
287 char *psz_access, char *psz_name )
289 sout_access_out_t *p_access;
292 if( !( p_access = vlc_object_create( p_sout,
293 sizeof( sout_access_out_t ) ) ) )
295 msg_Err( p_sout, "out of memory" );
299 psz_next = sout_CfgCreate( &p_access->psz_access, &p_access->p_cfg,
305 p_access->psz_name = strdup( psz_name ? psz_name : "" );
306 p_access->p_sout = p_sout;
307 p_access->p_sys = NULL;
308 p_access->pf_seek = NULL;
309 p_access->pf_read = NULL;
310 p_access->pf_write = NULL;
311 p_access->p_module = NULL;
313 p_access->i_writes = 0;
314 p_access->i_sent_bytes = 0;
316 vlc_object_attach( p_access, p_sout );
319 module_Need( p_access, "sout access", p_access->psz_access, VLC_TRUE );
321 if( !p_access->p_module )
323 free( p_access->psz_access );
324 free( p_access->psz_name );
325 vlc_object_detach( p_access );
326 vlc_object_destroy( p_access );
332 /*****************************************************************************
333 * sout_AccessDelete: delete an access out
334 *****************************************************************************/
335 void sout_AccessOutDelete( sout_access_out_t *p_access )
337 vlc_object_detach( p_access );
338 if( p_access->p_module )
340 module_Unneed( p_access, p_access->p_module );
342 free( p_access->psz_access );
344 sout_CfgDestroy( p_access->p_cfg );
346 free( p_access->psz_name );
348 vlc_object_destroy( p_access );
351 /*****************************************************************************
353 *****************************************************************************/
354 int sout_AccessOutSeek( sout_access_out_t *p_access, off_t i_pos )
356 return p_access->pf_seek( p_access, i_pos );
359 /*****************************************************************************
361 *****************************************************************************/
362 int sout_AccessOutRead( sout_access_out_t *p_access, block_t *p_buffer )
364 return( p_access->pf_read ?
365 p_access->pf_read( p_access, p_buffer ) : VLC_EGENERIC );
368 /*****************************************************************************
370 *****************************************************************************/
371 int sout_AccessOutWrite( sout_access_out_t *p_access, block_t *p_buffer )
374 p_access->i_writes++;
375 p_access->i_sent_bytes += p_buffer->i_buffer;
376 if( p_access->p_libvlc->b_stats && p_access->i_writes % 10 == 0 )
378 /* Access_out -> sout_instance -> input_thread_t */
379 input_thread_t *p_input =
380 (input_thread_t *)vlc_object_find( p_access, VLC_OBJECT_INPUT,
384 stats_UpdateInteger( p_input, "sout_sent_packets", 10 );
385 stats_UpdateInteger( p_input, "sout_sent_bytes",
386 p_access->i_sent_bytes );
387 stats_GetInteger( p_input,
388 p_access->p_parent->p_parent->i_object_id,
389 "sout_sent_bytes", &i_total );
390 stats_UpdateFloat( p_input, "sout_send_bitrate", (float)i_total );
392 p_access->i_sent_bytes = 0;
393 vlc_object_release( p_input );
396 return p_access->pf_write( p_access, p_buffer );
399 /*****************************************************************************
400 * sout_MuxNew: create a new mux
401 *****************************************************************************/
402 sout_mux_t * sout_MuxNew( sout_instance_t *p_sout, char *psz_mux,
403 sout_access_out_t *p_access )
408 p_mux = vlc_object_create( p_sout, sizeof( sout_mux_t ) );
411 msg_Err( p_sout, "out of memory" );
415 p_mux->p_sout = p_sout;
416 psz_next = sout_CfgCreate( &p_mux->psz_mux, &p_mux->p_cfg, psz_mux );
417 if( psz_next ) free( psz_next );
419 p_mux->p_access = p_access;
420 p_mux->pf_control = NULL;
421 p_mux->pf_addstream = NULL;
422 p_mux->pf_delstream = NULL;
423 p_mux->pf_mux = NULL;
424 p_mux->i_nb_inputs = 0;
425 p_mux->pp_inputs = NULL;
428 p_mux->p_module = NULL;
430 p_mux->b_add_stream_any_time = VLC_FALSE;
431 p_mux->b_waiting_stream = VLC_TRUE;
432 p_mux->i_add_stream_start = -1;
434 vlc_object_attach( p_mux, p_sout );
437 module_Need( p_mux, "sout mux", p_mux->psz_mux, VLC_TRUE );
439 if( p_mux->p_module == NULL )
441 FREE( p_mux->psz_mux );
443 vlc_object_detach( p_mux );
444 vlc_object_destroy( p_mux );
448 /* *** probe mux capacity *** */
449 if( p_mux->pf_control )
451 int b_answer = VLC_FALSE;
453 if( sout_MuxControl( p_mux, MUX_CAN_ADD_STREAM_WHILE_MUXING,
456 b_answer = VLC_FALSE;
461 msg_Dbg( p_sout, "muxer support adding stream at any time" );
462 p_mux->b_add_stream_any_time = VLC_TRUE;
463 p_mux->b_waiting_stream = VLC_FALSE;
465 /* If we control the output pace then it's better to wait before
466 * starting muxing (generates better streams/files). */
467 if( !p_sout->i_out_pace_nocontrol )
471 else if( sout_MuxControl( p_mux, MUX_GET_ADD_STREAM_WAIT,
474 b_answer = VLC_FALSE;
479 msg_Dbg( p_sout, "muxer prefers waiting for all ES before "
481 p_mux->b_waiting_stream = VLC_TRUE;
489 /*****************************************************************************
491 *****************************************************************************/
492 void sout_MuxDelete( sout_mux_t *p_mux )
494 vlc_object_detach( p_mux );
495 if( p_mux->p_module )
497 module_Unneed( p_mux, p_mux->p_module );
499 free( p_mux->psz_mux );
501 sout_CfgDestroy( p_mux->p_cfg );
503 vlc_object_destroy( p_mux );
506 /*****************************************************************************
508 *****************************************************************************/
509 sout_input_t *sout_MuxAddStream( sout_mux_t *p_mux, es_format_t *p_fmt )
511 sout_input_t *p_input;
513 if( !p_mux->b_add_stream_any_time && !p_mux->b_waiting_stream )
515 msg_Err( p_mux, "cannot add a new stream (unsupported while muxing "
516 "for this format)" );
520 msg_Dbg( p_mux, "adding a new input" );
522 /* create a new sout input */
523 p_input = malloc( sizeof( sout_input_t ) );
524 p_input->p_sout = p_mux->p_sout;
525 p_input->p_fmt = p_fmt;
526 p_input->p_fifo = block_FifoNew( p_mux->p_sout );
527 p_input->p_sys = NULL;
529 TAB_APPEND( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input );
530 if( p_mux->pf_addstream( p_mux, p_input ) < 0 )
532 msg_Err( p_mux, "cannot add this stream" );
533 TAB_REMOVE( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input );
534 block_FifoRelease( p_input->p_fifo );
542 /*****************************************************************************
543 * sout_MuxDeleteStream:
544 *****************************************************************************/
545 void sout_MuxDeleteStream( sout_mux_t *p_mux, sout_input_t *p_input )
549 if( p_mux->b_waiting_stream && p_input->p_fifo->i_depth > 0 )
551 /* We stop waiting, and call the muxer for taking care of the data
552 * before we remove this es */
553 p_mux->b_waiting_stream = VLC_FALSE;
554 p_mux->pf_mux( p_mux );
557 TAB_FIND( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input, i_index );
560 if( p_mux->pf_delstream( p_mux, p_input ) < 0 )
562 msg_Err( p_mux, "cannot del this stream from mux" );
565 /* remove the entry */
566 TAB_REMOVE( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input );
568 if( p_mux->i_nb_inputs == 0 )
570 msg_Warn( p_mux, "no more input stream for this mux" );
573 block_FifoRelease( p_input->p_fifo );
578 /*****************************************************************************
579 * sout_MuxSendBuffer:
580 *****************************************************************************/
581 void sout_MuxSendBuffer( sout_mux_t *p_mux, sout_input_t *p_input,
584 block_FifoPut( p_input->p_fifo, p_buffer );
586 if( p_mux->p_sout->i_out_pace_nocontrol )
588 mtime_t current_date = mdate();
589 if ( current_date > p_buffer->i_dts )
590 msg_Warn( p_mux, "late buffer for mux input ("I64Fd")",
591 current_date - p_buffer->i_dts );
594 if( p_mux->b_waiting_stream )
596 if( p_mux->i_add_stream_start < 0 )
598 p_mux->i_add_stream_start = p_buffer->i_dts;
601 if( p_mux->i_add_stream_start >= 0 &&
602 p_mux->i_add_stream_start + I64C(1500000) < p_buffer->i_dts )
604 /* Wait until we have more than 1.5 seconds worth of data
605 * before start muxing */
606 p_mux->b_waiting_stream = VLC_FALSE;
613 p_mux->pf_mux( p_mux );
616 /*****************************************************************************
618 *****************************************************************************/
619 static int mrl_Parse( mrl_t *p_mrl, char *psz_mrl )
621 char * psz_dup = strdup( psz_mrl );
622 char * psz_parser = psz_dup;
623 char * psz_access = "";
625 char * psz_name = "";
627 /* *** first parse psz_dest */
628 while( *psz_parser && *psz_parser != ':' )
630 if( *psz_parser == '{' )
632 while( *psz_parser && *psz_parser != '}' )
646 #if defined( WIN32 ) || defined( UNDER_CE )
647 if( psz_parser - psz_dup == 1 )
649 /* msg_Warn( p_sout, "drive letter %c: found in source string",
657 psz_access = psz_way = "";
662 *psz_parser++ = '\0';
664 /* let's skip '//' */
665 if( psz_parser[0] == '/' && psz_parser[1] == '/' )
670 psz_name = psz_parser ;
672 /* Come back to parse the access and mux plug-ins */
673 psz_parser = psz_dup;
680 else if( *psz_parser == '/' )
688 psz_access = psz_parser;
690 while( *psz_parser && *psz_parser != '/' )
692 if( *psz_parser == '{' )
694 while( *psz_parser && *psz_parser != '}' )
709 if( *psz_parser == '/' )
711 *psz_parser++ = '\0';
722 psz_way = psz_parser;
726 p_mrl->psz_access = strdup( psz_access );
727 p_mrl->psz_way = strdup( psz_way );
728 p_mrl->psz_name = strdup( psz_name );
731 return( VLC_SUCCESS );
735 /* mrl_Clean: clean p_mrl after a call to mrl_Parse */
736 static void mrl_Clean( mrl_t *p_mrl )
738 FREE( p_mrl->psz_access );
739 FREE( p_mrl->psz_way );
740 FREE( p_mrl->psz_name );
744 /****************************************************************************
745 ****************************************************************************
749 ****************************************************************************
750 ****************************************************************************/
752 /* create a complete chain */
754 module{option=*:option=*}[:module{option=*:...}]
758 * parse module{options=str, option="str "}:
759 * return a pointer on the rest
760 * XXX: psz_chain is modified
762 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
763 #define SKIPTRAILINGSPACE( p, e ) \
764 { while( e > p && ( *(e-1) == ' ' || *(e-1) == '\t' ) ) e--; }
766 /* go accross " " and { } */
767 static char *_get_chain_end( char *str )
775 if( !*p || *p == ',' || *p == '}' ) return p;
777 if( *p != '{' && *p != '"' && *p != '\'' )
783 if( *p == '{' ) c = '}';
791 if( *p == c ) return ++p;
792 else if( *p == '{' && c == '}' ) p = _get_chain_end( p );
798 char *sout_CfgCreate( char **ppsz_name, sout_cfg_t **pp_cfg, char *psz_chain )
800 sout_cfg_t *p_cfg = NULL;
806 if( !p ) return NULL;
810 while( *p && *p != '{' && *p != ':' && *p != ' ' && *p != '\t' ) p++;
812 if( p == psz_chain ) return NULL;
814 *ppsz_name = strndup( psz_chain, p - psz_chain );
832 while( *p && *p != '=' && *p != ',' && *p != '{' && *p != '}' &&
833 *p != ' ' && *p != '\t' ) p++;
835 /* fprintf( stderr, "name=%s - rest=%s\n", psz_name, p ); */
838 fprintf( stderr, "invalid options (empty)" );
842 cfg.psz_name = strndup( psz_name, p - psz_name );
846 if( *p == '=' || *p == '{' )
849 vlc_bool_t b_keep_brackets = (*p == '{');
853 end = _get_chain_end( p );
856 cfg.psz_value = NULL;
860 /* Skip heading and trailing spaces.
861 * This ain't necessary but will avoid simple
868 cfg.psz_value = NULL;
872 if( *p == '\'' || *p == '"' ||
873 ( !b_keep_brackets && *p == '{' ) )
877 if( *(end-1) != '\'' && *(end-1) == '"' )
878 SKIPTRAILINGSPACE( p, end );
880 if( end - 1 <= p ) cfg.psz_value = NULL;
881 else cfg.psz_value = strndup( p, end -1 - p );
885 SKIPTRAILINGSPACE( p, end );
886 if( end <= p ) cfg.psz_value = NULL;
887 else cfg.psz_value = strndup( p, end - p );
896 cfg.psz_value = NULL;
902 p_cfg->p_next = malloc( sizeof( sout_cfg_t ) );
903 memcpy( p_cfg->p_next, &cfg, sizeof( sout_cfg_t ) );
905 p_cfg = p_cfg->p_next;
909 p_cfg = malloc( sizeof( sout_cfg_t ) );
910 memcpy( p_cfg, &cfg, sizeof( sout_cfg_t ) );
925 if( *p == ':' ) return( strdup( p + 1 ) );
930 static void sout_CfgDestroy( sout_cfg_t *p_cfg )
932 while( p_cfg != NULL )
936 p_next = p_cfg->p_next;
938 FREE( p_cfg->psz_name );
939 FREE( p_cfg->psz_value );
946 void __sout_CfgParse( vlc_object_t *p_this, char *psz_prefix,
947 const char **ppsz_options, sout_cfg_t *cfg )
953 /* First, var_Create all variables */
954 for( i = 0; ppsz_options[i] != NULL; i++ )
956 asprintf( &psz_name, "%s%s", psz_prefix,
957 *ppsz_options[i] == '*' ? &ppsz_options[i][1] : ppsz_options[i] );
959 i_type = config_GetType( p_this, psz_name );
961 var_Create( p_this, psz_name, i_type | VLC_VAR_DOINHERIT );
965 /* Now parse options and set value */
966 if( psz_prefix == NULL ) psz_prefix = "";
971 vlc_bool_t b_yes = VLC_TRUE;
972 vlc_bool_t b_once = VLC_FALSE;
974 if( cfg->psz_name == NULL || *cfg->psz_name == '\0' )
979 for( i = 0; ppsz_options[i] != NULL; i++ )
981 if( !strcmp( ppsz_options[i], cfg->psz_name ) )
985 if( ( !strncmp( cfg->psz_name, "no-", 3 ) &&
986 !strcmp( ppsz_options[i], cfg->psz_name + 3 ) ) ||
987 ( !strncmp( cfg->psz_name, "no", 2 ) &&
988 !strcmp( ppsz_options[i], cfg->psz_name + 2 ) ) )
994 if( *ppsz_options[i] == '*' &&
995 !strcmp( &ppsz_options[i][1], cfg->psz_name ) )
1002 if( ppsz_options[i] == NULL )
1004 msg_Warn( p_this, "option %s is unknown", cfg->psz_name );
1010 asprintf( &psz_name, "%s%s", psz_prefix, b_once ? &ppsz_options[i][1] : ppsz_options[i] );
1012 /* get the type of the variable */
1013 i_type = config_GetType( p_this, psz_name );
1016 msg_Warn( p_this, "unknown option %s (value=%s)",
1017 cfg->psz_name, cfg->psz_value );
1020 if( i_type != VLC_VAR_BOOL && cfg->psz_value == NULL )
1022 msg_Warn( p_this, "missing value for option %s", cfg->psz_name );
1025 if( i_type != VLC_VAR_STRING && b_once )
1027 msg_Warn( p_this, "*option_name need to be a string option" );
1036 case VLC_VAR_INTEGER:
1037 val.i_int = strtol( cfg->psz_value ? cfg->psz_value : "0",
1041 val.f_float = atof( cfg->psz_value ? cfg->psz_value : "0" );
1043 case VLC_VAR_STRING:
1044 case VLC_VAR_MODULE:
1045 val.psz_string = cfg->psz_value;
1048 msg_Warn( p_this, "unhandled config var type" );
1049 memset( &val, 0, sizeof( vlc_value_t ) );
1056 var_Get( p_this, psz_name, &val2 );
1057 if( *val2.psz_string )
1059 free( val2.psz_string );
1060 msg_Dbg( p_this, "ignoring option %s (not first occurrence)", psz_name );
1063 free( val2.psz_string );
1065 var_Set( p_this, psz_name, val );
1066 msg_Dbg( p_this, "set sout option: %s to %s", psz_name, cfg->psz_value );
1076 * XXX name and p_cfg are used (-> do NOT free them)
1078 sout_stream_t *sout_StreamNew( sout_instance_t *p_sout, char *psz_chain )
1080 sout_stream_t *p_stream;
1084 msg_Err( p_sout, "invalid chain" );
1088 p_stream = vlc_object_create( p_sout, sizeof( sout_stream_t ) );
1092 msg_Err( p_sout, "out of memory" );
1096 p_stream->p_sout = p_sout;
1097 p_stream->p_sys = NULL;
1099 p_stream->psz_next =
1100 sout_CfgCreate( &p_stream->psz_name, &p_stream->p_cfg, psz_chain);
1102 msg_Dbg( p_sout, "stream=`%s'", p_stream->psz_name );
1104 vlc_object_attach( p_stream, p_sout );
1106 p_stream->p_module =
1107 module_Need( p_stream, "sout stream", p_stream->psz_name, VLC_TRUE );
1109 if( !p_stream->p_module )
1111 sout_StreamDelete( p_stream );
1118 void sout_StreamDelete( sout_stream_t *p_stream )
1120 msg_Dbg( p_stream, "destroying chain... (name=%s)", p_stream->psz_name );
1122 vlc_object_detach( p_stream );
1123 if( p_stream->p_module ) module_Unneed( p_stream, p_stream->p_module );
1125 FREE( p_stream->psz_name );
1126 FREE( p_stream->psz_next );
1128 sout_CfgDestroy( p_stream->p_cfg );
1130 msg_Dbg( p_stream, "destroying chain done" );
1131 vlc_object_destroy( p_stream );
1134 static char *_sout_stream_url_to_chain( vlc_object_t *p_this, char *psz_url )
1137 char *psz_chain, *p;
1139 mrl_Parse( &mrl, psz_url );
1140 p = psz_chain = malloc( 500 + strlen( mrl.psz_way ) +
1141 strlen( mrl.psz_access ) +
1142 strlen( mrl.psz_name ) );
1145 if( config_GetInt( p_this, "sout-display" ) )
1147 p += sprintf( p, "duplicate{dst=display,dst=std{mux=\"%s\","
1148 "access=\"%s\",url=\"%s\"}}",
1149 mrl.psz_way, mrl.psz_access, mrl.psz_name );
1153 p += sprintf( p, "std{mux=\"%s\",access=\"%s\",url=\"%s\"}",
1154 mrl.psz_way, mrl.psz_access, mrl.psz_name );
1158 return( psz_chain );