~ubuntu-branches/debian/wheezy/vlc/wheezy

« back to all changes in this revision

Viewing changes to modules/access/mms/mms.c

Tags: upstream-0.7.2.final
ImportĀ upstreamĀ versionĀ 0.7.2.final

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 * mms.c: MMS over tcp, udp and http access plug-in
 
3
 *****************************************************************************
 
4
 * Copyright (C) 2002-2004 VideoLAN
 
5
 * $Id: mms.c 7522 2004-04-27 16:35:15Z sam $
 
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 millisecond units." )
 
61
 
 
62
#define ALL_TEXT N_("Force selection of all streams")
 
63
 
 
64
#define BITRATE_TEXT N_("Select maximum bitrate stream")
 
65
#define BITRATE_LONGTEXT N_( \
 
66
    "Always select the stream with the maximum bitrate." )
 
67
 
 
68
vlc_module_begin();
 
69
    set_description( _("Microsoft Media Server (MMS) input") );
 
70
    set_capability( "access", 0 );
 
71
 
 
72
    add_integer( "mms-caching", 4 * DEFAULT_PTS_DELAY / 1000, NULL,
 
73
                 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
 
74
 
 
75
    add_bool( "mms-all", 0, NULL, ALL_TEXT, "", VLC_TRUE );
 
76
    add_integer( "mms-maxbitrate", 0, NULL, BITRATE_TEXT, BITRATE_LONGTEXT ,
 
77
                 VLC_FALSE );
 
78
 
 
79
    add_shortcut( "mms" );
 
80
    add_shortcut( "mmsu" );
 
81
    add_shortcut( "mmst" );
 
82
    add_shortcut( "mmsh" );
 
83
    set_callbacks( Open, Close );
 
84
vlc_module_end();
 
85
 
 
86
/*****************************************************************************
 
87
 * Open:
 
88
 *****************************************************************************/
 
89
static int Open( vlc_object_t *p_this )
 
90
{
 
91
    input_thread_t  *p_input = (input_thread_t*)p_this;
 
92
 
 
93
    /* First set ipv4/ipv6 */
 
94
    var_Create( p_input, "ipv4", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
 
95
    var_Create( p_input, "ipv6", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
 
96
 
 
97
    /* mms-caching */
 
98
    var_Create( p_input, "mms-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
 
99
 
 
100
    /* use specified method */
 
101
    if( *p_input->psz_access )
 
102
    {
 
103
        if( !strncmp( p_input->psz_access, "mmsu", 4 ) )
 
104
        {
 
105
            return E_( MMSTUOpen )( p_input );
 
106
        }
 
107
        else if( !strncmp( p_input->psz_access, "mmst", 4 ) )
 
108
        {
 
109
            return E_( MMSTUOpen )( p_input );
 
110
        }
 
111
        else if( !strncmp( p_input->psz_access, "mmsh", 4 ) )
 
112
        {
 
113
            return E_( MMSHOpen )( p_input );
 
114
        }
 
115
    }
 
116
 
 
117
    if( E_( MMSTUOpen )( p_input ) )
 
118
    {
 
119
        /* try mmsh if mmstu failed */
 
120
        return E_( MMSHOpen )( p_input );
 
121
    }
 
122
    return VLC_SUCCESS;
 
123
}
 
124
 
 
125
/*****************************************************************************
 
126
 * Close: free unused data structures
 
127
 *****************************************************************************/
 
128
static void Close( vlc_object_t *p_this )
 
129
{
 
130
    input_thread_t *  p_input = (input_thread_t *)p_this;
 
131
    access_sys_t   *  p_sys   = p_input->p_access_data;
 
132
 
 
133
    if( p_sys->i_proto == MMS_PROTO_TCP || p_sys->i_proto == MMS_PROTO_UDP )
 
134
    {
 
135
        E_( MMSTUClose )( p_input );
 
136
    }
 
137
    else if( p_sys->i_proto == MMS_PROTO_HTTP )
 
138
    {
 
139
        E_( MMSHClose )( p_input );
 
140
    }
 
141
}
 
142
 
 
143
/****************************************************************************
 
144
 * parse hostname:port/path@username:password
 
145
 * FIXME ipv6 ip will be baddly parsed (contain ':' )
 
146
 ****************************************************************************/
 
147
url_t *E_( url_new )  ( char * psz_url )
 
148
{
 
149
    url_t *p_url = malloc( sizeof( url_t ) );
 
150
 
 
151
    char  *psz_dup    = strdup( psz_url );
 
152
    char  *psz_parser = psz_dup;
 
153
 
 
154
    char  *psz_tmp;
 
155
 
 
156
    /* 1: get hostname:port */
 
157
    while( *psz_parser == '/' )
 
158
    {
 
159
        psz_parser++;
 
160
    }
 
161
 
 
162
    psz_tmp = psz_parser;
 
163
 
 
164
    while( *psz_parser &&
 
165
           *psz_parser != ':' &&  *psz_parser != '/' && *psz_parser != '@' )
 
166
    {
 
167
        psz_parser++;
 
168
    }
 
169
 
 
170
    p_url->psz_host     = strndup( psz_tmp, psz_parser - psz_tmp );
 
171
 
 
172
    if( *psz_parser == ':' )
 
173
    {
 
174
        psz_parser++;
 
175
        psz_tmp = psz_parser;
 
176
 
 
177
        while( *psz_parser && *psz_parser != '/' && *psz_parser != '@' )
 
178
        {
 
179
            psz_parser++;
 
180
        }
 
181
        p_url->i_port = atoi( psz_tmp );
 
182
    }
 
183
    else
 
184
    {
 
185
        p_url->i_port = 0;
 
186
    }
 
187
 
 
188
    /* 2: get path */
 
189
    if( *psz_parser == '/' )
 
190
    {
 
191
        //psz_parser++;
 
192
 
 
193
        psz_tmp = psz_parser;
 
194
 
 
195
        while( *psz_parser && *psz_parser != '@' )
 
196
        {
 
197
            psz_parser++;
 
198
        }
 
199
 
 
200
        p_url->psz_path = strndup( psz_tmp, psz_parser - psz_tmp );
 
201
    }
 
202
    else
 
203
    {
 
204
        p_url->psz_path = strdup( "" );
 
205
    }
 
206
 
 
207
    /* 3: usrname and password */
 
208
    if( *psz_parser == '@' )
 
209
    {
 
210
        psz_parser++;
 
211
 
 
212
        psz_tmp = psz_parser;
 
213
 
 
214
        while( *psz_parser && *psz_parser != ':' )
 
215
        {
 
216
            psz_parser++;
 
217
        }
 
218
 
 
219
        p_url->psz_username = strndup( psz_tmp, psz_parser - psz_tmp );
 
220
 
 
221
        if( *psz_parser == ':' )
 
222
        {
 
223
            psz_parser++;
 
224
 
 
225
            p_url->psz_password = strdup( psz_parser );
 
226
        }
 
227
        else
 
228
        {
 
229
            p_url->psz_password = strdup( "" );
 
230
        }
 
231
    }
 
232
    else
 
233
    {
 
234
        p_url->psz_username = strdup( "" );
 
235
        p_url->psz_password = strdup( "" );
 
236
    }
 
237
#if 0
 
238
    fprintf( stderr,
 
239
             "host=`%s' port=%d path=`%s' username=`%s' password=`%s'\n",
 
240
             p_url->psz_host,
 
241
             p_url->i_port,
 
242
             p_url->psz_path,
 
243
             p_url->psz_username,
 
244
             p_url->psz_password );
 
245
#endif
 
246
    free( psz_dup );
 
247
    return p_url;
 
248
}
 
249
 
 
250
void   E_( url_free ) ( url_t * p_url )
 
251
{
 
252
    free( p_url->psz_host );
 
253
    free( p_url->psz_path );
 
254
    free( p_url->psz_username );
 
255
    free( p_url->psz_password );
 
256
    free( p_url );
 
257
}