Commit 9256190a authored by Max Kellermann's avatar Max Kellermann

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).
parent 3a0dbb0a
...@@ -317,63 +317,61 @@ wasapi_output_get_client(WasapiOutput &output) noexcept ...@@ -317,63 +317,61 @@ wasapi_output_get_client(WasapiOutput &output) noexcept
inline void inline void
WasapiOutputThread::Work() noexcept WasapiOutputThread::Work() noexcept
{ try {
SetThreadName("Wasapi Output Worker"); SetThreadName("Wasapi Output Worker");
FormatDebug(wasapi_output_domain, "Working thread started"); FormatDebug(wasapi_output_domain, "Working thread started");
COM com; COM com;
while (true) { while (true) {
try { event.Wait();
event.Wait();
Status current_state = status.load(); Status current_state = status.load();
if (current_state == Status::FINISH) { if (current_state == Status::FINISH) {
FormatDebug(wasapi_output_domain, FormatDebug(wasapi_output_domain,
"Working thread stopped"); "Working thread stopped");
return; return;
} }
UINT32 write_in_frames = buffer_size_in_frames; UINT32 write_in_frames = buffer_size_in_frames;
if (!is_exclusive) { if (!is_exclusive) {
UINT32 data_in_frames = UINT32 data_in_frames =
GetCurrentPaddingFrames(client); GetCurrentPaddingFrames(client);
if (data_in_frames >= buffer_size_in_frames) { if (data_in_frames >= buffer_size_in_frames) {
continue; continue;
}
write_in_frames -= data_in_frames;
} }
write_in_frames -= data_in_frames;
}
BYTE *data; BYTE *data;
DWORD mode = 0; DWORD mode = 0;
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 MakeHResultError(result, "Failed to get buffer"); throw MakeHResultError(result, "Failed to get buffer");
} }
AtScopeExit(&) { AtScopeExit(&) {
render_client->ReleaseBuffer(write_in_frames, mode); render_client->ReleaseBuffer(write_in_frames, mode);
}; };
if (current_state == Status::PLAY) { if (current_state == Status::PLAY) {
const UINT32 write_size = write_in_frames * frame_size; const UINT32 write_size = write_in_frames * frame_size;
UINT32 new_data_size = 0; UINT32 new_data_size = 0;
new_data_size = spsc_buffer.pop(data, write_size); new_data_size = spsc_buffer.pop(data, write_size);
std::fill_n(data + new_data_size, std::fill_n(data + new_data_size,
write_size - new_data_size, 0); write_size - new_data_size, 0);
data_poped.Set(); data_poped.Set();
} else { } else {
mode = AUDCLNT_BUFFERFLAGS_SILENT; mode = AUDCLNT_BUFFERFLAGS_SILENT;
FormatDebug(wasapi_output_domain, FormatDebug(wasapi_output_domain,
"Working thread paused"); "Working thread paused");
}
} catch (...) {
error.ptr = std::current_exception();
error.occur.store(true);
error.thrown.Wait();
} }
} }
} catch (...) {
error.ptr = std::current_exception();
error.occur.store(true);
error.thrown.Wait();
} }
AudioOutput * AudioOutput *
......
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