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