34 #define IO_BUFFER_SIZE 32768
41 #define SHORT_SEEK_THRESHOLD 4096
76 int (*
read_packet)(
void *opaque, uint8_t *buf,
int buf_size),
77 int (*
write_packet)(
void *opaque, uint8_t *buf,
int buf_size),
78 int64_t (*seek)(
void *opaque, int64_t offset,
int whence))
109 unsigned char *buffer,
113 int (*
read_packet)(
void *opaque, uint8_t *buf,
int buf_size),
114 int (*
write_packet)(
void *opaque, uint8_t *buf,
int buf_size),
115 int64_t (*seek)(
void *opaque, int64_t offset,
int whence))
121 unsigned char *buffer,
125 int (*
read_packet)(
void *opaque, uint8_t *buf,
int buf_size),
126 int (*
write_packet)(
void *opaque, uint8_t *buf,
int buf_size),
127 int64_t (*seek)(
void *opaque, int64_t offset,
int whence))
135 unsigned char *buffer,
139 int (*
read_packet)(
void *opaque, uint8_t *buf,
int buf_size),
140 int (*
write_packet)(
void *opaque, uint8_t *buf,
int buf_size),
141 int64_t (*seek)(
void *opaque, int64_t offset,
int whence))
216 whence &= ~AVSEEK_FORCE;
223 if (whence != SEEK_CUR && whence != SEEK_SET)
226 if (whence == SEEK_CUR) {
232 offset1 = offset - pos;
240 (whence != SEEK_END || force)) {
249 #if CONFIG_MUXERS || CONFIG_NETWORK
257 if ((res = s->
seek(s->
opaque, offset, SEEK_SET)) < 0)
271 int64_t ret =
avio_seek(s, offset, SEEK_CUR);
272 return ret < 0 ? ret : 0;
292 if ((size = s->
seek(s->
opaque, -1, SEEK_END)) < 0)
338 #define GET(name, type) \
339 type get_be ##name(AVIOContext *s) \
341 return avio_rb ##name(s);\
343 type get_le ##name(AVIOContext *s) \
345 return avio_rl ##name(s);\
348 GET(16,
unsigned int)
349 GET(24,
unsigned int)
350 GET(32,
unsigned int)
355 #define PUT(name, type ) \
356 void put_le ##name(AVIOContext *s, type val)\
358 avio_wl ##name(s, val);\
360 void put_be ##name(AVIOContext *s, type val)\
362 avio_wb ##name(s, val);\
365 PUT(16,
unsigned int)
366 PUT(24,
unsigned int)
367 PUT(32,
unsigned int)
404 int64_t url_fseek(
AVIOContext *s, int64_t offset,
int whence)
416 int url_fprintf(
AVIOContext *s,
const char *fmt, ...)
423 ret = vsnprintf(buf,
sizeof(buf), fmt, ap);
436 int64_t av_url_read_fseek(
AVIOContext *s,
int stream_index,
437 int64_t timestamp,
int flags)
442 unsigned long (*update_checksum)(
unsigned long c,
const uint8_t *p,
unsigned int len),
443 unsigned long checksum)
455 int url_open_dyn_packet_buf(
AVIOContext **s,
int max_packet_size)
459 int url_close_dyn_buf(
AVIOContext *s, uint8_t **pbuffer)
474 avio_write(s, (
const unsigned char *) str, len);
482 const uint8_t *q = str;
510 avio_w8(bc, 128 | (val>>(7*i)));
517 avio_wl32(s, (uint32_t)(val & 0xffffffff));
524 avio_wb32(s, (uint32_t)(val & 0xffffffff));
621 unsigned long (*update_checksum)(
unsigned long c,
const uint8_t *p,
unsigned int len),
622 unsigned long checksum)
778 char *get_strz(
AVIOContext *s,
char *buf,
int maxlen)
792 if (c && i < maxlen-1)
794 }
while (c !=
'\n' && c);
807 buflen =
FFMIN(buflen - 1, maxlen);
808 for (i = 0; i < buflen; i++)
812 for (; i < maxlen; i++)
818 #define GET_STR16(type, read) \
819 int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\
824 return AVERROR(EINVAL); \
825 while (ret + 1 < maxlen) {\
828 GET_UTF16(ch, (ret += 2) <= maxlen ? read(pb) : 0, break;)\
831 PUT_UTF8(ch, tmp, if (q - buf < buflen - 1) *q++ = tmp;)\
856 val= (val<<7) + (tmp&127);
864 int buffer_size, max_packet_size;
867 if (max_packet_size) {
868 buffer_size = max_packet_size;
886 (*s)->max_packet_size = max_packet_size;
889 (*s)->read_seek = (int64_t (*)(
void *, int, int64_t, int))h->
prot->
url_read_seek;
928 int64_t buffer_start;
930 int overlap, new_size, alloc_size;
938 if ((buffer_start = s->
pos - buffer_size) > buf_size)
941 overlap = buf_size - buffer_start;
942 new_size = buf_size + buffer_size - overlap;
945 if (alloc_size > buf_size)
949 if (new_size > buf_size) {
950 memcpy(buf + buf_size, s->
buffer + overlap, buffer_size - overlap);
976 err =
ffurl_open(&h, filename, flags, int_cb, options);
1010 ret = vsnprintf(buf,
sizeof(buf), fmt, ap);
1017 char *url_fgets(
AVIOContext *s,
char *buf,
int buf_size)
1029 if ((q - buf) < buf_size - 1)
1052 int64_t timestamp,
int flags)
1058 ret = s->
read_seek(h, stream_index, timestamp, flags);
1062 pos = s->
seek(h, 0, SEEK_CUR);
1065 else if (pos !=
AVERROR(ENOSYS))
1106 unsigned new_size, new_allocated_size;
1109 new_size = d->
pos + buf_size;
1111 if(new_size < d->pos || new_size > INT_MAX/2)
1113 while (new_size > new_allocated_size) {
1114 if (!new_allocated_size)
1115 new_allocated_size = new_size;
1117 new_allocated_size += new_allocated_size / 2 + 1;
1126 memcpy(d->
buffer + d->
pos, buf, buf_size);
1135 unsigned char buf1[4];
1152 if (whence == SEEK_CUR)
1154 else if (whence == SEEK_END)
1156 if (offset < 0 || offset > 0x7fffffffLL)
1165 unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
1167 if(
sizeof(
DynBuffer) + io_buffer_size < io_buffer_size)
1180 (*s)->max_packet_size = max_packet_size;
1191 if (max_packet_size <= 0)
1215 return size - padding;
void avio_wl64(AVIOContext *s, uint64_t val)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
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.
static int64_t dyn_buf_seek(void *opaque, int64_t offset, int whence)
uint64_t avio_rb64(AVIOContext *s)
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.
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
#define GET_UTF8(val, GET_BYTE, ERROR)
Convert a UTF-8 character (up to 4 bytes) to its 32-bit UCS-4 encoded form.
void avio_wb16(AVIOContext *s, unsigned int val)
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
unsigned char * buf_ptr
Current position in the buffer.
unsigned char * buf_end
End of the data, may be less than buffer+buffer_size if the read function returned less data than req...
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
int write_flag
true if open for writing
int is_streamed
true if streamed (no seek possible), default = false
int ffio_read_partial(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
void ffio_fill(AVIOContext *s, int b, int count)
#define AVIO_FLAG_READ
read-only
unsigned int avio_rl24(AVIOContext *s)
struct URLProtocol * prot
#define AVIO_FLAG_WRITE
write-only
unsigned char * buffer
Start of the buffer.
void avio_wl24(AVIOContext *s, unsigned int val)
void avio_w8(AVIOContext *s, int b)
int64_t(* seek)(void *opaque, int64_t offset, int whence)
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
void * opaque
A private pointer, passed to the read/write/seek/...
static const AVOption ffio_url_options[]
static const AVClass * ffio_url_child_class_next(const AVClass *prev)
void avio_wb32(AVIOContext *s, unsigned int val)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int avio_put_str(AVIOContext *s, const char *str)
Write a NULL-terminated string.
void avio_wl32(AVIOContext *s, unsigned int val)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static void fill_buffer(AVIOContext *s)
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
unsigned long ffio_get_checksum(AVIOContext *s)
void avio_flush(AVIOContext *s)
int ffio_init_context(AVIOContext *s, 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))
#define AVERROR_EOF
End of file.
int ffio_set_buf_size(AVIOContext *s, int buf_size)
void avio_wb24(AVIOContext *s, unsigned int val)
void avio_wl16(AVIOContext *s, unsigned int val)
static void flush_buffer(AVIOContext *s)
Callback for checking whether to abort blocking functions.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
int(* write_packet)(void *opaque, uint8_t *buf, int buf_size)
unsigned int avio_rb24(AVIOContext *s)
static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
int(* read_packet)(void *opaque, uint8_t *buf, int buf_size)
#define SHORT_SEEK_THRESHOLD
Do seeks within this distance ahead of the current buffer by skipping data instead of calling the pro...
unsigned int avio_rl16(AVIOContext *s)
int avio_pause(AVIOContext *s, int pause)
Pause and resume playing - only meaningful if using a network streaming protocol (e.g.
unsigned int avio_rl32(AVIOContext *s)
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
static const AVIOInterruptCB int_cb
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
unsigned char * checksum_ptr
struct DynBuffer DynBuffer
int avio_printf(AVIOContext *s, const char *fmt,...)
int must_flush
true if the next seek should flush
static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
int(* url_read_pause)(URLContext *h, int pause)
int ff_get_line(AVIOContext *s, char *buf, int maxlen)
Read a whole line of text from AVIOContext.
#define GET_STR16(type, read)
unsigned long(* update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size)
int buffer_size
Maximum buffer size.
void avio_wb64(AVIOContext *s, uint64_t val)
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size)
Open a write only packetized memory stream with a maximum packet size of 'max_packet_size'.
int avio_open(AVIOContext **s, const char *filename, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
int64_t(* url_read_seek)(URLContext *h, int stream_index, int64_t timestamp, int flags)
static const OptionDef options[]
static int url_resetbuf(AVIOContext *s, int flags)
uint64_t avio_rl64(AVIOContext *s)
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Describe the class of an AVClass context structure.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
#define AVSEEK_FORCE
Oring this flag as into the "whence" parameter to a seek function causes it to seek by any means (lik...
unsigned int avio_rb16(AVIOContext *s)
#define PUT_UTF16(val, tmp, PUT_16BIT)
Convert a 32-bit Unicode character to its UTF-16 encoded form (2 or 4 bytes).
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int error
contains the error code or 0 if no error happened
int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char *buf, int buf_size)
Rewind the AVIOContext using the specified buffer containing the first buf_size bytes of the file...
int(* read_pause)(void *opaque, int pause)
Pause or resume playback for network streaming protocols - e.g.
int ff_get_v_length(uint64_t val)
Get the length in bytes which is needed to store val as v.
int ffurl_close(URLContext *h)
Close the resource accessed by the URLContext h, and free the memory used by it.
const AVClass ffurl_context_class
int avio_open2(AVIOContext **s, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
int64_t avio_size(AVIOContext *s)
Get the filesize.
const AVClass ffio_url_class
int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen)
Read a string from pb into buf.
int64_t ffurl_seek(URLContext *h, int64_t pos, int whence)
Change the position that will be used by the next read/write operation on the resource accessed by h...
static void * ffio_url_child_next(void *obj, void *prev)
int ffurl_open(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create an URLContext for accessing to the resource indicated by url, and open it. ...
int ffio_fdopen(AVIOContext **s, URLContext *h)
Create and initialize a AVIOContext for accessing the resource referenced by the URLContext h...
void ffio_init_checksum(AVIOContext *s, unsigned long(*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum)
int64_t pos
position in the file of the current buffer
#define AVSEEK_SIZE
Passing this as the "whence" parameter to a seek function causes it to return the filesize without se...
uint64_t ffio_read_varlen(AVIOContext *bc)
unsigned int avio_rb32(AVIOContext *s)
int eof_reached
true if eof reached
void ff_put_v(AVIOContext *bc, uint64_t val)
Put val using a variable number of bytes.
static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
int max_packet_size
if non zero, the stream is packetized with this max packet size
unbuffered private I/O API
int avio_put_str16le(AVIOContext *s, const char *str)
Convert an UTF-8 string to UTF-16LE and write it.
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
int avio_r8(AVIOContext *s)
int ffurl_read(URLContext *h, unsigned char *buf, int size)
Read up to size bytes from the resource accessed by h, and store the read bytes in buf...
int64_t avio_seek_time(AVIOContext *s, int stream_index, int64_t timestamp, int flags)
Seek to a given timestamp relative to some component stream.
static int get_byte(LZOContext *c)
Reads one byte from the input buffer, avoiding an overrun.