1 /*****************************************************************************
2 * stream_output.c : stream output module
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: stream_output.c,v 1.27 2003/04/29 21:32:21 fenrir Exp $
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
29 #include <stdlib.h> /* free() */
30 #include <stdio.h> /* sprintf() */
31 #include <string.h> /* strerror() */
37 /*****************************************************************************
39 *****************************************************************************/
40 #define sout_stream_url_to_chain( p, s ) _sout_stream_url_to_chain( VLC_OBJECT(p), s )
41 static char *_sout_stream_url_to_chain( vlc_object_t *, char * );
57 /* mrl_Parse: parse psz_mrl and fill p_mrl */
58 static int mrl_Parse( mrl_t *p_mrl, char *psz_mrl );
59 /* mrl_Clean: clean p_mrl after a call to mrl_Parse */
60 static void mrl_Clean( mrl_t *p_mrl );
62 #define FREE( p ) if( p ) { free( p ); (p) = NULL; }
64 /*****************************************************************************
65 * sout_NewInstance: creates a new stream output instance
66 *****************************************************************************/
67 sout_instance_t * __sout_NewInstance ( vlc_object_t *p_parent,
70 sout_instance_t *p_sout;
72 /* *** Allocate descriptor *** */
73 p_sout = vlc_object_create( p_parent, VLC_OBJECT_SOUT );
76 msg_Err( p_parent, "out of memory" );
80 /* *** init descriptor *** */
81 p_sout->psz_sout = strdup( psz_dest );
82 p_sout->i_preheader = 0;
85 vlc_mutex_init( p_sout, &p_sout->lock );
86 if( psz_dest && psz_dest[0] == '#' )
88 p_sout->psz_chain = strdup( &psz_dest[1] );
92 p_sout->psz_chain = sout_stream_url_to_chain( p_sout, psz_dest );
93 msg_Dbg( p_sout, "using sout chain=`%s'", p_sout->psz_chain );
96 p_sout->p_stream = sout_stream_new( p_sout, p_sout->psz_chain );
98 if( p_sout->p_stream == NULL )
100 msg_Err( p_sout, "stream chained failed for `%s'", p_sout->psz_chain );
102 FREE( p_sout->psz_sout );
103 FREE( p_sout->psz_chain );
105 vlc_object_destroy( p_sout );
109 vlc_object_attach( p_sout, p_parent );
113 /*****************************************************************************
114 * sout_DeleteInstance: delete a previously allocated instance
115 *****************************************************************************/
116 void sout_DeleteInstance( sout_instance_t * p_sout )
119 vlc_object_detach( p_sout );
121 /* *** free all string *** */
122 FREE( p_sout->psz_sout );
123 FREE( p_sout->psz_chain );
125 sout_stream_delete( p_sout->p_stream );
126 vlc_mutex_destroy( &p_sout->lock );
128 /* *** free structure *** */
129 vlc_object_destroy( p_sout );
132 /*****************************************************************************
134 *****************************************************************************/
135 sout_packetizer_input_t *__sout_InputNew( vlc_object_t *p_this,
136 sout_format_t *p_fmt )
138 sout_instance_t *p_sout = NULL;
139 sout_packetizer_input_t *p_input;
143 /* search an stream output */
144 for( i_try = 0; i_try < 12; i_try++ )
146 p_sout = vlc_object_find( p_this, VLC_OBJECT_SOUT, FIND_ANYWHERE );
153 msg_Dbg( p_this, "waiting for sout" );
158 msg_Err( p_this, "cannot find any stream ouput" );
162 msg_Dbg( p_sout, "adding a new input" );
164 /* *** create a packetizer input *** */
165 p_input = malloc( sizeof( sout_packetizer_input_t ) );
166 p_input->p_sout = p_sout;
167 p_input->p_fmt = p_fmt;
169 if( p_fmt->i_fourcc == VLC_FOURCC( 'n', 'u', 'l', 'l' ) )
171 vlc_object_release( p_sout );
175 /* *** add it to the stream chain */
176 vlc_mutex_lock( &p_sout->lock );
177 p_input->id = p_sout->p_stream->pf_add( p_sout->p_stream,
179 vlc_mutex_unlock( &p_sout->lock );
181 vlc_object_release( p_sout );
183 if( p_input->id == NULL )
193 int sout_InputDelete( sout_packetizer_input_t *p_input )
195 sout_instance_t *p_sout = p_input->p_sout;
197 msg_Dbg( p_sout, "removing an input" );
199 if( p_input->p_fmt->i_fourcc != VLC_FOURCC( 'n', 'u', 'l', 'l' ) )
201 vlc_mutex_lock( &p_sout->lock );
202 p_sout->p_stream->pf_del( p_sout->p_stream, p_input->id );
203 vlc_mutex_unlock( &p_sout->lock );
208 return( VLC_SUCCESS);
212 int sout_InputSendBuffer( sout_packetizer_input_t *p_input, sout_buffer_t *p_buffer )
214 sout_instance_t *p_sout = p_input->p_sout;
217 if( p_input->p_fmt->i_fourcc == VLC_FOURCC( 'n', 'u', 'l', 'l' ) )
219 sout_BufferDelete( p_input->p_sout, p_buffer );
223 vlc_mutex_lock( &p_sout->lock );
224 i_ret = p_sout->p_stream->pf_send( p_sout->p_stream, p_input->id, p_buffer );
225 vlc_mutex_unlock( &p_sout->lock );
230 /*****************************************************************************
231 * sout_AccessOutNew: allocate a new access out
232 *****************************************************************************/
233 sout_access_out_t *sout_AccessOutNew( sout_instance_t *p_sout,
234 char *psz_access, char *psz_name )
236 sout_access_out_t *p_access;
238 if( !( p_access = vlc_object_create( p_sout,
239 sizeof( sout_access_out_t ) ) ) )
241 msg_Err( p_sout, "out of memory" );
244 p_access->psz_access = strdup( psz_access ? psz_access : "" );
245 p_access->psz_name = strdup( psz_name ? psz_name : "" );
246 p_access->p_sout = p_sout;
247 p_access->p_sys = NULL;
248 p_access->pf_seek = NULL;
249 p_access->pf_write = NULL;
251 p_access->p_module = module_Need( p_access,
253 p_access->psz_access );;
255 if( !p_access->p_module )
257 free( p_access->psz_access );
258 free( p_access->psz_name );
259 vlc_object_destroy( p_access );
265 /*****************************************************************************
266 * sout_AccessDelete: delete an access out
267 *****************************************************************************/
268 void sout_AccessOutDelete( sout_access_out_t *p_access )
270 if( p_access->p_module )
272 module_Unneed( p_access, p_access->p_module );
274 free( p_access->psz_access );
275 free( p_access->psz_name );
277 vlc_object_destroy( p_access );
280 /*****************************************************************************
282 *****************************************************************************/
283 int sout_AccessOutSeek( sout_access_out_t *p_access, off_t i_pos )
285 return( p_access->pf_seek( p_access, i_pos ) );
288 /*****************************************************************************
290 *****************************************************************************/
291 int sout_AccessOutWrite( sout_access_out_t *p_access, sout_buffer_t *p_buffer )
293 return( p_access->pf_write( p_access, p_buffer ) );
297 /*****************************************************************************
298 * MuxNew: allocate a new mux
299 *****************************************************************************/
300 sout_mux_t * sout_MuxNew ( sout_instance_t *p_sout,
302 sout_access_out_t *p_access )
306 p_mux = vlc_object_create( p_sout,
307 sizeof( sout_mux_t ) );
310 msg_Err( p_sout, "out of memory" );
314 p_mux->p_sout = p_sout;
315 p_mux->psz_mux = strdup( psz_mux ? psz_mux : "" );
316 p_mux->p_access = p_access;
317 p_mux->i_preheader = 0;
318 p_mux->pf_capacity = NULL;
319 p_mux->pf_addstream = NULL;
320 p_mux->pf_delstream = NULL;
321 p_mux->pf_mux = NULL;
322 p_mux->i_nb_inputs = 0;
323 p_mux->pp_inputs = NULL;
327 p_mux->p_module = module_Need( p_mux,
330 if( p_mux->p_module == NULL )
332 FREE( p_mux->psz_mux );
334 vlc_object_destroy( p_mux );
338 /* *** probe mux capacity *** */
339 if( p_mux->pf_capacity )
342 if( p_mux->pf_capacity( p_mux,
343 SOUT_MUX_CAP_GET_ADD_STREAM_ANY_TIME,
344 NULL, (void*)&b_answer ) != SOUT_MUX_CAP_ERR_OK )
346 b_answer = VLC_FALSE;
350 msg_Dbg( p_sout, "muxer support adding stream at any time" );
351 p_mux->b_add_stream_any_time = VLC_TRUE;
352 p_mux->b_waiting_stream = VLC_FALSE;
356 p_mux->b_add_stream_any_time = VLC_FALSE;
357 p_mux->b_waiting_stream = VLC_TRUE;
362 p_mux->b_add_stream_any_time = VLC_FALSE;
363 p_mux->b_waiting_stream = VLC_TRUE;
365 p_mux->i_add_stream_start = -1;
370 void sout_MuxDelete ( sout_mux_t *p_mux )
372 if( p_mux->p_module )
374 module_Unneed( p_mux, p_mux->p_module );
376 free( p_mux->psz_mux );
378 vlc_object_destroy( p_mux );
381 sout_input_t *sout_MuxAddStream( sout_mux_t *p_mux,
382 sout_format_t *p_fmt )
384 sout_input_t *p_input;
386 if( !p_mux->b_add_stream_any_time && !p_mux->b_waiting_stream)
388 msg_Err( p_mux, "cannot add a new stream (unsuported while muxing for this format)" );
391 if( p_mux->i_add_stream_start < 0 )
393 /* we wait for one second */
394 p_mux->i_add_stream_start = mdate();
397 msg_Dbg( p_mux, "adding a new input" );
399 /* create a new sout input */
400 p_input = malloc( sizeof( sout_input_t ) );
401 p_input->p_sout = p_mux->p_sout;
402 p_input->p_fmt = p_fmt;
403 p_input->p_fifo = sout_FifoCreate( p_mux->p_sout );
404 p_input->p_sys = NULL;
406 TAB_APPEND( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input );
407 if( p_mux->pf_addstream( p_mux, p_input ) < 0 )
409 msg_Err( p_mux, "cannot add this stream" );
410 sout_MuxDeleteStream( p_mux, p_input );
417 void sout_MuxDeleteStream ( sout_mux_t *p_mux,
418 sout_input_t *p_input )
422 TAB_FIND( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input, i_index );
425 if( p_mux->pf_delstream( p_mux, p_input ) < 0 )
427 msg_Err( p_mux, "cannot del this stream from mux" );
430 /* remove the entry */
431 TAB_REMOVE( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input );
433 if( p_mux->i_nb_inputs == 0 )
435 msg_Warn( p_mux, "no more input stream for this mux" );
438 sout_FifoDestroy( p_mux->p_sout, p_input->p_fifo );
443 void sout_MuxSendBuffer ( sout_mux_t *p_mux,
444 sout_input_t *p_input,
445 sout_buffer_t *p_buffer )
447 sout_FifoPut( p_input->p_fifo, p_buffer );
449 if( p_mux->b_waiting_stream )
451 if( p_mux->i_add_stream_start > 0 &&
452 p_mux->i_add_stream_start + (mtime_t)1500000 < mdate() )
454 /* more than 1.5 second, start muxing */
455 p_mux->b_waiting_stream = VLC_FALSE;
462 p_mux->pf_mux( p_mux );
467 sout_fifo_t *sout_FifoCreate( sout_instance_t *p_sout )
471 if( !( p_fifo = malloc( sizeof( sout_fifo_t ) ) ) )
476 vlc_mutex_init( p_sout, &p_fifo->lock );
477 vlc_cond_init ( p_sout, &p_fifo->wait );
479 p_fifo->p_first = NULL;
480 p_fifo->pp_last = &p_fifo->p_first;
485 void sout_FifoFree( sout_instance_t *p_sout, sout_fifo_t *p_fifo )
487 sout_buffer_t *p_buffer;
489 vlc_mutex_lock( &p_fifo->lock );
490 p_buffer = p_fifo->p_first;
493 sout_buffer_t *p_next;
494 p_next = p_buffer->p_next;
495 sout_BufferDelete( p_sout, p_buffer );
498 vlc_mutex_unlock( &p_fifo->lock );
502 void sout_FifoDestroy( sout_instance_t *p_sout, sout_fifo_t *p_fifo )
504 sout_FifoFree( p_sout, p_fifo );
505 vlc_mutex_destroy( &p_fifo->lock );
506 vlc_cond_destroy ( &p_fifo->wait );
511 void sout_FifoPut( sout_fifo_t *p_fifo, sout_buffer_t *p_buffer )
513 vlc_mutex_lock( &p_fifo->lock );
517 *p_fifo->pp_last = p_buffer;
518 p_fifo->pp_last = &p_buffer->p_next;
521 p_buffer = p_buffer->p_next;
525 /* warm there is data in this fifo */
526 vlc_cond_signal( &p_fifo->wait );
527 vlc_mutex_unlock( &p_fifo->lock );
530 sout_buffer_t *sout_FifoGet( sout_fifo_t *p_fifo )
532 sout_buffer_t *p_buffer;
534 vlc_mutex_lock( &p_fifo->lock );
536 if( p_fifo->p_first == NULL )
538 vlc_cond_wait( &p_fifo->wait, &p_fifo->lock );
541 p_buffer = p_fifo->p_first;
543 p_fifo->p_first = p_buffer->p_next;
546 if( p_fifo->p_first == NULL )
548 p_fifo->pp_last = &p_fifo->p_first;
551 vlc_mutex_unlock( &p_fifo->lock );
553 p_buffer->p_next = NULL;
557 sout_buffer_t *sout_FifoShow( sout_fifo_t *p_fifo )
559 sout_buffer_t *p_buffer;
561 vlc_mutex_lock( &p_fifo->lock );
563 if( p_fifo->p_first == NULL )
565 vlc_cond_wait( &p_fifo->wait, &p_fifo->lock );
568 p_buffer = p_fifo->p_first;
570 vlc_mutex_unlock( &p_fifo->lock );
575 sout_buffer_t *sout_BufferNew( sout_instance_t *p_sout, size_t i_size )
577 sout_buffer_t *p_buffer;
581 msg_Dbg( p_sout, "allocating an new buffer, size:%d", (uint32_t)i_size );
584 p_buffer = malloc( sizeof( sout_buffer_t ) );
585 i_preheader = p_sout->i_preheader;
589 p_buffer->p_allocated_buffer = malloc( i_size + i_preheader );
590 p_buffer->p_buffer = p_buffer->p_allocated_buffer + i_preheader;
594 p_buffer->p_allocated_buffer = NULL;
595 p_buffer->p_buffer = NULL;
597 p_buffer->i_allocated_size = i_size + i_preheader;
598 p_buffer->i_buffer_size = i_size;
600 p_buffer->i_size = i_size;
601 p_buffer->i_length = 0;
604 p_buffer->i_bitrate = 0;
605 p_buffer->i_flags = 0x0000;
606 p_buffer->p_next = NULL;
610 int sout_BufferRealloc( sout_instance_t *p_sout, sout_buffer_t *p_buffer, size_t i_size )
616 "realloc buffer old size:%d new size:%d",
617 (uint32_t)p_buffer->i_allocated_size,
621 i_preheader = p_buffer->p_buffer - p_buffer->p_allocated_buffer;
623 if( !( p_buffer->p_allocated_buffer = realloc( p_buffer->p_allocated_buffer, i_size + i_preheader ) ) )
625 msg_Err( p_sout, "realloc failed" );
626 p_buffer->i_allocated_size = 0;
627 p_buffer->i_buffer_size = 0;
628 p_buffer->i_size = 0;
629 p_buffer->p_buffer = NULL;
632 p_buffer->p_buffer = p_buffer->p_allocated_buffer + i_preheader;
634 p_buffer->i_allocated_size = i_size + i_preheader;
635 p_buffer->i_buffer_size = i_size;
640 int sout_BufferReallocFromPreHeader( sout_instance_t *p_sout, sout_buffer_t *p_buffer, size_t i_size )
644 i_preheader = p_buffer->p_buffer - p_buffer->p_allocated_buffer;
646 if( i_preheader < i_size )
651 p_buffer->p_buffer -= i_size;
652 p_buffer->i_size += i_size;
653 p_buffer->i_buffer_size += i_size;
658 int sout_BufferDelete( sout_instance_t *p_sout, sout_buffer_t *p_buffer )
661 msg_Dbg( p_sout, "freeing buffer, size:%d", p_buffer->i_size );
663 if( p_buffer->p_allocated_buffer )
665 free( p_buffer->p_allocated_buffer );
671 sout_buffer_t *sout_BufferDuplicate( sout_instance_t *p_sout,
672 sout_buffer_t *p_buffer )
674 sout_buffer_t *p_dup;
676 p_dup = sout_BufferNew( p_sout, p_buffer->i_size );
678 p_dup->i_bitrate= p_buffer->i_bitrate;
679 p_dup->i_dts = p_buffer->i_dts;
680 p_dup->i_pts = p_buffer->i_pts;
681 p_dup->i_length = p_buffer->i_length;
682 p_dup->i_flags = p_buffer->i_flags;
683 p_sout->p_vlc->pf_memcpy( p_dup->p_buffer, p_buffer->p_buffer, p_buffer->i_size );
688 void sout_BufferChain( sout_buffer_t **pp_chain,
689 sout_buffer_t *p_buffer )
691 if( *pp_chain == NULL )
693 *pp_chain = p_buffer;
695 else if( p_buffer != NULL )
697 sout_buffer_t *p = *pp_chain;
704 p->p_next = p_buffer;
708 static int mrl_Parse( mrl_t *p_mrl, char *psz_mrl )
710 char * psz_dup = strdup( psz_mrl );
711 char * psz_parser = psz_dup;
712 char * psz_access = "";
714 char * psz_name = "";
716 /* *** first parse psz_dest */
717 while( *psz_parser && *psz_parser != ':' )
719 if( *psz_parser == '{' )
721 while( *psz_parser && *psz_parser != '}' )
735 #if defined( WIN32 ) || defined( UNDER_CE )
736 if( psz_parser - psz_dup == 1 )
738 /* msg_Warn( p_sout, "drive letter %c: found in source string",
746 psz_access = psz_way = "";
751 *psz_parser++ = '\0';
753 /* let's skip '//' */
754 if( psz_parser[0] == '/' && psz_parser[1] == '/' )
759 psz_name = psz_parser ;
761 /* Come back to parse the access and mux plug-ins */
762 psz_parser = psz_dup;
769 else if( *psz_parser == '/' )
777 psz_access = psz_parser;
779 while( *psz_parser && *psz_parser != '/' )
781 if( *psz_parser == '{' )
783 while( *psz_parser && *psz_parser != '}' )
798 if( *psz_parser == '/' )
800 *psz_parser++ = '\0';
811 psz_way = psz_parser;
815 p_mrl->psz_access = strdup( psz_access );
816 p_mrl->psz_way = strdup( psz_way );
817 p_mrl->psz_name = strdup( psz_name );
820 return( VLC_SUCCESS );
824 /* mrl_Clean: clean p_mrl after a call to mrl_Parse */
825 static void mrl_Clean( mrl_t *p_mrl )
827 FREE( p_mrl->psz_access );
828 FREE( p_mrl->psz_way );
829 FREE( p_mrl->psz_name );
833 /****************************************************************************
834 ****************************************************************************
838 ****************************************************************************
839 ****************************************************************************/
841 /* create a complete chain */
843 module{option=*:option=*}[:module{option=*:...}]
846 static char *_strndup( char *str, int i_len )
850 p = malloc( i_len + 1 );
851 strncpy( p, str, i_len );
858 * parse module{options=str, option="str "}:
859 * return a pointer on the rest
860 * XXX: psz_chain is modified
862 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
863 /* go accross " " and { } */
864 static char *_get_chain_end( char *str )
872 if( *p == '{' || *p == '"' || *p == '\'')
898 else if( *p == '{' && c == '}' )
900 p = _get_chain_end( p );
908 else if( *p == '\0' || *p == ',' || *p == '}' || *p == ' ' || *p == '\t' )
919 char * sout_cfg_parser( char **ppsz_name, sout_cfg_t **pp_cfg, char *psz_chain )
921 sout_cfg_t *p_cfg = NULL;
929 while( *p && *p != '{' && *p != ':' && *p != ' ' && *p != '\t' )
939 *ppsz_name = _strndup( psz_chain, p - psz_chain );
941 //fprintf( stderr, "name=%s - rest=%s\n", *ppsz_name, p );
959 while( *p && *p != '=' && *p != ',' && *p != '}' && *p != ' ' && *p != '\t' )
964 //fprintf( stderr, "name=%s - rest=%s\n", psz_name, p );
967 fprintf( stderr, "invalid options (empty)" );
971 cfg.psz_name = _strndup( psz_name, p - psz_name );
988 end = strchr( p, '"' );
992 // fprintf( stderr, "##%s -- %s\n", p, end );
993 cfg.psz_value = _strndup( p, end - p );
998 cfg.psz_value = strdup( p );
1006 while( *p && *p != ',' && *p != '}' && *p != ' ' && *p != '\t' )
1010 cfg.psz_value = _strndup( psz_value, p - psz_value );
1013 end = _get_chain_end( p );
1016 cfg.psz_value = NULL;
1020 if( *p == '\'' || *p =='"' || *p == '{' )
1027 cfg.psz_value = NULL;
1031 cfg.psz_value = _strndup( p, end - p );
1040 cfg.psz_value = NULL;
1046 p_cfg->p_next = malloc( sizeof( sout_cfg_t ) );
1047 memcpy( p_cfg->p_next, &cfg, sizeof( sout_cfg_t ) );
1049 p_cfg = p_cfg->p_next;
1053 p_cfg = malloc( sizeof( sout_cfg_t ) );
1054 memcpy( p_cfg, &cfg, sizeof( sout_cfg_t ) );
1075 return( strdup( p + 1 ) );
1086 * XXX name and p_cfg are used (-> do NOT free them)
1088 sout_stream_t *sout_stream_new( sout_instance_t *p_sout,
1091 sout_stream_t *p_stream;
1093 p_stream = vlc_object_create( p_sout, sizeof( sout_stream_t ) );
1097 msg_Err( p_sout, "out of memory" );
1101 p_stream->p_sout = p_sout;
1102 p_stream->p_sys = NULL;
1104 p_stream->psz_next = sout_cfg_parser( &p_stream->psz_name, &p_stream->p_cfg, psz_chain);
1105 msg_Dbg( p_sout, "stream=`%s'", p_stream->psz_name );
1107 p_stream->p_module =
1108 module_Need( p_stream, "sout stream", p_stream->psz_name );
1110 if( !p_stream->p_module )
1113 vlc_object_destroy( p_stream );
1120 void sout_stream_delete( sout_stream_t *p_stream )
1124 msg_Dbg( p_stream, "destroying chain... (name=%s)", p_stream->psz_name );
1125 module_Unneed( p_stream, p_stream->p_module );
1127 FREE( p_stream->psz_name );
1128 FREE( p_stream->psz_next );
1130 p_cfg = p_stream->p_cfg;
1131 while( p_cfg != NULL )
1135 p_next = p_cfg->p_next;
1137 FREE( p_cfg->psz_name );
1138 FREE( p_cfg->psz_value );
1144 msg_Dbg( p_stream, "destroying chain done" );
1145 vlc_object_destroy( p_stream );
1148 static char *_sout_stream_url_to_chain( vlc_object_t *p_this, char *psz_url )
1151 char *psz_chain, *p;
1152 char *psz_vcodec, *psz_acodec;
1154 mrl_Parse( &mrl, psz_url );
1155 p = psz_chain = malloc( 500 + strlen( mrl.psz_way ) + strlen( mrl.psz_access ) + strlen( mrl.psz_name ) );
1157 psz_vcodec = config_GetPsz( p_this, "sout-vcodec" );
1158 if( psz_vcodec && *psz_vcodec == '\0')
1162 psz_acodec = config_GetPsz( p_this, "sout-acodec" );
1163 if( psz_acodec && *psz_acodec == '\0' )
1167 /* set transcoding */
1168 if( psz_vcodec || psz_acodec )
1170 p += sprintf( p, "transcode{" );
1175 p += sprintf( p, "vcodec=%s,", psz_vcodec );
1177 if( ( br = config_GetInt( p_this, "sout-vbitrate" ) ) > 0 )
1179 p += sprintf( p, "vb=%d,", br * 1000 );
1187 p += sprintf( p, "acodec=%s,", psz_acodec );
1188 if( ( br = config_GetInt( p_this, "sout-abitrate" ) ) > 0 )
1190 p += sprintf( p, "ab=%d,", br * 1000 );
1195 p += sprintf( p, "}:" );
1199 if( config_GetInt( p_this, "sout-display" ) )
1201 p += sprintf( p, "duplicate{dst=display,dst=std{mux=%s,access=%s,url=\"%s\"}}", mrl.psz_way, mrl.psz_access, mrl.psz_name );
1205 p += sprintf( p, "std{mux=%s,access=%s,url=\"%s\"}", mrl.psz_way, mrl.psz_access, mrl.psz_name );
1208 return( psz_chain );