diff options
author | Alex Marsev <alex.marsev@gmail.com> | 2015-09-19 09:11:50 +0300 |
---|---|---|
committer | Alex Marsev <alex.marsev@gmail.com> | 2015-09-19 09:12:33 +0300 |
commit | f8ac0ae4db19c699860324ca3d93ec4c28e55479 (patch) | |
tree | 6e1674313eb110b81f3ccec68ae781db196dbe5d | |
parent | b6ef854e7b9132bb8b3e72cf0d6409ab07deb9c3 (diff) |
Move GetDefaultDeviceId() to MTA thread
-rw-r--r-- | src/AudioDeviceManager.cpp | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/src/AudioDeviceManager.cpp b/src/AudioDeviceManager.cpp index 1990bc1..4eaaae9 100644 --- a/src/AudioDeviceManager.cpp +++ b/src/AudioDeviceManager.cpp @@ -327,6 +327,30 @@ namespace SaneAudioRenderer return ex;
}
}
+
+ HRESULT GetDefaultDeviceIdInternal(IMMDeviceEnumerator* pEnumerator,
+ std::unique_ptr<WCHAR, CoTaskMemFreeDeleter>& id)
+ {
+ assert(pEnumerator);
+
+ id = nullptr;
+
+ try
+ {
+ IMMDevicePtr device;
+ ThrowIfFailed(pEnumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &device));
+
+ LPWSTR pDeviceId = nullptr;
+ ThrowIfFailed(device->GetId(&pDeviceId));
+ id = std::unique_ptr<WCHAR, CoTaskMemFreeDeleter>(pDeviceId);
+ }
+ catch (HRESULT ex)
+ {
+ return ex;
+ }
+
+ return S_OK;
+ }
}
AudioDeviceNotificationClient::AudioDeviceNotificationClient(std::atomic<uint32_t>& defaultDeviceSerial)
@@ -473,18 +497,12 @@ namespace SaneAudioRenderer {
assert(m_enumerator);
- try
- {
- IMMDevicePtr device;
- ThrowIfFailed(m_enumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &device));
+ std::unique_ptr<WCHAR, CoTaskMemFreeDeleter> id;
- LPWSTR pDeviceId = nullptr;
- ThrowIfFailed(device->GetId(&pDeviceId));
- return std::unique_ptr<WCHAR, CoTaskMemFreeDeleter>(pDeviceId);
- }
- catch (HRESULT)
- {
- return nullptr;
- }
+ m_function = [&] { return GetDefaultDeviceIdInternal(m_enumerator, id); };
+ m_wake.Set();
+ m_done.Wait();
+
+ return id;
}
}
|