Skip to content

Commit

Permalink
[AE] drop AE_FMT_LPCM from non-CoreAudio builds
Browse files Browse the repository at this point in the history
AE has a separate AEDataFormat AE_FMT_LPCM for multichannel PCM audio.
However, the data content is actually the same as AE_FMT_FLOAT, and
AE_FMT_LPCM is only used by CoreAudioAE.

CoreAudio uses the AE_FMT_FLOAT <=> AE_FMT_LPCM differentation to enter
a special "hog" mode, which is reportedly needed for multichannel HDMI
playback on CoreAudio. AE_FMT_LPCM mode is entered on CoreAudio systems
instead of AE_FMT_FLOAT (or other regular modes) when the multichannel
LPCM playback option is enabled in audio settings and the output device
type is HDMI.

Since AE_FMT_LPCM has no meaning outside CoreAudio, clearly mark it as
CoreAudio specific by making it conditional on TARGET_DARWIN, to avoid
confusion regarding the actual use case of that format type.

AE_FMT_LPCM is currently also added in device enumeration to
m_dataFormats on ALSA devices when the HDMI sink EDID contains a Short
Audio Descriptor with audio code 1 (LPCM). However, that makes no sense,
since the audio code simply means that the device accepts PCM input,
which all HDMI audio devices have to (obviously) support according to
the specification. Also, AESinkWASAPI adds AE_FMT_LPCM to m_dataFormats
for devices with 4+ channels, which is pointless as there is a separate
m_channelLayout member in AEAudioFormat for this purpose.
Both of these can be safely removed since m_dataFormats is used for
debug log purposes only (any actual users should use m_channelLayout
instead, which works with all sinks).

In the future CoreAudio could probably be changed to enter hog mode
based on the stream channel count directly, in order to avoid having a
special CoreAudio-specific format and related code in general
AudioEngine part.
  • Loading branch information
anssih committed Sep 30, 2012
1 parent 42bdcd7 commit e720a28
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
4 changes: 3 additions & 1 deletion xbmc/cores/AudioEngine/AEAudioFormat.h
Expand Up @@ -59,7 +59,9 @@ enum AEDataFormat
AE_FMT_EAC3,
AE_FMT_TRUEHD,
AE_FMT_DTSHD,
AE_FMT_LPCM,
#ifdef TARGET_DARWIN
AE_FMT_LPCM, /* used for the CoreAudio-specific multichannel hog mode; data is identical to AE_FMT_FLOAT */
#endif

AE_FMT_MAX
};
Expand Down
17 changes: 0 additions & 17 deletions xbmc/cores/AudioEngine/Sinks/AESinkWASAPI.cpp
Expand Up @@ -757,8 +757,6 @@ void CAESinkWASAPI::EnumerateDevicesEx(AEDeviceInfoList &deviceInfoList)
wfxex.Format.nBlockAlign = wfxex.Format.nChannels * (wfxex.Format.wBitsPerSample >> 3);
wfxex.Format.nAvgBytesPerSec = wfxex.Format.nSamplesPerSec * wfxex.Format.nBlockAlign;

bool hasLpcm = false;

