summaryrefslogtreecommitdiffstats
path: root/command.c
diff options
context:
space:
mode:
authorUoti Urpala <uau@glyph.nonexistent.invalid>2010-12-18 08:02:48 +0200
committerUoti Urpala <uau@glyph.nonexistent.invalid>2010-12-18 11:59:09 +0200
commitb9a3579ec980dfb01d0b952bf0b859ecdf62d7ea (patch)
tree9f90d981a92bb6cfb79e5feed1b3b9bfde9ab3b0 /command.c
parent7e366113f75c696ae2b32f5faa5f80ec3fca96b8 (diff)
downloadmpv-b9a3579ec980dfb01d0b952bf0b859ecdf62d7ea.tar.bz2
mpv-b9a3579ec980dfb01d0b952bf0b859ecdf62d7ea.tar.xz
commands: add generic option -> property wrapper
Add mp_property_generic_option(), a property function that can be used for generic option-based properties that do not require any action beyond manipulating the value of the option variable. Currently it directly implements GET and SET, plus STEP_UP for "choice" options only. Use it to add a property for -pts-association-mode (not particularly useful in normal use, but serves as a test).
Diffstat (limited to 'command.c')
-rw-r--r--command.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/command.c b/command.c
index 489cd2d047..247af1b9d1 100644
--- a/command.c
+++ b/command.c
@@ -34,6 +34,7 @@
#include "libvo/sub.h"
#include "m_option.h"
#include "m_property.h"
+#include "m_config.h"
#include "metadata.h"
#include "libmpcodecs/vf.h"
#include "libmpcodecs/vd.h"
@@ -226,6 +227,39 @@ static void log_sub(struct MPContext *mpctx)
/// \ingroup Properties
///@{
+static int mp_property_generic_option(struct m_option *prop, int action,
+ void *arg, MPContext *mpctx)
+{
+ char *optname = prop->priv;
+ const struct m_option *opt = m_config_get_option(mpctx->mconfig, optname);
+ void *valptr = m_option_get_ptr(opt, &mpctx->opts);
+
+ switch (action) {
+ case M_PROPERTY_GET_TYPE:
+ *(const struct m_option **)arg = opt;
+ return M_PROPERTY_OK;
+ case M_PROPERTY_GET:
+ m_option_copy(opt, arg, valptr);
+ return M_PROPERTY_OK;
+ case M_PROPERTY_SET:
+ m_option_copy(opt, valptr, arg);
+ return M_PROPERTY_OK;
+ case M_PROPERTY_STEP_UP:
+ if (opt->type == &m_option_type_choice) {
+ int v = *(int *) valptr;
+ int best = v;
+ struct m_opt_choice_alternatives *alt;
+ for (alt = opt->priv; alt->name; alt++)
+ if ((unsigned) alt->value - v - 1 < (unsigned) best - v - 1)
+ best = alt->value;
+ *(int *) valptr = best;
+ return M_PROPERTY_OK;
+ }
+ break;
+ }
+ return M_PROPERTY_NOT_IMPLEMENTED;
+}
+
/// OSD level (RW)
static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
@@ -2189,6 +2223,8 @@ static const m_option_t mp_properties[] = {
M_OPT_RANGE, 0, 1, NULL },
{ "capturing", mp_property_capture, CONF_TYPE_FLAG,
M_OPT_RANGE, 0, 1, NULL },
+ { "pts_association_mode", mp_property_generic_option, &m_option_type_choice,
+ 0, 0, 0, "pts-association-mode" },
// Audio
{ "volume", mp_property_volume, CONF_TYPE_FLOAT,
@@ -2362,6 +2398,7 @@ static struct property_osd_display {
{ "loop", 0, -1, _("Loop: %s") },
{ "chapter", -1, -1, NULL },
{ "capturing", 0, -1, _("Capturing: %s") },
+ { "pts_association_mode", 0, -1, "PTS association mode: %s" },
// audio
{ "volume", OSD_VOLUME, -1, _("Volume") },
{ "mute", 0, -1, _("Mute: %s") },