xbmc/xbmc — pull request #3074 by ecopoesis (2013-08-07 20:27:52+00:00)
Title: transcoding to AC3 for CoreAudio

Adds transcoding of multichannel audio to AC3 for the CoreAudioEngine.

Basic strategy is to detect is transcoding is needed and possible in CoreAudioAE when MakeStream is called. If transcoding is called for, that gets passed to OpenCoreAudio and changes how the CoreAudioAE object is setup.

The transcoding is triggered in CoreAudioAEStream. It uses the preexisting AEEncoderFFmpeg class that SoftAE uses for the same purpose. In CoreAudioAEStream, transcoded audio is mostly treated like passthrough audio.

Trickest bit CareAudioAEStream is the addition of a buffer for incoming audio that needs to be encoded. The encoder needs to work in specific block sizes, and the incoming stream is not always handed to us in appropriate chunks so we need to buffer it up so we can process it. This required a little fiddling with the delays to make sure sync was kept tight.

I've tested this on Mac mini (mid-2010) running 10.8.4 with both a Denon receiver and a Sonos Playbar, both over HDMI that has its audio stripped out to optical.

I've testing the following formats and everything works as I'd expect:

AC3 Enabled:
AC3 2ch -> passthrough
DTS 2ch -> PCM 2ch
MP3 2ch -> PCM 2ch
AAC 2ch -> PCM 2ch
AC3 5.1 -> passthrough
DTS 5.1 -> transcoded to AC3 5.1
AAC 5.1 -> transcoded to AC3 5.1
DTS-MA 5.1 -> transcoded to AC3 5.1
Dolby True 5.1 -> transcoded to AC3 5.1 (I think we should be able to strip the AC3 out of this stream and pass that through, but the existing code didn't do that either, it just decoded to PCM 5.1)

AC3 and DTS Enabled:

AC3 2ch -> passthrough
DTS 2ch -> passthrough
MP3 2ch -> PCM 2ch
AAC 2ch -> PCM 2ch
AC3 5.1 -> passthrough
DTS 5.1 -> passthrough
AAC 5.1 -> transcoded to AC3 5.1
DTS-MA 5.1 -> passthrough
Dolby True 5.1 -> transcoded to AC3 5.1