1 /*****************************************************************************
2 * mms.c: MMS over tcp, udp and http access plug-in
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VideoLAN
5 * $Id: mms.c,v 1.35 2004/01/21 16:56:16 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 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
31 #include <vlc/input.h>
35 /****************************************************************************
37 * MMSProtocole documentation found at http://get.to/sdp
38 ****************************************************************************/
40 /*****************************************************************************
42 *****************************************************************************/
50 static int Open ( vlc_object_t * );
51 static void Close ( vlc_object_t * );
54 /*****************************************************************************
56 *****************************************************************************/
57 #define CACHING_TEXT N_("Caching value in ms")
58 #define CACHING_LONGTEXT N_( \
59 "Allows you to modify the default caching value for mms streams. This " \
60 "value should be set in miliseconds units." )
63 set_description( _("Microsoft Media Server (MMS) input") );
64 set_capability( "access", 0 );
65 add_category_hint( "stream", NULL, VLC_TRUE );
66 add_integer( "mms-caching", 4 * DEFAULT_PTS_DELAY / 1000, NULL,
67 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
69 add_bool( "mms-all", 0, NULL,
70 "force selection of all streams",
71 "force selection of all streams", VLC_TRUE );
72 add_integer( "mms-maxbitrate", 0, NULL,
74 "set max bitrate for auto streams selections", VLC_FALSE );
75 add_shortcut( "mms" );
76 add_shortcut( "mmsu" );
77 add_shortcut( "mmst" );
78 add_shortcut( "mmsh" );
79 set_callbacks( Open, Close );
83 static int Open( vlc_object_t *p_this )
85 input_thread_t *p_input = (input_thread_t*)p_this;
87 /* First set ipv4/ipv6 */
88 var_Create( p_input, "ipv4", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
89 var_Create( p_input, "ipv6", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
92 var_Create( p_input, "mms-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
94 /* use specified method */
95 if( *p_input->psz_access )
97 if( !strncmp( p_input->psz_access, "mmsu", 4 ) )
99 return E_( MMSTUOpen )( p_input );
101 else if( !strncmp( p_input->psz_access, "mmst", 4 ) )
103 return E_( MMSTUOpen )( p_input );
105 else if( !strncmp( p_input->psz_access, "mmsh", 4 ) )
107 return E_( MMSHOpen )( p_input );
111 if( E_( MMSTUOpen )( p_input ) )
113 /* try mmsh if mmstu failed */
114 return E_( MMSHOpen )( p_input );
119 /*****************************************************************************
120 * Close: free unused data structures
121 *****************************************************************************/
122 static void Close( vlc_object_t *p_this )
124 input_thread_t * p_input = (input_thread_t *)p_this;
125 access_sys_t * p_sys = p_input->p_access_data;
127 if( p_sys->i_proto == MMS_PROTO_TCP || p_sys->i_proto == MMS_PROTO_UDP )
129 E_( MMSTUClose )( p_input );
131 else if( p_sys->i_proto == MMS_PROTO_HTTP )
133 E_( MMSHClose )( p_input );
137 /****************************************************************************
138 * parse hostname:port/path@username:password
139 * FIXME ipv6 ip will be baddly parsed (contain ':' )
140 ****************************************************************************/
141 url_t *E_( url_new ) ( char * psz_url )
143 url_t *p_url = malloc( sizeof( url_t ) );
145 char *psz_dup = strdup( psz_url );
146 char *psz_parser = psz_dup;
150 /* 1: get hostname:port */
151 while( *psz_parser == '/' )
156 psz_tmp = psz_parser;
158 while( *psz_parser &&
159 *psz_parser != ':' && *psz_parser != '/' && *psz_parser != '@' )
164 p_url->psz_host = strndup( psz_tmp, psz_parser - psz_tmp );
166 if( *psz_parser == ':' )
169 psz_tmp = psz_parser;
171 while( *psz_parser && *psz_parser != '/' && *psz_parser != '@' )
175 p_url->i_port = atoi( psz_tmp );
183 if( *psz_parser == '/' )
187 psz_tmp = psz_parser;
189 while( *psz_parser && *psz_parser != '@' )
194 p_url->psz_path = strndup( psz_tmp, psz_parser - psz_tmp );
198 p_url->psz_path = strdup( "" );
201 /* 3: usrname and password */
202 if( *psz_parser == '@' )
206 psz_tmp = psz_parser;
208 while( *psz_parser && *psz_parser != ':' )
213 p_url->psz_username = strndup( psz_tmp, psz_parser - psz_tmp );
215 if( *psz_parser == ':' )
219 p_url->psz_password = strdup( psz_parser );
223 p_url->psz_password = strdup( "" );
228 p_url->psz_username = strdup( "" );
229 p_url->psz_password = strdup( "" );
233 "host=`%s' port=%d path=`%s' username=`%s' password=`%s'\n",
238 p_url->psz_password );
244 void E_( url_free ) ( url_t * p_url )
246 free( p_url->psz_host );
247 free( p_url->psz_path );
248 free( p_url->psz_username );
249 free( p_url->psz_password );