From 7083f88ca8b98aa74dbc9e34d5c5cf6e150cfe0b Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 18 Jul 2014 15:10:28 +0200 Subject: video: don't block when reading video packets Instead of blocking on the demuxer when reading a packet, let packets be read asynchronously. Basically, it polls whether a packet is available, and if not, the playloop goes to sleep until the demuxer thread wakes it up. Note that the player will still block for I/O, because audio is still read synchronously. It's much harder to do the same change for audio (because of the design of the audio decoding path and especially initialization), so audio will have to be done later. --- player/loadfile.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'player/loadfile.c') diff --git a/player/loadfile.c b/player/loadfile.c index e1ffa5d783..9816dbf4cc 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -312,6 +312,21 @@ static struct sh_stream *select_fallback_stream(struct demuxer *d, return best_stream; } +// Called from the demuxer thread if a new packet is available. +static void wakeup_demux(void *pctx) +{ + struct MPContext *mpctx = pctx; + mp_input_wakeup(mpctx->input); +} + +static void enable_demux_thread(struct MPContext *mpctx) +{ + if (mpctx->demuxer && mpctx->opts->demuxer_thread) { + demux_set_wakeup_cb(mpctx->demuxer, wakeup_demux, mpctx); + demux_start_thread(mpctx->demuxer); + } +} + bool timeline_set_part(struct MPContext *mpctx, int i, bool force) { struct timeline_part *p = mpctx->timeline + mpctx->timeline_part; @@ -353,8 +368,7 @@ bool timeline_set_part(struct MPContext *mpctx, int i, bool force) } reselect_demux_streams(mpctx); - if (mpctx->demuxer && mpctx->opts->demuxer_thread) - demux_start_thread(mpctx->demuxer); + enable_demux_thread(mpctx); return true; } @@ -1188,8 +1202,7 @@ goto_reopen_demuxer: ; update_demuxer_properties(mpctx); - if (mpctx->demuxer && opts->demuxer_thread) - demux_start_thread(mpctx->demuxer); + enable_demux_thread(mpctx); if (mpctx->current_track[0][STREAM_VIDEO] && mpctx->current_track[0][STREAM_VIDEO]->attached_picture) -- cgit v1.2.3