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 module ffmpeg.libavformat.avio;
21 import std.stdint;
22 import std.stdio;
23 import ffmpeg.libavutil.avutil;
24 import ffmpeg.libavformat.avformat_version;
25 import ffmpeg.libavformat.url;
26 
27 @nogc nothrow extern(C):
28 /**
29  * @file
30  * @ingroup lavf_io
31  * Buffered I/O operations
32  */
33 
34 const int AVIO_SEEKABLE_NORMAL = 0x0001; /**< Seeking works like for a local file */
35 
36 /**
37  * Callback for checking whether to abort blocking functions.
38  * AVERROR_EXIT is returned in this case by the interrupted
39  * function. During blocking operations, callback is called with
40  * opaque as parameter. If the callback returns 1, the
41  * blocking operation will be aborted.
42  *
43  * No members can be added to this struct without a major bump, if
44  * new elements have been added after this struct in AVFormatContext
45  * or AVIOContext.
46  */
47 struct AVIOInterruptCB {
48     int function (void*) callback;
49     void *opaque;
50 }
51 
52 /**
53  * Directory entry types.
54  */
55 enum AVIODirEntryType {
56     AVIO_ENTRY_UNKNOWN,
57     AVIO_ENTRY_BLOCK_DEVICE,
58     AVIO_ENTRY_CHARACTER_DEVICE,
59     AVIO_ENTRY_DIRECTORY,
60     AVIO_ENTRY_NAMED_PIPE,
61     AVIO_ENTRY_SYMBOLIC_LINK,
62     AVIO_ENTRY_SOCKET,
63     AVIO_ENTRY_FILE,
64     AVIO_ENTRY_SERVER,
65     AVIO_ENTRY_SHARE,
66     AVIO_ENTRY_WORKGROUP
67 }
68 
69 /**
70  * Describes single entry of the directory.
71  *
72  * Only name and type fields are guaranteed be set.
73  * Rest of fields are protocol or/and platform dependent and might be unknown.
74  */
75 struct AVIODirEntry {
76     char *name;                           /**< Filename */
77     int type;                             /**< Type of the entry */
78     int utf8;                             /**< Set to 1 when name is encoded with UTF-8, 0 otherwise.
79                                                Name can be encoded with UTF-8 even though 0 is set. */
80     int64_t size;                         /**< File size in bytes, -1 if unknown. */
81     int64_t modification_timestamp;       /**< Time of last modification in microseconds since unix
82                                                epoch, -1 if unknown. */
83     int64_t access_timestamp;             /**< Time of last access in microseconds since unix epoch,
84                                                -1 if unknown. */
85     int64_t status_change_timestamp;      /**< Time of last status change in microseconds since unix
86                                                epoch, -1 if unknown. */
87     int64_t user_id;                      /**< User ID of owner, -1 if unknown. */
88     int64_t group_id;                     /**< Group ID of owner, -1 if unknown. */
89     int64_t filemode;                     /**< Unix file mode, -1 if unknown. */
90 }
91 
92 struct AVIODirContext {
93     URLContext *url_context;
94 }
95 
96 /**
97  * Bytestream IO Context.
98  * New fields can be added to the end with minor version bumps.
99  * Removal, reordering and changes to existing fields require a major
100  * version bump.
101  * sizeof(AVIOContext) must not be used outside libav*.
102  *
103  * @note None of the function pointers in AVIOContext should be called
104  *       directly, they should only be set by the client application
105  *       when implementing custom I/O. Normally these are set to the
106  *       function pointers specified in avio_alloc_context()
107  */
108 struct AVIOContext {
109     /**
110      * A class for private options.
111      *
112      * If this AVIOContext is created by avio_open2(), av_class is set and
113      * passes the options down to protocols.
114      *
115      * If this AVIOContext is manually allocated, then av_class may be set by
116      * the caller.
117      *
118      * warning -- this field can be NULL, be sure to not pass this AVIOContext
119      * to any av_opt_* functions in that case.
120      */
121     const AVClass *av_class;
122 
123     /*
124      * The following shows the relationship between buffer, buf_ptr, buf_end, buf_size,
125      * and pos, when reading and when writing (since AVIOContext is used for both):
126      *
127      **********************************************************************************
128      *                                   READING
129      **********************************************************************************
130      *
131      *                            |              buffer_size              |
132      *                            |---------------------------------------|
133      *                            |                                       |
134      *
135      *                         buffer          buf_ptr       buf_end
136      *                            +---------------+-----------------------+
137      *                            |/ / / / / / / /|/ / / / / / /|         |
138      *  read buffer:              |/ / consumed / | to be read /|         |
139      *                            |/ / / / / / / /|/ / / / / / /|         |
140      *                            +---------------+-----------------------+
141      *
142      *                                                         pos
143      *              +-------------------------------------------+-----------------+
144      *  input file: |                                           |                 |
145      *              +-------------------------------------------+-----------------+
146      *
147      *
148      **********************************************************************************
149      *                                   WRITING
150      **********************************************************************************
151      *
152      *                                          |          buffer_size          |
153      *                                          |-------------------------------|
154      *                                          |                               |
155      *
156      *                                       buffer              buf_ptr     buf_end
157      *                                          +-------------------+-----------+
158      *                                          |/ / / / / / / / / /|           |
159      *  write buffer:                           | / to be flushed / |           |
160      *                                          |/ / / / / / / / / /|           |
161      *                                          +-------------------+-----------+
162      *
163      *                                         pos
164      *               +--------------------------+-----------------------------------+
165      *  output file: |                          |                                   |
166      *               +--------------------------+-----------------------------------+
167      *
168      */
169     ubyte *buffer;  /**< Start of the buffer. */
170     int buffer_size;        /**< Maximum buffer size */
171     ubyte *buf_ptr; /**< Current position in the buffer */
172     ubyte *buf_end; /**< End of the data, may be less than
173                                  buffer+buffer_size if the read function returned
174                                  less data than requested, e.g. for streams where
175                                  no more data has been received yet. */
176     void *opaque;           /**< A private pointer, passed to the read/write/seek/...
177                                  functions. */
178     int function(void *opaque, uint8_t *buf, int buf_size) read_packet;
179     int function(void *opaque, uint8_t *buf, int buf_size) write_packet;
180     int64_t function(void *opaque, int64_t offset, int whence) seek;
181     int64_t pos;            /**< position in the file of the current buffer */
182     int must_flush;         /**< true if the next seek should flush */
183     int eof_reached;        /**< true if eof reached */
184     int write_flag;         /**< true if open for writing */
185     int max_packet_size;
186     uint  checksum;
187     ubyte *checksum_ptr;
188     uint function(uint checksum, const uint8_t *buf, uint size) update_checksum;
189     int error;              /**< contains the error code or 0 if no error happened */
190     /**
191      * Pause or resume playback for network streaming protocols - e.g. MMS.
192      */
193     int function(void *opaque, int pause) read_pause;
194     /**
195      * Seek to a given timestamp in stream with the specified stream_index.
196      * Needed for some network streaming protocols which don't support seeking
197      * to byte position.
198      */
199     int64_t function(void *opaque, int stream_index, 
200                          int64_t timestamp, int flags) read_seek;
201     /**
202      * A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
203      */
204     int seekable;
205 
206     /**
207      * max filesize, used to limit allocations
208      * This field is internal to libavformat and access from outside is not allowed.
209      */
210     int64_t maxsize;
211 
212     /**
213      * avio_read and avio_write should if possible be satisfied directly
214      * instead of going through a buffer, and avio_seek will always
215      * call the underlying seek function directly.
216      */
217     int direct;
218 
219     /**
220      * Bytes read statistic
221      * This field is internal to libavformat and access from outside is not allowed.
222      */
223     int64_t bytes_read;
224 
225     /**
226      * seek statistic
227      * This field is internal to libavformat and access from outside is not allowed.
228      */
229     int seek_count;
230 
231     /**
232      * writeout statistic
233      * This field is internal to libavformat and access from outside is not allowed.
234      */
235     int writeout_count;
236 
237     /**
238      * Original buffer size
239      * used internally after probing and ensure seekback to reset the buffer size
240      * This field is internal to libavformat and access from outside is not allowed.
241      */
242     int orig_buffer_size;
243 
244     /**
245      * Threshold to favor readahead over seek.
246      * This is current internal only, do not use from outside.
247      */
248     int short_seek_threshold;
249 
250     /**
251      * ',' separated list of allowed protocols.
252      */
253     const char *protocol_whitelist;
254 }
255 
256 /* unbuffered I/O */
257 
258 /**
259  * Return the name of the protocol that will handle the passed URL.
260  *
261  * NULL is returned if no protocol could be found for the given URL.
262  *
263  * @return Name of the protocol or NULL.
264  */
265 char *avio_find_protocol_name(const char *url);
266 
267 /**
268  * Return AVIO_FLAG_* access flags corresponding to the access permissions
269  * of the resource in url, or a negative value corresponding to an
270  * AVERROR code in case of failure. The returned access flags are
271  * masked by the value in flags.
272  *
273  * @note This function is intrinsically unsafe, in the sense that the
274  * checked resource may change its existence or permission status from
275  * one call to another. Thus you should not trust the returned value,
276  * unless you are sure that no other processes are accessing the
277  * checked resource.
278  */
279 int avio_check(const char *url, int flags);
280 
281 /**
282  * Move or rename a resource.
283  *
284  * @note url_src and url_dst should share the same protocol and authority.
285  *
286  * @param url_src url to resource to be moved
287  * @param url_dst new url to resource if the operation succeeded
288  * @return >=0 on success or negative on error.
289  */
290 int avpriv_io_move(const char *url_src, const char *url_dst);
291 
292 /**
293  * Delete a resource.
294  *
295  * @param url resource to be deleted.
296  * @return >=0 on success or negative on error.
297  */
298 int avpriv_io_delete(const char *url);
299 
300 /**
301  * Open directory for reading.
302  *
303  * @param s       directory read context. Pointer to a NULL pointer must be passed.
304  * @param url     directory to be listed.
305  * @param options A dictionary filled with protocol-private options. On return
306  *                this parameter will be destroyed and replaced with a dictionary
307  *                containing options that were not found. May be NULL.
308  * @return >=0 on success or negative on error.
309  */
310 int avio_open_dir(AVIODirContext **s, const char *url, AVDictionary **options);
311 
312 /**
313  * Get next directory entry.
314  *
315  * Returned entry must be freed with avio_free_directory_entry(). In particular
316  * it may outlive AVIODirContext.
317  *
318  * @param s         directory read context.
319  * @param[out] next next entry or NULL when no more entries.
320  * @return >=0 on success or negative on error. End of list is not considered an
321  *             error.
322  */
323 int avio_read_dir(AVIODirContext *s, AVIODirEntry **next);
324 
325 /**
326  * Close directory.
327  *
328  * @note Entries created using avio_read_dir() are not deleted and must be
329  * freeded with avio_free_directory_entry().
330  *
331  * @param s         directory read context.
332  * @return >=0 on success or negative on error.
333  */
334 int avio_close_dir(AVIODirContext **s);
335 
336 /**
337  * Free entry allocated by avio_read_dir().
338  *
339  * @param entry entry to be freed.
340  */
341 void avio_free_directory_entry(AVIODirEntry **entry);
342 
343 /**
344  * Allocate and initialize an AVIOContext for buffered I/O. It must be later
345  * freed with av_free().
346  *
347  * @param buffer Memory block for input/output operations via AVIOContext.
348  *        The buffer must be allocated with av_malloc() and friends.
349  *        It may be freed and replaced with a new buffer by libavformat.
350  *        AVIOContext.buffer holds the buffer currently in use,
351  *        which must be later freed with av_free().
352  * @param buffer_size The buffer size is very important for performance.
353  *        For protocols with fixed blocksize it should be set to this blocksize.
354  *        For others a typical size is a cache page, e.g. 4kb.
355  * @param write_flag Set to 1 if the buffer should be writable, 0 otherwise.
356  * @param opaque An opaque pointer to user-specific data.
357  * @param read_packet  A function for refilling the buffer, may be NULL.
358  * @param write_packet A function for writing the buffer contents, may be NULL.
359  *        The function may not change the input buffers content.
360  * @param seek A function for seeking to specified byte position, may be NULL.
361  *
362  * @return Allocated AVIOContext or NULL on failure.
363  */
364 AVIOContext *avio_alloc_context(
365                   ubyte *buffer,
366                   int buffer_size,
367                   int write_flag,
368                   void *opaque,
369                   int function(void *opaque, uint8_t *buf, int buf_size) read_packet,
370                   int function(void *opaque, uint8_t *buf, int buf_size) write_packet,
371                   int64_t function(void *opaque, int64_t offset, int whence) seek);
372 
373 void avio_w8(AVIOContext *s, int b);
374 void avio_write(AVIOContext *s, const ubyte *buf, int size);
375 void avio_wl64(AVIOContext *s, uint64_t val);
376 void avio_wb64(AVIOContext *s, uint64_t val);
377 void avio_wl32(AVIOContext *s, uint val);
378 void avio_wb32(AVIOContext *s, uint val);
379 void avio_wl24(AVIOContext *s, uint val);
380 void avio_wb24(AVIOContext *s, uint val);
381 void avio_wl16(AVIOContext *s, uint val);
382 void avio_wb16(AVIOContext *s, uint val);
383 
384 /**
385  * Write a NULL-terminated string.
386  * @return number of bytes written.
387  */
388 int avio_put_str(AVIOContext *s, const char *str);
389 
390 /**
391  * Convert an UTF-8 string to UTF-16LE and write it.
392  * @return number of bytes written.
393  */
394 int avio_put_str16le(AVIOContext *s, const char *str);
395 
396 /**
397  * Convert an UTF-8 string to UTF-16BE and write it.
398  * @param s the AVIOContext
399  * @param str NULL-terminated UTF-8 string
400  *
401  * @return number of bytes written.
402  */
403 int avio_put_str16be(AVIOContext *s, const char *str);
404 
405 /**
406  * Passing this as the "whence" parameter to a seek function causes it to
407  * return the filesize without seeking anywhere. Supporting this is optional.
408  * If it is not supported then the seek function will return <0.
409  */
410 enum AVSEEK_SIZE = 0x10000;
411 
412 /**
413  * Oring this flag as into the "whence" parameter to a seek function causes it to
414  * seek by any means (like reopening and linear reading) or other normally unreasonable
415  * means that can be extremely slow.
416  * This may be ignored by the seek code.
417  */
418 enum AVSEEK_FORCE = 0x20000;
419 
420 /**
421  * fseek() equivalent for AVIOContext.
422  * @return new position or AVERROR.
423  */
424 int64_t avio_seek(AVIOContext *s, int64_t offset, int whence);
425 
426 /**
427  * Skip given number of bytes forward
428  * @return new position or AVERROR.
429  */
430 int64_t avio_skip(AVIOContext *s, int64_t offset);
431 
432 /**
433  * ftell() equivalent for AVIOContext.
434  * @return position or AVERROR.
435  */
436 static int64_t avio_tell(AVIOContext *s)
437 {
438     return avio_seek(s, 0, SEEK_CUR);
439 }
440 
441 /**
442  * Get the filesize.
443  * @return filesize or AVERROR
444  */
445 int64_t avio_size(AVIOContext *s);
446 
447 /**
448  * feof() equivalent for AVIOContext.
449  * @return non zero if and only if end of file
450  */
451 int avio_feof(AVIOContext *s);
452 static if (FF_API_URL_FEOF) {
453 /**
454  * @deprecated use avio_feof()
455  */
456 deprecated
457 int url_feof(AVIOContext *s);
458 }
459 
460 /** @warning currently size is limited */
461 int avio_printf(AVIOContext *s, const char *fmt, ...);
462 
463 /**
464  * Force flushing of buffered data to the output s.
465  *
466  * Force the buffered data to be immediately written to the output,
467  * without to wait to fill the internal buffer.
468  */
469 void avio_flush(AVIOContext *s);
470 
471 /**
472  * Read size bytes from AVIOContext into buf.
473  * @return number of bytes read or AVERROR
474  */
475 int avio_read(AVIOContext *s, ubyte *buf, int size);
476 
477 /**
478  * @name Functions for reading from AVIOContext
479  * @{
480  *
481  * @note return 0 if EOF, so you cannot use it if EOF handling is
482  *       necessary
483  */
484 int          avio_r8  (AVIOContext *s);
485 uint avio_rl16(AVIOContext *s);
486 uint avio_rl24(AVIOContext *s);
487 uint avio_rl32(AVIOContext *s);
488 uint64_t     avio_rl64(AVIOContext *s);
489 uint avio_rb16(AVIOContext *s);
490 uint avio_rb24(AVIOContext *s);
491 uint avio_rb32(AVIOContext *s);
492 uint64_t     avio_rb64(AVIOContext *s);
493 /**
494  * @}
495  */
496 
497 /**
498  * Read a string from pb into buf. The reading will terminate when either
499  * a NULL character was encountered, maxlen bytes have been read, or nothing
500  * more can be read from pb. The result is guaranteed to be NULL-terminated, it
501  * will be truncated if buf is too small.
502  * Note that the string is not interpreted or validated in any way, it
503  * might get truncated in the middle of a sequence for multi-byte encodings.
504  *
505  * @return number of bytes read (is always <= maxlen).
506  * If reading ends on EOF or error, the return value will be one more than
507  * bytes actually read.
508  */
509 int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen);
510 
511 /**
512  * Read a UTF-16 string from pb and convert it to UTF-8.
513  * The reading will terminate when either a null or invalid character was
514  * encountered or maxlen bytes have been read.
515  * @return number of bytes read (is always <= maxlen)
516  */
517 int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen);
518 int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen);
519 
520 
521 /**
522  * @name URL open modes
523  * The flags argument to avio_open must be one of the following
524  * constants, optionally ORed with other flags.
525  * @{
526  */
527 enum AVIO_FLAG_READ = 1;                                      /**< read-only */
528 enum AVIO_FLAG_WRITE = 2;                                      /**< write-only */
529 enum AVIO_FLAG_READ_WRITE = (AVIO_FLAG_READ|AVIO_FLAG_WRITE);  /**< read-write pseudo flag */
530 /**
531  * @}
532  */
533 
534 /**
535  * Use non-blocking mode.
536  * If this flag is set, operations on the context will return
537  * AVERROR(EAGAIN) if they can not be performed immediately.
538  * If this flag is not set, operations on the context will never return
539  * AVERROR(EAGAIN).
540  * Note that this flag does not affect the opening/connecting of the
541  * context. Connecting a protocol will always block if necessary (e.g. on
542  * network protocols) but never hang (e.g. on busy devices).
543  * Warning: non-blocking protocols is work-in-progress; this flag may be
544  * silently ignored.
545  */
546 enum AVIO_FLAG_NONBLOCK = 8;
547 
548 /**
549  * Use direct mode.
550  * avio_read and avio_write should if possible be satisfied directly
551  * instead of going through a buffer, and avio_seek will always
552  * call the underlying seek function directly.
553  */
554 enum AVIO_FLAG_DIRECT = 0x8000;
555 
556 /**
557  * Create and initialize a AVIOContext for accessing the
558  * resource indicated by url.
559  * @note When the resource indicated by url has been opened in
560  * read+write mode, the AVIOContext can be used only for writing.
561  *
562  * @param s Used to return the pointer to the created AVIOContext.
563  * In case of failure the pointed to value is set to NULL.
564  * @param url resource to access
565  * @param flags flags which control how the resource indicated by url
566  * is to be opened
567  * @return >= 0 in case of success, a negative value corresponding to an
568  * AVERROR code in case of failure
569  */
570 int avio_open(AVIOContext **s, const char *url, int flags);
571 
572 /**
573  * Create and initialize a AVIOContext for accessing the
574  * resource indicated by url.
575  * @note When the resource indicated by url has been opened in
576  * read+write mode, the AVIOContext can be used only for writing.
577  *
578  * @param s Used to return the pointer to the created AVIOContext.
579  * In case of failure the pointed to value is set to NULL.
580  * @param url resource to access
581  * @param flags flags which control how the resource indicated by url
582  * is to be opened
583  * @param int_cb an interrupt callback to be used at the protocols level
584  * @param options  A dictionary filled with protocol-private options. On return
585  * this parameter will be destroyed and replaced with a dict containing options
586  * that were not found. May be NULL.
587  * @return >= 0 in case of success, a negative value corresponding to an
588  * AVERROR code in case of failure
589  */
590 int avio_open2(AVIOContext **s, const char *url, int flags,
591                const AVIOInterruptCB *int_cb, AVDictionary **options);
592 
593 /**
594  * Close the resource accessed by the AVIOContext s and free it.
595  * This function can only be used if s was opened by avio_open().
596  *
597  * The internal buffer is automatically flushed before closing the
598  * resource.
599  *
600  * @return 0 on success, an AVERROR < 0 on error.
601  * @see avio_closep
602  */
603 int avio_close(AVIOContext *s);
604 
605 /**
606  * Close the resource accessed by the AVIOContext *s, free it
607  * and set the pointer pointing to it to NULL.
608  * This function can only be used if s was opened by avio_open().
609  *
610  * The internal buffer is automatically flushed before closing the
611  * resource.
612  *
613  * @return 0 on success, an AVERROR < 0 on error.
614  * @see avio_close
615  */
616 int avio_closep(AVIOContext **s);
617 
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 /**
639  * Iterate through names of available protocols.
640  *
641  * @param opaque A private pointer representing current protocol.
642  *        It must be a pointer to NULL on first iteration and will
643  *        be updated by successive calls to avio_enum_protocols.
644  * @param output If set to 1, iterate over output protocols,
645  *               otherwise over input protocols.
646  *
647  * @return A static string containing the name of current protocol or NULL
648  */
649 char *avio_enum_protocols(void **opaque, int output);
650 
651 /**
652  * Pause and resume playing - only meaningful if using a network streaming
653  * protocol (e.g. MMS).
654  *
655  * @param h     IO context from which to call the read_pause function pointer
656  * @param pause 1 for pause, 0 for resume
657  */
658 int     avio_pause(AVIOContext *h, int pause);
659 
660 /**
661  * Seek to a given timestamp relative to some component stream.
662  * Only meaningful if using a network streaming protocol (e.g. MMS.).
663  *
664  * @param h IO context from which to call the seek function pointers
665  * @param stream_index The stream index that the timestamp is relative to.
666  *        If stream_index is (-1) the timestamp should be in AV_TIME_BASE
667  *        units from the beginning of the presentation.
668  *        If a stream_index >= 0 is used and the protocol does not support
669  *        seeking based on component streams, the call will fail.
670  * @param timestamp timestamp in AVStream.time_base units
671  *        or if there is no stream specified then in AV_TIME_BASE units.
672  * @param flags Optional combination of AVSEEK_FLAG_BACKWARD, AVSEEK_FLAG_BYTE
673  *        and AVSEEK_FLAG_ANY. The protocol may silently ignore
674  *        AVSEEK_FLAG_BACKWARD and AVSEEK_FLAG_ANY, but AVSEEK_FLAG_BYTE will
675  *        fail if used and not supported.
676  * @return >= 0 on success
677  * @see AVInputFormat::read_seek
678  */
679 int64_t avio_seek_time(AVIOContext *h, int stream_index,
680                        int64_t timestamp, int flags);
681 
682 /* Avoid a warning. The header can not be included because it breaks c++. */
683 struct AVBPrint;
684 
685 /**
686  * Read contents of h into print buffer, up to max_size bytes, or up to EOF.
687  *
688  * @return 0 for success (max_size bytes read or EOF reached), negative error
689  * code otherwise
690  */
691 int avio_read_to_bprint(AVIOContext *h, AVBPrint *pb, size_t max_size);
692 
693 /**
694  * Accept and allocate a client context on a server context.
695  * @param  s the server context
696  * @param  c the client context, must be unallocated
697  * @return   >= 0 on success or a negative value corresponding
698  *           to an AVERROR on failure
699  */
700 int avio_accept(AVIOContext *s, AVIOContext **c);
701 
702 /**
703  * Perform one step of the protocol handshake to accept a new client.
704  * This function must be called on a client returned by avio_accept() before
705  * using it as a read/write context.
706  * It is separate from avio_accept() because it may block.
707  * A step of the handshake is defined by places where the application may
708  * decide to change the proceedings.
709  * For example, on a protocol with a request header and a reply header, each
710  * one can constitute a step because the application may use the parameters
711  * from the request to change parameters in the reply; or each individual
712  * chunk of the request can constitute a step.
713  * If the handshake is already finished, avio_handshake() does nothing and
714  * returns 0 immediately.
715  *
716  * @param  c the client context to perform the handshake on
717  * @return   0   on a complete and successful handshake
718  *           > 0 if the handshake progressed, but is not complete
719  *           < 0 for an AVERROR code
720  */
721 int avio_handshake(AVIOContext *c);