mirror of https://github.com/mpv-player/mpv
core: make WAKEUP_PERIOD overridable by the vo
This is better than having just the operating system type decide the wakeup period, as e.g. when compiling for Win32/cygwin, a wakeup period of 0.5 would work perfectly fine. Instead, the default wakeup period is now only decided by availability of a working select() system call (which is the case on cygwin but not mingw and MSVC) AND a vo that can provide an event file descriptor or a similar hack (vo_corevideo). vos that cannot do either need polling for event handling and now can set the wakeup period to 0.02 in the vo code.
This commit is contained in:
parent
51c98619c8
commit
7d0a20954f
|
@ -36,17 +36,8 @@
|
|||
|
||||
#if defined(__MINGW32__) || defined(__CYGWIN__)
|
||||
#include <windows.h>
|
||||
// No proper file descriptor event handling; keep waking up to poll input
|
||||
#define WAKEUP_PERIOD 0.02
|
||||
#else
|
||||
/* Even if we can immediately wake up in response to most input events,
|
||||
* there are some timers which are not registered to the event loop
|
||||
* and need to be checked periodically (like automatic mouse cursor hiding).
|
||||
* OSD content updates behave similarly. Also some uncommon input devices
|
||||
* may not have proper FD event support.
|
||||
*/
|
||||
#define WAKEUP_PERIOD 0.5
|
||||
#endif
|
||||
#define WAKEUP_PERIOD 0.5
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -3140,6 +3131,28 @@ static void handle_pause_on_low_cache(struct MPContext *mpctx)
|
|||
}
|
||||
}
|
||||
|
||||
static double get_wakeup_period(struct MPContext *mpctx)
|
||||
{
|
||||
/* Even if we can immediately wake up in response to most input events,
|
||||
* there are some timers which are not registered to the event loop
|
||||
* and need to be checked periodically (like automatic mouse cursor hiding).
|
||||
* OSD content updates behave similarly. Also some uncommon input devices
|
||||
* may not have proper FD event support.
|
||||
*/
|
||||
double sleeptime = WAKEUP_PERIOD;
|
||||
|
||||
#ifndef HAVE_POSIX_SELECT
|
||||
// No proper file descriptor event handling; keep waking up to poll input
|
||||
sleeptime = FFMIN(sleeptime, 0.02);
|
||||
#endif
|
||||
|
||||
if (mpctx->video_out)
|
||||
if (mpctx->video_out->wakeup_period > 0)
|
||||
sleeptime = FFMIN(sleeptime, mpctx->video_out->wakeup_period);
|
||||
|
||||
return sleeptime;
|
||||
}
|
||||
|
||||
static void run_playloop(struct MPContext *mpctx)
|
||||
{
|
||||
struct MPOpts *opts = &mpctx->opts;
|
||||
|
@ -3147,7 +3160,7 @@ static void run_playloop(struct MPContext *mpctx)
|
|||
bool audio_left = false, video_left = false;
|
||||
double endpts = get_play_end_pts(mpctx);
|
||||
bool end_is_chapter = false;
|
||||
double sleeptime = WAKEUP_PERIOD;
|
||||
double sleeptime = get_wakeup_period(mpctx);
|
||||
bool was_restart = mpctx->restart_playback;
|
||||
|
||||
#ifdef CONFIG_ENCODING
|
||||
|
@ -3808,7 +3821,8 @@ static void idle_loop(struct MPContext *mpctx)
|
|||
{
|
||||
uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_VO);
|
||||
mp_cmd_t *cmd;
|
||||
while (!(cmd = mp_input_get_cmd(mpctx->input, WAKEUP_PERIOD * 1000,
|
||||
while (!(cmd = mp_input_get_cmd(mpctx->input,
|
||||
get_wakeup_period(mpctx) * 1000,
|
||||
false)));
|
||||
run_command(mpctx, cmd);
|
||||
mp_cmd_free(cmd);
|
||||
|
|
|
@ -241,6 +241,7 @@ struct vo {
|
|||
bool want_redraw; // visible frame wrong (window resize), needs refresh
|
||||
bool redrawing; // between redrawing frame and flipping it
|
||||
bool hasframe; // >= 1 frame has been drawn, so redraw is possible
|
||||
double wakeup_period; // if > 0, this sets the maximum wakeup period for event polling
|
||||
|
||||
double flip_queue_offset; // queue flip events at most this much in advance
|
||||
|
||||
|
|
|
@ -666,6 +666,9 @@ int vo_w32_init(struct vo *vo)
|
|||
if (WinID >= 0)
|
||||
EnableWindow(w32->window, 0);
|
||||
|
||||
// we don't have proper event handling
|
||||
vo->wakeup_period = 0.02;
|
||||
|
||||
updateScreenProperties(vo);
|
||||
|
||||
mp_msg(MSGT_VO, MSGL_V, "vo: win32: running at %dx%d with depth %d\n",
|
||||
|
|
Loading…
Reference in New Issue