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() */
39 /*****************************************************************************
41 *****************************************************************************/
42 static void sout_CfgDestroy( sout_cfg_t * );
44 #define sout_stream_url_to_chain( p, s ) \
45 _sout_stream_url_to_chain( VLC_OBJECT(p), s )
46 static char *_sout_stream_url_to_chain( vlc_object_t *, char * );
60 /* mrl_Parse: parse psz_mrl and fill p_mrl */
61 static int mrl_Parse( mrl_t *p_mrl, char *psz_mrl );
62 /* mrl_Clean: clean p_mrl after a call to mrl_Parse */
63 static void mrl_Clean( mrl_t *p_mrl );
65 #define FREE( p ) if( p ) { free( p ); (p) = NULL; }
67 /*****************************************************************************
68 * sout_NewInstance: creates a new stream output instance
69 *****************************************************************************/
70 sout_instance_t *__sout_NewInstance( vlc_object_t *p_parent, char * psz_dest )
72 sout_instance_t *p_sout;
76 if( var_Get( p_parent, "sout-keep", &keep ) < 0 )
78 msg_Warn( p_parent, "cannot get sout-keep value" );
79 keep.b_bool = VLC_FALSE;
83 if( ( p_sout = vlc_object_find( p_parent, VLC_OBJECT_SOUT,
84 FIND_ANYWHERE ) ) != NULL )
86 if( !strcmp( p_sout->psz_sout, psz_dest ) )
88 msg_Dbg( p_parent, "sout keep : reusing sout" );
89 msg_Dbg( p_parent, "sout keep : you probably want to use "
90 "gather stream_out" );
91 vlc_object_detach( p_sout );
92 vlc_object_attach( p_sout, p_parent );
93 vlc_object_release( p_sout );
98 msg_Dbg( p_parent, "sout keep : destroying unusable sout" );
99 vlc_object_release( p_sout );
100 sout_DeleteInstance( p_sout );
104 else if( !keep.b_bool )
106 while( ( p_sout = vlc_object_find( p_parent, VLC_OBJECT_SOUT,
107 FIND_PARENT ) ) != NULL )
109 msg_Dbg( p_parent, "sout keep : destroying old sout" );
110 vlc_object_release( p_sout );
111 sout_DeleteInstance( p_sout );
115 /* *** Allocate descriptor *** */
116 p_sout = vlc_object_create( p_parent, VLC_OBJECT_SOUT );
119 msg_Err( p_parent, "out of memory" );
123 /* *** init descriptor *** */
124 p_sout->psz_sout = strdup( psz_dest );
125 p_sout->p_meta = NULL;
126 p_sout->i_out_pace_nocontrol = 0;
127 p_sout->p_sys = NULL;
129 vlc_mutex_init( p_sout, &p_sout->lock );
130 if( psz_dest && psz_dest[0] == '#' )
132 p_sout->psz_chain = strdup( &psz_dest[1] );
136 p_sout->psz_chain = sout_stream_url_to_chain( p_sout, psz_dest );
137 msg_Dbg( p_sout, "using sout chain=`%s'", p_sout->psz_chain );
139 p_sout->p_stream = NULL;
141 /* attach it for inherit */
142 vlc_object_attach( p_sout, p_parent );
144 /* Create statistics */
145 stats_Create( p_parent, "sout_sent_packets",
146 VLC_VAR_INTEGER, STATS_COUNTER );
147 stats_Create( p_parent, "sout_sent_bytes", VLC_VAR_INTEGER, STATS_COUNTER );
148 stats_Create( p_parent, "sout_send_bitrate",
149 VLC_VAR_FLOAT, STATS_DERIVATIVE );
150 p_counter = stats_CounterGet( p_parent, p_parent->i_object_id,
151 "sout_send_bitrate" );
152 if( p_counter) p_counter->update_interval = 1000000;
154 p_sout->p_stream = sout_StreamNew( p_sout, p_sout->psz_chain );
156 if( p_sout->p_stream == NULL )
158 msg_Err( p_sout, "stream chained failed for `%s'", p_sout->psz_chain );
160 FREE( p_sout->psz_sout );
161 FREE( p_sout->psz_chain );
163 vlc_object_detach( p_sout );
164 vlc_object_destroy( p_sout );
170 /*****************************************************************************
171 * sout_DeleteInstance: delete a previously allocated instance
172 *****************************************************************************/
173 void sout_DeleteInstance( sout_instance_t * p_sout )
176 vlc_object_detach( p_sout );
178 /* remove the stream out chain */
179 sout_StreamDelete( p_sout->p_stream );
181 /* *** free all string *** */
182 FREE( p_sout->psz_sout );
183 FREE( p_sout->psz_chain );
188 vlc_meta_Delete( p_sout->p_meta );
191 vlc_mutex_destroy( &p_sout->lock );
193 /* *** free structure *** */
194 vlc_object_destroy( p_sout );
197 /*****************************************************************************
199 *****************************************************************************/
200 sout_packetizer_input_t *sout_InputNew( sout_instance_t *p_sout,
203 sout_packetizer_input_t *p_input;
205 msg_Dbg( p_sout, "adding a new input" );
207 /* *** create a packetizer input *** */
208 p_input = malloc( sizeof( sout_packetizer_input_t ) );
209 p_input->p_sout = p_sout;
210 p_input->p_fmt = p_fmt;
212 if( p_fmt->i_codec == VLC_FOURCC( 'n', 'u', 'l', 'l' ) )
214 vlc_object_release( p_sout );
218 /* *** add it to the stream chain */
219 vlc_mutex_lock( &p_sout->lock );
220 p_input->id = p_sout->p_stream->pf_add( p_sout->p_stream, p_fmt );
221 vlc_mutex_unlock( &p_sout->lock );
223 if( p_input->id == NULL )
232 /*****************************************************************************
234 *****************************************************************************/
235 int sout_InputDelete( sout_packetizer_input_t *p_input )
237 sout_instance_t *p_sout = p_input->p_sout;
239 msg_Dbg( p_sout, "removing an input" );
241 if( p_input->p_fmt->i_codec != VLC_FOURCC( 'n', 'u', 'l', 'l' ) )
243 vlc_mutex_lock( &p_sout->lock );
244 p_sout->p_stream->pf_del( p_sout->p_stream, p_input->id );
245 vlc_mutex_unlock( &p_sout->lock );
250 return( VLC_SUCCESS);
253 /*****************************************************************************
255 *****************************************************************************/
256 int sout_InputSendBuffer( sout_packetizer_input_t *p_input,
259 sout_instance_t *p_sout = p_input->p_sout;
262 if( p_input->p_fmt->i_codec == VLC_FOURCC( 'n', 'u', 'l', 'l' ) )
264 block_Release( p_buffer );
267 if( p_buffer->i_dts <= 0 )
269 msg_Warn( p_sout, "trying to send non-dated packet to stream output!");
270 block_Release( p_buffer );
274 vlc_mutex_lock( &p_sout->lock );
275 i_ret = p_sout->p_stream->pf_send( p_sout->p_stream,
276 p_input->id, p_buffer );
277 vlc_mutex_unlock( &p_sout->lock );
282 /*****************************************************************************
283 * sout_AccessOutNew: allocate a new access out
284 *****************************************************************************/
285 sout_access_out_t *sout_AccessOutNew( sout_instance_t *p_sout,
286 char *psz_access, char *psz_name )
288 sout_access_out_t *p_access;
291 if( !( p_access = vlc_object_create( p_sout,
292 sizeof( sout_access_out_t ) ) ) )
294 msg_Err( p_sout, "out of memory" );
298 psz_next = sout_CfgCreate( &p_access->psz_access, &p_access->p_cfg,
304 p_access->psz_name = strdup( psz_name ? psz_name : "" );
305 p_access->p_sout = p_sout;
306 p_access->p_sys = NULL;
307 p_access->pf_seek = NULL;
308 p_access->pf_read = NULL;
309 p_access->pf_write = NULL;
310 p_access->p_module = NULL;
311 vlc_object_attach( p_access, p_sout );
314 module_Need( p_access, "sout access", p_access->psz_access, VLC_TRUE );
316 if( !p_access->p_module )
318 free( p_access->psz_access );
319 free( p_access->psz_name );
320 vlc_object_detach( p_access );
321 vlc_object_destroy( p_access );
327 /*****************************************************************************
328 * sout_AccessDelete: delete an access out
329 *****************************************************************************/
330 void sout_AccessOutDelete( sout_access_out_t *p_access )
332 vlc_object_detach( p_access );
333 if( p_access->p_module )
335 module_Unneed( p_access, p_access->p_module );
337 free( p_access->psz_access );
339 sout_CfgDestroy( p_access->p_cfg );
341 free( p_access->psz_name );
343 vlc_object_destroy( p_access );
346 /*****************************************************************************
348 *****************************************************************************/
349 int sout_AccessOutSeek( sout_access_out_t *p_access, off_t i_pos )
351 return p_access->pf_seek( p_access, i_pos );
354 /*****************************************************************************
356 *****************************************************************************/
357 int sout_AccessOutRead( sout_access_out_t *p_access, block_t *p_buffer )
359 return( p_access->pf_read ?
360 p_access->pf_read( p_access, p_buffer ) : VLC_EGENERIC );
363 /*****************************************************************************
365 *****************************************************************************/
366 int sout_AccessOutWrite( sout_access_out_t *p_access, block_t *p_buffer )
369 /* Access_out -> sout_instance -> input_thread_t */
370 stats_UpdateInteger( p_access->p_parent->p_parent,
371 "sout_sent_packets", 1 );
372 stats_UpdateInteger( p_access->p_parent->p_parent,
373 "sout_sent_bytes", p_buffer->i_buffer );
374 stats_GetInteger( p_access->p_parent->p_parent,
375 p_access->p_parent->p_parent->i_object_id,
376 "sout_sent_bytes", &i_total );
377 stats_UpdateFloat( p_access->p_parent->p_parent, "sout_send_bitrate",
379 return p_access->pf_write( p_access, p_buffer );
382 /*****************************************************************************
383 * sout_MuxNew: create a new mux
384 *****************************************************************************/
385 sout_mux_t * sout_MuxNew( sout_instance_t *p_sout, char *psz_mux,
386 sout_access_out_t *p_access )
391 p_mux = vlc_object_create( p_sout, sizeof( sout_mux_t ) );
394 msg_Err( p_sout, "out of memory" );
398 p_mux->p_sout = p_sout;
399 psz_next = sout_CfgCreate( &p_mux->psz_mux, &p_mux->p_cfg, psz_mux );
400 if( psz_next ) free( psz_next );
402 p_mux->p_access = p_access;
403 p_mux->pf_control = NULL;
404 p_mux->pf_addstream = NULL;
405 p_mux->pf_delstream = NULL;
406 p_mux->pf_mux = NULL;
407 p_mux->i_nb_inputs = 0;
408 p_mux->pp_inputs = NULL;
411 p_mux->p_module = NULL;
413 p_mux->b_add_stream_any_time = VLC_FALSE;
414 p_mux->b_waiting_stream = VLC_TRUE;
415 p_mux->i_add_stream_start = -1;
417 vlc_object_attach( p_mux, p_sout );
420 module_Need( p_mux, "sout mux", p_mux->psz_mux, VLC_TRUE );
422 if( p_mux->p_module == NULL )
424 FREE( p_mux->psz_mux );
426 vlc_object_detach( p_mux );
427 vlc_object_destroy( p_mux );
431 /* *** probe mux capacity *** */
432 if( p_mux->pf_control )
434 int b_answer = VLC_FALSE;
436 if( sout_MuxControl( p_mux, MUX_CAN_ADD_STREAM_WHILE_MUXING,
439 b_answer = VLC_FALSE;
444 msg_Dbg( p_sout, "muxer support adding stream at any time" );
445 p_mux->b_add_stream_any_time = VLC_TRUE;
446 p_mux->b_waiting_stream = VLC_FALSE;
448 /* If we control the output pace then it's better to wait before
449 * starting muxing (generates better streams/files). */
450 if( !p_sout->i_out_pace_nocontrol )
454 else if( sout_MuxControl( p_mux, MUX_GET_ADD_STREAM_WAIT,
457 b_answer = VLC_FALSE;
462 msg_Dbg( p_sout, "muxer prefers waiting for all ES before "
464 p_mux->b_waiting_stream = VLC_TRUE;
472 /*****************************************************************************
474 *****************************************************************************/
475 void sout_MuxDelete( sout_mux_t *p_mux )
477 vlc_object_detach( p_mux );
478 if( p_mux->p_module )
480 module_Unneed( p_mux, p_mux->p_module );
482 free( p_mux->psz_mux );
484 sout_CfgDestroy( p_mux->p_cfg );
486 vlc_object_destroy( p_mux );
489 /*****************************************************************************
491 *****************************************************************************/
492 sout_input_t *sout_MuxAddStream( sout_mux_t *p_mux, es_format_t *p_fmt )
494 sout_input_t *p_input;
496 if( !p_mux->b_add_stream_any_time && !p_mux->b_waiting_stream )
498 msg_Err( p_mux, "cannot add a new stream (unsupported while muxing "
499 "for this format)" );
503 msg_Dbg( p_mux, "adding a new input" );
505 /* create a new sout input */
506 p_input = malloc( sizeof( sout_input_t ) );
507 p_input->p_sout = p_mux->p_sout;
508 p_input->p_fmt = p_fmt;
509 p_input->p_fifo = block_FifoNew( p_mux->p_sout );
510 p_input->p_sys = NULL;
512 TAB_APPEND( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input );
513 if( p_mux->pf_addstream( p_mux, p_input ) < 0 )
515 msg_Err( p_mux, "cannot add this stream" );
516 TAB_REMOVE( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input );
517 block_FifoRelease( p_input->p_fifo );
525 /*****************************************************************************
526 * sout_MuxDeleteStream:
527 *****************************************************************************/
528 void sout_MuxDeleteStream( sout_mux_t *p_mux, sout_input_t *p_input )
532 if( p_mux->b_waiting_stream && p_input->p_fifo->i_depth > 0 )
534 /* We stop waiting, and call the muxer for taking care of the data
535 * before we remove this es */
536 p_mux->b_waiting_stream = VLC_FALSE;
537 p_mux->pf_mux( p_mux );
540 TAB_FIND( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input, i_index );
543 if( p_mux->pf_delstream( p_mux, p_input ) < 0 )
545 msg_Err( p_mux, "cannot del this stream from mux" );
548 /* remove the entry */
549 TAB_REMOVE( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input );
551 if( p_mux->i_nb_inputs == 0 )
553 msg_Warn( p_mux, "no more input stream for this mux" );
556 block_FifoRelease( p_input->p_fifo );
561 /*****************************************************************************
562 * sout_MuxSendBuffer:
563 *****************************************************************************/
564 void sout_MuxSendBuffer( sout_mux_t *p_mux, sout_input_t *p_input,
567 block_FifoPut( p_input->p_fifo, p_buffer );
569 if( p_mux->p_sout->i_out_pace_nocontrol )
571 mtime_t current_date = mdate();
572 if ( current_date > p_buffer->i_dts )
573 msg_Warn( p_mux, "late buffer for mux input ("I64Fd")",
574 current_date - p_buffer->i_dts );
577 if( p_mux->b_waiting_stream )
579 if( p_mux->i_add_stream_start < 0 )
581 p_mux->i_add_stream_start = p_buffer->i_dts;
584 if( p_mux->i_add_stream_start >= 0 &&
585 p_mux->i_add_stream_start + I64C(1500000) < p_buffer->i_dts )
587 /* Wait until we have more than 1.5 seconds worth of data
588 * before start muxing */
589 p_mux->b_waiting_stream = VLC_FALSE;
596 p_mux->pf_mux( p_mux );
599 /*****************************************************************************
601 *****************************************************************************/
602 static int mrl_Parse( mrl_t *p_mrl, char *psz_mrl )
604 char * psz_dup = strdup( psz_mrl );
605 char * psz_parser = psz_dup;
606 char * psz_access = "";
608 char * psz_name = "";
610 /* *** first parse psz_dest */
611 while( *psz_parser && *psz_parser != ':' )
613 if( *psz_parser == '{' )
615 while( *psz_parser && *psz_parser != '}' )
629 #if defined( WIN32 ) || defined( UNDER_CE )
630 if( psz_parser - psz_dup == 1 )
632 /* msg_Warn( p_sout, "drive letter %c: found in source string",
640 psz_access = psz_way = "";
645 *psz_parser++ = '\0';
647 /* let's skip '//' */
648 if( psz_parser[0] == '/' && psz_parser[1] == '/' )
653 psz_name = psz_parser ;
655 /* Come back to parse the access and mux plug-ins */
656 psz_parser = psz_dup;
663 else if( *psz_parser == '/' )
671 psz_access = psz_parser;
673 while( *psz_parser && *psz_parser != '/' )
675 if( *psz_parser == '{' )
677 while( *psz_parser && *psz_parser != '}' )
692 if( *psz_parser == '/' )
694 *psz_parser++ = '\0';
705 psz_way = psz_parser;
709 p_mrl->psz_access = strdup( psz_access );
710 p_mrl->psz_way = strdup( psz_way );
711 p_mrl->psz_name = strdup( psz_name );
714 return( VLC_SUCCESS );
718 /* mrl_Clean: clean p_mrl after a call to mrl_Parse */
719 static void mrl_Clean( mrl_t *p_mrl )
721 FREE( p_mrl->psz_access );
722 FREE( p_mrl->psz_way );
723 FREE( p_mrl->psz_name );
727 /****************************************************************************
728 ****************************************************************************
732 ****************************************************************************
733 ****************************************************************************/
735 /* create a complete chain */
737 module{option=*:option=*}[:module{option=*:...}]
741 * parse module{options=str, option="str "}:
742 * return a pointer on the rest
743 * XXX: psz_chain is modified
745 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
746 #define SKIPTRAILINGSPACE( p, e ) \
747 { while( e > p && ( *(e-1) == ' ' || *(e-1) == '\t' ) ) e--; }
749 /* go accross " " and { } */
750 static char *_get_chain_end( char *str )
758 if( !*p || *p == ',' || *p == '}' ) return p;
760 if( *p != '{' && *p != '"' && *p != '\'' )
766 if( *p == '{' ) c = '}';
774 if( *p == c ) return ++p;
775 else if( *p == '{' && c == '}' ) p = _get_chain_end( p );
781 char *sout_CfgCreate( char **ppsz_name, sout_cfg_t **pp_cfg, char *psz_chain )
783 sout_cfg_t *p_cfg = NULL;
789 if( !p ) return NULL;
793 while( *p && *p != '{' && *p != ':' && *p != ' ' && *p != '\t' ) p++;
795 if( p == psz_chain ) return NULL;
797 *ppsz_name = strndup( psz_chain, p - psz_chain );
815 while( *p && *p != '=' && *p != ',' && *p != '{' && *p != '}' &&
816 *p != ' ' && *p != '\t' ) p++;
818 /* fprintf( stderr, "name=%s - rest=%s\n", psz_name, p ); */
821 fprintf( stderr, "invalid options (empty)" );
825 cfg.psz_name = strndup( psz_name, p - psz_name );
829 if( *p == '=' || *p == '{' )
832 vlc_bool_t b_keep_brackets = (*p == '{');
836 end = _get_chain_end( p );
839 cfg.psz_value = NULL;
843 /* Skip heading and trailing spaces.
844 * This ain't necessary but will avoid simple
851 cfg.psz_value = NULL;
855 if( *p == '\'' || *p == '"' ||
856 ( !b_keep_brackets && *p == '{' ) )
860 if( *(end-1) != '\'' && *(end-1) == '"' )
861 SKIPTRAILINGSPACE( p, end );
863 if( end - 1 <= p ) cfg.psz_value = NULL;
864 else cfg.psz_value = strndup( p, end -1 - p );
868 SKIPTRAILINGSPACE( p, end );
869 if( end <= p ) cfg.psz_value = NULL;
870 else cfg.psz_value = strndup( p, end - p );
879 cfg.psz_value = NULL;
885 p_cfg->p_next = malloc( sizeof( sout_cfg_t ) );
886 memcpy( p_cfg->p_next, &cfg, sizeof( sout_cfg_t ) );
888 p_cfg = p_cfg->p_next;
892 p_cfg = malloc( sizeof( sout_cfg_t ) );
893 memcpy( p_cfg, &cfg, sizeof( sout_cfg_t ) );
908 if( *p == ':' ) return( strdup( p + 1 ) );
913 static void sout_CfgDestroy( sout_cfg_t *p_cfg )
915 while( p_cfg != NULL )
919 p_next = p_cfg->p_next;
921 FREE( p_cfg->psz_name );
922 FREE( p_cfg->psz_value );
929 void __sout_CfgParse( vlc_object_t *p_this, char *psz_prefix,
930 const char **ppsz_options, sout_cfg_t *cfg )
936 /* First, var_Create all variables */
937 for( i = 0; ppsz_options[i] != NULL; i++ )
939 asprintf( &psz_name, "%s%s", psz_prefix,
940 *ppsz_options[i] == '*' ? &ppsz_options[i][1] : ppsz_options[i] );
942 i_type = config_GetType( p_this, psz_name );
944 var_Create( p_this, psz_name, i_type | VLC_VAR_DOINHERIT );
948 /* Now parse options and set value */
949 if( psz_prefix == NULL ) psz_prefix = "";
954 vlc_bool_t b_yes = VLC_TRUE;
955 vlc_bool_t b_once = VLC_FALSE;
957 if( cfg->psz_name == NULL || *cfg->psz_name == '\0' )
962 for( i = 0; ppsz_options[i] != NULL; i++ )
964 if( !strcmp( ppsz_options[i], cfg->psz_name ) )
968 if( ( !strncmp( cfg->psz_name, "no-", 3 ) &&
969 !strcmp( ppsz_options[i], cfg->psz_name + 3 ) ) ||
970 ( !strncmp( cfg->psz_name, "no", 2 ) &&
971 !strcmp( ppsz_options[i], cfg->psz_name + 2 ) ) )
977 if( *ppsz_options[i] == '*' &&
978 !strcmp( &ppsz_options[i][1], cfg->psz_name ) )
985 if( ppsz_options[i] == NULL )
987 msg_Warn( p_this, "option %s is unknown", cfg->psz_name );
993 asprintf( &psz_name, "%s%s", psz_prefix, b_once ? &ppsz_options[i][1] : ppsz_options[i] );
995 /* get the type of the variable */
996 i_type = config_GetType( p_this, psz_name );
999 msg_Warn( p_this, "unknown option %s (value=%s)",
1000 cfg->psz_name, cfg->psz_value );
1003 if( i_type != VLC_VAR_BOOL && cfg->psz_value == NULL )
1005 msg_Warn( p_this, "missing value for option %s", cfg->psz_name );
1008 if( i_type != VLC_VAR_STRING && b_once )
1010 msg_Warn( p_this, "*option_name need to be a string option" );
1019 case VLC_VAR_INTEGER:
1020 val.i_int = strtol( cfg->psz_value ? cfg->psz_value : "0",
1024 val.f_float = atof( cfg->psz_value ? cfg->psz_value : "0" );
1026 case VLC_VAR_STRING:
1027 case VLC_VAR_MODULE:
1028 val.psz_string = cfg->psz_value;
1031 msg_Warn( p_this, "unhandled config var type" );
1032 memset( &val, 0, sizeof( vlc_value_t ) );
1039 var_Get( p_this, psz_name, &val2 );
1040 if( *val2.psz_string )
1042 free( val2.psz_string );
1043 msg_Dbg( p_this, "ignoring option %s (not first occurrence)", psz_name );
1046 free( val2.psz_string );
1048 var_Set( p_this, psz_name, val );
1049 msg_Dbg( p_this, "set sout option: %s to %s", psz_name, cfg->psz_value );
1059 * XXX name and p_cfg are used (-> do NOT free them)
1061 sout_stream_t *sout_StreamNew( sout_instance_t *p_sout, char *psz_chain )
1063 sout_stream_t *p_stream;
1067 msg_Err( p_sout, "invalid chain" );
1071 p_stream = vlc_object_create( p_sout, sizeof( sout_stream_t ) );
1075 msg_Err( p_sout, "out of memory" );
1079 p_stream->p_sout = p_sout;
1080 p_stream->p_sys = NULL;
1082 p_stream->psz_next =
1083 sout_CfgCreate( &p_stream->psz_name, &p_stream->p_cfg, psz_chain);
1085 msg_Dbg( p_sout, "stream=`%s'", p_stream->psz_name );
1087 vlc_object_attach( p_stream, p_sout );
1089 p_stream->p_module =
1090 module_Need( p_stream, "sout stream", p_stream->psz_name, VLC_TRUE );
1092 if( !p_stream->p_module )
1094 sout_StreamDelete( p_stream );
1101 void sout_StreamDelete( sout_stream_t *p_stream )
1103 msg_Dbg( p_stream, "destroying chain... (name=%s)", p_stream->psz_name );
1105 vlc_object_detach( p_stream );
1106 if( p_stream->p_module ) module_Unneed( p_stream, p_stream->p_module );
1108 FREE( p_stream->psz_name );
1109 FREE( p_stream->psz_next );
1111 sout_CfgDestroy( p_stream->p_cfg );
1113 msg_Dbg( p_stream, "destroying chain done" );
1114 vlc_object_destroy( p_stream );
1117 static char *_sout_stream_url_to_chain( vlc_object_t *p_this, char *psz_url )
1120 char *psz_chain, *p;
1122 mrl_Parse( &mrl, psz_url );
1123 p = psz_chain = malloc( 500 + strlen( mrl.psz_way ) +
1124 strlen( mrl.psz_access ) +
1125 strlen( mrl.psz_name ) );
1128 if( config_GetInt( p_this, "sout-display" ) )
1130 p += sprintf( p, "duplicate{dst=display,dst=std{mux=\"%s\","
1131 "access=\"%s\",url=\"%s\"}}",
1132 mrl.psz_way, mrl.psz_access, mrl.psz_name );
1136 p += sprintf( p, "std{mux=\"%s\",access=\"%s\",url=\"%s\"}",
1137 mrl.psz_way, mrl.psz_access, mrl.psz_name );
1141 return( psz_chain );