summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--audio/out/ao_wasapi.c8
-rwxr-xr-xaudio/out/ao_wasapi_utils.c31
-rwxr-xr-xaudio/out/ao_wasapi_utils.h3
3 files changed, 32 insertions, 10 deletions
diff --git a/audio/out/ao_wasapi.c b/audio/out/ao_wasapi.c
index 39d6a5bda6..66de466bbc 100644
--- a/audio/out/ao_wasapi.c
+++ b/audio/out/ao_wasapi.c
@@ -191,7 +191,7 @@ static int init(struct ao *ao)
wasapi_fill_VistaBlob(state);
if (state->opt_list) {
- wasapi_enumerate_devices(state->log);
+ wasapi_enumerate_devices(state->log, NULL, NULL);
}
if (state->opt_exclusive) {
@@ -329,6 +329,11 @@ static void audio_resume(struct ao *ao)
IAudioClient_Start(state->pAudioClientProxy);
}
+static void list_devs(struct ao *ao, struct ao_device_list *list)
+{
+ wasapi_enumerate_devices(mp_null_log, ao, list);
+}
+
#define OPT_BASE_STRUCT struct wasapi_state
const struct ao_driver audio_out_wasapi = {
@@ -339,6 +344,7 @@ const struct ao_driver audio_out_wasapi = {
.control = control,
//.reset = audio_reset, <- doesn't wait for audio callback to return
.resume = audio_resume,
+ .list_devs = list_devs,
.priv_size = sizeof(wasapi_state),
.options = (const struct m_option[]) {
OPT_FLAG("exclusive", opt_exclusive, 0),
diff --git a/audio/out/ao_wasapi_utils.c b/audio/out/ao_wasapi_utils.c
index bf59d7802b..043183d32a 100755
--- a/audio/out/ao_wasapi_utils.c
+++ b/audio/out/ao_wasapi_utils.c
@@ -619,8 +619,10 @@ end:
return found;
}
-static HRESULT enumerate_with_state(struct mp_log *log, char *header,
- int status, int with_id)
+// Warning: ao and list are NULL in the "--ao=wasapi:device=help" path!
+static HRESULT enumerate_with_state(struct mp_log *log, struct ao *ao,
+ struct ao_device_list *list,
+ char *header, int status, int with_id)
{
HRESULT hr;
IMMDeviceEnumerator *pEnumerator = NULL;
@@ -668,6 +670,12 @@ static HRESULT enumerate_with_state(struct mp_log *log, char *header,
mp_info(log, "%s, ID: %s%s\n", name, id, mark);
}
+ if (ao) {
+ char *desc = talloc_asprintf(NULL, "%s, ID: %s%s", name, id, mark);
+ struct ao_device_desc e = {id, desc};
+ ao_device_list_add(list, ao, &e);
+ }
+
talloc_free(name);
talloc_free(id);
SAFE_RELEASE(pDevice, IMMDevice_Release(pDevice));
@@ -685,14 +693,17 @@ exit_label:
return hr;
}
-int wasapi_enumerate_devices(struct mp_log *log)
+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, "Active devices:", DEVICE_STATE_ACTIVE, 1);
+ hr = enumerate_with_state(log, ao, list, "Active devices:",
+ DEVICE_STATE_ACTIVE, 1);
EXIT_ON_ERROR(hr);
- hr = enumerate_with_state(log, "Unplugged devices:", DEVICE_STATE_UNPLUGGED, 0);
+ hr = enumerate_with_state(log, ao, list, "Unplugged devices:",
+ DEVICE_STATE_UNPLUGGED, 0);
EXIT_ON_ERROR(hr);
CoUninitialize();
return 0;
@@ -822,7 +833,7 @@ int wasapi_validate_device(struct mp_log *log, const m_option_t *opt,
struct bstr name, struct bstr param)
{
if (bstr_equals0(param, "help")) {
- wasapi_enumerate_devices(log);
+ wasapi_enumerate_devices(log, NULL, NULL);
return M_OPT_EXIT;
}
@@ -901,7 +912,11 @@ int wasapi_thread_init(struct ao *ao)
HRESULT hr;
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
- if (!state->opt_device) {
+ char *device = state->opt_device;
+ if (!device || !device[0])
+ device = ao->device;
+
+ if (!device || !device[0]) {
IMMDeviceEnumerator *pEnumerator;
hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL,
&IID_IMMDeviceEnumerator, (void**)&pEnumerator);
@@ -916,7 +931,7 @@ int wasapi_thread_init(struct ao *ao)
MP_VERBOSE(ao, "default device ID: %s\n", id);
talloc_free(id);
} else {
- hr = find_and_load_device(ao, &state->pDevice, state->opt_device);
+ hr = find_and_load_device(ao, &state->pDevice, device);
}
EXIT_ON_ERROR(hr);
diff --git a/audio/out/ao_wasapi_utils.h b/audio/out/ao_wasapi_utils.h
index fdc6e4fb7c..ee171ebb3c 100755
--- a/audio/out/ao_wasapi_utils.h
+++ b/audio/out/ao_wasapi_utils.h
@@ -31,7 +31,8 @@ int wasapi_fill_VistaBlob(wasapi_state *state);
const char *wasapi_explain_err(const HRESULT hr);
-int wasapi_enumerate_devices(struct mp_log *log);
+int wasapi_enumerate_devices(struct mp_log *log, struct ao *ao,
+ struct ao_device_list *list);
int wasapi_validate_device(struct mp_log *log, const m_option_t *opt,
struct bstr name, struct bstr param);