summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-02-16 23:39:07 +0100
committerwm4 <wm4@nowhere>2020-02-16 23:43:13 +0100
commit27bf978e757346068d24cdf5f4ee9a7e0aec7d2a (patch)
treed814dd9009b227b4cae91543484dbcc68c55a60e /demux
parent20eead18130fd460d8e9eff50ce14afd3646faab (diff)
downloadmpv-27bf978e757346068d24cdf5f4ee9a7e0aec7d2a.tar.bz2
mpv-27bf978e757346068d24cdf5f4ee9a7e0aec7d2a.tar.xz
demux: invert update_cache() locking
Equivalent, just slightly more convenient for the following change.
Diffstat (limited to 'demux')
-rw-r--r--demux/demux.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/demux/demux.c b/demux/demux.c
index 88c4374e63..8d30a5ddac 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -2227,9 +2227,9 @@ static bool read_packet(struct demux_internal *in)
bool eof = true;
if (demux->desc->read_packet && !demux_cancel_test(demux))
eof = !demux->desc->read_packet(demux, &pkt);
- update_cache(in);
pthread_mutex_lock(&in->lock);
+ update_cache(in);
if (pkt) {
assert(pkt->stream >= 0 && pkt->stream < in->num_streams);
@@ -2508,9 +2508,7 @@ static bool thread_work(struct demux_internal *in)
return true; // read_packet unlocked, so recheck conditions
}
if (mp_time_us() >= in->next_cache_update) {
- pthread_mutex_unlock(&in->lock);
update_cache(in);
- pthread_mutex_lock(&in->lock);
return true;
}
return false;
@@ -3075,11 +3073,11 @@ void demux_update(demuxer_t *demuxer, double pts)
assert(demuxer == demuxer->in->d_user);
struct demux_internal *in = demuxer->in;
+ pthread_mutex_lock(&in->lock);
+
if (!in->threading)
update_cache(in);
- pthread_mutex_lock(&in->lock);
-
pts = MP_ADD_PTS(pts, -in->ts_offset);
struct timed_metadata *prev = lookup_timed_metadata(in, in->last_playback_pts);
@@ -4021,15 +4019,17 @@ static void update_bytes_read(struct demux_internal *in)
in->byte_level_seeks += new_seeks;
}
-// must be called not locked
+// must be called locked, temporarily unlocks
static void update_cache(struct demux_internal *in)
{
struct demuxer *demuxer = in->d_thread;
struct stream *stream = demuxer->stream;
- // Don't lock while querying the stream.
struct mp_tags *stream_metadata = NULL;
+ // 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);
@@ -4059,8 +4059,6 @@ static void update_cache(struct demux_internal *in)
// The idea is to update as long as there is "activity".
if (in->bytes_per_second)
in->next_cache_update = now + MP_SECOND_US + 1;
-
- pthread_mutex_unlock(&in->lock);
}
static void dumper_close(struct demux_internal *in)