34 #define IO_BUFFER_SIZE 32768 41 #define SHORT_SEEK_THRESHOLD 4096 56 return prev ?
NULL :
internal->h;
64 #define OFFSET(x) offsetof(AVIOInternal, x) 66 {
"protocol_whitelist",
"A comma-separated list of allowed protocols",
68 {
"protocol_blacklist",
"A comma-separated list of forbidden protocols",
116 int64_t (*seek)(
void *opaque, int64_t offset,
int whence))
137 s->
pos = buffer_size;
152 unsigned char *buffer,
158 int64_t (*seek)(
void *opaque, int64_t offset,
int whence))
247 whence &= ~AVSEEK_FORCE;
254 if (whence != SEEK_CUR && whence != SEEK_SET)
257 if (whence == SEEK_CUR) {
263 offset1 = offset - pos;
271 (whence != SEEK_END || force)) {
286 if ((res = s->
seek(s->
opaque, offset, SEEK_SET)) < 0)
308 if ((size = s->
seek(s->
opaque, -1, SEEK_END)) < 0)
337 avio_write(s, (
const unsigned char *) str, len);
343 #define PUT_STR16(type, write) \ 344 int avio_put_str16 ## type(AVIOContext * s, const char *str) \ 346 const uint8_t *q = str; \ 353 GET_UTF8(ch, *q++, break; ) \ 354 PUT_UTF16(ch, tmp, write(s, tmp); ret += 2; ) \ 381 avio_w8(bc, 128 | (val >> (7 * i)));
388 avio_wl32(s, (uint32_t)(val & 0xffffffff));
395 avio_wb32(s, (uint32_t)(val & 0xffffffff));
525 unsigned long (*update_checksum)(
unsigned long c,
const uint8_t *p,
unsigned int len),
711 if (c && i < maxlen-1)
713 }
while (c !=
'\n' && c);
726 buflen =
FFMIN(buflen - 1, maxlen);
727 for (i = 0; i < buflen; i++)
731 for (; i < maxlen; i++)
737 #define GET_STR16(type, read) \ 738 int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\ 743 return AVERROR(EINVAL); \ 744 while (ret + 1 < maxlen) {\ 747 GET_UTF16(ch, (ret += 2) <= maxlen ? read(pb) : 0, break;)\ 750 PUT_UTF8(ch, tmp, if (q - buf < buflen - 1) *q++ = tmp;)\ 775 val= (val<<7) + (tmp&127);
783 return ffurl_read(internal->h, buf, buf_size);
792 static int64_t
io_seek(
void *opaque, int64_t offset,
int whence)
795 return ffurl_seek(internal->h, offset, whence);
801 if (!internal->h->prot->url_read_pause)
803 return internal->h->prot->url_read_pause(internal->h, pause);
809 if (!internal->h->prot->url_read_seek)
811 return internal->h->prot->url_read_seek(internal->h, stream_index, timestamp, flags);
818 int buffer_size, max_packet_size;
821 if (max_packet_size) {
822 buffer_size = max_packet_size;
845 (*s)->max_packet_size = max_packet_size;
891 int64_t buffer_start;
893 int overlap, new_size, alloc_size;
901 if ((buffer_start = s->
pos - buffer_size) > buf_size)
904 overlap = buf_size - buffer_start;
905 new_size = buf_size + buffer_size - overlap;
908 if (alloc_size > buf_size)
912 if (new_size > buf_size) {
913 memcpy(buf + buf_size, s->
buffer + overlap, buffer_size - overlap);
938 char *proto_whitelist =
NULL, *proto_blacklist =
NULL;
946 proto_whitelist = e->
value;
949 proto_blacklist = e->
value;
956 err =
ffurl_open(&h, filename, flags, int_cb, options, protocols,
NULL);
969 internal = (*s)->opaque;
1018 ret = vsnprintf(buf,
sizeof(buf), fmt, ap);
1032 int64_t timestamp,
int flags)
1044 else if (pos !=
AVERROR(ENOSYS))
1062 unsigned new_size, new_allocated_size;
1065 new_size = d->
pos + buf_size;
1067 if (new_size < d->pos || new_size > INT_MAX/2)
1069 while (new_size > new_allocated_size) {
1070 if (!new_allocated_size)
1071 new_allocated_size = new_size;
1073 new_allocated_size += new_allocated_size / 2 + 1;
1085 memcpy(d->
buffer + d->
pos, buf, buf_size);
1094 unsigned char buf1[4];
1111 if (whence == SEEK_CUR)
1113 else if (whence == SEEK_END)
1115 if (offset < 0 || offset > 0x7fffffffLL)
1124 unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
1126 if (
sizeof(
DynBuffer) + io_buffer_size < io_buffer_size)
1139 (*s)->max_packet_size = max_packet_size;
1150 if (max_packet_size <= 0)
1180 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)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
uint64_t avio_rb64(AVIOContext *s)
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
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.
static int64_t io_read_seek(void *opaque, int stream_index, int64_t timestamp, int flags)
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
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
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)
#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...
void * opaque
A private pointer, passed to the read/write/seek/...
const URLProtocol ** protocols
static void * io_priv_child_next(void *obj, void *prev)
void avio_wb32(AVIOContext *s, unsigned int val)
static const AVClass * ff_avio_child_class_next(const AVClass *prev)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static int io_read_packet(void *opaque, uint8_t *buf, int buf_size)
Trailer data, which doesn't contain actual content, but only for finalizing the output file...
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.
static int io_read_pause(void *opaque, int pause)
unsigned long ffio_get_checksum(AVIOContext *s)
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
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))
A point in the output bytestream where a demuxer can start parsing (for non self synchronizing bytest...
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
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.
int ffurl_open(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const URLProtocol **protocols, URLContext *parent)
Create an URLContext for accessing to the resource indicated by url, and open it. ...
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(). ...
unsigned int avio_rb24(AVIOContext *s)
static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
static const AVOption ff_avio_options[]
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...
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)
char * protocol_blacklist
This is any, unlabelled data.
int(* read_packet)(void *opaque, uint8_t *buf, int buf_size)
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.
const AVIOInterruptCB int_cb
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
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,...)
AVIODataMarkerType
Different data types that can be returned via the AVIO write_data_type callback.
int64_t(* seek)(void *opaque, int64_t offset, int whence)
int must_flush
true if the next seek should flush
static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
int ff_get_line(AVIOContext *s, char *buf, int maxlen)
Read a whole line of text from AVIOContext.
#define GET_STR16(type, read)
static volatile int checksum
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 PUT_STR16(type, write)
#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 av_opt_set_dict(void *obj, AVDictionary **options)
int avio_open(AVIOContext **s, const char *filename, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
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.
int(* write_packet)(void *opaque, uint8_t *buf, int buf_size)
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
Passing this flag as the "whence" parameter to a seek function causes it to seek by any means (like r...
unsigned int avio_rb16(AVIOContext *s)
int ignore_boundary_point
If set, don'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).
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
int error
contains the error code or 0 if no error happened
static const AVClass io_priv_class
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...
static const AVOption io_priv_options[]
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
enum AVIODataMarkerType current_type
Internal, not meant to be used from outside of AVIOContext.
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.
int(* read_pause)(void *opaque, int pause)
Pause or resume playback for network streaming protocols - e.g.
int64_t avio_size(AVIOContext *s)
Get the filesize.
void av_opt_free(void *obj)
Free all allocated objects in obj.
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...
const struct URLProtocol * prot
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.
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
unsigned long(* update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size)
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
ORing this as the "whence" parameter to a seek function causes it to return the filesize without seek...
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
uint64_t ffio_read_varlen(AVIOContext *bc)
unsigned int avio_rb32(AVIOContext *s)
A point in the output bytestream where a decoder can start decoding (i.e.
int eof_reached
true if eof reached
static int io_write_packet(void *opaque, uint8_t *buf, int buf_size)
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
char * protocol_whitelist
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
int avio_r8(AVIOContext *s)
const URLProtocol ** ffurl_get_protocols(const char *whitelist, const char *blacklist)
Construct a list of protocols matching a given whitelist and/or blacklist.
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(* read_seek)(void *opaque, int stream_index, int64_t timestamp, int flags)
Seek to a given timestamp in stream with the specified stream_index.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static int64_t io_seek(void *opaque, int64_t offset, int whence)
Header data; this needs to be present for the stream to be decodeable.
#define AV_NOPTS_VALUE
Undefined timestamp value.
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)
static const AVClass * io_priv_child_class_next(const AVClass *prev)