Commit 8878aef0 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit 'daf1e0d3'

* commit 'daf1e0d3':
  avio: Add an internal function for reading without copying
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 7ed002d7 daf1e0d3
...@@ -37,6 +37,23 @@ int ffio_init_context(AVIOContext *s, ...@@ -37,6 +37,23 @@ int ffio_init_context(AVIOContext *s,
int64_t (*seek)(void *opaque, int64_t offset, int whence)); int64_t (*seek)(void *opaque, int64_t offset, int whence));
/**
* Read size bytes from AVIOContext, returning a pointer.
* Note that the data pointed at by the returned pointer is only
* valid until the next call that references the same IO context.
* @param s IO context
* @param buf pointer to buffer into which to assemble the requested
* data if it is not available in contiguous addresses in the
* underlying buffer
* @param size number of bytes requested
* @param data address at which to store pointer: this will be a
* a direct pointer into the underlying buffer if the requested
* number of bytes are available at contiguous addresses, otherwise
* will be a copy of buf
* @return number of bytes read or AVERROR
*/
int ffio_read_indirect(AVIOContext *s, unsigned char *buf, int size, unsigned char **data);
/** /**
* Read size bytes from AVIOContext into buf. * Read size bytes from AVIOContext into buf.
* This reads at most 1 packet. If that is not enough fewer bytes will be * This reads at most 1 packet. If that is not enough fewer bytes will be
......
...@@ -525,6 +525,18 @@ int avio_read(AVIOContext *s, unsigned char *buf, int size) ...@@ -525,6 +525,18 @@ int avio_read(AVIOContext *s, unsigned char *buf, int size)
return size1 - size; return size1 - size;
} }
int ffio_read_indirect(AVIOContext *s, unsigned char *buf, int size, unsigned char **data)
{
if (s->buf_end - s->buf_ptr >= size && !s->write_flag) {
*data = s->buf_ptr;
s->buf_ptr += size;
return size;
} else {
*data = buf;
return avio_read(s, buf, size);
}
}
int ffio_read_partial(AVIOContext *s, unsigned char *buf, int size) int ffio_read_partial(AVIOContext *s, unsigned char *buf, int size)
{ {
int len; int len;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment