36 #define IO_BUFFER_SIZE 32768
43 #define SHORT_SEEK_THRESHOLD 4096
79 int64_t (*seek)(
void *opaque, int64_t
offset,
int whence))
102 s->
pos = buffer_size;
112 unsigned char *buffer,
118 int64_t (*seek)(
void *opaque, int64_t
offset,
int whence))
209 whence &= ~AVSEEK_FORCE;
217 if (whence != SEEK_CUR && whence != SEEK_SET)
220 if (whence == SEEK_CUR) {
229 offset1 = offset - pos;
231 offset1 >= 0 && offset1 <= buffer_size - s->write_flag) {
238 (whence != SEEK_END || force)) {
244 }
else if(!s->
write_flag && offset1 < 0 && -offset1 < buffer_size>>1 && s->
seek && offset > 0) {
247 pos -=
FFMIN(buffer_size>>1, pos);
248 if ((res = s->
seek(s->
opaque, pos, SEEK_SET)) < 0)
255 return avio_seek(s, offset, SEEK_SET | force);
264 if ((res = s->
seek(s->
opaque, offset, SEEK_SET)) < 0)
292 if ((size = s->
seek(s->
opaque, -1, SEEK_END)) < 0)
339 avio_write(s, (
const unsigned char *) str, len);
360 av_log(s,
AV_LOG_ERROR,
"Invaid UTF8 sequence in avio_put_str16%s\n", be ?
"be" :
"le");
373 #define PUT_STR16(type, big_endian) \
374 int avio_put_str16 ## type(AVIOContext *s, const char *str) \
376 return put_str16(s, str, big_endian); \
406 avio_wl32(s, (uint32_t)(val & 0xffffffff));
413 avio_wb32(s, (uint32_t)(val & 0xffffffff));
517 unsigned long (*update_checksum)(
unsigned long c,
const uint8_t *p,
unsigned int len),
518 unsigned long checksum)
704 if (c && i < maxlen-1)
706 }
while (c !=
'\n' && c !=
'\r' && c);
721 buflen =
FFMIN(buflen - 1, maxlen);
722 for (i = 0; i < buflen; i++)
726 for (; i < maxlen; i++)
732 #define GET_STR16(type, read) \
733 int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\
738 return AVERROR(EINVAL); \
739 while (ret + 1 < maxlen) {\
742 GET_UTF16(ch, (ret += 2) <= maxlen ? read(pb) : 0, break;)\
745 PUT_UTF8(ch, tmp, if (q - buf < buflen - 1) *q++ = tmp;)\
770 val= (val<<7) + (tmp&127);
778 int buffer_size, max_packet_size;
781 if (max_packet_size) {
782 buffer_size = max_packet_size;
793 (int64_t (*)(
void *, int64_t,
int))
ffurl_seek);
800 (*s)->max_packet_size = max_packet_size;
803 (*s)->read_seek = (int64_t (*)(
void *, int, int64_t, int))h->
prot->
url_read_seek;
818 if (buf_size < filled || s->seekable || !s->
read_packet)
826 memcpy(buffer, s->
buffer, filled);
867 int64_t buffer_start;
869 int overlap, new_size, alloc_size;
880 if ((buffer_start = s->
pos - buffer_size) > buf_size) {
885 overlap = buf_size - buffer_start;
886 new_size = buf_size + buffer_size - overlap;
889 if (alloc_size > buf_size)
890 if (!(buf = (*bufp) =
av_realloc_f(buf, 1, alloc_size)))
893 if (new_size > buf_size) {
894 memcpy(buf + buf_size, s->
buffer + overlap, buffer_size - overlap);
920 err =
ffurl_open(&h, filename, flags, int_cb, options);
934 return avio_open2(pb, url, flags, int_cb, options);
969 ret =
vsnprintf(buf,
sizeof(buf), fmt, ap);
983 int64_t timestamp,
int flags)
989 ret = s->
read_seek(h, stream_index, timestamp, flags);
993 pos = s->
seek(h, 0, SEEK_CUR);
996 else if (pos !=
AVERROR(ENOSYS))
1032 unsigned new_size, new_allocated_size;
1035 new_size = d->
pos + buf_size;
1037 if (new_size < d->pos || new_size > INT_MAX/2)
1039 while (new_size > new_allocated_size) {
1040 if (!new_allocated_size)
1041 new_allocated_size = new_size;
1043 new_allocated_size += new_allocated_size / 2 + 1;
1055 memcpy(d->
buffer + d->
pos, buf, buf_size);
1064 unsigned char buf1[4];
1081 if (whence == SEEK_CUR)
1083 else if (whence == SEEK_END)
1085 if (offset < 0 || offset > 0x7fffffffLL)
1094 unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
1096 if (
sizeof(
DynBuffer) + io_buffer_size < io_buffer_size)
1109 (*s)->max_packet_size = max_packet_size;
1120 if (max_packet_size <= 0)
1150 return size - padding;
void avio_wl64(AVIOContext *s, uint64_t val)
const char const char void * val
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)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
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.
#define av_realloc_f(p, o, n)
void avio_wb16(AVIOContext *s, unsigned int val)
ptrdiff_t const GLvoid * data
#define AV_LOG_WARNING
Something somehow does not look correct.
int avio_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
#define LIBAVUTIL_VERSION_INT
unsigned char * buf_ptr
Current position in the buffer.
int writeout_count
writeout statistic This field is internal to libavformat and access from outside is not allowed...
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
int avio_read_to_bprint(AVIOContext *h, AVBPrint *pb, size_t max_size)
Read contents of h into print buffer, up to max_size bytes, or up to EOF.
#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/...
void avio_wb32(AVIOContext *s, unsigned int val)
static const AVClass * ff_avio_child_class_next(const AVClass *prev)
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...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
static void fill_buffer(AVIOContext *s)
unsigned long ffio_get_checksum(AVIOContext *s)
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
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))
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
int64_t bytes_read
Bytes read statistic This field is internal to libavformat and access from outside is not allowed...
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.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int(* write_packet)(void *opaque, uint8_t *buf, int buf_size)
unsigned int avio_rb24(AVIOContext *s)
const AVIOInterruptCB int_cb
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)
static const AVOption ff_avio_options[]
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
simple assert() macros that are a bit more flexible than ISO C assert().
static void * ff_avio_child_next(void *obj, void *prev)
#define SHORT_SEEK_THRESHOLD
Do seeks within this distance ahead of the current buffer by skipping data instead of calling the pro...
static const uint8_t offset[127][2]
int direct
avio_read and avio_write should if possible be satisfied directly instead of going through a buffer...
unsigned int avio_rl16(AVIOContext *s)
int seek_count
seek statistic This field is internal to libavformat and access from outside is not allowed...
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.
int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
const AVClass ff_avio_class
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 ffio_open2_wrapper(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
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)
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
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.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#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'.
#define PUT_STR16(type, big_endian)
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)
int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char **bufp, int buf_size)
Rewind the AVIOContext using the specified buffer containing the first buf_size bytes of the file...
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.
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...
#define AVIO_FLAG_DIRECT
Use direct mode.
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).
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
int error
contains the error code or 0 if no error happened
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
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)
const AVClass ffurl_context_class
int orig_buffer_size
Original buffer size used internally after probing and ensure seekback to reset the buffer size This ...
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
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.
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...
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)
static int put_str16(AVIOContext *s, const char *str, const int be)
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 void writeout(AVIOContext *s, const uint8_t *data, int len)
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
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
unbuffered private I/O API
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
int avio_r8(AVIOContext *s)
static int write_packet(AVFormatContext *s1, AVPacket *pkt)
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)