diff options
author | Memphiz <memphis@machzwo.de> | 2014-05-13 23:59:10 +0200 |
---|---|---|
committer | Memphiz <memphis@machzwo.de> | 2014-06-05 22:24:39 +0200 |
commit | 70068126527ac4383f1bc85c75e5cd141f3ae85a (patch) | |
tree | fbb7fc0e4ca4089b163cce8955679c04f8a1ebc7 | |
parent | 54708139cb31de3ef78a37b1d9b53e6b4ec0a630 (diff) |
[ae/ca] - add support for fetching the stereo channel layout of a device
4 files changed, 55 insertions, 0 deletions
diff --git a/xbmc/cores/AudioEngine/Sinks/osx/CoreAudioChannelLayout.cpp b/xbmc/cores/AudioEngine/Sinks/osx/CoreAudioChannelLayout.cpp index 05645c28b4..6ca5df4770 100644 --- a/xbmc/cores/AudioEngine/Sinks/osx/CoreAudioChannelLayout.cpp +++ b/xbmc/cores/AudioEngine/Sinks/osx/CoreAudioChannelLayout.cpp @@ -105,6 +105,34 @@ bool CCoreAudioChannelLayout::CopyLayout(AudioChannelLayout& layout) return (ret == noErr); } +bool CCoreAudioChannelLayout::CopyLayoutForStereo(UInt32 layout[2]) +{ + enum { + kVariableLengthArray_deprecated = 1 + }; + + free(m_pLayout); + m_pLayout = NULL; + + UInt32 channels = 2; + UInt32 size = sizeof(AudioChannelLayout) + (channels - kVariableLengthArray_deprecated) * sizeof(AudioChannelDescription); + + m_pLayout = (AudioChannelLayout*)malloc(size); + m_pLayout->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions; + m_pLayout->mNumberChannelDescriptions = 2;//stereo + + AudioChannelDescription desc; + desc.mChannelFlags = kAudioChannelFlags_AllOff; + memset(desc.mCoordinates, 0, sizeof(desc.mCoordinates)); + + desc.mChannelLabel = layout[0];// label for channel 1 + m_pLayout->mChannelDescriptions[0] = desc; + + desc.mChannelLabel = layout[1];// label for channel 2 + m_pLayout->mChannelDescriptions[1] = desc; + return true; +} + UInt32 CCoreAudioChannelLayout::GetChannelCountForLayout(AudioChannelLayout& layout) { UInt32 channels = 0; diff --git a/xbmc/cores/AudioEngine/Sinks/osx/CoreAudioChannelLayout.h b/xbmc/cores/AudioEngine/Sinks/osx/CoreAudioChannelLayout.h index cf95c83666..64721c9d4c 100644 --- a/xbmc/cores/AudioEngine/Sinks/osx/CoreAudioChannelLayout.h +++ b/xbmc/cores/AudioEngine/Sinks/osx/CoreAudioChannelLayout.h @@ -79,6 +79,7 @@ public: operator AudioChannelLayout*() {return m_pLayout;} bool CopyLayout(AudioChannelLayout &layout); + bool CopyLayoutForStereo(UInt32 layout[2]); static UInt32 GetChannelCountForLayout(AudioChannelLayout &layout); static const char* ChannelLabelToString(UInt32 label); static const char* ChannelLayoutToString(AudioChannelLayout &layout, std::string &str); diff --git a/xbmc/cores/AudioEngine/Sinks/osx/CoreAudioDevice.cpp b/xbmc/cores/AudioEngine/Sinks/osx/CoreAudioDevice.cpp index 20b8728996..2fe3bb9b5c 100644 --- a/xbmc/cores/AudioEngine/Sinks/osx/CoreAudioDevice.cpp +++ b/xbmc/cores/AudioEngine/Sinks/osx/CoreAudioDevice.cpp @@ -547,6 +547,31 @@ bool CCoreAudioDevice::GetPreferredChannelLayout(CCoreAudioChannelLayout& layout return (ret == noErr); } +bool CCoreAudioDevice::GetPreferredChannelLayoutForStereo(CCoreAudioChannelLayout &layout) +{ + if (!m_DeviceId) + return false; + + AudioObjectPropertyAddress propertyAddress; + propertyAddress.mScope = kAudioDevicePropertyScopeOutput; + propertyAddress.mElement = 0; + propertyAddress.mSelector = kAudioDevicePropertyPreferredChannelsForStereo; + + UInt32 channels[2];// this will receive the channel labels + UInt32 propertySize = sizeof(channels); + + OSStatus ret = AudioObjectGetPropertyData(m_DeviceId, &propertyAddress, 0, NULL, &propertySize, &channels); + if (ret != noErr) + CLog::Log(LOGERROR, "CCoreAudioDevice::GetPreferredChannelLayoutForStereo: " + "Unable to retrieve preferred channel layout. Error = %s", GetError(ret).c_str()); + else + { + // Copy/generate a layout into the result into the caller's instance + layout.CopyLayoutForStereo(channels); + } + return (ret == noErr); +} + bool CCoreAudioDevice::GetDataSources(CoreAudioDataSourceList* pList) { if (!pList || !m_DeviceId) diff --git a/xbmc/cores/AudioEngine/Sinks/osx/CoreAudioDevice.h b/xbmc/cores/AudioEngine/Sinks/osx/CoreAudioDevice.h index e95f8c12f1..afe90a14c7 100644 --- a/xbmc/cores/AudioEngine/Sinks/osx/CoreAudioDevice.h +++ b/xbmc/cores/AudioEngine/Sinks/osx/CoreAudioDevice.h @@ -61,6 +61,7 @@ public: bool GetMixingSupport(); bool SetCurrentVolume(Float32 vol); bool GetPreferredChannelLayout(CCoreAudioChannelLayout &layout); + bool GetPreferredChannelLayoutForStereo(CCoreAudioChannelLayout &layout); bool GetDataSources(CoreAudioDataSourceList *pList); Float64 GetNominalSampleRate(); bool SetNominalSampleRate(Float64 sampleRate); |