summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--audio/out/ao_wasapi.c29
-rwxr-xr-xaudio/out/ao_wasapi_utils.c42
-rwxr-xr-xaudio/out/ao_wasapi_utils.h6
3 files changed, 22 insertions, 55 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),
diff --git a/audio/out/ao_wasapi_utils.c b/audio/out/ao_wasapi_utils.c
index eb4350f96d..1b201f6b20 100755
--- a/audio/out/ao_wasapi_utils.c
+++ b/audio/out/ao_wasapi_utils.c
@@ -829,20 +829,15 @@ end:
return found;
}
-HRESULT wasapi_enumerate_devices(struct ao *ao,
- struct ao_device_list *list)
+void wasapi_list_devs(struct ao *ao, struct ao_device_list *list)
{
- IMMDeviceEnumerator *pEnumerator = NULL;
+ struct wasapi_state *state = (struct wasapi_state *)ao->priv;
IMMDeviceCollection *pDevices = NULL;
IMMDevice *pDevice = NULL;
char *name = NULL, *id = NULL;
- HRESULT hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL,
- &IID_IMMDeviceEnumerator,
- (void **)&pEnumerator);
- EXIT_ON_ERROR(hr);
- hr = IMMDeviceEnumerator_EnumAudioEndpoints(pEnumerator, eRender,
- DEVICE_STATE_ACTIVE, &pDevices);
+ HRESULT hr = IMMDeviceEnumerator_EnumAudioEndpoints(state->pEnumerator, eRender,
+ DEVICE_STATE_ACTIVE, &pDevices);
EXIT_ON_ERROR(hr);
int count;
@@ -871,9 +866,8 @@ HRESULT wasapi_enumerate_devices(struct ao *ao,
SAFE_RELEASE(pDevice, IMMDevice_Release(pDevice));
}
SAFE_RELEASE(pDevices, IMMDeviceCollection_Release(pDevices));
- SAFE_RELEASE(pEnumerator, IMMDeviceEnumerator_Release(pEnumerator));
- return S_OK;
+ return;
exit_label:
MP_ERR(ao, "Error enumerating devices: %s (0x%"PRIx32")\n",
wasapi_explain_err(hr), (uint32_t) hr);
@@ -881,8 +875,6 @@ exit_label:
talloc_free(id);
SAFE_RELEASE(pDevice, IMMDevice_Release(pDevice));
SAFE_RELEASE(pDevices, IMMDeviceCollection_Release(pDevices));
- SAFE_RELEASE(pEnumerator, IMMDeviceEnumerator_Release(pEnumerator));
- return hr;
}
static HRESULT load_default_device(struct ao *ao, IMMDeviceEnumerator* pEnumerator,
@@ -1169,30 +1161,6 @@ exit_label:
return hr;
}
-HRESULT wasapi_hotplug_init(struct ao *ao)
-{
- struct wasapi_state *state = (struct wasapi_state *)ao->priv;
- 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);
-
- return S_OK;
-exit_label:
- MP_ERR(state, "Error setting up audio hotplug: %s (0x%"PRIx32")\n",
- wasapi_explain_err(hr), (uint32_t) hr);
- return hr;
-}
-
-void wasapi_hotplug_uninit(struct ao *ao)
-{
- struct wasapi_state *state = (struct wasapi_state *)ao->priv;
- wasapi_change_uninit(ao);
- SAFE_RELEASE(state->pEnumerator, IMMDeviceEnumerator_Release(state->pEnumerator));
-}
-
void wasapi_thread_uninit(struct ao *ao)
{
struct wasapi_state *state = (struct wasapi_state *)ao->priv;
diff --git a/audio/out/ao_wasapi_utils.h b/audio/out/ao_wasapi_utils.h
index 9806bba4a9..c0eb77388d 100755
--- a/audio/out/ao_wasapi_utils.h
+++ b/audio/out/ao_wasapi_utils.h
@@ -36,16 +36,12 @@ bool wasapi_fill_VistaBlob(wasapi_state *state);
const char *wasapi_explain_err(const HRESULT hr);
-HRESULT wasapi_enumerate_devices(struct ao *ao,
- struct ao_device_list *list);
+void wasapi_list_devs(struct ao *ao, struct ao_device_list *list);
void wasapi_dispatch(void);
HRESULT wasapi_thread_init(struct ao *ao);
void wasapi_thread_uninit(struct ao *ao);
-HRESULT wasapi_hotplug_init(struct ao *ao);
-void wasapi_hotplug_uninit(struct ao *ao);
-
HRESULT wasapi_setup_proxies(wasapi_state *state);
void wasapi_release_proxies(wasapi_state *state);