summaryrefslogtreecommitdiffstats
path: root/demux/demux.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-05-18 00:01:07 +0200
committerwm4 <wm4@nowhere>2019-09-19 20:37:04 +0200
commitfc4e59f25d68aeb2a33333b01f12a440d5b737e6 (patch)
treee320e989b009549788b6d21cce3a05aaac31d6a0 /demux/demux.c
parent62e9a0c5f6be63c4cbe6387cbd3419fe19e98b74 (diff)
downloadmpv-fc4e59f25d68aeb2a33333b01f12a440d5b737e6.tar.bz2
mpv-fc4e59f25d68aeb2a33333b01f12a440d5b737e6.tar.xz
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.
Diffstat (limited to 'demux/demux.c')
-rw-r--r--demux/demux.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/demux/demux.c b/demux/demux.c
index 3022469b18..ae6d3a96f6 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -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)