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