mirror of
https://github.com/moonlight-stream/moonlight-qt
synced 2024-11-10 13:44:17 +00:00
Implement fast AES detection logic for Windows and macOS
This commit is contained in:
parent
75ddac54c5
commit
ce8b24dfa7
3 changed files with 42 additions and 3 deletions
|
@ -604,9 +604,16 @@ bool Session::initialize()
|
|||
m_StreamConfig.bitrate = m_Preferences->bitrateKbps;
|
||||
|
||||
#ifndef STEAM_LINK
|
||||
// Enable audio encryption as long as we're not on Steam Link.
|
||||
// That hardware can hardly handle Opus decoding at all.
|
||||
m_StreamConfig.encryptionFlags = ENCFLG_AUDIO;
|
||||
// Opt-in to all encryption features if we detect that the platform
|
||||
// has AES cryptography acceleration instructions.
|
||||
if (StreamUtils::hasFastAes()) {
|
||||
m_StreamConfig.encryptionFlags = ENCFLG_ALL;
|
||||
}
|
||||
else {
|
||||
// Enable audio encryption as long as we're not on Steam Link.
|
||||
// That hardware can hardly handle Opus decoding at all.
|
||||
m_StreamConfig.encryptionFlags = ENCFLG_AUDIO;
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
Uint32 StreamUtils::getPlatformWindowFlags()
|
||||
{
|
||||
#if defined(Q_OS_DARWIN)
|
||||
|
@ -95,6 +99,31 @@ int StreamUtils::getDisplayRefreshRate(SDL_Window* window)
|
|||
return mode.refresh_rate;
|
||||
}
|
||||
|
||||
bool StreamUtils::hasFastAes()
|
||||
{
|
||||
#ifndef __has_builtin
|
||||
#define __has_builtin(x) 0
|
||||
#endif
|
||||
|
||||
#if __has_builtin(__builtin_cpu_supports) && defined(Q_PROCESSOR_X86)
|
||||
return __builtin_cpu_supports("aes");
|
||||
#elif defined(__BUILTIN_CPU_SUPPORTS__) && defined(Q_PROCESSOR_POWER)
|
||||
return __builtin_cpu_supports("vcrypto");
|
||||
#elif defined(Q_OS_WINDOWS) && defined(Q_PROCESSOR_ARM)
|
||||
return IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE);
|
||||
#elif defined(_MSC_VER) && defined(Q_PROCESSOR_X86)
|
||||
int regs[4];
|
||||
__cpuid(regs, 1);
|
||||
return regs[2] & (1 << 25); // AES-NI
|
||||
#elif defined(Q_OS_DARWIN)
|
||||
// Everything that runs Catalina and later has AES-NI or ARMv8 crypto instructions
|
||||
return true;
|
||||
#else
|
||||
// Assume AES is fast if we don't recognize the OS or processor
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool StreamUtils::getNativeDesktopMode(int displayIndex, SDL_DisplayMode* mode)
|
||||
{
|
||||
#ifdef Q_OS_DARWIN
|
||||
|
|
|
@ -33,4 +33,7 @@ public:
|
|||
|
||||
static
|
||||
int getDisplayRefreshRate(SDL_Window* window);
|
||||
|
||||
static
|
||||
bool hasFastAes();
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue