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