[PATCH v2 1/3] mmdevapi: Make MMDevEnumerator a static variable.
Rémi Bernon
rbernon at codeweavers.com
Thu Jun 3 08:21:12 CDT 2021
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
dlls/mmdevapi/devenum.c | 40 ++++++++++++++--------------------------
1 file changed, 14 insertions(+), 26 deletions(-)
diff --git a/dlls/mmdevapi/devenum.c b/dlls/mmdevapi/devenum.c
index fc33cac17ec..a5863af2705 100644
--- a/dlls/mmdevapi/devenum.c
+++ b/dlls/mmdevapi/devenum.c
@@ -56,10 +56,9 @@ typedef struct MMDevPropStoreImpl
typedef struct MMDevEnumImpl
{
IMMDeviceEnumerator IMMDeviceEnumerator_iface;
- LONG ref;
+ BOOL initialized;
} MMDevEnumImpl;
-static MMDevEnumImpl *MMDevEnumerator;
static MMDevice **MMDevice_head;
static MMDevice *MMDevice_def_rec, *MMDevice_def_play;
static DWORD MMDevice_count;
@@ -69,6 +68,7 @@ static const IMMDeviceVtbl MMDeviceVtbl;
static const IPropertyStoreVtbl MMDevPropVtbl;
static const IMMEndpointVtbl MMEndpointVtbl;
+static MMDevEnumImpl enumerator;
static IMMDevice info_device;
typedef struct MMDevColImpl
@@ -860,23 +860,15 @@ static const IMMDeviceCollectionVtbl MMDevColVtbl =
HRESULT MMDevEnum_Create(REFIID riid, void **ppv)
{
- MMDevEnumImpl *This = MMDevEnumerator;
-
- if (!This)
+ if (!enumerator.initialized)
{
- This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
- *ppv = NULL;
- if (!This)
- return E_OUTOFMEMORY;
- This->ref = 1;
- This->IMMDeviceEnumerator_iface.lpVtbl = &MMDevEnumVtbl;
- MMDevEnumerator = This;
-
+ enumerator.initialized = TRUE;
load_devices_from_reg();
load_driver_devices(eRender);
load_driver_devices(eCapture);
}
- return IMMDeviceEnumerator_QueryInterface(&This->IMMDeviceEnumerator_iface, riid, ppv);
+
+ return IMMDeviceEnumerator_QueryInterface(&enumerator.IMMDeviceEnumerator_iface, riid, ppv);
}
void MMDevEnum_Free(void)
@@ -886,8 +878,6 @@ void MMDevEnum_Free(void)
RegCloseKey(key_render);
RegCloseKey(key_capture);
key_render = key_capture = NULL;
- HeapFree(GetProcessHeap(), 0, MMDevEnumerator);
- MMDevEnumerator = NULL;
}
static HRESULT WINAPI MMDevEnum_QueryInterface(IMMDeviceEnumerator *iface, REFIID riid, void **ppv)
@@ -910,20 +900,12 @@ static HRESULT WINAPI MMDevEnum_QueryInterface(IMMDeviceEnumerator *iface, REFII
static ULONG WINAPI MMDevEnum_AddRef(IMMDeviceEnumerator *iface)
{
- MMDevEnumImpl *This = impl_from_IMMDeviceEnumerator(iface);
- LONG ref = InterlockedIncrement(&This->ref);
- TRACE("Refcount now %i\n", ref);
- return ref;
+ return 2;
}
static ULONG WINAPI MMDevEnum_Release(IMMDeviceEnumerator *iface)
{
- MMDevEnumImpl *This = impl_from_IMMDeviceEnumerator(iface);
- LONG ref = InterlockedDecrement(&This->ref);
- if (!ref)
- MMDevEnum_Free();
- TRACE("Refcount now %i\n", ref);
- return ref;
+ return 1;
}
static HRESULT WINAPI MMDevEnum_EnumAudioEndpoints(IMMDeviceEnumerator *iface, EDataFlow flow, DWORD mask, IMMDeviceCollection **devices)
@@ -1287,6 +1269,12 @@ static const IMMDeviceEnumeratorVtbl MMDevEnumVtbl =
MMDevEnum_UnregisterEndpointNotificationCallback
};
+static MMDevEnumImpl enumerator =
+{
+ {&MMDevEnumVtbl},
+ FALSE,
+};
+
static HRESULT MMDevPropStore_Create(MMDevice *parent, DWORD access, IPropertyStore **ppv)
{
MMDevPropStore *This;
--
2.31.0
More information about the wine-devel
mailing list