// // Initialize the capturer. // bool CWASAPICapture::Initialize(UINT32 EngineLatency) { // // Create our shutdown event - we want auto reset events that start in the not-signaled state. // _ShutdownEvent = CreateEventEx(NULL, NULL, 0, EVENT_MODIFY_STATE | SYNCHRONIZE); if (_ShutdownEvent == NULL) { printf_s("Unable to create shutdown event: %d.\n", GetLastError()); return false; } // // Now activate an IAudioClient object on our preferred endpoint and retrieve the mix format for that endpoint. // HRESULT hr = _Endpoint->Activate(__uuidof(IAudioClient), CLSCTX_INPROC_SERVER, NULL, reinterpret_cast<void **>(&_AudioClient)); if (FAILED(hr)) { printf_s("Unable to activate audio client: %x.\n", hr); return false; } hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&_DeviceEnumerator)); if (FAILED(hr)) { printf_s("Unable to instantiate device enumerator: %x\n", hr); return false; } // // Load the MixFormat. This may differ depending on the shared mode used // if (!LoadFormat()) { printf_s("Failed to load the mix format \n"); return false; } // // Remember our configured latency // _EngineLatencyInMS = EngineLatency; if (!InitializeAudioEngine()) { return false; } return true; }
// // Initialize the capturer. // bool CWASAPICapture::Initialize(UINT32 EngineLatency) { // // Create our shutdown event - we want auto reset events that start in the not-signaled state. // _ShutdownEvent = CreateEventEx(NULL, NULL, 0, EVENT_MODIFY_STATE | SYNCHRONIZE); PersistentAssert(_ShutdownEvent != NULL, "CreateEventEx failed"); // // Create our stream switch event- we want auto reset events that start in the not-signaled state. // Note that we create this event even if we're not going to stream switch - that's because the event is used // in the main loop of the capturer and thus it has to be set. // _StreamSwitchEvent = CreateEventEx(NULL, NULL, 0, EVENT_MODIFY_STATE | SYNCHRONIZE); PersistentAssert(_StreamSwitchEvent != NULL, "CreateEventEx failed"); // // Now activate an IAudioClient object on our preferred endpoint and retrieve the mix format for that endpoint. // HRESULT hr = _Endpoint->Activate(__uuidof(IAudioClient), CLSCTX_INPROC_SERVER, NULL, reinterpret_cast<void **>(&_AudioClient)); PersistentAssert(SUCCEEDED(hr), "_Endpoint->Activate failed"); hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&_DeviceEnumerator)); PersistentAssert(SUCCEEDED(hr), "CoCreateInstance failed"); // // Load the MixFormat. This may differ depending on the shared mode used // LoadFormat(); // // Remember our configured latency in case we'll need it for a stream switch later. // _EngineLatencyInMS = EngineLatency; InitializeAudioEngine(); return true; }