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