1 /*****************************************************************************
2 * standard.c: standard stream output module
3 *****************************************************************************
4 * Copyright (C) 2003-2004 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
36 /*****************************************************************************
38 *****************************************************************************/
39 #define ACCESS_TEXT N_("Output access method")
40 #define ACCESS_LONGTEXT N_( \
41 "Allows you to specify the output access method used for the streaming " \
43 #define MUX_TEXT N_("Output muxer")
44 #define MUX_LONGTEXT N_( \
45 "Allows you to specify the output muxer method used for the streaming " \
47 #define URL_TEXT N_("Output URL (deprecated)")
48 #define URL_LONGTEXT N_( \
49 "Allows you to specify the output URL used for the streaming output." \
50 "Deprecated, use dst instead." )
52 #define DST_TEXT N_("Output destination")
53 #define DST_LONGTEXT N_( \
54 "Allows you to specify the output destination used for the streaming output." )
56 #define NAME_TEXT N_("Session name")
57 #define NAME_LONGTEXT N_( \
58 "Name of the session that will be announced with SAP" )
60 #define GROUP_TEXT N_("Session groupname")
61 #define GROUP_LONGTEXT N_( \
62 "Name of the group that will be announced for the session" )
64 #define SAP_TEXT N_("SAP announcing")
65 #define SAP_LONGTEXT N_("Announce this session with SAP")
67 static int Open ( vlc_object_t * );
68 static void Close ( vlc_object_t * );
70 #define SOUT_CFG_PREFIX "sout-standard-"
73 set_shortname( _("Standard"));
74 set_description( _("Standard stream output") );
75 set_capability( "sout stream", 50 );
76 add_shortcut( "standard" );
77 add_shortcut( "std" );
78 set_category( CAT_SOUT );
79 set_subcategory( SUBCAT_SOUT_STREAM );
81 add_string( SOUT_CFG_PREFIX "access", "", NULL, ACCESS_TEXT,
82 ACCESS_LONGTEXT, VLC_FALSE );
83 add_string( SOUT_CFG_PREFIX "mux", "", NULL, MUX_TEXT,
84 MUX_LONGTEXT, VLC_FALSE );
85 add_string( SOUT_CFG_PREFIX "dst", "", NULL, DST_TEXT,
86 DST_LONGTEXT, VLC_FALSE );
87 add_deprecated( SOUT_CFG_PREFIX "url", VLC_FALSE );
89 add_bool( SOUT_CFG_PREFIX "sap", 0, NULL, SAP_TEXT, SAP_LONGTEXT, VLC_TRUE );
90 add_string( SOUT_CFG_PREFIX "name", "", NULL, NAME_TEXT, NAME_LONGTEXT,
92 add_string( SOUT_CFG_PREFIX "group", "", NULL, GROUP_TEXT, GROUP_LONGTEXT,
94 add_suppressed_bool( SOUT_CFG_PREFIX "sap-ipv6" );
96 set_callbacks( Open, Close );
100 /*****************************************************************************
101 * Exported prototypes
102 *****************************************************************************/
103 static const char *ppsz_sout_options[] = {
104 "access", "mux", "url", "dst",
105 "sap", "name", "group", NULL
108 #define DEFAULT_PORT 1234
110 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
111 static int Del ( sout_stream_t *, sout_stream_id_t * );
112 static int Send( sout_stream_t *, sout_stream_id_t *, block_t* );
114 struct sout_stream_sys_t
117 session_descriptor_t *p_session;
120 /*****************************************************************************
122 *****************************************************************************/
123 static int Open( vlc_object_t *p_this )
125 sout_stream_t *p_stream = (sout_stream_t*)p_this;
126 sout_instance_t *p_sout = p_stream->p_sout;
134 sout_access_out_t *p_access;
137 char *psz_mux_byext = NULL;
139 sout_CfgParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options,
142 var_Get( p_stream, SOUT_CFG_PREFIX "access", &val );
143 psz_access = *val.psz_string ? val.psz_string : NULL;
144 if( !*val.psz_string ) free( val.psz_string );
146 var_Get( p_stream, SOUT_CFG_PREFIX "mux", &val );
147 psz_mux = *val.psz_string ? val.psz_string : NULL;
148 if( !*val.psz_string ) free( val.psz_string );
151 var_Get( p_stream, SOUT_CFG_PREFIX "dst", &val );
152 psz_url = *val.psz_string ? val.psz_string : NULL;
153 if( !*val.psz_string ) free( val.psz_string );
155 p_stream->p_sys = malloc( sizeof( sout_stream_sys_t) );
156 p_stream->p_sys->p_session = NULL;
158 msg_Dbg( p_this, "creating `%s/%s://%s'", psz_access, psz_mux, psz_url );
160 /* ext -> muxer name */
161 if( psz_url && strrchr( psz_url, '.' ) )
164 static struct { char *ext; char *mux; } exttomux[] =
184 char *psz_ext = strrchr( psz_url, '.' ) + 1;
187 msg_Dbg( p_this, "extention is %s", psz_ext );
188 for( i = 0; exttomux[i].ext != NULL; i++ )
190 if( !strcasecmp( psz_ext, exttomux[i].ext ) )
192 psz_mux_byext = exttomux[i].mux;
196 msg_Dbg( p_this, "extention -> mux=%s", psz_mux_byext );
199 /* We fix access/mux to valid couple */
201 if( !psz_access && !psz_mux )
206 "no access _and_ no muxer, extention gives file/%s",
208 psz_access = strdup("file");
209 psz_mux = strdup(psz_mux_byext);
213 msg_Err( p_stream, "no access _and_ no muxer (fatal error)" );
218 if( psz_access && !psz_mux )
220 /* access given, no mux */
221 if( !strncmp( psz_access, "mmsh", 4 ) )
223 psz_mux = strdup("asfh");
225 else if( !strncmp( psz_access, "udp", 3 ) ||
226 !strncmp( psz_access, "rtp", 3 ) )
228 psz_mux = strdup("ts");
230 else if( psz_mux_byext )
232 psz_mux = strdup(psz_mux_byext);
236 msg_Err( p_stream, "no mux specified or found by extention" );
240 else if( psz_mux && !psz_access )
242 /* mux given, no access */
243 if( !strncmp( psz_mux, "asfh", 4 ) )
245 psz_access = strdup("mmsh");
250 psz_access = strdup("file");
254 /* fix or warn of incompatible couple */
255 if( psz_mux && psz_access )
257 if( !strncmp( psz_access, "mmsh", 4 ) &&
258 strncmp( psz_mux, "asfh", 4 ) )
260 char *p = strchr( psz_mux,'{' );
262 msg_Warn( p_stream, "fixing to mmsh/asfh" );
265 /* -> a little memleak but ... */
266 psz_mux = malloc( strlen( "asfh" ) + strlen( p ) + 1);
267 sprintf( psz_mux, "asfh%s", p );
271 psz_mux = strdup("asfh");
274 else if( ( !strncmp( psz_access, "rtp", 3 ) ||
275 !strncmp( psz_access, "udp", 3 ) ) &&
276 strncmp( psz_mux, "ts", 2 ) )
278 msg_Err( p_stream, "for now udp and rtp are only valid with TS" );
280 else if( strncmp( psz_access, "file", 4 ) &&
281 ( !strncmp( psz_mux, "mov", 3 ) ||
282 !strncmp( psz_mux, "mp4", 3 ) ) )
284 msg_Err( p_stream, "mov and mp4 work only with file output" );
288 msg_Dbg( p_this, "using `%s/%s://%s'", psz_access, psz_mux, psz_url );
290 /* *** find and open appropriate access module *** */
291 p_access = sout_AccessOutNew( p_sout, psz_access, psz_url );
292 if( p_access == NULL )
294 msg_Err( p_stream, "no suitable sout access module for `%s/%s://%s'",
295 psz_access, psz_mux, psz_url );
296 if( psz_access ) free( psz_access );
297 if( psz_mux ) free( psz_mux );
300 msg_Dbg( p_stream, "access opened" );
302 /* *** find and open appropriate mux module *** */
303 p_mux = sout_MuxNew( p_sout, psz_mux, p_access );
306 msg_Err( p_stream, "no suitable sout mux module for `%s/%s://%s'",
307 psz_access, psz_mux, psz_url );
309 sout_AccessOutDelete( p_access );
310 if( psz_access ) free( psz_access );
311 if( psz_mux ) free( psz_mux );
314 msg_Dbg( p_stream, "mux opened" );
316 /* *** Create the SAP Session structure *** */
317 var_Get( p_stream, SOUT_CFG_PREFIX "sap", &val );
319 ( strstr( psz_access, "udp" ) || strstr( psz_access , "rtp" ) ) )
321 session_descriptor_t *p_session = sout_AnnounceSessionCreate();
322 announce_method_t *p_method =
323 sout_AnnounceMethodCreate( METHOD_TYPE_SAP );
326 var_Get( p_stream, SOUT_CFG_PREFIX "name", &val );
327 if( *val.psz_string )
328 p_session->psz_name = val.psz_string;
331 p_session->psz_name = strdup( psz_url );
332 free( val.psz_string );
335 var_Get( p_stream, SOUT_CFG_PREFIX "group", &val );
336 if( *val.psz_string )
337 p_session->psz_group = val.psz_string;
339 free( val.psz_string );
341 /* Now, parse the URL to extract host and port */
342 vlc_UrlParse( &url, psz_url , 0);
346 if( url.i_port == 0 ) url.i_port = DEFAULT_PORT;
348 p_session->psz_uri = strdup( url.psz_host );
349 p_session->i_port = url.i_port;
350 p_session->psz_sdp = NULL;
352 var_Get( p_access, "sout-udp-ttl", &val );
353 p_session->i_ttl = val.i_int;
354 p_session->i_payload = 33;
355 p_session->b_rtp = strstr( psz_access, "rtp") ? 1 : 0;
357 msg_Info( p_this, "SAP Enabled");
359 sout_AnnounceRegister( p_sout, p_session, p_method );
360 p_stream->p_sys->p_session = p_session;
362 vlc_UrlClean( &url );
367 p_stream->pf_add = Add;
368 p_stream->pf_del = Del;
369 p_stream->pf_send = Send;
371 p_stream->p_sys->p_mux = p_mux;
373 if( psz_access ) free( psz_access );
374 if( psz_mux ) free( psz_mux );
375 if( psz_url ) free( psz_url );
381 /*****************************************************************************
383 *****************************************************************************/
384 static void Close( vlc_object_t * p_this )
386 sout_stream_t *p_stream = (sout_stream_t*)p_this;
387 sout_stream_sys_t *p_sys = p_stream->p_sys;
388 sout_access_out_t *p_access = p_sys->p_mux->p_access;
390 if( p_sys->p_session != NULL )
392 sout_AnnounceUnRegister( p_stream->p_sout, p_sys->p_session );
393 sout_AnnounceSessionDestroy( p_sys->p_session );
397 sout_MuxDelete( p_sys->p_mux );
398 sout_AccessOutDelete( p_access );
403 struct sout_stream_id_t
405 sout_input_t *p_input;
409 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
411 sout_stream_sys_t *p_sys = p_stream->p_sys;
412 sout_stream_id_t *id;
414 id = malloc( sizeof( sout_stream_id_t ) );
415 if( ( id->p_input = sout_MuxAddStream( p_sys->p_mux, p_fmt ) ) == NULL )
425 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
427 sout_stream_sys_t *p_sys = p_stream->p_sys;
429 sout_MuxDeleteStream( p_sys->p_mux, id->p_input );
436 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
439 sout_stream_sys_t *p_sys = p_stream->p_sys;
441 sout_MuxSendBuffer( p_sys->p_mux, id->p_input, p_buffer );