diff options
author | wm4 <wm4@nowhere> | 2015-06-26 23:06:21 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-06-26 23:06:21 +0200 |
commit | d6737c5fab489964558b1eed934969c4f151912d (patch) | |
tree | 3c35d89e60b52b2ba4a787db20f9af527f24b94d | |
parent | efb50cabe6a479fad1f440474a1eb1f47e0ce58f (diff) |
audio: replace format name table
Having a big switch() is simpler.
-rw-r--r-- | audio/format.c | 57 | ||||
-rw-r--r-- | audio/format.h | 11 | ||||
-rw-r--r-- | audio/out/ao_coreaudio_utils.c | 7 | ||||
-rw-r--r-- | options/m_option.c | 10 |
4 files changed, 30 insertions, 55 deletions
diff --git a/audio/format.c b/audio/format.c index 131f4d06eb..7da99b6a0e 100644 --- a/audio/format.c +++ b/audio/format.c @@ -124,31 +124,6 @@ int af_fmt_from_planar(int format) return format; } -const struct af_fmt_entry af_fmtstr_table[] = { - {"u8", AF_FORMAT_U8}, - {"s16", AF_FORMAT_S16}, - {"s24", AF_FORMAT_S24}, - {"s32", AF_FORMAT_S32}, - {"float", AF_FORMAT_FLOAT}, - {"double", AF_FORMAT_DOUBLE}, - - {"u8p", AF_FORMAT_U8P}, - {"s16p", AF_FORMAT_S16P}, - {"s32p", AF_FORMAT_S32P}, - {"floatp", AF_FORMAT_FLOATP}, - {"doublep", AF_FORMAT_DOUBLEP}, - - {"spdif-aac", AF_FORMAT_S_AAC}, - {"spdif-ac3", AF_FORMAT_S_AC3}, - {"spdif-dts", AF_FORMAT_S_DTS}, - {"spdif-dtshd", AF_FORMAT_S_DTSHD}, - {"spdif-eac3", AF_FORMAT_S_EAC3}, - {"spdif-mp3", AF_FORMAT_S_MP3}, - {"spdif-truehd",AF_FORMAT_S_TRUEHD}, - - {0} -}; - bool af_fmt_is_valid(int format) { return format > 0 && format < AF_FORMAT_COUNT; @@ -156,11 +131,26 @@ bool af_fmt_is_valid(int format) const char *af_fmt_to_str(int format) { - for (int i = 0; af_fmtstr_table[i].name; i++) { - if (af_fmtstr_table[i].format == format) - return af_fmtstr_table[i].name; + switch (format) { + case AF_FORMAT_U8: return "u8"; + case AF_FORMAT_S16: return "s16"; + case AF_FORMAT_S24: return "s24"; + case AF_FORMAT_S32: return "s32"; + case AF_FORMAT_FLOAT: return "float"; + case AF_FORMAT_DOUBLE: return "double"; + case AF_FORMAT_U8P: return "u8p"; + case AF_FORMAT_S16P: return "s16p"; + case AF_FORMAT_S32P: return "s32p"; + case AF_FORMAT_FLOATP: return "floatp"; + case AF_FORMAT_DOUBLEP: return "doublep"; + case AF_FORMAT_S_AAC: return "spdif-aac"; + case AF_FORMAT_S_AC3: return "spdif-ac3"; + case AF_FORMAT_S_DTS: return "spdif-dts"; + case AF_FORMAT_S_DTSHD: return "spdif-dtshd"; + case AF_FORMAT_S_EAC3: return "spdif-eac3"; + case AF_FORMAT_S_MP3: return "spdif-mp3"; + case AF_FORMAT_S_TRUEHD: return "spdif-truehd"; } - return "??"; } @@ -175,15 +165,6 @@ int af_fmt_seconds_to_bytes(int format, float seconds, int channels, int sampler return bytes; } -int af_str2fmt_short(bstr str) -{ - for (int i = 0; af_fmtstr_table[i].name; i++) { - if (!bstrcasecmp0(str, af_fmtstr_table[i].name)) - return af_fmtstr_table[i].format; - } - return 0; -} - void af_fill_silence(void *dst, size_t bytes, int format) { memset(dst, af_fmt_unsigned(format) ? 0x80 : 0, bytes); diff --git a/audio/format.h b/audio/format.h index 36a005500e..83da59cf61 100644 --- a/audio/format.h +++ b/audio/format.h @@ -22,10 +22,9 @@ #ifndef MPLAYER_AF_FORMAT_H #define MPLAYER_AF_FORMAT_H +#include <stddef.h> #include <stdbool.h> -#include "misc/bstr.h" - enum af_format { AF_FORMAT_UNKNOWN = 0, @@ -60,14 +59,6 @@ enum af_format { #define AF_FORMAT_IS_FLOAT(f) af_fmt_is_float(f) #define AF_FORMAT_IS_PLANAR(f) af_fmt_is_planar(f) -struct af_fmt_entry { - const char *name; - int format; -}; - -extern const struct af_fmt_entry af_fmtstr_table[]; - -int af_str2fmt_short(bstr str); const char *af_fmt_to_str(int format); int af_fmt2bps(int format); diff --git a/audio/out/ao_coreaudio_utils.c b/audio/out/ao_coreaudio_utils.c index 7d504bb04b..96382512e8 100644 --- a/audio/out/ao_coreaudio_utils.c +++ b/audio/out/ao_coreaudio_utils.c @@ -236,12 +236,11 @@ bool ca_asbd_equals(const AudioStreamBasicDescription *a, // Return the AF_FORMAT_* (AF_FORMAT_S16 etc.) corresponding to the asbd. int ca_asbd_to_mp_format(const AudioStreamBasicDescription *asbd) { - for (int n = 0; af_fmtstr_table[n].format; n++) { - int mp_format = af_fmtstr_table[n].format; + for (int fmt = 1; fmt < AF_FORMAT_COUNT; fmt++) { AudioStreamBasicDescription mp_asbd = {0}; - ca_fill_asbd_raw(&mp_asbd, mp_format, 0, asbd->mChannelsPerFrame); + ca_fill_asbd_raw(&mp_asbd, fmt, 0, asbd->mChannelsPerFrame); if (ca_asbd_equals(&mp_asbd, asbd)) - return mp_format; + return fmt; } return 0; } diff --git a/options/m_option.c b/options/m_option.c index 8acdc8390d..347a2726db 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -2217,13 +2217,17 @@ static int parse_afmt(struct mp_log *log, const m_option_t *opt, if (!bstrcmp0(param, "help")) { mp_info(log, "Available formats:"); - for (int i = 0; af_fmtstr_table[i].name; i++) - mp_info(log, " %s", af_fmtstr_table[i].name); + for (int i = 1; i < AF_FORMAT_COUNT; i++) + mp_info(log, " %s", af_fmt_to_str(i)); mp_info(log, "\n"); return M_OPT_EXIT - 1; } - int fmt = af_str2fmt_short(param); + int fmt = 0; + for (int i = 1; i < AF_FORMAT_COUNT; i++) { + if (bstr_equals0(param, af_fmt_to_str(i))) + fmt = i; + } if (!fmt) { mp_err(log, "Option %.*s: unknown format name: '%.*s'\n", BSTR_P(name), BSTR_P(param)); |