summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Mitchell <kevmitch@gmail.com>2016-01-04 17:43:22 -0800
committerKevin Mitchell <kevmitch@gmail.com>2016-01-05 17:47:55 -0800
commitd22d24a6d53abdeac32e13317a78c0b905769185 (patch)
tree8f347752fc8c47aa0e953290ad7e83eb009f17f0
parentfb84c6974d0026aab7e23aedd4136952b1c6ab7b (diff)
downloadmpv-d22d24a6d53abdeac32e13317a78c0b905769185.tar.bz2
mpv-d22d24a6d53abdeac32e13317a78c0b905769185.tar.xz
ao_wasapi: move device selection to main thread
In attempt to simplify the audio event thread, this can now be moved out.
-rw-r--r--audio/out/ao_wasapi.c7
-rw-r--r--audio/out/ao_wasapi_utils.c10
-rw-r--r--audio/out/ao_wasapi_utils.h1
3 files changed, 10 insertions, 8 deletions
diff --git a/audio/out/ao_wasapi.c b/audio/out/ao_wasapi.c
index 37f6d3b4de..9f8a3fedd7 100644
--- a/audio/out/ao_wasapi.c
+++ b/audio/out/ao_wasapi.c
@@ -273,7 +273,7 @@ static void uninit(struct ao *ao)
SAFE_RELEASE(state->hInitDone, CloseHandle(state->hInitDone));
SAFE_RELEASE(state->hWake, CloseHandle(state->hWake));
SAFE_RELEASE(state->hAudioThread,CloseHandle(state->hAudioThread));
-
+ talloc_free(state->deviceID);
CoUninitialize();
MP_DBG(ao, "Uninit wasapi done\n");
}
@@ -286,6 +286,11 @@ static int init(struct ao *ao)
struct wasapi_state *state = ao->priv;
state->log = ao->log;
+ if (!find_device(ao)) {
+ uninit(ao);
+ return -1;
+ }
+
state->hInitDone = CreateEventW(NULL, FALSE, FALSE, NULL);
state->hWake = CreateEventW(NULL, FALSE, FALSE, NULL);
if (!state->hInitDone || !state->hWake) {
diff --git a/audio/out/ao_wasapi_utils.c b/audio/out/ao_wasapi_utils.c
index 10f686c6ab..70d8fd180f 100644
--- a/audio/out/ao_wasapi_utils.c
+++ b/audio/out/ao_wasapi_utils.c
@@ -933,7 +933,7 @@ exit_label:
return hr;
}
-static HRESULT find_device(struct ao *ao)
+bool find_device(struct ao *ao)
{
struct wasapi_state *state = ao->priv;
bstr device = bstr_strip(bstr0(state->opt_device));
@@ -996,7 +996,7 @@ static HRESULT find_device(struct ao *ao)
exit_label:
talloc_free(d);
destroy_enumerator(enumerator);
- return state->deviceID ? S_OK : E_FAIL;
+ return !!state->deviceID;
}
static void *unmarshal(struct wasapi_state *state, REFIID type, IStream **from)
@@ -1092,10 +1092,7 @@ HRESULT wasapi_thread_init(struct ao *ao)
MP_DBG(ao, "Init wasapi thread\n");
int64_t retry_wait = 1;
retry: ;
- HRESULT hr = find_device(ao);
- EXIT_ON_ERROR(hr);
-
- hr = load_device(ao->log, &state->pDevice, state->deviceID);
+ HRESULT hr = load_device(ao->log, &state->pDevice, state->deviceID);
EXIT_ON_ERROR(hr);
MP_DBG(ao, "Activating pAudioClient interface\n");
@@ -1154,7 +1151,6 @@ void wasapi_thread_uninit(struct ao *ao)
SAFE_RELEASE(state->pSessionControl, IAudioSessionControl_Release(state->pSessionControl));
SAFE_RELEASE(state->pAudioClient, IAudioClient_Release(state->pAudioClient));
SAFE_RELEASE(state->pDevice, IMMDevice_Release(state->pDevice));
- SAFE_RELEASE(state->deviceID, talloc_free(state->deviceID));
SAFE_RELEASE(state->hTask, AvRevertMmThreadCharacteristics(state->hTask));
MP_DBG(ao, "Thread uninit done\n");
}
diff --git a/audio/out/ao_wasapi_utils.h b/audio/out/ao_wasapi_utils.h
index 8e6b4318d3..1d0c0e5dcd 100644
--- a/audio/out/ao_wasapi_utils.h
+++ b/audio/out/ao_wasapi_utils.h
@@ -38,6 +38,7 @@ char *mp_HRESULT_to_str_buf(char *buf, size_t buf_size, HRESULT hr);
bool wasapi_fill_VistaBlob(wasapi_state *state);
void wasapi_list_devs(struct ao *ao, struct ao_device_list *list);
+bool find_device(struct ao *ao);
void wasapi_dispatch(struct ao *ao);
HRESULT wasapi_thread_init(struct ao *ao);