summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-01-08 00:14:20 +0100
committerwm4 <wm4@nowhere>2020-01-08 00:16:01 +0100
commitdb9048f21aa955dbd7176d4e8d7245297e97177b (patch)
treec8c602ecc0b50b94a5be18544fd80c657f184b3f
parentd3cef97ad38fb027262a905bd82e1d3d2549aec7 (diff)
downloadmpv-db9048f21aa955dbd7176d4e8d7245297e97177b.tar.bz2
mpv-db9048f21aa955dbd7176d4e8d7245297e97177b.tar.xz
command: add osd-dimensions property
This "bundles" all OSD properties. It also makes some previously Lua-only values available (Lua has mp.get_osd_margins(), unsure if anything uses it). The main intention is actually to allow retrieving all fields in an "atomic" way. (Could introduce a mechanism on the level of the mpv client API to do this, but doing ti ad-hoc all the time like this commit is easier.)
-rw-r--r--DOCS/man/input.rst31
-rw-r--r--player/command.c48
2 files changed, 57 insertions, 22 deletions
diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst
index d6430581a8..75709d1adf 100644
--- a/DOCS/man/input.rst
+++ b/DOCS/man/input.rst
@@ -2177,9 +2177,40 @@ Property list
``overlay-add`` command. It gives you the actual OSD size, which can be
different from the window size in some cases.
+ Alias to ``osd-dimensions/w`` and ``osd-dimensions/h``.
+
``osd-par``
Last known OSD display pixel aspect (can be 0).
+ Alias to ``osd-dimensions/osd-par``.
+
+``osd-dimensions``
+ Last known OSD dimensions.
+
+ Has the following sub-properties (which can be read as ``MPV_FORMAT_NODE``
+ or Lua table with ``mp.get_property_native``):
+
+ ``w``
+ Size of the VO window in OSD render units (usually pixels, but may be
+ scaled pixels with VOs like ``xv``).
+
+ ``h``
+ Size of the VO window in OSD render units,
+
+ ``par``
+ Pixel aspect ratio of the OSD (usually 1).
+
+ ``aspect``
+ Display aspect ratio of the VO window. (Computing from the properties
+ above.)
+
+ ``mt``, ``mb``, ``ml``, ``mr``
+ OSD to video margins (top, bottom, left, right). This describes the
+ area into which the video is rendered.
+
+ Any of these properties may be unavailable or set to dummy values if the
+ VO window is not created or visible.
+
``sub-text``
Return the current subtitle text regardless of sub visibility.
Formatting is stripped. If the subtitle is not text-based
diff --git a/player/command.c b/player/command.c
index f95762395a..dca0d0f589 100644
--- a/player/command.c
+++ b/player/command.c
@@ -2455,28 +2455,31 @@ static int mp_property_vo(void *ctx, struct m_property *p, int action, void *arg
mpctx->video_out ? mpctx->video_out->driver->name : NULL);
}
-static int mp_property_osd_w(void *ctx, struct m_property *prop,
- int action, void *arg)
+static int mp_property_osd_dim(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
MPContext *mpctx = ctx;
struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd);
- return m_property_int_ro(action, arg, vo_res.w);
-}
-static int mp_property_osd_h(void *ctx, struct m_property *prop,
- int action, void *arg)
-{
- MPContext *mpctx = ctx;
- struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd);
- return m_property_int_ro(action, arg, vo_res.h);
-}
+ if (!mpctx->video_out || !mpctx->video_out->config_ok)
+ vo_res = (struct mp_osd_res){0};
-static int mp_property_osd_par(void *ctx, struct m_property *prop,
- int action, void *arg)
-{
- MPContext *mpctx = ctx;
- struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd);
- return m_property_double_ro(action, arg, vo_res.display_par);
+ double aspect = 1.0 * vo_res.w / MPMAX(vo_res.h, 1) /
+ (vo_res.display_par ? vo_res.display_par : 1);
+
+ struct m_sub_property props[] = {
+ {"w", SUB_PROP_DOUBLE(vo_res.w)},
+ {"h", SUB_PROP_DOUBLE(vo_res.h)},
+ {"par", SUB_PROP_DOUBLE(vo_res.display_par)},
+ {"aspect", SUB_PROP_DOUBLE(aspect)},
+ {"mt", SUB_PROP_DOUBLE(vo_res.mt)},
+ {"mb", SUB_PROP_DOUBLE(vo_res.mb)},
+ {"ml", SUB_PROP_DOUBLE(vo_res.ml)},
+ {"mr", SUB_PROP_DOUBLE(vo_res.mr)},
+ {0}
+ };
+
+ return m_property_read_sub(props, action, arg);
}
static int mp_property_osd_sym(void *ctx, struct m_property *prop,
@@ -3398,9 +3401,10 @@ static const struct m_property mp_properties_base[] = {
{"estimated-frame-count", mp_property_frame_count},
{"estimated-frame-number", mp_property_frame_number},
- {"osd-width", mp_property_osd_w},
- {"osd-height", mp_property_osd_h},
- {"osd-par", mp_property_osd_par},
+ {"osd-dimensions", mp_property_osd_dim},
+ M_PROPERTY_ALIAS("osd-width", "osd-dimensions/w"),
+ M_PROPERTY_ALIAS("osd-height", "osd-dimensions/h"),
+ M_PROPERTY_ALIAS("osd-par", "osd-dimensions/par"),
{"osd-sym-cc", mp_property_osd_sym},
{"osd-ass-cc", mp_property_osd_ass},
@@ -3494,7 +3498,7 @@ static const char *const *const mp_event_property_change[] = {
E(MPV_EVENT_VIDEO_RECONFIG, "video-out-params", "video-params",
"video-format", "video-codec", "video-bitrate", "dwidth", "dheight",
"width", "height", "fps", "aspect", "vo-configured", "current-vo",
- "video-aspect", "video-dec-params",
+ "video-aspect", "video-dec-params", "osd-dimensions",
"hwdec", "hwdec-current", "hwdec-interop"),
E(MPV_EVENT_AUDIO_RECONFIG, "audio-format", "audio-codec", "audio-bitrate",
"samplerate", "channels", "audio", "volume", "mute",
@@ -3509,7 +3513,7 @@ static const char *const *const mp_event_property_change[] = {
"demuxer-cache-time", "cache-buffering-state", "cache-speed",
"demuxer-cache-state"),
E(MP_EVENT_WIN_RESIZE, "current-window-scale", "osd-width", "osd-height",
- "osd-par"),
+ "osd-par", "osd-dimensions"),
E(MP_EVENT_WIN_STATE, "window-minimized", "display-names", "display-fps",
"fullscreen", "window-maximized"),
E(MP_EVENT_CHANGE_PLAYLIST, "playlist", "playlist-pos", "playlist-pos-1",