summaryrefslogtreecommitdiffstats
path: root/libaf
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-08-29 00:34:21 +0200
committerwm4 <wm4@nowhere>2012-08-29 00:36:44 +0200
commit7c45be712f93dc965fd6c8393aa476d42cbbd64d (patch)
tree22815d9db15b2bdeae78607fbeeaff90eff97424 /libaf
parent7bb95cd8a5130a971d3d07eb79ba08fc91e4b7cb (diff)
downloadmpv-7c45be712f93dc965fd6c8393aa476d42cbbd64d.tar.bz2
mpv-7c45be712f93dc965fd6c8393aa476d42cbbd64d.tar.xz
options, libaf: unify audio format name handling
Remove the duplicated list of audio format names from m_option.c. Remove "long" audio format names, and let af_fmt2str() print the usual short format names. The long names were overly verbose, and were actually rarely user visible. The only difference between af_fmt2str() and af_fmt2str_short() is that the former prints unknown format values as hexadecimal string as fallback.
Diffstat (limited to 'libaf')
-rw-r--r--libaf/af_format.c2
-rw-r--r--libaf/af_format.h10
-rw-r--r--libaf/format.c79
3 files changed, 28 insertions, 63 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;
}