1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VideoLAN
5 * $Id: standard.c,v 1.13 2003/08/28 21:02:14 fenrir Exp $
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 *****************************************************************************/
35 #define DEFAULT_IPV6_SCOPE "8"
37 /*****************************************************************************
39 *****************************************************************************/
40 static int Open ( vlc_object_t * );
41 static void Close ( vlc_object_t * );
43 static sout_stream_id_t *Add ( sout_stream_t *, sout_format_t * );
44 static int Del ( sout_stream_t *, sout_stream_id_t * );
45 static int Send( sout_stream_t *, sout_stream_id_t *, sout_buffer_t* );
47 /*****************************************************************************
49 *****************************************************************************/
51 set_description( _("Standard stream") );
52 set_capability( "sout stream", 50 );
53 add_shortcut( "standard" );
54 add_shortcut( "std" );
55 set_callbacks( Open, Close );
58 struct sout_stream_sys_t
65 /*****************************************************************************
67 *****************************************************************************/
68 static int Open( vlc_object_t *p_this )
70 sout_stream_t *p_stream = (sout_stream_t*)p_this;
71 sout_instance_t *p_sout = p_stream->p_sout;
72 sout_stream_sys_t *p_sys = malloc( sizeof( sout_stream_sys_t) );
74 char *psz_mux = sout_cfg_find_value( p_stream->p_cfg, "mux" );
75 char *psz_access = sout_cfg_find_value( p_stream->p_cfg, "access" );
76 char *psz_url = sout_cfg_find_value( p_stream->p_cfg, "url" );
77 char *psz_ipv = sout_cfg_find_value( p_stream->p_cfg, "sap_ipv" );
78 char *psz_v6_scope = sout_cfg_find_value( p_stream->p_cfg, "sap_v6scope" );
80 sout_cfg_t *p_sap_cfg = sout_cfg_find( p_stream->p_cfg, "sap" );
82 sout_cfg_t *p_slp_cfg = sout_cfg_find( p_stream->p_cfg, "slp" );
85 sout_access_out_t *p_access;
88 char *psz_mux_byext = NULL;
93 msg_Dbg( p_this, "creating `%s/%s://%s'",
94 psz_access, psz_mux, psz_url );
96 /* ext -> muxer name */
97 if( psz_url && strrchr( psz_url, '.' ) )
100 static struct { char *ext; char *mux; } exttomux[] =
117 char *psz_ext = strrchr( psz_url, '.' ) + 1;
120 msg_Dbg( p_this, "extention is %s", psz_ext );
121 for( i = 0; exttomux[i].ext != NULL; i++ )
123 if( !strcasecmp( psz_ext, exttomux[i].ext ) )
125 psz_mux_byext = exttomux[i].mux;
129 msg_Dbg( p_this, "extention -> mux=%s", psz_mux_byext );
132 /* We fix access/mux to valid couple */
134 if( ( psz_access == NULL || *psz_access == '\0' )&&
135 ( psz_mux == NULL || *psz_mux == '\0' ) )
140 "no access _and_ no muxer, extention gives file/%s",
143 psz_mux = psz_mux_byext;
147 msg_Err( p_stream, "no access _and_ no muxer (fatal error)" );
152 if( psz_access && *psz_access &&
153 ( psz_mux == NULL || *psz_mux == '\0' ) )
155 /* access given, no mux */
156 if( !strcmp( psz_access, "mmsh" ) )
160 else if( !strcmp( psz_access, "udp" ) )
166 psz_mux = psz_mux_byext;
169 else if( psz_mux && *psz_mux &&
170 ( psz_access == NULL || *psz_access == '\0' ) )
172 /* mux given, no access */
173 if( !strcmp( psz_mux, "asfh" ) )
184 /* fix or warm of incompatible couple */
185 if( psz_mux && *psz_mux && psz_access && *psz_access )
187 if( !strcmp( psz_access, "mmsh" ) && strcmp( psz_mux, "asfh" ) )
189 msg_Warn( p_stream, "fixing to mmsh/asfh" );
192 else if( ( !strcmp( psz_access, "rtp" ) ||
193 !strcmp( psz_access, "udp" ) ) &&
194 strncmp( psz_mux, "ts", 2 ) )
196 msg_Err( p_stream, "for now udp and rtp are only valid with TS" );
198 else if( strcmp( psz_access, "file" ) &&
199 ( !strcmp( psz_mux, "mov" ) || !strcmp( psz_mux, "mp4" ) ) )
201 msg_Err( p_stream, "mov and mp4 work only with file output" );
205 msg_Dbg( p_this, "using `%s/%s://%s'", psz_access, psz_mux, psz_url );
207 /* *** find and open appropriate access module *** */
208 p_access = sout_AccessOutNew( p_sout, psz_access, psz_url );
209 if( p_access == NULL )
211 msg_Err( p_stream, "no suitable sout access module for `%s/%s://%s'",
212 psz_access, psz_mux, psz_url );
213 return( VLC_EGENERIC );
215 msg_Dbg( p_stream, "access opened" );
217 /* *** find and open appropriate mux module *** */
218 p_mux = sout_MuxNew( p_sout, psz_mux, p_access );
221 msg_Err( p_stream, "no suitable sout mux module for `%s/%s://%s'",
222 psz_access, psz_mux, psz_url );
224 sout_AccessOutDelete( p_access );
225 return( VLC_EGENERIC );
227 msg_Dbg( p_stream, "mux opened" );
229 /* *** Create the SAP Session structure *** */
232 ( strstr( psz_access, "udp" ) || strstr( psz_access , "rtp" ) ) )
234 msg_Info( p_this, "SAP Enabled");
236 if( psz_ipv == NULL )
240 if( psz_v6_scope == NULL )
242 psz_v6_scope = DEFAULT_IPV6_SCOPE;
244 msg_Dbg( p_sout , "Creating SAP with IPv%i", atoi(psz_ipv) );
246 p_sys->p_sap = sout_SAPNew( p_sout , psz_url ,
247 p_sap_cfg->psz_value ? p_sap_cfg->psz_value : psz_url,
248 atoi(psz_ipv), psz_v6_scope );
251 msg_Err( p_sout,"Unable to initialize SAP. SAP disabled");
254 /* *** Register with slp *** */
256 if( p_slp_cfg && ( strstr( psz_access, "udp" ) ||
257 strstr( psz_access , "rtp" ) ) )
259 msg_Info( p_this, "SLP Enabled");
260 if( sout_SLPReg( p_sout, psz_url,
261 p_slp_cfg->psz_value ? p_slp_cfg->psz_value : psz_url) )
263 msg_Warn( p_sout, "SLP Registering failed");
267 p_sys->p_slp = (slp_session_t*)malloc(sizeof(slp_session_t));
270 msg_Warn(p_sout,"Out of memory");
273 p_sys->p_slp->psz_url= strdup(psz_url);
274 p_sys->p_slp->psz_name = strdup(
275 p_slp_cfg->psz_value ? p_slp_cfg->psz_value : psz_url);
281 p_sout->i_preheader = __MAX( p_sout->i_preheader, p_mux->i_preheader );
284 p_sys->p_mux = p_mux;
286 p_stream->pf_add = Add;
287 p_stream->pf_del = Del;
288 p_stream->pf_send = Send;
290 p_stream->p_sys = p_sys;
294 /*****************************************************************************
296 *****************************************************************************/
298 static void Close( vlc_object_t * p_this )
300 sout_stream_t *p_stream = (sout_stream_t*)p_this;
301 sout_stream_sys_t *p_sys = p_stream->p_sys;
302 sout_access_out_t *p_access = p_sys->p_mux->p_access;
305 sout_SAPDelete( (sout_instance_t *)p_this , p_sys->p_sap );
310 sout_SLPDereg( (sout_instance_t *)p_this,
311 p_sys->p_slp->psz_url,
312 p_sys->p_slp->psz_name);
318 sout_MuxDelete( p_sys->p_mux );
319 sout_AccessOutDelete( p_access );
324 struct sout_stream_id_t
326 sout_input_t *p_input;
330 static sout_stream_id_t * Add( sout_stream_t *p_stream, sout_format_t *p_fmt )
332 sout_stream_sys_t *p_sys = p_stream->p_sys;
333 sout_stream_id_t *id;
335 id = malloc( sizeof( sout_stream_id_t ) );
336 if( ( id->p_input = sout_MuxAddStream( p_sys->p_mux, p_fmt ) ) == NULL )
346 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
348 sout_stream_sys_t *p_sys = p_stream->p_sys;
350 sout_MuxDeleteStream( p_sys->p_mux, id->p_input );
357 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
358 sout_buffer_t *p_buffer )
360 sout_stream_sys_t *p_sys = p_stream->p_sys;
361 sout_instance_t *p_sout = p_stream->p_sout;
363 sout_MuxSendBuffer( p_sys->p_mux, id->p_input, p_buffer );
366 sout_SAPSend( p_sout , p_sys->p_sap );