diff options
author | wm4 <wm4@nowhere> | 2019-01-05 08:52:41 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2019-09-19 20:37:04 +0200 |
commit | 390772b58f180c3e74f370bdfc7521de1d6822b4 (patch) | |
tree | 6212c77ae9e5aa60816501b2089ae4df3e210534 /demux/demux.c | |
parent | ebf183eeec388d87a19415ee01970b21b6ef6832 (diff) | |
download | mpv-390772b58f180c3e74f370bdfc7521de1d6822b4.tar.bz2 mpv-390772b58f180c3e74f370bdfc7521de1d6822b4.tar.xz |
demux_timeline: report network speed of slave connections
demux_timeline doesn't do any transport accesses itself. The slave
demuxers do this (these will actually access the stream layer and
perform e.g. network accesses). As a consequence, demux_timeline always
reported 0 bytes read, and network speed display didn't work.
Fix this by awkwardly reporting the amount of read bytes upwards. This
is not very nice, and requires explicit calls whenever the slave "might"
have read data.
Due to the way the reporting is done, it only works if the slaves do not
run demuxer threads, which makes things even less nice. (Fortunately
they don't anyway, because it would be a waste of resources.) Some
identifiers contain the word "hack" as a warning.
Some of the stupidity comes from the fact that demux.c itself resets the
stats randomly in order to calculate the bytes_per_second value, which
is useless for a slave, but of course is still done, because demux.c
itself is not aware of whether it's on the slave or top-level layer.
Unfortunately, this must do.
In theory, the demuxer thread/cache layer should be separated from
demuxer implementations. This would get rid of all the awkwardness and
nonsense. For example, the only threading involved would be the caching
layer, completely separate from demuxers themselves. It'd be the only
thing calculates speed rates for the player frontend, too (instead of
doing it for each demuxer, even if unused).
Diffstat (limited to 'demux/demux.c')
-rw-r--r-- | demux/demux.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/demux/demux.c b/demux/demux.c index 2c252e6c20..6908bbcca5 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -220,6 +220,7 @@ struct demux_internal { bool enable_recording; struct mp_recorder *recorder; int64_t slave_unbuffered_read_bytes; // value repoted from demuxer impl. + int64_t hack_unbuffered_read_bytes; // for demux_get_bytes_read_hack() int64_t cache_unbuffered_read_bytes; // for demux_reader_state.bytes_per_second }; @@ -3049,6 +3050,7 @@ static void update_bytes_read(struct demux_internal *in) in->slave_unbuffered_read_bytes = 0; in->cache_unbuffered_read_bytes += new; + in->hack_unbuffered_read_bytes += new; } // must be called not locked @@ -3105,6 +3107,23 @@ void demux_report_unbuffered_read_bytes(struct demuxer *demuxer, int64_t new) in->slave_unbuffered_read_bytes += new; } +// Return bytes read since last query. It's a hack because it works only if +// the demuxer thread is disabled. +int64_t demux_get_bytes_read_hack(struct demuxer *demuxer) +{ + struct demux_internal *in = demuxer->in; + + // Required because demuxer==in->d_user, and we access in->d_thread. + // Locking won't solve this, because we also need to access struct stream. + assert(!in->threading); + + update_bytes_read(in); + + int64_t res = in->hack_unbuffered_read_bytes; + in->hack_unbuffered_read_bytes = 0; + return res; +} + void demux_get_bitrate_stats(struct demuxer *demuxer, double *rates) { struct demux_internal *in = demuxer->in; |