From 89e608e16953ddcf3167035c6a4833ca49c29e90 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Wed, 13 Dec 2023 14:38:26 +0100 Subject: [PATCH] vo_gpu_next: add dynamic hook parameters Fixes: https://github.com/haasn/libplacebo/issues/230 Fixes: https://github.com/mpv-player/mpv/issues/8206 --- video/out/vo_gpu_next.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/video/out/vo_gpu_next.c b/video/out/vo_gpu_next.c index c1e1450576..7fc1ff6d60 100644 --- a/video/out/vo_gpu_next.c +++ b/video/out/vo_gpu_next.c @@ -913,6 +913,9 @@ static void update_tm_viz(struct pl_color_map_params *params, params->visualize_hue = M_PI / 4.0; } +static void update_hook_opts_dynamic(struct priv *p, const struct pl_hook *hook, + const struct mp_image *mpi); + static void draw_frame(struct vo *vo, struct vo_frame *frame) { struct priv *p = vo->priv; @@ -1118,6 +1121,10 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame) // temporary memory that is only valid for this `pl_queue_update`. ((uint64_t *) mix.signatures)[i] ^= fp->osd_sync << 48; } + + // Update dynamic hook parameters + for (int i = 0; i < pars->params.num_hooks; i++) + update_hook_opts_dynamic(p, p->hooks[i], frame->current); } // Render frame @@ -2070,6 +2077,28 @@ static void update_lut(struct priv *p, struct user_lut *lut) talloc_free(lutdata.start); } +static void update_hook_opts_dynamic(struct priv *p, const struct pl_hook *hook, + const struct mp_image *mpi) +{ + const struct { const char *name; double value; } opts[] = { + { "PTS", mpi->pts }, + }; + + for (int i = 0; i < hook->num_parameters; i++) { + const struct pl_hook_par *hp = &hook->parameters[i]; + for (int n = 0; n < MP_ARRAY_SIZE(opts); n++) { + if (strcmp(hp->name, opts[n].name) != 0) + continue; + + switch (hp->type) { + case PL_VAR_FLOAT: hp->data->f = opts[n].value; break; + case PL_VAR_SINT: hp->data->i = round(opts[n].value); break; + case PL_VAR_UINT: hp->data->u = round(opts[n].value); break; + } + } + } +} + static void update_hook_opts(struct priv *p, char **opts, const char *shaderpath, const struct pl_hook *hook) {