34 #define IO_BUFFER_SIZE 32768
41 #define SHORT_SEEK_THRESHOLD 4096
77 int64_t (*seek)(
void *opaque, int64_t offset,
int whence))
108 unsigned char *buffer,
114 int64_t (*seek)(
void *opaque, int64_t offset,
int whence))
191 whence &= ~AVSEEK_FORCE;
198 if (whence != SEEK_CUR && whence != SEEK_SET)
201 if (whence == SEEK_CUR) {
207 offset1 = offset - pos;
215 (whence != SEEK_END || force)) {
230 if ((res = s->
seek(s->
opaque, offset, SEEK_SET)) < 0)
252 if ((size = s->
seek(s->
opaque, -1, SEEK_END)) < 0)
281 avio_write(s, (
const unsigned char *) str, len);
319 avio_w8(bc, 128 | (val >> (7 * i)));
326 avio_wl32(s, (uint32_t)(val & 0xffffffff));
333 avio_wb32(s, (uint32_t)(val & 0xffffffff));
432 unsigned long (*update_checksum)(
unsigned long c,
const uint8_t *p,
unsigned int len),
433 unsigned long checksum)
610 if (c && i < maxlen-1)
612 }
while (c !=
'\n' && c);
625 buflen =
FFMIN(buflen - 1, maxlen);
626 for (i = 0; i < buflen; i++)
630 for (; i < maxlen; i++)
636 #define GET_STR16(type, read) \
637 int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\
642 return AVERROR(EINVAL); \
643 while (ret + 1 < maxlen) {\
646 GET_UTF16(ch, (ret += 2) <= maxlen ? read(pb) : 0, break;)\
649 PUT_UTF8(ch, tmp, if (q - buf < buflen - 1) *q++ = tmp;)\
674 val= (val<<7) + (tmp&127);
682 int buffer_size, max_packet_size;
685 if (max_packet_size) {
686 buffer_size = max_packet_size;
701 (*s)->max_packet_size = max_packet_size;
704 (*s)->read_seek = (int64_t (*)(
void *, int, int64_t, int))h->
prot->
url_read_seek;
741 int64_t buffer_start;
743 int overlap, new_size, alloc_size;
751 if ((buffer_start = s->
pos - buffer_size) > buf_size)
754 overlap = buf_size - buffer_start;
755 new_size = buf_size + buffer_size - overlap;
758 if (alloc_size > buf_size)
762 if (new_size > buf_size) {
763 memcpy(buf + buf_size, s->
buffer + overlap, buffer_size - overlap);
789 err =
ffurl_open(&h, filename, flags, int_cb, options);
828 ret = vsnprintf(buf,
sizeof(buf), fmt, ap);
842 int64_t timestamp,
int flags)
848 ret = s->
read_seek(h, stream_index, timestamp, flags);
852 pos = s->
seek(h, 0, SEEK_CUR);
855 else if (pos !=
AVERROR(ENOSYS))
873 unsigned new_size, new_allocated_size;
876 new_size = d->
pos + buf_size;
878 if (new_size < d->pos || new_size > INT_MAX/2)
880 while (new_size > new_allocated_size) {
881 if (!new_allocated_size)
882 new_allocated_size = new_size;
884 new_allocated_size += new_allocated_size / 2 + 1;
896 memcpy(d->
buffer + d->
pos, buf, buf_size);
905 unsigned char buf1[4];
922 if (whence == SEEK_CUR)
924 else if (whence == SEEK_END)
926 if (offset < 0 || offset > 0x7fffffffLL)
935 unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
937 if (
sizeof(
DynBuffer) + io_buffer_size < io_buffer_size)
950 (*s)->max_packet_size = max_packet_size;
961 if (max_packet_size <= 0)
991 return size - padding;
void avio_wl64(AVIOContext *s, uint64_t val)
void * av_malloc(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)
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
int64_t(* seek)(void *opaque, int64_t offset, int whence)
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_open_null_buf(AVIOContext **s)
Open a write-only fake memory stream.
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))
int av_reallocp(void *ptr, size_t size)
Allocate or reallocate a block of memory.
#define AVERROR_EOF
End of file.
int ffio_set_buf_size(AVIOContext *s, int buf_size)
int ffio_read_indirect(AVIOContext *s, unsigned char *buf, int size, const unsigned char **data)
Read size bytes from AVIOContext, returning a pointer.
void avio_wb24(AVIOContext *s, unsigned int val)
void avio_wl16(AVIOContext *s, unsigned int val)
const OptionDef options[]
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.
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
unsigned int avio_rl32(AVIOContext *s)
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
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
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 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)
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).
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)
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
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.
int ffio_close_null_buf(AVIOContext *s)
Close a null buffer.
static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)
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...
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
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.
unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf, unsigned int len)