summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-06-16 20:57:43 +0200
committerwm4 <wm4@nowhere>2015-06-16 21:11:59 +0200
commit831d7c3c400b554484561bf912c1f9657f8192cd (patch)
tree7c3abe2dadd826f58ac316f9c35b56d9e869d760
parent488ebdb0d57b4e822e8dac4fac18dfe460b61ac6 (diff)
downloadmpv-831d7c3c400b554484561bf912c1f9657f8192cd.tar.bz2
mpv-831d7c3c400b554484561bf912c1f9657f8192cd.tar.xz
audio: remove S8, U16, U24, U32 formats
They are useless. Not only are they actually rarely in use; but libavcodec doesn't even output them, as libavcodec has no such sample formats for decoded audio. Even if it should happen that we actually still need them (e.g. if doing direct hardware output), there are better solutions. Swapping the sign is a fast and lossless operation and can be done inplace, so AO actually needing it could do this directly. If you wonder why we keep U8 instead of S8: because libavcodec does it.
-rw-r--r--TOOLS/old-makefile1
-rw-r--r--audio/filter/af.c2
-rw-r--r--audio/filter/af_bs2b.c4
-rw-r--r--audio/filter/af_convert24.c4
-rw-r--r--audio/filter/af_convertsignendian.c107
-rw-r--r--audio/format.c15
-rw-r--r--audio/format.h25
-rw-r--r--audio/out/ao_alsa.c5
-rw-r--r--audio/out/ao_coreaudio_utils.c2
-rw-r--r--audio/out/ao_oss.c20
-rw-r--r--audio/out/ao_rsound.c17
-rw-r--r--audio/out/ao_sdl.c2
-rw-r--r--audio/out/ao_sndio.c20
-rw-r--r--wscript_build.py1
14 files changed, 26 insertions, 199 deletions
diff --git a/TOOLS/old-makefile b/TOOLS/old-makefile
index 32b547894a..d0846240a8 100644
--- a/TOOLS/old-makefile
+++ b/TOOLS/old-makefile
@@ -124,7 +124,6 @@ SOURCES = audio/audio.c \
audio/filter/af_center.c \
audio/filter/af_channels.c \
audio/filter/af_convert24.c \
- audio/filter/af_convertsignendian.c \
audio/filter/af_delay.c \
audio/filter/af_dummy.c \
audio/filter/af_equalizer.c \
diff --git a/audio/filter/af.c b/audio/filter/af.c
index 67083c493b..c0535f957c 100644
--- a/audio/filter/af.c
+++ b/audio/filter/af.c
@@ -56,7 +56,6 @@ extern const struct af_info af_info_scaletempo;
extern const struct af_info af_info_bs2b;
extern const struct af_info af_info_lavfi;
extern const struct af_info af_info_convert24;
-extern const struct af_info af_info_convertsignendian;
extern const struct af_info af_info_rubberband;
static const struct af_info *const filter_list[] = {
@@ -94,7 +93,6 @@ static const struct af_info *const filter_list[] = {
#endif
// Must come last, because they're fallback format conversion filter
&af_info_convert24,
- &af_info_convertsignendian,
NULL
};
diff --git a/audio/filter/af_bs2b.c b/audio/filter/af_bs2b.c
index 10d6f4e3fc..beb4dc9b96 100644
--- a/audio/filter/af_bs2b.c
+++ b/audio/filter/af_bs2b.c
@@ -57,12 +57,8 @@ static int filter_##name(struct af_instance *af, struct mp_audio *data) \
#define FILTERS \
FILTER(FLOAT, f) \
FILTER(S32, s32) \
- FILTER(U32, u32) \
FILTER(S24, s24) \
- FILTER(U24, u24) \
FILTER(S16, s16) \
- FILTER(U16, u16) \
- FILTER(S8, s8) \
FILTER(U8, u8)
#define FILTER DEF_FILTER
diff --git a/audio/filter/af_convert24.c b/audio/filter/af_convert24.c
index ab04c931b6..a81e84e2af 100644
--- a/audio/filter/af_convert24.c
+++ b/audio/filter/af_convert24.c
@@ -24,9 +24,7 @@
static bool test_conversion(int src_format, int dst_format)
{
- return (src_format == AF_FORMAT_U24 && dst_format == AF_FORMAT_U32) ||
- (src_format == AF_FORMAT_S24 && dst_format == AF_FORMAT_S32) ||
- (src_format == AF_FORMAT_U32 && dst_format == AF_FORMAT_U24) ||
+ return (src_format == AF_FORMAT_S24 && dst_format == AF_FORMAT_S32) ||
(src_format == AF_FORMAT_S32 && dst_format == AF_FORMAT_S24);
}
diff --git a/audio/filter/af_convertsignendian.c b/audio/filter/af_convertsignendian.c
deleted file mode 100644
index abbd260a0f..0000000000
--- a/audio/filter/af_convertsignendian.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * This file is part of mpv.
- *
- * mpv is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * mpv is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with mpv. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <stdlib.h>
-#include <assert.h>
-
-#include "af.h"
-#include "audio/format.h"
-#include "osdep/endian.h"
-
-static bool test_conversion(int src_format, int dst_format)
-{
- if ((src_format & AF_FORMAT_PLANAR) ||
- (dst_format & AF_FORMAT_PLANAR))
- return false;
- if (((src_format & ~AF_FORMAT_SIGN_MASK) ==
- (dst_format & ~AF_FORMAT_SIGN_MASK)) &&
- ((src_format & AF_FORMAT_TYPE_MASK) == AF_FORMAT_I))
- return true;
- return false;
-}
-
-static int control(struct af_instance *af, int cmd, void *arg)
-{
- switch (cmd) {
- case AF_CONTROL_REINIT: {
- struct mp_audio *in = arg;
- struct mp_audio orig_in = *in;
- struct mp_audio *out = af->data;
-
- if (!test_conversion(in->format, out->format))
- return AF_DETACH;
-
- out->rate = in->rate;
- mp_audio_set_channels(out, &in->channels);
-
- return mp_audio_config_equals(in, &orig_in) ? AF_OK : AF_FALSE;
- }
- case AF_CONTROL_SET_FORMAT: {
- mp_audio_set_format(af->data, *(int*)arg);
- return AF_OK;
- }
- }
- return AF_UNKNOWN;
-}
-
-static void si2us(void *data, int len, int bps)
-{
- ptrdiff_t i = -(len * bps);
- uint8_t *p = &((uint8_t *)data)[len * bps];
- if (BYTE_ORDER == LITTLE_ENDIAN && bps > 1)
- p += bps - 1;
- if (len <= 0)
- return;
- do {
- p[i] ^= 0x80;
- } while (i += bps);
-}
-
-static int filter(struct af_instance *af, struct mp_audio *data)
-{
- if (!data)
- return 0;
- if (af_make_writeable(af, data) < 0) {
- talloc_free(data);
- return -1;
- }
-
- int infmt = data->format;
- int outfmt = af->data->format;
- size_t len = data->samples * data->nch;
-
- if ((infmt & AF_FORMAT_SIGN_MASK) != (outfmt & AF_FORMAT_SIGN_MASK))
- si2us(data->planes[0], len, data->bps);
-
- mp_audio_set_format(data, outfmt);
- af_add_output_frame(af, data);
- return 0;
-}
-
-static int af_open(struct af_instance *af)
-{
- af->control = control;
- af->filter_frame = filter;
- return AF_OK;
-}
-
-const struct af_info af_info_convertsignendian = {
- .info = "Convert between sample format sign",
- .name = "convertsign",
- .open = af_open,
- .test_conversion = test_conversion,
-};
diff --git a/audio/format.c b/audio/format.c
index 401214281b..98957f9bd4 100644
--- a/audio/format.c
+++ b/audio/format.c
@@ -65,6 +65,12 @@ int af_fmt_change_bits(int format, int bits)
return af_fmt_is_valid(format) ? format : 0;
}
+// All formats are considered signed, except explicitly unsigned int formats.
+bool af_fmt_unsigned(int format)
+{
+ return format == AF_FORMAT_U8 || format == AF_FORMAT_U8P;
+}
+
static const int planar_formats[][2] = {
{AF_FORMAT_U8P, AF_FORMAT_U8},
{AF_FORMAT_S16P, AF_FORMAT_S16},
@@ -101,12 +107,8 @@ int af_fmt_from_planar(int format)
const struct af_fmt_entry af_fmtstr_table[] = {
{"u8", AF_FORMAT_U8},
- {"s8", AF_FORMAT_S8},
- {"u16", AF_FORMAT_U16},
{"s16", AF_FORMAT_S16},
- {"u24", AF_FORMAT_U24},
{"s24", AF_FORMAT_S24},
- {"u32", AF_FORMAT_U32},
{"s32", AF_FORMAT_S32},
{"float", AF_FORMAT_FLOAT},
{"double", AF_FORMAT_DOUBLE},
@@ -169,8 +171,7 @@ int af_str2fmt_short(bstr str)
void af_fill_silence(void *dst, size_t bytes, int format)
{
- bool us = (format & AF_FORMAT_SIGN_MASK) == AF_FORMAT_US;
- memset(dst, us ? 0x80 : 0, bytes);
+ memset(dst, af_fmt_unsigned(format) ? 0x80 : 0, bytes);
}
#define FMT_DIFF(type, a, b) (((a) & type) - ((b) & type))
@@ -191,8 +192,6 @@ int af_format_conversion_score(int dst_format, int src_format)
int score = 1024;
if (FMT_DIFF(AF_FORMAT_INTERLEAVING_MASK, dst_format, src_format))
score -= 1; // has to (de-)planarize
- if (FMT_DIFF(AF_FORMAT_SIGN_MASK, dst_format, src_format))
- score -= 4; // has to swap sign
if (FMT_DIFF(AF_FORMAT_TYPE_MASK, dst_format, src_format)) {
int dst_bits = dst_format & AF_FORMAT_BITS_MASK;
if ((dst_format & AF_FORMAT_TYPE_MASK) == AF_FORMAT_F) {
diff --git a/audio/format.h b/audio/format.h
index c4e269f2f5..060b191c2b 100644
--- a/audio/format.h
+++ b/audio/format.h
@@ -26,11 +26,6 @@
#include "misc/bstr.h"
-// Signed/unsigned
-#define AF_FORMAT_SI (0<<0) // Signed
-#define AF_FORMAT_US (1<<0) // Unsigned
-#define AF_FORMAT_SIGN_MASK (1<<0)
-
// Bits used
// Some code assumes they're sorted by size.
#define AF_FORMAT_8BIT (0<<1)
@@ -64,22 +59,18 @@
enum af_format {
AF_FORMAT_UNKNOWN = 0,
- AF_FORMAT_U8 = AF_FORMAT_I|AF_FORMAT_US|AF_FORMAT_8BIT,
- AF_FORMAT_S8 = AF_FORMAT_I|AF_FORMAT_SI|AF_FORMAT_8BIT,
- AF_FORMAT_U16 = AF_FORMAT_I|AF_FORMAT_US|AF_FORMAT_16BIT,
- AF_FORMAT_S16 = AF_FORMAT_I|AF_FORMAT_SI|AF_FORMAT_16BIT,
- AF_FORMAT_U24 = AF_FORMAT_I|AF_FORMAT_US|AF_FORMAT_24BIT,
- AF_FORMAT_S24 = AF_FORMAT_I|AF_FORMAT_SI|AF_FORMAT_24BIT,
- AF_FORMAT_U32 = AF_FORMAT_I|AF_FORMAT_US|AF_FORMAT_32BIT,
- AF_FORMAT_S32 = AF_FORMAT_I|AF_FORMAT_SI|AF_FORMAT_32BIT,
+ AF_FORMAT_U8 = AF_FORMAT_I|AF_FORMAT_8BIT,
+ AF_FORMAT_S16 = AF_FORMAT_I|AF_FORMAT_16BIT,
+ AF_FORMAT_S24 = AF_FORMAT_I|AF_FORMAT_24BIT,
+ AF_FORMAT_S32 = AF_FORMAT_I|AF_FORMAT_32BIT,
AF_FORMAT_FLOAT = AF_FORMAT_F|AF_FORMAT_32BIT,
AF_FORMAT_DOUBLE = AF_FORMAT_F|AF_FORMAT_64BIT,
// Planar variants
- AF_FORMAT_U8P = AF_INTP|AF_FORMAT_US|AF_FORMAT_8BIT,
- AF_FORMAT_S16P = AF_INTP|AF_FORMAT_SI|AF_FORMAT_16BIT,
- AF_FORMAT_S32P = AF_INTP|AF_FORMAT_SI|AF_FORMAT_32BIT,
+ AF_FORMAT_U8P = AF_INTP|AF_FORMAT_8BIT,
+ AF_FORMAT_S16P = AF_INTP|AF_FORMAT_16BIT,
+ AF_FORMAT_S32P = AF_INTP|AF_FORMAT_32BIT,
AF_FORMAT_FLOATP = AF_FLTP|AF_FORMAT_32BIT,
AF_FORMAT_DOUBLEP = AF_FLTP|AF_FORMAT_64BIT,
@@ -113,6 +104,8 @@ int af_fmt2bps(int format);
int af_fmt2bits(int format);
int af_fmt_change_bits(int format, int bits);
+bool af_fmt_unsigned(int format);
+
int af_fmt_to_planar(int format);
int af_fmt_from_planar(int format);
diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c
index 6ff39ffcb2..1c4eaec139 100644
--- a/audio/out/ao_alsa.c
+++ b/audio/out/ao_alsa.c
@@ -204,14 +204,9 @@ alsa_error:
}
static const int mp_to_alsa_format[][2] = {
- {AF_FORMAT_S8, SND_PCM_FORMAT_S8},
{AF_FORMAT_U8, SND_PCM_FORMAT_U8},
- {AF_FORMAT_U16, SND_PCM_FORMAT_U16},
{AF_FORMAT_S16, SND_PCM_FORMAT_S16},
- {AF_FORMAT_U32, SND_PCM_FORMAT_U32},
{AF_FORMAT_S32, SND_PCM_FORMAT_S32},
- {AF_FORMAT_U24,
- MP_SELECT_LE_BE(SND_PCM_FORMAT_U24_3LE, SND_PCM_FORMAT_U24_3BE)},
{AF_FORMAT_S24,
MP_SELECT_LE_BE(SND_PCM_FORMAT_S24_3LE, SND_PCM_FORMAT_S24_3BE)},
{AF_FORMAT_FLOAT, SND_PCM_FORMAT_FLOAT},
diff --git a/audio/out/ao_coreaudio_utils.c b/audio/out/ao_coreaudio_utils.c
index b861fa3686..52b0e32194 100644
--- a/audio/out/ao_coreaudio_utils.c
+++ b/audio/out/ao_coreaudio_utils.c
@@ -177,7 +177,7 @@ static void ca_fill_asbd_raw(AudioStreamBasicDescription *asbd, int mp_format,
if ((mp_format & AF_FORMAT_TYPE_MASK) == AF_FORMAT_F) {
asbd->mFormatFlags |= kAudioFormatFlagIsFloat;
- } else if ((mp_format & AF_FORMAT_SIGN_MASK) == AF_FORMAT_SI) {
+ } else if (!af_fmt_unsigned(mp_format)) {
asbd->mFormatFlags |= kAudioFormatFlagIsSignedInteger;
}
diff --git a/audio/out/ao_oss.c b/audio/out/ao_oss.c
index bf320e9b65..bcb21aeffd 100644
--- a/audio/out/ao_oss.c
+++ b/audio/out/ao_oss.c
@@ -94,40 +94,20 @@ static const struct mp_chmap oss_layouts[MP_NUM_CHANNELS + 1] = {
#define AFMT_S16_NE MP_SELECT_LE_BE(AFMT_S16_LE, AFMT_S16_BE)
#endif
-#if !defined(AFMT_U16_NE) && defined(AFMT_U16_LE) && defined(AFMT_U16_BE)
-#define AFMT_U16_NE MP_SELECT_LE_BE(AFMT_U16_LE, AFMT_U16_BE)
-#endif
-
-#if !defined(AFMT_U24_NE) && defined(AFMT_U24_LE) && defined(AFMT_U24_BE)
-#define AFMT_U24_NE MP_SELECT_LE_BE(AFMT_U24_LE, AFMT_U24_BE)
-#endif
-
#if !defined(AFMT_S24_NE) && defined(AFMT_S24_LE) && defined(AFMT_S24_BE)
#define AFMT_S24_NE MP_SELECT_LE_BE(AFMT_S24_LE, AFMT_S24_BE)
#endif
-#if !defined(AFMT_U32_NE) && defined(AFMT_U32_LE) && defined(AFMT_U32_BE)
-#define AFMT_U32_NE AFMT_U32MP_SELECT_LE_BE(AFMT_U32_LE, AFMT_U32_BE)
-#endif
-
#if !defined(AFMT_S32_NE) && defined(AFMT_S32_LE) && defined(AFMT_S32_BE)
#define AFMT_S32_NE AFMT_S32MP_SELECT_LE_BE(AFMT_S32_LE, AFMT_S32_BE)
#endif
static const int format_table[][2] = {
{AFMT_U8, AF_FORMAT_U8},
- {AFMT_S8, AF_FORMAT_S8},
- {AFMT_U16_NE, AF_FORMAT_U16},
{AFMT_S16_NE, AF_FORMAT_S16},
-#ifdef AFMT_U24_NE
- {AFMT_U24_NE, AF_FORMAT_U24},
-#endif
#ifdef AFMT_S24_NE
{AFMT_S24_NE, AF_FORMAT_S24},
#endif
-#ifdef AFMT_U32_NE
- {AFMT_U32_NE, AF_FORMAT_U32},
-#endif
#ifdef AFMT_S32_NE
{AFMT_S32_NE, AF_FORMAT_S32},
#endif
diff --git a/audio/out/ao_rsound.c b/audio/out/ao_rsound.c
index ef1a00111a..0385b09cb8 100644
--- a/audio/out/ao_rsound.c
+++ b/audio/out/ao_rsound.c
@@ -48,26 +48,9 @@ static int set_format(struct ao *ao)
case AF_FORMAT_U8:
rsd_format = RSD_U8;
break;
- case AF_FORMAT_S8:
- rsd_format = RSD_S8;
- break;
- case AF_FORMAT_S16:
- rsd_format = RSD_S16_NE;
- break;
- case AF_FORMAT_U16:
- rsd_format = RSD_U16_NE;
- break;
- case AF_FORMAT_S24:
- case AF_FORMAT_U24:
- rsd_format = RSD_S32_NE;
- ao->format = AF_FORMAT_S32;
- break;
case AF_FORMAT_S32:
rsd_format = RSD_S32_NE;
break;
- case AF_FORMAT_U32:
- rsd_format = RSD_U32_NE;
- break;
default:
rsd_format = RSD_S16_NE;
ao->format = AF_FORMAT_S16;
diff --git a/audio/out/ao_sdl.c b/audio/out/ao_sdl.c
index c1ecff8f24..bf65a4a4d8 100644
--- a/audio/out/ao_sdl.c
+++ b/audio/out/ao_sdl.c
@@ -39,8 +39,6 @@ struct priv
static const int fmtmap[][2] = {
{AF_FORMAT_U8, AUDIO_U8},
- {AF_FORMAT_S8, AUDIO_S8},
- {AF_FORMAT_U16, AUDIO_U16SYS},
{AF_FORMAT_S16, AUDIO_S16SYS},
#ifdef AUDIO_S32SYS
{AF_FORMAT_S32, AUDIO_S32SYS},
diff --git a/audio/out/ao_sndio.c b/audio/out/ao_sndio.c
index abce0efd36..f192ef98b5 100644
--- a/audio/out/ao_sndio.c
+++ b/audio/out/ao_sndio.c
@@ -116,12 +116,8 @@ static int init(struct ao *ao)
};
static const struct af_to_par af_to_par[] = {
{AF_FORMAT_U8, 8, 0},
- {AF_FORMAT_S8, 8, 1},
- {AF_FORMAT_U16, 16, 0},
{AF_FORMAT_S16, 16, 1},
- {AF_FORMAT_U24, 24, 0},
{AF_FORMAT_S24, 24, 1},
- {AF_FORMAT_U32, 32, 0},
{AF_FORMAT_S32, 32, 1},
};
const struct af_to_par *ap;
@@ -178,14 +174,14 @@ static int init(struct ao *ao)
MP_ERR(ao, "swapped endian output not supported\n");
goto error;
}
- if (p->par.bits == 8 && p->par.bps == 1) {
- ao->format = p->par.sig ? AF_FORMAT_S8 : AF_FORMAT_U8;
- } else if (p->par.bits == 16 && p->par.bps == 2) {
- ao->format = p->par.sig ? AF_FORMAT_S16 : AF_FORMAT_U16;
- } else if ((p->par.bits == 24 || p->par.msb) && p->par.bps == 3) {
- ao->format = p->par.sig ? AF_FORMAT_S24 : AF_FORMAT_U24;
- } else if ((p->par.bits == 32 || p->par.msb) && p->par.bps == 4) {
- ao->format = p->par.sig ? AF_FORMAT_S32 : AF_FORMAT_U32;
+ if (p->par.bits == 8 && p->par.bps == 1 && !p->par.sig) {
+ ao->format = AF_FORMAT_U8;
+ } else if (p->par.bits == 16 && p->par.bps == 2 && p->par.sig) {
+ ao->format = AF_FORMAT_S16;
+ } else if ((p->par.bits == 24 || p->par.msb) && p->par.bps == 3 && p->par.sig) {
+ ao->format = AF_FORMAT_S24;
+ } else if ((p->par.bits == 32 || p->par.msb) && p->par.bps == 4 && p->par.sig) {
+ ao->format = AF_FORMAT_S32;
} else {
MP_ERR(ao, "couldn't set format\n");
goto error;
diff --git a/wscript_build.py b/wscript_build.py
index 26d622a9d9..76be30cde8 100644
--- a/wscript_build.py
+++ b/wscript_build.py
@@ -104,7 +104,6 @@ def build(ctx):
( "audio/filter/af_center.c" ),
( "audio/filter/af_channels.c" ),
( "audio/filter/af_convert24.c" ),
- ( "audio/filter/af_convertsignendian.c" ),
( "audio/filter/af_delay.c" ),
( "audio/filter/af_drc.c" ),
( "audio/filter/af_dummy.c" ),