| FFmpegKit Android API 6.0

Loading...
Searching...
No Matches
ffmpegkit_abidetect.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018-2021 Taner Sener
3 *
4 * This file is part of FFmpegKit.
5 *
6 * FFmpegKit is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * FFmpegKit is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "cpu-features.h"
21#include "fftools_ffmpeg.h"
22#include "ffmpegkit_abidetect.h"
23
25 const char *abiDetectClassName = "com/arthenica/ffmpegkit/AbiDetect";
26
28JNINativeMethod abiDetectMethods[] = {
29 {"getNativeAbi", "()Ljava/lang/String;", (void*) Java_com_arthenica_ffmpegkit_AbiDetect_getNativeAbi},
30 {"getNativeCpuAbi", "()Ljava/lang/String;", (void*) Java_com_arthenica_ffmpegkit_AbiDetect_getNativeCpuAbi},
31 {"isNativeLTSBuild", "()Z", (void*) Java_com_arthenica_ffmpegkit_AbiDetect_isNativeLTSBuild},
32 {"getNativeBuildConf", "()Ljava/lang/String;", (void*) Java_com_arthenica_ffmpegkit_AbiDetect_getNativeBuildConf}
33};
34
42jint JNI_OnLoad(JavaVM *vm, void *reserved) {
43 JNIEnv *env;
44 if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_6) != JNI_OK) {
45 LOGE("OnLoad failed to GetEnv for class %s.\n", abiDetectClassName);
46 return JNI_FALSE;
47 }
48
49 jclass abiDetectClass = (*env)->FindClass(env, abiDetectClassName);
50 if (abiDetectClass == NULL) {
51 LOGE("OnLoad failed to FindClass %s.\n", abiDetectClassName);
52 return JNI_FALSE;
53 }
54
55 if ((*env)->RegisterNatives(env, abiDetectClass, abiDetectMethods, 4) < 0) {
56 LOGE("OnLoad failed to RegisterNatives for class %s.\n", abiDetectClassName);
57 return JNI_FALSE;
58 }
59
60 return JNI_VERSION_1_6;
61}
62
70JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_AbiDetect_getNativeAbi(JNIEnv *env, jclass object) {
71
72#ifdef FFMPEG_KIT_ARM_V7A
73 return (*env)->NewStringUTF(env, "arm-v7a");
74#elif FFMPEG_KIT_ARM64_V8A
75 return (*env)->NewStringUTF(env, "arm64-v8a");
76#elif FFMPEG_KIT_X86
77 return (*env)->NewStringUTF(env, "x86");
78#elif FFMPEG_KIT_X86_64
79 return (*env)->NewStringUTF(env, "x86_64");
80#else
81 return (*env)->NewStringUTF(env, "unknown");
82#endif
83
84}
85
93JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_AbiDetect_getNativeCpuAbi(JNIEnv *env, jclass object) {
94 AndroidCpuFamily family = android_getCpuFamily();
95
96 if (family == ANDROID_CPU_FAMILY_ARM) {
97 uint64_t features = android_getCpuFeatures();
98
99 if (features & ANDROID_CPU_ARM_FEATURE_ARMv7) {
100 if (features & ANDROID_CPU_ARM_FEATURE_NEON) {
101 return (*env)->NewStringUTF(env, ABI_ARMV7A_NEON);
102 } else {
103 return (*env)->NewStringUTF(env, ABI_ARMV7A);
104 }
105 } else {
106 return (*env)->NewStringUTF(env, ABI_ARM);
107 }
108
109 } else if (family == ANDROID_CPU_FAMILY_ARM64) {
110 return (*env)->NewStringUTF(env, ABI_ARM64_V8A);
111 } else if (family == ANDROID_CPU_FAMILY_X86) {
112 return (*env)->NewStringUTF(env, ABI_X86);
113 } else if (family == ANDROID_CPU_FAMILY_X86_64) {
114 return (*env)->NewStringUTF(env, ABI_X86_64);
115 } else {
116 return (*env)->NewStringUTF(env, ABI_UNKNOWN);
117 }
118}
119
127JNIEXPORT jboolean JNICALL Java_com_arthenica_ffmpegkit_AbiDetect_isNativeLTSBuild(JNIEnv *env, jclass object) {
128 #if defined(FFMPEG_KIT_LTS)
129 return JNI_TRUE;
130 #else
131 return JNI_FALSE;
132 #endif
133}
134
142JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_AbiDetect_getNativeBuildConf(JNIEnv *env, jclass object) {
143 return (*env)->NewStringUTF(env, FFMPEG_CONFIGURATION);
144}
LOGE
#define LOGE(...)
Definition ffmpegkit.h:48
Java_com_arthenica_ffmpegkit_AbiDetect_getNativeAbi
JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_AbiDetect_getNativeAbi(JNIEnv *env, jclass object)
Definition ffmpegkit_abidetect.c:70
Java_com_arthenica_ffmpegkit_AbiDetect_getNativeBuildConf
JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_AbiDetect_getNativeBuildConf(JNIEnv *env, jclass object)
Definition ffmpegkit_abidetect.c:142
Java_com_arthenica_ffmpegkit_AbiDetect_isNativeLTSBuild
JNIEXPORT jboolean JNICALL Java_com_arthenica_ffmpegkit_AbiDetect_isNativeLTSBuild(JNIEnv *env, jclass object)
Definition ffmpegkit_abidetect.c:127
abiDetectClassName
const char * abiDetectClassName
Definition ffmpegkit_abidetect.c:25
JNI_OnLoad
jint JNI_OnLoad(JavaVM *vm, void *reserved)
Definition ffmpegkit_abidetect.c:42
abiDetectMethods
JNINativeMethod abiDetectMethods[]
Definition ffmpegkit_abidetect.c:28
Java_com_arthenica_ffmpegkit_AbiDetect_getNativeCpuAbi
JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_AbiDetect_getNativeCpuAbi(JNIEnv *env, jclass object)
Definition ffmpegkit_abidetect.c:93
ffmpegkit_abidetect.h
ABI_X86_64
#define ABI_X86_64
Definition ffmpegkit_abidetect.h:39
ABI_ARM
#define ABI_ARM
Definition ffmpegkit_abidetect.h:33
ABI_ARMV7A_NEON
#define ABI_ARMV7A_NEON
Definition ffmpegkit_abidetect.h:27
ABI_X86
#define ABI_X86
Definition ffmpegkit_abidetect.h:36
ABI_UNKNOWN
#define ABI_UNKNOWN
Definition ffmpegkit_abidetect.h:45
ABI_ARM64_V8A
#define ABI_ARM64_V8A
Definition ffmpegkit_abidetect.h:42
ABI_ARMV7A
#define ABI_ARMV7A
Definition ffmpegkit_abidetect.h:30
fftools_ffmpeg.h