demux: invert update_cache() locking

Equivalent, just slightly more convenient for the following change.
This commit is contained in:
wm4 2020-02-16 23:39:07 +01:00
parent 20eead1813
commit 27bf978e75
1 changed files with 7 additions and 9 deletions

View File

@ -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)