From 7893ab5a7ebab3bd04571105b55a6e4486134821 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 7 Jul 2019 03:34:24 +0200 Subject: 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.) --- demux/demux.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/demux/demux.c b/demux/demux.c index 967b5c9310..2056c12d11 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -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; -- cgit v1.2.3