Commit 6a75c48d authored by Max Kellermann's avatar Max Kellermann

win32/HResult: add MakeHResultError()

None of the current FormatHResultError() callers need the format string.
parent 48bdd09f
...@@ -59,9 +59,9 @@ public: ...@@ -59,9 +59,9 @@ public:
result = endpoint_volume->GetMasterVolumeLevelScalar( result = endpoint_volume->GetMasterVolumeLevelScalar(
&volume_level); &volume_level);
if (FAILED(result)) { if (FAILED(result)) {
throw FormatHResultError(result, throw MakeHResultError(result,
"Unable to get master " "Unable to get master "
"volume level"); "volume level");
} }
} else { } else {
auto session_volume = auto session_volume =
...@@ -69,7 +69,7 @@ public: ...@@ -69,7 +69,7 @@ public:
result = session_volume->GetMasterVolume(&volume_level); result = session_volume->GetMasterVolume(&volume_level);
if (FAILED(result)) { if (FAILED(result)) {
throw FormatHResultError( throw MakeHResultError(
result, "Unable to get master volume"); result, "Unable to get master volume");
} }
} }
...@@ -95,7 +95,7 @@ public: ...@@ -95,7 +95,7 @@ public:
result = endpoint_volume->SetMasterVolumeLevelScalar( result = endpoint_volume->SetMasterVolumeLevelScalar(
volume_level, nullptr); volume_level, nullptr);
if (FAILED(result)) { if (FAILED(result)) {
throw FormatHResultError( throw MakeHResultError(
result, result,
"Unable to set master volume level"); "Unable to set master volume level");
} }
...@@ -106,7 +106,7 @@ public: ...@@ -106,7 +106,7 @@ public:
result = session_volume->SetMasterVolume(volume_level, result = session_volume->SetMasterVolume(volume_level,
nullptr); nullptr);
if (FAILED(result)) { if (FAILED(result)) {
throw FormatHResultError( throw MakeHResultError(
result, "Unable to set master volume"); result, "Unable to set master volume");
} }
} }
......
...@@ -33,8 +33,8 @@ GetBufferSizeInFrames(IAudioClient &client) ...@@ -33,8 +33,8 @@ GetBufferSizeInFrames(IAudioClient &client)
HRESULT result = client.GetBufferSize(&buffer_size_in_frames); HRESULT result = client.GetBufferSize(&buffer_size_in_frames);
if (FAILED(result)) if (FAILED(result))
throw FormatHResultError(result, throw MakeHResultError(result,
"Unable to get audio client buffer size"); "Unable to get audio client buffer size");
return buffer_size_in_frames; return buffer_size_in_frames;
} }
...@@ -46,8 +46,8 @@ GetCurrentPaddingFrames(IAudioClient &client) ...@@ -46,8 +46,8 @@ GetCurrentPaddingFrames(IAudioClient &client)
HRESULT result = client.GetCurrentPadding(&padding_frames); HRESULT result = client.GetCurrentPadding(&padding_frames);
if (FAILED(result)) if (FAILED(result))
throw FormatHResultError(result, throw MakeHResultError(result,
"Failed to get current padding"); "Failed to get current padding");
return padding_frames; return padding_frames;
} }
...@@ -59,7 +59,7 @@ GetMixFormat(IAudioClient &client) ...@@ -59,7 +59,7 @@ GetMixFormat(IAudioClient &client)
HRESULT result = client.GetMixFormat(&f); HRESULT result = client.GetMixFormat(&f);
if (FAILED(result)) if (FAILED(result))
throw FormatHResultError(result, "GetMixFormat failed"); throw MakeHResultError(result, "GetMixFormat failed");
return ComHeapPtr{f}; return ComHeapPtr{f};
} }
...@@ -69,7 +69,7 @@ Start(IAudioClient &client) ...@@ -69,7 +69,7 @@ Start(IAudioClient &client)
{ {
HRESULT result = client.Start(); HRESULT result = client.Start();
if (FAILED(result)) if (FAILED(result))
throw FormatHResultError(result, "Failed to start client"); throw MakeHResultError(result, "Failed to start client");
} }
inline void inline void
...@@ -77,7 +77,7 @@ Stop(IAudioClient &client) ...@@ -77,7 +77,7 @@ Stop(IAudioClient &client)
{ {
HRESULT result = client.Stop(); HRESULT result = client.Stop();
if (FAILED(result)) if (FAILED(result))
throw FormatHResultError(result, "Failed to stop client"); throw MakeHResultError(result, "Failed to stop client");
} }
inline void inline void
...@@ -85,7 +85,7 @@ SetEventHandle(IAudioClient &client, HANDLE h) ...@@ -85,7 +85,7 @@ SetEventHandle(IAudioClient &client, HANDLE h)
{ {
HRESULT result = client.SetEventHandle(h); HRESULT result = client.SetEventHandle(h);
if (FAILED(result)) if (FAILED(result))
throw FormatHResultError(result, "Unable to set event handle"); throw MakeHResultError(result, "Unable to set event handle");
} }
template<typename T> template<typename T>
...@@ -95,7 +95,7 @@ GetService(IAudioClient &client) ...@@ -95,7 +95,7 @@ GetService(IAudioClient &client)
T *p = nullptr; T *p = nullptr;
HRESULT result = client.GetService(IID_PPV_ARGS(&p)); HRESULT result = client.GetService(IID_PPV_ARGS(&p));
if (FAILED(result)) if (FAILED(result))
throw FormatHResultError(result, "Unable to get service"); throw MakeHResultError(result, "Unable to get service");
return ComPtr{p}; return ComPtr{p};
} }
......
...@@ -33,8 +33,8 @@ GetDefaultAudioEndpoint(IMMDeviceEnumerator &e) ...@@ -33,8 +33,8 @@ GetDefaultAudioEndpoint(IMMDeviceEnumerator &e)
HRESULT result = e.GetDefaultAudioEndpoint(eRender, eMultimedia, HRESULT result = e.GetDefaultAudioEndpoint(eRender, eMultimedia,
&device); &device);
if (FAILED(result)) if (FAILED(result))
throw FormatHResultError(result, throw MakeHResultError(result,
"Unable to get default device for multimedia"); "Unable to get default device for multimedia");
return ComPtr{device}; return ComPtr{device};
} }
...@@ -47,7 +47,7 @@ EnumAudioEndpoints(IMMDeviceEnumerator &e) ...@@ -47,7 +47,7 @@ EnumAudioEndpoints(IMMDeviceEnumerator &e)
HRESULT result = e.EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, HRESULT result = e.EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE,
&dc); &dc);
if (FAILED(result)) if (FAILED(result))
throw FormatHResultError(result, "Unable to enumerate devices"); throw MakeHResultError(result, "Unable to enumerate devices");
return ComPtr{dc}; return ComPtr{dc};
} }
...@@ -59,7 +59,7 @@ GetCount(IMMDeviceCollection &dc) ...@@ -59,7 +59,7 @@ GetCount(IMMDeviceCollection &dc)
HRESULT result = dc.GetCount(&count); HRESULT result = dc.GetCount(&count);
if (FAILED(result)) if (FAILED(result))
throw FormatHResultError(result, "Collection->GetCount failed"); throw MakeHResultError(result, "Collection->GetCount failed");
return count; return count;
} }
...@@ -71,7 +71,7 @@ Item(IMMDeviceCollection &dc, UINT i) ...@@ -71,7 +71,7 @@ Item(IMMDeviceCollection &dc, UINT i)
auto result = dc.Item(i, &device); auto result = dc.Item(i, &device);
if (FAILED(result)) if (FAILED(result))
throw FormatHResultError(result, "Collection->Item failed"); throw MakeHResultError(result, "Collection->Item failed");
return ComPtr{device}; return ComPtr{device};
} }
...@@ -83,7 +83,7 @@ GetState(IMMDevice &device) ...@@ -83,7 +83,7 @@ GetState(IMMDevice &device)
HRESULT result = device.GetState(&state);; HRESULT result = device.GetState(&state);;
if (FAILED(result)) if (FAILED(result))
throw FormatHResultError(result, "Unable to get device status"); throw MakeHResultError(result, "Unable to get device status");
return state; return state;
} }
...@@ -96,7 +96,7 @@ Activate(IMMDevice &device) ...@@ -96,7 +96,7 @@ Activate(IMMDevice &device)
HRESULT result = device.Activate(__uuidof(T), CLSCTX_ALL, HRESULT result = device.Activate(__uuidof(T), CLSCTX_ALL,
nullptr, (void **)&p); nullptr, (void **)&p);
if (FAILED(result)) if (FAILED(result))
throw FormatHResultError(result, "Unable to activate device"); throw MakeHResultError(result, "Unable to activate device");
return ComPtr{p}; return ComPtr{p};
} }
...@@ -108,8 +108,8 @@ OpenPropertyStore(IMMDevice &device) ...@@ -108,8 +108,8 @@ OpenPropertyStore(IMMDevice &device)
HRESULT result = device.OpenPropertyStore(STGM_READ, &property_store); HRESULT result = device.OpenPropertyStore(STGM_READ, &property_store);
if (FAILED(result)) if (FAILED(result))
throw FormatHResultError(result, throw MakeHResultError(result,
"Device->OpenPropertyStore failed"); "Device->OpenPropertyStore failed");
return ComPtr{property_store}; return ComPtr{property_store};
} }
......
...@@ -336,7 +336,7 @@ void WasapiOutputThread::Work() noexcept { ...@@ -336,7 +336,7 @@ void WasapiOutputThread::Work() noexcept {
if (HRESULT result = if (HRESULT result =
render_client->GetBuffer(write_in_frames, &data); render_client->GetBuffer(write_in_frames, &data);
FAILED(result)) { FAILED(result)) {
throw FormatHResultError(result, "Failed to get buffer"); throw MakeHResultError(result, "Failed to get buffer");
} }
AtScopeExit(&) { AtScopeExit(&) {
...@@ -457,7 +457,7 @@ void WasapiOutput::DoOpen(AudioFormat &audio_format) { ...@@ -457,7 +457,7 @@ void WasapiOutput::DoOpen(AudioFormat &audio_format) {
if (HRESULT result = if (HRESULT result =
client->GetDevicePeriod(&default_device_period, &min_device_period); client->GetDevicePeriod(&default_device_period, &min_device_period);
FAILED(result)) { FAILED(result)) {
throw FormatHResultError(result, "Unable to get device period"); throw MakeHResultError(result, "Unable to get device period");
} }
FormatDebug(wasapi_output_domain, FormatDebug(wasapi_output_domain,
"Default device period: %I64u ns, Minimum device period: " "Default device period: %I64u ns, Minimum device period: "
...@@ -505,8 +505,7 @@ void WasapiOutput::DoOpen(AudioFormat &audio_format) { ...@@ -505,8 +505,7 @@ void WasapiOutput::DoOpen(AudioFormat &audio_format) {
} }
if (FAILED(result)) { if (FAILED(result)) {
throw FormatHResultError( throw MakeHResultError(result, "Unable to initialize audio client");
result, "Unable to initialize audio client");
} }
} }
} else { } else {
...@@ -515,8 +514,8 @@ void WasapiOutput::DoOpen(AudioFormat &audio_format) { ...@@ -515,8 +514,8 @@ void WasapiOutput::DoOpen(AudioFormat &audio_format) {
buffer_duration, 0, buffer_duration, 0,
reinterpret_cast<WAVEFORMATEX *>(&device_format), nullptr); reinterpret_cast<WAVEFORMATEX *>(&device_format), nullptr);
FAILED(result)) { FAILED(result)) {
throw FormatHResultError(result, throw MakeHResultError(result,
"Unable to initialize audio client"); "Unable to initialize audio client");
} }
} }
...@@ -773,7 +772,7 @@ void WasapiOutput::FindSharedFormatSupported(AudioFormat &audio_format) { ...@@ -773,7 +772,7 @@ void WasapiOutput::FindSharedFormatSupported(AudioFormat &audio_format) {
} }
if (FAILED(result) && result != AUDCLNT_E_UNSUPPORTED_FORMAT) { if (FAILED(result) && result != AUDCLNT_E_UNSUPPORTED_FORMAT) {
throw FormatHResultError(result, "IsFormatSupported failed"); throw MakeHResultError(result, "IsFormatSupported failed");
} }
switch (result) { switch (result) {
...@@ -802,7 +801,7 @@ void WasapiOutput::FindSharedFormatSupported(AudioFormat &audio_format) { ...@@ -802,7 +801,7 @@ void WasapiOutput::FindSharedFormatSupported(AudioFormat &audio_format) {
result_string.c_str()); result_string.c_str());
} }
if (FAILED(result)) { if (FAILED(result)) {
throw FormatHResultError(result, "Format is not supported"); throw MakeHResultError(result, "Format is not supported");
} }
break; break;
case S_FALSE: case S_FALSE:
......
...@@ -31,7 +31,7 @@ public: ...@@ -31,7 +31,7 @@ public:
COM() { COM() {
if (HRESULT result = CoInitializeEx(nullptr, COINIT_MULTITHREADED); if (HRESULT result = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
FAILED(result)) { FAILED(result)) {
throw FormatHResultError( throw MakeHResultError(
result, result,
"Unable to initialize COM with COINIT_MULTITHREADED"); "Unable to initialize COM with COINIT_MULTITHREADED");
} }
...@@ -39,7 +39,7 @@ public: ...@@ -39,7 +39,7 @@ public:
COM(bool) { COM(bool) {
if (HRESULT result = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); if (HRESULT result = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
FAILED(result)) { FAILED(result)) {
throw FormatHResultError( throw MakeHResultError(
result, result,
"Unable to initialize COM with COINIT_APARTMENTTHREADED"); "Unable to initialize COM with COINIT_APARTMENTTHREADED");
} }
......
...@@ -85,7 +85,7 @@ public: ...@@ -85,7 +85,7 @@ public:
::CoCreateInstance(class_id, unknown_outer, class_context, ::CoCreateInstance(class_id, unknown_outer, class_context,
__uuidof(T), reinterpret_cast<void **>(&ptr)); __uuidof(T), reinterpret_cast<void **>(&ptr));
if (FAILED(result)) { if (FAILED(result)) {
throw FormatHResultError(result, "Unable to create instance"); throw MakeHResultError(result, "Unable to create instance");
} }
} }
......
...@@ -74,6 +74,13 @@ static inline const std::error_category &hresult_category() noexcept { ...@@ -74,6 +74,13 @@ static inline const std::error_category &hresult_category() noexcept {
return hresult_category_instance; return hresult_category_instance;
} }
inline std::system_error
MakeHResultError(HRESULT result, const char *msg) noexcept
{
return std::system_error(std::error_code(result, hresult_category()),
msg);
}
gcc_printf(2, 3) std::system_error gcc_printf(2, 3) std::system_error
FormatHResultError(HRESULT result, const char *fmt, ...) noexcept; FormatHResultError(HRESULT result, const char *fmt, ...) noexcept;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment