#include <Functiondiscoverykeys_devpkey.h>
#include <Rpc.h>
#include "cores/AudioEngine/Utils/AEUtil.h"
+#include "utils/StringUtils.h"
#pragma comment(lib, "Rpcrt4.lib")
extern HWND g_hWnd;
LPGUID deviceGUID = NULL;
RPC_CSTR wszUuid = NULL;
HRESULT hr = E_FAIL;
+ std::string strDeviceGUID = device;
std::list<DSDevice> DSDeviceList;
std::string deviceFriendlyName;
DirectSoundEnumerate(DSEnumCallback, &DSDeviceList);
+ if(StringUtils::EndsWith(device, std::string("default")))
+ strDeviceGUID = GetDefaultDevice();
+
for (std::list<DSDevice>::iterator itt = DSDeviceList.begin(); itt != DSDeviceList.end(); ++itt)
{
if ((*itt).lpGuid)
hr = (UuidToString((*itt).lpGuid, &wszUuid));
std::string sztmp = (char*)wszUuid;
std::string szGUID = "{" + std::string(sztmp.begin(), sztmp.end()) + "}";
- if (strcasecmp(szGUID.c_str(), device.c_str()) == 0)
+ if (strcasecmp(szGUID.c_str(), strDeviceGUID.c_str()) == 0)
{
deviceGUID = (*itt).lpGuid;
deviceFriendlyName = (*itt).name.c_str();
break;
}
}
- if (hr == RPC_S_OK) RpcStringFree(&wszUuid);
+ if (hr == RPC_S_OK) RpcStringFree(&wszUuid);
}
hr = DirectSoundCreate(deviceGUID, &m_pDSound, NULL);
if (FAILED(hr))
{
- CLog::Log(LOGERROR, __FUNCTION__": Failed to create the DirectSound device.");
- CLog::Log(LOGERROR, __FUNCTION__": DSErr: %s", dserr2str(hr));
- return false;
+ CLog::Log(LOGERROR, __FUNCTION__": Failed to create the DirectSound device %s with error %s, trying the default device.", deviceFriendlyName.c_str(), dserr2str(hr));
+ hr = DirectSoundCreate(NULL, &m_pDSound, NULL);
+ if (FAILED(hr))
+ {
+ CLog::Log(LOGERROR, __FUNCTION__": Failed to create the default DirectSound device with error %s.", dserr2str(hr));
+ return false;
+ }
}
HWND tmp_hWnd;
HRESULT hr;
+ std::string strDD = GetDefaultDevice();
+
/* See if we are on Windows XP */
if (!g_sysinfo.IsWindowsVersionAtLeast(CSysInfo::WindowsVersionVista))
{
deviceInfo.m_sampleRates.push_back((DWORD) 96000);
deviceInfoList.push_back(deviceInfo);
+
+ // add the default device with m_deviceName = default
+ if(strDD == deviceInfo.m_deviceName)
+ {
+ deviceInfo.m_deviceName = std::string("default");
+ deviceInfo.m_displayName = std::string("default");
+ deviceInfo.m_displayNameExtra = std::string("");
+ deviceInfoList.push_back(deviceInfo);
+ }
}
RpcStringFree(&cszGUID);
deviceInfo.m_deviceType = aeDeviceType;
deviceInfoList.push_back(deviceInfo);
- }
- // since AE takes the first device in deviceInfoList as default audio device we need
- // to sort it in order to use the real default device
- if(deviceInfoList.size() > 1)
- {
- std::string strDD = GetDefaultDevice();
- for (AEDeviceInfoList::iterator itt = deviceInfoList.begin(); itt != deviceInfoList.end(); ++itt)
+ // add the default device with m_deviceName = default
+ if(strDD == strDevName)
{
- CAEDeviceInfo devInfo = *itt;
- if(devInfo.m_deviceName == strDD)
- {
- deviceInfoList.erase(itt);
- deviceInfoList.insert(deviceInfoList.begin(), devInfo);
- break;
- }
+ deviceInfo.m_deviceName = std::string("default");
+ deviceInfo.m_displayName = std::string("default");
+ deviceInfo.m_displayNameExtra = std::string("");
+ deviceInfoList.push_back(deviceInfo);
}
}