]> git.sesse.net Git - vlc/blob - src/input/access.c
decoder: fix data race in input_DecoderFrameNext()
[vlc] / src / input / access.c
1 /*****************************************************************************
2  * access.c
3  *****************************************************************************
4  * Copyright (C) 1999-2008 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Author: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * 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 "access.h"
29 #include <libvlc.h>
30 #include <vlc_url.h>
31 #include <vlc_modules.h>
32
33 /* Decode URL (which has had its scheme stripped earlier) to a file path. */
34 char *get_path(const char *location)
35 {
36     char *url, *path;
37
38     /* Prepending "file://" is a bit hackish. But then again, we do not want
39      * to hard-code the list of schemes that use file paths in make_path().
40      */
41     if (asprintf(&url, "file://%s", location) == -1)
42         return NULL;
43
44     path = make_path (url);
45     free (url);
46     return path;
47 }
48
49 #undef access_New
50 /*****************************************************************************
51  * access_New:
52  *****************************************************************************/
53 access_t *access_New( vlc_object_t *p_obj, input_thread_t *p_parent_input,
54                       const char *psz_access, const char *psz_demux,
55                       const char *psz_location )
56 {
57     access_t *p_access = vlc_custom_create( p_obj, sizeof (*p_access),
58                                             "access" );
59
60     if( p_access == NULL )
61         return NULL;
62
63     /* */
64
65     p_access->p_input = p_parent_input;
66
67     p_access->psz_access = strdup( psz_access );
68     p_access->psz_location = strdup( psz_location );
69     p_access->psz_filepath = get_path( psz_location );
70     p_access->psz_demux  = strdup( psz_demux );
71     if( p_access->psz_access == NULL || p_access->psz_location == NULL
72      || p_access->psz_demux == NULL )
73         goto error;
74
75     msg_Dbg( p_obj, "creating access '%s' location='%s', path='%s'",
76              psz_access, psz_location,
77              p_access->psz_filepath ? p_access->psz_filepath : "(null)" );
78
79     p_access->pf_read    = NULL;
80     p_access->pf_block   = NULL;
81     p_access->pf_readdir = NULL;
82     p_access->pf_seek    = NULL;
83     p_access->pf_control = NULL;
84     p_access->p_sys      = NULL;
85
86     access_InitFields( p_access );
87
88     p_access->p_module = module_need( p_access, "access", psz_access, true );
89     if( p_access->p_module == NULL )
90         goto error;
91
92     return p_access;
93
94 error:
95     free( p_access->psz_access );
96     free( p_access->psz_location );
97     free( p_access->psz_filepath );
98     free( p_access->psz_demux );
99     vlc_object_release( p_access );
100     return NULL;
101 }
102
103 /*****************************************************************************
104  * access_Delete:
105  *****************************************************************************/
106 void access_Delete( access_t *p_access )
107 {
108     module_unneed( p_access, p_access->p_module );
109
110     free( p_access->psz_access );
111     free( p_access->psz_location );
112     free( p_access->psz_filepath );
113     free( p_access->psz_demux );
114
115     vlc_object_release( p_access );
116 }
117
118
119 /*****************************************************************************
120  * access_GetParentInput:
121  *****************************************************************************/
122 input_thread_t * access_GetParentInput( access_t *p_access )
123 {
124     return p_access->p_input ? vlc_object_hold((vlc_object_t *)p_access->p_input) : NULL;
125 }
126