AudioCommon/WASAPI: Use std::string_view where applicable

This commit is contained in:
Silent 2019-08-17 11:05:33 +02:00
parent 7d59ad262f
commit 5dbbf36563
No known key found for this signature in database
GPG Key ID: AE53149BB0C45AF1
2 changed files with 7 additions and 4 deletions

View File

@ -59,14 +59,16 @@ static bool HandleWinAPI(std::string_view message, HRESULT result)
{ {
if (FAILED(result)) if (FAILED(result))
{ {
_com_error err(result); std::string error;
std::string error = TStrToUTF8(err.ErrorMessage());
switch (result) switch (result)
{ {
case AUDCLNT_E_DEVICE_IN_USE: case AUDCLNT_E_DEVICE_IN_USE:
error = "Audio endpoint already in use!"; error = "Audio endpoint already in use!";
break; break;
default:
error = TStrToUTF8(_com_error(result).ErrorMessage()).c_str();
break;
} }
ERROR_LOG_FMT(AUDIO, "WASAPI: {}: {}", message, error); ERROR_LOG_FMT(AUDIO, "WASAPI: {}: {}", message, error);
@ -75,6 +77,7 @@ static bool HandleWinAPI(std::string_view message, HRESULT result)
return SUCCEEDED(result); return SUCCEEDED(result);
} }
std::vector<std::string> WASAPIStream::GetAvailableDevices() std::vector<std::string> WASAPIStream::GetAvailableDevices()
{ {
HRESULT result = CoInitializeEx(nullptr, COINIT_MULTITHREADED); HRESULT result = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
@ -131,7 +134,7 @@ std::vector<std::string> WASAPIStream::GetAvailableDevices()
return device_names; return device_names;
} }
ComPtr<IMMDevice> WASAPIStream::GetDeviceByName(std::string name) ComPtr<IMMDevice> WASAPIStream::GetDeviceByName(std::string_view name)
{ {
HRESULT result = CoInitializeEx(nullptr, COINIT_MULTITHREADED); HRESULT result = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
// RPC_E_CHANGED_MODE means that thread has COM already initialized with a different threading // RPC_E_CHANGED_MODE means that thread has COM already initialized with a different threading

View File

@ -40,7 +40,7 @@ public:
static bool isValid(); static bool isValid();
static std::vector<std::string> GetAvailableDevices(); static std::vector<std::string> GetAvailableDevices();
static Microsoft::WRL::ComPtr<IMMDevice> GetDeviceByName(std::string name); static Microsoft::WRL::ComPtr<IMMDevice> GetDeviceByName(std::string_view name);
private: private:
u32 m_frames_in_buffer = 0; u32 m_frames_in_buffer = 0;