summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-09-21 14:05:52 +0200
committerwm4 <wm4@nowhere>2012-10-12 10:10:31 +0200
commit74adc534b9dd8dde67042e8f3f448da3baca2fef (patch)
treefcee39a92e55e702884cb113ad8b7bee579a9b41
parente4dda184aa2100c8781e7427f526cc2b1afb2fde (diff)
downloadmpv-74adc534b9dd8dde67042e8f3f448da3baca2fef.tar.bz2
mpv-74adc534b9dd8dde67042e8f3f448da3baca2fef.tar.xz
commands: make M_PROPERTY_GET_TYPE return an option copy
Change the type of the arg for this action from m_option** to m_option*. This makes it easier to change some aspects of the option dynamically.
-rw-r--r--command.c28
-rw-r--r--m_property.c40
-rw-r--r--m_property.h2
3 files changed, 35 insertions, 35 deletions
diff --git a/command.c b/command.c
index 5905ea6832..74ef6d2f7d 100644
--- a/command.c
+++ b/command.c
@@ -125,7 +125,7 @@ static int mp_property_generic_option(struct m_option *prop, int action,
switch (action) {
case M_PROPERTY_GET_TYPE:
- *(const struct m_option **)arg = opt->opt;
+ *(struct m_option *)arg = *(opt->opt);
return M_PROPERTY_OK;
case M_PROPERTY_GET:
m_option_copy(opt->opt, arg, valptr);
@@ -513,7 +513,7 @@ static int mp_property_metadata(m_option_t *prop, int action, void *arg,
*(char **)ka->arg = talloc_strdup(NULL, meta);
return M_PROPERTY_OK;
case M_PROPERTY_GET_TYPE:
- *(const m_option_t **)ka->arg = &key_type;
+ *(struct m_option *)ka->arg = key_type;
return M_PROPERTY_OK;
}
}
@@ -918,22 +918,22 @@ static int levels_property_helper(int offset, m_option_t *prop, int action,
if (action != M_PROPERTY_PRINT)
return colormatrix_property_helper(prop, action, arg, mpctx);
- const struct m_option *opt = NULL;
+ struct m_option opt = {0};
mp_property_generic_option(prop, M_PROPERTY_GET_TYPE, &opt, mpctx);
- assert(opt);
+ assert(opt.type);
int requested = 0;
mp_property_generic_option(prop, M_PROPERTY_GET, &requested, mpctx);
struct mp_csp_details actual = {0};
int actual_level = -1;
- char *req_level = m_option_print(opt, &requested);
+ char *req_level = m_option_print(&opt, &requested);
char *real_level = NULL;
if (mpctx->sh_video) {
struct vf_instance *vf = mpctx->sh_video->vfilter;
if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &actual) == true) {
actual_level = *(enum mp_csp_levels *)(((char *)&actual) + offset);
- real_level = m_option_print(opt, &actual_level);
+ real_level = m_option_print(&opt, &actual_level);
} else {
real_level = talloc_strdup(NULL, "Unknown");
}
@@ -1591,8 +1591,7 @@ static struct property_osd_display {
static int show_property_osd(MPContext *mpctx, const char *pname)
{
struct MPOpts *opts = &mpctx->opts;
- int r;
- m_option_t *prop;
+ struct m_option prop = {0};
struct property_osd_display *p;
// look for the command
@@ -1603,21 +1602,22 @@ static int show_property_osd(MPContext *mpctx, const char *pname)
if (!p->name)
return -1;
- if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
+ if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0)
return -1;
if (p->osd_progbar == -1)
mpctx->add_osd_seek_info = true;
else if (p->osd_progbar) {
- if (prop->type == CONF_TYPE_INT) {
- if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
+ if (prop.type == CONF_TYPE_INT) {
+ int i;
+ if (mp_property_do(pname, M_PROPERTY_GET, &i, mpctx) > 0)
set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
- prop->min, prop->max, r);
- } else if (prop->type == CONF_TYPE_FLOAT) {
+ prop.min, prop.max, i);
+ } else if (prop.type == CONF_TYPE_FLOAT) {
float f;
if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
- prop->min, prop->max, f);
+ prop.min, prop.max, f);
} else {
mp_msg(MSGT_CPLAYER, MSGL_ERR,
"Property use an unsupported type.\n");
diff --git a/m_property.c b/m_property.c
index aebdde88ef..f2899912d6 100644
--- a/m_property.c
+++ b/m_property.c
@@ -58,7 +58,7 @@ static int do_action(const m_option_t *prop_list, const char *name,
int (*control)(const m_option_t*, int, void*, void*) = prop->p;
int r = control(prop, action, arg, ctx);
if (action == M_PROPERTY_GET_TYPE && r < 0) {
- *(const m_option_t **)arg = prop;
+ *(struct m_option *)arg = *prop;
return M_PROPERTY_OK;
}
return r;
@@ -70,11 +70,11 @@ int m_property_do(const m_option_t *prop_list, const char *name,
union m_option_value val = {0};
int r;
- const m_option_t *opt = NULL;
+ struct m_option opt = {0};
r = do_action(prop_list, name, M_PROPERTY_GET_TYPE, &opt, ctx);
if (r <= 0)
return r;
- assert(opt);
+ assert(opt.type);
switch (action) {
case M_PROPERTY_PRINT: {
@@ -83,25 +83,25 @@ int m_property_do(const m_option_t *prop_list, const char *name,
// Fallback to m_option
if ((r = do_action(prop_list, name, M_PROPERTY_GET, &val, ctx)) <= 0)
return r;
- char *str = m_option_pretty_print(opt, &val);
- m_option_free(opt, &val);
+ char *str = m_option_pretty_print(&opt, &val);
+ m_option_free(&opt, &val);
*(char **)arg = str;
return str != NULL;
}
case M_PROPERTY_TO_STRING: {
if ((r = do_action(prop_list, name, M_PROPERTY_GET, &val, ctx)) <= 0)
return r;
- char *str = m_option_print(opt, &val);
- m_option_free(opt, &val);
+ char *str = m_option_print(&opt, &val);
+ m_option_free(&opt, &val);
*(char **)arg = str;
return str != NULL;
}
case M_PROPERTY_PARSE: {
// (reject 0 return value: success, but empty string with flag)
- if (m_option_parse(opt, bstr0(opt->name), bstr0(arg), &val) <= 0)
+ if (m_option_parse(&opt, bstr0(opt->name), bstr0(arg), &val) <= 0)
return M_PROPERTY_ERROR;
r = do_action(prop_list, name, M_PROPERTY_SET, &val, ctx);
- m_option_free(opt, &val);
+ m_option_free(&opt, &val);
return r;
}
case M_PROPERTY_SWITCH: {
@@ -109,25 +109,25 @@ int m_property_do(const m_option_t *prop_list, const char *name,
M_PROPERTY_NOT_IMPLEMENTED)
return r;
// Fallback to m_option
- if (!opt->type->add)
+ if (!opt.type->add)
return M_PROPERTY_NOT_IMPLEMENTED;
if ((r = do_action(prop_list, name, M_PROPERTY_GET, &val, ctx)) <= 0)
return r;
- bool wrap = opt->type == &m_option_type_choice ||
- opt->type == &m_option_type_flag;
- opt->type->add(opt, &val, *(double*)arg, wrap);
+ bool wrap = opt.type == &m_option_type_choice ||
+ opt.type == &m_option_type_flag;
+ opt.type->add(&opt, &val, *(double*)arg, wrap);
r = do_action(prop_list, name, M_PROPERTY_SET, &val, ctx);
- m_option_free(opt, &val);
+ m_option_free(&opt, &val);
return r;
}
case M_PROPERTY_SET: {
- if (!opt->type->clamp) {
+ if (!opt.type->clamp) {
mp_msg(MSGT_CPLAYER, MSGL_WARN, "Property '%s' without clamp().\n",
name);
} else {
- m_option_copy(opt, &val, arg);
- r = opt->type->clamp(opt, arg);
- m_option_free(opt, &val);
+ m_option_copy(&opt, &val, arg);
+ r = opt.type->clamp(&opt, arg);
+ m_option_free(&opt, &val);
if (r != 0) {
mp_msg(MSGT_CPLAYER, MSGL_ERR,
"Property '%s': invalid value.\n", name);
@@ -205,14 +205,14 @@ char *m_properties_expand_string(const m_option_t *prop_list, char *str,
char pname[pl + 1];
memcpy(pname, str + (is_not ? 3 : 2), pl);
pname[pl] = 0;
- struct m_option *opt;
+ struct m_option opt = {0};
union m_option_value val = {0};
if (m_property_do(prop_list, pname, M_PROPERTY_GET_TYPE, &opt, ctx) <= 0 &&
m_property_do(prop_list, pname, M_PROPERTY_GET, &val, ctx) <= 0)
{
if (!is_not)
skip = 1, skip_lvl = lvl;
- m_option_free(opt, &val);
+ m_option_free(&opt, &val);
} else if (is_not)
skip = 1, skip_lvl = lvl;
}
diff --git a/m_property.h b/m_property.h
index 99ab05ad62..2893fc569d 100644
--- a/m_property.h
+++ b/m_property.h
@@ -25,7 +25,7 @@ enum mp_property_action {
// Get the property type. This defines the fundamental data type read from
// or written to the property.
// If unimplemented, the m_option entry that defines the property is used.
- // arg: const m_option**
+ // arg: m_option*
M_PROPERTY_GET_TYPE,
// Get the current value.