From cd7ec016e79c5e521c80045c6cf04fedbe6e64fc Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 22 Aug 2013 18:27:31 +0200 Subject: stream: allow potentially faster skipping Instead of always skipping in STREAM_BUFFER_SIZE blocks, allow an arbitrary size. This allows - in theory - faster forward seeking in pipes. (Maybe not a very significant change, but it reduces the number of things that depend on STREAM_BUFFER_SIZE for no good reason. Though we still use that value as minimum read size.) --- stream/stream.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'stream') diff --git a/stream/stream.c b/stream/stream.c index 3687dc75b0..b17b7fc19a 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -37,6 +37,7 @@ #include "config.h" +#include "mpvcore/mp_common.h" #include "mpvcore/bstr.h" #include "mpvcore/mp_msg.h" #include "osdep/timer.h" @@ -421,15 +422,23 @@ eof_out: return len; } -int stream_fill_buffer(stream_t *s) +static int stream_fill_buffer_by(stream_t *s, int64_t len) { - int len = s->sector_size ? s->sector_size : STREAM_BUFFER_SIZE; + len = MPMIN(len, s->read_chunk); + len = MPMAX(len, STREAM_BUFFER_SIZE); + if (s->sector_size) + len = s->sector_size; len = stream_read_unbuffered(s, s->buffer, len); s->buf_pos = 0; s->buf_len = len; return s->buf_len; } +int stream_fill_buffer(stream_t *s) +{ + return stream_fill_buffer_by(s, STREAM_BUFFER_SIZE); +} + // Read between 1..buf_size bytes of data, return how much data has been read. // Return 0 on EOF, error, of if buf_size was 0. int stream_read_partial(stream_t *s, char *buf, int buf_size) @@ -520,7 +529,7 @@ static int stream_skip_read(struct stream *s, int64_t len) while (len > 0) { int x = s->buf_len - s->buf_pos; if (x == 0) { - if (!stream_fill_buffer(s)) + if (!stream_fill_buffer_by(s, len)) return 0; // EOF x = s->buf_len - s->buf_pos; } -- cgit v1.2.3