static int init(struct ao *ao) { MP_VERBOSE(ao, "init!\n"); ao->format = af_fmt_from_planar(ao->format); struct mp_chmap_sel sel = {0}; mp_chmap_sel_add_waveext(&sel); if (!ao_chmap_sel_adjust(ao, &sel, &ao->channels)) return -1; struct wasapi_state *state = (struct wasapi_state *)ao->priv; state->log = ao->log; wasapi_fill_VistaBlob(state); if (state->opt_list) { wasapi_enumerate_devices(state->log, NULL, NULL); } if (state->opt_exclusive) { state->share_mode = AUDCLNT_SHAREMODE_EXCLUSIVE; } else { state->share_mode = AUDCLNT_SHAREMODE_SHARED; } state->init_done = CreateEventW(NULL, FALSE, FALSE, NULL); state->hUninit = CreateEventW(NULL, FALSE, FALSE, NULL); state->hFeed = CreateEventW(NULL, FALSE, FALSE, NULL); /* for wasapi event mode */ state->hForceFeed = CreateEventW(NULL, FALSE, FALSE, NULL); state->hFeedDone = CreateEventW(NULL, FALSE, FALSE, NULL); if (!state->init_done || !state->hFeed || !state->hUninit || !state->hForceFeed || !state->hFeedDone) { closehandles(ao); /* failed to init events */ return -1; } state->init_ret = -1; state->threadLoop = (HANDLE)CreateThread(NULL, 0, &ThreadLoop, ao, 0, NULL); if (!state->threadLoop) { /* failed to init thread */ MP_ERR(ao, "fail to create thread!\n"); return -1; } WaitForSingleObject(state->init_done, INFINITE); /* wait on init complete */ if (state->init_ret) { if (!ao->probing) { MP_ERR(ao, "thread_init failed!\n"); } } else MP_VERBOSE(ao, "Init Done!\n"); wasapi_setup_proxies(state); return state->init_ret; }
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; if(!wasapi_fill_VistaBlob(state)) MP_WARN(ao, "Error loading thread priority functions\n"); 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_setup_proxies(state); MP_DBG(ao, "Init wasapi done\n"); return 0; }