avio: add and use ffurl_protocol_next().
[libav.git] / libavformat / url.h
CommitLineData
5652bb94
AK
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"
b8404847
AK
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 */
5cec8971 33
026e1757 34extern int (*url_interrupt_cb)(void);
c486dade
AK
35
36typedef 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;
6aa0b98f 45 AVIOInterruptCB interrupt_callback;
c486dade 46} URLContext;
5593f031
AK
47
48typedef struct URLProtocol {
49 const char *name;
50 int (*url_open)( URLContext *h, const char *url, int flags);
51 int (*url_read)( URLContext *h, unsigned char *buf, int size);
52 int (*url_write)(URLContext *h, const unsigned char *buf, int size);
53 int64_t (*url_seek)( URLContext *h, int64_t pos, int whence);
54 int (*url_close)(URLContext *h);
55 struct URLProtocol *next;
56 int (*url_read_pause)(URLContext *h, int pause);
57 int64_t (*url_read_seek)(URLContext *h, int stream_index,
58 int64_t timestamp, int flags);
59 int (*url_get_file_handle)(URLContext *h);
60 int priv_data_size;
61 const AVClass *priv_data_class;
62 int flags;
175389c8 63 int (*url_check)(URLContext *h, int mask);
5593f031 64} URLProtocol;
b8404847 65#endif
5652bb94
AK
66
67/**
68 * Create a URLContext for accessing to the resource indicated by
69 * url, but do not initiate the connection yet.
70 *
71 * @param puc pointer to the location where, in case of success, the
72 * function puts the pointer to the created URLContext
73 * @param flags flags which control how the resource indicated by url
74 * is to be opened
6f1b7b39
MS
75 * @param int_cb interrupt callback to use for the URLContext, may be
76 * NULL
5652bb94
AK
77 * @return 0 in case of success, a negative value corresponding to an
78 * AVERROR code in case of failure
79 */
6f1b7b39
MS
80int ffurl_alloc(URLContext **puc, const char *filename, int flags,
81 const AVIOInterruptCB *int_cb);
5652bb94 82
62eaaeac
AK
83/**
84 * Connect an URLContext that has been allocated by ffurl_alloc
85 */
96c1e6d4 86int ffurl_connect(URLContext *uc);
62eaaeac 87
0589da0a
AK
88/**
89 * Create an URLContext for accessing to the resource indicated by
90 * url, and open it.
91 *
92 * @param puc pointer to the location where, in case of success, the
93 * function puts the pointer to the created URLContext
94 * @param flags flags which control how the resource indicated by url
95 * is to be opened
6f1b7b39
MS
96 * @param int_cb interrupt callback to use for the URLContext, may be
97 * NULL
0589da0a
AK
98 * @return 0 in case of success, a negative value corresponding to an
99 * AVERROR code in case of failure
100 */
6f1b7b39
MS
101int ffurl_open(URLContext **puc, const char *filename, int flags,
102 const AVIOInterruptCB *int_cb);
0589da0a 103
bc371aca
AK
104/**
105 * Read up to size bytes from the resource accessed by h, and store
106 * the read bytes in buf.
107 *
108 * @return The number of bytes actually read, or a negative value
109 * corresponding to an AVERROR code in case of error. A value of zero
110 * indicates that it is not possible to read more from the accessed
111 * resource (except if the value of the size argument is also zero).
112 */
113int ffurl_read(URLContext *h, unsigned char *buf, int size);
114
dce37564
AK
115/**
116 * Read as many bytes as possible (up to size), calling the
117 * read function multiple times if necessary.
118 * This makes special short-read handling in applications
119 * unnecessary, if the return value is < size then it is
120 * certain there was either an error or the end of file was reached.
121 */
122int ffurl_read_complete(URLContext *h, unsigned char *buf, int size);
123
925e908b
AK
124/**
125 * Write size bytes from buf to the resource accessed by h.
126 *
127 * @return the number of bytes actually written, or a negative value
128 * corresponding to an AVERROR code in case of failure
129 */
130int ffurl_write(URLContext *h, const unsigned char *buf, int size);
131
58a48c65
AK
132/**
133 * Change the position that will be used by the next read/write
134 * operation on the resource accessed by h.
135 *
136 * @param pos specifies the new position to set
137 * @param whence specifies how pos should be interpreted, it must be
138 * one of SEEK_SET (seek from the beginning), SEEK_CUR (seek from the
139 * current position), SEEK_END (seek from the end), or AVSEEK_SIZE
140 * (return the filesize of the requested resource, pos is ignored).
141 * @return a negative value corresponding to an AVERROR code in case
142 * of failure, or the resulting file position, measured in bytes from
143 * the beginning of the file. You can use this feature together with
144 * SEEK_CUR to read the current file position.
145 */
146int64_t ffurl_seek(URLContext *h, int64_t pos, int whence);
147
e52a9145
AK
148/**
149 * Close the resource accessed by the URLContext h, and free the
150 * memory used by it.
151 *
152 * @return a negative value if an error condition occurred, 0
153 * otherwise
154 */
155int ffurl_close(URLContext *h);
156
32a97d46
AK
157/**
158 * Return the filesize of the resource accessed by h, AVERROR(ENOSYS)
159 * if the operation is not supported by h, or another negative value
160 * corresponding to an AVERROR error code in case of failure.
161 */
162int64_t ffurl_size(URLContext *h);
163
1869ea03
AK
164/**
165 * Return the file descriptor associated with this URL. For RTP, this
166 * will return only the RTP file descriptor, not the RTCP file descriptor.
167 *
168 * @return the file descriptor associated with this URL, or <0 on error.
169 */
170int ffurl_get_file_handle(URLContext *h);
171
8e76a19b
AK
172/**
173 * Register the URLProtocol protocol.
174 *
175 * @param size the size of the URLProtocol struct referenced
176 */
177int ffurl_register_protocol(URLProtocol *protocol, int size);
178
c4a090dd
MS
179/**
180 * Check if the user has requested to interrup a blocking function
181 * associated with cb.
182 */
183int ff_check_interrupt(AVIOInterruptCB *cb);
184
163a3113
AK
185/**
186 * Iterate over all available protocols.
187 *
188 * @param prev result of the previous call to this functions or NULL.
189 */
190URLProtocol *ffurl_protocol_next(URLProtocol *prev);
191
d6bbe761
AK
192/* udp.c */
193int ff_udp_set_remote_url(URLContext *h, const char *uri);
194int ff_udp_get_local_port(URLContext *h);
195
153382e1 196#endif /* AVFORMAT_URL_H */