diff options
author | wm4 <wm4@nowhere> | 2014-08-12 23:02:08 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-08-12 23:24:08 +0200 |
commit | df58e822377af0a3802bba862de80eafaea732cb (patch) | |
tree | 05a5bfc611612c4397bdaec4c9127c537498bcec /player/playloop.c | |
parent | a1be3cf147e18a49c88c613d65478ede9676a744 (diff) | |
download | mpv-df58e822377af0a3802bba862de80eafaea732cb.tar.bz2 mpv-df58e822377af0a3802bba862de80eafaea732cb.tar.xz |
video: move display and timing to a separate thread
The VO is run inside its own thread. It also does most of video timing.
The playloop hands the image data and a realtime timestamp to the VO,
and the VO does the rest.
In particular, this allows the playloop to do other things, instead of
blocking for video redraw. But if anything accesses the VO during video
timing, it will block.
This also fixes vo_sdl.c event handling; but that is only a side-effect,
since reimplementing the broken way would require more effort.
Also drop --softsleep. In theory, this option helps if the kernel's
sleeping mechanism is too inaccurate for video timing. In practice, I
haven't ever encountered a situation where it helps, and it just burns
CPU cycles. On the other hand it's probably actively harmful, because
it prevents the libavcodec decoder threads from doing real work.
Side note:
Originally, I intended that multiple frames can be queued to the VO. But
this is not done, due to problems with OSD and other certain features.
OSD in particular is simply designed in a way that it can be neither
timed nor copied, so you do have to render it into the video frame
before you can draw the next frame. (Subtitles have no such restriction.
sd_lavc was even updated to fix this.) It seems the right solution to
queuing multiple VO frames is rendering on VO-backed framebuffers, like
vo_vdpau.c does. This requires VO driver support, and is out of scope
of this commit.
As consequence, the VO has a queue size of 1. The existing video queue
is just needed to compute frame duration, and will be moved out in the
next commit.
Diffstat (limited to 'player/playloop.c')
-rw-r--r-- | player/playloop.c | 28 |
1 files changed, 3 insertions, 25 deletions
diff --git a/player/playloop.c b/player/playloop.c index 361b9284af..b96ba2caa2 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -516,8 +516,7 @@ static void handle_osd_redraw(struct MPContext *mpctx) // Don't redraw immediately during a seek (makes it significantly slower). if (mp_time_sec() - mpctx->start_timestamp < 0.1) return; - bool want_redraw = vo_get_want_redraw(mpctx->video_out) | - osd_query_and_reset_want_redraw(mpctx->osd); + bool want_redraw = osd_query_and_reset_want_redraw(mpctx->osd); if (!want_redraw) return; vo_redraw(mpctx->video_out); @@ -806,22 +805,6 @@ static void handle_dummy_ticks(struct MPContext *mpctx) } } -static double get_wakeup_period(struct MPContext *mpctx) -{ - double sleeptime = 100.0; // infinite for all practical purposes - -#if !HAVE_POSIX_SELECT - // No proper file descriptor event handling; keep waking up to poll input - sleeptime = MPMIN(sleeptime, 0.02); -#endif - - if (mpctx->video_out) - if (mpctx->video_out->wakeup_period > 0) - sleeptime = MPMIN(sleeptime, mpctx->video_out->wakeup_period); - - return sleeptime; -} - void run_playloop(struct MPContext *mpctx) { struct MPOpts *opts = mpctx->opts; @@ -851,9 +834,6 @@ void run_playloop(struct MPContext *mpctx) endpts = end; } - if (mpctx->video_out) - vo_check_events(mpctx->video_out); - handle_cursor_autohide(mpctx); handle_heartbeat_cmd(mpctx); @@ -943,7 +923,7 @@ void run_playloop(struct MPContext *mpctx) mp_input_get_cmd(mpctx->input, mpctx->sleeptime * 1000, true); MP_STATS(mpctx, "end sleep"); } - mpctx->sleeptime = get_wakeup_period(mpctx); + mpctx->sleeptime = 100.0; // infinite for all practical purposes handle_pause_on_low_cache(mpctx); @@ -982,13 +962,11 @@ void idle_loop(struct MPContext *mpctx) uninit |= INITIALIZED_VO; uninit_player(mpctx, uninit); handle_force_window(mpctx, false); - if (mpctx->video_out) - vo_check_events(mpctx->video_out); update_osd_msg(mpctx); handle_osd_redraw(mpctx); mp_cmd_t *cmd = mp_input_get_cmd(mpctx->input, mpctx->sleeptime * 1000, false); - mpctx->sleeptime = get_wakeup_period(mpctx); + mpctx->sleeptime = 100.0; if (cmd) run_command(mpctx, cmd); mp_cmd_free(cmd); |