diff options
author | Max Kellermann <max@musicpd.org> | 2021-03-08 22:14:23 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2021-03-08 22:15:36 +0100 |
commit | 9256190a9b8fb36b69bd6c73315bf09a10363204 (patch) | |
tree | 580a8f0926c46335f6ff0ecd083f63a215d05959 | |
parent | 3a0dbb0a6750e9a62de8716a8d312484b475be0d (diff) |
output/wasapi: move catch block to the Work() function level
If an exception has been caught, the method cannot continue playback,
therefore it doesn't make sense to have the "catch" block inside the
"while" block (and not break the loop after catching an exception).
-rw-r--r-- | src/output/plugins/wasapi/WasapiOutputPlugin.cxx | 86 |
1 files changed, 42 insertions, 44 deletions
diff --git a/src/output/plugins/wasapi/WasapiOutputPlugin.cxx b/src/output/plugins/wasapi/WasapiOutputPlugin.cxx index 19a8ddf2e..922604bef 100644 --- a/src/output/plugins/wasapi/WasapiOutputPlugin.cxx +++ b/src/output/plugins/wasapi/WasapiOutputPlugin.cxx @@ -317,63 +317,61 @@ wasapi_output_get_client(WasapiOutput &output) noexcept inline void WasapiOutputThread::Work() noexcept -{ +try { SetThreadName("Wasapi Output Worker"); FormatDebug(wasapi_output_domain, "Working thread started"); COM com; while (true) { - try { - event.Wait(); + event.Wait(); - Status current_state = status.load(); - if (current_state == Status::FINISH) { - FormatDebug(wasapi_output_domain, - "Working thread stopped"); - return; - } + Status current_state = status.load(); + if (current_state == Status::FINISH) { + FormatDebug(wasapi_output_domain, + "Working thread stopped"); + return; + } - UINT32 write_in_frames = buffer_size_in_frames; - if (!is_exclusive) { - UINT32 data_in_frames = - GetCurrentPaddingFrames(client); + UINT32 write_in_frames = buffer_size_in_frames; + if (!is_exclusive) { + UINT32 data_in_frames = + GetCurrentPaddingFrames(client); - if (data_in_frames >= buffer_size_in_frames) { - continue; - } - write_in_frames -= data_in_frames; + if (data_in_frames >= buffer_size_in_frames) { + continue; } + write_in_frames -= data_in_frames; + } - BYTE *data; - DWORD mode = 0; + BYTE *data; + DWORD mode = 0; - if (HRESULT result = - render_client->GetBuffer(write_in_frames, &data); - FAILED(result)) { - throw MakeHResultError(result, "Failed to get buffer"); - } + if (HRESULT result = + render_client->GetBuffer(write_in_frames, &data); + FAILED(result)) { + throw MakeHResultError(result, "Failed to get buffer"); + } - AtScopeExit(&) { - render_client->ReleaseBuffer(write_in_frames, mode); - }; - - if (current_state == Status::PLAY) { - const UINT32 write_size = write_in_frames * frame_size; - UINT32 new_data_size = 0; - new_data_size = spsc_buffer.pop(data, write_size); - std::fill_n(data + new_data_size, - write_size - new_data_size, 0); - data_poped.Set(); - } else { - mode = AUDCLNT_BUFFERFLAGS_SILENT; - FormatDebug(wasapi_output_domain, - "Working thread paused"); - } - } catch (...) { - error.ptr = std::current_exception(); - error.occur.store(true); - error.thrown.Wait(); + AtScopeExit(&) { + render_client->ReleaseBuffer(write_in_frames, mode); + }; + + if (current_state == Status::PLAY) { + const UINT32 write_size = write_in_frames * frame_size; + UINT32 new_data_size = 0; + new_data_size = spsc_buffer.pop(data, write_size); + std::fill_n(data + new_data_size, + write_size - new_data_size, 0); + data_poped.Set(); + } else { + mode = AUDCLNT_BUFFERFLAGS_SILENT; + FormatDebug(wasapi_output_domain, + "Working thread paused"); } } +} catch (...) { + error.ptr = std::current_exception(); + error.occur.store(true); + error.thrown.Wait(); } AudioOutput * |