]> git.sesse.net Git - vlc/blob - modules/access/mms/mms.c
Fix duration that input_AddInfo uses milliseconds.
[vlc] / modules / access / mms / mms.c
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.34 2003/05/15 22:27:36 massiot Exp $
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdlib.h>
29
30 #include <vlc/vlc.h>
31 #include <vlc/input.h>
32
33 #include "mms.h"
34
35 /****************************************************************************
36  * NOTES:
37  *  MMSProtocole documentation found at http://get.to/sdp
38  ****************************************************************************/
39
40 /*****************************************************************************
41  * Local prototypes
42  *****************************************************************************/
43
44 struct access_sys_t
45 {
46     int i_proto;
47
48 };
49
50 static int  Open        ( vlc_object_t * );
51 static void Close       ( vlc_object_t * );
52
53
54 /*****************************************************************************
55  * Module descriptor
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." )
61
62 vlc_module_begin();
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 );
68
69         add_bool( "mms-all", 0, NULL,
70                   "force selection of all streams",
71                   "force selection of all streams", VLC_TRUE );
72 #if 0
73         add_string( "mms-stream", NULL, NULL,
74                     "streams selection",
75                     "force this stream selection", VLC_TRUE );
76 #endif
77         add_integer( "mms-maxbitrate", 0, NULL,
78                      "max bitrate",
79                      "set max bitrate for auto streams selections", VLC_FALSE );
80     add_shortcut( "mms" );
81     add_shortcut( "mmsu" );
82     add_shortcut( "mmst" );
83     add_shortcut( "mmsh" );
84     set_callbacks( Open, Close );
85 vlc_module_end();
86
87
88 static int Open( vlc_object_t *p_this )
89 {
90     input_thread_t  *p_input = (input_thread_t*)p_this;
91
92     int i_err;
93
94
95     if( *p_input->psz_access )
96     {
97         if( !strncmp( p_input->psz_access, "mmsu", 4 ) )
98         {
99             return E_( MMSTUOpen )( p_input );
100         }
101         else if( !strncmp( p_input->psz_access, "mmst", 4 ) )
102         {
103             return E_( MMSTUOpen )( p_input );
104         }
105         else if( !strncmp( p_input->psz_access, "mmsh", 4 ) )
106         {
107             return E_( MMSHOpen )( p_input );
108         }
109     }
110
111
112     i_err = E_( MMSTUOpen )( p_input );
113
114     if( i_err )
115     {
116         i_err = E_( MMSHOpen )( p_input );
117     }
118
119     return i_err;
120 }
121
122 /*****************************************************************************
123  * Close: free unused data structures
124  *****************************************************************************/
125 static void Close( vlc_object_t *p_this )
126 {
127     input_thread_t *  p_input = (input_thread_t *)p_this;
128     access_sys_t   *  p_sys   = p_input->p_access_data;
129
130     if( p_sys->i_proto == MMS_PROTO_TCP || p_sys->i_proto == MMS_PROTO_UDP )
131     {
132         E_( MMSTUClose )( p_input );
133     }
134     else if( p_sys->i_proto == MMS_PROTO_HTTP )
135     {
136         E_( MMSHClose )( p_input );
137     }
138 }
139
140 /****************************************************************************
141  * parse hostname:port/path@username:password
142  * FIXME ipv6 ip will be baddly parsed (contain ':' )
143  ****************************************************************************/
144 url_t *E_( url_new )  ( char * psz_url )
145 {
146     url_t *p_url = malloc( sizeof( url_t ) );
147
148     char  *psz_dup    = strdup( psz_url );
149     char  *psz_parser = psz_dup;
150
151     char  *psz_tmp;
152
153     /* 1: get hostname:port */
154     while( *psz_parser == '/' )
155     {
156         psz_parser++;
157     }
158
159     psz_tmp = psz_parser;
160
161     while( *psz_parser &&
162            *psz_parser != ':' &&  *psz_parser != '/' && *psz_parser != '@' )
163     {
164         psz_parser++;
165     }
166
167     p_url->psz_host     = strndup( psz_tmp, psz_parser - psz_tmp );
168
169     if( *psz_parser == ':' )
170     {
171         psz_parser++;
172         psz_tmp = psz_parser;
173
174         while( *psz_parser && *psz_parser != '/' && *psz_parser != '@' )
175         {
176             psz_parser++;
177         }
178         p_url->i_port = atoi( psz_tmp );
179     }
180     else
181     {
182         p_url->i_port = 0;
183     }
184
185     /* 2: get path */
186     if( *psz_parser == '/' )
187     {
188         //psz_parser++;
189
190         psz_tmp = psz_parser;
191
192         while( *psz_parser && *psz_parser != '@' )
193         {
194             psz_parser++;
195         }
196
197         p_url->psz_path = strndup( psz_tmp, psz_parser - psz_tmp );
198     }
199     else
200     {
201         p_url->psz_path = strdup( "" );
202     }
203
204     /* 3: usrname and password */
205     if( *psz_parser == '@' )
206     {
207         psz_parser++;
208
209         psz_tmp = psz_parser;
210
211         while( *psz_parser && *psz_parser != ':' )
212         {
213             psz_parser++;
214         }
215
216         p_url->psz_username = strndup( psz_tmp, psz_parser - psz_tmp );
217
218         if( *psz_parser == ':' )
219         {
220             psz_parser++;
221
222             p_url->psz_password = strdup( psz_parser );
223         }
224         else
225         {
226             p_url->psz_password = strdup( "" );
227         }
228     }
229     else
230     {
231         p_url->psz_username = strdup( "" );
232         p_url->psz_password = strdup( "" );
233     }
234 #if 0
235     fprintf( stderr,
236              "host=`%s' port=%d path=`%s' username=`%s' password=`%s'\n",
237              p_url->psz_host,
238              p_url->i_port,
239              p_url->psz_path,
240              p_url->psz_username,
241              p_url->psz_password );
242 #endif
243     free( psz_dup );
244     return p_url;
245 }
246
247 void   E_( url_free ) ( url_t * p_url )
248 {
249     free( p_url->psz_host );
250     free( p_url->psz_path );
251     free( p_url->psz_username );
252     free( p_url->psz_password );
253     free( p_url );
254 }