Statistics
| Branch: | Revision:

ffmpeg / libavformat / url.h @ 175389c8

History | View | Annotate | Download (6.13 KB)

1
/*
2
 *
3
 * This file is part of Libav.
4
 *
5
 * Libav is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9
 *
10
 * Libav is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with Libav; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
 */
19

    
20
/**
21
 * @file
22
 * unbuffered private I/O API
23
 */
24

    
25
#ifndef AVFORMAT_URL_H
26
#define AVFORMAT_URL_H
27

    
28
#include "avio.h"
29
#include "libavformat/version.h"
30

    
31
#if !FF_API_OLD_AVIO
32
#define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */
33

    
34
extern int (*url_interrupt_cb)(void);
35

    
36
typedef struct URLContext {
37
    const AVClass *av_class;    /**< information for av_log(). Set by url_open(). */
38
    struct URLProtocol *prot;
39
    void *priv_data;
40
    char *filename;             /**< specified URL */
41
    int flags;
42
    int max_packet_size;        /**< if non zero, the stream is packetized with this max packet size */
43
    int is_streamed;            /**< true if streamed (no seek possible), default = false */
44
    int is_connected;
45
} URLContext;
46

    
47
typedef struct URLProtocol {
48
    const char *name;
49
    int     (*url_open)( URLContext *h, const char *url, int flags);
50
    int     (*url_read)( URLContext *h, unsigned char *buf, int size);
51
    int     (*url_write)(URLContext *h, const unsigned char *buf, int size);
52
    int64_t (*url_seek)( URLContext *h, int64_t pos, int whence);
53
    int     (*url_close)(URLContext *h);
54
    struct URLProtocol *next;
55
    int (*url_read_pause)(URLContext *h, int pause);
56
    int64_t (*url_read_seek)(URLContext *h, int stream_index,
57
                             int64_t timestamp, int flags);
58
    int (*url_get_file_handle)(URLContext *h);
59
    int priv_data_size;
60
    const AVClass *priv_data_class;
61
    int flags;
62
    int (*url_check)(URLContext *h, int mask);
63
} URLProtocol;
64
#endif
65

    
66
/**
67
 * Create a URLContext for accessing to the resource indicated by
68
 * url, but do not initiate the connection yet.
69
 *
70
 * @param puc pointer to the location where, in case of success, the
71
 * function puts the pointer to the created URLContext
72
 * @param flags flags which control how the resource indicated by url
73
 * is to be opened
74
 * @return 0 in case of success, a negative value corresponding to an
75
 * AVERROR code in case of failure
76
 */
77
int ffurl_alloc(URLContext **h, const char *url, int flags);
78

    
79
/**
80
 * Connect an URLContext that has been allocated by ffurl_alloc
81
 */
82
int ffurl_connect(URLContext *h);
83

    
84
/**
85
 * Create an URLContext for accessing to the resource indicated by
86
 * url, and open it.
87
 *
88
 * @param puc pointer to the location where, in case of success, the
89
 * function puts the pointer to the created URLContext
90
 * @param flags flags which control how the resource indicated by url
91
 * is to be opened
92
 * @return 0 in case of success, a negative value corresponding to an
93
 * AVERROR code in case of failure
94
 */
95
int ffurl_open(URLContext **h, const char *url, int flags);
96

    
97
/**
98
 * Read up to size bytes from the resource accessed by h, and store
99
 * the read bytes in buf.
100
 *
101
 * @return The number of bytes actually read, or a negative value
102
 * corresponding to an AVERROR code in case of error. A value of zero
103
 * indicates that it is not possible to read more from the accessed
104
 * resource (except if the value of the size argument is also zero).
105
 */
106
int ffurl_read(URLContext *h, unsigned char *buf, int size);
107

    
108
/**
109
 * Read as many bytes as possible (up to size), calling the
110
 * read function multiple times if necessary.
111
 * This makes special short-read handling in applications
112
 * unnecessary, if the return value is < size then it is
113
 * certain there was either an error or the end of file was reached.
114
 */
115
int ffurl_read_complete(URLContext *h, unsigned char *buf, int size);
116

    
117
/**
118
 * Write size bytes from buf to the resource accessed by h.
119
 *
120
 * @return the number of bytes actually written, or a negative value
121
 * corresponding to an AVERROR code in case of failure
122
 */
123
int ffurl_write(URLContext *h, const unsigned char *buf, int size);
124

    
125
/**
126
 * Change the position that will be used by the next read/write
127
 * operation on the resource accessed by h.
128
 *
129
 * @param pos specifies the new position to set
130
 * @param whence specifies how pos should be interpreted, it must be
131
 * one of SEEK_SET (seek from the beginning), SEEK_CUR (seek from the
132
 * current position), SEEK_END (seek from the end), or AVSEEK_SIZE
133
 * (return the filesize of the requested resource, pos is ignored).
134
 * @return a negative value corresponding to an AVERROR code in case
135
 * of failure, or the resulting file position, measured in bytes from
136
 * the beginning of the file. You can use this feature together with
137
 * SEEK_CUR to read the current file position.
138
 */
139
int64_t ffurl_seek(URLContext *h, int64_t pos, int whence);
140

    
141
/**
142
 * Close the resource accessed by the URLContext h, and free the
143
 * memory used by it.
144
 *
145
 * @return a negative value if an error condition occurred, 0
146
 * otherwise
147
 */
148
int ffurl_close(URLContext *h);
149

    
150
/**
151
 * Return the filesize of the resource accessed by h, AVERROR(ENOSYS)
152
 * if the operation is not supported by h, or another negative value
153
 * corresponding to an AVERROR error code in case of failure.
154
 */
155
int64_t ffurl_size(URLContext *h);
156

    
157
/**
158
 * Return the file descriptor associated with this URL. For RTP, this
159
 * will return only the RTP file descriptor, not the RTCP file descriptor.
160
 *
161
 * @return the file descriptor associated with this URL, or <0 on error.
162
 */
163
int ffurl_get_file_handle(URLContext *h);
164

    
165
/**
166
 * Register the URLProtocol protocol.
167
 *
168
 * @param size the size of the URLProtocol struct referenced
169
 */
170
int ffurl_register_protocol(URLProtocol *protocol, int size);
171

    
172
/* udp.c */
173
int ff_udp_set_remote_url(URLContext *h, const char *uri);
174
int ff_udp_get_local_port(URLContext *h);
175

    
176
#endif //AVFORMAT_URL_H