// Try with KSAUDIO_SPEAKER_DIRECTOUT
for (unsigned int k = WASAPI_SPEAKER_COUNT; k > 0; k--)
{
Expand All @@ -769,11 +767,6 @@ void CAESinkWASAPI::EnumerateDevicesEx(AEDeviceInfoList &deviceInfoList)
hr = pClient->IsFormatSupported(AUDCLNT_SHAREMODE_EXCLUSIVE, &wfxex.Format, NULL);
if (SUCCEEDED(hr))
{
if (k > 3) // Add only multichannel LPCM
{
deviceInfo.m_dataFormats.push_back(AE_FMT_LPCM);
hasLpcm = true;
}
break;
}
}
Expand All @@ -788,11 +781,6 @@ void CAESinkWASAPI::EnumerateDevicesEx(AEDeviceInfoList &deviceInfoList)
hr = pClient->IsFormatSupported(AUDCLNT_SHAREMODE_EXCLUSIVE, &wfxex.Format, NULL);
if (SUCCEEDED(hr))
{
if ( !hasLpcm && k > 3) // Add only multichannel LPCM
{
deviceInfo.m_dataFormats.push_back(AE_FMT_LPCM);
hasLpcm = true;
}
break;
}
}
Expand All @@ -810,11 +798,6 @@ void CAESinkWASAPI::EnumerateDevicesEx(AEDeviceInfoList &deviceInfoList)
{
if ( deviceChannels.Count() < nmbOfCh)
deviceChannels = layoutsList[i];
if ( !hasLpcm && nmbOfCh > 3) // Add only multichannel LPCM
{
deviceInfo.m_dataFormats.push_back(AE_FMT_LPCM);
hasLpcm = true;
}
}
}
pClient->Release();
Expand Down
1 change: 0 additions & 1 deletion xbmc/cores/AudioEngine/Utils/AEELDParser.cpp
Expand Up @@ -194,7 +194,6 @@ void CAEELDParser::Parse(const uint8_t *data, size_t length, CAEDeviceInfo& info
case CEA_861_FORMAT_DTS : fmt = AE_FMT_DTS ; break;
case CEA_861_FORMAT_DTSHD: fmt = AE_FMT_DTSHD ; break;
case CEA_861_FORMAT_EAC3 : fmt = AE_FMT_EAC3 ; break;
case CEA_861_FORMAT_LPCM : fmt = AE_FMT_LPCM ; break;
case CEA_861_FORMAT_MLP : fmt = AE_FMT_TRUEHD; break;

This comment has been minimized.

Copy link
@davilla

davilla Sep 30, 2012

what is this ?

This comment has been minimized.

Copy link
@anssih

anssih Sep 30, 2012

Author Owner

From commit log:
AE_FMT_LPCM is currently also added in device enumeration to
m_dataFormats on ALSA devices when the HDMI sink EDID contains a Short
Audio Descriptor with audio code 1 (LPCM). However, that makes no sense,
since the audio code simply means that the device accepts PCM input,
which all HDMI audio devices have to (obviously) support according to
the specification.

As noted, this is used for debug.log purposes only.

}

Expand Down
4 changes: 4 additions & 0 deletions xbmc/cores/AudioEngine/Utils/AEUtil.cpp
Expand Up @@ -106,7 +106,9 @@ const unsigned int CAEUtil::DataFormatToBits(const enum AEDataFormat dataFormat)
16, /* EAC3 */
16, /* TRUEHD */
16, /* DTS-HD */
#ifdef TARGET_DARWIN
32 /* LPCM */
#endif
};

return formats[dataFormat];
Expand Down Expand Up @@ -148,7 +150,9 @@ const char* CAEUtil::DataFormatToStr(const enum AEDataFormat dataFormat)
"AE_FMT_EAC3",
"AE_FMT_TRUEHD",
"AE_FMT_DTSHD",
#ifdef TARGET_DARWIN
"AE_FMT_LPCM"
#endif
};

return formats[dataFormat];
Expand Down
9 changes: 8 additions & 1 deletion xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp
Expand Up @@ -173,13 +173,17 @@ int CDVDAudioCodecFFmpeg::Decode(BYTE* pData, int iSize)
m_iBuffered += iBytesUsed;
else
m_iBuffered = 0;


#ifdef TARGET_DARWIN
if(m_bLpcmMode)
ConvertToFloat();
#endif

return iBytesUsed;
}

#ifdef TARGET_DARWIN
// used by the CoreAudio-specific "LPCM hog mode"
void CDVDAudioCodecFFmpeg::ConvertToFloat()
{
if(m_pCodecContext->sample_fmt != AV_SAMPLE_FMT_FLT && m_iBufferSize1 > 0)
Expand Down Expand Up @@ -217,6 +221,7 @@ void CDVDAudioCodecFFmpeg::ConvertToFloat()
m_iBufferSize2 = len * m_dllAvUtil.av_get_bytes_per_sample(AV_SAMPLE_FMT_FLT);
}
}
#endif

int CDVDAudioCodecFFmpeg::GetData(BYTE** dst)
{
Expand Down Expand Up @@ -264,11 +269,13 @@ int CDVDAudioCodecFFmpeg::GetEncodedSampleRate()

enum AEDataFormat CDVDAudioCodecFFmpeg::GetDataFormat()
{
#if TARGET_DARWIN
if(m_bLpcmMode)
{
return AE_FMT_LPCM;
}
else
#endif
{
switch(m_pCodecContext->sample_fmt)
{
Expand Down

0 comments on commit e720a28

Please sign in to comment.