[AE/CA] - fixed - if user has selected "default" output device we need to reinit...
authorMemphiz <memphis@machzwo.de>
Mon, 21 Jan 2013 21:35:23 +0000 (22:35 +0100)
committerMemphiz <memphis@machzwo.de>
Mon, 21 Jan 2013 21:35:23 +0000 (22:35 +0100)
xbmc/cores/AudioEngine/Engines/CoreAudio/CoreAudioAE.cpp
xbmc/cores/AudioEngine/Engines/CoreAudio/CoreAudioAE.h

index b8f77c7..944fa97 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "CoreAudioAEStream.h"
 #include "CoreAudioAESound.h"
+#include "CoreAudioHardware.h"
 #include "cores/AudioEngine/Utils/AEUtil.h"
 #include "settings/GUISettings.h"
 #include "settings/Settings.h"
@@ -53,7 +54,8 @@ CCoreAudioAE::CCoreAudioAE() :
   m_streamsPlaying     (false         ),
   m_isSuspended        (false         ),
   m_softSuspend        (false         ),
-  m_softSuspendTimer   (0             )
+  m_softSuspendTimer   (0             ),
+  m_currentAudioDevice (0             )
 {
   HAL = new CCoreAudioAEHAL;
 }
@@ -272,6 +274,11 @@ bool CCoreAudioAE::OpenCoreAudio(unsigned int sampleRate, bool forceRaw,
       (*itt)->Initialize();
     streamLock.Leave();
   }
+  
+  if (m_Initialized)
+  {
+    m_currentAudioDevice = CCoreAudioHardware::FindAudioDevice(m_outputDevice);
+  }
 
   return m_Initialized;
 }
@@ -429,6 +436,7 @@ CCoreAudioAEHAL* CCoreAudioAE::GetHAL()
 IAEStream* CCoreAudioAE::MakeStream(enum AEDataFormat dataFormat,
   unsigned int sampleRate, unsigned int encodedSamplerate, CAEChannelInfo channelLayout, unsigned int options)
 {
+  bool defaultDeviceChanged = false;
   // if we are suspended we don't
   // want anyone to mess with us
   if (m_isSuspended && !m_softSuspend)
@@ -443,6 +451,18 @@ IAEStream* CCoreAudioAE::MakeStream(enum AEDataFormat dataFormat,
   m_streams.push_back(stream);
   streamLock.Leave();
 
+  // check if default device has changed - in that case we need to reinit
+  // TODO hook into osx callbacks for getting notifiaction on device
+  // changes and then queue a change of the default device
+  // to a point where engine is idle.
+  std::string outputDevice = g_guiSettings.GetString("audiooutput.audiodevice");
+  if (outputDevice.compare("CoreAudio:default") == 0)
+  {
+    AudioDeviceID currentId = CCoreAudioHardware::FindAudioDevice("default");
+    if (currentId != m_currentAudioDevice)
+      defaultDeviceChanged = true;
+  }
+
   if ((options & AESTREAM_PAUSED) == 0)
     Stop();
 
@@ -450,7 +470,8 @@ IAEStream* CCoreAudioAE::MakeStream(enum AEDataFormat dataFormat,
   if (m_Initialized && ( m_lastStreamFormat != dataFormat ||
                          m_lastChLayoutCount != channelLayout.Count() ||
                          m_lastSampleRate != sampleRate ||
-                         COREAUDIO_IS_RAW(dataFormat)))
+                         COREAUDIO_IS_RAW(dataFormat) ||
+                         defaultDeviceChanged))
   {
     CSingleLock engineLock(m_engineLock);
     Stop();
index bdb9ccb..0803597 100644 (file)
@@ -174,4 +174,5 @@ private:
   bool              m_isSuspended;
   bool              m_softSuspend;
   unsigned int      m_softSuspendTimer;
+  AudioDeviceID     m_currentAudioDevice;
 };