aboutsummaryrefslogtreecommitdiffstats
path: root/alc/backends
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2022-11-19 17:25:48 -0800
committerChris Robinson <[email protected]>2022-11-19 17:25:48 -0800
commit62e6051eb9eb0890a7d0014d051b003e7f670662 (patch)
tree064b44f26914740c4001c668c1976cb76c38aabe /alc/backends
parent201f5cb63ff8fb2781afa8afeda6a0e699f9e6c4 (diff)
Fix WASAPI capture handling the background COM thread
Diffstat (limited to 'alc/backends')
-rw-r--r--alc/backends/wasapi.cpp48
1 files changed, 30 insertions, 18 deletions
diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp
index 1ce064e8..5a35b5be 100644
--- a/alc/backends/wasapi.cpp
+++ b/alc/backends/wasapi.cpp
@@ -813,7 +813,7 @@ void WasapiPlayback::open(const char *name)
{
DeinitThread();
throw al::backend_exception{al::backend_error::DeviceError, "Device init failed: 0x%08lx",
- hr};
+ mOpenStatus};
}
}
@@ -1338,7 +1338,10 @@ struct WasapiCapture final : public BackendBase, WasapiProxy {
WasapiCapture::~WasapiCapture()
{
if(SUCCEEDED(mOpenStatus))
+ {
pushMessage(MsgType::CloseDevice).wait();
+ DeinitThread();
+ }
mOpenStatus = E_FAIL;
if(mNotifyEvent != nullptr)
@@ -1441,35 +1444,44 @@ FORCE_ALIGN int WasapiCapture::recordProc()
void WasapiCapture::open(const char *name)
{
- HRESULT hr{S_OK};
+ if(SUCCEEDED(mOpenStatus))
+ throw al::backend_exception{al::backend_error::DeviceError,
+ "Unexpected duplicate open call"};
mNotifyEvent = CreateEventW(nullptr, FALSE, FALSE, nullptr);
if(mNotifyEvent == nullptr)
{
- ERR("Failed to create notify event: %lu\n", GetLastError());
- hr = E_FAIL;
+ ERR("Failed to create notify events: %lu\n", GetLastError());
+ throw al::backend_exception{al::backend_error::DeviceError,
+ "Failed to create notify events"};
}
- if(SUCCEEDED(hr))
+ HRESULT hr{InitThread()};
+ if(FAILED(hr))
+ {
+ throw al::backend_exception{al::backend_error::DeviceError,
+ "Failed to init COM thread: 0x%08lx", hr};
+ }
+
+ if(name)
{
- if(name)
+ if(CaptureDevices.empty())
+ pushMessage(MsgType::EnumerateCapture);
+ if(std::strncmp(name, DevNameHead, DevNameHeadLen) == 0)
{
- if(CaptureDevices.empty())
- pushMessage(MsgType::EnumerateCapture);
- if(std::strncmp(name, DevNameHead, DevNameHeadLen) == 0)
- {
- name += DevNameHeadLen;
- if(*name == '\0')
- name = nullptr;
- }
+ name += DevNameHeadLen;
+ if(*name == '\0')
+ name = nullptr;
}
- hr = pushMessage(MsgType::OpenDevice, name).get();
}
- mOpenStatus = hr;
- if(FAILED(hr))
+ mOpenStatus = pushMessage(MsgType::OpenDevice, name).get();
+ if(FAILED(mOpenStatus))
+ {
+ DeinitThread();
throw al::backend_exception{al::backend_error::DeviceError, "Device init failed: 0x%08lx",
- hr};
+ mOpenStatus};
+ }
hr = pushMessage(MsgType::ResetDevice).get();
if(FAILED(hr))