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 DST_TEXT N_("Output destination")
48 #define DST_LONGTEXT N_( \
49 "Allows you to specify the output destination used for the streaming output." )
51 #define NAME_TEXT N_("Session name")
52 #define NAME_LONGTEXT N_( \
53 "Name of the session that will be announced with SAP." )
55 #define GROUP_TEXT N_("Session groupname")
56 #define GROUP_LONGTEXT N_( \
57 "Name of the group that will be announced for the session." )
59 #define SAP_TEXT N_("SAP announcing")
60 #define SAP_LONGTEXT N_("Announce this session with SAP.")
62 static int Open ( vlc_object_t * );
63 static void Close ( vlc_object_t * );
65 #define SOUT_CFG_PREFIX "sout-standard-"
68 set_shortname( _("Standard"));
69 set_description( _("Standard stream output") );
70 set_capability( "sout stream", 50 );
71 add_shortcut( "standard" );
72 add_shortcut( "std" );
73 set_category( CAT_SOUT );
74 set_subcategory( SUBCAT_SOUT_STREAM );
76 add_string( SOUT_CFG_PREFIX "access", "", NULL, ACCESS_TEXT,
77 ACCESS_LONGTEXT, VLC_FALSE );
78 add_string( SOUT_CFG_PREFIX "mux", "", NULL, MUX_TEXT,
79 MUX_LONGTEXT, VLC_FALSE );
80 add_string( SOUT_CFG_PREFIX "dst", "", NULL, DST_TEXT,
81 DST_LONGTEXT, VLC_FALSE );
82 add_deprecated( SOUT_CFG_PREFIX "url", VLC_FALSE );
84 add_bool( SOUT_CFG_PREFIX "sap", 0, NULL, SAP_TEXT, SAP_LONGTEXT, VLC_TRUE );
85 add_string( SOUT_CFG_PREFIX "name", "", NULL, NAME_TEXT, NAME_LONGTEXT,
87 add_string( SOUT_CFG_PREFIX "group", "", NULL, GROUP_TEXT, GROUP_LONGTEXT,
89 add_suppressed_bool( SOUT_CFG_PREFIX "sap-ipv6" );
91 set_callbacks( Open, Close );
95 /*****************************************************************************
97 *****************************************************************************/
98 static const char *ppsz_sout_options[] = {
99 "access", "mux", "url", "dst",
100 "sap", "name", "group", NULL
103 #define DEFAULT_PORT 1234
105 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
106 static int Del ( sout_stream_t *, sout_stream_id_t * );
107 static int Send( sout_stream_t *, sout_stream_id_t *, block_t* );
109 struct sout_stream_sys_t
112 session_descriptor_t *p_session;
115 /*****************************************************************************
117 *****************************************************************************/
118 static int Open( vlc_object_t *p_this )
120 sout_stream_t *p_stream = (sout_stream_t*)p_this;
121 sout_instance_t *p_sout = p_stream->p_sout;
129 sout_access_out_t *p_access;
132 char *psz_mux_byext = NULL;
134 sout_CfgParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options,
137 var_Get( p_stream, SOUT_CFG_PREFIX "access", &val );
138 psz_access = *val.psz_string ? val.psz_string : NULL;
139 if( !*val.psz_string ) free( val.psz_string );
141 var_Get( p_stream, SOUT_CFG_PREFIX "mux", &val );
142 psz_mux = *val.psz_string ? val.psz_string : NULL;
143 if( !*val.psz_string ) free( val.psz_string );
146 var_Get( p_stream, SOUT_CFG_PREFIX "dst", &val );
147 psz_url = *val.psz_string ? val.psz_string : NULL;
148 if( !*val.psz_string ) free( val.psz_string );
150 p_stream->p_sys = malloc( sizeof( sout_stream_sys_t) );
151 p_stream->p_sys->p_session = NULL;
153 msg_Dbg( p_this, "creating `%s/%s://%s'", psz_access, psz_mux, psz_url );
155 /* ext -> muxer name */
156 if( psz_url && strrchr( psz_url, '.' ) )
159 static struct { char *ext; char *mux; } exttomux[] =
179 char *psz_ext = strrchr( psz_url, '.' ) + 1;
182 msg_Dbg( p_this, "extention is %s", psz_ext );
183 for( i = 0; exttomux[i].ext != NULL; i++ )
185 if( !strcasecmp( psz_ext, exttomux[i].ext ) )
187 psz_mux_byext = exttomux[i].mux;
191 msg_Dbg( p_this, "extention -> mux=%s", psz_mux_byext );
194 /* We fix access/mux to valid couple */
196 if( !psz_access && !psz_mux )
201 "no access _and_ no muxer, extention gives file/%s",
203 psz_access = strdup("file");
204 psz_mux = strdup(psz_mux_byext);
208 msg_Err( p_stream, "no access _and_ no muxer (fatal error)" );
213 if( psz_access && !psz_mux )
215 /* access given, no mux */
216 if( !strncmp( psz_access, "mmsh", 4 ) )
218 psz_mux = strdup("asfh");
220 else if( !strncmp( psz_access, "udp", 3 ) ||
221 !strncmp( psz_access, "rtp", 3 ) )
223 psz_mux = strdup("ts");
225 else if( psz_mux_byext )
227 psz_mux = strdup(psz_mux_byext);
231 msg_Err( p_stream, "no mux specified or found by extention" );
235 else if( psz_mux && !psz_access )
237 /* mux given, no access */
238 if( !strncmp( psz_mux, "asfh", 4 ) )
240 psz_access = strdup("mmsh");
245 psz_access = strdup("file");
249 /* fix or warn of incompatible couple */
250 if( psz_mux && psz_access )
252 if( !strncmp( psz_access, "mmsh", 4 ) &&
253 strncmp( psz_mux, "asfh", 4 ) )
255 char *p = strchr( psz_mux,'{' );
257 msg_Warn( p_stream, "fixing to mmsh/asfh" );
260 /* -> a little memleak but ... */
261 psz_mux = malloc( strlen( "asfh" ) + strlen( p ) + 1);
262 sprintf( psz_mux, "asfh%s", p );
266 psz_mux = strdup("asfh");
269 else if( ( !strncmp( psz_access, "rtp", 3 ) ||
270 !strncmp( psz_access, "udp", 3 ) ) &&
271 strncmp( psz_mux, "ts", 2 ) )
273 msg_Err( p_stream, "for now udp and rtp are only valid with TS" );
275 else if( strncmp( psz_access, "file", 4 ) &&
276 ( !strncmp( psz_mux, "mov", 3 ) ||
277 !strncmp( psz_mux, "mp4", 3 ) ) )
279 msg_Err( p_stream, "mov and mp4 work only with file output" );
283 msg_Dbg( p_this, "using `%s/%s://%s'", psz_access, psz_mux, psz_url );
285 /* *** find and open appropriate access module *** */
286 p_access = sout_AccessOutNew( p_sout, psz_access, psz_url );
287 if( p_access == NULL )
289 msg_Err( p_stream, "no suitable sout access module for `%s/%s://%s'",
290 psz_access, psz_mux, psz_url );
291 if( psz_access ) free( psz_access );
292 if( psz_mux ) free( psz_mux );
295 msg_Dbg( p_stream, "access opened" );
297 /* *** find and open appropriate mux module *** */
298 p_mux = sout_MuxNew( p_sout, psz_mux, p_access );
301 msg_Err( p_stream, "no suitable sout mux module for `%s/%s://%s'",
302 psz_access, psz_mux, psz_url );
304 sout_AccessOutDelete( p_access );
305 if( psz_access ) free( psz_access );
306 if( psz_mux ) free( psz_mux );
309 msg_Dbg( p_stream, "mux opened" );
311 /* *** Create the SAP Session structure *** */
312 var_Get( p_stream, SOUT_CFG_PREFIX "sap", &val );
314 ( strstr( psz_access, "udp" ) || strstr( psz_access , "rtp" ) ) )
316 session_descriptor_t *p_session = sout_AnnounceSessionCreate();
317 announce_method_t *p_method =
318 sout_AnnounceMethodCreate( METHOD_TYPE_SAP );
321 var_Get( p_stream, SOUT_CFG_PREFIX "name", &val );
322 if( *val.psz_string )
323 p_session->psz_name = val.psz_string;
326 p_session->psz_name = strdup( psz_url );
327 free( val.psz_string );
330 var_Get( p_stream, SOUT_CFG_PREFIX "group", &val );
331 if( *val.psz_string )
332 p_session->psz_group = val.psz_string;
334 free( val.psz_string );
336 /* Now, parse the URL to extract host and port */
337 vlc_UrlParse( &url, psz_url , 0);
341 if( url.i_port == 0 ) url.i_port = DEFAULT_PORT;
343 p_session->psz_uri = strdup( url.psz_host );
344 p_session->i_port = url.i_port;
345 p_session->psz_sdp = NULL;
347 var_Get( p_access, "sout-udp-ttl", &val );
348 p_session->i_ttl = val.i_int;
349 p_session->i_payload = 33;
350 p_session->b_rtp = strstr( psz_access, "rtp") ? 1 : 0;
352 msg_Info( p_this, "SAP Enabled");
354 sout_AnnounceRegister( p_sout, p_session, p_method );
355 p_stream->p_sys->p_session = p_session;
357 vlc_UrlClean( &url );
362 p_stream->pf_add = Add;
363 p_stream->pf_del = Del;
364 p_stream->pf_send = Send;
366 p_stream->p_sys->p_mux = p_mux;
368 if( psz_access ) free( psz_access );
369 if( psz_mux ) free( psz_mux );
370 if( psz_url ) free( psz_url );
376 /*****************************************************************************
378 *****************************************************************************/
379 static void Close( vlc_object_t * p_this )
381 sout_stream_t *p_stream = (sout_stream_t*)p_this;
382 sout_stream_sys_t *p_sys = p_stream->p_sys;
383 sout_access_out_t *p_access = p_sys->p_mux->p_access;
385 if( p_sys->p_session != NULL )
387 sout_AnnounceUnRegister( p_stream->p_sout, p_sys->p_session );
388 sout_AnnounceSessionDestroy( p_sys->p_session );
392 sout_MuxDelete( p_sys->p_mux );
393 sout_AccessOutDelete( p_access );
398 struct sout_stream_id_t
400 sout_input_t *p_input;
404 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
406 sout_stream_sys_t *p_sys = p_stream->p_sys;
407 sout_stream_id_t *id;
409 id = malloc( sizeof( sout_stream_id_t ) );
410 if( ( id->p_input = sout_MuxAddStream( p_sys->p_mux, p_fmt ) ) == NULL )
420 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
422 sout_stream_sys_t *p_sys = p_stream->p_sys;
424 sout_MuxDeleteStream( p_sys->p_mux, id->p_input );
431 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
434 sout_stream_sys_t *p_sys = p_stream->p_sys;
436 sout_MuxSendBuffer( p_sys->p_mux, id->p_input, p_buffer );