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 
90 };
91 
104 typedef struct AVIOContext {
118  unsigned char *buffer;
120  unsigned char *buf_ptr;
121  unsigned char *buf_end;
125  void *opaque;
127  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
128  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
129  int64_t (*seek)(void *opaque, int64_t offset, int whence);
130  int64_t pos;
135  unsigned long checksum;
136  unsigned char *checksum_ptr;
137  unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
138  int error;
142  int (*read_pause)(void *opaque, int pause);
148  int64_t (*read_seek)(void *opaque, int stream_index,
149  int64_t timestamp, int flags);
153  int seekable;
154 
158  int (*write_data_type)(void *opaque, uint8_t *buf, int buf_size,
159  enum AVIODataMarkerType type, int64_t time);
166 
171  int64_t last_time;
172 } AVIOContext;
173 
186 int avio_check(const char *url, int flags);
187 
206  unsigned char *buffer,
207  int buffer_size,
208  int write_flag,
209  void *opaque,
210  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
211  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
212  int64_t (*seek)(void *opaque, int64_t offset, int whence));
213 
214 void avio_w8(AVIOContext *s, int b);
215 void avio_write(AVIOContext *s, const unsigned char *buf, int size);
216 void avio_wl64(AVIOContext *s, uint64_t val);
217 void avio_wb64(AVIOContext *s, uint64_t val);
218 void avio_wl32(AVIOContext *s, unsigned int val);
219 void avio_wb32(AVIOContext *s, unsigned int val);
220 void avio_wl24(AVIOContext *s, unsigned int val);
221 void avio_wb24(AVIOContext *s, unsigned int val);
222 void avio_wl16(AVIOContext *s, unsigned int val);
223 void avio_wb16(AVIOContext *s, unsigned int val);
224 
229 int avio_put_str(AVIOContext *s, const char *str);
230 
238 int avio_put_str16le(AVIOContext *s, const char *str);
239 
247 int avio_put_str16be(AVIOContext *s, const char *str);
248 
259 void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type);
260 
266 #define AVSEEK_SIZE 0x10000
267 
274 #define AVSEEK_FORCE 0x20000
275 
280 int64_t avio_seek(AVIOContext *s, int64_t offset, int whence);
281 
286 static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
287 {
288  return avio_seek(s, offset, SEEK_CUR);
289 }
290 
296 {
297  return avio_seek(s, 0, SEEK_CUR);
298 }
299 
304 int64_t avio_size(AVIOContext *s);
305 
307 int avio_printf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3);
308 
309 void avio_flush(AVIOContext *s);
310 
311 
316 int avio_read(AVIOContext *s, unsigned char *buf, int size);
317 
325 int avio_r8 (AVIOContext *s);
326 unsigned int avio_rl16(AVIOContext *s);
327 unsigned int avio_rl24(AVIOContext *s);
328 unsigned int avio_rl32(AVIOContext *s);
329 uint64_t avio_rl64(AVIOContext *s);
330 unsigned int avio_rb16(AVIOContext *s);
331 unsigned int avio_rb24(AVIOContext *s);
332 unsigned int avio_rb32(AVIOContext *s);
333 uint64_t avio_rb64(AVIOContext *s);
350 int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen);
351 
358 int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen);
359 int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen);
360 
361 
368 #define AVIO_FLAG_READ 1
369 #define AVIO_FLAG_WRITE 2
370 #define AVIO_FLAG_READ_WRITE (AVIO_FLAG_READ|AVIO_FLAG_WRITE)
387 #define AVIO_FLAG_NONBLOCK 8
388 
403 int avio_open(AVIOContext **s, const char *url, int flags);
404 
423 int avio_open2(AVIOContext **s, const char *url, int flags,
425 
436 int avio_close(AVIOContext *s);
437 
449 int avio_closep(AVIOContext **s);
450 
451 
459 
469 int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
470 
482 const char *avio_enum_protocols(void **opaque, int output);
483 
491 int avio_pause(AVIOContext *h, int pause);
492 
512 int64_t avio_seek_time(AVIOContext *h, int stream_index,
513  int64_t timestamp, int flags);
514 
515 #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:928
void avio_wb64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:392
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:398
Bytestream IO Context.
Definition: avio.h:104
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:297
int size
int avio_put_str16be(AVIOContext *s, const char *str)
Convert an UTF-8 string to UTF-16BE and write it.
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1155
int64_t last_time
Definition: avio.h:171
unsigned char * buf_ptr
Current position in the buffer.
Definition: avio.h:120
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:121
int write_flag
true if open for writing
Definition: avio.h:133
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:242
unsigned char * buffer
Start of the buffer.
Definition: avio.h:118
void * opaque
A private pointer, passed to the read/write/seek/...
Definition: avio.h:125
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:681
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:1143
void * opaque
Definition: avio.h:53
Trailer data, which doesn&#39;t contain actual content, but only for finalizing the output file...
Definition: avio.h:89
Public dictionary API.
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:316
uint8_t
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:696
#define b
Definition: input.c:52
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
Definition: aviobuf.c:422
const AVClass * av_class
A class for private options.
Definition: avio.h:117
A point in the output bytestream where a demuxer can start parsing (for non self synchronizing bytest...
Definition: avio.h:77
static int flags
Definition: log.c:50
uint64_t avio_rb64(AVIOContext *s)
Definition: aviobuf.c:761
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:295
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:221
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:545
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:301
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:386
const OptionDef options[]
Definition: avconv_opt.c:2447
int max_packet_size
Definition: avio.h:134
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:151
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:665
const char * avio_enum_protocols(void **opaque, int output)
Iterate through names of available protocols.
Definition: protocols.c:83
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:983
unsigned long checksum
Definition: avio.h:135
#define av_printf_format(fmtpos, attrpos)
Definition: attributes.h:117
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:536
This is any, unlabelled data.
Definition: avio.h:84
int(* read_packet)(void *opaque, uint8_t *buf, int buf_size)
Definition: avio.h:127
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:153
int void avio_flush(AVIOContext *s)
Definition: aviobuf.c:236
unsigned int avio_rb24(AVIOContext *s)
Definition: aviobuf.c:689
const AVIOInterruptCB int_cb
Definition: avconv.c:140
unsigned char * checksum_ptr
Definition: avio.h:136
AVIODataMarkerType
Different data types that can be returned via the AVIO write_data_type callback.
Definition: avio.h:60
void avio_wb24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:416
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: avio.h:286
int64_t(* seek)(void *opaque, int64_t offset, int whence)
Definition: avio.h:129
int must_flush
true if the next seek should flush
Definition: avio.h:131
Libavformat version macros.
int buffer_size
Maximum buffer size.
Definition: avio.h:119
int avio_put_str(AVIOContext *s, const char *str)
Write a NULL-terminated string.
Definition: aviobuf.c:332
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:200
int(* write_packet)(void *opaque, uint8_t *buf, int buf_size)
Definition: avio.h:128
Describe the class of an AVClass context structure.
Definition: log.h:34
int avio_put_str16le(AVIOContext *s, const char *str)
Convert an UTF-8 string to UTF-16LE and write it.
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:933
int ignore_boundary_point
If set, don&#39;t call write_data_type separately for AVIO_DATA_MARKER_BOUNDARY_POINT, but ignore them and treat them as AVIO_DATA_MARKER_UNKNOWN (to avoid needlessly small chunks of data returned from the callback).
Definition: avio.h:165
int error
contains the error code or 0 if no error happened
Definition: avio.h:138
void avio_wl24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:410
int avio_pause(AVIOContext *h, int pause)
Pause and resume playing - only meaningful if using a network streaming protocol (e.g.
Definition: aviobuf.c:1024
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:404
enum AVIODataMarkerType current_type
Internal, not meant to be used from outside of AVIOContext.
Definition: avio.h:170
int(* read_pause)(void *opaque, int pause)
Pause or resume playback for network streaming protocols - e.g.
Definition: avio.h:142
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:649
common internal and external API header
int(* write_data_type)(void *opaque, uint8_t *buf, int buf_size, enum AVIODataMarkerType type, int64_t time)
A callback that is used instead of write_packet.
Definition: avio.h:158
int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen)
unsigned long(* update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size)
Definition: avio.h:137
int64_t pos
position in the file of the current buffer
Definition: avio.h:130
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:1031
A point in the output bytestream where a decoder can start decoding (i.e.
Definition: avio.h:71
int eof_reached
true if eof reached
Definition: avio.h:132
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:324
#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:719
unsigned int avio_rl24(AVIOContext *s)
Definition: aviobuf.c:657
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:1004
uint64_t avio_rl64(AVIOContext *s)
Definition: aviobuf.c:673
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:148
Header data; this needs to be present for the stream to be decodeable.
Definition: avio.h:64
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2