CAEFActory: add VerifyOutputDevice() implementation
authormontellese <montellese@xbmc.org>
Wed, 21 Nov 2012 23:37:55 +0000 (00:37 +0100)
committermontellese <montellese@xbmc.org>
Wed, 21 Nov 2012 23:37:55 +0000 (00:37 +0100)
xbmc/cores/AudioEngine/AEFactory.cpp
xbmc/cores/AudioEngine/AEFactory.h

index fd79aed..86392c1 100644 (file)
@@ -197,6 +197,32 @@ void CAEFactory::EnumerateOutputDevices(AEDeviceList &devices, bool passthrough)
     AE->EnumerateOutputDevices(devices, passthrough);
 }
 
+void CAEFactory::VerifyOutputDevice(std::string &device, bool passthrough)
+{
+  AEDeviceList devices;
+  EnumerateOutputDevices(devices, passthrough);
+  std::string firstDevice;
+
+  for (AEDeviceList::const_iterator deviceIt = devices.begin(); deviceIt != devices.end(); deviceIt++)
+  {
+    std::string currentDevice = deviceIt->second;
+    /* remember the first device so we can default to it if required */
+    if (firstDevice.empty())
+      firstDevice = deviceIt->second;
+
+    if (deviceIt->second == device)
+      return;
+    else if (deviceIt->first == device)
+    {
+      device = deviceIt->second;
+      return;
+    }
+  }
+
+  /* if the device wasnt found, set it to the first viable output */
+  device = firstDevice;
+}
+
 std::string CAEFactory::GetDefaultDevice(bool passthrough)
 {
   if(AE)
index 7542e3b..3c296ef 100644 (file)
@@ -46,6 +46,7 @@ public:
   static void SetSoundMode(const int mode);
   static void OnSettingsChange(std::string setting);
   static void EnumerateOutputDevices(AEDeviceList &devices, bool passthrough);
+  static void VerifyOutputDevice(std::string &device, bool passthrough);
   static std::string GetDefaultDevice(bool passthrough);
   static bool SupportsRaw();
   static void SetMute(const bool enabled);