Skip to content

Commit

Permalink
player/video: update dynamic hdr params
Browse files Browse the repository at this point in the history
  • Loading branch information
kasper93 committed Nov 3, 2024
1 parent b057af0 commit 1948fdb
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions player/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions video/mp_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions video/mp_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions video/out/vo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions video/out/vo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions video/out/vo_gpu_next.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 1948fdb

Please sign in to comment.