From 1948fdb191fc366a5bc08935bc3d60f239313ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sat, 12 Oct 2024 03:58:20 +0200 Subject: [PATCH] player/video: update dynamic hdr params --- player/video.c | 5 +++++ video/mp_image.c | 15 +++++++++++++++ video/mp_image.h | 3 +++ video/out/vo.c | 2 ++ video/out/vo.h | 2 ++ video/out/vo_gpu_next.c | 3 +-- 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/player/video.c b/player/video.c index ee2da584cc8d6..2291379c85539 100644 --- a/player/video.c +++ b/player/video.c @@ -1192,6 +1192,11 @@ void write_video(struct MPContext *mpctx) goto error; } mp_notify(mpctx, MPV_EVENT_VIDEO_RECONFIG, NULL); + } else { + // Update parameters that don't require reconfiguring the VO. + mp_mutex_lock(&vo->params_mutex); + mp_image_params_update_dynamic(vo->params, p, vo->has_peak_detect_values); + mp_mutex_unlock(&vo->params_mutex); } mpctx->time_frame -= get_relative_time(mpctx); diff --git a/video/mp_image.c b/video/mp_image.c index 83fa7e9ea6c8b..bf53ef09399e7 100644 --- a/video/mp_image.c +++ b/video/mp_image.c @@ -851,6 +851,21 @@ bool mp_image_params_static_equal(const struct mp_image_params *p1, return mp_image_params_equal(&a, &b); } +void mp_image_params_update_dynamic(struct mp_image_params *dst, + const struct mp_image_params *src, + bool has_peak_detect_values) +{ + dst->repr.dovi = src->repr.dovi; + // Don't overwrite peak-detected HDR metadata if available. + float max_pq_y = dst->color.hdr.max_pq_y; + float avg_pq_y = dst->color.hdr.avg_pq_y; + dst->color.hdr = src->color.hdr; + if (has_peak_detect_values) { + dst->color.hdr.max_pq_y = max_pq_y; + dst->color.hdr.avg_pq_y = avg_pq_y; + } +} + // Restore color system, transfer, and primaries to their original values // before dovi mapping. void mp_image_params_restore_dovi_mapping(struct mp_image_params *params) diff --git a/video/mp_image.h b/video/mp_image.h index 2208deb26d282..1064b36207361 100644 --- a/video/mp_image.h +++ b/video/mp_image.h @@ -182,6 +182,9 @@ bool mp_image_params_equal(const struct mp_image_params *p1, const struct mp_image_params *p2); bool mp_image_params_static_equal(const struct mp_image_params *p1, const struct mp_image_params *p2); +void mp_image_params_update_dynamic(struct mp_image_params *dst, + const struct mp_image_params *src, + bool has_peak_detect_values); void mp_image_params_restore_dovi_mapping(struct mp_image_params *params); void mp_image_params_get_dsize(const struct mp_image_params *p, diff --git a/video/out/vo.c b/video/out/vo.c index db29690950cc1..7c1e121212f34 100644 --- a/video/out/vo.c +++ b/video/out/vo.c @@ -597,6 +597,7 @@ static void run_reconfig(void *p) mp_mutex_lock(&vo->params_mutex); talloc_free(vo->params); vo->params = talloc_dup(vo, params); + vo->has_peak_detect_values = false; mp_mutex_unlock(&vo->params_mutex); if (vo->driver->reconfig2) { @@ -611,6 +612,7 @@ static void run_reconfig(void *p) mp_mutex_lock(&vo->params_mutex); talloc_free(vo->params); vo->params = NULL; + vo->has_peak_detect_values = false; mp_mutex_unlock(&vo->params_mutex); } diff --git a/video/out/vo.h b/video/out/vo.h index 3afbd6ea21b23..059d12c6d6342 100644 --- a/video/out/vo.h +++ b/video/out/vo.h @@ -486,6 +486,8 @@ struct vo { mp_mutex params_mutex; // Configured parameters (changed in vo_reconfig) struct mp_image_params *params; + // Whether the VO sets the max_pq_y/avg_pq_y fields on draw_frame. + bool has_peak_detect_values; // Target display parameters (VO is responsible for re-/setting) struct mp_image_params *target_params; diff --git a/video/out/vo_gpu_next.c b/video/out/vo_gpu_next.c index 00d8c5c65bf66..8f00011adfc19 100644 --- a/video/out/vo_gpu_next.c +++ b/video/out/vo_gpu_next.c @@ -1149,9 +1149,8 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame) vo->target_params = &p->target_params; if (vo->params) { - vo->params->color.hdr = ref_frame.color.hdr; // Augment metadata with peak detection max_pq_y / avg_pq_y - pl_renderer_get_hdr_metadata(p->rr, &vo->params->color.hdr); + vo->has_peak_detect_values = pl_renderer_get_hdr_metadata(p->rr, &vo->params->color.hdr); } mp_mutex_unlock(&vo->params_mutex);