summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-02-16 23:49:42 +0100
committerwm4 <wm4@nowhere>2020-02-16 23:49:42 +0100
commit1a54339705f71a67faa900a125d467ba121e3ae6 (patch)
tree25e8436dbac7edfaedbbe7abd8f5812ed0ccf875 /demux
parent27bf978e757346068d24cdf5f4ee9a7e0aec7d2a (diff)
downloadmpv-1a54339705f71a67faa900a125d467ba121e3ae6.tar.bz2
mpv-1a54339705f71a67faa900a125d467ba121e3ae6.tar.xz
demux: only query stream size at most once per second
Instead of every packet. Doing it every packet led to the performance regression mentioned in the fstat() commit. This should now be over, but out of being careful, don't query the file size that often. This is only used for user interface things, so this should not cause any problems. For the sake of leaving the code compact, abuse another thing that is updated only every second (speed statistics).
Diffstat (limited to 'demux')
-rw-r--r--demux/demux.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/demux/demux.c b/demux/demux.c
index 8d30a5ddac..8360b9069f 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -4027,12 +4027,17 @@ static void update_cache(struct demux_internal *in)
struct mp_tags *stream_metadata = NULL;
+ int64_t now = mp_time_us();
+ int64_t diff = now - in->last_speed_query;
+ bool do_update = diff >= MP_SECOND_US;
+
// Don't lock while querying the stream.
pthread_mutex_unlock(&in->lock);
int64_t stream_size = -1;
if (stream) {
- stream_size = stream_get_size(stream);
+ if (do_update)
+ stream_size = stream_get_size(stream);
stream_control(stream, STREAM_CTRL_GET_METADATA, &stream_metadata);
}
@@ -4040,7 +4045,8 @@ static void update_cache(struct demux_internal *in)
pthread_mutex_lock(&in->lock);
- in->stream_size = stream_size;
+ if (do_update)
+ in->stream_size = stream_size;
if (stream_metadata) {
add_timed_metadata(in, stream_metadata, NULL, MP_NOPTS_VALUE);
talloc_free(stream_metadata);
@@ -4048,9 +4054,7 @@ static void update_cache(struct demux_internal *in)
in->next_cache_update = INT64_MAX;
- int64_t now = mp_time_us();
- int64_t diff = now - in->last_speed_query;
- if (diff >= MP_SECOND_US) {
+ if (do_update) {
uint64_t bytes = in->cache_unbuffered_read_bytes;
in->cache_unbuffered_read_bytes = 0;
in->last_speed_query = now;