diff options
author | Ben Avison <bavison@riscosopen.org> | 2013-07-31 23:46:08 +0100 |
---|---|---|
committer | popcornmix <popcornmix@gmail.com> | 2013-08-07 21:36:10 +0100 |
commit | 5ce8f2bf354b7adf904ac3e1438915586c5a0bb1 (patch) | |
tree | d906aa9a5554a3731895b4471edcd594548303f7 /lib | |
parent | 60d1fd5587487fe41e910f7d557d490e7a6f79ea (diff) |
[ffmpeg] - backport - avio: Add an internal function for reading without copying
As long as there is enough contiguous data in the avio buffer,
just return a pointer to it instead of copying it to the caller
provided buffer.
Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ffmpeg/libavformat/avio_internal.h | 17 | ||||
-rw-r--r-- | lib/ffmpeg/libavformat/aviobuf.c | 12 |
2 files changed, 29 insertions, 0 deletions
diff --git a/lib/ffmpeg/libavformat/avio_internal.h b/lib/ffmpeg/libavformat/avio_internal.h index cf3676402b..e9ece571b9 100644 --- a/lib/ffmpeg/libavformat/avio_internal.h +++ b/lib/ffmpeg/libavformat/avio_internal.h @@ -38,6 +38,23 @@ int ffio_init_context(AVIOContext *s, /** + * 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. * This reads at most 1 packet. If that is not enough fewer bytes will be * returned. diff --git a/lib/ffmpeg/libavformat/aviobuf.c b/lib/ffmpeg/libavformat/aviobuf.c index 7a73a1791f..465c46d53c 100644 --- a/lib/ffmpeg/libavformat/aviobuf.c +++ b/lib/ffmpeg/libavformat/aviobuf.c @@ -522,6 +522,18 @@ int avio_read(AVIOContext *s, unsigned char *buf, int 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 len; |