avio: make url_filesize() internal.
[libav.git] / libavformat / avio.h
CommitLineData
04d7f601 1/*
04d7f601
DB
2 * copyright (c) 2001 Fabrice Bellard
3 *
2912e87a 4 * This file is part of Libav.
b78e7197 5 *
2912e87a 6 * Libav is free software; you can redistribute it and/or
04d7f601
DB
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
b78e7197 9 * version 2.1 of the License, or (at your option) any later version.
04d7f601 10 *
2912e87a 11 * Libav is distributed in the hope that it will be useful,
04d7f601
DB
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
2912e87a 17 * License along with Libav; if not, write to the Free Software
04d7f601
DB
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
98790382
SS
20#ifndef AVFORMAT_AVIO_H
21#define AVFORMAT_AVIO_H
f031df23 22
aafe9b63 23/**
ba87f080 24 * @file
aafe9b63 25 * unbuffered I/O operations
3f4c2bf9
SS
26 *
27 * @warning This file has to be considered an internal but installed
28 * header, so it should not be directly included in your projects.
aafe9b63
SS
29 */
30
99545457
MR
31#include <stdint.h>
32
30f68128 33#include "libavutil/common.h"
ed8d5766 34#include "libavutil/log.h"
30f68128 35
50196a98
AK
36#include "libavformat/version.h"
37
de6d9b64
FB
38/* unbuffered I/O */
39
1308f273
MN
40/**
41 * URL Context.
42 * New fields can be added to the end with minor version bumps.
8bfb108b 43 * Removal, reordering and changes to existing fields require a major
1308f273 44 * version bump.
8bfb108b 45 * sizeof(URLContext) must not be used outside libav*.
1308f273 46 */
597b4b3f 47typedef struct URLContext {
404eba44 48#if FF_API_URL_CLASS
5acef35f
BA
49 const AVClass *av_class; ///< information for av_log(). Set by url_open().
50#endif
de6d9b64 51 struct URLProtocol *prot;
115329f1 52 int flags;
c3316802
PI
53 int is_streamed; /**< true if streamed (no seek possible), default = false */
54 int max_packet_size; /**< if non zero, the stream is packetized with this max packet size */
de6d9b64 55 void *priv_data;
725b3da9 56 char *filename; /**< specified URL */
ffbb289a 57 int is_connected;
597b4b3f 58} URLContext;
de6d9b64 59
e2307053 60#if FF_API_OLD_AVIO
de6d9b64
FB
61typedef struct URLPollEntry {
62 URLContext *handle;
63 int events;
64 int revents;
65} URLPollEntry;
e2307053 66#endif
de6d9b64 67
fe174fc8
NG
68/**
69 * @defgroup open_modes URL open modes
70 * The flags argument to url_open and cosins must be one of the following
71 * constants, optionally ORed with other flags.
72 * @{
73 */
74#define URL_RDONLY 0 /**< read-only */
75#define URL_WRONLY 1 /**< write-only */
76#define URL_RDWR 2 /**< read-write */
77/**
78 * @}
79 */
80
81/**
82 * Use non-blocking mode.
83 * If this flag is set, operations on the context will return
84 * AVERROR(EAGAIN) if they can not be performed immediately.
85 * If this flag is not set, operations on the context will never return
86 * AVERROR(EAGAIN).
87 * Note that this flag does not affect the opening/connecting of the
88 * context. Connecting a protocol will always block if necessary (e.g. on
89 * network protocols) but never hang (e.g. on busy devices).
90 * Warning: non-blocking protocols is work-in-progress; this flag may be
91 * silently ignored.
92 */
93#define URL_FLAG_NONBLOCK 4
f031df23 94
019ac05a
FB
95typedef int URLInterruptCB(void);
96
333e8943 97#if FF_API_OLD_AVIO
333146dd 98/**
333e8943
AK
99 * @defgroup old_url_funcs Old url_* functions
100 * @deprecated use the buffered API based on AVIOContext instead
101 * @{
333146dd 102 */
333e8943
AK
103attribute_deprecated int url_open_protocol (URLContext **puc, struct URLProtocol *up,
104 const char *url, int flags);
5652bb94 105attribute_deprecated int url_alloc(URLContext **h, const char *url, int flags);
62eaaeac 106attribute_deprecated int url_connect(URLContext *h);
0589da0a 107attribute_deprecated int url_open(URLContext **h, const char *url, int flags);
bc371aca 108attribute_deprecated int url_read(URLContext *h, unsigned char *buf, int size);
dce37564 109attribute_deprecated int url_read_complete(URLContext *h, unsigned char *buf, int size);
925e908b 110attribute_deprecated int url_write(URLContext *h, const unsigned char *buf, int size);
58a48c65 111attribute_deprecated int64_t url_seek(URLContext *h, int64_t pos, int whence);
e52a9145 112attribute_deprecated int url_close(URLContext *h);
32a97d46 113attribute_deprecated int64_t url_filesize(URLContext *h);
333e8943 114#endif
333146dd 115
b0634fd1 116/**
49bd8e4b 117 * Return a non-zero value if the resource indicated by url
8a36b59b
SS
118 * exists, 0 otherwise.
119 */
725b3da9 120int url_exist(const char *url);
8a36b59b 121
f3f5eb6e 122/**
f0a80394
RB
123 * Return the file descriptor associated with this URL. For RTP, this
124 * will return only the RTP file descriptor, not the RTCP file descriptor.
f0a80394
RB
125 *
126 * @return the file descriptor associated with this URL, or <0 on error.
127 */
128int url_get_file_handle(URLContext *h);
129
130/**
c306748c 131 * Return the maximum packet size associated to packetized file
8bfb108b 132 * handle. If the file is not packetized (stream like HTTP or file on
c306748c
PI
133 * disk), then 0 is returned.
134 *
135 * @param h file handle
136 * @return maximum packet size in bytes
137 */
f031df23 138int url_get_max_packet_size(URLContext *h);
8bf256bc
SS
139
140/**
141 * Copy the filename of the resource accessed by h to buf.
142 *
143 * @param buf_size size in bytes of buf
144 */
f746a046
FB
145void url_get_filename(URLContext *h, char *buf, int buf_size);
146
c3316802 147/**
8bfb108b 148 * The callback is called in blocking functions to test regulary if
c76374c6 149 * asynchronous interruption is needed. AVERROR_EXIT is returned
c3316802 150 * in this case by the interrupted function. 'NULL' means no interrupt
8bfb108b 151 * callback is given.
c3316802 152 */
019ac05a
FB
153void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
154
e2307053 155#if FF_API_OLD_AVIO
de6d9b64 156/* not implemented */
e2307053
AK
157attribute_deprecated int url_poll(URLPollEntry *poll_table, int n, int timeout);
158#endif
de6d9b64 159
502bdf68
MN
160/**
161 * Pause and resume playing - only meaningful if using a network streaming
162 * protocol (e.g. MMS).
163 * @param pause 1 for pause, 0 for resume
164 */
165int av_url_read_pause(URLContext *h, int pause);
8bfb108b 166
536333a0
BA
167/**
168 * Seek to a given timestamp relative to some component stream.
8bfb108b 169 * Only meaningful if using a network streaming protocol (e.g. MMS.).
536333a0
BA
170 * @param stream_index The stream index that the timestamp is relative to.
171 * If stream_index is (-1) the timestamp should be in AV_TIME_BASE
172 * units from the beginning of the presentation.
173 * If a stream_index >= 0 is used and the protocol does not support
174 * seeking based on component streams, the call will fail with ENOTSUP.
00ef4f58 175 * @param timestamp timestamp in AVStream.time_base units
536333a0
BA
176 * or if there is no stream specified then in AV_TIME_BASE units.
177 * @param flags Optional combination of AVSEEK_FLAG_BACKWARD, AVSEEK_FLAG_BYTE
178 * and AVSEEK_FLAG_ANY. The protocol may silently ignore
179 * AVSEEK_FLAG_BACKWARD and AVSEEK_FLAG_ANY, but AVSEEK_FLAG_BYTE will
180 * fail with ENOTSUP if used and not supported.
181 * @return >= 0 on success
182 * @see AVInputFormat::read_seek
183 */
7f37f568
DB
184int64_t av_url_read_seek(URLContext *h, int stream_index,
185 int64_t timestamp, int flags);
536333a0 186
8f73c060
MS
187#define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */
188
de6d9b64
FB
189typedef struct URLProtocol {
190 const char *name;
725b3da9 191 int (*url_open)(URLContext *h, const char *url, int flags);
de6d9b64 192 int (*url_read)(URLContext *h, unsigned char *buf, int size);
27241cbf 193 int (*url_write)(URLContext *h, const unsigned char *buf, int size);
bc5c918e 194 int64_t (*url_seek)(URLContext *h, int64_t pos, int whence);
de6d9b64 195 int (*url_close)(URLContext *h);
de6d9b64 196 struct URLProtocol *next;
502bdf68 197 int (*url_read_pause)(URLContext *h, int pause);
7f37f568
DB
198 int64_t (*url_read_seek)(URLContext *h, int stream_index,
199 int64_t timestamp, int flags);
f0a80394 200 int (*url_get_file_handle)(URLContext *h);
735cf6b2
MS
201 int priv_data_size;
202 const AVClass *priv_data_class;
f3bea991 203 int flags;
de6d9b64
FB
204} URLProtocol;
205
838b27b4 206#if FF_API_REGISTER_PROTOCOL
de6d9b64 207extern URLProtocol *first_protocol;
d1037c12
SS
208#endif
209
019ac05a 210extern URLInterruptCB *url_interrupt_cb;
de6d9b64 211
9075d1e0
SS
212/**
213 * If protocol is NULL, returns the first registered protocol,
c1b02101 214 * if protocol is non-NULL, returns the next registered protocol after protocol,
9075d1e0
SS
215 * or NULL if protocol is the last one.
216 */
84be6e72
MN
217URLProtocol *av_protocol_next(URLProtocol *p);
218
838b27b4 219#if FF_API_REGISTER_PROTOCOL
65c40e4e
SS
220/**
221 * @deprecated Use av_register_protocol() instead.
222 */
223attribute_deprecated int register_protocol(URLProtocol *protocol);
9b07a2dc
MS
224
225/**
226 * @deprecated Use av_register_protocol2() instead.
227 */
228attribute_deprecated int av_register_protocol(URLProtocol *protocol);
65c40e4e
SS
229#endif
230
d19a046e 231/**
49bd8e4b 232 * Register the URLProtocol protocol.
9b07a2dc
MS
233 *
234 * @param size the size of the URLProtocol struct referenced
d19a046e 235 */
9b07a2dc 236int av_register_protocol2(URLProtocol *protocol, int size);
de6d9b64 237
8978feda
AK
238#define AVIO_SEEKABLE_NORMAL 0x0001 /**< Seeking works like for a local file */
239
1308f273 240/**
333e8943
AK
241 * @}
242 */
243
244/**
1308f273
MN
245 * Bytestream IO Context.
246 * New fields can be added to the end with minor version bumps.
8bfb108b 247 * Removal, reordering and changes to existing fields require a major
1308f273 248 * version bump.
ae628ec1 249 * sizeof(AVIOContext) must not be used outside libav*.
1308f273 250 */
de6d9b64
FB
251typedef struct {
252 unsigned char *buffer;
253 int buffer_size;
254 unsigned char *buf_ptr, *buf_end;
255 void *opaque;
0c1a9eda 256 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
576ae256 257 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
bc5c918e
DB
258 int64_t (*seek)(void *opaque, int64_t offset, int whence);
259 int64_t pos; /**< position in the file of the current buffer */
c3316802
PI
260 int must_flush; /**< true if the next seek should flush */
261 int eof_reached; /**< true if eof reached */
262 int write_flag; /**< true if open for writing */
8978feda
AK
263#if FF_API_OLD_AVIO
264 attribute_deprecated int is_streamed;
265#endif
f031df23 266 int max_packet_size;
ee9f36a8
MN
267 unsigned long checksum;
268 unsigned char *checksum_ptr;
269 unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
576ae256 270 int error; ///< contains the error code or 0 if no error happened
502bdf68 271 int (*read_pause)(void *opaque, int pause);
7f37f568
DB
272 int64_t (*read_seek)(void *opaque, int stream_index,
273 int64_t timestamp, int flags);
8978feda
AK
274 /**
275 * A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
276 */
277 int seekable;
ae628ec1 278} AVIOContext;
de6d9b64 279
ae628ec1
AK
280#if FF_API_OLD_AVIO
281typedef attribute_deprecated AVIOContext ByteIOContext;
ae628ec1 282
e731b8d8 283attribute_deprecated int init_put_byte(AVIOContext *s,
de6d9b64
FB
284 unsigned char *buffer,
285 int buffer_size,
286 int write_flag,
287 void *opaque,
1e0f3468
RD
288 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
289 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
bc5c918e 290 int64_t (*seek)(void *opaque, int64_t offset, int whence));
8d9ac969
AK
291attribute_deprecated AVIOContext *av_alloc_put_byte(
292 unsigned char *buffer,
293 int buffer_size,
294 int write_flag,
295 void *opaque,
296 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
297 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
298 int64_t (*seek)(void *opaque, int64_t offset, int whence));
b7effd4e
AK
299
300/**
301 * @defgroup old_avio_funcs Old put_/get_*() functions
302 * @deprecated use the avio_ -prefixed functions instead.
303 * @{
304 */
305attribute_deprecated int get_buffer(AVIOContext *s, unsigned char *buf, int size);
b3db9cee 306attribute_deprecated int get_partial_buffer(AVIOContext *s, unsigned char *buf, int size);
b7effd4e
AK
307attribute_deprecated int get_byte(AVIOContext *s);
308attribute_deprecated unsigned int get_le16(AVIOContext *s);
309attribute_deprecated unsigned int get_le24(AVIOContext *s);
310attribute_deprecated unsigned int get_le32(AVIOContext *s);
311attribute_deprecated uint64_t get_le64(AVIOContext *s);
312attribute_deprecated unsigned int get_be16(AVIOContext *s);
313attribute_deprecated unsigned int get_be24(AVIOContext *s);
314attribute_deprecated unsigned int get_be32(AVIOContext *s);
315attribute_deprecated uint64_t get_be64(AVIOContext *s);
77eb5504
AK
316
317attribute_deprecated void put_byte(AVIOContext *s, int b);
0ac8e2bf 318attribute_deprecated void put_nbyte(AVIOContext *s, int b, int count);
77eb5504
AK
319attribute_deprecated void put_buffer(AVIOContext *s, const unsigned char *buf, int size);
320attribute_deprecated void put_le64(AVIOContext *s, uint64_t val);
321attribute_deprecated void put_be64(AVIOContext *s, uint64_t val);
322attribute_deprecated void put_le32(AVIOContext *s, unsigned int val);
323attribute_deprecated void put_be32(AVIOContext *s, unsigned int val);
324attribute_deprecated void put_le24(AVIOContext *s, unsigned int val);
325attribute_deprecated void put_be24(AVIOContext *s, unsigned int val);
326attribute_deprecated void put_le16(AVIOContext *s, unsigned int val);
327attribute_deprecated void put_be16(AVIOContext *s, unsigned int val);
61840b43 328attribute_deprecated void put_tag(AVIOContext *s, const char *tag);
b7effd4e
AK
329/**
330 * @}
331 */
22a3212e 332
933e90a6 333attribute_deprecated int av_url_read_fpause(AVIOContext *h, int pause);
491653ed 334attribute_deprecated int64_t av_url_read_fseek (AVIOContext *h, int stream_index,
933e90a6 335 int64_t timestamp, int flags);
22a3212e
AK
336
337/**
338 * @defgroup old_url_f_funcs Old url_f* functions
339 * @deprecated use the avio_ -prefixed functions instead.
340 * @{
341 */
342attribute_deprecated int url_fopen( AVIOContext **s, const char *url, int flags);
343attribute_deprecated int url_fclose(AVIOContext *s);
6b4aa5da 344attribute_deprecated int64_t url_fseek(AVIOContext *s, int64_t offset, int whence);
0300db8a 345attribute_deprecated int url_fskip(AVIOContext *s, int64_t offset);
a2704c97 346attribute_deprecated int64_t url_ftell(AVIOContext *s);
76aa876e 347attribute_deprecated int64_t url_fsize(AVIOContext *s);
e5197539
AK
348#define URL_EOF (-1)
349attribute_deprecated int url_fgetc(AVIOContext *s);
59f65d95 350attribute_deprecated int url_setbufsize(AVIOContext *s, int buf_size);
d9d86e00
AK
351#ifdef __GNUC__
352attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
353#else
354attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...);
355#endif
b7f2fdde 356attribute_deprecated void put_flush_packet(AVIOContext *s);
b92c5452 357attribute_deprecated int url_open_dyn_buf(AVIOContext **s);
403ee835 358attribute_deprecated int url_open_dyn_packet_buf(AVIOContext **s, int max_packet_size);
6dc7d80d 359attribute_deprecated int url_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
724f6a0f 360attribute_deprecated int url_fdopen(AVIOContext **s, URLContext *h);
22a3212e
AK
361/**
362 * @}
363 */
66e5b1df
AK
364
365/**
366 * @deprecated use AVIOContext.eof_reached
367 */
368attribute_deprecated int url_feof(AVIOContext *s);
3e68b3ba 369attribute_deprecated int url_ferror(AVIOContext *s);
4ec153bb
AK
370
371attribute_deprecated int udp_set_remote_url(URLContext *h, const char *uri);
372attribute_deprecated int udp_get_local_port(URLContext *h);
4c4427a7
AK
373
374attribute_deprecated void init_checksum(AVIOContext *s,
375 unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
376 unsigned long checksum);
b64030f2 377attribute_deprecated unsigned long get_checksum(AVIOContext *s);
e731b8d8 378#endif
8d9ac969 379
3c96c648
AK
380/**
381 * Allocate and initialize an AVIOContext for buffered I/O. It must be later
382 * freed with av_free().
383 *
384 * @param buffer Memory block for input/output operations via AVIOContext.
385 * @param buffer_size The buffer size is very important for performance.
386 * For protocols with fixed blocksize it should be set to this blocksize.
387 * For others a typical size is a cache page, e.g. 4kb.
388 * @param write_flag Set to 1 if the buffer should be writable, 0 otherwise.
389 * @param opaque An opaque pointer to user-specific data.
390 * @param read_packet A function for refilling the buffer, may be NULL.
391 * @param write_packet A function for writing the buffer contents, may be NULL.
392 * @param seek A function for seeking to specified byte position, may be NULL.
393 *
394 * @return Allocated AVIOContext or NULL on failure.
395 */
8d9ac969 396AVIOContext *avio_alloc_context(
1e0f3468
RD
397 unsigned char *buffer,
398 int buffer_size,
399 int write_flag,
400 void *opaque,
0c1a9eda 401 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
576ae256 402 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
bc5c918e 403 int64_t (*seek)(void *opaque, int64_t offset, int whence));
de6d9b64 404
77eb5504 405void avio_w8(AVIOContext *s, int b);
77eb5504
AK
406void avio_write(AVIOContext *s, const unsigned char *buf, int size);
407void avio_wl64(AVIOContext *s, uint64_t val);
408void avio_wb64(AVIOContext *s, uint64_t val);
409void avio_wl32(AVIOContext *s, unsigned int val);
410void avio_wb32(AVIOContext *s, unsigned int val);
411void avio_wl24(AVIOContext *s, unsigned int val);
412void avio_wb24(AVIOContext *s, unsigned int val);
413void avio_wl16(AVIOContext *s, unsigned int val);
414void avio_wb16(AVIOContext *s, unsigned int val);
de6d9b64 415
4efd5cf3 416#if FF_API_OLD_AVIO
ae628ec1 417attribute_deprecated void put_strz(AVIOContext *s, const char *buf);
4efd5cf3
AK
418#endif
419
420/**
421 * Write a NULL-terminated string.
422 * @return number of bytes written.
423 */
ae628ec1 424int avio_put_str(AVIOContext *s, const char *str);
75bdb984 425
67e21020 426/**
dccbd97d
AK
427 * Convert an UTF-8 string to UTF-16LE and write it.
428 * @return number of bytes written.
429 */
ae628ec1 430int avio_put_str16le(AVIOContext *s, const char *str);
dccbd97d
AK
431
432/**
230a4686
AK
433 * Passing this as the "whence" parameter to a seek function causes it to
434 * return the filesize without seeking anywhere. Supporting this is optional.
435 * If it is not supported then the seek function will return <0.
436 */
437#define AVSEEK_SIZE 0x10000
438
439/**
440 * Oring this flag as into the "whence" parameter to a seek function causes it to
441 * seek by any means (like reopening and linear reading) or other normally unreasonble
442 * means that can be extreemly slow.
443 * This may be ignored by the seek code.
444 */
445#define AVSEEK_FORCE 0x20000
446
447/**
ae628ec1 448 * fseek() equivalent for AVIOContext.
67e21020
MN
449 * @return new position or AVERROR.
450 */
6b4aa5da 451int64_t avio_seek(AVIOContext *s, int64_t offset, int whence);
67e21020
MN
452
453/**
2af07d36
PR
454 * Skip given number of bytes forward
455 * @return new position or AVERROR.
456 */
af020732
AK
457static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
458{
459 return avio_seek(s, offset, SEEK_CUR);
460}
2af07d36
PR
461
462/**
ae628ec1 463 * ftell() equivalent for AVIOContext.
67e21020
MN
464 * @return position or AVERROR.
465 */
af020732
AK
466static av_always_inline int64_t avio_tell(AVIOContext *s)
467{
468 return avio_seek(s, 0, SEEK_CUR);
469}
67e21020
MN
470
471/**
49bd8e4b 472 * Get the filesize.
67e21020
MN
473 * @return filesize or AVERROR
474 */
76aa876e 475int64_t avio_size(AVIOContext *s);
67e21020 476
c3316802 477/** @warning currently size is limited */
572f992e 478#ifdef __GNUC__
d9d86e00 479int avio_printf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
572f992e 480#else
d9d86e00 481int avio_printf(AVIOContext *s, const char *fmt, ...);
572f992e 482#endif
a8c5ab27 483
655e45e7 484#if FF_API_OLD_AVIO
c3316802 485/** @note unlike fgets, the EOL character is not returned and a whole
7f37f568 486 line is parsed. return NULL if first char read was EOF */
655e45e7
AK
487attribute_deprecated char *url_fgets(AVIOContext *s, char *buf, int buf_size);
488#endif
f031df23 489
b7f2fdde 490void avio_flush(AVIOContext *s);
de6d9b64 491
4edfcecc
MN
492
493/**
ae628ec1 494 * Read size bytes from AVIOContext into buf.
32e543f8 495 * @return number of bytes read or AVERROR
4edfcecc 496 */
b7effd4e 497int avio_read(AVIOContext *s, unsigned char *buf, int size);
4edfcecc 498
c3316802 499/** @note return 0 if EOF, so you cannot use it if EOF handling is
7f37f568 500 necessary */
b7effd4e
AK
501int avio_r8 (AVIOContext *s);
502unsigned int avio_rl16(AVIOContext *s);
503unsigned int avio_rl24(AVIOContext *s);
504unsigned int avio_rl32(AVIOContext *s);
505uint64_t avio_rl64(AVIOContext *s);
de6d9b64 506
93b78d12 507/**
41d8555f
RD
508 * Read a string from pb into buf. The reading will terminate when either
509 * a NULL character was encountered, maxlen bytes have been read, or nothing
510 * more can be read from pb. The result is guaranteed to be NULL-terminated, it
511 * will be truncated if buf is too small.
512 * Note that the string is not interpreted or validated in any way, it
513 * might get truncated in the middle of a sequence for multi-byte encodings.
514 *
515 * @return number of bytes read (is always <= maxlen).
516 * If reading ends on EOF or error, the return value will be one more than
517 * bytes actually read.
518 */
519int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen);
520
521/**
93b78d12
AK
522 * Read a UTF-16 string from pb and convert it to UTF-8.
523 * The reading will terminate when either a null or invalid character was
524 * encountered or maxlen bytes have been read.
525 * @return number of bytes read (is always <= maxlen)
526 */
ae628ec1
AK
527int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen);
528int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen);
93b78d12 529
e16ead07
AK
530#if FF_API_OLD_AVIO
531/**
532 * @deprecated use avio_get_str instead
533 */
534attribute_deprecated char *get_strz(AVIOContext *s, char *buf, int maxlen);
535#endif
b7effd4e
AK
536unsigned int avio_rb16(AVIOContext *s);
537unsigned int avio_rb24(AVIOContext *s);
538unsigned int avio_rb32(AVIOContext *s);
539uint64_t avio_rb64(AVIOContext *s);
de6d9b64 540
8978feda
AK
541#if FF_API_OLD_AVIO
542/**
543 * @deprecated Use AVIOContext.seekable field directly.
544 */
545attribute_deprecated static inline int url_is_streamed(AVIOContext *s)
de6d9b64 546{
8978feda 547 return !s->seekable;
de6d9b64 548}
8978feda 549#endif
de6d9b64 550
364cacc7 551#if FF_API_URL_RESETBUF
770d9daf
BA
552/** Reset the buffer for reading or writing.
553 * @note Will drop any data currently in the buffer without transmitting it.
554 * @param flags URL_RDONLY to set up the buffer for reading, or URL_WRONLY
555 * to set up the buffer for writing. */
ae628ec1 556int url_resetbuf(AVIOContext *s, int flags);
08580cb0 557#endif
a8c5ab27 558
fe4fbb58 559/**
ae628ec1 560 * Create and initialize a AVIOContext for accessing the
fe4fbb58
SS
561 * resource indicated by url.
562 * @note When the resource indicated by url has been opened in
ae628ec1 563 * read+write mode, the AVIOContext can be used only for writing.
fe4fbb58 564 *
ae628ec1 565 * @param s Used to return the pointer to the created AVIOContext.
fe4fbb58
SS
566 * In case of failure the pointed to value is set to NULL.
567 * @param flags flags which control how the resource indicated by url
568 * is to be opened
569 * @return 0 in case of success, a negative value corresponding to an
570 * AVERROR code in case of failure
571 */
22a3212e 572int avio_open(AVIOContext **s, const char *url, int flags);
fe4fbb58 573
22a3212e 574int avio_close(AVIOContext *s);
a8c5ab27 575
e8bb2e24 576#if FF_API_OLD_AVIO
8d9769a7
AK
577attribute_deprecated URLContext *url_fileno(AVIOContext *s);
578
c3316802 579/**
e8bb2e24 580 * @deprecated use AVIOContext.max_packet_size directly.
a8c5ab27 581 */
e8bb2e24 582attribute_deprecated int url_fget_max_packet_size(AVIOContext *s);
de6d9b64 583
83fddaeb 584attribute_deprecated int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags);
a8c5ab27 585
c3316802 586/** return the written or read size */
35f10235
AK
587attribute_deprecated int url_close_buf(AVIOContext *s);
588#endif
de6d9b64 589
c3316802 590/**
a8c5ab27
PI
591 * Open a write only memory stream.
592 *
593 * @param s new IO context
594 * @return zero if no error.
595 */
b92c5452 596int avio_open_dyn_buf(AVIOContext **s);
a8c5ab27 597
c3316802 598/**
a8c5ab27 599 * Return the written size and a pointer to the buffer. The buffer
403ee835
AK
600 * must be freed with av_free().
601 * Padding of FF_INPUT_BUFFER_PADDING_SIZE is added to the buffer.
de1807bb 602 *
a8c5ab27 603 * @param s IO context
e8b7c70f 604 * @param pbuffer pointer to a byte buffer
a8c5ab27
PI
605 * @return the length of the byte buffer
606 */
6dc7d80d 607int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
f031df23 608
8ef30ac1 609#if FF_API_UDP_GET_FILE
f031df23 610int udp_get_file_handle(URLContext *h);
f0a80394 611#endif
f031df23 612
98790382 613#endif /* AVFORMAT_AVIO_H */