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)