Use google cpu_features library
Currently, ndk cpu-features is being used. This is now deprecated and google open-source cpu_features library is recommended. PiperOrigin-RevId: 273987647
This commit is contained in:
parent
58cb7d29ca
commit
d01d8f0344
@ -17,7 +17,8 @@ To use this extension you need to clone the ExoPlayer repository and depend on
|
|||||||
its modules locally. Instructions for doing this can be found in ExoPlayer's
|
its modules locally. Instructions for doing this can be found in ExoPlayer's
|
||||||
[top level README][].
|
[top level README][].
|
||||||
|
|
||||||
In addition, it's necessary to fetch libgav1 and its dependencies as follows:
|
In addition, it's necessary to fetch cpu_features library and libgav1 with its
|
||||||
|
dependencies as follows:
|
||||||
|
|
||||||
* Set the following environment variables:
|
* Set the following environment variables:
|
||||||
|
|
||||||
@ -27,6 +28,13 @@ EXOPLAYER_ROOT="$(pwd)"
|
|||||||
AV1_EXT_PATH="${EXOPLAYER_ROOT}/extensions/av1/src/main"
|
AV1_EXT_PATH="${EXOPLAYER_ROOT}/extensions/av1/src/main"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* Fetch cpu_features library:
|
||||||
|
|
||||||
|
```
|
||||||
|
cd "${AV1_EXT_PATH}/jni" && \
|
||||||
|
git clone https://github.com/google/cpu_features
|
||||||
|
```
|
||||||
|
|
||||||
* Fetch libgav1:
|
* Fetch libgav1:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -11,6 +11,7 @@ project(libgav1JNI C CXX)
|
|||||||
# armeabi-v7a build. This flag enables it.
|
# armeabi-v7a build. This flag enables it.
|
||||||
if(${ANDROID_ABI} MATCHES "armeabi-v7a")
|
if(${ANDROID_ABI} MATCHES "armeabi-v7a")
|
||||||
add_compile_options("-mfpu=neon")
|
add_compile_options("-mfpu=neon")
|
||||||
|
add_compile_options("-fPIC")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(libgav1_jni_root "${CMAKE_CURRENT_SOURCE_DIR}")
|
set(libgav1_jni_root "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
@ -21,6 +22,14 @@ set(libgav1_jni_output_directory
|
|||||||
set(libgav1_root "${libgav1_jni_root}/libgav1")
|
set(libgav1_root "${libgav1_jni_root}/libgav1")
|
||||||
set(libgav1_build "${libgav1_jni_build}/libgav1")
|
set(libgav1_build "${libgav1_jni_build}/libgav1")
|
||||||
|
|
||||||
|
set(cpu_features_root "${libgav1_jni_root}/cpu_features")
|
||||||
|
set(cpu_features_build "${libgav1_jni_build}/cpu_features")
|
||||||
|
|
||||||
|
# Build cpu_features library.
|
||||||
|
add_subdirectory("${cpu_features_root}"
|
||||||
|
"${cpu_features_build}"
|
||||||
|
EXCLUDE_FROM_ALL)
|
||||||
|
|
||||||
# Build libgav1.
|
# Build libgav1.
|
||||||
add_subdirectory("${libgav1_root}"
|
add_subdirectory("${libgav1_root}"
|
||||||
"${libgav1_build}"
|
"${libgav1_build}"
|
||||||
@ -34,14 +43,10 @@ add_library(gav1JNI
|
|||||||
# Locate NDK log library.
|
# Locate NDK log library.
|
||||||
find_library(android_log_lib log)
|
find_library(android_log_lib log)
|
||||||
|
|
||||||
# Build cpufeatures library.
|
|
||||||
include(AndroidNdkModules)
|
|
||||||
android_ndk_import_module_cpufeatures()
|
|
||||||
|
|
||||||
# Link libgav1JNI against used libraries.
|
# Link libgav1JNI against used libraries.
|
||||||
target_link_libraries(gav1JNI
|
target_link_libraries(gav1JNI
|
||||||
PRIVATE android
|
PRIVATE android
|
||||||
PRIVATE cpufeatures
|
PRIVATE cpu_features
|
||||||
PRIVATE libgav1_static
|
PRIVATE libgav1_static
|
||||||
PRIVATE ${android_log_lib})
|
PRIVATE ${android_log_lib})
|
||||||
|
|
||||||
|
@ -17,10 +17,14 @@
|
|||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
#include <android/native_window.h>
|
#include <android/native_window.h>
|
||||||
#include <android/native_window_jni.h>
|
#include <android/native_window_jni.h>
|
||||||
#ifdef __ARM_NEON
|
|
||||||
|
#include "cpu_features_macros.h" // NOLINT
|
||||||
|
#ifdef CPU_FEATURES_ARCH_ARM
|
||||||
|
#include "cpuinfo_arm.h" // NOLINT
|
||||||
|
#endif // CPU_FEATURES_ARCH_ARM
|
||||||
|
#ifdef CPU_FEATURES_COMPILED_ANY_ARM_NEON
|
||||||
#include <arm_neon.h>
|
#include <arm_neon.h>
|
||||||
#endif // __ARM_NEON
|
#endif // CPU_FEATURES_COMPILED_ANY_ARM_NEON
|
||||||
#include <cpu-features.h>
|
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@ -380,7 +384,7 @@ void Convert10BitFrameTo8BitDataBuffer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __ARM_NEON
|
#ifdef CPU_FEATURES_COMPILED_ANY_ARM_NEON
|
||||||
void Convert10BitFrameTo8BitDataBufferNeon(
|
void Convert10BitFrameTo8BitDataBufferNeon(
|
||||||
const libgav1::DecoderBuffer* decoder_buffer, jbyte* data) {
|
const libgav1::DecoderBuffer* decoder_buffer, jbyte* data) {
|
||||||
uint32x2_t lcg_value = vdup_n_u32(random());
|
uint32x2_t lcg_value = vdup_n_u32(random());
|
||||||
@ -477,7 +481,7 @@ void Convert10BitFrameTo8BitDataBufferNeon(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // __ARM_NEON
|
#endif // CPU_FEATURES_COMPILED_ANY_ARM_NEON
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -487,18 +491,20 @@ DECODER_FUNC(jlong, gav1Init, jint threads) {
|
|||||||
return kStatusError;
|
return kStatusError;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __arm__
|
#ifdef CPU_FEATURES_ARCH_ARM
|
||||||
// Libgav1 requires NEON with arm ABIs.
|
// Libgav1 requires NEON with arm ABIs.
|
||||||
#ifdef __ARM_NEON
|
#ifdef CPU_FEATURES_COMPILED_ANY_ARM_NEON
|
||||||
if (!(android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON)) {
|
const cpu_features::ArmFeatures arm_features =
|
||||||
|
cpu_features::GetArmInfo().features;
|
||||||
|
if (!arm_features.neon) {
|
||||||
context->jni_status_code = kJniStatusNeonNotSupported;
|
context->jni_status_code = kJniStatusNeonNotSupported;
|
||||||
return reinterpret_cast<jlong>(context);
|
return reinterpret_cast<jlong>(context);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
context->jni_status_code = kJniStatusNeonNotSupported;
|
context->jni_status_code = kJniStatusNeonNotSupported;
|
||||||
return reinterpret_cast<jlong>(context);
|
return reinterpret_cast<jlong>(context);
|
||||||
#endif // __ARM_NEON
|
#endif // CPU_FEATURES_COMPILED_ANY_ARM_NEON
|
||||||
#endif // __arm__
|
#endif // CPU_FEATURES_ARCH_ARM
|
||||||
|
|
||||||
libgav1::DecoderSettings settings;
|
libgav1::DecoderSettings settings;
|
||||||
settings.threads = threads;
|
settings.threads = threads;
|
||||||
@ -590,11 +596,11 @@ DECODER_FUNC(jint, gav1GetFrame, jlong jContext, jobject jOutputBuffer,
|
|||||||
CopyFrameToDataBuffer(decoder_buffer, data);
|
CopyFrameToDataBuffer(decoder_buffer, data);
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
#ifdef __ARM_NEON
|
#ifdef CPU_FEATURES_COMPILED_ANY_ARM_NEON
|
||||||
Convert10BitFrameTo8BitDataBufferNeon(decoder_buffer, data);
|
Convert10BitFrameTo8BitDataBufferNeon(decoder_buffer, data);
|
||||||
#else
|
#else
|
||||||
Convert10BitFrameTo8BitDataBuffer(decoder_buffer, data);
|
Convert10BitFrameTo8BitDataBuffer(decoder_buffer, data);
|
||||||
#endif // __ARM_NEON
|
#endif // CPU_FEATURES_COMPILED_ANY_ARM_NEON
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
context->jni_status_code = kJniStatusBitDepth12NotSupportedWithYuv;
|
context->jni_status_code = kJniStatusBitDepth12NotSupportedWithYuv;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user