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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
40 /*****************************************************************************
42 *****************************************************************************/
43 #define ACCESS_TEXT N_("Output access method")
44 #define ACCESS_LONGTEXT N_( \
45 "Allows you to specify the output access method used for the streaming " \
47 #define MUX_TEXT N_("Output muxer")
48 #define MUX_LONGTEXT N_( \
49 "Allows you to specify the output muxer method used for the streaming " \
51 #define URL_TEXT N_("Output URL (deprecated)")
52 #define URL_LONGTEXT N_( \
53 "Allows you to specify the output URL used for the streaming output." \
54 "Deprecated, use dst instead." )
56 #define DST_TEXT N_("Output destination")
57 #define DST_LONGTEXT N_( \
58 "Allows you to specify the output destination used for the streaming output." )
60 #define NAME_TEXT N_("Session name")
61 #define NAME_LONGTEXT N_( \
62 "Name of the session that will be announced with SAP or SLP" )
64 #define GROUP_TEXT N_("Session groupname")
65 #define GROUP_LONGTEXT N_( \
66 "Name of the group that will be announced for the session" )
68 #define SAP_TEXT N_("SAP announcing")
69 #define SAP_LONGTEXT N_("Announce this session with SAP")
71 #define SLP_TEXT N_("SLP announcing")
72 #define SLP_LONGTEXT N_("Announce this session with SLP")
74 static int Open ( vlc_object_t * );
75 static void Close ( vlc_object_t * );
77 #define SOUT_CFG_PREFIX "sout-standard-"
80 set_shortname( _("Standard"));
81 set_description( _("Standard stream output") );
82 set_capability( "sout stream", 50 );
83 add_shortcut( "standard" );
84 add_shortcut( "std" );
85 set_category( CAT_SOUT );
86 set_subcategory( SUBCAT_SOUT_STREAM );
88 add_string( SOUT_CFG_PREFIX "access", "", NULL, ACCESS_TEXT,
89 ACCESS_LONGTEXT, VLC_FALSE );
90 add_string( SOUT_CFG_PREFIX "mux", "", NULL, MUX_TEXT,
91 MUX_LONGTEXT, VLC_FALSE );
92 add_string( SOUT_CFG_PREFIX "url", "", NULL, URL_TEXT,
93 URL_LONGTEXT, VLC_FALSE );
94 add_string( SOUT_CFG_PREFIX "dst", "", NULL, DST_TEXT,
95 DST_LONGTEXT, VLC_FALSE );
97 add_bool( SOUT_CFG_PREFIX "sap", 0, NULL, SAP_TEXT, SAP_LONGTEXT, VLC_TRUE );
98 add_string( SOUT_CFG_PREFIX "name", "", NULL, NAME_TEXT, NAME_LONGTEXT,
100 add_string( SOUT_CFG_PREFIX "group", "", NULL, GROUP_TEXT, GROUP_LONGTEXT,
102 add_suppressed_bool( SOUT_CFG_PREFIX "sap-ipv6" );
104 add_bool( SOUT_CFG_PREFIX "slp", 0, NULL, SLP_TEXT, SLP_LONGTEXT, VLC_TRUE );
106 set_callbacks( Open, Close );
110 /*****************************************************************************
111 * Exported prototypes
112 *****************************************************************************/
113 static const char *ppsz_sout_options[] = {
114 "access", "mux", "url", "dst",
115 "sap", "name", "group", "slp", NULL
118 #define DEFAULT_PORT 1234
120 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
121 static int Del ( sout_stream_t *, sout_stream_id_t * );
122 static int Send( sout_stream_t *, sout_stream_id_t *, block_t* );
124 struct sout_stream_sys_t
127 slp_session_t *p_slp;
128 session_descriptor_t *p_session;
131 /*****************************************************************************
133 *****************************************************************************/
134 static int Open( vlc_object_t *p_this )
136 sout_stream_t *p_stream = (sout_stream_t*)p_this;
137 sout_instance_t *p_sout = p_stream->p_sout;
138 slp_session_t *p_slp = NULL;
146 sout_access_out_t *p_access;
149 char *psz_mux_byext = NULL;
151 sout_CfgParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options,
154 var_Get( p_stream, SOUT_CFG_PREFIX "access", &val );
155 psz_access = *val.psz_string ? val.psz_string : NULL;
156 if( !*val.psz_string ) free( val.psz_string );
158 var_Get( p_stream, SOUT_CFG_PREFIX "mux", &val );
159 psz_mux = *val.psz_string ? val.psz_string : NULL;
160 if( !*val.psz_string ) free( val.psz_string );
163 var_Get( p_stream, SOUT_CFG_PREFIX "dst", &val );
164 psz_url = *val.psz_string ? val.psz_string : NULL;
165 if( !*val.psz_string ) free( val.psz_string );
168 /* XXX dst take preference over url (url will be removed later) */
169 var_Get( p_stream, SOUT_CFG_PREFIX "url", &val );
170 psz_url = *val.psz_string ? val.psz_string : NULL;
171 if( !*val.psz_string ) free( val.psz_string );
174 p_stream->p_sys = malloc( sizeof( sout_stream_sys_t) );
175 p_stream->p_sys->p_session = NULL;
177 msg_Dbg( p_this, "creating `%s/%s://%s'", psz_access, psz_mux, psz_url );
179 /* ext -> muxer name */
180 if( psz_url && strrchr( psz_url, '.' ) )
183 static struct { char *ext; char *mux; } exttomux[] =
203 char *psz_ext = strrchr( psz_url, '.' ) + 1;
206 msg_Dbg( p_this, "extention is %s", psz_ext );
207 for( i = 0; exttomux[i].ext != NULL; i++ )
209 if( !strcasecmp( psz_ext, exttomux[i].ext ) )
211 psz_mux_byext = exttomux[i].mux;
215 msg_Dbg( p_this, "extention -> mux=%s", psz_mux_byext );
218 /* We fix access/mux to valid couple */
220 if( !psz_access && !psz_mux )
225 "no access _and_ no muxer, extention gives file/%s",
227 psz_access = strdup("file");
228 psz_mux = strdup(psz_mux_byext);
232 msg_Err( p_stream, "no access _and_ no muxer (fatal error)" );
237 if( psz_access && !psz_mux )
239 /* access given, no mux */
240 if( !strncmp( psz_access, "mmsh", 4 ) )
242 psz_mux = strdup("asfh");
244 else if( !strncmp( psz_access, "udp", 3 ) )
246 psz_mux = strdup("ts");
248 else if( psz_mux_byext )
250 psz_mux = strdup(psz_mux_byext);
254 msg_Err( p_stream, "no mux specified or found by extention" );
258 else if( psz_mux && !psz_access )
260 /* mux given, no access */
261 if( !strncmp( psz_mux, "asfh", 4 ) )
263 psz_access = strdup("mmsh");
268 psz_access = strdup("file");
272 /* fix or warn of incompatible couple */
273 if( psz_mux && psz_access )
275 if( !strncmp( psz_access, "mmsh", 4 ) &&
276 strncmp( psz_mux, "asfh", 4 ) )
278 char *p = strchr( psz_mux,'{' );
280 msg_Warn( p_stream, "fixing to mmsh/asfh" );
283 /* -> a little memleak but ... */
284 psz_mux = malloc( strlen( "asfh" ) + strlen( p ) + 1);
285 sprintf( psz_mux, "asfh%s", p );
289 psz_mux = strdup("asfh");
292 else if( ( !strncmp( psz_access, "rtp", 3 ) ||
293 !strncmp( psz_access, "udp", 3 ) ) &&
294 strncmp( psz_mux, "ts", 2 ) )
296 msg_Err( p_stream, "for now udp and rtp are only valid with TS" );
298 else if( strncmp( psz_access, "file", 4 ) &&
299 ( !strncmp( psz_mux, "mov", 3 ) ||
300 !strncmp( psz_mux, "mp4", 3 ) ) )
302 msg_Err( p_stream, "mov and mp4 work only with file output" );
306 msg_Dbg( p_this, "using `%s/%s://%s'", psz_access, psz_mux, psz_url );
308 /* *** find and open appropriate access module *** */
309 p_access = sout_AccessOutNew( p_sout, psz_access, psz_url );
310 if( p_access == NULL )
312 msg_Err( p_stream, "no suitable sout access module for `%s/%s://%s'",
313 psz_access, psz_mux, psz_url );
314 if( psz_access ) free( psz_access );
315 if( psz_mux ) free( psz_mux );
318 msg_Dbg( p_stream, "access opened" );
320 /* *** find and open appropriate mux module *** */
321 p_mux = sout_MuxNew( p_sout, psz_mux, p_access );
324 msg_Err( p_stream, "no suitable sout mux module for `%s/%s://%s'",
325 psz_access, psz_mux, psz_url );
327 sout_AccessOutDelete( p_access );
328 if( psz_access ) free( psz_access );
329 if( psz_mux ) free( psz_mux );
332 msg_Dbg( p_stream, "mux opened" );
334 /* *** Create the SAP Session structure *** */
335 var_Get( p_stream, SOUT_CFG_PREFIX "sap", &val );
337 ( strstr( psz_access, "udp" ) || strstr( psz_access , "rtp" ) ) )
339 session_descriptor_t *p_session = sout_AnnounceSessionCreate();
340 announce_method_t *p_method =
341 sout_AnnounceMethodCreate( METHOD_TYPE_SAP );
344 var_Get( p_stream, SOUT_CFG_PREFIX "name", &val );
345 if( *val.psz_string )
346 p_session->psz_name = val.psz_string;
349 p_session->psz_name = strdup( psz_url );
350 free( val.psz_string );
353 var_Get( p_stream, SOUT_CFG_PREFIX "group", &val );
354 if( *val.psz_string )
355 p_session->psz_group = val.psz_string;
357 free( val.psz_string );
359 /* Now, parse the URL to extract host and port */
360 vlc_UrlParse( &url, psz_url , 0);
364 if( url.i_port == 0 ) url.i_port = DEFAULT_PORT;
366 p_session->psz_uri = strdup( url.psz_host );
367 p_session->i_port = url.i_port;
368 p_session->psz_sdp = NULL;
370 p_session->i_ttl = config_GetInt( p_sout, "ttl" );
371 p_session->i_payload = 33;
372 p_session->b_rtp = strstr( psz_access, "rtp") ? 1 : 0;
374 msg_Info( p_this, "SAP Enabled");
376 sout_AnnounceRegister( p_sout, p_session, p_method );
377 p_stream->p_sys->p_session = p_session;
379 vlc_UrlClean( &url );
384 /* *** Register with slp *** */
386 var_Get( p_stream, SOUT_CFG_PREFIX "slp", &val );
388 ( strstr( psz_access, "udp" ) || strstr( psz_access , "rtp" ) ) )
392 msg_Info( p_this, "SLP Enabled");
393 var_Get( p_stream, SOUT_CFG_PREFIX "name", &val );
394 if( *val.psz_string )
396 i_ret = sout_SLPReg( p_sout, psz_url, val.psz_string );
400 i_ret = sout_SLPReg( p_sout, psz_url, psz_url );
405 msg_Warn( p_sout, "SLP Registering failed");
409 p_slp = malloc(sizeof(slp_session_t));
410 p_slp->psz_url = strdup( psz_url );
412 strdup( *val.psz_string ? val.psz_string : psz_url );
414 free( val.psz_string );
418 p_stream->pf_add = Add;
419 p_stream->pf_del = Del;
420 p_stream->pf_send = Send;
422 p_stream->p_sys->p_mux = p_mux;
423 p_stream->p_sys->p_slp = p_slp;
425 if( psz_access ) free( psz_access );
426 if( psz_mux ) free( psz_mux );
427 if( psz_url ) free( psz_url );
433 /*****************************************************************************
435 *****************************************************************************/
436 static void Close( vlc_object_t * p_this )
438 sout_stream_t *p_stream = (sout_stream_t*)p_this;
439 sout_stream_sys_t *p_sys = p_stream->p_sys;
440 sout_access_out_t *p_access = p_sys->p_mux->p_access;
442 if( p_sys->p_session != NULL )
444 sout_AnnounceUnRegister( p_stream->p_sout, p_sys->p_session );
445 sout_AnnounceSessionDestroy( p_sys->p_session );
451 sout_SLPDereg( (sout_instance_t *)p_this,
452 p_sys->p_slp->psz_url,
453 p_sys->p_slp->psz_name);
459 sout_MuxDelete( p_sys->p_mux );
460 sout_AccessOutDelete( p_access );
465 struct sout_stream_id_t
467 sout_input_t *p_input;
471 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
473 sout_stream_sys_t *p_sys = p_stream->p_sys;
474 sout_stream_id_t *id;
476 id = malloc( sizeof( sout_stream_id_t ) );
477 if( ( id->p_input = sout_MuxAddStream( p_sys->p_mux, p_fmt ) ) == NULL )
487 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
489 sout_stream_sys_t *p_sys = p_stream->p_sys;
491 sout_MuxDeleteStream( p_sys->p_mux, id->p_input );
498 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
501 sout_stream_sys_t *p_sys = p_stream->p_sys;
503 sout_MuxSendBuffer( p_sys->p_mux, id->p_input, p_buffer );