demux: cleaner mutex usage

The demuxer layer can start a thread to decouple the rest of the player
from blocking I/O (such as network accesses). But this particular
function does not support running with the thread enabled. The mutex use
within it is only since thread_work() may temporarily unlock the mutex,
and unlocking an unlocked mutex is not allowed. Most of the rest of the
code still does proper locking, even if it's pointless and effectively
single-threaded.

To make this look slightly cleaner, extend the mutex around the rest of
the code (like threaded code would have to do). This is mostly a
cosmetic change.
This commit is contained in:
wm4 2019-05-18 00:01:07 +02:00
parent 62e9a0c5f6
commit fc4e59f25d
1 changed files with 6 additions and 5 deletions

View File

@ -2003,26 +2003,27 @@ int demux_read_packet_async(struct sh_stream *sh, struct demux_packet **out_pkt)
struct demux_packet *demux_read_any_packet(struct demuxer *demuxer)
{
struct demux_internal *in = demuxer->in;
pthread_mutex_lock(&in->lock);
assert(!in->threading); // doesn't work with threading
struct demux_packet *out_pkt = NULL;
bool read_more = true;
while (read_more && !in->blocked) {
bool all_eof = true;
for (int n = 0; n < in->num_streams; n++) {
in->reading = true; // force read_packet() to read
struct demux_packet *out_pkt = NULL;
int r = dequeue_packet(in->streams[n]->ds, &out_pkt);
if (r > 0)
return out_pkt;
goto done;
if (r == 0)
all_eof = false;
}
// retry after calling this
pthread_mutex_lock(&in->lock); // lock only because thread_work unlocks
read_more = thread_work(in);
read_more &= !all_eof;
pthread_mutex_unlock(&in->lock);
}
return NULL;
done:
pthread_mutex_unlock(&in->lock);
return out_pkt;
}
void demuxer_help(struct mp_log *log)