summaryrefslogtreecommitdiffstats
path: root/audio/out/ao_wasapi.c
diff options
context:
space:
mode:
authorKevin Mitchell <kevmitch@gmail.com>2015-03-31 12:53:05 -0700
committerKevin Mitchell <kevmitch@gmail.com>2015-03-31 13:43:32 -0700
commitb6c28dd26b6415181b406e1118920b13f80286b4 (patch)
tree2a7ee7350851c83de68f76b69f53bb1b79886874 /audio/out/ao_wasapi.c
parentea00fe0eebe234c5f6f0f01f7f117cca3516d4df (diff)
downloadmpv-b6c28dd26b6415181b406e1118920b13f80286b4.tar.bz2
mpv-b6c28dd26b6415181b406e1118920b13f80286b4.tar.xz
ao_wasapi: simplify hotplug
Take advantage of the fact that list_devs is called with a hotplug_inited ao. Also eliminate unnecessary nested function abstraction of hotplug_(un)init and list_devs. However, keep list_devs in ao_wasapi_utils.c since it uses the private functions get_device_id, get_device_name and exposing these would require including headers for IMMDevice in ao_wasapi_utils.h.
Diffstat (limited to 'audio/out/ao_wasapi.c')
-rw-r--r--audio/out/ao_wasapi.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/audio/out/ao_wasapi.c b/audio/out/ao_wasapi.c
index 5821409f91..441962d2ac 100644
--- a/audio/out/ao_wasapi.c
+++ b/audio/out/ao_wasapi.c
@@ -389,26 +389,29 @@ static void audio_resume(struct ao *ao)
static void hotplug_uninit(struct ao *ao)
{
MP_DBG(ao, "Hotplug uninit\n");
- wasapi_hotplug_uninit(ao);
+ struct wasapi_state *state = (struct wasapi_state *)ao->priv;
+ wasapi_change_uninit(ao);
+ SAFE_RELEASE(state->pEnumerator, IMMDeviceEnumerator_Release(state->pEnumerator));
CoUninitialize();
}
static int hotplug_init(struct ao *ao)
{
MP_DBG(ao, "Hotplug init\n");
+ struct wasapi_state *state = (struct wasapi_state *)ao->priv;
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
- if (wasapi_hotplug_init(ao) != S_OK) {
- hotplug_uninit(ao);
- return -1;
- }
- return 0;
-}
+ HRESULT hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL,
+ &IID_IMMDeviceEnumerator, (void **)&state->pEnumerator);
+ EXIT_ON_ERROR(hr);
+ hr = wasapi_change_init(ao, true);
+ EXIT_ON_ERROR(hr);
-static void list_devs(struct ao *ao, struct ao_device_list *list)
-{
- CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
- wasapi_enumerate_devices(ao, list);
- CoUninitialize();
+ return 0;
+ exit_label:
+ MP_ERR(state, "Error setting up audio hotplug: %s (0x%"PRIx32")\n",
+ wasapi_explain_err(hr), (uint32_t) hr);
+ hotplug_uninit(ao);
+ return -1;
}
#define OPT_BASE_STRUCT struct wasapi_state
@@ -421,7 +424,7 @@ const struct ao_driver audio_out_wasapi = {
.control = control,
.reset = audio_reset,
.resume = audio_resume,
- .list_devs = list_devs,
+ .list_devs = wasapi_list_devs,
.hotplug_init = hotplug_init,
.hotplug_uninit = hotplug_uninit,
.priv_size = sizeof(wasapi_state),