Playing AAC multichannel (5.1 surround) audio stream on Apple TV

I have written a tvOS app which receives AAC 5.1 audio stream over the network and I am using AudioToolbox to decode (mFormatID = kAudioFormatMPEGAAC) to 5.1 channels. But I only hear 2 channels (Stereo) outputs on my 5.1 surround system (which is connected to the TV using an Audio Optical cable).

I am not sure why PCM multi-channel is not outputting from AppleTV. Am I missing anything?

Decoder parameters:

    AudioStreamBasicDescription asbd
= {0};

    asbd.mFormatID =
kAudioFormatMPEG4AAC;

    asbd.mFormatFlags =
kMPEG4Object_AAC_Main;

    asbd.mSampleRate = samplingRate;

    asbd.mBitsPerChannel = 0;

    asbd.mBytesPerPacket = 0; 

    asbd.mFramesPerPacket = 1024;

    asbd.mBytesPerFrame = 0;。

    asbd.mChannelsPerFrame = numOfChannels; // 6

    asbd.mBitsPerChannel = 0; 

    asbd.mReserved = 0; 

Additionally, when I query the total number of audio channels on AppleTV, it is always 2 (even though it is connected to the surround system). This is just for me to know audio capabilities.

AVAudioSession.sharedInstance().currentRoute.outputs[0].channels

An optical cable haven't got enough bandwidth to transmit 6 channels of PCM audio. It can only do 6 channels of AC3 or DTS.

I don't remember if the AppleTV will automatically convert it to AC3 if you set it to do so in the AppleTV settings.

Playing AAC multichannel (5.1 surround) audio stream on Apple TV
 
 
Q