aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPaul Adenot <[email protected]>2020-08-04 16:27:27 +0200
committerPaul Adenot <[email protected]>2020-09-09 14:30:03 +0200
commit5d5fa34e13f0bcf3356c7323e4ca800001675013 (patch)
tree4fa18a40b472f621b15de2828bb44384f1878a19
parent51f413eac684a89780cfde6a0f44a4c687a433dd (diff)
downloadcubeb-5d5fa34e13f0bcf3356c7323e4ca800001675013.tar.gz
cubeb-5d5fa34e13f0bcf3356c7323e4ca800001675013.zip
Always get a device enumerator when creating a stream
-rw-r--r--src/cubeb_wasapi.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/cubeb_wasapi.cpp b/src/cubeb_wasapi.cpp
index 6a7a30f..51620ac 100644
--- a/src/cubeb_wasapi.cpp
+++ b/src/cubeb_wasapi.cpp
@@ -1334,17 +1334,11 @@ void wasapi_destroy(cubeb * context);
HRESULT register_notification_client(cubeb_stream * stm)
{
- HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),
- NULL, CLSCTX_INPROC_SERVER,
- IID_PPV_ARGS(stm->device_enumerator.receive()));
- if (FAILED(hr)) {
- LOG("Could not get device enumerator: %lx", hr);
- return hr;
- }
+ assert(stm->device_enumerator);
stm->notification_client.reset(new wasapi_endpoint_notification_client(stm->reconfigure_event, stm->role));
- hr = stm->device_enumerator->RegisterEndpointNotificationCallback(stm->notification_client.get());
+ HRESULT hr = stm->device_enumerator->RegisterEndpointNotificationCallback(stm->notification_client.get());
if (FAILED(hr)) {
LOG("Could not register endpoint notification callback: %lx", hr);
stm->notification_client = nullptr;
@@ -1372,7 +1366,6 @@ HRESULT unregister_notification_client(cubeb_stream * stm)
}
stm->notification_client = nullptr;
- stm->device_enumerator = nullptr;
return S_OK;
}
@@ -2358,6 +2351,14 @@ wasapi_stream_init(cubeb * context, cubeb_stream ** stream,
stm->role = eConsole;
+ HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),
+ NULL, CLSCTX_INPROC_SERVER,
+ IID_PPV_ARGS(stm->device_enumerator.receive()));
+ if (FAILED(hr)) {
+ LOG("Could not get device enumerator: %lx", hr);
+ return hr;
+ }
+
if (input_stream_params) {
stm->input_stream_params = *input_stream_params;
stm->input_device_id = utf8_to_wstr(reinterpret_cast<char const *>(input_device));
@@ -2488,6 +2489,8 @@ void wasapi_stream_destroy(cubeb_stream * stm)
// must be destroyed in wasapi_stream_destroy.
stm->linear_input_buffer.reset();
+ stm->device_enumerator = nullptr;
+
{
auto_lock lock(stm->stream_reset_lock);
close_wasapi_stream(stm);