# HG changeset patch # User mstorsjo # Date 1279344390 0 # Node ID 68c7733519cac678b4e750ae25429ef9e83f9187 # Parent e3af32f5ee3e02570928a7e8cef3018ee54283a4 aviobuf: Do short seeks forward by reading and skipping data instead of a proper seek This improves performance on e.g. seekable http. diff -r e3af32f5ee3e -r 68c7733519ca aviobuf.c --- a/aviobuf.c Sat Jul 17 05:08:01 2010 +0000 +++ b/aviobuf.c Sat Jul 17 05:26:30 2010 +0000 @@ -28,6 +28,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); @@ -153,7 +160,9 @@ 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);