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