summaryrefslogtreecommitdiffstats
path: root/demux/demux.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-01-05 08:49:31 +0100
committerwm4 <wm4@nowhere>2019-09-19 20:37:04 +0200
commitebf183eeec388d87a19415ee01970b21b6ef6832 (patch)
tree7b3d5ced6d0d590c46679eafa6c4b42dbb16ee27 /demux/demux.c
parent27a09b42ed04ecd73215ab73ac146b287c3fd9f6 (diff)
downloadmpv-ebf183eeec388d87a19415ee01970b21b6ef6832.tar.bz2
mpv-ebf183eeec388d87a19415ee01970b21b6ef6832.tar.xz
demux: slightly cleanup network speed reporting
It was an ugly hack, and the next commit will make it even uglier. Slightly reduce the ugliness to prevent death of too many brain cells, though it's still an ugly hack. The cleanup is really minor, but I guess the following commit would be much worse otherwise. In particular, this commit checks accesses (instead of having a public field with evil access rules), which should avoid misunderstandings and incorrect use. Strictly speaking, the added field is redundant, but the next commit complicates it a bit.
Diffstat (limited to 'demux/demux.c')
-rw-r--r--demux/demux.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/demux/demux.c b/demux/demux.c
index 042e3a9cc3..2c252e6c20 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -219,6 +219,8 @@ struct demux_internal {
// -- Access from demuxer thread only
bool enable_recording;
struct mp_recorder *recorder;
+ int64_t slave_unbuffered_read_bytes; // value repoted from demuxer impl.
+ int64_t cache_unbuffered_read_bytes; // for demux_reader_state.bytes_per_second
};
// A continuous range of cached packets for all enabled streams.
@@ -3036,6 +3038,19 @@ void demux_block_reading(struct demuxer *demuxer, bool block)
pthread_mutex_unlock(&in->lock);
}
+static void update_bytes_read(struct demux_internal *in)
+{
+ struct demuxer *demuxer = in->d_thread;
+ struct stream *stream = demuxer->stream;
+
+ int64_t new = stream->total_unbuffered_read_bytes +
+ in->slave_unbuffered_read_bytes;
+ stream->total_unbuffered_read_bytes = 0;
+ in->slave_unbuffered_read_bytes = 0;
+
+ in->cache_unbuffered_read_bytes += new;
+}
+
// must be called not locked
static void update_cache(struct demux_internal *in)
{
@@ -3048,8 +3063,7 @@ static void update_cache(struct demux_internal *in)
int64_t stream_size = stream_get_size(stream);
stream_control(stream, STREAM_CTRL_GET_METADATA, &stream_metadata);
- demuxer->total_unbuffered_read_bytes += stream->total_unbuffered_read_bytes;
- stream->total_unbuffered_read_bytes = 0;
+ update_bytes_read(in);
pthread_mutex_lock(&in->lock);
@@ -3068,8 +3082,8 @@ static void update_cache(struct demux_internal *in)
int64_t now = mp_time_us();
int64_t diff = now - in->last_speed_query;
if (diff >= MP_SECOND_US) {
- uint64_t bytes = demuxer->total_unbuffered_read_bytes;
- demuxer->total_unbuffered_read_bytes = 0;
+ 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);
}
@@ -3080,6 +3094,17 @@ static void update_cache(struct demux_internal *in)
pthread_mutex_unlock(&in->lock);
}
+// Used by demuxers to report the amount of transferred bytes. This is for
+// streams which circumvent demuxer->stream (stream statistics are handled by
+// demux.c itself).
+void demux_report_unbuffered_read_bytes(struct demuxer *demuxer, int64_t new)
+{
+ struct demux_internal *in = demuxer->in;
+ assert(demuxer == in->d_thread);
+
+ in->slave_unbuffered_read_bytes += new;
+}
+
void demux_get_bitrate_stats(struct demuxer *demuxer, double *rates)
{
struct demux_internal *in = demuxer->in;