diff options
author | Kevin Mitchell <kevmitch@gmail.com> | 2014-11-14 22:47:28 -0800 |
---|---|---|
committer | Kevin Mitchell <kevmitch@gmail.com> | 2014-11-17 04:13:52 -0800 |
commit | 3da6f723c6ceba468412f2282ab4f7958ca6f5d7 (patch) | |
tree | a175f6a7eff45230f1cb5f473278296aa15e8710 /audio/out/ao_wasapi_utils.c | |
parent | e28102f1a8d4c5284fa2d2eb13fe4147eefcd02b (diff) | |
download | mpv-3da6f723c6ceba468412f2282ab4f7958ca6f5d7.tar.bz2 mpv-3da6f723c6ceba468412f2282ab4f7958ca6f5d7.tar.xz |
ao/wasapi: tidy up better on failure
Before, failures, particularly in the thread loop init, could lead to a
bad state for the duration of mpvs execution. Make sure that
everything that was initialized gets properly and safely
uninitialized.
Diffstat (limited to 'audio/out/ao_wasapi_utils.c')
-rwxr-xr-x | audio/out/ao_wasapi_utils.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/audio/out/ao_wasapi_utils.c b/audio/out/ao_wasapi_utils.c index e54cbcd0bc..69bbefe5ef 100755 --- a/audio/out/ao_wasapi_utils.c +++ b/audio/out/ao_wasapi_utils.c @@ -921,13 +921,20 @@ exit_label: return hr; } +void wasapi_dispatch(void) +{ + /* dispatch any possible pending messages */ + MSG msg; + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) + DispatchMessage(&msg); +} + HRESULT wasapi_thread_init(struct ao *ao) { struct wasapi_state *state = (struct wasapi_state *)ao->priv; HRESULT hr; MP_DBG(ao, "Init wasapi thread\n"); state->initial_volume = -1.0; - CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); char *device = state->opt_device; if (!device || !device[0]) @@ -1010,10 +1017,14 @@ void wasapi_thread_uninit(struct ao *ao) { struct wasapi_state *state = (struct wasapi_state *)ao->priv; + wasapi_dispatch(); + if (state->pAudioClient) IAudioClient_Stop(state->pAudioClient); - if (state->opt_exclusive) + if (state->opt_exclusive && + state->pEndpointVolume && + state->initial_volume > 0 ) IAudioEndpointVolume_SetMasterVolumeLevelScalar(state->pEndpointVolume, state->initial_volume, NULL); |