yading@11
|
1 /*
|
yading@11
|
2 *
|
yading@11
|
3 * This file is part of FFmpeg.
|
yading@11
|
4 *
|
yading@11
|
5 * FFmpeg is free software; you can redistribute it and/or
|
yading@11
|
6 * modify it under the terms of the GNU Lesser General Public
|
yading@11
|
7 * License as published by the Free Software Foundation; either
|
yading@11
|
8 * version 2.1 of the License, or (at your option) any later version.
|
yading@11
|
9 *
|
yading@11
|
10 * FFmpeg is distributed in the hope that it will be useful,
|
yading@11
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@11
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@11
|
13 * Lesser General Public License for more details.
|
yading@11
|
14 *
|
yading@11
|
15 * You should have received a copy of the GNU Lesser General Public
|
yading@11
|
16 * License along with FFmpeg; if not, write to the Free Software
|
yading@11
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@11
|
18 */
|
yading@11
|
19
|
yading@11
|
20 /**
|
yading@11
|
21 * @file
|
yading@11
|
22 * unbuffered private I/O API
|
yading@11
|
23 */
|
yading@11
|
24
|
yading@11
|
25 #ifndef AVFORMAT_URL_H
|
yading@11
|
26 #define AVFORMAT_URL_H
|
yading@11
|
27
|
yading@11
|
28 #include "avio.h"
|
yading@11
|
29 #include "libavformat/version.h"
|
yading@11
|
30
|
yading@11
|
31 #include "libavutil/dict.h"
|
yading@11
|
32 #include "libavutil/log.h"
|
yading@11
|
33
|
yading@11
|
34 #define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */
|
yading@11
|
35 #define URL_PROTOCOL_FLAG_NETWORK 2 /*< The protocol uses network */
|
yading@11
|
36
|
yading@11
|
37 extern int (*url_interrupt_cb)(void);
|
yading@11
|
38
|
yading@11
|
39 extern const AVClass ffurl_context_class;
|
yading@11
|
40
|
yading@11
|
41 typedef struct URLContext {
|
yading@11
|
42 const AVClass *av_class; /**< information for av_log(). Set by url_open(). */
|
yading@11
|
43 struct URLProtocol *prot;
|
yading@11
|
44 void *priv_data;
|
yading@11
|
45 char *filename; /**< specified URL */
|
yading@11
|
46 int flags;
|
yading@11
|
47 int max_packet_size; /**< if non zero, the stream is packetized with this max packet size */
|
yading@11
|
48 int is_streamed; /**< true if streamed (no seek possible), default = false */
|
yading@11
|
49 int is_connected;
|
yading@11
|
50 AVIOInterruptCB interrupt_callback;
|
yading@11
|
51 int64_t rw_timeout; /**< maximum time to wait for (network) read/write operation completion, in mcs */
|
yading@11
|
52 } URLContext;
|
yading@11
|
53
|
yading@11
|
54 typedef struct URLProtocol {
|
yading@11
|
55 const char *name;
|
yading@11
|
56 int (*url_open)( URLContext *h, const char *url, int flags);
|
yading@11
|
57 /**
|
yading@11
|
58 * This callback is to be used by protocols which open further nested
|
yading@11
|
59 * protocols. options are then to be passed to ffurl_open()/ffurl_connect()
|
yading@11
|
60 * for those nested protocols.
|
yading@11
|
61 */
|
yading@11
|
62 int (*url_open2)(URLContext *h, const char *url, int flags, AVDictionary **options);
|
yading@11
|
63
|
yading@11
|
64 /**
|
yading@11
|
65 * Read data from the protocol.
|
yading@11
|
66 * If data is immediately available (even less than size), EOF is
|
yading@11
|
67 * reached or an error occurs (including EINTR), return immediately.
|
yading@11
|
68 * Otherwise:
|
yading@11
|
69 * In non-blocking mode, return AVERROR(EAGAIN) immediately.
|
yading@11
|
70 * In blocking mode, wait for data/EOF/error with a short timeout (0.1s),
|
yading@11
|
71 * and return AVERROR(EAGAIN) on timeout.
|
yading@11
|
72 * Checking interrupt_callback, looping on EINTR and EAGAIN and until
|
yading@11
|
73 * enough data has been read is left to the calling function; see
|
yading@11
|
74 * retry_transfer_wrapper in avio.c.
|
yading@11
|
75 */
|
yading@11
|
76 int (*url_read)( URLContext *h, unsigned char *buf, int size);
|
yading@11
|
77 int (*url_write)(URLContext *h, const unsigned char *buf, int size);
|
yading@11
|
78 int64_t (*url_seek)( URLContext *h, int64_t pos, int whence);
|
yading@11
|
79 int (*url_close)(URLContext *h);
|
yading@11
|
80 struct URLProtocol *next;
|
yading@11
|
81 int (*url_read_pause)(URLContext *h, int pause);
|
yading@11
|
82 int64_t (*url_read_seek)(URLContext *h, int stream_index,
|
yading@11
|
83 int64_t timestamp, int flags);
|
yading@11
|
84 int (*url_get_file_handle)(URLContext *h);
|
yading@11
|
85 int (*url_get_multi_file_handle)(URLContext *h, int **handles,
|
yading@11
|
86 int *numhandles);
|
yading@11
|
87 int (*url_shutdown)(URLContext *h, int flags);
|
yading@11
|
88 int priv_data_size;
|
yading@11
|
89 const AVClass *priv_data_class;
|
yading@11
|
90 int flags;
|
yading@11
|
91 int (*url_check)(URLContext *h, int mask);
|
yading@11
|
92 } URLProtocol;
|
yading@11
|
93
|
yading@11
|
94 /**
|
yading@11
|
95 * Create a URLContext for accessing to the resource indicated by
|
yading@11
|
96 * url, but do not initiate the connection yet.
|
yading@11
|
97 *
|
yading@11
|
98 * @param puc pointer to the location where, in case of success, the
|
yading@11
|
99 * function puts the pointer to the created URLContext
|
yading@11
|
100 * @param flags flags which control how the resource indicated by url
|
yading@11
|
101 * is to be opened
|
yading@11
|
102 * @param int_cb interrupt callback to use for the URLContext, may be
|
yading@11
|
103 * NULL
|
yading@11
|
104 * @return 0 in case of success, a negative value corresponding to an
|
yading@11
|
105 * AVERROR code in case of failure
|
yading@11
|
106 */
|
yading@11
|
107 int ffurl_alloc(URLContext **puc, const char *filename, int flags,
|
yading@11
|
108 const AVIOInterruptCB *int_cb);
|
yading@11
|
109
|
yading@11
|
110 /**
|
yading@11
|
111 * Connect an URLContext that has been allocated by ffurl_alloc
|
yading@11
|
112 *
|
yading@11
|
113 * @param options A dictionary filled with options for nested protocols,
|
yading@11
|
114 * i.e. it will be passed to url_open2() for protocols implementing it.
|
yading@11
|
115 * This parameter will be destroyed and replaced with a dict containing options
|
yading@11
|
116 * that were not found. May be NULL.
|
yading@11
|
117 */
|
yading@11
|
118 int ffurl_connect(URLContext *uc, AVDictionary **options);
|
yading@11
|
119
|
yading@11
|
120 /**
|
yading@11
|
121 * Create an URLContext for accessing to the resource indicated by
|
yading@11
|
122 * url, and open it.
|
yading@11
|
123 *
|
yading@11
|
124 * @param puc pointer to the location where, in case of success, the
|
yading@11
|
125 * function puts the pointer to the created URLContext
|
yading@11
|
126 * @param flags flags which control how the resource indicated by url
|
yading@11
|
127 * is to be opened
|
yading@11
|
128 * @param int_cb interrupt callback to use for the URLContext, may be
|
yading@11
|
129 * NULL
|
yading@11
|
130 * @param options A dictionary filled with protocol-private options. On return
|
yading@11
|
131 * this parameter will be destroyed and replaced with a dict containing options
|
yading@11
|
132 * that were not found. May be NULL.
|
yading@11
|
133 * @return 0 in case of success, a negative value corresponding to an
|
yading@11
|
134 * AVERROR code in case of failure
|
yading@11
|
135 */
|
yading@11
|
136 int ffurl_open(URLContext **puc, const char *filename, int flags,
|
yading@11
|
137 const AVIOInterruptCB *int_cb, AVDictionary **options);
|
yading@11
|
138
|
yading@11
|
139 /**
|
yading@11
|
140 * Read up to size bytes from the resource accessed by h, and store
|
yading@11
|
141 * the read bytes in buf.
|
yading@11
|
142 *
|
yading@11
|
143 * @return The number of bytes actually read, or a negative value
|
yading@11
|
144 * corresponding to an AVERROR code in case of error. A value of zero
|
yading@11
|
145 * indicates that it is not possible to read more from the accessed
|
yading@11
|
146 * resource (except if the value of the size argument is also zero).
|
yading@11
|
147 */
|
yading@11
|
148 int ffurl_read(URLContext *h, unsigned char *buf, int size);
|
yading@11
|
149
|
yading@11
|
150 /**
|
yading@11
|
151 * Read as many bytes as possible (up to size), calling the
|
yading@11
|
152 * read function multiple times if necessary.
|
yading@11
|
153 * This makes special short-read handling in applications
|
yading@11
|
154 * unnecessary, if the return value is < size then it is
|
yading@11
|
155 * certain there was either an error or the end of file was reached.
|
yading@11
|
156 */
|
yading@11
|
157 int ffurl_read_complete(URLContext *h, unsigned char *buf, int size);
|
yading@11
|
158
|
yading@11
|
159 /**
|
yading@11
|
160 * Write size bytes from buf to the resource accessed by h.
|
yading@11
|
161 *
|
yading@11
|
162 * @return the number of bytes actually written, or a negative value
|
yading@11
|
163 * corresponding to an AVERROR code in case of failure
|
yading@11
|
164 */
|
yading@11
|
165 int ffurl_write(URLContext *h, const unsigned char *buf, int size);
|
yading@11
|
166
|
yading@11
|
167 /**
|
yading@11
|
168 * Change the position that will be used by the next read/write
|
yading@11
|
169 * operation on the resource accessed by h.
|
yading@11
|
170 *
|
yading@11
|
171 * @param pos specifies the new position to set
|
yading@11
|
172 * @param whence specifies how pos should be interpreted, it must be
|
yading@11
|
173 * one of SEEK_SET (seek from the beginning), SEEK_CUR (seek from the
|
yading@11
|
174 * current position), SEEK_END (seek from the end), or AVSEEK_SIZE
|
yading@11
|
175 * (return the filesize of the requested resource, pos is ignored).
|
yading@11
|
176 * @return a negative value corresponding to an AVERROR code in case
|
yading@11
|
177 * of failure, or the resulting file position, measured in bytes from
|
yading@11
|
178 * the beginning of the file. You can use this feature together with
|
yading@11
|
179 * SEEK_CUR to read the current file position.
|
yading@11
|
180 */
|
yading@11
|
181 int64_t ffurl_seek(URLContext *h, int64_t pos, int whence);
|
yading@11
|
182
|
yading@11
|
183 /**
|
yading@11
|
184 * Close the resource accessed by the URLContext h, and free the
|
yading@11
|
185 * memory used by it. Also set the URLContext pointer to NULL.
|
yading@11
|
186 *
|
yading@11
|
187 * @return a negative value if an error condition occurred, 0
|
yading@11
|
188 * otherwise
|
yading@11
|
189 */
|
yading@11
|
190 int ffurl_closep(URLContext **h);
|
yading@11
|
191 int ffurl_close(URLContext *h);
|
yading@11
|
192
|
yading@11
|
193 /**
|
yading@11
|
194 * Return the filesize of the resource accessed by h, AVERROR(ENOSYS)
|
yading@11
|
195 * if the operation is not supported by h, or another negative value
|
yading@11
|
196 * corresponding to an AVERROR error code in case of failure.
|
yading@11
|
197 */
|
yading@11
|
198 int64_t ffurl_size(URLContext *h);
|
yading@11
|
199
|
yading@11
|
200 /**
|
yading@11
|
201 * Return the file descriptor associated with this URL. For RTP, this
|
yading@11
|
202 * will return only the RTP file descriptor, not the RTCP file descriptor.
|
yading@11
|
203 *
|
yading@11
|
204 * @return the file descriptor associated with this URL, or <0 on error.
|
yading@11
|
205 */
|
yading@11
|
206 int ffurl_get_file_handle(URLContext *h);
|
yading@11
|
207
|
yading@11
|
208 /**
|
yading@11
|
209 * Return the file descriptors associated with this URL.
|
yading@11
|
210 *
|
yading@11
|
211 * @return 0 on success or <0 on error.
|
yading@11
|
212 */
|
yading@11
|
213 int ffurl_get_multi_file_handle(URLContext *h, int **handles, int *numhandles);
|
yading@11
|
214
|
yading@11
|
215 /**
|
yading@11
|
216 * Signal the URLContext that we are done reading or writing the stream.
|
yading@11
|
217 *
|
yading@11
|
218 * @param h pointer to the resource
|
yading@11
|
219 * @param flags flags which control how the resource indicated by url
|
yading@11
|
220 * is to be shutdown
|
yading@11
|
221 *
|
yading@11
|
222 * @return a negative value if an error condition occurred, 0
|
yading@11
|
223 * otherwise
|
yading@11
|
224 */
|
yading@11
|
225 int ffurl_shutdown(URLContext *h, int flags);
|
yading@11
|
226
|
yading@11
|
227 /**
|
yading@11
|
228 * Register the URLProtocol protocol.
|
yading@11
|
229 *
|
yading@11
|
230 * @param size the size of the URLProtocol struct referenced
|
yading@11
|
231 */
|
yading@11
|
232 int ffurl_register_protocol(URLProtocol *protocol, int size);
|
yading@11
|
233
|
yading@11
|
234 /**
|
yading@11
|
235 * Check if the user has requested to interrup a blocking function
|
yading@11
|
236 * associated with cb.
|
yading@11
|
237 */
|
yading@11
|
238 int ff_check_interrupt(AVIOInterruptCB *cb);
|
yading@11
|
239
|
yading@11
|
240 /**
|
yading@11
|
241 * Iterate over all available protocols.
|
yading@11
|
242 *
|
yading@11
|
243 * @param prev result of the previous call to this functions or NULL.
|
yading@11
|
244 */
|
yading@11
|
245 URLProtocol *ffurl_protocol_next(URLProtocol *prev);
|
yading@11
|
246
|
yading@11
|
247 /* udp.c */
|
yading@11
|
248 int ff_udp_set_remote_url(URLContext *h, const char *uri);
|
yading@11
|
249 int ff_udp_get_local_port(URLContext *h);
|
yading@11
|
250
|
yading@11
|
251 #endif /* AVFORMAT_URL_H */
|