diff options
author | Reinhard Tartler <siretart@tauware.de> | 2010-07-19 19:51:29 +0000 |
---|---|---|
committer | Reinhard Tartler <siretart@tauware.de> | 2010-07-19 19:51:29 +0000 |
commit | 93883b0c390c87f85e6f7bb22428d789bc842b12 (patch) | |
tree | 3bdcbf99b0159dd42cef5db355293d38829fc034 | |
parent | 61eb1655141747886fe2fc43036e0402015777f3 (diff) | |
download | ffmpeg-93883b0c390c87f85e6f7bb22428d789bc842b12.tar.gz |
aviobuf: Do short seeks forward by reading and skipping data instead of a proper seek
This improves performance on e.g. seekable http.
backport r24280 by mstorsjo
Originally committed as revision 24335 to svn://svn.ffmpeg.org/ffmpeg/branches/0.6
-rw-r--r-- | libavformat/aviobuf.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 8684903464..2a2fb78169 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -27,6 +27,13 @@ #define IO_BUFFER_SIZE 32768 +/** + * Do seeks within this distance ahead of the current buffer by skipping + * data instead of calling the protocol seek function, for seekable + * protocols. + */ +#define SHORT_SEEK_THRESHOLD 4096 + static void fill_buffer(ByteIOContext *s); #if LIBAVFORMAT_VERSION_MAJOR >= 53 static int url_resetbuf(ByteIOContext *s, int flags); @@ -152,7 +159,9 @@ int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence) offset1 >= 0 && offset1 <= (s->buf_end - s->buffer)) { /* can do the seek inside the buffer */ s->buf_ptr = s->buffer + offset1; - } else if(s->is_streamed && !s->write_flag && offset1 >= 0 && + } else if ((s->is_streamed || + offset1 <= s->buf_end + SHORT_SEEK_THRESHOLD - s->buffer) && + !s->write_flag && offset1 >= 0 && (whence != SEEK_END || force)) { while(s->pos < offset && !s->eof_reached) fill_buffer(s); |