demux: minor simplification for backward cache size option

Always set max_bytes_bw to 0 if seekable cache is disabled, instead at
the place of its use. This is the only use of it, so the commit should
not change any behavior.

(Alternatively, this could drop the max_bytes_bw variable, use the
option directly, and keep the old code that resets it on use of the
cache is disabled.)
This commit is contained in:
wm4 2019-07-07 03:34:24 +02:00
parent 5c0a626dee
commit 7893ab5a7e
1 changed files with 4 additions and 2 deletions

View File

@ -2189,14 +2189,13 @@ static void prune_old_packets(struct demux_internal *in)
// It's not clear what the ideal way to prune old packets is. For now, we
// prune the oldest packet runs, as long as the total cache amount is too
// big.
size_t max_bytes = in->seekable_cache ? in->max_bytes_bw : 0;
while (1) {
uint64_t fw_bytes = 0;
for (int n = 0; n < in->num_streams; n++) {
struct demux_stream *ds = in->streams[n]->ds;
fw_bytes += get_foward_buffered_bytes(ds);
}
uint64_t max_avail = max_bytes;
uint64_t max_avail = in->max_bytes_bw;
// Backward cache (if enabled at all) can use unused forward cache.
// Still leave 1 byte free, so the read_packet logic doesn't get stuck.
if (max_avail && in->max_bytes > (fw_bytes + 1))
@ -2370,6 +2369,9 @@ static void update_opts(struct demux_internal *in)
in->seekable_cache = seekable == 1;
in->using_network_cache_opts = is_streaming && use_cache;
if (!in->seekable_cache)
in->max_bytes_bw = 0;
if (!in->can_cache) {
in->seekable_cache = false;
in->min_secs = 0;