summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-01-24 00:44:53 +0100
committerKevin Mitchell <kevmitch@gmail.com>2018-01-25 20:18:32 -0800
commitcabfbc34b539c06ae37745a200996bd351b64cf5 (patch)
treef1a40b5f98088142865a7b6fc207cf33d07e8f14
parentbd25fc5307a326a37c9136256a719c57840050f9 (diff)
downloadmpv-cabfbc34b539c06ae37745a200996bd351b64cf5.tar.bz2
mpv-cabfbc34b539c06ae37745a200996bd351b64cf5.tar.xz
m_option: add missing print callbacks
Add the print callback to all option types (except pseudo option types which don't represent values). This makes it less confusing for client API users (no strange properties that can't be read), and also lists the default properly with --list-options. Fix the option type for audio formats - they use int, not uint32_t. Fix some identation cosmetic issues.
-rw-r--r--options/m_option.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/options/m_option.c b/options/m_option.c
index 7ce137ba53..8cdf8aee11 100644
--- a/options/m_option.c
+++ b/options/m_option.c
@@ -429,10 +429,20 @@ bad:
return M_OPT_INVALID;
}
+static char *print_intpair(const m_option_t *opt, const void *val)
+{
+ const int *p = val;
+ char *res = talloc_asprintf(NULL, "%d", p[0]);
+ if (p[1] != -1)
+ res = talloc_asprintf_append(res, "-%d", p[1]);
+ return res;
+}
+
const struct m_option_type m_option_type_intpair = {
.name = "Int[-Int]",
.size = sizeof(int[2]),
.parse = parse_intpair,
+ .print = print_intpair,
.copy = copy_opt,
};
@@ -645,7 +655,7 @@ const struct m_option_type m_option_type_choice = {
.parse = parse_choice,
.print = print_choice,
.copy = copy_opt,
- .add = add_choice,
+ .add = add_choice,
.set = choice_set,
.get = choice_get,
};
@@ -2098,10 +2108,17 @@ static int parse_imgfmt(struct mp_log *log, const m_option_t *opt,
return 1;
}
+static char *print_imgfmt(const m_option_t *opt, const void *val)
+{
+ int fmt = *(int *)val;
+ return talloc_strdup(NULL, fmt ? mp_imgfmt_to_name(fmt) : "no");
+}
+
const m_option_type_t m_option_type_imgfmt = {
.name = "Image format",
.size = sizeof(int),
.parse = parse_imgfmt,
+ .print = print_imgfmt,
.copy = copy_opt,
};
@@ -2132,10 +2149,17 @@ static int parse_fourcc(struct mp_log *log, const m_option_t *opt,
return 1;
}
+static char *print_fourcc(const m_option_t *opt, const void *val)
+{
+ unsigned int fourcc = *(unsigned int *)val;
+ return talloc_asprintf(NULL, "%08x", fourcc);
+}
+
const m_option_type_t m_option_type_fourcc = {
.name = "FourCC",
.size = sizeof(unsigned int),
.parse = parse_fourcc,
+ .print = print_fourcc,
.copy = copy_opt,
};
@@ -2167,16 +2191,22 @@ static int parse_afmt(struct mp_log *log, const m_option_t *opt,
}
if (dst)
- *((uint32_t *)dst) = fmt;
+ *((int *)dst) = fmt;
return 1;
}
+static char *print_afmt(const m_option_t *opt, const void *val)
+{
+ int fmt = *(int *)val;
+ return talloc_strdup(NULL, fmt ? af_fmt_to_str(fmt) : "no");
+}
+
const m_option_type_t m_option_type_afmt = {
- // Please report any missing formats
.name = "Audio format",
- .size = sizeof(uint32_t),
+ .size = sizeof(int),
.parse = parse_afmt,
+ .print = print_afmt,
.copy = copy_opt,
};
@@ -2376,7 +2406,7 @@ const m_option_type_t m_option_type_time = {
.print = print_time,
.pretty_print = pretty_print_time,
.copy = copy_opt,
- .add = add_double,
+ .add = add_double,
.set = time_set,
.get = time_get,
};