avio.h
Go to the documentation of this file.
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 
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
51 typedef struct {
52  int (*callback)(void*);
53  void *opaque;
55 
68 typedef struct {
69 #if !FF_API_OLD_AVIO
70 
83 #endif
84  unsigned char *buffer;
86  unsigned char *buf_ptr;
87  unsigned char *buf_end;
91  void *opaque;
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;
97  int must_flush;
99  int write_flag;
100 #if FF_API_OLD_AVIO
101  attribute_deprecated int is_streamed;
102 #endif
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;
111  int (*read_pause)(void *opaque, int pause);
117  int64_t (*read_seek)(void *opaque, int stream_index,
118  int64_t timestamp, int flags);
122  int seekable;
123 } AVIOContext;
124 
125 /* unbuffered I/O */
126 
127 #if FF_API_OLD_AVIO
128 
136 typedef struct URLContext {
137  const AVClass *av_class;
138  struct URLProtocol *prot;
139  int flags;
140  int is_streamed;
141  int max_packet_size;
142  void *priv_data;
143  char *filename;
144  int is_connected;
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 
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 
188 #define URL_RDONLY 1
189 #define URL_WRONLY 2
190 #define URL_RDWR (URL_RDONLY|URL_WRONLY)
207 #define URL_FLAG_NONBLOCK 8
208 
209 typedef int URLInterruptCB(void);
210 extern URLInterruptCB *url_interrupt_cb;
211 
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));
241 attribute_deprecated URLProtocol *av_protocol_next(URLProtocol *p);
247 attribute_deprecated int av_register_protocol2(URLProtocol *protocol, int size);
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 
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);
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);
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 
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);
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);
351 attribute_deprecated char *url_fgets(AVIOContext *s, char *buf, int buf_size);
355 attribute_deprecated char *get_strz(AVIOContext *s, char *buf, int maxlen);
359 attribute_deprecated static inline int url_is_streamed(AVIOContext *s)
360 {
361  return !s->seekable;
362 }
364 
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 
373 attribute_deprecated int url_close_buf(AVIOContext *s);
374 
380 attribute_deprecated int url_exist(const char *url);
381 #endif // FF_API_OLD_AVIO
382 
395 int avio_check(const char *url, int flags);
396 
397 #if FF_API_OLD_INTERRUPT_CB
398 
406 attribute_deprecated void avio_set_interrupt_cb(int (*interrupt_cb)(void));
407 #endif
408 
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 
450 int avio_put_str(AVIOContext *s, const char *str);
451 
456 int avio_put_str16le(AVIOContext *s, const char *str);
457 
463 #define AVSEEK_SIZE 0x10000
464 
471 #define AVSEEK_FORCE 0x20000
472 
477 int64_t avio_seek(AVIOContext *s, int64_t offset, int whence);
478 
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 
493 {
494  return avio_seek(s, 0, SEEK_CUR);
495 }
496 
501 int64_t avio_size(AVIOContext *s);
502 
504 int avio_printf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3);
505 
506 void avio_flush(AVIOContext *s);
507 
508 
513 int avio_read(AVIOContext *s, unsigned char *buf, int size);
514 
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);
547 int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen);
548 
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 
565 #define AVIO_FLAG_READ 1
566 #define AVIO_FLAG_WRITE 2
567 #define AVIO_FLAG_READ_WRITE (AVIO_FLAG_READ|AVIO_FLAG_WRITE)
584 #define AVIO_FLAG_NONBLOCK 8
585 
599 int avio_open(AVIOContext **s, const char *url, int flags);
600 
618 int avio_open2(AVIOContext **s, const char *url, int flags,
620 
627 int avio_close(AVIOContext *s);
628 
636 
646 int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
647 
659 const char *avio_enum_protocols(void **opaque, int output);
660 
666 int avio_pause(AVIOContext *h, int pause);
667 
685 int64_t avio_seek_time(AVIOContext *h, int stream_index,
686  int64_t timestamp, int flags);
687 
688 #endif /* AVFORMAT_AVIO_H */
int avio_open(AVIOContext **s, const char *url, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: aviobuf.c:965
void avio_wb64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:521
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:527
Bytestream IO Context.
Definition: avio.h:68
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:281
int size
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1196
int(* url_check)(URLContext *h, int mask)
Definition: url.h:75
int flags
Definition: url.h:74
unsigned char * buf_ptr
Current position in the buffer.
Definition: avio.h:86
unsigned char * buf_end
End of the data, may be less than buffer+buffer_size if the read function returned less data than req...
Definition: avio.h:87
int write_flag
true if open for writing
Definition: avio.h:99
int is_streamed
true if streamed (no seek possible), default = false
Definition: url.h:49
static int write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: assenc.c:58
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:148
AVIOInterruptCB interrupt_callback
Definition: url.h:51
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:211
struct URLProtocol * prot
Definition: url.h:44
unsigned char * buffer
Start of the buffer.
Definition: avio.h:84
#define b
Definition: swscale.c:1335
int flags
Definition: url.h:47
void * opaque
A private pointer, passed to the read/write/seek/...
Definition: avio.h:91
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:754
int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen)
Read a UTF-16 string from pb and convert it to UTF-8.
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1184
void * opaque
Definition: avio.h:53
const AVClass * priv_data_class
Definition: url.h:73
struct URLProtocol * next
Definition: url.h:67
Public dictionary API.
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:316
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:769
int(* url_get_file_handle)(URLContext *h)
Definition: url.h:71
static int flags
Definition: log.c:34
uint32_t tag
Definition: movenc.c:670
uint64_t avio_rb64(AVIOContext *s)
Definition: aviobuf.c:842
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:492
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:190
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:652
int avio_check(const char *url, int flags)
Return AVIO_FLAG_* access flags corresponding to the access permissions of the resource in url...
Definition: avio.c:407
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:515
int max_packet_size
Definition: avio.h:103
Callback for checking whether to abort blocking functions.
Definition: avio.h:51
AVIOContext * avio_alloc_context(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Allocate and initialize an AVIOContext for buffered I/O.
Definition: aviobuf.c:134
struct URLProtocol URLProtocol
static const uint16_t mask[17]
Definition: lzw.c:36
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:738
const char * avio_enum_protocols(void **opaque, int output)
Iterate through names of available protocols.
Definition: avio.c:99
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:987
int(* url_open)(URLContext *h, const char *url, int flags)
Definition: url.h:56
unsigned long checksum
Definition: avio.h:104
#define av_printf_format(fmtpos, attrpos)
Definition: attributes.h:133
int(* url_write)(URLContext *h, const unsigned char *buf, int size)
Definition: url.h:64
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:632
int(* url_read)(URLContext *h, unsigned char *buf, int size)
Definition: url.h:63
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:122
int void avio_flush(AVIOContext *s)
Definition: aviobuf.c:205
unsigned int avio_rb24(AVIOContext *s)
Definition: aviobuf.c:762
static const AVIOInterruptCB int_cb
Definition: avconv.c:661
unsigned char * checksum_ptr
Definition: avio.h:105
void avio_wb24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:545
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: avio.h:483
int must_flush
true if the next seek should flush
Definition: avio.h:97
struct URLContext URLContext
int(* url_read_pause)(URLContext *h, int pause)
Definition: url.h:68
static char buffer[20]
Definition: seek-test.c:34
int64_t(* url_seek)(URLContext *h, int64_t pos, int whence)
Definition: url.h:65
Libavformat version macros.
int buffer_size
Maximum buffer size.
Definition: avio.h:85
int is_connected
Definition: url.h:50
int avio_put_str(AVIOContext *s, const char *str)
Write a NULL-terminated string.
Definition: aviobuf.c:469
int64_t(* url_read_seek)(URLContext *h, int stream_index, int64_t timestamp, int flags)
Definition: url.h:69
static const OptionDef options[]
Definition: avconv.c:105
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:169
Definition: url.h:42
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: libcdio.c:109
Describe the class of an AVClass context structure.
Definition: log.h:33
void * priv_data
Definition: url.h:45
int avio_put_str16le(AVIOContext *s, const char *str)
Convert an UTF-8 string to UTF-16LE and write it.
Definition: aviobuf.c:480
int avio_open2(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: aviobuf.c:970
int error
contains the error code or 0 if no error happened
Definition: avio.h:107
void avio_wl24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:539
int avio_pause(AVIOContext *h, int pause)
Pause and resume playing - only meaningful if using a network streaming protocol (e.g.
Definition: aviobuf.c:1044
const char * name
Definition: url.h:55
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:533
const AVClass * av_class
information for av_log().
Definition: url.h:43
#define attribute_deprecated
Definition: attributes.h:87
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:722
common internal and external API header
int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen)
char * filename
specified URL
Definition: url.h:46
int64_t pos
position in the file of the current buffer
Definition: avio.h:96
int(* url_interrupt_cb)(void)
int64_t avio_seek_time(AVIOContext *h, int stream_index, int64_t timestamp, int flags)
Seek to a given timestamp relative to some component stream.
Definition: aviobuf.c:1051
int eof_reached
true if eof reached
Definition: avio.h:98
int len
AVClass * av_class
A class for private options.
Definition: avio.h:82
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:324
int max_packet_size
if non zero, the stream is packetized with this max packet size
Definition: url.h:48
int(* url_close)(URLContext *h)
Definition: url.h:66
#define av_always_inline
Definition: attributes.h:39
int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen)
Read a string from pb into buf.
Definition: aviobuf.c:800
unsigned int avio_rl24(AVIOContext *s)
Definition: aviobuf.c:730
int priv_data_size
Definition: url.h:72
uint64_t avio_rl64(AVIOContext *s)
Definition: aviobuf.c:746
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
static int get_byte(LZOContext *c)
Reads one byte from the input buffer, avoiding an overrun.
Definition: lzo.c:43