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 /// \bug [String] "Output method to use for the stream."
41 #define ACCESS_LONGTEXT N_( \
42 "This is the output access method that will be used." )
43 #define MUX_TEXT N_("Output muxer")
44 /// \bug [String] "Muxer to use for the stream."
45 #define MUX_LONGTEXT N_( \
46 "This is the muxer that will be used." )
47 #define DST_TEXT N_("Output destination")
48 /// \bug [String] "Destination (URL) to use for the stream."
49 #define DST_LONGTEXT N_( \
50 "This is the destination (URL) that will be used for the stream." )
51 #define NAME_TEXT N_("Session name")
52 #define NAME_LONGTEXT N_( \
53 "This allows you to specify a name for the session, that will be announced "\
54 "if you choose to use SAP." )
56 #define GROUP_TEXT N_("Session groupname")
57 #define GROUP_LONGTEXT N_( \
58 "This allows you to specify a group for the session, that will be announced "\
59 "if you choose to use SAP." )
61 #define SAP_TEXT N_("SAP announcing")
62 #define SAP_LONGTEXT N_("Announce this session with SAP.")
64 static int Open ( vlc_object_t * );
65 static void Close ( vlc_object_t * );
67 #define SOUT_CFG_PREFIX "sout-standard-"
70 set_shortname( _("Standard"));
71 set_description( _("Standard stream output") );
72 set_capability( "sout stream", 50 );
73 add_shortcut( "standard" );
74 add_shortcut( "std" );
75 set_category( CAT_SOUT );
76 set_subcategory( SUBCAT_SOUT_STREAM );
78 add_string( SOUT_CFG_PREFIX "access", "", NULL, ACCESS_TEXT,
79 ACCESS_LONGTEXT, VLC_FALSE );
80 add_string( SOUT_CFG_PREFIX "mux", "", NULL, MUX_TEXT,
81 MUX_LONGTEXT, VLC_FALSE );
82 add_string( SOUT_CFG_PREFIX "dst", "", NULL, DST_TEXT,
83 DST_LONGTEXT, VLC_FALSE );
84 add_deprecated( SOUT_CFG_PREFIX "url", VLC_FALSE );
86 add_bool( SOUT_CFG_PREFIX "sap", 0, NULL, SAP_TEXT, SAP_LONGTEXT, VLC_TRUE );
87 add_string( SOUT_CFG_PREFIX "name", "", NULL, NAME_TEXT, NAME_LONGTEXT,
89 add_string( SOUT_CFG_PREFIX "group", "", NULL, GROUP_TEXT, GROUP_LONGTEXT,
91 add_suppressed_bool( SOUT_CFG_PREFIX "sap-ipv6" );
93 set_callbacks( Open, Close );
97 /*****************************************************************************
99 *****************************************************************************/
100 static const char *ppsz_sout_options[] = {
101 "access", "mux", "url", "dst",
102 "sap", "name", "group", NULL
105 #define DEFAULT_PORT 1234
107 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
108 static int Del ( sout_stream_t *, sout_stream_id_t * );
109 static int Send( sout_stream_t *, sout_stream_id_t *, block_t* );
111 struct sout_stream_sys_t
114 session_descriptor_t *p_session;
117 /*****************************************************************************
119 *****************************************************************************/
120 static int Open( vlc_object_t *p_this )
122 sout_stream_t *p_stream = (sout_stream_t*)p_this;
123 sout_instance_t *p_sout = p_stream->p_sout;
131 sout_access_out_t *p_access;
134 char *psz_mux_byext = NULL;
136 sout_CfgParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options,
139 var_Get( p_stream, SOUT_CFG_PREFIX "access", &val );
140 psz_access = *val.psz_string ? val.psz_string : NULL;
141 if( !*val.psz_string ) free( val.psz_string );
143 var_Get( p_stream, SOUT_CFG_PREFIX "mux", &val );
144 psz_mux = *val.psz_string ? val.psz_string : NULL;
145 if( !*val.psz_string ) free( val.psz_string );
148 var_Get( p_stream, SOUT_CFG_PREFIX "dst", &val );
149 psz_url = *val.psz_string ? val.psz_string : NULL;
150 if( !*val.psz_string ) free( val.psz_string );
152 p_stream->p_sys = malloc( sizeof( sout_stream_sys_t) );
153 p_stream->p_sys->p_session = NULL;
155 msg_Dbg( p_this, "creating `%s/%s://%s'", psz_access, psz_mux, psz_url );
157 /* ext -> muxer name */
158 if( psz_url && strrchr( psz_url, '.' ) )
161 static struct { char *ext; char *mux; } exttomux[] =
181 char *psz_ext = strrchr( psz_url, '.' ) + 1;
184 msg_Dbg( p_this, "extension is %s", psz_ext );
185 for( i = 0; exttomux[i].ext != NULL; i++ )
187 if( !strcasecmp( psz_ext, exttomux[i].ext ) )
189 psz_mux_byext = exttomux[i].mux;
193 msg_Dbg( p_this, "extension -> mux=%s", psz_mux_byext );
196 /* We fix access/mux to valid couple */
198 if( !psz_access && !psz_mux )
203 "no access _and_ no muxer, extension gives file/%s",
205 psz_access = strdup("file");
206 psz_mux = strdup(psz_mux_byext);
210 msg_Err( p_stream, "no access _and_ no muxer (fatal error)" );
215 if( psz_access && !psz_mux )
217 /* access given, no mux */
218 if( !strncmp( psz_access, "mmsh", 4 ) )
220 psz_mux = strdup("asfh");
222 else if( !strncmp( psz_access, "udp", 3 ) ||
223 !strncmp( psz_access, "rtp", 3 ) )
225 psz_mux = strdup("ts");
227 else if( psz_mux_byext )
229 psz_mux = strdup(psz_mux_byext);
233 msg_Err( p_stream, "no mux specified or found by extension" );
237 else if( psz_mux && !psz_access )
239 /* mux given, no access */
240 if( !strncmp( psz_mux, "asfh", 4 ) )
242 psz_access = strdup("mmsh");
247 psz_access = strdup("file");
251 /* fix or warn of incompatible couple */
252 if( psz_mux && psz_access )
254 if( !strncmp( psz_access, "mmsh", 4 ) &&
255 strncmp( psz_mux, "asfh", 4 ) )
257 char *p = strchr( psz_mux,'{' );
259 msg_Warn( p_stream, "fixing to mmsh/asfh" );
262 /* -> a little memleak but ... */
263 psz_mux = malloc( strlen( "asfh" ) + strlen( p ) + 1);
264 sprintf( psz_mux, "asfh%s", p );
268 psz_mux = strdup("asfh");
271 else if( ( !strncmp( psz_access, "rtp", 3 ) ||
272 !strncmp( psz_access, "udp", 3 ) ) &&
273 strncmp( psz_mux, "ts", 2 ) )
275 msg_Err( p_stream, "for now udp and rtp are only valid with TS" );
277 else if( strncmp( psz_access, "file", 4 ) &&
278 ( !strncmp( psz_mux, "mov", 3 ) ||
279 !strncmp( psz_mux, "mp4", 3 ) ) )
281 msg_Err( p_stream, "mov and mp4 work only with file output" );
285 msg_Dbg( p_this, "using `%s/%s://%s'", psz_access, psz_mux, psz_url );
287 /* *** find and open appropriate access module *** */
288 p_access = sout_AccessOutNew( p_sout, psz_access, psz_url );
289 if( p_access == NULL )
291 msg_Err( p_stream, "no suitable sout access module for `%s/%s://%s'",
292 psz_access, psz_mux, psz_url );
293 if( psz_access ) free( psz_access );
294 if( psz_mux ) free( psz_mux );
297 msg_Dbg( p_stream, "access opened" );
299 /* *** find and open appropriate mux module *** */
300 p_mux = sout_MuxNew( p_sout, psz_mux, p_access );
303 msg_Err( p_stream, "no suitable sout mux module for `%s/%s://%s'",
304 psz_access, psz_mux, psz_url );
306 sout_AccessOutDelete( p_access );
307 if( psz_access ) free( psz_access );
308 if( psz_mux ) free( psz_mux );
311 msg_Dbg( p_stream, "mux opened" );
313 /* *** Create the SAP Session structure *** */
314 var_Get( p_stream, SOUT_CFG_PREFIX "sap", &val );
316 ( strstr( psz_access, "udp" ) || strstr( psz_access , "rtp" ) ) )
318 session_descriptor_t *p_session = sout_AnnounceSessionCreate();
319 announce_method_t *p_method =
320 sout_AnnounceMethodCreate( METHOD_TYPE_SAP );
323 var_Get( p_stream, SOUT_CFG_PREFIX "name", &val );
324 if( *val.psz_string )
325 p_session->psz_name = val.psz_string;
328 p_session->psz_name = strdup( psz_url );
329 free( val.psz_string );
332 var_Get( p_stream, SOUT_CFG_PREFIX "group", &val );
333 if( *val.psz_string )
334 p_session->psz_group = val.psz_string;
336 free( val.psz_string );
338 /* Now, parse the URL to extract host and port */
339 vlc_UrlParse( &url, psz_url , 0);
343 if( url.i_port == 0 ) url.i_port = DEFAULT_PORT;
345 p_session->psz_uri = strdup( url.psz_host );
346 p_session->i_port = url.i_port;
347 p_session->psz_sdp = NULL;
349 var_Get( p_access, "sout-udp-ttl", &val );
350 p_session->i_ttl = val.i_int;
351 p_session->i_payload = 33;
352 p_session->b_rtp = strstr( psz_access, "rtp") ? 1 : 0;
354 msg_Info( p_this, "SAP Enabled");
356 sout_AnnounceRegister( p_sout, p_session, p_method );
357 p_stream->p_sys->p_session = p_session;
359 vlc_UrlClean( &url );
364 p_stream->pf_add = Add;
365 p_stream->pf_del = Del;
366 p_stream->pf_send = Send;
368 p_stream->p_sys->p_mux = p_mux;
370 if( psz_access ) free( psz_access );
371 if( psz_mux ) free( psz_mux );
372 if( psz_url ) free( psz_url );
378 /*****************************************************************************
380 *****************************************************************************/
381 static void Close( vlc_object_t * p_this )
383 sout_stream_t *p_stream = (sout_stream_t*)p_this;
384 sout_stream_sys_t *p_sys = p_stream->p_sys;
385 sout_access_out_t *p_access = p_sys->p_mux->p_access;
387 if( p_sys->p_session != NULL )
389 sout_AnnounceUnRegister( p_stream->p_sout, p_sys->p_session );
390 sout_AnnounceSessionDestroy( p_sys->p_session );
394 sout_MuxDelete( p_sys->p_mux );
395 sout_AccessOutDelete( p_access );
400 struct sout_stream_id_t
402 sout_input_t *p_input;
406 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
408 sout_stream_sys_t *p_sys = p_stream->p_sys;
409 sout_stream_id_t *id;
411 id = malloc( sizeof( sout_stream_id_t ) );
412 if( ( id->p_input = sout_MuxAddStream( p_sys->p_mux, p_fmt ) ) == NULL )
422 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
424 sout_stream_sys_t *p_sys = p_stream->p_sys;
426 sout_MuxDeleteStream( p_sys->p_mux, id->p_input );
433 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
436 sout_stream_sys_t *p_sys = p_stream->p_sys;
438 sout_MuxSendBuffer( p_sys->p_mux, id->p_input, p_buffer );