diff options
author | Alex Marsev <alex.marsev@gmail.com> | 2016-02-07 23:54:44 +0300 |
---|---|---|
committer | Alex Marsev <alex.marsev@gmail.com> | 2016-02-08 00:07:07 +0300 |
commit | 037347b79de1d41ddc0330cd195a99f7cf6b9567 (patch) | |
tree | 44bc71820d36cd8c235142a338ec7ccefa60a1b9 | |
parent | 83b535b70c957ffb158ff637cc0596a2e245c2b0 (diff) |
Check if event mode is supported before using it
-rw-r--r-- | src/AudioDevice.h | 2 | ||||
-rw-r--r-- | src/AudioDeviceManager.cpp | 10 | ||||
-rw-r--r-- | src/Utils.h | 10 |
3 files changed, 21 insertions, 1 deletions
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);
+ }
}
|