From daf1e0d3de03bd424016e2a7520e4e94ece5c0ac Mon Sep 17 00:00:00 2001 From: Ben Avison Date: Wed, 31 Jul 2013 23:46:08 +0100 Subject: avio: Add an internal function for reading without copying MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ö --- libavformat/aviobuf.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libavformat/aviobuf.c') diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index bc89768ef6..07aa88068f 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -490,6 +490,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; -- cgit v1.2.3