Skip to content
This repository
Browse code

Merge pull request #2197 from wsoltys/aedefault

[WIN32] workaround: get the default audio interface for DirectSound to have audio on a fresh installation.
  • Loading branch information...
commit 906a15a85733a3b684c38e1484dc0e283e0a0a8c 2 parents 6a384a1 + 1e84246
wsoltys authored February 09, 2013
75  xbmc/cores/AudioEngine/Sinks/AESinkDirectSound.cpp
@@ -622,12 +622,25 @@ void CAESinkDirectSound::EnumerateDevicesEx(AEDeviceInfoList &deviceInfoList)
622 622
     deviceInfo.m_displayNameExtra = std::string("DirectSound: ").append(strFriendlyName);
623 623
     deviceInfo.m_deviceType       = aeDeviceType;
624 624
 
625  
-    /* Now logged by AESinkFactory on startup */
626  
-    //CLog::Log(LOGDEBUG,"Audio Device %d:    %s", i, ((std::string)deviceInfo).c_str());
627  
-
628 625
     deviceInfoList.push_back(deviceInfo);
629 626
   }
630 627
 
  628
+  // since AE takes the first device in deviceInfoList as default audio device we need
  629
+  // to sort it in order to use the real default device
  630
+  if(deviceInfoList.size() > 1)
  631
+  {
  632
+    std::string strDD = GetDefaultDevice();
  633
+    for (AEDeviceInfoList::iterator itt = deviceInfoList.begin(); itt != deviceInfoList.end(); ++itt)
  634
+    {
  635
+      CAEDeviceInfo devInfo = *itt;
  636
+      if(devInfo.m_deviceName == strDD)
  637
+      {
  638
+        deviceInfoList.erase(itt);
  639
+        deviceInfoList.insert(deviceInfoList.begin(), devInfo);
  640
+      }
  641
+    }
  642
+  }
  643
+
631 644
   return;
632 645
 
633 646
 failed:
@@ -825,5 +838,61 @@ const char *CAESinkDirectSound::WASAPIErrToStr(HRESULT err)
825 838
   return NULL;
826 839
 }
827 840
 
  841
+std::string CAESinkDirectSound::GetDefaultDevice()
  842
+{
  843
+  IMMDeviceEnumerator* pEnumerator = NULL;
  844
+  IMMDevice*           pDevice = NULL;
  845
+  IPropertyStore*      pProperty = NULL;
  846
+  HRESULT              hr;
  847
+  PROPVARIANT          varName;
  848
+  std::string          strDevName = "default";
  849
+
  850
+  hr = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void**)&pEnumerator);
  851
+  if (FAILED(hr))
  852
+  {
  853
+    CLog::Log(LOGERROR, __FUNCTION__": Could not allocate WASAPI device enumerator. CoCreateInstance error code: %s", WASAPIErrToStr(hr));
  854
+    goto failed;
  855
+  }
  856
+
  857
+  hr = pEnumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &pDevice);
  858
+  if (FAILED(hr))
  859
+  {
  860
+    CLog::Log(LOGERROR, __FUNCTION__": Retrieval of audio endpoint enumeration failed.");
  861
+    goto failed;
  862
+  }
  863
+
  864
+  hr = pDevice->OpenPropertyStore(STGM_READ, &pProperty);
  865
+  if (FAILED(hr))
  866
+  {
  867
+    CLog::Log(LOGERROR, __FUNCTION__": Retrieval of DirectSound endpoint properties failed.");
  868
+    goto failed;
  869
+  }
  870
+
  871
+  PropVariantInit(&varName);
  872
+  hr = pProperty->GetValue(PKEY_AudioEndpoint_FormFactor, &varName);
  873
+  if (FAILED(hr))
  874
+  {
  875
+    CLog::Log(LOGERROR, __FUNCTION__": Retrieval of DirectSound endpoint form factor failed.");
  876
+    goto failed;
  877
+  }
  878
+  AEDeviceType aeDeviceType = winEndpoints[(EndpointFormFactor)varName.uiVal].aeDeviceType;
  879
+  PropVariantClear(&varName);
  880
+
  881
+  hr = pProperty->GetValue(PKEY_AudioEndpoint_GUID, &varName);
  882
+  if (FAILED(hr))
  883
+  {
  884
+    CLog::Log(LOGERROR, __FUNCTION__": Retrieval of DirectSound endpoint GUID failed.");    
  885
+    goto failed;
  886
+  }
828 887
 
  888
+  strDevName = localWideToUtf(varName.pwszVal);
  889
+  PropVariantClear(&varName);
829 890
 
  891
+failed:
  892
+
  893
+  SAFE_RELEASE(pProperty);
  894
+  SAFE_RELEASE(pDevice);
  895
+  SAFE_RELEASE(pEnumerator);
  896
+
  897
+  return strDevName;
  898
+}
1  xbmc/cores/AudioEngine/Sinks/AESinkDirectSound.h
@@ -44,6 +44,7 @@ class CAESinkDirectSound : public IAESink
44 44
   virtual double       GetCacheTotal      ();
45 45
   virtual unsigned int AddPackets         (uint8_t *data, unsigned int frames, bool hasAudio);
46 46
   static  void         EnumerateDevicesEx (AEDeviceInfoList &deviceInfoList);
  47
+  static  std::string  GetDefaultDevice   ();
47 48
 private:
48 49
   void          AEChannelsFromSpeakerMask(DWORD speakers);
49 50
   DWORD         SpeakerMaskFromAEChannels(const CAEChannelInfo &channels);

0 notes on commit 906a15a

Please sign in to comment.
Something went wrong with that request. Please try again.