36 #define IO_BUFFER_SIZE 32768 43 #define SHORT_SEEK_THRESHOLD 32768 51 #if FF_API_CHILD_CLASS_NEXT 52 static const AVClass *ff_avio_child_class_next(
const AVClass *prev)
61 *iter = (
void*)(uintptr_t)
c;
65 #define OFFSET(x) offsetof(AVIOContext,x) 66 #define E AV_OPT_FLAG_ENCODING_PARAM 67 #define D AV_OPT_FLAG_DECODING_PARAM 69 {
"protocol_whitelist",
"List of protocols that are allowed to be used",
OFFSET(protocol_whitelist),
AV_OPT_TYPE_STRING, { .str =
NULL }, 0, 0,
D },
79 #if FF_API_CHILD_CLASS_NEXT 80 .child_class_next = ff_avio_child_class_next,
95 int64_t (*seek)(
void *opaque, int64_t
offset,
int whence))
122 s->
pos = buffer_size;
139 unsigned char *buffer,
145 int64_t (*seek)(
void *opaque, int64_t
offset,
int whence))
260 whence &= ~AVSEEK_FORCE;
272 if (whence != SEEK_CUR && whence != SEEK_SET)
275 if (whence == SEEK_CUR) {
279 if (offset > INT64_MAX - offset1)
294 offset1 = offset -
pos;
301 offset1 <= buffer_size + short_seek) &&
304 (whence != SEEK_END || force)) {
310 }
else if(!s->
write_flag && offset1 < 0 && -offset1 < buffer_size>>1 && s->
seek && offset > 0) {
313 pos -=
FFMIN(buffer_size>>1, pos);
314 if ((res = s->
seek(s->
opaque, pos, SEEK_SET)) < 0)
321 return avio_seek(s, offset, SEEK_SET | force);
329 if ((res = s->
seek(s->
opaque, offset, SEEK_SET)) < 0)
360 if ((size = s->
seek(s->
opaque, -1, SEEK_END)) < 0)
400 avio_write(s, (
const unsigned char *) str, len);
421 av_log(s,
AV_LOG_ERROR,
"Invalid UTF8 sequence in avio_put_str16%s\n", be ?
"be" :
"le");
436 #define PUT_STR16(type, big_endian) \ 437 int avio_put_str16 ## type(AVIOContext *s, const char *str) \ 439 return put_str16(s, str, big_endian); \ 449 avio_wl32(s, (uint32_t)(val & 0xffffffff));
456 avio_wb32(s, (uint32_t)(val & 0xffffffff));
526 #if FF_API_OLD_AVIO_EOF_0 579 }
else if (len < 0) {
653 }
else if (len < 0) {
800 if (c && i < maxlen-1)
802 }
while (c !=
'\n' && c !=
'\r' && c);
829 end = (c ==
'\r' || c ==
'\n' || c ==
'\0');
832 }
while (!end && len <
sizeof(tmp));
871 buflen =
FFMIN(buflen - 1, maxlen);
872 for (i = 0; i < buflen; i++)
876 for (; i < maxlen; i++)
882 #define GET_STR16(type, read) \ 883 int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\ 888 return AVERROR(EINVAL); \ 889 while (ret + 1 < maxlen) {\ 892 GET_UTF16(ch, (ret += 2) <= maxlen ? read(pb) : 0, break;)\ 895 PUT_UTF8(ch, tmp, if (q - buf < buflen - 1) *q++ = tmp;)\ 920 val= (val<<7) + (tmp&127);
928 int buffer_size, max_packet_size;
931 if (max_packet_size) {
932 buffer_size = max_packet_size;
937 if (buffer_size > INT_MAX/2)
948 (int64_t (*)(
void *, int64_t,
int))
ffurl_seek);
965 (*s)->max_packet_size = max_packet_size;
1009 if (buf_size <= s->buf_end - s->
buf_ptr)
1012 buf_size += max_buffer_size - 1;
1018 if (buf_size <= s->buffer_size) {
1026 memcpy(buffer, s->
buf_ptr, filled);
1061 if (buf_size <= s->buffer_size)
1100 int64_t buffer_start;
1102 int overlap, new_size, alloc_size;
1113 if ((buffer_start = s->
pos - buffer_size) > buf_size) {
1118 overlap = buf_size - buffer_start;
1119 new_size = buf_size + buffer_size - overlap;
1122 if (alloc_size > buf_size)
1123 if (!(buf = (*bufp) =
av_realloc_f(buf, 1, alloc_size)))
1126 if (new_size > buf_size) {
1127 memcpy(buf + buf_size, s->
buffer + overlap, buffer_size - overlap);
1128 buf_size = new_size;
1148 const char *whitelist,
const char *blacklist
1224 for(; *strings; strings++)
1225 avio_write(s, (
const unsigned char *)*strings, strlen(*strings));
1236 int64_t timestamp,
int flags)
1248 else if (pos !=
AVERROR(ENOSYS))
1304 new_size = (unsigned)d->
pos + buf_size;
1305 if (new_size < d->
pos || new_size > INT_MAX)
1311 while (new_size > new_allocated_size)
1312 new_allocated_size += new_allocated_size / 2 + 1;
1314 new_allocated_size =
FFMIN(new_allocated_size, INT_MAX);
1323 memcpy(d->
buffer + d->
pos, buf, buf_size);
1332 unsigned char buf1[4];
1349 if (whence == SEEK_CUR)
1351 else if (whence == SEEK_END)
1355 if (offset > INT_MAX)
1364 unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
1366 if (
sizeof(
DynBuffer) + io_buffer_size < io_buffer_size)
1379 (*s)->max_packet_size = max_packet_size;
1390 if (max_packet_size <= 0)
1455 return size - padding;
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
void avio_wl64(AVIOContext *s, uint64_t 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)
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.
int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist, URLContext *parent)
Create an URLContext for accessing to the resource indicated by url, and open it. ...
static void update_checksum(AVIOContext *s)
#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)
Similar to feof() but also returns nonzero on read errors.
#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
void ffio_reset_dyn_buf(AVIOContext *s)
Reset a dynamic buffer.
int is_streamed
true if streamed (no seek possible), default = false
static const AVClass * child_class_iterate(void **iter)
int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
#define AVIO_SEEKABLE_TIME
Seeking by timestamp with avio_seek_time() is possible.
void ffio_fill(AVIOContext *s, int b, int count)
#define AVIO_FLAG_READ
read-only
const char * av_default_item_name(void *ptr)
Return the context name.
unsigned int avio_rl24(AVIOContext *s)
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
int min_packet_size
Try to buffer at least this amount of data before flushing it.
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...
void * opaque
A private pointer, passed to the read/write/seek/...
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
void avio_wb32(AVIOContext *s, unsigned int val)
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Trailer data, which doesn't contain actual content, but only for finalizing the output file...
int avio_accept(AVIOContext *s, AVIOContext **c)
Accept and allocate a client context on a server context.
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.
A point in the output bytestream where the underlying AVIOContext might flush the buffer depending on...
static void fill_buffer(AVIOContext *s)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
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)
Force flushing of buffered data.
int ffio_open_null_buf(AVIOContext **s)
Open a write-only fake memory stream.
URLContext * ffio_geturlcontext(AVIOContext *s)
Return the URLContext associated with the AVIOContext.
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...
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
Public header for CRC hash function implementation.
int64_t bytes_read
Bytes read statistic This field is internal to libavformat and access from outside is not allowed...
#define AVERROR_EOF
End of file.
#define AV_LOG_VERBOSE
Detailed information.
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)
int ffio_open_whitelist(AVIOContext **s, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist)
unsigned long ff_crcEDB88320_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
void avio_print_string_array(AVIOContext *s, const char *strings[])
Write a NULL terminated array of strings to the context.
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.
unsigned int avio_rb24(AVIOContext *s)
const AVIOInterruptCB int_cb
static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
const char * protocol_whitelist
static const AVOption ff_avio_options[]
int ffio_realloc_buf(AVIOContext *s, int buf_size)
Reallocate a given buffer for AVIOContext.
int64_t ff_read_line_to_bprint_overwrite(AVIOContext *s, AVBPrint *bp)
Read a whole line of text from AVIOContext to an AVBPrint buffer overwriting its contents.
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
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...
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)
static int read_packet_wrapper(AVIOContext *s, uint8_t *buf, int size)
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.
unsigned int avio_rl32(AVIOContext *s)
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.
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.
int ffurl_get_short_seek(URLContext *h)
Return the current short seek threshold value for this URL.
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 ffurl_handshake(URLContext *c)
Perform one step of the protocol handshake to accept a new client.
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
void avio_context_free(AVIOContext **ps)
Free the supplied IO context and everything associated with it.
static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
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)
static volatile int checksum
int ffurl_accept(URLContext *s, URLContext **c)
Accept an URLContext c on an URLContext s.
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.
int(* short_seek_get)(void *opaque)
A callback that is used instead of short_seek_threshold.
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'.
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
char * av_strdup(const char *s)
Duplicate a string.
const char * protocol_blacklist
#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.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it be(in the first position) for now.Options-------Then comes the options array.This is what will define the user accessible options.For example
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)
int(* url_read_pause)(URLContext *h, int pause)
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)
void av_vbprintf(AVBPrint *buf, const char *fmt, va_list vl_arg)
Append a formatted string to a print buffer.
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...
#define AVIO_FLAG_DIRECT
Use direct mode.
unsigned int avio_rb16(AVIOContext *s)
int short_seek_threshold
Threshold to favor readahead over seek.
#define PUT_UTF16(val, tmp, PUT_16BIT)
Convert a 32-bit Unicode character to its UTF-16 encoded form (2 or 4 bytes).
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
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
#define flags(name, subs,...)
int ffurl_close(URLContext *h)
const AVClass ffurl_context_class
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
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.
enum AVIODataMarkerType current_type
Internal, not meant to be used from outside of AVIOContext.
int avio_handshake(AVIOContext *c)
Perform one step of the protocol handshake to accept a new client.
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.
const OptionDef options[]
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.
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)
int64_t ff_read_line_to_bprint(AVIOContext *s, AVBPrint *bp)
Read a whole line of text from AVIOContext to an AVBPrint buffer.
unsigned int avio_rb32(AVIOContext *s)
unsigned char * buf_ptr_max
Maximum reached position before a backward seek in the write buffer, used keeping track of already wr...
A point in the output bytestream where a decoder can start decoding (i.e.
static int put_str16(AVIOContext *s, const char *str, const int be)
int eof_reached
true if was unable to read due to error or eof
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)
int avio_read_partial(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
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
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
int ff_get_chomp_line(AVIOContext *s, char *buf, int maxlen)
Same as ff_get_line but strip the white-space characters in the text tail.
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
int avio_r8(AVIOContext *s)
int min_packet_size
if non zero, the stream is packetized with this min packet size
static double val(void *priv, double ch)
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.
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)
int64_t(* url_read_seek)(URLContext *h, int stream_index, int64_t timestamp, int flags)