diff options
author | wm4 <wm4@nowhere> | 2013-04-05 15:25:09 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-05-12 21:24:54 +0200 |
commit | 0042735d7aefb2f05a79ba2eae741a63f22ea0c9 (patch) | |
tree | b3fa1b42a3fb27003e6b02c1cdd4feb935c1bb04 /core/m_option.c | |
parent | 1e37d35970398856e911487754056db9509f0c5a (diff) | |
download | mpv-0042735d7aefb2f05a79ba2eae741a63f22ea0c9.tar.bz2 mpv-0042735d7aefb2f05a79ba2eae741a63f22ea0c9.tar.xz |
audio: add channel map API
Unused, will be used in the following commits.
Let chmap.h define the number of maximum channels, because that is most
convenient.
Diffstat (limited to 'core/m_option.c')
-rw-r--r-- | core/m_option.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/core/m_option.c b/core/m_option.c index 6e7b20a688..b1e0f50dd9 100644 --- a/core/m_option.c +++ b/core/m_option.c @@ -1555,6 +1555,48 @@ const m_option_type_t m_option_type_afmt = { .copy = copy_opt, }; +#include "audio/chmap.h" + +static int parse_chmap(const m_option_t *opt, struct bstr name, + struct bstr param, void *dst) +{ + // min>0: at least min channels, min=0: empty ok, min=-1: invalid ok + int min_ch = (opt->flags & M_OPT_MIN) ? opt->min : 1; + + if (bstr_equals0(param, "help")) { + mp_chmap_print_help(MSGT_CFGPARSER, MSGL_INFO); + return M_OPT_EXIT - 1; + } + + if (param.len == 0 && min_ch >= 1) + return M_OPT_MISSING_PARAM; + + struct mp_chmap res = {0}; + if (!mp_chmap_from_str(&res, param)) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "Error parsing channel layout: %.*s\n", BSTR_P(param)); + return M_OPT_INVALID; + } + + if ((min_ch > 0 && !mp_chmap_is_valid(&res)) || + (min_ch >= 0 && mp_chmap_is_empty(&res))) + { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "Invalid channel layout: %.*s\n", BSTR_P(param)); + return M_OPT_INVALID; + } + + *(struct mp_chmap *)dst = res; + + return 1; +} + +const m_option_type_t m_option_type_chmap = { + .name = "Audio channels or channel map", + .size = sizeof(struct mp_chmap *), + .parse = parse_chmap, + .copy = copy_opt, +}; static int parse_timestring(struct bstr str, double *time, char endchar) { |