xbmc/xbmc — pull request #973 by anssih (2012-05-17 18:49:39+00:00)
Title: [AE] Fix issues related to endianness in passthrough

Currently the code assumes that the sink takes S16_NE when performing passthrough. However, this may not be the case, and especially on big-endian systems the sink may want S16_LE instead (if the audio hardware / API takes that instead of S16_BE).

Byteswapping is currently performed by AEPackIEC61937 on little-endian systems to get the IEC 61937 data from the standard format to S16_LE byteswapped format. This is done because S16_LE audio hardware will byteswap the data (as IEC958 is big-endian) and it will return to the original raw format.

Optimally, when outputting to a S16_BE device, no byteswap should be performed, and when outputting to a S16_LE device, one byteswap should be performed. The best place to do that is the packetizer, because it knows what part of the stream is zero padding (and there can be lots of padding) which doesn't need to be byteswapped.

Unfortunately, our packetizer doesn't know what the endianness of the output sink is (as packetization happens in the player already). Therefore this patchset adds additional byteswap at engine/sink level, which will be triggered when output device has a non-system endianness.

This patchset only makes the byteswap happen when using the ALSA sink, however, previously I've seen also big-endian osx-ppc systems needing S16_LE passthrough with CoreAudio. That platform is no longer supported, though. and the CoreAudio code has changed a bit (due to AE switch), so I'm not sure if we need to do something to allow proper (non-"DD-Wav") passthrough using kAudioFormat60958AC3 on big-endian CoreAudio systems - I guess it doesn't matter since we don't have such systems. The IOS code seems to not use kAudioFormat60958AC3 at all.

Also fixed are some DTS passthrough issues (passthrough of LE DTS, pre-padded DTS, and crash on invalid DTS), see the commit log for more info about that. (similar crash issues due to improper validation seem to exist for other passthrough formats as well, will look at those later)

This PR adds a new file (xbmc/utils/EndianSwap.cpp), so win32/osx buildsystem will need an update.

I'm not 100% sure if I've done all the stuff the way the AE people want it, so please do give suggestions if you have those.