Skip to content

Commit 2e32cc0

Browse files
committed
Fix for channel count when using request_channel_layout with TrueHD
1 parent 1c8a3ef commit 2e32cc0

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

OMXAudio.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,15 @@ bool COMXAudio::PortSettingsChanged()
386386
return true;
387387
}
388388

389-
bool COMXAudio::Initialize(const CStdString& device, int iChannels, uint64_t channelMap,
389+
static unsigned count_bits(uint64_t value)
390+
{
391+
unsigned bits = 0;
392+
for(;value;++bits)
393+
value &= value - 1;
394+
return bits;
395+
}
396+
397+
bool COMXAudio::Initialize(const CStdString& device, uint64_t channelMap,
390398
COMXStreamInfo &hints, enum PCMLayout layout, unsigned int uiSampleRate, unsigned int uiBitsPerSample, bool boostOnDownmix,
391399
OMXClock *clock, bool bUsePassthrough, bool bUseHWDecode, bool is_live, float fifo_size)
392400
{
@@ -401,7 +409,7 @@ bool COMXAudio::Initialize(const CStdString& device, int iChannels, uint64_t cha
401409
m_deviceuse = device;
402410
m_HWDecode = bUseHWDecode;
403411
m_Passthrough = bUsePassthrough;
404-
m_InputChannels = iChannels;
412+
m_InputChannels = count_bits(channelMap);
405413
m_fifo_size = fifo_size;
406414
m_normalize_downmix = !boostOnDownmix;
407415
m_live = is_live;
@@ -463,7 +471,7 @@ bool COMXAudio::Initialize(const CStdString& device, int iChannels, uint64_t cha
463471
m_OutputChannels = BuildChannelMapCEA(outLayout, GetChannelLayout(layout));
464472
CPCMRemap m_remap;
465473
m_remap.Reset();
466-
/*outLayout = */m_remap.SetInputFormat (iChannels, inLayout, uiBitsPerSample / 8, uiSampleRate, layout, boostOnDownmix);
474+
/*outLayout = */m_remap.SetInputFormat (m_InputChannels, inLayout, uiBitsPerSample / 8, uiSampleRate, layout, boostOnDownmix);
467475
m_remap.SetOutputFormat(m_OutputChannels, outLayout);
468476
m_remap.GetDownmixMatrix(m_downmix_matrix);
469477
m_wave_header.dwChannelMask = channelMap;

OMXAudio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class COMXAudio
5959
unsigned int GetAudioRenderingLatency();
6060
float GetMaxLevel(double &pts);
6161
COMXAudio();
62-
bool Initialize(const CStdString& device, int iChannels, uint64_t channelMap,
62+
bool Initialize(const CStdString& device, uint64_t channelMap,
6363
COMXStreamInfo &hints, enum PCMLayout layout, unsigned int uiSamplesPerSec, unsigned int uiBitsPerSample, bool boostOnDownmix,
6464
OMXClock *clock, bool bUsePassthrough = false, bool bUseHWDecode = false, bool is_live = false, float fifo_size = 0);
6565
~COMXAudio();

OMXAudioCodecOMX.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ COMXAudioCodecOMX::~COMXAudioCodecOMX()
5959
Dispose();
6060
}
6161

62-
bool COMXAudioCodecOMX::Open(COMXStreamInfo &hints)
62+
bool COMXAudioCodecOMX::Open(COMXStreamInfo &hints, enum PCMLayout layout)
6363
{
6464
AVCodec* pCodec;
6565
m_bOpenedCodec = false;
@@ -91,21 +91,27 @@ bool COMXAudioCodecOMX::Open(COMXStreamInfo &hints)
9191
m_pCodecContext->block_align = hints.blockalign;
9292
m_pCodecContext->bit_rate = hints.bitrate;
9393
m_pCodecContext->bits_per_coded_sample = hints.bitspersample;
94-
95-
// vorbis has variable sized planar output, so skip concatenation
96-
if (hints.codec == AV_CODEC_ID_VORBIS)
97-
m_bNoConcatenate = true;
98-
99-
enum PCMLayout layout = PCM_LAYOUT_2_0;// todo: fill in
10094
if (hints.codec == AV_CODEC_ID_TRUEHD)
10195
{
10296
if (layout == PCM_LAYOUT_2_0)
97+
{
10398
m_pCodecContext->request_channel_layout = AV_CH_LAYOUT_STEREO;
99+
m_pCodecContext->channels = 2;
100+
m_pCodecContext->channel_layout = m_dllAvUtil.av_get_default_channel_layout(m_pCodecContext->channels);
101+
}
104102
else if (layout <= PCM_LAYOUT_5_1)
103+
{
105104
m_pCodecContext->request_channel_layout = AV_CH_LAYOUT_5POINT1;
105+
m_pCodecContext->channels = 6;
106+
m_pCodecContext->channel_layout = m_dllAvUtil.av_get_default_channel_layout(m_pCodecContext->channels);
107+
}
106108
}
107109
if (m_pCodecContext->request_channel_layout)
108-
CLog::Log(LOGNOTICE,"COMXAudioCodecOMX::Open() Requesting channel layout of %d", (unsigned)m_pCodecContext->request_channel_layout);
110+
CLog::Log(LOGNOTICE,"COMXAudioCodecOMX::Open() Requesting channel layout of %x", (unsigned)m_pCodecContext->request_channel_layout);
111+
112+
// vorbis has variable sized planar output, so skip concatenation
113+
if (hints.codec == AV_CODEC_ID_VORBIS)
114+
m_bNoConcatenate = true;
109115

110116
if(m_pCodecContext->bits_per_coded_sample == 0)
111117
m_pCodecContext->bits_per_coded_sample = 16;

OMXAudioCodecOMX.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class COMXAudioCodecOMX
3535
public:
3636
COMXAudioCodecOMX();
3737
~COMXAudioCodecOMX();
38-
bool Open(COMXStreamInfo &hints);
38+
bool Open(COMXStreamInfo &hints, enum PCMLayout layout);
3939
void Dispose();
4040
int Decode(BYTE* pData, int iSize, double dts, double pts);
4141
int GetData(BYTE** dst, double &dts, double &pts);

OMXPlayerAudio.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ bool OMXPlayerAudio::OpenAudioCodec()
389389
{
390390
m_pAudioCodec = new COMXAudioCodecOMX();
391391

392-
if(!m_pAudioCodec->Open(m_hints))
392+
if(!m_pAudioCodec->Open(m_hints, m_layout))
393393
{
394394
delete m_pAudioCodec; m_pAudioCodec = NULL;
395395
return false;
@@ -443,7 +443,7 @@ bool OMXPlayerAudio::OpenDecoder()
443443
if(m_passthrough)
444444
m_hw_decode = false;
445445

446-
bAudioRenderOpen = m_decoder->Initialize(m_device, m_hints.channels, m_pAudioCodec->GetChannelMap(),
446+
bAudioRenderOpen = m_decoder->Initialize(m_device, m_pAudioCodec->GetChannelMap(),
447447
m_hints, m_layout, m_hints.samplerate, m_pAudioCodec->GetBitsPerSample(), m_boost_on_downmix,
448448
m_av_clock, m_passthrough, m_hw_decode, m_live, m_fifo_size);
449449

0 commit comments

Comments
 (0)