From 0042735d7aefb2f05a79ba2eae741a63f22ea0c9 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 5 Apr 2013 15:25:09 +0200 Subject: 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. --- core/m_option.c | 42 ++++++++++++++++++++++++++++++++++++++++++ core/m_option.h | 4 ++++ 2 files changed, 46 insertions(+) (limited to 'core') 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) { diff --git a/core/m_option.h b/core/m_option.h index fd0ebbd44c..66e7208801 100644 --- a/core/m_option.h +++ b/core/m_option.h @@ -60,6 +60,7 @@ extern const m_option_type_t m_option_type_afmt; extern const m_option_type_t m_option_type_color; extern const m_option_type_t m_option_type_geometry; extern const m_option_type_t m_option_type_size_box; +extern const m_option_type_t m_option_type_chmap; // Callback used by m_option_type_print_func options. typedef int (*m_opt_func_full_t)(const m_option_t *, const char *, const char *); @@ -581,6 +582,9 @@ static inline void m_option_free(const m_option_t *opt, void *dst) #define OPT_AUDIOFORMAT(...) \ OPT_GENERAL(int, __VA_ARGS__, .type = &m_option_type_afmt) +#define OPT_CHMAP(...) \ + OPT_GENERAL(struct mp_chmap, __VA_ARGS__, .type = &m_option_type_chmap) + #define M_CHOICES(choices) \ .priv = (void *)&(const struct m_opt_choice_alternatives[]){ \ -- cgit v1.2.3