summaryrefslogtreecommitdiffstats
path: root/audio/filter/af_lavcac3enc.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-09-23 19:34:14 +0200
committerwm4 <wm4@nowhere>2014-09-23 19:34:14 +0200
commit5b5a3d0c469fa5e282b60eb9ac2b7e4414640d80 (patch)
tree76c5f217ee981d969627e2e26f924e2ade1684d9 /audio/filter/af_lavcac3enc.c
parent1f4a74cbed9a631fc86d332e0869decb47f33be2 (diff)
downloadmpv-5b5a3d0c469fa5e282b60eb9ac2b7e4414640d80.tar.bz2
mpv-5b5a3d0c469fa5e282b60eb9ac2b7e4414640d80.tar.xz
audio: remove swapped-endian spdif formats
IEC 61937 frames should always be little endian (little endian 16 bit words). I don't see any apparent need why the audio chain should handle swapped-endian formats. It could be that some audio outputs might want them (especially on big endian architectures). On the other hand, it's not clear how that works on these architectures, and it's not even known whether the current code works on big endian at all. If something should break, and it should turn out that swapped-endian spdif is needed on any platform/AO, swapping still could be done in-place within the affected AO, and there's no need for the additional complexity in the rest of the player. Note that af_lavcac3enc outputs big endian spdif frames for unknown reasons. Normally, the resulting data is just pulled through an auto- inserted conversion filter and turned into little endian. Maybe this was done as a trick so that the code didn't have to byte-swap the actual audio frame. In any case, just make it output little endian frames. All of this is untested, because I have no receiver hardware.
Diffstat (limited to 'audio/filter/af_lavcac3enc.c')
-rw-r--r--audio/filter/af_lavcac3enc.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/audio/filter/af_lavcac3enc.c b/audio/filter/af_lavcac3enc.c
index 8c34b417af..0763057665 100644
--- a/audio/filter/af_lavcac3enc.c
+++ b/audio/filter/af_lavcac3enc.c
@@ -30,6 +30,7 @@
#include <libavutil/audioconvert.h>
#include <libavutil/intreadwrite.h>
#include <libavutil/common.h>
+#include <libavutil/bswap.h>
#include <libavutil/mem.h>
#include "common/common.h"
@@ -87,7 +88,7 @@ static int control(struct af_instance *af, int cmd, void *arg)
if (in->nch > AC3_MAX_CHANNELS)
mp_audio_set_num_channels(in, AC3_MAX_CHANNELS);
- mp_audio_set_format(af->data, AF_FORMAT_AC3_BE);
+ mp_audio_set_format(af->data, AF_FORMAT_AC3);
mp_audio_set_num_channels(af->data, 2);
if (!mp_audio_config_equals(in, &orig_in))
@@ -150,6 +151,12 @@ static void uninit(struct af_instance* af)
}
}
+static void swap_16(uint16_t *ptr, size_t size)
+{
+ for (size_t n = 0; n < size; n++)
+ ptr[n] = av_bswap16(ptr[n]);
+}
+
// Filter data through filter
static int filter(struct af_instance* af, struct mp_audio* audio, int flags)
{
@@ -223,11 +230,11 @@ static int filter(struct af_instance* af, struct mp_audio* audio, int flags)
frame_size = AC3_FRAME_SIZE * 2 * 2;
header_len = 8;
- AV_WB16(hdr, 0xF872); // iec 61937 syncword 1
- AV_WB16(hdr + 2, 0x4E1F); // iec 61937 syncword 2
+ AV_WL16(hdr, 0xF872); // iec 61937 syncword 1
+ AV_WL16(hdr + 2, 0x4E1F); // iec 61937 syncword 2
hdr[4] = bsmod; // bsmod
hdr[5] = 0x01; // data-type ac3
- AV_WB16(hdr + 6, len << 3); // number of bits in payload
+ AV_WL16(hdr + 6, len << 3); // number of bits in payload
}
size_t max_size = (max_out_samples - out->samples) * out->sstride;
@@ -239,6 +246,7 @@ static int filter(struct af_instance* af, struct mp_audio* audio, int flags)
memcpy(buf + header_len, s->pkt.data, s->pkt.size);
memset(buf + header_len + s->pkt.size, 0,
frame_size - (header_len + s->pkt.size));
+ swap_16((uint16_t *)(buf + header_len), s->pkt.size / 2);
out->samples += frame_size / out->sstride;
}