summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-03-21 14:14:04 +0100
committerwm4 <wm4@nowhere>2020-03-21 19:32:50 +0100
commit2de783125b29d42193258f885396a21598f1dde1 (patch)
treec79d31282fbc35eabd26b088c9b44218fadbe5ff
parentc892eff9299e364012eeae351ead3a40f1070ae1 (diff)
downloadmpv-2de783125b29d42193258f885396a21598f1dde1.tar.bz2
mpv-2de783125b29d42193258f885396a21598f1dde1.tar.xz
demux: average reported download speed some more
Currently, this reported the number of received bytes per second. Improve this slightly by averaging over 2 seconds (but still updating every second).
-rw-r--r--demux/demux.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/demux/demux.c b/demux/demux.c
index 478029b35a..1922f68397 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -272,6 +272,7 @@ struct demux_internal {
// Cached state.
int64_t stream_size;
int64_t last_speed_query;
+ double speed_query_prev_sample;
uint64_t bytes_per_second;
int64_t next_cache_update;
@@ -4108,7 +4109,10 @@ static void update_cache(struct demux_internal *in)
uint64_t bytes = in->cache_unbuffered_read_bytes;
in->cache_unbuffered_read_bytes = 0;
in->last_speed_query = now;
- in->bytes_per_second = bytes / (diff / (double)MP_SECOND_US);
+ double speed = bytes / (diff / (double)MP_SECOND_US);
+ in->bytes_per_second = 0.5 * in->speed_query_prev_sample +
+ 0.5 * speed;
+ in->speed_query_prev_sample = speed;
}
// The idea is to update as long as there is "activity".
if (in->bytes_per_second)