]> git.sesse.net Git - vlc/blob - src/input/access.c
Don't include config.h from the headers - refs #297.
[vlc] / src / input / access.c
1 /*****************************************************************************
2  * access.c
3  *****************************************************************************
4  * Copyright (C) 1999-2004 the VideoLAN team
5  * $Id$
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <vlc/vlc.h>
29
30 #include "input_internal.h"
31
32 /*****************************************************************************
33  * access2_InternalNew:
34  *****************************************************************************/
35 static access_t *access2_InternalNew( vlc_object_t *p_obj, const char *psz_access,
36                                       const char *psz_demux, const char *psz_path,
37                                       access_t *p_source, vlc_bool_t b_quick )
38 {
39     access_t *p_access = vlc_object_create( p_obj, VLC_OBJECT_ACCESS );
40
41     if( p_access == NULL )
42     {
43         msg_Err( p_obj, "vlc_object_create() failed" );
44         return NULL;
45     }
46
47     /* Parse URL */
48     p_access->p_source = p_source;
49     if( p_source )
50     {
51         msg_Dbg( p_obj, "creating access filter '%s'", psz_access );
52         p_access->psz_access = strdup( p_source->psz_access );
53         p_access->psz_path   = strdup( p_source->psz_path );
54         p_access->psz_demux   = strdup( p_source->psz_demux );
55     }
56     else
57     {
58         p_access->psz_path   = strdup( psz_path );
59         if( b_quick )
60         {
61             if( strncmp( psz_path, "file://", 7 ) == 0 )
62                 p_access->psz_access = strdup( "" );
63             else
64                 p_access->psz_access = strdup( "file" );
65         }
66         else
67             p_access->psz_access = strdup( psz_access );
68
69         p_access->psz_demux  = strdup( psz_demux );
70
71         if( !b_quick )
72             msg_Dbg( p_obj, "creating access '%s' path='%s'",
73                      psz_access, psz_path );
74     }
75
76     p_access->pf_read    = NULL;
77     p_access->pf_block   = NULL;
78     p_access->pf_seek    = NULL;
79     p_access->pf_control = NULL;
80     p_access->p_sys      = NULL;
81     p_access->info.i_update = 0;
82     p_access->info.i_size   = 0;
83     p_access->info.i_pos    = 0;
84     p_access->info.b_eof    = VLC_FALSE;
85     p_access->info.b_prebuffered = VLC_FALSE;
86     p_access->info.i_title  = 0;
87     p_access->info.i_seekpoint = 0;
88
89
90     /* Before module_Need (for var_Create...) */
91     vlc_object_attach( p_access, p_obj );
92
93     if( p_source )
94     {
95         p_access->p_module =
96             module_Need( p_access, "access_filter", psz_access, VLC_TRUE );
97     }
98     else
99     {
100         p_access->p_module =
101             module_Need( p_access, "access2", p_access->psz_access, VLC_TRUE );
102     }
103
104     if( p_access->p_module == NULL )
105     {
106         msg_StackAdd( "could not create access" );
107         vlc_object_detach( p_access );
108         free( p_access->psz_access );
109         free( p_access->psz_path );
110         free( p_access->psz_demux );
111         vlc_object_destroy( p_access );
112         return NULL;
113     }
114
115     return p_access;
116 }
117
118 /*****************************************************************************
119  * access2_New:
120  *****************************************************************************/
121 access_t *__access2_New( vlc_object_t *p_obj, const char *psz_access,
122                          const char *psz_demux, const char *psz_path, vlc_bool_t b_quick )
123 {
124     return access2_InternalNew( p_obj, psz_access, psz_demux,
125                                 psz_path, NULL, b_quick );
126 }
127
128 /*****************************************************************************
129  * access2_FilterNew:
130  *****************************************************************************/
131 access_t *access2_FilterNew( access_t *p_source, const char *psz_access_filter )
132 {
133     return access2_InternalNew( VLC_OBJECT(p_source), psz_access_filter,
134                                 NULL, NULL, p_source, VLC_FALSE );
135 }
136
137 /*****************************************************************************
138  * access2_Delete:
139  *****************************************************************************/
140 void access2_Delete( access_t *p_access )
141 {
142     module_Unneed( p_access, p_access->p_module );
143     vlc_object_detach( p_access );
144
145     free( p_access->psz_access );
146     free( p_access->psz_path );
147     free( p_access->psz_demux );
148
149     if( p_access->p_source )
150     {
151         access2_Delete( p_access->p_source );
152     }
153
154     vlc_object_destroy( p_access );
155 }
156