Skip to content

Commit

Permalink
Offer a 7.1 downmix audio type for files with more then 8 channels of…
Browse files Browse the repository at this point in the history
… audio

Fixes AAC 22.2 channel playback (GitHub Nevcairiel#477)
  • Loading branch information
Nevcairiel committed Aug 23, 2022
1 parent 8e3fcaf commit c2461ad
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions decoder/LAVAudio/LAVAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,11 @@ HRESULT CLAVAudio::GetMediaType(int iPosition, CMediaType *pMediaType)

if (dwChannelMask == AV_CH_LAYOUT_5POINT1 && iPosition > 1 && iPosition < 4)
dwChannelMask = AV_CH_LAYOUT_5POINT1_BACK;
else if (nChannels > 8 && iPosition > 1 && iPosition < 4) // more then 8 channel, offer a downmix to 8 channel
{
nChannels = 8;
dwChannelMask = AV_CH_LAYOUT_7POINT1;
}
else if (iPosition > 1)
return VFW_S_NO_MORE_ITEMS;

Expand Down Expand Up @@ -2765,6 +2770,33 @@ HRESULT CLAVAudio::Deliver(BufferDetails &buffer)
buffer.wBitsPerSample);
goto retry_qa;
}
// more then 8 channel, try 7.1 fallback format
if (buffer.layout.nb_channels > 8)
{
DbgLog((LOG_TRACE, 1, L"-> Trying to fallback to 7.1 (have more then 8 channel)"));
mt = CreateMediaType(buffer.sfFormat, buffer.dwSamplesPerSec, 8,
(DWORD)AV_CH_LAYOUT_7POINT1, buffer.wBitsPerSample);

hr = m_pOutput->GetConnected()->QueryAccept(&mt);

if (hr != S_OK)
{
mt = CreateMediaType(SampleFormat_16, buffer.dwSamplesPerSec, 8, AV_CH_LAYOUT_7POINT1, 16);
hr = m_pOutput->GetConnected()->QueryAccept(&mt);
if (hr == S_OK)
m_FallbackFormat = SampleFormat_16;
}

if (hr == S_OK)
{
DbgLog((LOG_TRACE, 1, L"-> Override Mixing to layout to 7.1"));
av_channel_layout_uninit(&m_chOverrideMixer);
av_channel_layout_from_mask(&m_chOverrideMixer, AV_CH_LAYOUT_7POINT1);
m_bMixingSettingsChanged = TRUE;
// Mix to the new layout
PerformAVRProcessing(&buffer);
}
}
// If a 16-bit fallback isn't enough, try to retain current channel layout as well
if (hr != S_OK)
{
Expand Down

0 comments on commit c2461ad

Please sign in to comment.