summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-09-23 21:04:37 +0200
committerwm4 <wm4@nowhere>2014-09-23 23:09:25 +0200
commitb745c2d0050468580aec0a4e12aec854fefd1796 (patch)
tree0df9a9f56b339cabc68376840b4d283b848acdf8 /demux
parent5b5a3d0c469fa5e282b60eb9ac2b7e4414640d80 (diff)
downloadmpv-b745c2d0050468580aec0a4e12aec854fefd1796.tar.bz2
mpv-b745c2d0050468580aec0a4e12aec854fefd1796.tar.xz
audio: drop swapped-endian audio formats
Until now, the audio chain could handle both little endian and big endian formats. This actually doesn't make much sense, since the audio API and the HW will most likely prefer native formats. Or at the very least, it should be trivial for audio drivers to do the byte swapping themselves. From now on, the audio chain contains native-endian formats only. All AOs and some filters are adjusted. af_convertsignendian.c is now wrongly named, but the filter name is adjusted. In some cases, the audio infrastructure was reused on the demuxer side, but that is relatively easy to rectify. This is a quite intrusive and radical change. It's possible that it will break some things (especially if they're obscure or not Linux), so watch out for regressions. It's probably still better to do it the bulldozer way, since slow transition and researching foreign platforms would take a lot of time and effort.
Diffstat (limited to 'demux')
-rw-r--r--demux/demux_raw.c10
-rw-r--r--demux/demux_tv.c13
-rw-r--r--demux/stheader.h1
3 files changed, 17 insertions, 7 deletions
diff --git a/demux/demux_raw.c b/demux/demux_raw.c
index 288a1c931c..5dae30308a 100644
--- a/demux/demux_raw.c
+++ b/demux/demux_raw.c
@@ -34,10 +34,13 @@
#include "video/img_format.h"
#include "video/img_fourcc.h"
+#include "osdep/endian.h"
+
struct demux_rawaudio_opts {
struct mp_chmap channels;
int samplerate;
int aformat;
+ int endian;
};
#define OPT_BASE_STRUCT struct demux_rawaudio_opts
@@ -46,13 +49,16 @@ const struct m_sub_options demux_rawaudio_conf = {
OPT_CHMAP("channels", channels, CONF_MIN, .min = 1),
OPT_INTRANGE("rate", samplerate, 0, 1000, 8 * 48000),
OPT_AUDIOFORMAT("format", aformat, 0),
+ OPT_CHOICE("endian", endian, 0, ({"native", 0}, {"le", 1}, {"be", 2})),
{0}
},
.size = sizeof(struct demux_rawaudio_opts),
.defaults = &(const struct demux_rawaudio_opts){
+ // Note that currently, stream_cdda expects exactly these parameters!
.channels = MP_CHMAP_INIT_STEREO,
.samplerate = 44100,
.aformat = AF_FORMAT_S16,
+ .endian = 0,
},
};
@@ -121,6 +127,10 @@ static int demux_rawaudio_open(demuxer_t *demuxer, enum demux_check check)
w->nBlockAlign = w->nChannels * samplesize;
w->wBitsPerSample = 8 * samplesize;
w->cbSize = 0;
+ int machine_endian = BYTE_ORDER == BIG_ENDIAN ? 2 : 1;
+ int endian = opts->endian ? opts->endian : machine_endian;
+ // wav usually implies little endian
+ sh_audio->big_endian = endian == 2;
struct priv *p = talloc_ptrtype(demuxer, p);
demuxer->priv = p;
diff --git a/demux/demux_tv.c b/demux/demux_tv.c
index fe7584a387..a4421a86cf 100644
--- a/demux/demux_tv.c
+++ b/demux/demux_tv.c
@@ -11,6 +11,7 @@
#include "audio/format.h"
#include "video/img_fourcc.h"
+#include "osdep/endian.h"
#include "stream/stream.h"
#include "stream/tv.h"
@@ -106,14 +107,10 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check)
{
case AF_FORMAT_U8:
case AF_FORMAT_S8:
- case AF_FORMAT_U16_LE:
- case AF_FORMAT_U16_BE:
- case AF_FORMAT_S16_LE:
- case AF_FORMAT_S16_BE:
- case AF_FORMAT_S32_LE:
- case AF_FORMAT_S32_BE:
+ case AF_FORMAT_U16:
+ case AF_FORMAT_S16:
+ case AF_FORMAT_S32:
break;
- case AF_FORMAT_MPEG2:
default:
MP_ERR(tvh, "Audio type '%s' unsupported!\n",
af_fmt_to_str(audio_format));
@@ -147,6 +144,8 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check)
sh_audio->wf->nSamplesPerSec = sh_audio->samplerate;
sh_audio->wf->nBlockAlign = block_align;
sh_audio->wf->nAvgBytesPerSec = bytes_per_second;
+ // wav header usually implies little endian
+ sh_audio->big_endian = BYTE_ORDER == BIG_ENDIAN;
MP_VERBOSE(tvh, " TV audio: %d channels, %d bits, %d Hz\n",
sh_audio->wf->nChannels, sh_audio->wf->wBitsPerSample,
diff --git a/demux/stheader.h b/demux/stheader.h
index af1e7bb44a..806f7d9c5a 100644
--- a/demux/stheader.h
+++ b/demux/stheader.h
@@ -70,6 +70,7 @@ typedef struct sh_audio {
int bitrate; // compressed bits/sec
// win32-compatible codec parameters:
MP_WAVEFORMATEX *wf;
+ bool big_endian; // endianess with wf and mp-pcm
// note codec extradata may be either under "wf" or "codecdata"
unsigned char *codecdata;
int codecdata_len;