OSDN Git Service

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