From 037347b79de1d41ddc0330cd195a99f7cf6b9567 Mon Sep 17 00:00:00 2001 From: Alex Marsev Date: Sun, 7 Feb 2016 23:54:44 +0300 Subject: Check if event mode is supported before using it --- src/AudioDevice.h | 2 ++ src/AudioDeviceManager.cpp | 10 +++++++++- src/Utils.h | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/AudioDevice.h b/src/AudioDevice.h index 3c73970..40e6c2d 100644 --- a/src/AudioDevice.h +++ b/src/AudioDevice.h @@ -11,6 +11,8 @@ namespace SaneAudioRenderer SharedString adapterName; SharedString endpointName; UINT32 endpointFormFactor; + bool supportsSharedEventMode; + bool supportsExclusiveEventMode; IAudioClientPtr audioClient; IAudioRenderClientPtr audioRenderClient; diff --git a/src/AudioDeviceManager.cpp b/src/AudioDeviceManager.cpp index 8d7b357..9ac1c52 100644 --- a/src/AudioDeviceManager.cpp +++ b/src/AudioDeviceManager.cpp @@ -135,6 +135,13 @@ namespace SaneAudioRenderer }; backend.endpointFormFactor = GetDevicePropertyUint(devicePropertyStore, formFactorKey); + static const PROPERTYKEY supportsEventModeKey = { // PKEY_AudioEndpoint_Supports_EventDriven_Mode + {0x1da5d803, 0xd492, 0x4edd, {0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e}}, 7 + }; + backend.supportsSharedEventMode = IsWindows7OrGreater(); + backend.supportsExclusiveEventMode = backend.supportsSharedEventMode && + GetDevicePropertyUint(devicePropertyStore, supportsEventModeKey); + ThrowIfFailed(device->Activate(__uuidof(IAudioClient), CLSCTX_INPROC_SERVER, nullptr, (void**)&backend.audioClient)); } @@ -336,7 +343,8 @@ namespace SaneAudioRenderer } } - backend->eventMode = realtime || backend->exclusive; + backend->eventMode = (realtime && backend->supportsSharedEventMode) || + (backend->exclusive && backend->supportsExclusiveEventMode); { AUDCLNT_SHAREMODE mode = backend->exclusive ? AUDCLNT_SHAREMODE_EXCLUSIVE : diff --git a/src/Utils.h b/src/Utils.h index 053eda3..94aec10 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -145,4 +145,14 @@ namespace SaneAudioRenderer HMODULE m_lib = NULL; Func m_func = nullptr; }; + + inline bool IsWindows7OrGreater() + { + OSVERSIONINFOEX info = {sizeof(info)}; + info.dwMajorVersion = 6; + info.dwMinorVersion = 1; + auto rule = VerSetConditionMask(VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL), + VER_MINORVERSION, VER_GREATER_EQUAL); + return !!VerifyVersionInfo(&info, VER_MAJORVERSION | VER_MINORVERSION, rule); + } } -- cgit v1.2.3