aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-03-01 23:09:40 +0100
committerMichael Niedermayer <michaelni@gmx.at>2014-03-23 20:31:05 +0100
commit01507eb1f87dcccfe6e0e66cd3ab0a4a973169f1 (patch)
tree580ec8c78bd2ea3f6fe7e1685c3ff77a0bc34c70
parent938ff937100541d0060d4500c153e7459385658a (diff)
downloadffmpeg-01507eb1f87dcccfe6e0e66cd3ab0a4a973169f1.tar.gz
avformat/aviobuf: optimize sequential backward seeking
This reduces the number of protocol seeks Signed-off-by: Michael Niedermayer <michaelni@gmx.at> (cherry picked from commit 9600486d10a9728f1503363334268ecfafa9b0e5) Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavformat/aviobuf.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 18431e7086..95fdf200ef 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -234,9 +234,20 @@ int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
if (s->eof_reached)
return AVERROR_EOF;
s->buf_ptr = s->buf_end + offset - s->pos;
- } else {
+ } else if(!s->write_flag && offset1 < 0 && -offset1 < buffer_size>>1 && s->seek && offset > 0) {
int64_t res;
+ pos -= FFMIN(buffer_size>>1, pos);
+ if ((res = s->seek(s->opaque, pos, SEEK_SET)) < 0)
+ return res;
+ s->buf_end =
+ s->buf_ptr = s->buffer;
+ s->pos = pos;
+ s->eof_reached = 0;
+ fill_buffer(s);
+ return avio_seek(s, offset, SEEK_SET | force);
+ } else {
+ int64_t res;
if (s->write_flag) {
flush_buffer(s);
s->must_flush = 1;