Opt in for video encryption on platforms with fast AES implementations

This commit is contained in:
Cameron Gutman 2024-01-15 15:05:38 -06:00
parent f7520ba40c
commit 3f9f8f7b3b
2 changed files with 33 additions and 1 deletions

View File

@ -55,7 +55,9 @@ endif
LOCAL_LDLIBS := -llog LOCAL_LDLIBS := -llog
LOCAL_STATIC_LIBRARIES := libopus libssl libcrypto LOCAL_STATIC_LIBRARIES := libopus libssl libcrypto cpufeatures
LOCAL_LDFLAGS += -Wl,--exclude-libs,ALL LOCAL_LDFLAGS += -Wl,--exclude-libs,ALL
include $(BUILD_SHARED_LIBRARY) include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/cpufeatures)

View File

@ -8,6 +8,8 @@
#include <opus_multistream.h> #include <opus_multistream.h>
#include <android/log.h> #include <android/log.h>
#include <cpu-features.h>
static OpusMSDecoder* Decoder; static OpusMSDecoder* Decoder;
static OPUS_MULTISTREAM_CONFIGURATION OpusConfig; static OPUS_MULTISTREAM_CONFIGURATION OpusConfig;
@ -426,6 +428,29 @@ static CONNECTION_LISTENER_CALLBACKS BridgeConnListenerCallbacks = {
.setControllerLED = BridgeClSetControllerLED, .setControllerLED = BridgeClSetControllerLED,
}; };
static bool
hasFastAes() {
if (android_getCpuCount() <= 2) {
return false;
}
switch (android_getCpuFamily()) {
case ANDROID_CPU_FAMILY_ARM:
return !!(android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_AES);
case ANDROID_CPU_FAMILY_ARM64:
return !!(android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_AES);
case ANDROID_CPU_FAMILY_X86:
case ANDROID_CPU_FAMILY_X86_64:
return !!(android_getCpuFeatures() & ANDROID_CPU_X86_FEATURE_AES_NI);
case ANDROID_CPU_FAMILY_MIPS:
case ANDROID_CPU_FAMILY_MIPS64:
return false;
default:
// Assume new architectures will all have crypto acceleration (RISC-V will)
return true;
}
}
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_com_limelight_nvstream_jni_MoonBridge_startConnection(JNIEnv *env, jclass clazz, Java_com_limelight_nvstream_jni_MoonBridge_startConnection(JNIEnv *env, jclass clazz,
jstring address, jstring appVersion, jstring gfeVersion, jstring address, jstring appVersion, jstring gfeVersion,
@ -469,6 +494,11 @@ Java_com_limelight_nvstream_jni_MoonBridge_startConnection(JNIEnv *env, jclass c
BridgeVideoRendererCallbacks.capabilities = videoCapabilities; BridgeVideoRendererCallbacks.capabilities = videoCapabilities;
// Enable all encryption features if the platform has fast AES support
if (hasFastAes()) {
streamConfig.encryptionFlags = ENCFLG_ALL;
}
int ret = LiStartConnection(&serverInfo, int ret = LiStartConnection(&serverInfo,
&streamConfig, &streamConfig,
&BridgeConnListenerCallbacks, &BridgeConnListenerCallbacks,