mirror of
https://github.com/mpv-player/mpv
synced 2024-08-24 07:21:49 +02:00
ao_wasapi: make find_deviceID read only wrt struct ao
This makes it clearer that state->device is being allocated.
This commit is contained in:
parent
d22d24a6d5
commit
8368ead1fa
@ -286,7 +286,8 @@ static int init(struct ao *ao)
|
|||||||
struct wasapi_state *state = ao->priv;
|
struct wasapi_state *state = ao->priv;
|
||||||
state->log = ao->log;
|
state->log = ao->log;
|
||||||
|
|
||||||
if (!find_device(ao)) {
|
state->deviceID = find_deviceID(ao);
|
||||||
|
if (!state->deviceID) {
|
||||||
uninit(ao);
|
uninit(ao);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -904,16 +904,6 @@ exit_label:
|
|||||||
destroy_enumerator(enumerator);
|
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,
|
static HRESULT load_device(struct mp_log *l,
|
||||||
IMMDevice **ppDevice, LPWSTR deviceID)
|
IMMDevice **ppDevice, LPWSTR deviceID)
|
||||||
{
|
{
|
||||||
@ -933,8 +923,18 @@ exit_label:
|
|||||||
return hr;
|
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;
|
struct wasapi_state *state = ao->priv;
|
||||||
bstr device = bstr_strip(bstr0(state->opt_device));
|
bstr device = bstr_strip(bstr0(state->opt_device));
|
||||||
if (!device.len)
|
if (!device.len)
|
||||||
@ -950,7 +950,7 @@ bool find_device(struct ao *ao)
|
|||||||
if (!device.len) {
|
if (!device.len) {
|
||||||
MP_VERBOSE(ao, "No device specified. Selecting default.\n");
|
MP_VERBOSE(ao, "No device specified. Selecting default.\n");
|
||||||
d = default_device_desc(enumerator);
|
d = default_device_desc(enumerator);
|
||||||
select_device(state, d);
|
deviceID = select_device(ao->log, d);
|
||||||
goto exit_label;
|
goto exit_label;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -960,7 +960,7 @@ bool find_device(struct ao *ao)
|
|||||||
if (!rest.len && 0 <= devno && devno < enumerator->count) {
|
if (!rest.len && 0 <= devno && devno < enumerator->count) {
|
||||||
MP_VERBOSE(ao, "Selecting device by number: #%lld\n", devno);
|
MP_VERBOSE(ao, "Selecting device by number: #%lld\n", devno);
|
||||||
d = device_desc_for_num(enumerator, devno);
|
d = device_desc_for_num(enumerator, devno);
|
||||||
select_device(state, d);
|
deviceID = select_device(ao->log, d);
|
||||||
goto exit_label;
|
goto exit_label;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -973,14 +973,14 @@ bool find_device(struct ao *ao)
|
|||||||
|
|
||||||
if (bstrcmp(device, bstr_strip(bstr0(d->id))) == 0) {
|
if (bstrcmp(device, bstr_strip(bstr0(d->id))) == 0) {
|
||||||
MP_VERBOSE(ao, "Selecting device by id: \'%.*s\'\n", BSTR_P(device));
|
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;
|
goto exit_label;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bstrcmp(device, bstr_strip(bstr0(d->name))) == 0) {
|
if (bstrcmp(device, bstr_strip(bstr0(d->name))) == 0) {
|
||||||
if (!state->deviceID) {
|
if (!state->deviceID) {
|
||||||
MP_VERBOSE(ao, "Selecting device by name: \'%.*s\'\n", BSTR_P(device));
|
MP_VERBOSE(ao, "Selecting device by name: \'%.*s\'\n", BSTR_P(device));
|
||||||
select_device(state, d);
|
deviceID = select_device(ao->log, d);
|
||||||
} else {
|
} else {
|
||||||
MP_WARN(ao, "Multiple devices matched \'%.*s\'."
|
MP_WARN(ao, "Multiple devices matched \'%.*s\'."
|
||||||
"Ignoring device \'%s\' (%s).\n",
|
"Ignoring device \'%s\' (%s).\n",
|
||||||
@ -990,13 +990,13 @@ bool find_device(struct ao *ao)
|
|||||||
SAFE_RELEASE(d, talloc_free(d));
|
SAFE_RELEASE(d, talloc_free(d));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!state->deviceID)
|
if (!deviceID)
|
||||||
MP_ERR(ao, "Failed to find device \'%.*s\'\n", BSTR_P(device));
|
MP_ERR(ao, "Failed to find device \'%.*s\'\n", BSTR_P(device));
|
||||||
|
|
||||||
exit_label:
|
exit_label:
|
||||||
talloc_free(d);
|
talloc_free(d);
|
||||||
destroy_enumerator(enumerator);
|
destroy_enumerator(enumerator);
|
||||||
return !!state->deviceID;
|
return deviceID;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *unmarshal(struct wasapi_state *state, REFIID type, IStream **from)
|
static void *unmarshal(struct wasapi_state *state, REFIID type, IStream **from)
|
||||||
|
@ -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);
|
bool wasapi_fill_VistaBlob(wasapi_state *state);
|
||||||
|
|
||||||
void wasapi_list_devs(struct ao *ao, struct ao_device_list *list);
|
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);
|
void wasapi_dispatch(struct ao *ao);
|
||||||
HRESULT wasapi_thread_init(struct ao *ao);
|
HRESULT wasapi_thread_init(struct ao *ao);
|
||||||
|
Loading…
Reference in New Issue
Block a user