]> git.sesse.net Git - vlc/blob - src/input/access.c
* all: begin to introduce access_t (nothing working yet).
[vlc] / src / input / access.c
1 /*****************************************************************************
2  * access.c
3  *****************************************************************************
4  * Copyright (C) 1999-2004 VideoLAN
5  * $Id: demux.c 7546 2004-04-29 13:53:29Z gbazin $
6  *
7  * Author: 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 #include <stdlib.h>
25 #include <vlc/vlc.h>
26 #include <vlc/input.h>
27
28 #include "ninput.h"
29
30 int access_vaControl( input_thread_t *p_input, int i_query, va_list args )
31 {
32     if( p_input->pf_access_control )
33     {
34         return p_input->pf_access_control( p_input, i_query, args );
35     }
36     return VLC_EGENERIC;
37 }
38
39 int access_Control( input_thread_t *p_input, int i_query, ...  )
40 {
41     va_list args;
42     int     i_result;
43
44     va_start( args, i_query );
45     i_result = access_vaControl( p_input, i_query, args );
46     va_end( args );
47
48     return i_result;
49 }
50
51 int access_vaControlDefault( input_thread_t *p_input, int i_query, va_list args )
52 {
53     return VLC_EGENERIC;
54 }
55
56 /*****************************************************************************
57  * access2_New:
58  *****************************************************************************/
59 access_t *__access2_New( vlc_object_t *p_obj,
60                        char *psz_mrl, stream_t *s, es_out_t *out )
61 {
62     msg_Err( p_obj, "access2_New not yet implemented" );
63     return NULL;
64 #if 0
65     access_t *p_access = vlc_object_create( p_obj, VLC_OBJECT_ACCESS );
66
67     char    *psz_dup = strdup( psz_mrl ? psz_mrl : "" );
68     char    *psz = strchr( psz_dup, ':' );
69     char    *psz_module;
70
71     if( p_demux == NULL )
72     {
73         free( psz_dup );
74         return NULL;
75     }
76
77     /* Parse URL */
78     p_demux->psz_access = NULL;
79     p_demux->psz_demux  = NULL;
80     p_demux->psz_path   = NULL;
81
82     if( psz )
83     {
84         *psz++ = '\0';
85
86         if( psz[0] == '/' && psz[1] == '/' )
87         {
88             psz += 2;
89         }
90         p_demux->psz_path = strdup( psz );
91
92         psz = strchr( psz_dup, '/' );
93         if( psz )
94         {
95             *psz++ = '\0';
96             p_demux->psz_access = strdup( psz_dup );
97             p_demux->psz_demux  = strdup( psz );
98         }
99     }
100     else
101     {
102         p_demux->psz_path = strdup( psz_mrl );
103     }
104     free( psz_dup );
105
106
107     if( p_demux->psz_access == NULL )
108     {
109         p_demux->psz_access = strdup( "" );
110     }
111     if( p_demux->psz_demux == NULL )
112     {
113         p_demux->psz_demux = strdup( "" );
114     }
115     if( p_demux->psz_path == NULL )
116     {
117         p_demux->psz_path = strdup( "" );
118     }
119     msg_Dbg( p_obj, "demux2_New: '%s' -> access='%s' demux='%s' path='%s'",
120              psz_mrl,
121              p_demux->psz_access, p_demux->psz_demux, p_demux->psz_path );
122
123     p_demux->s          = s;
124     p_demux->out        = out;
125
126     p_demux->pf_demux   = NULL;
127     p_demux->pf_control = NULL;
128     p_demux->p_sys      = NULL;
129
130     psz_module = p_demux->psz_demux;
131     if( *psz_module == '\0' && strrchr( p_demux->psz_path, '.' ) )
132     {
133         /* XXX: add only file without any problem here and with strong detection.
134          *  - no .mp3, .a52, ... (aac is added as it works only by file ext anyway
135          *  - wav can't be added 'cause of a52 and dts in them as raw audio
136          */
137         static struct { char *ext; char *demux; } exttodemux[] =
138         {
139             { "aac",  "aac" },
140             { "aiff", "aiff" },
141             { "asf",  "asf" }, { "wmv",  "asf" }, { "wma",  "asf" },
142             { "avi",  "avi" },
143             { "au",   "au" },
144             { "flac", "flac" },
145             { "dv",   "dv" },
146             { "m3u",  "m3u" },
147             { "mkv",  "mkv" }, { "mka",  "mkv" }, { "mks",  "mkv" },
148             { "mp4",  "mp4" }, { "m4a",  "mp4" }, { "mov",  "mp4" }, { "moov", "mp4" },
149             { "mod",  "mod" }, { "xm",   "mod" },
150             { "nsv",  "nsv" },
151             { "ogg",  "ogg" }, { "ogm",  "ogg" },
152             { "pva",  "pva" },
153             { "rm",   "rm" },
154             { "",  "" },
155         };
156
157         char *psz_ext = strrchr( p_demux->psz_path, '.' ) + 1;
158         int  i;
159
160         for( i = 0; exttodemux[i].ext != NULL; i++ )
161         {
162             if( !strcasecmp( psz_ext, exttodemux[i].ext ) )
163             {
164                 psz_module = exttodemux[i].demux;
165                 break;
166             }
167         }
168     }
169
170     /* Before module_Need (for var_Create...) */
171     vlc_object_attach( p_demux, p_obj );
172
173     p_demux->p_module =
174         module_Need( p_demux, "demux2", psz_module,
175                      !strcmp( psz_module, p_demux->psz_demux ) ? VLC_TRUE : VLC_FALSE );
176
177     if( p_demux->p_module == NULL )
178     {
179         vlc_object_detach( p_demux );
180         free( p_demux->psz_path );
181         free( p_demux->psz_demux );
182         free( p_demux->psz_access );
183         vlc_object_destroy( p_demux );
184         return NULL;
185     }
186
187     return p_demux;
188 #endif
189 }
190
191 /*****************************************************************************
192  * demux2_Delete:
193  *****************************************************************************/
194 void access2_Delete( access_t *p_access )
195 {
196     module_Unneed( p_access, p_access->p_module );
197     vlc_object_detach( p_access );
198
199     free( p_access->psz_access );
200     free( p_access->psz_path );
201     free( p_access->psz_demux );
202
203     vlc_object_destroy( p_access );
204 }