vo: change vo->driver->wait_events to nanoseconds

In many cases, this is purely cosmetic because poll still only accepts
microseconds. There's still a gain here however since
pthread_cond_timedwait can take a realtime ts now.

Additionally, 37d6604d70 changed the value
added to timeout_ms in X11 and Wayland to ensure that it would never be
0 and rounded up. This was both incomplete, several other parts of the
player have this same problem like drm, and not really needed. Instead
the MPCLAMP is just adjusted to have a min of 1.
This commit is contained in:
Dudemanguy 2023-09-17 21:34:32 -05:00
parent c82c55b4b9
commit a899e14bcc
19 changed files with 39 additions and 39 deletions

View File

@ -1304,15 +1304,15 @@ void vo_drm_set_monitor_par(struct vo *vo)
MP_VERBOSE(drm, "Monitor pixel aspect: %g\n", vo->monitor_par);
}
void vo_drm_wait_events(struct vo *vo, int64_t until_time_us)
void vo_drm_wait_events(struct vo *vo, int64_t until_time_ns)
{
struct vo_drm_state *drm = vo->drm;
if (drm->vt_switcher_active) {
int64_t wait_us = until_time_us - mp_time_us();
int timeout_ms = MPCLAMP((wait_us + 500) / 1000, 0, 10000);
int64_t wait_ns = until_time_ns - mp_time_ns();
int timeout_ms = MPCLAMP(wait_ns / 1e6, 1, 10000);
vt_switcher_poll(&drm->vt_switcher, timeout_ms);
} else {
vo_wait_default(vo, until_time_us);
vo_wait_default(vo, until_time_ns);
}
}

View File

@ -114,7 +114,7 @@ double vo_drm_get_display_fps(struct vo_drm_state *drm);
void vo_drm_get_vsync(struct vo *vo, struct vo_vsync_info *info);
void vo_drm_set_monitor_par(struct vo *vo);
void vo_drm_uninit(struct vo *vo);
void vo_drm_wait_events(struct vo *vo, int64_t until_time_us);
void vo_drm_wait_events(struct vo *vo, int64_t until_time_ns);
void vo_drm_wait_on_flip(struct vo_drm_state *drm);
void vo_drm_wakeup(struct vo *vo);

View File

@ -48,7 +48,7 @@ struct ra_ctx_fns {
// These behave exactly like vo_driver.wakeup/wait_events. They are
// optional.
void (*wakeup)(struct ra_ctx *ctx);
void (*wait_events)(struct ra_ctx *ctx, int64_t until_time_us);
void (*wait_events)(struct ra_ctx *ctx, int64_t until_time_ns);
void (*update_render_opts)(struct ra_ctx *ctx);
// Initialize/destroy the 'struct ra' and possibly the underlying VO backend.

View File

@ -734,9 +734,9 @@ static int drm_egl_control(struct ra_ctx *ctx, int *events, int request,
return ret;
}
static void drm_egl_wait_events(struct ra_ctx *ctx, int64_t until_time_us)
static void drm_egl_wait_events(struct ra_ctx *ctx, int64_t until_time_ns)
{
vo_drm_wait_events(ctx->vo, until_time_us);
vo_drm_wait_events(ctx->vo, until_time_ns);
}
static void drm_egl_wakeup(struct ra_ctx *ctx)

View File

@ -334,9 +334,9 @@ static void glx_wakeup(struct ra_ctx *ctx)
vo_x11_wakeup(ctx->vo);
}
static void glx_wait_events(struct ra_ctx *ctx, int64_t until_time_us)
static void glx_wait_events(struct ra_ctx *ctx, int64_t until_time_ns)
{
vo_x11_wait_events(ctx->vo, until_time_us);
vo_x11_wait_events(ctx->vo, until_time_ns);
}
const struct ra_ctx_fns ra_ctx_glx = {

View File

@ -198,9 +198,9 @@ static void wayland_egl_wakeup(struct ra_ctx *ctx)
vo_wayland_wakeup(ctx->vo);
}
static void wayland_egl_wait_events(struct ra_ctx *ctx, int64_t until_time_us)
static void wayland_egl_wait_events(struct ra_ctx *ctx, int64_t until_time_ns)
{
vo_wayland_wait_events(ctx->vo, until_time_us);
vo_wayland_wait_events(ctx->vo, until_time_ns);
}
static void wayland_egl_update_render_opts(struct ra_ctx *ctx)

