Libav
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 AVIOInterruptCB {
52  int (*callback)(void*);
53  void *opaque;
55 
68 typedef struct AVIOContext {
81  const AVClass *av_class;
82  unsigned char *buffer;
84  unsigned char *buf_ptr;
85  unsigned char *buf_end;
89  void *opaque;
91  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
92  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
93  int64_t (*seek)(void *opaque, int64_t offset, int whence);
94  int64_t pos;
95  int must_flush;
97  int write_flag;
99  unsigned long checksum;
100  unsigned char *checksum_ptr;
101  unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
102  int error;
106  int (*read_pause)(void *opaque, int pause);
112  int64_t (*read_seek)(void *opaque, int stream_index,
113  int64_t timestamp, int flags);
117  int seekable;
118 } AVIOContext;
119 
120 /* unbuffered I/O */
121 
134 int avio_check(const char *url, int flags);
135 
154  unsigned char *buffer,
155  int buffer_size,
156  int write_flag,
157  void *opaque,
158  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
159  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
160  int64_t (*seek)(void *opaque, int64_t offset, int whence));
161 
162 void avio_w8(AVIOContext *s, int b);
163 void avio_write(AVIOContext *s, const unsigned char *buf, int size);
164 void avio_wl64(AVIOContext *s, uint64_t val);
165 void avio_wb64(AVIOContext *s, uint64_t val);
166 void avio_wl32(AVIOContext *s, unsigned int val);
167 void avio_wb32(AVIOContext *s, unsigned int val);
168 void avio_wl24(AVIOContext *s, unsigned int val);
169 void avio_wb24(AVIOContext *s, unsigned int val);
170 void avio_wl16(AVIOContext *s, unsigned int val);
171 void avio_wb16(AVIOContext *s, unsigned int val);
172 
177 int avio_put_str(AVIOContext *s, const char *str);
178 
183 int avio_put_str16le(AVIOContext *s, const char *str);
184 
190 #define AVSEEK_SIZE 0x10000
191 
198 #define AVSEEK_FORCE 0x20000
199 
204 int64_t avio_seek(AVIOContext *s, int64_t offset, int whence);
205 
210 static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
211 {
212  return avio_seek(s, offset, SEEK_CUR);
213 }
214 
220 {
221  return avio_seek(s, 0, SEEK_CUR);
222 }
223 
228 int64_t avio_size(AVIOContext *s);
229 
230 int avio_feof(AVIOContext *s);
231 
233 int avio_printf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3);
234 
235 void avio_flush(AVIOContext *s);
236 
237 
242 int avio_read(AVIOContext *s, unsigned char *buf, int size);
243 
251 int avio_r8 (AVIOContext *s);
252 unsigned int avio_rl16(AVIOContext *s);
253 unsigned int avio_rl24(AVIOContext *s);
254 unsigned int avio_rl32(AVIOContext *s);
255 uint64_t avio_rl64(AVIOContext *s);
256 unsigned int avio_rb16(AVIOContext *s);
257 unsigned int avio_rb24(AVIOContext *s);
258 unsigned int avio_rb32(AVIOContext *s);
259 uint64_t avio_rb64(AVIOContext *s);
276 int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen);
277 
284 int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen);
285 int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen);
286 
287 
294 #define AVIO_FLAG_READ 1
295 #define AVIO_FLAG_WRITE 2
296 #define AVIO_FLAG_READ_WRITE (AVIO_FLAG_READ|AVIO_FLAG_WRITE)
313 #define AVIO_FLAG_NONBLOCK 8
314 
329 int avio_open(AVIOContext **s, const char *url, int flags);
330 
349 int avio_open2(AVIOContext **s, const char *url, int flags,
351 
362 int avio_close(AVIOContext *s);
363 
375 int avio_closep(AVIOContext **s);
376 
377 
385 
395 int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
396 
408 const char *avio_enum_protocols(void **opaque, int output);
409 
417 int avio_pause(AVIOContext *h, int pause);
418 
438 int64_t avio_seek_time(AVIOContext *h, int stream_index,
439  int64_t timestamp, int flags);
440 
441 #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:789
void avio_wb64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:341
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:347
Bytestream IO Context.
Definition: avio.h:68
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:241
int64_t(* read_seek)(void *opaque, int stream_index, int64_t timestamp, int flags)
Seek to a given timestamp in stream with the specified stream_index.
Definition: avio.h:112
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:977
unsigned char * buf_ptr
Current position in the buffer.
Definition: avio.h:84
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:85
int write_flag
true if open for writing
Definition: avio.h:97
static int write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: assenc.c:58
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:186
unsigned char * buffer
Start of the buffer.
Definition: avio.h:82
int64_t(* seek)(void *opaque, int64_t offset, int whence)
Definition: avio.h:93
void * opaque
A private pointer, passed to the read/write/seek/...
Definition: avio.h:89
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:591
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:965
void * opaque
Definition: avio.h:53
Public dictionary API.
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:271
uint8_t
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:606
#define b
Definition: input.c:52
const AVClass * av_class
A class for private options.
Definition: avio.h:81
static int flags
Definition: log.c:44
uint64_t avio_rb64(AVIOContext *s)
Definition: aviobuf.c:671
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:219
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:165
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:463
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:318
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:335
const OptionDef options[]
Definition: avconv_opt.c:2187
int max_packet_size
Definition: avio.h:98
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:107
int(* write_packet)(void *opaque, uint8_t *buf, int buf_size)
Definition: avio.h:92
int(* read_packet)(void *opaque, uint8_t *buf, int buf_size)
Definition: avio.h:91
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:575
const char * avio_enum_protocols(void **opaque, int output)
Iterate through names of available protocols.
Definition: avio.c:86
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:811
unsigned long checksum
Definition: avio.h:99
#define av_printf_format(fmtpos, attrpos)
Definition: attributes.h:117
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:454
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:117
int void avio_flush(AVIOContext *s)
Definition: aviobuf.c:180
unsigned int avio_rb24(AVIOContext *s)
Definition: aviobuf.c:599
const AVIOInterruptCB int_cb
Definition: avconv.c:141
unsigned char * checksum_ptr
Definition: avio.h:100
void avio_wb24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:365
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: avio.h:210
int must_flush
true if the next seek should flush
Definition: avio.h:95
static char buffer[20]
Definition: seek-test.c:31
Libavformat version macros.
unsigned long(* update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size)
Definition: avio.h:101
int buffer_size
Maximum buffer size.
Definition: avio.h:83
int avio_put_str(AVIOContext *s, const char *str)
Write a NULL-terminated string.
Definition: aviobuf.c:287
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:144
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: libcdio.c:114
Describe the class of an AVClass context structure.
Definition: log.h:33
int avio_put_str16le(AVIOContext *s, const char *str)
Convert an UTF-8 string to UTF-16LE and write it.
Definition: aviobuf.c:298
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:794
int error
contains the error code or 0 if no error happened
Definition: avio.h:102
void avio_wl24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:359
int avio_pause(AVIOContext *h, int pause)
Pause and resume playing - only meaningful if using a network streaming protocol (e.g.
Definition: aviobuf.c:845
int(* read_pause)(void *opaque, int pause)
Pause or resume playback for network streaming protocols - e.g.
Definition: avio.h:106
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:353
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:559
common internal and external API header
int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen)
int64_t pos
position in the file of the current buffer
Definition: avio.h:94
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:852
int eof_reached
true if eof reached
Definition: avio.h:96
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:279
#define av_always_inline
Definition: attributes.h:40
int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen)
Read a string from pb into buf.
Definition: aviobuf.c:629
int avio_feof(AVIOContext *s)
Definition: aviobuf.c:260
unsigned int avio_rl24(AVIOContext *s)
Definition: aviobuf.c:567
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
Definition: aviobuf.c:825
uint64_t avio_rl64(AVIOContext *s)
Definition: aviobuf.c:583
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2