diff options
author | wm4 <wm4@nowhere> | 2017-06-27 14:45:30 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2017-06-29 10:38:05 +0200 |
commit | 3e9075787fba1455f0c754c5387c954e1eaa0973 (patch) | |
tree | aee95f543f17ec6001749c7ab6391299deb8d066 /audio/out/ao_wasapi_utils.c | |
parent | 4637b029cdd168d4196f5ab69fa5f91556ee5d11 (diff) | |
download | mpv-3e9075787fba1455f0c754c5387c954e1eaa0973.tar.bz2 mpv-3e9075787fba1455f0c754c5387c954e1eaa0973.tar.xz |
ao_wasapi: UWP wrapper hack support
UWP does not support the whole IMMDevice API. Instead, you need to use a
new API (available starting from Windows 8), which is in addition not in
MinGW, and extremely unpleasant to use.
The wasapiuwp2.dll wrapper is a small custom MSVC DLL, which does this
instead, and returns a normal IAudioClient.
Before this, ao_wasapi did not initialize on UWP.
Diffstat (limited to 'audio/out/ao_wasapi_utils.c')
-rw-r--r-- | audio/out/ao_wasapi_utils.c | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/audio/out/ao_wasapi_utils.c b/audio/out/ao_wasapi_utils.c index 3aec5ac29a..8cfeecf08d 100644 --- a/audio/out/ao_wasapi_utils.c +++ b/audio/out/ao_wasapi_utils.c @@ -922,15 +922,45 @@ HRESULT wasapi_thread_init(struct ao *ao) MP_DBG(ao, "Init wasapi thread\n"); int64_t retry_wait = 1; bool align_hack = false; + HRESULT hr; retry: ; - HRESULT hr = load_device(ao->log, &state->pDevice, state->deviceID); - EXIT_ON_ERROR(hr); + if (state->deviceID) { + hr = load_device(ao->log, &state->pDevice, state->deviceID); + EXIT_ON_ERROR(hr); - MP_DBG(ao, "Activating pAudioClient interface\n"); - hr = IMMDeviceActivator_Activate(state->pDevice, &IID_IAudioClient, - CLSCTX_ALL, NULL, + MP_DBG(ao, "Activating pAudioClient interface\n"); + hr = IMMDeviceActivator_Activate(state->pDevice, &IID_IAudioClient, + CLSCTX_ALL, NULL, + (void **)&state->pAudioClient); + EXIT_ON_ERROR(hr); + } else { + MP_VERBOSE(ao, "Trying UWP wrapper.\n"); + + HRESULT (*wuCreateDefaultAudioRenderer)(IUnknown **res) = NULL; + HANDLE lib = LoadLibraryW(L"wasapiuwp2.dll"); + if (!lib) { + MP_ERR(ao, "Wrapper not found: %d\n", (int)GetLastError()); + hr = E_FAIL; + EXIT_ON_ERROR(hr); + } + if (lib) { + wuCreateDefaultAudioRenderer = + (void*)GetProcAddress(lib, "wuCreateDefaultAudioRenderer"); + } + if (!wuCreateDefaultAudioRenderer) { + MP_ERR(ao, "Function not found.\n"); + hr = E_FAIL; + EXIT_ON_ERROR(hr); + } + IUnknown *res = NULL; + hr = wuCreateDefaultAudioRenderer(&res); + MP_VERBOSE(ao, "Device: %s %p\n", mp_HRESULT_to_str(hr), res); + EXIT_ON_ERROR(hr); + hr = IUnknown_QueryInterface(res, &IID_IAudioClient, (void **)&state->pAudioClient); - EXIT_ON_ERROR(hr); + IUnknown_Release(res); + EXIT_ON_ERROR(hr); + } MP_DBG(ao, "Probing formats\n"); if (!find_formats(ao)) { |