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