summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorKevin Mitchell <kevmitch@gmail.com>2016-01-04 18:09:03 -0800
committerKevin Mitchell <kevmitch@gmail.com>2016-01-05 17:47:55 -0800
commit8368ead1fa279e84012eaffcad321bb3cd1ed166 (patch)
tree4bbfc04580548dbe050b156060cb7734d730df2a /audio
parentd22d24a6d53abdeac32e13317a78c0b905769185 (diff)
downloadmpv-8368ead1fa279e84012eaffcad321bb3cd1ed166.tar.bz2
mpv-8368ead1fa279e84012eaffcad321bb3cd1ed166.tar.xz
ao_wasapi: make find_deviceID read only wrt struct ao
This makes it clearer that state->device is being allocated.
Diffstat (limited to 'audio')
-rw-r--r--audio/out/ao_wasapi.c3
-rw-r--r--audio/out/ao_wasapi_utils.c34
-rw-r--r--audio/out/ao_wasapi_utils.h2
3 files changed, 20 insertions, 19 deletions
diff --git a/audio/out/ao_wasapi.c b/audio/out/ao_wasapi.c
index 9f8a3fedd7..e6f1c32662 100644
--- a/audio/out/ao_wasapi.c
+++ b/audio/out/ao_wasapi.c
@@ -286,7 +286,8 @@ static int init(struct ao *ao)
struct wasapi_state *state = ao->priv;
state->log = ao->log;
- if (!find_device(ao)) {
+ state->deviceID = find_deviceID(ao);
+ if (!state->deviceID) {
uninit(ao);
return -1;
}
diff --git a/audio/out/ao_wasapi_utils.c b/audio/out/ao_wasapi_utils.c
index 70d8fd180f..92ca547a4d 100644
--- a/audio/out/ao_wasapi_utils.c
+++ b/audio/out/ao_wasapi_utils.c
@@ -904,16 +904,6 @@ exit_label:
destroy_enumerator(enumerator);
}
-static void select_device(struct wasapi_state *state, struct device_desc *d)
-{
- if (!d)
- return;
- MP_VERBOSE(state, "Selecting device \'%s\' (%s)\n", d->id, d->name);
- state->deviceID = talloc_memdup(NULL, d->deviceID,
- (wcslen(d->deviceID) + 1) * sizeof(wchar_t));
- return;
-}
-
static HRESULT load_device(struct mp_log *l,
IMMDevice **ppDevice, LPWSTR deviceID)
{
@@ -933,8 +923,18 @@ exit_label:
return hr;
}
-bool find_device(struct ao *ao)
+static LPWSTR select_device(struct mp_log *l, struct device_desc *d)
+{
+ if (!d)
+ return NULL;
+ mp_verbose(l, "Selecting device \'%s\' (%s)\n", d->id, d->name);
+ return talloc_memdup(NULL, d->deviceID,
+ (wcslen(d->deviceID) + 1) * sizeof(wchar_t));
+}
+
+LPWSTR find_deviceID(struct ao *ao)
{
+ LPWSTR deviceID = NULL;
struct wasapi_state *state = ao->priv;
bstr device = bstr_strip(bstr0(state->opt_device));
if (!device.len)
@@ -950,7 +950,7 @@ bool find_device(struct ao *ao)
if (!device.len) {
MP_VERBOSE(ao, "No device specified. Selecting default.\n");
d = default_device_desc(enumerator);
- select_device(state, d);
+ deviceID = select_device(ao->log, d);
goto exit_label;
}
@@ -960,7 +960,7 @@ bool find_device(struct ao *ao)
if (!rest.len && 0 <= devno && devno < enumerator->count) {
MP_VERBOSE(ao, "Selecting device by number: #%lld\n", devno);
d = device_desc_for_num(enumerator, devno);
- select_device(state, d);
+ deviceID = select_device(ao->log, d);
goto exit_label;
}
@@ -973,14 +973,14 @@ bool find_device(struct ao *ao)
if (bstrcmp(device, bstr_strip(bstr0(d->id))) == 0) {
MP_VERBOSE(ao, "Selecting device by id: \'%.*s\'\n", BSTR_P(device));
- select_device(state, d);
+ deviceID = select_device(ao->log, d);
goto exit_label;
}
if (bstrcmp(device, bstr_strip(bstr0(d->name))) == 0) {
if (!state->deviceID) {
MP_VERBOSE(ao, "Selecting device by name: \'%.*s\'\n", BSTR_P(device));
- select_device(state, d);
+ deviceID = select_device(ao->log, d);
} else {
MP_WARN(ao, "Multiple devices matched \'%.*s\'."
"Ignoring device \'%s\' (%s).\n",
@@ -990,13 +990,13 @@ bool find_device(struct ao *ao)
SAFE_RELEASE(d, talloc_free(d));
}
- if (!state->deviceID)
+ if (!deviceID)
MP_ERR(ao, "Failed to find device \'%.*s\'\n", BSTR_P(device));
exit_label:
talloc_free(d);
destroy_enumerator(enumerator);
- return !!state->deviceID;
+ return deviceID;
}
static void *unmarshal(struct wasapi_state *state, REFIID type, IStream **from)
diff --git a/audio/out/ao_wasapi_utils.h b/audio/out/ao_wasapi_utils.h
index 1d0c0e5dcd..410eaeda14 100644
--- a/audio/out/ao_wasapi_utils.h
+++ b/audio/out/ao_wasapi_utils.h
@@ -38,7 +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);
+LPWSTR find_deviceID(struct ao *ao);
void wasapi_dispatch(struct ao *ao);
HRESULT wasapi_thread_init(struct ao *ao);