mirror of https://github.com/mpv-player/mpv
ao_wasapi: make persistent enumerator local to change_notify
This is no longer required by anything else
This commit is contained in:
parent
243a2976a8
commit
efb9943637
|
@ -455,10 +455,7 @@ static void audio_resume(struct ao *ao)
|
|||
static void hotplug_uninit(struct ao *ao)
|
||||
{
|
||||
MP_DBG(ao, "Hotplug uninit\n");
|
||||
struct wasapi_state *state = ao->priv;
|
||||
wasapi_change_uninit(ao);
|
||||
SAFE_RELEASE(state->pEnumerator,
|
||||
IMMDeviceEnumerator_Release(state->pEnumerator));
|
||||
CoUninitialize();
|
||||
}
|
||||
|
||||
|
@ -468,11 +465,7 @@ static int hotplug_init(struct ao *ao)
|
|||
struct wasapi_state *state = ao->priv;
|
||||
state->log = ao->log;
|
||||
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
||||
HRESULT hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL,
|
||||
&IID_IMMDeviceEnumerator,
|
||||
(void **)&state->pEnumerator);
|
||||
EXIT_ON_ERROR(hr);
|
||||
hr = wasapi_change_init(ao, true);
|
||||
HRESULT hr = wasapi_change_init(ao, true);
|
||||
EXIT_ON_ERROR(hr);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
typedef struct change_notify {
|
||||
IMMNotificationClient client; // this must be first in the structure!
|
||||
IMMDeviceEnumerator *pEnumerator; // object where client is registered
|
||||
LPWSTR monitored; // Monitored device
|
||||
bool is_hotplug;
|
||||
struct ao *ao;
|
||||
|
@ -69,7 +70,6 @@ typedef struct wasapi_state {
|
|||
IMMDevice *pDevice;
|
||||
IAudioClient *pAudioClient;
|
||||
IAudioRenderClient *pRenderClient;
|
||||
IMMDeviceEnumerator *pEnumerator;
|
||||
|
||||
// WASAPI internal clock information, for estimating delay
|
||||
IAudioClock *pAudioClock;
|
||||
|
|
|
@ -203,13 +203,17 @@ HRESULT wasapi_change_init(struct ao *ao, bool is_hotplug)
|
|||
{
|
||||
struct wasapi_state *state = ao->priv;
|
||||
struct change_notify *change = &state->change;
|
||||
HRESULT hr;
|
||||
HRESULT hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL,
|
||||
&IID_IMMDeviceEnumerator,
|
||||
(void **)&change->pEnumerator);
|
||||
EXIT_ON_ERROR(hr);
|
||||
|
||||
// COM voodoo to emulate c++ class
|
||||
change->client.lpVtbl = &sIMMDeviceEnumeratorVtbl_vtbl;
|
||||
|
||||
// register the change notification client
|
||||
hr = IMMDeviceEnumerator_RegisterEndpointNotificationCallback(
|
||||
state->pEnumerator, (IMMNotificationClient *)change);
|
||||
change->pEnumerator, (IMMNotificationClient *)change);
|
||||
EXIT_ON_ERROR(hr);
|
||||
|
||||
// so the callbacks can access the ao
|
||||
|
@ -240,10 +244,11 @@ void wasapi_change_uninit(struct ao *ao)
|
|||
struct wasapi_state *state = ao->priv;
|
||||
struct change_notify *change = &state->change;
|
||||
|
||||
if (state->pEnumerator && change->client.lpVtbl) {
|
||||
if (change->pEnumerator && change->client.lpVtbl) {
|
||||
IMMDeviceEnumerator_UnregisterEndpointNotificationCallback(
|
||||
state->pEnumerator, (IMMNotificationClient *)change);
|
||||
change->pEnumerator, (IMMNotificationClient *)change);
|
||||
}
|
||||
|
||||
if (change->monitored) CoTaskMemFree(change->monitored);
|
||||
SAFE_RELEASE(change->pEnumerator, IMMDeviceEnumerator_Release(change->pEnumerator));
|
||||
}
|
||||
|
|
|
@ -1101,13 +1101,7 @@ HRESULT wasapi_thread_init(struct ao *ao)
|
|||
MP_DBG(ao, "Init wasapi thread\n");
|
||||
int64_t retry_wait = 1;
|
||||
retry: ;
|
||||
|
||||
HRESULT hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL,
|
||||
&IID_IMMDeviceEnumerator,
|
||||
(void **)&state->pEnumerator);
|
||||
EXIT_ON_ERROR(hr);
|
||||
|
||||
hr = find_device(ao);
|
||||
HRESULT hr = find_device(ao);
|
||||
EXIT_ON_ERROR(hr);
|
||||
|
||||
hr = load_device(ao->log, &state->pDevice, state->deviceID);
|
||||
|
@ -1170,7 +1164,6 @@ void wasapi_thread_uninit(struct ao *ao)
|
|||
SAFE_RELEASE(state->pAudioClient, IAudioClient_Release(state->pAudioClient));
|
||||
SAFE_RELEASE(state->pDevice, IMMDevice_Release(state->pDevice));
|
||||
SAFE_RELEASE(state->deviceID, talloc_free(state->deviceID));
|
||||
SAFE_RELEASE(state->pEnumerator, IMMDeviceEnumerator_Release(state->pEnumerator));
|
||||
SAFE_RELEASE(state->hTask, AvRevertMmThreadCharacteristics(state->hTask));
|
||||
MP_DBG(ao, "Thread uninit done\n");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue