access.c 5.14 KB
Newer Older
1
2
3
/*****************************************************************************
 * access.c
 *****************************************************************************
Jean-Baptiste Kempf's avatar
LGPL    
Jean-Baptiste Kempf committed
4
 * Copyright (C) 1999-2008 VLC authors and VideoLAN
dionoea's avatar
dionoea committed
5
 * $Id$
6
 *
Laurent Aimar's avatar
Laurent Aimar committed
7
 * Author: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
8
 *
Jean-Baptiste Kempf's avatar
LGPL    
Jean-Baptiste Kempf committed
9
10
11
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
12
13
14
15
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
LGPL    
Jean-Baptiste Kempf committed
16
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
18
 *
Jean-Baptiste Kempf's avatar
LGPL    
Jean-Baptiste Kempf committed
19
20
21
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22
23
 *****************************************************************************/

24
25
26
27
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

28
29
#include <assert.h>

30
#include "access.h"
31
#include "input_internal.h"
32
#include <libvlc.h>
33
#include <vlc_url.h>
34
#include <vlc_modules.h>
35
36

/* Decode URL (which has had its scheme stripped earlier) to a file path. */
37
char *get_path(const char *location)
38
39
40
{
    char *url, *path;

Pierre Ynard's avatar
Pierre Ynard committed
41
    /* Prepending "file://" is a bit hackish. But then again, we do not want
42
43
44
45
46
47
48
49
50
     * to hard-code the list of schemes that use file paths in make_path().
     */
    if (asprintf(&url, "file://%s", location) == -1)
        return NULL;

    path = make_path (url);
    free (url);
    return path;
}
51

52
#undef access_New
53
/*****************************************************************************
Laurent Aimar's avatar
Laurent Aimar committed
54
 * access_New:
55
 *****************************************************************************/
56
57
58
access_t *access_New( vlc_object_t *p_obj, input_thread_t *p_parent_input,
                      const char *psz_access, const char *psz_demux,
                      const char *psz_location )
59
{
60
    access_t *p_access = vlc_custom_create( p_obj, sizeof (*p_access),
61
                                            "access" );
62

63
    if( p_access == NULL )
64
65
        return NULL;

Laurent Aimar's avatar
Laurent Aimar committed
66
67
    /* */

68
69
    p_access->p_input = p_parent_input;

70
    p_access->psz_access = strdup( psz_access );
71
    p_access->psz_location = strdup( psz_location );
72
    p_access->psz_filepath = get_path( psz_location );
73
    p_access->psz_demux  = strdup( psz_demux );
74
75
76
    if( p_access->psz_access == NULL || p_access->psz_location == NULL
     || p_access->psz_demux == NULL )
        goto error;
77

78
    msg_Dbg( p_obj, "creating access '%s' location='%s', path='%s'",
79
80
             psz_access, psz_location,
             p_access->psz_filepath ? p_access->psz_filepath : "(null)" );
81

82
83
    p_access->pf_read    = NULL;
    p_access->pf_block   = NULL;
84
    p_access->pf_readdir = NULL;
85
86
87
    p_access->pf_seek    = NULL;
    p_access->pf_control = NULL;
    p_access->p_sys      = NULL;
Laurent Aimar's avatar
Laurent Aimar committed
88

Laurent Aimar's avatar
Laurent Aimar committed
89
    access_InitFields( p_access );
90

Laurent Aimar's avatar
Laurent Aimar committed
91
    p_access->p_module = module_need( p_access, "access", psz_access, true );
92
    if( p_access->p_module == NULL )
93
        goto error;
94

95
    assert( p_access->pf_control != NULL );
96

97
    return p_access;
98
99
100
101
102
103
104
105

error:
    free( p_access->psz_access );
    free( p_access->psz_location );
    free( p_access->psz_filepath );
    free( p_access->psz_demux );
    vlc_object_release( p_access );
    return NULL;
106
107
}

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
access_t *vlc_access_NewMRL(vlc_object_t *parent, const char *mrl)
{
    char *buf = strdup(mrl);
    if (unlikely(buf == NULL))
        return NULL;

    const char *access, *demux, *location, *anchor;
    input_SplitMRL(&access, &demux, &location, &anchor, buf);

    /* Both demux and anchor are ignored, since they are of no use here. */
    access_t *obj = access_New(parent, NULL, access, "", location);

    free(buf);
    return obj;
}

void vlc_access_Delete(access_t *access)
{
126
127
128
129
130
131
132
    module_unneed(access, access->p_module);

    free(access->psz_access);
    free(access->psz_location);
    free(access->psz_filepath);
    free(access->psz_demux);
    vlc_object_release(access);
133
}
134
135
136
137
138
139
140
141
142

/*****************************************************************************
 * access_GetParentInput:
 *****************************************************************************/
input_thread_t * access_GetParentInput( access_t *p_access )
{
    return p_access->p_input ? vlc_object_hold((vlc_object_t *)p_access->p_input) : NULL;
}

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*****************************************************************************
 * access_vaDirectoryControlHelper:
 *****************************************************************************/
int access_vaDirectoryControlHelper( access_t *p_access, int i_query, va_list args )
{
    VLC_UNUSED( p_access );

    switch( i_query )
    {
        case ACCESS_CAN_SEEK:
        case ACCESS_CAN_FASTSEEK:
        case ACCESS_CAN_PAUSE:
        case ACCESS_CAN_CONTROL_PACE:
            *va_arg( args, bool* ) = false;
            break;
        case ACCESS_GET_PTS_DELAY:
            *va_arg( args, int64_t * ) = 0;
            break;
        default:
            return VLC_EGENERIC;
     }
     return VLC_SUCCESS;
}