mirror of https://github.com/mpv-player/mpv
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.)
This commit is contained in:
parent
f806e268c6
commit
cd7ec016e7
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue