]> git.sesse.net Git - vlc/blob - modules/access/mms/mms.c
230e9e210b09c062922738341d536af017cf77d0
[vlc] / modules / access / mms / mms.c
1 /*****************************************************************************
2  * mms.c: MMS over tcp, udp and http access plug-in
3  *****************************************************************************
4  * Copyright (C) 2002-2004 the VideoLAN team
5  * $Id$
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #include <vlc/vlc.h>
29 #include <vlc_access.h>
30
31 #include "mms.h"
32
33 /****************************************************************************
34  * NOTES:
35  *  MMSProtocole documentation found at http://get.to/sdp
36  ****************************************************************************/
37
38 /*****************************************************************************
39  * Module descriptor
40  *****************************************************************************/
41 static int  Open ( vlc_object_t * );
42 static void Close( vlc_object_t * );
43
44 #define CACHING_TEXT N_("Caching value in ms")
45 #define CACHING_LONGTEXT N_( \
46     "Caching value for MMS streams. This " \
47     "value should be set in milliseconds." )
48
49 #define ALL_TEXT N_("Force selection of all streams")
50 #define ALL_LONGTEXT N_( \
51     "MMS streams can contain several elementary streams, with different " \
52     "bitrates. You can choose to select all of them." )
53
54 #define BITRATE_TEXT N_( "Maximum bitrate" )
55 #define BITRATE_LONGTEXT N_( \
56     "Select the stream with the maximum bitrate under that limit."  )
57
58 #define PROXY_TEXT N_("HTTP proxy")
59 #define PROXY_LONGTEXT N_( \
60     "HTTP proxy to be used It must be of the form " \
61     "http://[user[:pass]@]myproxy.mydomain:myport/ ; " \
62     "if empty, the http_proxy environment variable will be tried." )
63
64 vlc_module_begin();
65     set_shortname( "MMS" );
66     set_description( _("Microsoft Media Server (MMS) input") );
67     set_capability( "access2", -1 );
68     set_category( CAT_INPUT );
69     set_subcategory( SUBCAT_INPUT_ACCESS );
70
71     add_integer( "mms-caching", 19 * DEFAULT_PTS_DELAY / 1000, NULL,
72                  CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
73         change_safe();
74
75     add_bool( "mms-all", 0, NULL, ALL_TEXT, ALL_LONGTEXT, VLC_TRUE );
76         change_safe();
77     add_integer( "mms-maxbitrate", 0, NULL, BITRATE_TEXT, BITRATE_LONGTEXT ,
78                  VLC_FALSE );
79         change_safe();
80     add_string( "mmsh-proxy", NULL, NULL, PROXY_TEXT, PROXY_LONGTEXT,
81                     VLC_FALSE );
82         change_safe();
83
84     add_shortcut( "mms" );
85     add_shortcut( "mmsu" );
86     add_shortcut( "mmst" );
87     add_shortcut( "mmsh" );
88     add_shortcut( "http" );
89     set_callbacks( Open, Close );
90 vlc_module_end();
91
92 /*****************************************************************************
93  * Local prototypes
94  *****************************************************************************/
95 struct access_sys_t
96 {
97     int i_proto;
98 };
99
100 /*****************************************************************************
101  * Open:
102  *****************************************************************************/
103 static int Open( vlc_object_t *p_this )
104 {
105     access_t *p_access = (access_t*)p_this;
106
107     /* First set ipv4/ipv6 */
108     var_Create( p_access, "ipv4", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
109     var_Create( p_access, "ipv6", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
110
111     /* mms-caching */
112     var_Create( p_access, "mms-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
113
114     /* use specified method */
115     if( *p_access->psz_access )
116     {
117         if( !strncmp( p_access->psz_access, "mmsu", 4 ) )
118         {
119             return E_( MMSTUOpen )( p_access );
120         }
121         else if( !strncmp( p_access->psz_access, "mmst", 4 ) )
122         {
123             return E_( MMSTUOpen )( p_access );
124         }
125         else if( !strncmp( p_access->psz_access, "mmsh", 4 ) ||
126                  !strncmp( p_access->psz_access, "http", 4 ) )
127         {
128             return E_( MMSHOpen )( p_access );
129         }
130     }
131
132     if( E_( MMSTUOpen )( p_access ) )
133     {
134         /* try mmsh if mmstu failed */
135         return E_( MMSHOpen )( p_access );
136     }
137     return VLC_SUCCESS;
138 }
139
140 /*****************************************************************************
141  * Close: free unused data structures
142  *****************************************************************************/
143 static void Close( vlc_object_t *p_this )
144 {
145     access_t     *p_access = (access_t*)p_this;
146     access_sys_t *p_sys = p_access->p_sys;
147
148     if( ( p_sys->i_proto == MMS_PROTO_TCP ) ||
149         ( p_sys->i_proto == MMS_PROTO_UDP ) )
150     {
151         E_( MMSTUClose )( p_access );
152     }
153     else if( p_sys->i_proto == MMS_PROTO_HTTP )
154     {
155         E_( MMSHClose )( p_access );
156     }
157 }