mirror of
https://github.com/mpv-player/mpv
synced 2025-02-16 20:27:23 +00:00
ao/wasapi: fix unmatched CoUninitialize() on init failure
This commit is contained in:
parent
d0c37f0731
commit
d40c0d4f90
@ -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
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user