win-wasapi: Persist objects beyond Start/Stop

Initialize IMMNotificationClient and IMMDeviceEnumerator in constructor
to simplify cleanup and initializaiton. Both can survive a reset.
This commit is contained in:
jpark37
2021-09-25 11:51:14 -07:00
parent 12442c3e57
commit 15f9d37aef

View File

@@ -23,12 +23,12 @@ static void GetWASAPIDefaults(obs_data_t *settings);
(KSAUDIO_SPEAKER_SURROUND | SPEAKER_LOW_FREQUENCY)
class WASAPISource {
ComPtr<IMMNotificationClient> notify;
ComPtr<IMMDeviceEnumerator> enumerator;
ComPtr<IMMDevice> device;
ComPtr<IAudioClient> client;
ComPtr<IAudioCaptureClient> capture;
ComPtr<IAudioRenderClient> render;
ComPtr<IMMDeviceEnumerator> enumerator;
ComPtr<IMMNotificationClient> notify;
obs_source_t *source;
wstring default_id;
@@ -149,6 +149,20 @@ WASAPISource::WASAPISource(obs_data_t *settings, obs_source_t *source_,
if (!receiveSignal.Valid())
throw "Could not create receive signal";
notify = new WASAPINotify(this);
if (!notify)
throw "Could not create WASAPINotify";
HRESULT res = CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr,
CLSCTX_ALL,
IID_PPV_ARGS(enumerator.Assign()));
if (FAILED(res))
throw HRError("Failed to create enumerator", res);
res = enumerator->RegisterEndpointNotificationCallback(notify);
if (FAILED(res))
throw HRError("Failed to register endpoint callback", res);
Start();
}
@@ -365,23 +379,10 @@ void WASAPISource::InitCapture()
void WASAPISource::Initialize()
{
HRESULT res;
res = CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr,
CLSCTX_ALL, __uuidof(IMMDeviceEnumerator),
(void **)enumerator.Assign());
if (FAILED(res))
throw HRError("Failed to create enumerator", res);
InitDevice();
device_name = GetDeviceName(device);
if (!notify) {
notify = new WASAPINotify(this);
enumerator->RegisterEndpointNotificationCallback(notify);
}
HRESULT resSample;
IPropertyStore *store = nullptr;
PWAVEFORMATEX deviceFormatProperties;