[PATCH 2/5] winepulse.drv: Cache the devices looked up in the registry.
Gabriel Ivăncescu
gabrielopcode at gmail.com
Wed Feb 9 08:10:55 CST 2022
Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
Will be necessary for next patch since we'll have to look it up on each
prop call.
dlls/winepulse.drv/mmdevdrv.c | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c
index bf14324..0e4fe9e 100644
--- a/dlls/winepulse.drv/mmdevdrv.c
+++ b/dlls/winepulse.drv/mmdevdrv.c
@@ -63,6 +63,14 @@ static struct pulse_config pulse_config;
static HANDLE pulse_thread;
static struct list g_sessions = LIST_INIT(g_sessions);
+static struct list g_devices_cache = LIST_INIT(g_devices_cache);
+
+struct device_cache {
+ struct list entry;
+ GUID guid;
+ EDataFlow dataflow;
+ char device[0];
+};
static GUID pulse_render_guid =
{ 0xfd47d9cc, 0x4218, 0x4135, { 0x9c, 0xe2, 0x0c, 0x19, 0x5c, 0x87, 0x40, 0x5b } };
@@ -88,6 +96,10 @@ BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, void *reserved)
if (__wine_unix_call(pulse_handle, process_attach, NULL))
return FALSE;
} else if (reason == DLL_PROCESS_DETACH) {
+ struct device_cache *device, *device_next;
+
+ LIST_FOR_EACH_ENTRY_SAFE(device, device_next, &g_devices_cache, struct device_cache, entry)
+ free(device);
__wine_unix_call(pulse_handle, process_detach, NULL);
if (pulse_thread) {
WaitForSingleObject(pulse_thread, INFINITE);
@@ -372,6 +384,7 @@ int WINAPI AUDDRV_GetPriority(void)
static BOOL get_pulse_name_by_guid(const GUID *guid, char name[256], EDataFlow *flow)
{
+ struct device_cache *device;
DWORD key_name_size;
WCHAR key_name[258];
DWORD index = 0;
@@ -387,6 +400,15 @@ static BOOL get_pulse_name_by_guid(const GUID *guid, char name[256], EDataFlow *
return TRUE;
}
+ /* Check the cache first */
+ LIST_FOR_EACH_ENTRY(device, &g_devices_cache, struct device_cache, entry) {
+ if (!IsEqualGUID(guid, &device->guid))
+ continue;
+ *flow = device->dataflow;
+ strcpy(name, device->device);
+ return TRUE;
+ }
+
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Wine\\Drivers\\winepulse.drv\\devices",
0, KEY_READ | KEY_WOW64_64KEY, &key) != ERROR_SUCCESS) {
WARN("No devices found in registry\n");
@@ -398,6 +420,7 @@ static BOOL get_pulse_name_by_guid(const GUID *guid, char name[256], EDataFlow *
LSTATUS status;
GUID reg_guid;
HKEY dev_key;
+ int len;
key_name_size = ARRAY_SIZE(key_name);
if (RegEnumKeyExW(key, index++, key_name, &key_name_size, NULL,
@@ -427,7 +450,16 @@ static BOOL get_pulse_name_by_guid(const GUID *guid, char name[256], EDataFlow *
return FALSE;
}
- return WideCharToMultiByte(CP_UNIXCP, 0, key_name + 2, -1, name, 256, NULL, NULL);
+ if (!(len = WideCharToMultiByte(CP_UNIXCP, 0, key_name + 2, -1, name, 256, NULL, NULL)))
+ return FALSE;
+
+ if ((device = malloc(FIELD_OFFSET(struct device_cache, device[len])))) {
+ device->guid = reg_guid;
+ device->dataflow = *flow;
+ strcpy(device->device, name);
+ list_add_tail(&g_devices_cache, &device->entry);
+ }
+ return TRUE;
}
}
--
2.34.1
More information about the wine-devel
mailing list