summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2010-07-17 05:26:30 +0000
committerMartin Storsjö <martin@martin.st>2010-07-17 05:26:30 +0000
commit7939d0edce490589ce66ccfa21dac0e75a2c2f1c (patch)
treea4a13300b27562230314f450fa5f7134cde1933d
parenta58e6ceae087bf24e10d4cfa88c05d9377287539 (diff)
aviobuf: Do short seeks forward by reading and skipping data instead of a proper seek
This improves performance on e.g. seekable http. Originally committed as revision 24280 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavformat/aviobuf.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index d4db268225..f311d51bd2 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -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 @@ 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);