diff options
author | wm4 <wm4@nowhere> | 2013-08-22 18:27:31 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-08-22 19:14:26 +0200 |
commit | cd7ec016e79c5e521c80045c6cf04fedbe6e64fc (patch) | |
tree | 36d954a4a0af9488c4fde7f5b9e3ea4dfbca67a2 /stream | |
parent | f806e268c6c3a76f65b1282219e16fcdfb80a9b5 (diff) | |
download | mpv-cd7ec016e79c5e521c80045c6cf04fedbe6e64fc.tar.bz2 mpv-cd7ec016e79c5e521c80045c6cf04fedbe6e64fc.tar.xz |
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.)
Diffstat (limited to 'stream')
-rw-r--r-- | stream/stream.c | 15 |
1 files changed, 12 insertions, 3 deletions
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; } |