summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libaf/af_format.c2
-rw-r--r--libaf/af_format.h10
-rw-r--r--libaf/format.c79
-rw-r--r--m_option.c68
4 files changed, 36 insertions, 123 deletions
diff --git a/libaf/af_format.c b/libaf/af_format.c
index b9f13e6dca..ea9f39e2e6 100644
--- a/libaf/af_format.c
+++ b/libaf/af_format.c
@@ -144,7 +144,7 @@ static int control(struct af_instance_s* af, int cmd, void* arg)
return AF_OK;
}
case AF_CONTROL_COMMAND_LINE:{
- int format = af_str2fmt_short(arg);
+ int format = af_str2fmt_short(bstr0(arg));
if (format == -1) {
mp_msg(MSGT_AFILTER, MSGL_ERR, "[format] %s is not a valid format\n", (char *)arg);
return AF_ERROR;
diff --git a/libaf/af_format.h b/libaf/af_format.h
index 08f6892e41..36f5c3fb59 100644
--- a/libaf/af_format.h
+++ b/libaf/af_format.h
@@ -25,6 +25,7 @@
#include <sys/types.h>
#include "config.h"
+#include "bstr.h"
// Endianness
#define AF_FORMAT_BE (0<<0) // Big Endian
@@ -118,7 +119,14 @@
#define AF_FORMAT_IS_AC3(fmt) (((fmt) & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_AC3)
#define AF_FORMAT_IS_IEC61937(fmt) (((fmt) & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_IEC61937)
-int af_str2fmt_short(const char *str);
+struct af_fmt_entry {
+ const char *name;
+ int format;
+};
+
+extern const struct af_fmt_entry af_fmtstr_table[];
+
+int af_str2fmt_short(bstr str);
int af_fmt2bits(int format);
int af_bits2fmt(int bits);
char* af_fmt2str(int format, char* str, int size);
diff --git a/libaf/format.c b/libaf/format.c
index 408ef6b5e2..ffdf435e71 100644
--- a/libaf/format.c
+++ b/libaf/format.c
@@ -53,64 +53,16 @@ int af_bits2fmt(int bits)
converted string, size is the size of the buffer */
char* af_fmt2str(int format, char* str, int size)
{
- int i=0;
-
- if (size < 1)
- return NULL;
- size--; // reserve one for terminating 0
-
- // Endianness
- if(AF_FORMAT_LE == (format & AF_FORMAT_END_MASK))
- i+=snprintf(str,size-i,"little-endian ");
- else
- i+=snprintf(str,size-i,"big-endian ");
-
- if(format & AF_FORMAT_SPECIAL_MASK){
- switch(format & AF_FORMAT_SPECIAL_MASK){
- case(AF_FORMAT_MU_LAW):
- i+=snprintf(&str[i],size-i,"mu-law "); break;
- case(AF_FORMAT_A_LAW):
- i+=snprintf(&str[i],size-i,"A-law "); break;
- case(AF_FORMAT_MPEG2):
- i+=snprintf(&str[i],size-i,"MPEG-2 "); break;
- case(AF_FORMAT_AC3):
- i+=snprintf(&str[i],size-i,"AC3 "); break;
- case(AF_FORMAT_IEC61937):
- i+=snprintf(&str[i],size-i,"IEC61937 "); break;
- case(AF_FORMAT_IMA_ADPCM):
- i+=snprintf(&str[i],size-i,"IMA-ADPCM "); break;
- default:
- i+=snprintf(&str[i],size-i,"%s",mp_gtext("unknown format "));
+ const char *name = af_fmt2str_short(format);
+ if (name) {
+ snprintf(str, size, "%s", name);
+ } else {
+ snprintf(str, size, "%#x", format);
}
- }
- else{
- // Bits
- i+=snprintf(&str[i],size-i,"%d-bit ", af_fmt2bits(format));
-
- // Point
- if(AF_FORMAT_F == (format & AF_FORMAT_POINT_MASK))
- i+=snprintf(&str[i],size-i,"float ");
- else{
- // Sign
- if(AF_FORMAT_US == (format & AF_FORMAT_SIGN_MASK))
- i+=snprintf(&str[i],size-i,"unsigned ");
- else
- i+=snprintf(&str[i],size-i,"signed ");
-
- i+=snprintf(&str[i],size-i,"int ");
- }
- }
- // remove trailing space
- if (i > 0 && str[i - 1] == ' ')
- i--;
- str[i] = 0; // make sure it is 0 terminated.
- return str;
+ return str;
}
-static struct {
- const char *name;
- const int format;
-} af_fmtstr_table[] = {
+const struct af_fmt_entry af_fmtstr_table[] = {
{ "mulaw", AF_FORMAT_MU_LAW },
{ "alaw", AF_FORMAT_A_LAW },
{ "mpeg2", AF_FORMAT_MPEG2 },
@@ -146,7 +98,7 @@ static struct {
{ "floatbe", AF_FORMAT_FLOAT_BE },
{ "floatne", AF_FORMAT_FLOAT_NE },
- { NULL, 0 }
+ {0}
};
const char *af_fmt2str_short(int format)
@@ -160,13 +112,18 @@ const char *af_fmt2str_short(int format)
return "??";
}
-int af_str2fmt_short(const char* str)
+int af_str2fmt_short(bstr str)
{
- int i;
+ if (bstr_startswith0(str, "0x")) {
+ bstr rest;
+ int fmt = bstrtoll(str, &rest, 16);
+ if (rest.len == 0)
+ return fmt;
+ }
- for (i = 0; af_fmtstr_table[i].name; i++)
- if (!strcasecmp(str, af_fmtstr_table[i].name))
- return af_fmtstr_table[i].format;
+ 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 -1;
}
diff --git a/m_option.c b/m_option.c
index 941ae28f89..e4c7759f50 100644
--- a/m_option.c
+++ b/m_option.c
@@ -953,78 +953,26 @@ const m_option_type_t m_option_type_imgfmt = {
#include "libaf/af_format.h"
-/* FIXME: snyc with af_format.h */
-static struct {
- const char *name;
- unsigned int fmt;
-} mp_afmt_list[] = {
- // SPECIAL
- {"mulaw", AF_FORMAT_MU_LAW},
- {"alaw", AF_FORMAT_A_LAW},
- {"mpeg2", AF_FORMAT_MPEG2},
- {"ac3le", AF_FORMAT_AC3_LE},
- {"ac3be", AF_FORMAT_AC3_BE},
- {"ac3ne", AF_FORMAT_AC3_NE},
- {"imaadpcm", AF_FORMAT_IMA_ADPCM},
- // ORDINARY
- {"u8", AF_FORMAT_U8},
- {"s8", AF_FORMAT_S8},
- {"u16le", AF_FORMAT_U16_LE},
- {"u16be", AF_FORMAT_U16_BE},
- {"u16ne", AF_FORMAT_U16_NE},
- {"s16le", AF_FORMAT_S16_LE},
- {"s16be", AF_FORMAT_S16_BE},
- {"s16ne", AF_FORMAT_S16_NE},
- {"u24le", AF_FORMAT_U24_LE},
- {"u24be", AF_FORMAT_U24_BE},
- {"u24ne", AF_FORMAT_U24_NE},
- {"s24le", AF_FORMAT_S24_LE},
- {"s24be", AF_FORMAT_S24_BE},
- {"s24ne", AF_FORMAT_S24_NE},
- {"u32le", AF_FORMAT_U32_LE},
- {"u32be", AF_FORMAT_U32_BE},
- {"u32ne", AF_FORMAT_U32_NE},
- {"s32le", AF_FORMAT_S32_LE},
- {"s32be", AF_FORMAT_S32_BE},
- {"s32ne", AF_FORMAT_S32_NE},
- {"floatle", AF_FORMAT_FLOAT_LE},
- {"floatbe", AF_FORMAT_FLOAT_BE},
- {"floatne", AF_FORMAT_FLOAT_NE},
- { NULL, 0 }
-};
-
static int parse_afmt(const m_option_t *opt, struct bstr name,
struct bstr param, void *dst)
{
- uint32_t fmt = 0;
- int i;
-
if (param.len == 0)
return M_OPT_MISSING_PARAM;
if (!bstrcmp0(param, "help")) {
mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Available formats:");
- for (i = 0; mp_afmt_list[i].name; i++)
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s", mp_afmt_list[i].name);
+ for (int i = 0; af_fmtstr_table[i].name; i++)
+ mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s", af_fmtstr_table[i].name);
mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n");
return M_OPT_EXIT - 1;
}
- if (bstr_startswith0(param, "0x"))
- fmt = bstrtoll(param, NULL, 16);
- else {
- for (i = 0; mp_afmt_list[i].name; i++) {
- if (!bstrcasecmp0(param, mp_afmt_list[i].name)) {
- fmt = mp_afmt_list[i].fmt;
- break;
- }
- }
- if (!mp_afmt_list[i].name) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Option %.*s: unknown format name: '%.*s'\n",
- BSTR_P(name), BSTR_P(param));
- return M_OPT_INVALID;
- }
+ int fmt = af_str2fmt_short(param);
+ if (fmt == -1) {
+ mp_msg(MSGT_CFGPARSER, MSGL_ERR,
+ "Option %.*s: unknown format name: '%.*s'\n",
+ BSTR_P(name), BSTR_P(param));
+ return M_OPT_INVALID;
}
if (dst)