From d40c0d4f9006b4195a5509ae182e377ae88d16f6 Mon Sep 17 00:00:00 2001 From: Kevin Mitchell Date: Thu, 27 Nov 2014 18:44:06 -0800 Subject: ao/wasapi: fix unmatched CoUninitialize() on init failure --- audio/out/ao_wasapi.c | 5 +++++ audio/out/ao_wasapi_utils.c | 8 -------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/audio/out/ao_wasapi.c b/audio/out/ao_wasapi.c index 8477a9cb51..30767549fd 100644 --- a/audio/out/ao_wasapi.c +++ b/audio/out/ao_wasapi.c @@ -195,12 +195,15 @@ static void uninit(struct ao *ao) if (state->VistaBlob.hAvrt) FreeLibrary(state->VistaBlob.hAvrt); closehandles(ao); + CoUninitialize(); MP_DBG(ao, "Uninit wasapi done\n"); } static int init(struct ao *ao) { MP_DBG(ao, "Init wasapi\n"); + CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + ao->format = af_fmt_from_planar(ao->format); struct mp_chmap_sel sel = {0}; mp_chmap_sel_add_waveext(&sel); @@ -356,7 +359,9 @@ static void audio_resume(struct ao *ao) static void list_devs(struct ao *ao, struct ao_device_list *list) { + CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); wasapi_enumerate_devices(mp_null_log, ao, list); + CoUninitialize(); } #define OPT_BASE_STRUCT struct wasapi_state diff --git a/audio/out/ao_wasapi_utils.c b/audio/out/ao_wasapi_utils.c index 71b8b20e1f..40829c6f9e 100755 --- a/audio/out/ao_wasapi_utils.c +++ b/audio/out/ao_wasapi_utils.c @@ -733,20 +733,16 @@ int wasapi_enumerate_devices(struct mp_log *log, struct ao *ao, struct ao_device_list *list) { HRESULT hr; - CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); - hr = enumerate_with_state(log, ao, list, "Active devices:", DEVICE_STATE_ACTIVE, 1); EXIT_ON_ERROR(hr); hr = enumerate_with_state(log, ao, list, "Unplugged devices:", DEVICE_STATE_UNPLUGGED, 0); EXIT_ON_ERROR(hr); - CoUninitialize(); return 0; exit_label: mp_err(log, "Error enumerating devices: %s (0x%"PRIx32")\n", wasapi_explain_err(hr), (uint32_t)hr); - CoUninitialize(); return 1; } @@ -904,8 +900,6 @@ int wasapi_validate_device(struct mp_log *log, const m_option_t *opt, HRESULT wasapi_setup_proxies(struct wasapi_state *state) { HRESULT hr; - CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); - #define UNMARSHAL(type, to, from) do { \ hr = CoGetInterfaceAndReleaseStream((from), &(type), (void**) &(to)); \ (from) = NULL; \ @@ -931,8 +925,6 @@ void wasapi_release_proxies(wasapi_state *state) { SAFE_RELEASE(state->pAudioVolumeProxy, IUnknown_Release(state->pAudioVolumeProxy)); SAFE_RELEASE(state->pEndpointVolumeProxy, IUnknown_Release(state->pEndpointVolumeProxy)); SAFE_RELEASE(state->pSessionControlProxy, IUnknown_Release(state->pSessionControlProxy)); - - CoUninitialize(); } static HRESULT create_proxies(struct wasapi_state *state) { -- cgit v1.2.3