Skip to content

Commit 3ed900d

Browse files
committed
player/command: add subrandr-version property
Allows script to detect the presence of subrandr at runtime, useful for determining whether this mpv instance can play SRV3 subtitles.
1 parent 125ef1f commit 3ed900d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

DOCS/man/input.rst

+6
Original file line numberDiff line numberDiff line change
@@ -3886,6 +3886,12 @@ Property list
38863886
somewhat weird form (apparently "hex BCD"), indicating the release version
38873887
of the libass library linked to mpv.
38883888

3889+
``subrandr-version``
3890+
The value of ``sbr_library_version()`` as a string in the format
3891+
``<major>.<minor>.<patch>``, indicating the release version of the subrandr
3892+
library linked to mpv. This property is unavailable if mpv is not compiled
3893+
with subrandr enabled.
3894+
38893895
``platform``
38903896
Returns a string describing what target platform mpv was built for. The value
38913897
of this is dependent on what the underlying build system detects. Some of the

player/command.c

+32
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@
2525
#include <math.h>
2626
#include <sys/types.h>
2727

28+
#include "config.h" // for HAVE_SUBRANDR
29+
2830
#include <ass/ass.h>
31+
#if HAVE_SUBRANDR
32+
#include <subrandr/subrandr.h>
33+
#endif
2934
#include <libavutil/avstring.h>
3035
#include <libavutil/common.h>
3136
#include <libavutil/timecode.h>
@@ -3665,6 +3670,32 @@ static int mp_property_libass_version(void *ctx, struct m_property *prop,
36653670
return m_property_int64_ro(action, arg, ass_library_version());
36663671
}
36673672

3673+
static int mp_property_subrandr_version(void *ctx, struct m_property *prop,
3674+
int action, void *arg)
3675+
{
3676+
#if HAVE_SUBRANDR
3677+
switch (action) {
3678+
case M_PROPERTY_GET: {
3679+
struct bstr result = (bstr) {NULL, 0};
3680+
uint32_t major, minor, patch;
3681+
sbr_library_version(&major, &minor, &patch);
3682+
if(bstr_xappend_asprintf(NULL, &result, "%" PRIu32 ".%" PRIu32 ".%" PRIu32,
3683+
major, minor, patch) < 0)
3684+
return M_PROPERTY_ERROR;
3685+
3686+
*(char **)arg = result.start;
3687+
return M_PROPERTY_OK;
3688+
}
3689+
case M_PROPERTY_GET_TYPE:
3690+
*(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_STRING};
3691+
return M_PROPERTY_OK;
3692+
}
3693+
return M_PROPERTY_NOT_IMPLEMENTED;
3694+
#else
3695+
return M_PROPERTY_UNAVAILABLE;
3696+
#endif
3697+
}
3698+
36683699
static int mp_property_platform(void *ctx, struct m_property *prop,
36693700
int action, void *arg)
36703701
{
@@ -4446,6 +4477,7 @@ static const struct m_property mp_properties_base[] = {
44464477
{"mpv-configuration", mp_property_configuration},
44474478
{"ffmpeg-version", mp_property_ffmpeg},
44484479
{"libass-version", mp_property_libass_version},
4480+
{"subrandr-version", mp_property_subrandr_version},
44494481
{"platform", mp_property_platform},
44504482

44514483
{"options", mp_property_options},

0 commit comments

Comments
 (0)