mirror of https://github.com/mpv-player/mpv
demux: invert update_cache() locking
Equivalent, just slightly more convenient for the following change.
This commit is contained in:
parent
20eead1813
commit
27bf978e75
|
@ -2227,9 +2227,9 @@ static bool read_packet(struct demux_internal *in)
|
||||||
bool eof = true;
|
bool eof = true;
|
||||||
if (demux->desc->read_packet && !demux_cancel_test(demux))
|
if (demux->desc->read_packet && !demux_cancel_test(demux))
|
||||||
eof = !demux->desc->read_packet(demux, &pkt);
|
eof = !demux->desc->read_packet(demux, &pkt);
|
||||||
update_cache(in);
|
|
||||||
|
|
||||||
pthread_mutex_lock(&in->lock);
|
pthread_mutex_lock(&in->lock);
|
||||||
|
update_cache(in);
|
||||||
|
|
||||||
if (pkt) {
|
if (pkt) {
|
||||||
assert(pkt->stream >= 0 && pkt->stream < in->num_streams);
|
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
|
return true; // read_packet unlocked, so recheck conditions
|
||||||
}
|
}
|
||||||
if (mp_time_us() >= in->next_cache_update) {
|
if (mp_time_us() >= in->next_cache_update) {
|
||||||
pthread_mutex_unlock(&in->lock);
|
|
||||||
update_cache(in);
|
update_cache(in);
|
||||||
pthread_mutex_lock(&in->lock);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -3075,11 +3073,11 @@ void demux_update(demuxer_t *demuxer, double pts)
|
||||||
assert(demuxer == demuxer->in->d_user);
|
assert(demuxer == demuxer->in->d_user);
|
||||||
struct demux_internal *in = demuxer->in;
|
struct demux_internal *in = demuxer->in;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&in->lock);
|
||||||
|
|
||||||
if (!in->threading)
|
if (!in->threading)
|
||||||
update_cache(in);
|
update_cache(in);
|
||||||
|
|
||||||
pthread_mutex_lock(&in->lock);
|
|
||||||
|
|
||||||
pts = MP_ADD_PTS(pts, -in->ts_offset);
|
pts = MP_ADD_PTS(pts, -in->ts_offset);
|
||||||
|
|
||||||
struct timed_metadata *prev = lookup_timed_metadata(in, in->last_playback_pts);
|
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;
|
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)
|
static void update_cache(struct demux_internal *in)
|
||||||
{
|
{
|
||||||
struct demuxer *demuxer = in->d_thread;
|
struct demuxer *demuxer = in->d_thread;
|
||||||
struct stream *stream = demuxer->stream;
|
struct stream *stream = demuxer->stream;
|
||||||
|
|
||||||
// Don't lock while querying the stream.
|
|
||||||
struct mp_tags *stream_metadata = NULL;
|
struct mp_tags *stream_metadata = NULL;
|
||||||
|
|
||||||
|
// Don't lock while querying the stream.
|
||||||
|
pthread_mutex_unlock(&in->lock);
|
||||||
|
|
||||||
int64_t stream_size = -1;
|
int64_t stream_size = -1;
|
||||||
if (stream) {
|
if (stream) {
|
||||||
stream_size = stream_get_size(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".
|
// The idea is to update as long as there is "activity".
|
||||||
if (in->bytes_per_second)
|
if (in->bytes_per_second)
|
||||||
in->next_cache_update = now + MP_SECOND_US + 1;
|
in->next_cache_update = now + MP_SECOND_US + 1;
|
||||||
|
|
||||||
pthread_mutex_unlock(&in->lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dumper_close(struct demux_internal *in)
|
static void dumper_close(struct demux_internal *in)
|
||||||
|
|
Loading…
Reference in New Issue