[omxplayer] Make use of audio decode fast paths when downmixing
authorpopcornmix <popcornmix@gmail.com>
Thu, 13 Mar 2014 16:08:46 +0000 (16:08 +0000)
committerpopcornmix <popcornmix@gmail.com>
Wed, 9 Jul 2014 20:08:41 +0000 (21:08 +0100)
The TrueHD codec actually works in 3 stages.
It decodes the downmixed stereo.
It then decodes the differences required to produce 5.1.
It then decodes the differences required to produce 7.1.

Many users end up downmixing this 7.1 stream back to 2.0.
Much better to tell the codec we only need the 2.0 stream.

When playing a 94s duration video file on an overclocked Pi, the audio decode took:
7.1 channels: 39.6s
5.1 channels: 36.5s
2.0 channels: 23.0s

So, it's almost twice as fast to decode TrueHD when only stereo is required.

xbmc/cores/omxplayer/OMXAudioCodecOMX.cpp

index bb3bea4..ffbaf56 100644 (file)
@@ -25,6 +25,7 @@
 #include "utils/log.h"
 
 #include "cores/AudioEngine/Utils/AEUtil.h"
+#include "cores/AudioEngine/AEFactory.h"
 
 // the size of the audio_render output port buffers
 #define AUDIO_DECODE_OUTPUT_BUFFER (32*1024)
@@ -86,6 +87,15 @@ bool COMXAudioCodecOMX::Open(CDVDStreamInfo &hints)
   m_pCodecContext->block_align = hints.blockalign;
   m_pCodecContext->bit_rate = hints.bitrate;
   m_pCodecContext->bits_per_coded_sample = hints.bitspersample;
+  if (hints.codec == AV_CODEC_ID_TRUEHD)
+  {
+    if (CAEFactory::HasStereoAudioChannelCount())
+      m_pCodecContext->request_channel_layout = AV_CH_LAYOUT_STEREO;
+    else if (!CAEFactory::HasHDAudioChannelCount())
+      m_pCodecContext->request_channel_layout = AV_CH_LAYOUT_5POINT1;
+  }
+  if (m_pCodecContext->request_channel_layout)
+    CLog::Log(LOGNOTICE,"COMXAudioCodecOMX::Open() Requesting channel layout of %x", (unsigned)m_pCodecContext->request_channel_layout);
 
   // vorbis has variable sized planar output, so skip concatenation
   if (hints.codec == AV_CODEC_ID_VORBIS)