ffmpeg / libavformat / avio.h @ 230a4686
History | View | Annotate | Download (22.7 KB)
1 |
/*
|
---|---|
2 |
* copyright (c) 2001 Fabrice Bellard
|
3 |
*
|
4 |
* This file is part of Libav.
|
5 |
*
|
6 |
* Libav is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU Lesser General Public
|
8 |
* License as published by the Free Software Foundation; either
|
9 |
* version 2.1 of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* Libav is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
* Lesser General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU Lesser General Public
|
17 |
* License along with Libav; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
19 |
*/
|
20 |
#ifndef AVFORMAT_AVIO_H
|
21 |
#define AVFORMAT_AVIO_H
|
22 |
|
23 |
/**
|
24 |
* @file
|
25 |
* unbuffered I/O operations
|
26 |
*
|
27 |
* @warning This file has to be considered an internal but installed
|
28 |
* header, so it should not be directly included in your projects.
|
29 |
*/
|
30 |
|
31 |
#include <stdint.h> |
32 |
|
33 |
#include "libavutil/common.h" |
34 |
#include "libavutil/log.h" |
35 |
|
36 |
#include "libavformat/version.h" |
37 |
|
38 |
/* unbuffered I/O */
|
39 |
|
40 |
/**
|
41 |
* URL Context.
|
42 |
* New fields can be added to the end with minor version bumps.
|
43 |
* Removal, reordering and changes to existing fields require a major
|
44 |
* version bump.
|
45 |
* sizeof(URLContext) must not be used outside libav*.
|
46 |
*/
|
47 |
typedef struct URLContext { |
48 |
#if FF_API_URL_CLASS
|
49 |
const AVClass *av_class; ///< information for av_log(). Set by url_open(). |
50 |
#endif
|
51 |
struct URLProtocol *prot;
|
52 |
int flags;
|
53 |
int is_streamed; /**< true if streamed (no seek possible), default = false */ |
54 |
int max_packet_size; /**< if non zero, the stream is packetized with this max packet size */ |
55 |
void *priv_data;
|
56 |
char *filename; /**< specified URL */ |
57 |
int is_connected;
|
58 |
} URLContext; |
59 |
|
60 |
#if FF_API_OLD_AVIO
|
61 |
typedef struct URLPollEntry { |
62 |
URLContext *handle; |
63 |
int events;
|
64 |
int revents;
|
65 |
} URLPollEntry; |
66 |
#endif
|
67 |
|
68 |
/**
|
69 |
* @defgroup open_modes URL open modes
|
70 |
* The flags argument to url_open and cosins must be one of the following
|
71 |
* constants, optionally ORed with other flags.
|
72 |
* @{
|
73 |
*/
|
74 |
#define URL_RDONLY 0 /**< read-only */ |
75 |
#define URL_WRONLY 1 /**< write-only */ |
76 |
#define URL_RDWR 2 /**< read-write */ |
77 |
/**
|
78 |
* @}
|
79 |
*/
|
80 |
|
81 |
/**
|
82 |
* Use non-blocking mode.
|
83 |
* If this flag is set, operations on the context will return
|
84 |
* AVERROR(EAGAIN) if they can not be performed immediately.
|
85 |
* If this flag is not set, operations on the context will never return
|
86 |
* AVERROR(EAGAIN).
|
87 |
* Note that this flag does not affect the opening/connecting of the
|
88 |
* context. Connecting a protocol will always block if necessary (e.g. on
|
89 |
* network protocols) but never hang (e.g. on busy devices).
|
90 |
* Warning: non-blocking protocols is work-in-progress; this flag may be
|
91 |
* silently ignored.
|
92 |
*/
|
93 |
#define URL_FLAG_NONBLOCK 4 |
94 |
|
95 |
typedef int URLInterruptCB(void); |
96 |
|
97 |
#if FF_API_OLD_AVIO
|
98 |
/**
|
99 |
* @defgroup old_url_funcs Old url_* functions
|
100 |
* @deprecated use the buffered API based on AVIOContext instead
|
101 |
* @{
|
102 |
*/
|
103 |
attribute_deprecated int url_open_protocol (URLContext **puc, struct URLProtocol *up, |
104 |
const char *url, int flags); |
105 |
attribute_deprecated int url_alloc(URLContext **h, const char *url, int flags); |
106 |
attribute_deprecated int url_connect(URLContext *h);
|
107 |
attribute_deprecated int url_open(URLContext **h, const char *url, int flags); |
108 |
attribute_deprecated int url_read(URLContext *h, unsigned char *buf, int size); |
109 |
attribute_deprecated int url_read_complete(URLContext *h, unsigned char *buf, int size); |
110 |
attribute_deprecated int url_write(URLContext *h, const unsigned char *buf, int size); |
111 |
#endif
|
112 |
|
113 |
/**
|
114 |
* Change the position that will be used by the next read/write
|
115 |
* operation on the resource accessed by h.
|
116 |
*
|
117 |
* @param pos specifies the new position to set
|
118 |
* @param whence specifies how pos should be interpreted, it must be
|
119 |
* one of SEEK_SET (seek from the beginning), SEEK_CUR (seek from the
|
120 |
* current position), SEEK_END (seek from the end), or AVSEEK_SIZE
|
121 |
* (return the filesize of the requested resource, pos is ignored).
|
122 |
* @return a negative value corresponding to an AVERROR code in case
|
123 |
* of failure, or the resulting file position, measured in bytes from
|
124 |
* the beginning of the file. You can use this feature together with
|
125 |
* SEEK_CUR to read the current file position.
|
126 |
*/
|
127 |
int64_t url_seek(URLContext *h, int64_t pos, int whence);
|
128 |
|
129 |
/**
|
130 |
* Close the resource accessed by the URLContext h, and free the
|
131 |
* memory used by it.
|
132 |
*
|
133 |
* @return a negative value if an error condition occurred, 0
|
134 |
* otherwise
|
135 |
*/
|
136 |
int url_close(URLContext *h);
|
137 |
|
138 |
/**
|
139 |
* Return a non-zero value if the resource indicated by url
|
140 |
* exists, 0 otherwise.
|
141 |
*/
|
142 |
int url_exist(const char *url); |
143 |
|
144 |
/**
|
145 |
* Return the filesize of the resource accessed by h, AVERROR(ENOSYS)
|
146 |
* if the operation is not supported by h, or another negative value
|
147 |
* corresponding to an AVERROR error code in case of failure.
|
148 |
*/
|
149 |
int64_t url_filesize(URLContext *h); |
150 |
|
151 |
/**
|
152 |
* Return the file descriptor associated with this URL. For RTP, this
|
153 |
* will return only the RTP file descriptor, not the RTCP file descriptor.
|
154 |
*
|
155 |
* @return the file descriptor associated with this URL, or <0 on error.
|
156 |
*/
|
157 |
int url_get_file_handle(URLContext *h);
|
158 |
|
159 |
/**
|
160 |
* Return the maximum packet size associated to packetized file
|
161 |
* handle. If the file is not packetized (stream like HTTP or file on
|
162 |
* disk), then 0 is returned.
|
163 |
*
|
164 |
* @param h file handle
|
165 |
* @return maximum packet size in bytes
|
166 |
*/
|
167 |
int url_get_max_packet_size(URLContext *h);
|
168 |
|
169 |
/**
|
170 |
* Copy the filename of the resource accessed by h to buf.
|
171 |
*
|
172 |
* @param buf_size size in bytes of buf
|
173 |
*/
|
174 |
void url_get_filename(URLContext *h, char *buf, int buf_size); |
175 |
|
176 |
/**
|
177 |
* The callback is called in blocking functions to test regulary if
|
178 |
* asynchronous interruption is needed. AVERROR_EXIT is returned
|
179 |
* in this case by the interrupted function. 'NULL' means no interrupt
|
180 |
* callback is given.
|
181 |
*/
|
182 |
void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
|
183 |
|
184 |
#if FF_API_OLD_AVIO
|
185 |
/* not implemented */
|
186 |
attribute_deprecated int url_poll(URLPollEntry *poll_table, int n, int timeout); |
187 |
#endif
|
188 |
|
189 |
/**
|
190 |
* Pause and resume playing - only meaningful if using a network streaming
|
191 |
* protocol (e.g. MMS).
|
192 |
* @param pause 1 for pause, 0 for resume
|
193 |
*/
|
194 |
int av_url_read_pause(URLContext *h, int pause); |
195 |
|
196 |
/**
|
197 |
* Seek to a given timestamp relative to some component stream.
|
198 |
* Only meaningful if using a network streaming protocol (e.g. MMS.).
|
199 |
* @param stream_index The stream index that the timestamp is relative to.
|
200 |
* If stream_index is (-1) the timestamp should be in AV_TIME_BASE
|
201 |
* units from the beginning of the presentation.
|
202 |
* If a stream_index >= 0 is used and the protocol does not support
|
203 |
* seeking based on component streams, the call will fail with ENOTSUP.
|
204 |
* @param timestamp timestamp in AVStream.time_base units
|
205 |
* or if there is no stream specified then in AV_TIME_BASE units.
|
206 |
* @param flags Optional combination of AVSEEK_FLAG_BACKWARD, AVSEEK_FLAG_BYTE
|
207 |
* and AVSEEK_FLAG_ANY. The protocol may silently ignore
|
208 |
* AVSEEK_FLAG_BACKWARD and AVSEEK_FLAG_ANY, but AVSEEK_FLAG_BYTE will
|
209 |
* fail with ENOTSUP if used and not supported.
|
210 |
* @return >= 0 on success
|
211 |
* @see AVInputFormat::read_seek
|
212 |
*/
|
213 |
int64_t av_url_read_seek(URLContext *h, int stream_index,
|
214 |
int64_t timestamp, int flags);
|
215 |
|
216 |
#define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */ |
217 |
|
218 |
typedef struct URLProtocol { |
219 |
const char *name; |
220 |
int (*url_open)(URLContext *h, const char *url, int flags); |
221 |
int (*url_read)(URLContext *h, unsigned char *buf, int size); |
222 |
int (*url_write)(URLContext *h, const unsigned char *buf, int size); |
223 |
int64_t (*url_seek)(URLContext *h, int64_t pos, int whence);
|
224 |
int (*url_close)(URLContext *h);
|
225 |
struct URLProtocol *next;
|
226 |
int (*url_read_pause)(URLContext *h, int pause); |
227 |
int64_t (*url_read_seek)(URLContext *h, int stream_index,
|
228 |
int64_t timestamp, int flags);
|
229 |
int (*url_get_file_handle)(URLContext *h);
|
230 |
int priv_data_size;
|
231 |
const AVClass *priv_data_class;
|
232 |
int flags;
|
233 |
} URLProtocol; |
234 |
|
235 |
#if FF_API_REGISTER_PROTOCOL
|
236 |
extern URLProtocol *first_protocol;
|
237 |
#endif
|
238 |
|
239 |
extern URLInterruptCB *url_interrupt_cb;
|
240 |
|
241 |
/**
|
242 |
* If protocol is NULL, returns the first registered protocol,
|
243 |
* if protocol is non-NULL, returns the next registered protocol after protocol,
|
244 |
* or NULL if protocol is the last one.
|
245 |
*/
|
246 |
URLProtocol *av_protocol_next(URLProtocol *p); |
247 |
|
248 |
#if FF_API_REGISTER_PROTOCOL
|
249 |
/**
|
250 |
* @deprecated Use av_register_protocol() instead.
|
251 |
*/
|
252 |
attribute_deprecated int register_protocol(URLProtocol *protocol);
|
253 |
|
254 |
/**
|
255 |
* @deprecated Use av_register_protocol2() instead.
|
256 |
*/
|
257 |
attribute_deprecated int av_register_protocol(URLProtocol *protocol);
|
258 |
#endif
|
259 |
|
260 |
/**
|
261 |
* Register the URLProtocol protocol.
|
262 |
*
|
263 |
* @param size the size of the URLProtocol struct referenced
|
264 |
*/
|
265 |
int av_register_protocol2(URLProtocol *protocol, int size); |
266 |
|
267 |
#define AVIO_SEEKABLE_NORMAL 0x0001 /**< Seeking works like for a local file */ |
268 |
|
269 |
/**
|
270 |
* @}
|
271 |
*/
|
272 |
|
273 |
/**
|
274 |
* Bytestream IO Context.
|
275 |
* New fields can be added to the end with minor version bumps.
|
276 |
* Removal, reordering and changes to existing fields require a major
|
277 |
* version bump.
|
278 |
* sizeof(AVIOContext) must not be used outside libav*.
|
279 |
*/
|
280 |
typedef struct { |
281 |
unsigned char *buffer; |
282 |
int buffer_size;
|
283 |
unsigned char *buf_ptr, *buf_end; |
284 |
void *opaque;
|
285 |
int (*read_packet)(void *opaque, uint8_t *buf, int buf_size); |
286 |
int (*write_packet)(void *opaque, uint8_t *buf, int buf_size); |
287 |
int64_t (*seek)(void *opaque, int64_t offset, int whence); |
288 |
int64_t pos; /**< position in the file of the current buffer */
|
289 |
int must_flush; /**< true if the next seek should flush */ |
290 |
int eof_reached; /**< true if eof reached */ |
291 |
int write_flag; /**< true if open for writing */ |
292 |
#if FF_API_OLD_AVIO
|
293 |
attribute_deprecated int is_streamed;
|
294 |
#endif
|
295 |
int max_packet_size;
|
296 |
unsigned long checksum; |
297 |
unsigned char *checksum_ptr; |
298 |
unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size); |
299 |
int error; ///< contains the error code or 0 if no error happened |
300 |
int (*read_pause)(void *opaque, int pause); |
301 |
int64_t (*read_seek)(void *opaque, int stream_index, |
302 |
int64_t timestamp, int flags);
|
303 |
/**
|
304 |
* A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
|
305 |
*/
|
306 |
int seekable;
|
307 |
} AVIOContext; |
308 |
|
309 |
#if FF_API_OLD_AVIO
|
310 |
typedef attribute_deprecated AVIOContext ByteIOContext;
|
311 |
|
312 |
attribute_deprecated int init_put_byte(AVIOContext *s,
|
313 |
unsigned char *buffer, |
314 |
int buffer_size,
|
315 |
int write_flag,
|
316 |
void *opaque,
|
317 |
int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), |
318 |
int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), |
319 |
int64_t (*seek)(void *opaque, int64_t offset, int whence)); |
320 |
attribute_deprecated AVIOContext *av_alloc_put_byte( |
321 |
unsigned char *buffer, |
322 |
int buffer_size,
|
323 |
int write_flag,
|
324 |
void *opaque,
|
325 |
int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), |
326 |
int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), |
327 |
int64_t (*seek)(void *opaque, int64_t offset, int whence)); |
328 |
|
329 |
/**
|
330 |
* @defgroup old_avio_funcs Old put_/get_*() functions
|
331 |
* @deprecated use the avio_ -prefixed functions instead.
|
332 |
* @{
|
333 |
*/
|
334 |
attribute_deprecated int get_buffer(AVIOContext *s, unsigned char *buf, int size); |
335 |
attribute_deprecated int get_partial_buffer(AVIOContext *s, unsigned char *buf, int size); |
336 |
attribute_deprecated int get_byte(AVIOContext *s);
|
337 |
attribute_deprecated unsigned int get_le16(AVIOContext *s); |
338 |
attribute_deprecated unsigned int get_le24(AVIOContext *s); |
339 |
attribute_deprecated unsigned int get_le32(AVIOContext *s); |
340 |
attribute_deprecated uint64_t get_le64(AVIOContext *s); |
341 |
attribute_deprecated unsigned int get_be16(AVIOContext *s); |
342 |
attribute_deprecated unsigned int get_be24(AVIOContext *s); |
343 |
attribute_deprecated unsigned int get_be32(AVIOContext *s); |
344 |
attribute_deprecated uint64_t get_be64(AVIOContext *s); |
345 |
|
346 |
attribute_deprecated void put_byte(AVIOContext *s, int b); |
347 |
attribute_deprecated void put_nbyte(AVIOContext *s, int b, int count); |
348 |
attribute_deprecated void put_buffer(AVIOContext *s, const unsigned char *buf, int size); |
349 |
attribute_deprecated void put_le64(AVIOContext *s, uint64_t val);
|
350 |
attribute_deprecated void put_be64(AVIOContext *s, uint64_t val);
|
351 |
attribute_deprecated void put_le32(AVIOContext *s, unsigned int val); |
352 |
attribute_deprecated void put_be32(AVIOContext *s, unsigned int val); |
353 |
attribute_deprecated void put_le24(AVIOContext *s, unsigned int val); |
354 |
attribute_deprecated void put_be24(AVIOContext *s, unsigned int val); |
355 |
attribute_deprecated void put_le16(AVIOContext *s, unsigned int val); |
356 |
attribute_deprecated void put_be16(AVIOContext *s, unsigned int val); |
357 |
attribute_deprecated void put_tag(AVIOContext *s, const char *tag); |
358 |
/**
|
359 |
* @}
|
360 |
*/
|
361 |
|
362 |
attribute_deprecated int av_url_read_fpause(AVIOContext *h, int pause); |
363 |
attribute_deprecated int64_t av_url_read_fseek (AVIOContext *h, int stream_index,
|
364 |
int64_t timestamp, int flags);
|
365 |
|
366 |
/**
|
367 |
* @defgroup old_url_f_funcs Old url_f* functions
|
368 |
* @deprecated use the avio_ -prefixed functions instead.
|
369 |
* @{
|
370 |
*/
|
371 |
attribute_deprecated int url_fopen( AVIOContext **s, const char *url, int flags); |
372 |
attribute_deprecated int url_fclose(AVIOContext *s);
|
373 |
attribute_deprecated int64_t url_fseek(AVIOContext *s, int64_t offset, int whence);
|
374 |
attribute_deprecated int url_fskip(AVIOContext *s, int64_t offset);
|
375 |
attribute_deprecated int64_t url_ftell(AVIOContext *s); |
376 |
attribute_deprecated int64_t url_fsize(AVIOContext *s); |
377 |
#define URL_EOF (-1) |
378 |
attribute_deprecated int url_fgetc(AVIOContext *s);
|
379 |
attribute_deprecated int url_setbufsize(AVIOContext *s, int buf_size); |
380 |
#ifdef __GNUC__
|
381 |
attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); |
382 |
#else
|
383 |
attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...); |
384 |
#endif
|
385 |
attribute_deprecated void put_flush_packet(AVIOContext *s);
|
386 |
attribute_deprecated int url_open_dyn_buf(AVIOContext **s);
|
387 |
attribute_deprecated int url_open_dyn_packet_buf(AVIOContext **s, int max_packet_size); |
388 |
attribute_deprecated int url_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
|
389 |
attribute_deprecated int url_fdopen(AVIOContext **s, URLContext *h);
|
390 |
/**
|
391 |
* @}
|
392 |
*/
|
393 |
|
394 |
/**
|
395 |
* @deprecated use AVIOContext.eof_reached
|
396 |
*/
|
397 |
attribute_deprecated int url_feof(AVIOContext *s);
|
398 |
attribute_deprecated int url_ferror(AVIOContext *s);
|
399 |
|
400 |
attribute_deprecated int udp_set_remote_url(URLContext *h, const char *uri); |
401 |
attribute_deprecated int udp_get_local_port(URLContext *h);
|
402 |
|
403 |
attribute_deprecated void init_checksum(AVIOContext *s,
|
404 |
unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), |
405 |
unsigned long checksum); |
406 |
attribute_deprecated unsigned long get_checksum(AVIOContext *s); |
407 |
#endif
|
408 |
|
409 |
/**
|
410 |
* Allocate and initialize an AVIOContext for buffered I/O. It must be later
|
411 |
* freed with av_free().
|
412 |
*
|
413 |
* @param buffer Memory block for input/output operations via AVIOContext.
|
414 |
* @param buffer_size The buffer size is very important for performance.
|
415 |
* For protocols with fixed blocksize it should be set to this blocksize.
|
416 |
* For others a typical size is a cache page, e.g. 4kb.
|
417 |
* @param write_flag Set to 1 if the buffer should be writable, 0 otherwise.
|
418 |
* @param opaque An opaque pointer to user-specific data.
|
419 |
* @param read_packet A function for refilling the buffer, may be NULL.
|
420 |
* @param write_packet A function for writing the buffer contents, may be NULL.
|
421 |
* @param seek A function for seeking to specified byte position, may be NULL.
|
422 |
*
|
423 |
* @return Allocated AVIOContext or NULL on failure.
|
424 |
*/
|
425 |
AVIOContext *avio_alloc_context( |
426 |
unsigned char *buffer, |
427 |
int buffer_size,
|
428 |
int write_flag,
|
429 |
void *opaque,
|
430 |
int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), |
431 |
int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), |
432 |
int64_t (*seek)(void *opaque, int64_t offset, int whence)); |
433 |
|
434 |
void avio_w8(AVIOContext *s, int b); |
435 |
void avio_write(AVIOContext *s, const unsigned char *buf, int size); |
436 |
void avio_wl64(AVIOContext *s, uint64_t val);
|
437 |
void avio_wb64(AVIOContext *s, uint64_t val);
|
438 |
void avio_wl32(AVIOContext *s, unsigned int val); |
439 |
void avio_wb32(AVIOContext *s, unsigned int val); |
440 |
void avio_wl24(AVIOContext *s, unsigned int val); |
441 |
void avio_wb24(AVIOContext *s, unsigned int val); |
442 |
void avio_wl16(AVIOContext *s, unsigned int val); |
443 |
void avio_wb16(AVIOContext *s, unsigned int val); |
444 |
|
445 |
#if FF_API_OLD_AVIO
|
446 |
attribute_deprecated void put_strz(AVIOContext *s, const char *buf); |
447 |
#endif
|
448 |
|
449 |
/**
|
450 |
* Write a NULL-terminated string.
|
451 |
* @return number of bytes written.
|
452 |
*/
|
453 |
int avio_put_str(AVIOContext *s, const char *str); |
454 |
|
455 |
/**
|
456 |
* Convert an UTF-8 string to UTF-16LE and write it.
|
457 |
* @return number of bytes written.
|
458 |
*/
|
459 |
int avio_put_str16le(AVIOContext *s, const char *str); |
460 |
|
461 |
/**
|
462 |
* Passing this as the "whence" parameter to a seek function causes it to
|
463 |
* return the filesize without seeking anywhere. Supporting this is optional.
|
464 |
* If it is not supported then the seek function will return <0.
|
465 |
*/
|
466 |
#define AVSEEK_SIZE 0x10000 |
467 |
|
468 |
/**
|
469 |
* Oring this flag as into the "whence" parameter to a seek function causes it to
|
470 |
* seek by any means (like reopening and linear reading) or other normally unreasonble
|
471 |
* means that can be extreemly slow.
|
472 |
* This may be ignored by the seek code.
|
473 |
*/
|
474 |
#define AVSEEK_FORCE 0x20000 |
475 |
|
476 |
/**
|
477 |
* fseek() equivalent for AVIOContext.
|
478 |
* @return new position or AVERROR.
|
479 |
*/
|
480 |
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence);
|
481 |
|
482 |
/**
|
483 |
* Skip given number of bytes forward
|
484 |
* @return new position or AVERROR.
|
485 |
*/
|
486 |
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
|
487 |
{ |
488 |
return avio_seek(s, offset, SEEK_CUR);
|
489 |
} |
490 |
|
491 |
/**
|
492 |
* ftell() equivalent for AVIOContext.
|
493 |
* @return position or AVERROR.
|
494 |
*/
|
495 |
static av_always_inline int64_t avio_tell(AVIOContext *s)
|
496 |
{ |
497 |
return avio_seek(s, 0, SEEK_CUR); |
498 |
} |
499 |
|
500 |
/**
|
501 |
* Get the filesize.
|
502 |
* @return filesize or AVERROR
|
503 |
*/
|
504 |
int64_t avio_size(AVIOContext *s); |
505 |
|
506 |
/** @warning currently size is limited */
|
507 |
#ifdef __GNUC__
|
508 |
int avio_printf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); |
509 |
#else
|
510 |
int avio_printf(AVIOContext *s, const char *fmt, ...); |
511 |
#endif
|
512 |
|
513 |
#if FF_API_OLD_AVIO
|
514 |
/** @note unlike fgets, the EOL character is not returned and a whole
|
515 |
line is parsed. return NULL if first char read was EOF */
|
516 |
attribute_deprecated char *url_fgets(AVIOContext *s, char *buf, int buf_size); |
517 |
#endif
|
518 |
|
519 |
void avio_flush(AVIOContext *s);
|
520 |
|
521 |
|
522 |
/**
|
523 |
* Read size bytes from AVIOContext into buf.
|
524 |
* @return number of bytes read or AVERROR
|
525 |
*/
|
526 |
int avio_read(AVIOContext *s, unsigned char *buf, int size); |
527 |
|
528 |
/** @note return 0 if EOF, so you cannot use it if EOF handling is
|
529 |
necessary */
|
530 |
int avio_r8 (AVIOContext *s);
|
531 |
unsigned int avio_rl16(AVIOContext *s); |
532 |
unsigned int avio_rl24(AVIOContext *s); |
533 |
unsigned int avio_rl32(AVIOContext *s); |
534 |
uint64_t avio_rl64(AVIOContext *s); |
535 |
|
536 |
/**
|
537 |
* Read a string from pb into buf. The reading will terminate when either
|
538 |
* a NULL character was encountered, maxlen bytes have been read, or nothing
|
539 |
* more can be read from pb. The result is guaranteed to be NULL-terminated, it
|
540 |
* will be truncated if buf is too small.
|
541 |
* Note that the string is not interpreted or validated in any way, it
|
542 |
* might get truncated in the middle of a sequence for multi-byte encodings.
|
543 |
*
|
544 |
* @return number of bytes read (is always <= maxlen).
|
545 |
* If reading ends on EOF or error, the return value will be one more than
|
546 |
* bytes actually read.
|
547 |
*/
|
548 |
int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen); |
549 |
|
550 |
/**
|
551 |
* Read a UTF-16 string from pb and convert it to UTF-8.
|
552 |
* The reading will terminate when either a null or invalid character was
|
553 |
* encountered or maxlen bytes have been read.
|
554 |
* @return number of bytes read (is always <= maxlen)
|
555 |
*/
|
556 |
int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen); |
557 |
int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen); |
558 |
|
559 |
#if FF_API_OLD_AVIO
|
560 |
/**
|
561 |
* @deprecated use avio_get_str instead
|
562 |
*/
|
563 |
attribute_deprecated char *get_strz(AVIOContext *s, char *buf, int maxlen); |
564 |
#endif
|
565 |
unsigned int avio_rb16(AVIOContext *s); |
566 |
unsigned int avio_rb24(AVIOContext *s); |
567 |
unsigned int avio_rb32(AVIOContext *s); |
568 |
uint64_t avio_rb64(AVIOContext *s); |
569 |
|
570 |
#if FF_API_OLD_AVIO
|
571 |
/**
|
572 |
* @deprecated Use AVIOContext.seekable field directly.
|
573 |
*/
|
574 |
attribute_deprecated static inline int url_is_streamed(AVIOContext *s) |
575 |
{ |
576 |
return !s->seekable;
|
577 |
} |
578 |
#endif
|
579 |
|
580 |
#if FF_API_URL_RESETBUF
|
581 |
/** Reset the buffer for reading or writing.
|
582 |
* @note Will drop any data currently in the buffer without transmitting it.
|
583 |
* @param flags URL_RDONLY to set up the buffer for reading, or URL_WRONLY
|
584 |
* to set up the buffer for writing. */
|
585 |
int url_resetbuf(AVIOContext *s, int flags); |
586 |
#endif
|
587 |
|
588 |
/**
|
589 |
* Create and initialize a AVIOContext for accessing the
|
590 |
* resource indicated by url.
|
591 |
* @note When the resource indicated by url has been opened in
|
592 |
* read+write mode, the AVIOContext can be used only for writing.
|
593 |
*
|
594 |
* @param s Used to return the pointer to the created AVIOContext.
|
595 |
* In case of failure the pointed to value is set to NULL.
|
596 |
* @param flags flags which control how the resource indicated by url
|
597 |
* is to be opened
|
598 |
* @return 0 in case of success, a negative value corresponding to an
|
599 |
* AVERROR code in case of failure
|
600 |
*/
|
601 |
int avio_open(AVIOContext **s, const char *url, int flags); |
602 |
|
603 |
int avio_close(AVIOContext *s);
|
604 |
|
605 |
#if FF_API_OLD_AVIO
|
606 |
attribute_deprecated URLContext *url_fileno(AVIOContext *s); |
607 |
|
608 |
/**
|
609 |
* @deprecated use AVIOContext.max_packet_size directly.
|
610 |
*/
|
611 |
attribute_deprecated int url_fget_max_packet_size(AVIOContext *s);
|
612 |
|
613 |
attribute_deprecated int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags); |
614 |
|
615 |
/** return the written or read size */
|
616 |
attribute_deprecated int url_close_buf(AVIOContext *s);
|
617 |
#endif
|
618 |
|
619 |
/**
|
620 |
* Open a write only memory stream.
|
621 |
*
|
622 |
* @param s new IO context
|
623 |
* @return zero if no error.
|
624 |
*/
|
625 |
int avio_open_dyn_buf(AVIOContext **s);
|
626 |
|
627 |
/**
|
628 |
* Return the written size and a pointer to the buffer. The buffer
|
629 |
* must be freed with av_free().
|
630 |
* Padding of FF_INPUT_BUFFER_PADDING_SIZE is added to the buffer.
|
631 |
*
|
632 |
* @param s IO context
|
633 |
* @param pbuffer pointer to a byte buffer
|
634 |
* @return the length of the byte buffer
|
635 |
*/
|
636 |
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
|
637 |
|
638 |
#if FF_API_UDP_GET_FILE
|
639 |
int udp_get_file_handle(URLContext *h);
|
640 |
#endif
|
641 |
|
642 |
#endif /* AVFORMAT_AVIO_H */ |