From da3bfc96e90001175c59aeed442b1eff05bfc18a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Thu, 31 Aug 2023 16:59:14 +0200 Subject: [PATCH] vo: add video-target-params property --- DOCS/interface-changes.rst | 1 + DOCS/man/input.rst | 5 +++++ player/command.c | 19 ++++++++++++++++++- video/out/vo.c | 14 ++++++++++++++ video/out/vo.h | 2 ++ 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/DOCS/interface-changes.rst b/DOCS/interface-changes.rst index 13f8cf20ef..146ed0f6b0 100644 --- a/DOCS/interface-changes.rst +++ b/DOCS/interface-changes.rst @@ -61,6 +61,7 @@ Interface changes - remove `--alpha` and reintroduce `--background` option for better control over blending alpha components into specific background types - add `--border-background` option + - add `video-target-params` property --- mpv 0.37.0 --- - `--save-position-on-quit` and its associated commands now store state files in %LOCALAPPDATA% instead of %APPDATA% directory by default on Windows. diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index aa9f9af35a..1a829c0d5e 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -2647,6 +2647,11 @@ Property list Has the same sub-properties as ``video-params``. +``video-target-params`` + Same as ``video-params``, but with the target properties that VO outputs to. + + Has the same sub-properties as ``video-params``. + ``video-frame-info`` Approximate information of the current frame. Note that if any of these are used on OSD, the information might be off by a few frames due to OSD diff --git a/player/command.c b/player/command.c index 29ece5b7fb..2f479a5a14 100644 --- a/player/command.c +++ b/player/command.c @@ -2439,6 +2439,22 @@ static int mp_property_vo_imgparams(void *ctx, struct m_property *prop, return property_imgparams(&p, action, arg); } +static int mp_property_tgt_imgparams(void *ctx, struct m_property *prop, + int action, void *arg) +{ + MPContext *mpctx = ctx; + struct vo *vo = mpctx->video_out; + if (!mpctx->video_out) + return M_PROPERTY_UNAVAILABLE; + + int valid = m_property_read_sub_validate(ctx, prop, action, arg); + if (valid != M_PROPERTY_VALID) + return valid; + + struct mp_image_params p = vo_get_target_params(vo); + return property_imgparams(&p, action, arg); +} + static int mp_property_dec_imgparams(void *ctx, struct m_property *prop, int action, void *arg) { @@ -3965,6 +3981,7 @@ static const struct m_property mp_properties_base[] = { {"current-ao", mp_property_ao}, // Video + {"video-target-params", mp_property_tgt_imgparams}, {"video-out-params", mp_property_vo_imgparams}, {"video-dec-params", mp_property_dec_imgparams}, {"video-params", mp_property_vd_imgparams}, @@ -4107,7 +4124,7 @@ static const char *const *const mp_event_property_change[] = { "decoder-frame-drop-count", "frame-drop-count", "video-frame-info", "vf-metadata", "af-metadata", "sub-start", "sub-end", "secondary-sub-start", "secondary-sub-end", "video-out-params", "video-dec-params", "video-params", - "deinterlace-active"), + "deinterlace-active", "video-target-params"), E(MP_EVENT_DURATION_UPDATE, "duration"), E(MPV_EVENT_VIDEO_RECONFIG, "video-out-params", "video-params", "video-format", "video-codec", "video-bitrate", "dwidth", "dheight", diff --git a/video/out/vo.c b/video/out/vo.c index 08a0a9f88b..319e2c07fb 100644 --- a/video/out/vo.c +++ b/video/out/vo.c @@ -614,6 +614,10 @@ static void run_reconfig(void *p) mp_mutex_unlock(&vo->params_mutex); } + mp_mutex_lock(&vo->params_mutex); + talloc_free(vo->target_params); + vo->target_params = NULL; + mp_mutex_unlock(&vo->params_mutex); mp_mutex_lock(&in->lock); talloc_free(in->current_frame); in->current_frame = NULL; @@ -1480,3 +1484,13 @@ struct mp_image_params vo_get_current_params(struct vo *vo) mp_mutex_unlock(&vo->params_mutex); return p; } + +struct mp_image_params vo_get_target_params(struct vo *vo) +{ + struct mp_image_params p = {0}; + mp_mutex_lock(&vo->params_mutex); + if (vo->target_params) + p = *vo->target_params; + mp_mutex_unlock(&vo->params_mutex); + return p; +} diff --git a/video/out/vo.h b/video/out/vo.h index 3879d024e7..3deee0d3a7 100644 --- a/video/out/vo.h +++ b/video/out/vo.h @@ -481,6 +481,7 @@ struct vo { // generic getter is protected by params_mutex. mp_mutex params_mutex; struct mp_image_params *params; // Configured parameters (changed in vo_reconfig) + struct mp_image_params *target_params; // Target display parameters // --- The following fields can be accessed only by the VO thread, or from // anywhere _if_ the VO thread is suspended (use vo->dispatch). @@ -554,5 +555,6 @@ void vo_get_src_dst_rects(struct vo *vo, struct mp_rect *out_src, struct vo_frame *vo_frame_ref(struct vo_frame *frame); struct mp_image_params vo_get_current_params(struct vo *vo); +struct mp_image_params vo_get_target_params(struct vo *vo); #endif /* MPLAYER_VIDEO_OUT_H */