static int hotplug_init(struct ao *ao) { MP_DBG(ao, "Hotplug init\n"); struct wasapi_state *state = ao->priv; state->log = ao->log; CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); HRESULT hr = wasapi_change_init(ao, true); EXIT_ON_ERROR(hr); return 0; exit_label: MP_ERR(state, "Error setting up audio hotplug: %s\n", mp_HRESULT_to_str(hr)); hotplug_uninit(ao); return -1; }
static int init(struct ao *ao) { MP_DBG(ao, "Init wasapi\n"); CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); struct wasapi_state *state = ao->priv; state->log = ao->log; state->deviceID = find_deviceID(ao); if (!state->deviceID) { uninit(ao); return -1; } wasapi_change_init(ao, false); state->hInitDone = CreateEventW(NULL, FALSE, FALSE, NULL); state->hWake = CreateEventW(NULL, FALSE, FALSE, NULL); if (!state->hInitDone || !state->hWake) { MP_ERR(ao, "Error creating events\n"); uninit(ao); return -1; } state->init_ret = E_FAIL; state->hAudioThread = CreateThread(NULL, 0, &AudioThread, ao, 0, NULL); if (!state->hAudioThread) { MP_ERR(ao, "Failed to create audio thread\n"); uninit(ao); return -1; } WaitForSingleObject(state->hInitDone, INFINITE); // wait on init complete SAFE_RELEASE(state->hInitDone,CloseHandle(state->hInitDone)); if (state->init_ret != S_OK) { if (!ao->probing) MP_ERR(ao, "Received failure from audio thread\n"); uninit(ao); return -1; } wasapi_receive_proxies(state); MP_DBG(ao, "Init wasapi done\n"); return 0; }
static int hotplug_init(struct ao *ao) { MP_DBG(ao, "Hotplug init\n"); struct wasapi_state *state = ao->priv; state->log = ao->log; CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); HRESULT hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, &IID_IMMDeviceEnumerator, (void **)&state->pEnumerator); EXIT_ON_ERROR(hr); hr = wasapi_change_init(ao, true); EXIT_ON_ERROR(hr); return 0; exit_label: MP_ERR(state, "Error setting up audio hotplug: %s\n", mp_HRESULT_to_str(hr)); hotplug_uninit(ao); return -1; }