diff options
author | Memphiz <memphis@machzwo.de> | 2014-05-22 14:52:37 +0200 |
---|---|---|
committer | Memphiz <memphis@machzwo.de> | 2014-05-23 10:07:12 +0200 |
commit | 3f8b1ffea79180e372fcaf095e56fd7200fa1fa6 (patch) | |
tree | 9d8ea4bcd620c73398f808a235bd12ee7604cc95 | |
parent | 6c7c69142b1d4a24a891a59ed4ab085c25e86eb1 (diff) |
[AE/osxsink] - fixed - fire CAEFactory::DeviceChange() when the default device
changes not only when the list of devices itself changes (fixes transition of default devices when default is changed externally via audio midi setup for example)
-rw-r--r-- | xbmc/cores/AudioEngine/Sinks/AESinkDARWINOSX.cpp | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/xbmc/cores/AudioEngine/Sinks/AESinkDARWINOSX.cpp b/xbmc/cores/AudioEngine/Sinks/AESinkDARWINOSX.cpp index 1aa20f9737..27c555346f 100644 --- a/xbmc/cores/AudioEngine/Sinks/AESinkDARWINOSX.cpp +++ b/xbmc/cores/AudioEngine/Sinks/AESinkDARWINOSX.cpp @@ -304,16 +304,45 @@ OSStatus deviceChangedCB(AudioObjectID inObjectID, const AudioObjectPropertyAddress inAddresses[], void* inClientData) { - CLog::Log(LOGDEBUG, "CoreAudio: audiodevicelist changed - reenumerating"); - CAEFactory::DeviceChange(); - CLog::Log(LOGDEBUG, "CoreAudio: audiodevicelist changed - done"); + bool deviceChanged = false; + static AudioDeviceID oldDefaultDevice = 0; + AudioDeviceID currentDefaultOutputDevice = 0; + + for (unsigned int i = 0; i < inNumberAddresses; i++) + { + switch (inAddresses[i].mSelector) + { + case kAudioHardwarePropertyDefaultOutputDevice: + currentDefaultOutputDevice = CCoreAudioHardware::GetDefaultOutputDevice(); + // This listener is called on every change of the hardware + // device. So check if the default device has really changed. + if (oldDefaultDevice != currentDefaultOutputDevice) + { + deviceChanged = true; + oldDefaultDevice = currentDefaultOutputDevice; + } + break; + default: + deviceChanged = true; + break; + } + if (deviceChanged) + break; + } + + if (deviceChanged) + { + CLog::Log(LOGDEBUG, "CoreAudio: audiodevicelist changed - reenumerating"); + CAEFactory::DeviceChange(); + CLog::Log(LOGDEBUG, "CoreAudio: audiodevicelist changed - done"); + } return noErr; } void RegisterDeviceChangedCB(bool bRegister, void *ref) { OSStatus ret = noErr; - const AudioObjectPropertyAddress inAdr = + AudioObjectPropertyAddress inAdr = { kAudioHardwarePropertyDevices, kAudioObjectPropertyScopeGlobal, @@ -321,9 +350,17 @@ void RegisterDeviceChangedCB(bool bRegister, void *ref) }; if (bRegister) + { + ret = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &inAdr, deviceChangedCB, ref); + inAdr.mSelector = kAudioHardwarePropertyDefaultOutputDevice; ret = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &inAdr, deviceChangedCB, ref); + } else + { ret = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &inAdr, deviceChangedCB, ref); + inAdr.mSelector = kAudioHardwarePropertyDefaultOutputDevice; + ret = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &inAdr, deviceChangedCB, ref); + } if (ret != noErr) CLog::Log(LOGERROR, "CCoreAudioAE::Deinitialize - error %s a listener callback for device changes!", bRegister?"attaching":"removing"); |