aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMatthew Gregan <[email protected]>2022-01-09 08:45:52 +1300
committerMatthew Gregan <[email protected]>2022-01-11 08:31:50 +1300
commit9edd150d9d6483917feab1dd3ad429f25fd5a19c (patch)
tree22606fa16978e3c180bac28829bc4fc5746bd98a
parent9e29d728b0025c674904f83f5a13a88d1a6a5edc (diff)
downloadcubeb-9edd150d9d6483917feab1dd3ad429f25fd5a19c.tar.gz
cubeb-9edd150d9d6483917feab1dd3ad429f25fd5a19c.zip
waspi: Simplify default devices query and avoid nullptr deref.
-rw-r--r--src/cubeb_wasapi.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/cubeb_wasapi.cpp b/src/cubeb_wasapi.cpp
index 9685de3..cec688c 100644
--- a/src/cubeb_wasapi.cpp
+++ b/src/cubeb_wasapi.cpp
@@ -199,6 +199,24 @@ struct wasapi_default_devices {
wasapi_get_default_device_id(eCapture, eCommunications, enumerator))
{
}
+
+ bool is_default(EDataFlow flow, ERole role, wchar_t const * id)
+ {
+ wchar_t const * default_id = nullptr;
+ if (flow == eRender && role == eConsole) {
+ default_id = this->render_console_id.get();
+ } else if (flow == eRender && role == eCommunications) {
+ default_id = this->render_comms_id.get();
+ } else if (flow == eCapture && role == eConsole) {
+ default_id = this->capture_console_id.get();
+ } else if (flow == eCapture && role == eCommunications) {
+ default_id = this->capture_comms_id.get();
+ }
+
+ return default_id && wcscmp(id, default_id) == 0;
+ }
+
+private:
com_heap_ptr<wchar_t> render_console_id;
com_heap_ptr<wchar_t> render_comms_id;
com_heap_ptr<wchar_t> capture_console_id;
@@ -3160,17 +3178,11 @@ wasapi_create_device(cubeb * ctx, cubeb_device_info & ret,
}
ret.preferred = CUBEB_DEVICE_PREF_NONE;
- if ((flow == eRender &&
- wcscmp(device_id.get(), defaults->render_console_id.get()) == 0) ||
- (flow == eCapture &&
- wcscmp(device_id.get(), defaults->capture_console_id.get()) == 0)) {
+ if (defaults->is_default(flow, eConsole, device_id.get())) {
ret.preferred =
(cubeb_device_pref)(ret.preferred | CUBEB_DEVICE_PREF_MULTIMEDIA |
CUBEB_DEVICE_PREF_NOTIFICATION);
- } else if ((flow == eRender &&
- wcscmp(device_id.get(), defaults->render_comms_id.get()) == 0) ||
- (flow == eCapture &&
- wcscmp(device_id.get(), defaults->capture_comms_id.get()) == 0)) {
+ } else if (defaults->is_default(flow, eCommunications, device_id.get())) {
ret.preferred =
(cubeb_device_pref)(ret.preferred | CUBEB_DEVICE_PREF_VOICE);
}