[WIN32][WASAPI]: made wasapi sink accept default as device string. set "wasapi:defaul...
authorwsoltys <wiso@no.way>
Tue, 16 Jul 2013 19:17:38 +0000 (21:17 +0200)
committerRainer Hochecker <fernetmenta@online.de>
Thu, 1 Aug 2013 14:28:30 +0000 (16:28 +0200)
xbmc/cores/AudioEngine/Sinks/AESinkWASAPI.cpp
xbmc/settings/Settings.cpp

index 8a3d7ce..8995a0c 100644 (file)
@@ -34,6 +34,7 @@
 #include "../Utils/AEDeviceInfo.h"
 #include <Mmreg.h>
 #include <mmdeviceapi.h>
+#include "utils/StringUtils.h"
 
 #pragma comment(lib, "Avrt.lib")
 
@@ -206,6 +207,7 @@ bool CAESinkWASAPI::Initialize(AEAudioFormat &format, std::string &device)
     return false;
 
   m_device = device;
+  bool bdefault = false;
 
   /* Save requested format */
   /* Clear returned format */
@@ -227,41 +229,47 @@ bool CAESinkWASAPI::Initialize(AEAudioFormat &format, std::string &device)
   hr = pEnumDevices->GetCount(&uiCount);
   EXIT_ON_FAILURE(hr, __FUNCTION__": Retrieval of audio endpoint count failed.")
 
-  for (UINT i = 0; i < uiCount; i++)
+  if(StringUtils::EndsWith(device, std::string("default")))
+    bdefault = true;
+
+  if(!bdefault)
   {
-    IPropertyStore *pProperty = NULL;
-    PROPVARIANT varName;
+    for (UINT i = 0; i < uiCount; i++)
+    {
+      IPropertyStore *pProperty = NULL;
+      PROPVARIANT varName;
 
-    hr = pEnumDevices->Item(i, &m_pDevice);
-    EXIT_ON_FAILURE(hr, __FUNCTION__": Retrieval of WASAPI endpoint failed.")
+      hr = pEnumDevices->Item(i, &m_pDevice);
+      EXIT_ON_FAILURE(hr, __FUNCTION__": Retrieval of WASAPI endpoint failed.")
 
-    hr = m_pDevice->OpenPropertyStore(STGM_READ, &pProperty);
-    EXIT_ON_FAILURE(hr, __FUNCTION__": Retrieval of WASAPI endpoint properties failed.")
+      hr = m_pDevice->OpenPropertyStore(STGM_READ, &pProperty);
+      EXIT_ON_FAILURE(hr, __FUNCTION__": Retrieval of WASAPI endpoint properties failed.")
 
-    hr = pProperty->GetValue(PKEY_AudioEndpoint_GUID, &varName);
-    if (FAILED(hr))
-    {
-      CLog::Log(LOGERROR, __FUNCTION__": Retrieval of WASAPI endpoint GUID failed.");
-      SAFE_RELEASE(pProperty);
-      goto failed;
-    }
+      hr = pProperty->GetValue(PKEY_AudioEndpoint_GUID, &varName);
+      if (FAILED(hr))
+      {
+        CLog::Log(LOGERROR, __FUNCTION__": Retrieval of WASAPI endpoint GUID failed.");
+        SAFE_RELEASE(pProperty);
+        goto failed;
+      }
 
-    std::string strDevName = localWideToUtf(varName.pwszVal);
+      std::string strDevName = localWideToUtf(varName.pwszVal);
 
-    if (device == strDevName)
-      i = uiCount;
-    else
-      SAFE_RELEASE(m_pDevice);
+      if (device == strDevName)
+        i = uiCount;
+      else
+        SAFE_RELEASE(m_pDevice);
 
-    PropVariantClear(&varName);
-    SAFE_RELEASE(pProperty);
+      PropVariantClear(&varName);
+      SAFE_RELEASE(pProperty);
+    }
   }
-
   SAFE_RELEASE(pEnumDevices);
 
   if (!m_pDevice)
   {
-    CLog::Log(LOGINFO, __FUNCTION__": Could not locate the device named \"%s\" in the list of WASAPI endpoint devices.  Trying the default device...", device.c_str());
+    if(!bdefault)
+      CLog::Log(LOGINFO, __FUNCTION__": Could not locate the device named \"%s\" in the list of WASAPI endpoint devices.  Trying the default device...", device.c_str());
     hr = pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &m_pDevice);
     EXIT_ON_FAILURE(hr, __FUNCTION__": Could not retrieve the default WASAPI audio endpoint.")
 
@@ -583,6 +591,13 @@ void CAESinkWASAPI::EnumerateDevicesEx(AEDeviceInfoList &deviceInfoList, bool fo
   WAVEFORMATEXTENSIBLE wfxex = {0};
   HRESULT              hr;
 
+  // add default device entry
+  deviceInfo.m_deviceName       = std::string("default");
+  deviceInfo.m_displayName      = std::string("default");
+
+  /* Store the device info */
+  deviceInfoList.push_back(deviceInfo);
+
   hr = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void**)&pEnumerator);
   EXIT_ON_FAILURE(hr, __FUNCTION__": Could not allocate WASAPI device enumerator. CoCreateInstance error code: %li", hr)
 
index cb58944..cbbbcb4 100644 (file)
@@ -645,6 +645,9 @@ void CSettings::InitializeDefaults()
   ((CSettingString*)m_settingsManager->GetSetting("audiooutput.audiodevice"))->SetDefault(defaultAudioDeviceName);
   ((CSettingString*)m_settingsManager->GetSetting("audiooutput.passthroughdevice"))->SetDefault(defaultAudioDeviceName);
   #endif
+#elif defined(TARGET_WINDOWS)
+  ((CSettingString*)m_settingsManager->GetSetting("audiooutput.audiodevice"))->SetDefault(std::string("WASAPI:default"));
+  ((CSettingString*)m_settingsManager->GetSetting("audiooutput.passthroughdevice"))->SetDefault(std::string("WASAPI:default"));
 #else
   ((CSettingString*)m_settingsManager->GetSetting("audiooutput.audiodevice"))->SetDefault(CAEFactory::GetDefaultDevice(false));
   ((CSettingString*)m_settingsManager->GetSetting("audiooutput.passthroughdevice"))->SetDefault(CAEFactory::GetDefaultDevice(true));