1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-17 04:15:13 +00:00

cache: fix backbuffer logic

Currently, this is perfectly equivalent, because back_size is hardcoded
to buffer_size/2. But this fixes the logic for the case the back_size
can be configured freely.
This commit is contained in:
wm4 2015-07-22 23:30:05 +02:00
parent aeb99f2718
commit 63d112746d

View File

@ -215,11 +215,12 @@ static bool cache_fill(struct priv *s)
// number of buffer bytes which should be preserved in backwards direction
int64_t back = MPCLAMP(read - s->min_filepos, 0, s->back_size);
// limit maximum readahead to half the total buffer size, to ensure that
// we don't stall the network when starting a file (not reading new data
// by preserving the backbuffer) - unless the whole file fits in the cache
// limit maximum readahead so that the backbuffer space is reserved, even
// if the backbuffer is not used. limit it to ensure that we don't stall the
// network when starting a file, or we wouldn't download new data until we
// get new free space again. (unless everything fits in the cache.)
if (s->stream_size > s->buffer_size)
back = MPMAX(back, s->buffer_size / 2);
back = MPMAX(back, s->back_size);
// number of buffer bytes that are valid and can be read
int64_t newb = FFMAX(s->max_filepos - read, 0);