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).
This commit is contained in:
wm4 2020-03-21 14:14:04 +01:00
parent c892eff929
commit 2de783125b
1 changed files with 5 additions and 1 deletions

View File

@ -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)