summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2023-09-17 21:34:32 -0500
committerDudemanguy <random342@airmail.cc>2023-10-10 19:10:55 +0000
commita899e14bccb667af243f8fce454160e17ae45c2a (patch)
tree77fede3fe581c4cedbe6cf04f456e16937374dfb
parentc82c55b4b9d4015ba79fb36170defb328563cdea (diff)
downloadmpv-a899e14bccb667af243f8fce454160e17ae45c2a.tar.bz2
mpv-a899e14bccb667af243f8fce454160e17ae45c2a.tar.xz
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, 37d6604d70c8c594de2817db26356c4c950ac0fd 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.
-rw-r--r--video/out/drm_common.c8
-rw-r--r--video/out/drm_common.h2
-rw-r--r--video/out/gpu/context.h2
-rw-r--r--video/out/opengl/context_drm_egl.c4
-rw-r--r--video/out/opengl/context_glx.c4
-rw-r--r--video/out/opengl/context_wayland.c4
-rw-r--r--video/out/opengl/context_x11egl.c4
-rw-r--r--video/out/vo.c4
-rw-r--r--video/out/vo.h2
-rw-r--r--video/out/vo_gpu.c6
-rw-r--r--video/out/vo_gpu_next.c6
-rw-r--r--video/out/vo_sdl.c6
-rw-r--r--video/out/vulkan/context_display.c2
-rw-r--r--video/out/vulkan/context_wayland.c4
-rw-r--r--video/out/vulkan/context_xlib.c4
-rw-r--r--video/out/wayland_common.c6
-rw-r--r--video/out/wayland_common.h2
-rw-r--r--video/out/x11_common.c6
-rw-r--r--video/out/x11_common.h2
19 files changed, 39 insertions, 39 deletions
diff --git a/video/out/drm_common.c b/video/out/drm_common.c
index 4f235956ad..dd53793dbb 100644
--- a/video/out/drm_common.c
+++ b/video/out/drm_common.c
@@ -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);
}
}
diff --git a/video/out/drm_common.h b/video/out/drm_common.h
index ac91584899..cadef2019f 100644
--- a/video/out/drm_common.h
+++ b/video/out/drm_common.h
@@ -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);
diff --git a/video/out/gpu/context.h b/video/out/gpu/context.h
index 27d8462f97..6788e6fd89 100644
--- a/video/out/gpu/context.h
+++ b/video/out/gpu/context.h
@@ -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.
diff --git a/video/out/opengl/context_drm_egl.c b/video/out/opengl/context_drm_egl.c
index 5141f2ce2a..16046b1577 100644
--- a/video/out/opengl/context_drm_egl.c
+++ b/video/out/opengl/context_drm_egl.c
@@ -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)
diff --git a/video/out/opengl/context_glx.c b/video/out/opengl/context_glx.c
index 5d22563632..40622245e6 100644
--- a/video/out/opengl/context_glx.c
+++ b/video/out/opengl/context_glx.c
@@ -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 = {
diff --git a/video/out/opengl/context_wayland.c b/video/out/opengl/context_wayland.c
index aa8bb2d921..26c52688d3 100644
--- a/video/out/opengl/context_wayland.c
+++ b/video/out/opengl/context_wayland.c
@@ -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)
diff --git a/video/out/opengl/context_x11egl.c b/video/out/opengl/context_x11egl.c
index a0f710f3ec..3201f298f6 100644
--- a/video/out/opengl/context_x11egl.c
+++ b/video/out/opengl/context_x11egl.c
@@ -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 = {
diff --git a/video/out/vo.c b/video/out/vo.c
index 7b50b90745..4fab586dfd 100644
--- a/video/out/vo.c
+++ b/video/out/vo.c
@@ -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);
diff --git a/video/out/vo.h b/video/out/vo.h
index d67ca5fe51..710bd6e10f 100644
--- a/video/out/vo.h
+++ b/video/out/vo.h
@@ -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.
diff --git a/video/out/vo_gpu.c b/video/out/vo_gpu.c
index 8939561a38..c02e6e730d 100644
--- a/video/out/vo_gpu.c
+++ b/video/out/vo_gpu.c
@@ -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);
}
}
diff --git a/video/out/vo_gpu_next.c b/video/out/vo_gpu_next.c
index 8014f7def1..d5c234f4bb 100644
--- a/video/out/vo_gpu_next.c
+++ b/video/out/vo_gpu_next.c
@@ -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);
}
}
diff --git a/video/out/vo_sdl.c b/video/out/vo_sdl.c
index b5e3d5b041..e101f8d620 100644
--- a/video/out/vo_sdl.c
+++ b/video/out/vo_sdl.c
@@ -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)) {
diff --git a/video/out/vulkan/context_display.c b/video/out/vulkan/context_display.c
index da801dd921..84cef1e8c2 100644
--- a/video/out/vulkan/context_display.c
+++ b/video/out/vulkan/context_display.c
@@ -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
}
diff --git a/video/out/vulkan/context_wayland.c b/video/out/vulkan/context_wayland.c
index 5ca6265a91..761ff5b12c 100644
--- a/video/out/vulkan/context_wayland.c
+++ b/video/out/vulkan/context_wayland.c
@@ -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)
diff --git a/video/out/vulkan/context_xlib.c b/video/out/vulkan/context_xlib.c
index 0c01d56fc9..673dc312b7 100644
--- a/video/out/vulkan/context_xlib.c
+++ b/video/out/vulkan/context_xlib.c
@@ -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 = {
diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c
index 47dc4d9605..04b7d1f7bd 100644
--- a/video/out/wayland_common.c
+++ b/video/out/wayland_common.c
@@ -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);
}
diff --git a/video/out/wayland_common.h b/video/out/wayland_common.h
index 3b4366318c..060583278e 100644
--- a/video/out/wayland_common.h
+++ b/video/out/wayland_common.h
@@ -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);
diff --git a/video/out/x11_common.c b/video/out/x11_common.c
index 78e4778ecf..be5002b068 100644
--- a/video/out/x11_common.c
+++ b/video/out/x11_common.c
@@ -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);
diff --git a/video/out/x11_common.h b/video/out/x11_common.h
index 0ea0cd574f..d4409f14e8 100644
--- a/video/out/x11_common.h
+++ b/video/out/x11_common.h
@@ -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);