From 63d112746dcf6b3c62b16cfd50eee91128054ce2 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 22 Jul 2015 23:30:05 +0200 Subject: 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. --- stream/cache.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/stream/cache.c b/stream/cache.c index fc4b2761da..da8c841571 100644 --- a/stream/cache.c +++ b/stream/cache.c @@ -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); -- cgit v1.2.3