aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMatthew Gregan <[email protected]>2022-04-03 15:48:23 +1200
committerMatthew Gregan <[email protected]>2022-04-11 20:35:16 +1200
commite91fa6b3f25963533e1b7919b988bd20a9422118 (patch)
tree22590348a291535d9a2ea218fa524367b7211537
parent1079b1f926f3494371d693be9a1a742aa8e0d102 (diff)
downloadcubeb-e91fa6b3f25963533e1b7919b988bd20a9422118.tar.gz
cubeb-e91fa6b3f25963533e1b7919b988bd20a9422118.zip
wasapi: Enumerate only active devices when matching BT output device.
Potentially significantly shrinks the list of devices to search when matching BT output device with specified BT input device. On my local machine, this shrinks the list from 25 to 7, and reduces the initial enumerate time from ~67ms to ~32ms (and a subsequent call from ~14ms to ~12ms).
-rw-r--r--src/cubeb_wasapi.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/cubeb_wasapi.cpp b/src/cubeb_wasapi.cpp
index 7e1c1e5..7fe0778 100644
--- a/src/cubeb_wasapi.cpp
+++ b/src/cubeb_wasapi.cpp
@@ -240,8 +240,9 @@ wasapi_create_device(cubeb * ctx, cubeb_device_info & ret,
void
wasapi_destroy_device(cubeb_device_info * device_info);
static int
-wasapi_enumerate_devices(cubeb * context, cubeb_device_type type,
- cubeb_device_collection * out);
+wasapi_enumerate_devices_internal(cubeb * context, cubeb_device_type type,
+ cubeb_device_collection * out,
+ DWORD state_mask);
static int
wasapi_device_collection_destroy(cubeb * ctx,
cubeb_device_collection * collection);
@@ -2393,10 +2394,10 @@ wasapi_find_bt_handsfree_output_device(cubeb_stream * stm)
return nullptr;
}
- int rv = wasapi_enumerate_devices(
+ int rv = wasapi_enumerate_devices_internal(
stm->context,
(cubeb_device_type)(CUBEB_DEVICE_TYPE_INPUT | CUBEB_DEVICE_TYPE_OUTPUT),
- &collection);
+ &collection, DEVICE_STATE_ACTIVE);
if (rv != CUBEB_OK) {
return nullptr;
}
@@ -3330,8 +3331,9 @@ wasapi_destroy_device(cubeb_device_info * device)
}
static int
-wasapi_enumerate_devices(cubeb * context, cubeb_device_type type,
- cubeb_device_collection * out)
+wasapi_enumerate_devices_internal(cubeb * context, cubeb_device_type type,
+ cubeb_device_collection * out,
+ DWORD state_mask)
{
com_ptr<IMMDeviceEnumerator> enumerator;
com_ptr<IMMDeviceCollection> collection;
@@ -3359,10 +3361,7 @@ wasapi_enumerate_devices(cubeb * context, cubeb_device_type type,
return CUBEB_ERROR;
}
- hr = enumerator->EnumAudioEndpoints(
- flow,
- DEVICE_STATE_ACTIVE | DEVICE_STATE_DISABLED | DEVICE_STATE_UNPLUGGED,
- collection.receive());
+ hr = enumerator->EnumAudioEndpoints(flow, state_mask, collection.receive());
if (FAILED(hr)) {
LOG("Could not enumerate audio endpoints: %lx", hr);
return CUBEB_ERROR;
@@ -3397,6 +3396,15 @@ wasapi_enumerate_devices(cubeb * context, cubeb_device_type type,
}
static int
+wasapi_enumerate_devices(cubeb * context, cubeb_device_type type,
+ cubeb_device_collection * out)
+{
+ return wasapi_enumerate_devices_internal(
+ context, type, out,
+ DEVICE_STATE_ACTIVE | DEVICE_STATE_DISABLED | DEVICE_STATE_UNPLUGGED);
+}
+
+static int
wasapi_device_collection_destroy(cubeb * /*ctx*/,
cubeb_device_collection * collection)
{