Commit e8fae3ce authored by Ghislain MARY's avatar Ghislain MARY

Fix memory leaks + Call CoInitialize so that device enumeration works.

parent 3a823949
......@@ -33,8 +33,10 @@ const IID IID_IAudioClient2 = __uuidof(IAudioClient2);
const IID IID_IAudioCaptureClient = __uuidof(IAudioCaptureClient);
const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient);
#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE)
const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
#endif
/******************************************************************************
* Methods to (de)initialize and run the WASAPI sound capture filter *
......@@ -396,7 +398,8 @@ static void ms_wasapi_snd_card_detect_with_data_flow(MSSndCardManager *m, EDataF
IMMDevice *pEndpoint = NULL;
IPropertyStore *pProps = NULL;
LPWSTR pwszID = NULL;
HRESULT result = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void**)&pEnumerator);
HRESULT result = CoInitialize(NULL);
result = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void**)&pEnumerator);
REPORT_ERROR("mswasapi: Could not create an instance of the device enumerator", result);
result = pEnumerator->EnumAudioEndpoints(data_flow, DEVICE_STATE_ACTIVE, &pCollection);
REPORT_ERROR("mswasapi: Could not enumerate audio endpoints", result);
......
......@@ -50,3 +50,13 @@ typedef struct WasapiSndCard {
std::vector<wchar_t> *id_vector;
LPWSTR id;
} WasapiSndCard;
extern const IID IID_IAudioClient2;
extern const IID IID_IAudioCaptureClient;
extern const IID IID_IAudioRenderClient;
#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE)
extern const CLSID CLSID_MMDeviceEnumerator;
extern const IID IID_IMMDeviceEnumerator;
#endif
......@@ -86,12 +86,16 @@ void MSWASAPIReader::init(LPCWSTR id)
#else
IMMDeviceEnumerator *pEnumerator = NULL;
IMMDevice *pDevice = NULL;
CoInitialize(NULL);
result = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void**)&pEnumerator);
REPORT_ERROR("mswasapi: Could not create an instance of the device enumerator", result);
mCaptureId = id;
result = pEnumerator->GetDevice(mCaptureId, &pDevice);
REPORT_ERROR("mswasapi: Could not get the rendering device", result);
pDevice->Activate(IID_IAudioClient2, CLSCTX_ALL, NULL, (void **)&mAudioClient);
SAFE_RELEASE(pEnumerator);
REPORT_ERROR("mswasapi: Could not get the capture device", result);
result = pDevice->Activate(IID_IAudioClient2, CLSCTX_ALL, NULL, (void **)&mAudioClient);
SAFE_RELEASE(pDevice);
REPORT_ERROR("mswasapi: Could not activate the capture device", result);
#endif
properties.cbSize = sizeof AudioClientProperties;
properties.bIsOffload = false;
......
......@@ -84,12 +84,16 @@ void MSWASAPIWriter::init(LPCWSTR id) {
#else
IMMDeviceEnumerator *pEnumerator = NULL;
IMMDevice *pDevice = NULL;
CoInitialize(NULL);
result = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void**)&pEnumerator);
REPORT_ERROR("mswasapi: Could not create an instance of the device enumerator", result);
mRenderId = id;
result = pEnumerator->GetDevice(mRenderId, &pDevice);
SAFE_RELEASE(pEnumerator);
REPORT_ERROR("mswasapi: Could not get the rendering device", result);
pDevice->Activate(IID_IAudioClient2, CLSCTX_ALL, NULL, (void **)&mAudioClient);
result = pDevice->Activate(IID_IAudioClient2, CLSCTX_ALL, NULL, (void **)&mAudioClient);
SAFE_RELEASE(pDevice);
REPORT_ERROR("mswasapi: Could not activate the rendering device", result);
#endif
properties.cbSize = sizeof AudioClientProperties;
properties.bIsOffload = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment