summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas Haas <git@nand.wakku.to>2016-06-08 11:39:31 +0200
committerwm4 <wm4@nowhere>2016-06-08 22:11:38 +0200
commitff37d7efeca2a53819104039348dfbe39c4aca98 (patch)
tree148e64f210ca031cd0194d7c435cd5b8da1f0336
parent54c48bd80120a3085e6d23f7cf6124b0657436e7 (diff)
downloadmpv-ff37d7efeca2a53819104039348dfbe39c4aca98.tar.bz2
mpv-ff37d7efeca2a53819104039348dfbe39c4aca98.tar.xz
vo_opengl: refactor performance data properties
Instead of having 9 different properties, requiring 18 different VOCTRLs to read them all, they are now exposed as a single property. This is not only cleaner (since they're all together) but also allows querying all 9 of them with only a single VOCTRL (by using mp.get_property_native). (The extra factor of 2 was due to an extra query being needed to get the type, which is now also unnecessary) This makes it much easier to access performance metrics from within a lua script, and also makes it easier to just show a readable, formatted version via show-text.
-rw-r--r--DOCS/man/input.rst62
-rw-r--r--options/m_property.h2
-rw-r--r--player/command.c77
3 files changed, 74 insertions, 67 deletions
diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst
index 89bb41c046..d58f2dc4d5 100644
--- a/DOCS/man/input.rst
+++ b/DOCS/man/input.rst
@@ -894,30 +894,6 @@ Property list
.. note:: This is only an estimate. (It's computed from two unreliable
quantities: fps and possibly rounded timestamps.)
-``render-time-last``
- Time needed to render the last frame in microseconds. Not implemented by
- all VOs.
-
-``render-time-avg``
- Average of ``render-time-last`` over the last few frames. (The exact
- averaging time is variable, but it should generally be a few seconds)
-
-``render-time-peak``
- Peak (maximum) of ``render-time-last`` over the last few frames.
-
-``present-time-last``, ``present-time-avg``, ``present-time-peak``
- Analogous to ``render-time-last`` etc. but measures the time needed to
- draw a rendered frame to the screen. Not implemented by all VOs.
-
- (This is separate from ``render-time-last`` because VOs may interpolate,
- deinterlace or otherwise mix multiple source frames into a single output
- frame)
-
-``upload-time-last``, ``upload-time-avg``, ``upload-time-peak``
- Analogous to ``render-time-last`` etc. but measures the time needed to
- upload a frame from system memory to a GPU texture. Not implemented by all
- VOs.
-
``path``
Full path of the currently played file. Usually this is exactly the same
string you pass on the mpv command line or the ``loadfile`` command, even
@@ -1961,6 +1937,44 @@ Property list
whether the video window is visible. If the ``--force-window`` option is
used, this is usually always returns ``yes``.
+``vo-performance``
+ Some video output performance metrics. Not implemented by all VOs. This has
+ a number of sup-properties, of the form ``vo-performance/<metric>-<value>``,
+ all of them in milliseconds.
+
+ ``<metric>`` refers to one of:
+
+ ``upload``
+ Time needed to make the frame available to the GPU (if necessary).
+ ``render``
+ Time needed to perform all necessary video postprocessing and rendering
+ passes (if necessary).
+ ``present``
+ Time needed to present a rendered frame on-screen.
+
+ When a step is unnecessary or skipped, it will have the value 0.
+
+ ``<value>`` refers to one of:
+
+ ``last``
+ Last measured value.
+ ``avg``
+ Average over a fixed number of past samples. (The exact timeframe
+ varies, but it should generally be a handful of seconds)
+ ``peak``
+ The peak (highest value) within this averaging range.
+
+ When querying the property with the client API using ``MPV_FORMAT_NODE``,
+ or with Lua ``mp.get_property_native``, this will return a mpv_node with
+ the following contents:
+
+ ::
+
+ MPV_FORMAT_NODE_MAP
+ "<metric>-<value>" MPV_FORMAT_INT64
+
+ (One entry for each ``<metric>`` and ``<value>`` combination)
+
``video-bitrate``, ``audio-bitrate``, ``sub-bitrate``
Bitrate values calculated on the packet level. This works by dividing the
bit size of all packets between two keyframes by their presentation
diff --git a/options/m_property.h b/options/m_property.h
index 93a4a73578..42fe1c7ecf 100644
--- a/options/m_property.h
+++ b/options/m_property.h
@@ -184,6 +184,8 @@ struct m_sub_property {
// Convenience macros which can be used as part of a sub_property entry.
#define SUB_PROP_INT(i) \
.type = {.type = CONF_TYPE_INT}, .value = {.int_ = (i)}
+#define SUB_PROP_INT64(i) \
+ .type = {.type = CONF_TYPE_INT64}, .value = {.int64 = (i)}
#define SUB_PROP_STR(s) \
.type = {.type = CONF_TYPE_STRING}, .value = {.string = (char *)(s)}
#define SUB_PROP_FLOAT(f) \
diff --git a/player/command.c b/player/command.c
index 5a8af686fe..52c2a849a1 100644
--- a/player/command.c
+++ b/player/command.c
@@ -2381,39 +2381,6 @@ static int panscan_property_helper(void *ctx, struct m_property *prop,
return r;
}
-// Properties retrieved through VOCTRL_PERFORMANCE_DATA
-static int perfdata_property_helper(void *ctx, struct m_property *prop,
- int action, void *arg)
-{
- MPContext *mpctx = ctx;
- if (!mpctx->video_out)
- return M_PROPERTY_UNAVAILABLE;
-
- struct voctrl_performance_data data = {0};
- if (vo_control(mpctx->video_out, VOCTRL_PERFORMANCE_DATA, &data) <= 0)
- return M_PROPERTY_UNAVAILABLE;
-
- // Figure out the right field based on the name. This string
- // match should never fail (based on the hard-coded property names)
- struct bstr name = bstr0(prop->name), prefix, field;
- bstr_split_tok(name, "-", &prefix, &name);
- bstr_split_tok(name, "-", &name, &field);
-
- // No need to have a failure case or fallthrough since these checks are all
- // mutually exclusive and will never fail (based on the hard-coded names)
- struct voctrl_performance_entry e = {0};
- if (bstrcmp0(prefix, "upload") == 0) e = data.upload;
- if (bstrcmp0(prefix, "render") == 0) e = data.render;
- if (bstrcmp0(prefix, "present") == 0) e = data.present;
-
- uint64_t val = 0;
- if (bstrcmp0(field, "last") == 0) val = e.last;
- if (bstrcmp0(field, "avg") == 0) val = e.avg;
- if (bstrcmp0(field, "peak") == 0) val = e.peak;
-
- return m_property_int64_ro(action, arg, val);
-}
-
/// Helper to set vo flags.
/** \ingroup PropertyImplHelper
*/
@@ -2820,6 +2787,39 @@ static int mp_property_vo_configured(void *ctx, struct m_property *prop,
mpctx->video_out && mpctx->video_out->config_ok);
}
+static int mp_property_vo_performance(void *ctx, struct m_property *prop,
+ int action, void *arg)
+{
+ MPContext *mpctx = ctx;
+ if (!mpctx->video_out)
+ return M_PROPERTY_UNAVAILABLE;
+
+ // Return the type right away if requested, to avoid having to
+ // go through a completely unnecessary VOCTRL
+ if (action == M_PROPERTY_GET_TYPE) {
+ *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_NODE};
+ return M_PROPERTY_OK;
+ }
+
+ struct voctrl_performance_data data = {0};
+ if (vo_control(mpctx->video_out, VOCTRL_PERFORMANCE_DATA, &data) <= 0)
+ return M_PROPERTY_UNAVAILABLE;
+
+#define SUB_PROP_PERFDATA(N) \
+ {#N "-last", SUB_PROP_INT64(data.N.last)}, \
+ {#N "-avg", SUB_PROP_INT64(data.N.avg)}, \
+ {#N "-peak", SUB_PROP_INT64(data.N.peak)}
+
+ struct m_sub_property props[] = {
+ SUB_PROP_PERFDATA(upload),
+ SUB_PROP_PERFDATA(render),
+ SUB_PROP_PERFDATA(present),
+ {0}
+ };
+
+ return m_property_read_sub(props, action, arg);
+}
+
static int mp_property_vo(void *ctx, struct m_property *p, int action, void *arg)
{
MPContext *mpctx = ctx;
@@ -3803,6 +3803,7 @@ static const struct m_property mp_properties[] = {
M_PROPERTY_ALIAS("height", "video-params/h"),
{"window-scale", mp_property_window_scale},
{"vo-configured", mp_property_vo_configured},
+ {"vo-performance", mp_property_vo_performance},
{"current-vo", mp_property_vo},
{"fps", mp_property_fps},
{"estimated-vf-fps", mp_property_vf_fps},
@@ -3818,16 +3819,6 @@ static const struct m_property mp_properties[] = {
{"estimated-frame-count", mp_property_frame_count},
{"estimated-frame-number", mp_property_frame_number},
- {"upload-time-last", perfdata_property_helper},
- {"upload-time-avg", perfdata_property_helper},
- {"upload-time-peak", perfdata_property_helper},
- {"render-time-last", perfdata_property_helper},
- {"render-time-avg", perfdata_property_helper},
- {"render-time-peak", perfdata_property_helper},
- {"present-time-last", perfdata_property_helper},
- {"present-time-avg", perfdata_property_helper},
- {"present-time-peak", perfdata_property_helper},
-
{"osd-width", mp_property_osd_w},
{"osd-height", mp_property_osd_h},
{"osd-par", mp_property_osd_par},