View File

@ -208,9 +208,9 @@ static void mpegl_wakeup(struct ra_ctx *ctx)
vo_x11_wakeup(ctx->vo);
}
static void mpegl_wait_events(struct ra_ctx *ctx, int64_t until_time_us)
static void mpegl_wait_events(struct ra_ctx *ctx, int64_t until_time_ns)
{
vo_x11_wait_events(ctx->vo, until_time_us);
vo_x11_wait_events(ctx->vo, until_time_ns);
}
const struct ra_ctx_fns ra_ctx_x11_egl = {

View File

@ -717,7 +717,7 @@ void vo_wait_default(struct vo *vo, int64_t until_time)
pthread_mutex_lock(&in->lock);
if (!in->need_wakeup) {
struct timespec ts = mp_time_us_to_realtime(until_time);
struct timespec ts = mp_time_ns_to_realtime(until_time);
pthread_cond_timedwait(&in->wakeup, &in->lock, &ts);
}
pthread_mutex_unlock(&in->lock);
@ -1064,7 +1064,7 @@ static void *vo_thread(void *ptr)
stats_event(in->stats, "iterations");
vo->driver->control(vo, VOCTRL_CHECK_EVENTS, NULL);
bool working = render_frame(vo);
int64_t now = mp_time_us();
int64_t now = mp_time_ns();
int64_t wait_until = now + (working ? 0 : (int64_t)1e9);
pthread_mutex_lock(&in->lock);

View File

@ -414,7 +414,7 @@ struct vo_driver {
* immediately.
*/
void (*wakeup)(struct vo *vo);
void (*wait_events)(struct vo *vo, int64_t until_time_us);
void (*wait_events)(struct vo *vo, int64_t until_time_ns);
/*
* Closes driver. Should restore the original state of the system.

View File

@ -252,13 +252,13 @@ static void wakeup(struct vo *vo)
p->ctx->fns->wakeup(p->ctx);
}
static void wait_events(struct vo *vo, int64_t until_time_us)
static void wait_events(struct vo *vo, int64_t until_time_ns)
{
struct gpu_priv *p = vo->priv;
if (p->ctx && p->ctx->fns->wait_events) {
p->ctx->fns->wait_events(p->ctx, until_time_us);
p->ctx->fns->wait_events(p->ctx, until_time_ns);
} else {
vo_wait_default(vo, until_time_us);
vo_wait_default(vo, until_time_ns);
}
}

View File

@ -1578,13 +1578,13 @@ static void wakeup(struct vo *vo)
p->ra_ctx->fns->wakeup(p->ra_ctx);
}
static void wait_events(struct vo *vo, int64_t until_time_us)
static void wait_events(struct vo *vo, int64_t until_time_ns)
{
struct priv *p = vo->priv;
if (p->ra_ctx && p->ra_ctx->fns->wait_events) {
p->ra_ctx->fns->wait_events(p->ra_ctx, until_time_us);
p->ra_ctx->fns->wait_events(p->ra_ctx, until_time_ns);
} else {
vo_wait_default(vo, until_time_us);
vo_wait_default(vo, until_time_ns);
}
}

View File

@ -520,10 +520,10 @@ static void wakeup(struct vo *vo)
SDL_PushEvent(&event);
}
static void wait_events(struct vo *vo, int64_t until_time_us)
static void wait_events(struct vo *vo, int64_t until_time_ns)
{
int64_t wait_us = until_time_us - mp_time_us();
int timeout_ms = MPCLAMP((wait_us + 500) / 1000, 0, 10000);
int64_t wait_ns = until_time_ns - mp_time_ns();
int timeout_ms = MPCLAMP(wait_ns / 1e6, 1, 10000);
SDL_Event ev;
while (SDL_WaitEventTimeout(&ev, timeout_ms)) {

View File

@ -474,7 +474,7 @@ static void display_wakeup(struct ra_ctx *ctx)
// TODO
}
static void display_wait_events(struct ra_ctx *ctx, int64_t until_time_us)
static void display_wait_events(struct ra_ctx *ctx, int64_t until_time_ns)
{
// TODO
}

View File

@ -142,9 +142,9 @@ static void wayland_vk_wakeup(struct ra_ctx *ctx)
vo_wayland_wakeup(ctx->vo);
}
static void wayland_vk_wait_events(struct ra_ctx *ctx, int64_t until_time_us)
static void wayland_vk_wait_events(struct ra_ctx *ctx, int64_t until_time_ns)
{
vo_wayland_wait_events(ctx->vo, until_time_us);
vo_wayland_wait_events(ctx->vo, until_time_ns);
}
static void wayland_vk_update_render_opts(struct ra_ctx *ctx)

View File

@ -126,9 +126,9 @@ static void xlib_wakeup(struct ra_ctx *ctx)
vo_x11_wakeup(ctx->vo);
}
static void xlib_wait_events(struct ra_ctx *ctx, int64_t until_time_us)
static void xlib_wait_events(struct ra_ctx *ctx, int64_t until_time_ns)
{
vo_x11_wait_events(ctx->vo, until_time_us);
vo_x11_wait_events(ctx->vo, until_time_ns);
}
const struct ra_ctx_fns ra_ctx_vulkan_xlib = {

View File

@ -2604,12 +2604,12 @@ void vo_wayland_wait_frame(struct vo_wayland_state *wl)
wl->timeout_count = 0;
}
void vo_wayland_wait_events(struct vo *vo, int64_t until_time_us)
void vo_wayland_wait_events(struct vo *vo, int64_t until_time_ns)
{
struct vo_wayland_state *wl = vo->wl;
int64_t wait_us = until_time_us - mp_time_us();
int timeout_ms = MPCLAMP((wait_us + 999) / 1000, 0, 10000);
int64_t wait_ns = until_time_ns - mp_time_ns();
int timeout_ms = MPCLAMP(wait_ns / 1e6, 1, 10000);
wayland_dispatch_events(wl, 2, timeout_ms);
}

View File

@ -180,7 +180,7 @@ void vo_wayland_handle_fractional_scale(struct vo_wayland_state *wl);
void vo_wayland_set_opaque_region(struct vo_wayland_state *wl, bool alpha);
void vo_wayland_sync_swap(struct vo_wayland_state *wl);
void vo_wayland_uninit(struct vo *vo);
void vo_wayland_wait_events(struct vo *vo, int64_t until_time_us);
void vo_wayland_wait_events(struct vo *vo, int64_t until_time_ns);
void vo_wayland_wait_frame(struct vo_wayland_state *wl);
void vo_wayland_wakeup(struct vo *vo);

View File

@ -2168,7 +2168,7 @@ void vo_x11_wakeup(struct vo *vo)
(void)write(x11->wakeup_pipe[1], &(char){0}, 1);
}
void vo_x11_wait_events(struct vo *vo, int64_t until_time_us)
void vo_x11_wait_events(struct vo *vo, int64_t until_time_ns)
{
struct vo_x11_state *x11 = vo->x11;
@ -2176,8 +2176,8 @@ void vo_x11_wait_events(struct vo *vo, int64_t until_time_us)
{ .fd = x11->event_fd, .events = POLLIN },
{ .fd = x11->wakeup_pipe[0], .events = POLLIN },
};
int64_t wait_us = until_time_us - mp_time_us();
int timeout_ms = MPCLAMP((wait_us + 999) / 1000, 0, 10000);
int64_t wait_ns = until_time_ns - mp_time_ns();
int timeout_ms = MPCLAMP(wait_ns / 1e6, 1, 10000);
poll(fds, 2, timeout_ms);

View File

@ -154,7 +154,7 @@ int vo_x11_control(struct vo *vo, int *events, int request, void *arg);
void vo_x11_present(struct vo *vo);
void vo_x11_sync_swap(struct vo *vo);
void vo_x11_wakeup(struct vo *vo);
void vo_x11_wait_events(struct vo *vo, int64_t until_time_us);
void vo_x11_wait_events(struct vo *vo, int64_t until_time_ns);
void vo_x11_silence_xlib(int dir);