MobileFFmpeg Android API  2.0
abidetect.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Taner Sener
3  *
4  * This file is part of MobileFFmpeg.
5  *
6  * MobileFFmpeg 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  * MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "cpu-features.h"
21 #include "abidetect.h"
22 
24 const char *abiDetectClassName = "com/arthenica/mobileffmpeg/AbiDetect";
25 
27 JNINativeMethod abiDetectMethods[] = {
28  {"getAbi", "()Ljava/lang/String;", (void*) Java_com_arthenica_mobileffmpeg_AbiDetect_getAbi}
29 };
30 
38 jint JNI_OnLoad(JavaVM *vm, void *reserved) {
39  JNIEnv *env;
40  if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_6) != JNI_OK) {
41  LOGE("OnLoad failed to GetEnv for class %s.", abiDetectClassName);
42  return JNI_FALSE;
43  }
44 
45  jclass abiDetectClass = (*env)->FindClass(env, abiDetectClassName);
46  if (abiDetectClass == NULL) {
47  LOGE("OnLoad failed to FindClass %s.", abiDetectClassName);
48  return JNI_FALSE;
49  }
50 
51  if ((*env)->RegisterNatives(env, abiDetectClass, abiDetectMethods, 1) < 0) {
52  LOGE("OnLoad failed to RegisterNatives for class %s.", abiDetectClassName);
53  return JNI_FALSE;
54  }
55 
56  return JNI_VERSION_1_6;
57 }
58 
66 JNIEXPORT jstring JNICALL Java_com_arthenica_mobileffmpeg_AbiDetect_getAbi(JNIEnv *env, jclass object) {
67  AndroidCpuFamily family = android_getCpuFamily();
68 
69  if (family == ANDROID_CPU_FAMILY_ARM) {
70  uint64_t features = android_getCpuFeatures();
71 
72  if (features & ANDROID_CPU_ARM_FEATURE_ARMv7) {
73  if (features & ANDROID_CPU_ARM_FEATURE_NEON) {
74  return (*env)->NewStringUTF(env, ABI_ARMV7A_NEON);
75  } else {
76  return (*env)->NewStringUTF(env, ABI_ARMV7A);
77  }
78  } else {
79  return (*env)->NewStringUTF(env, ABI_ARM);
80  }
81 
82  } else if (family == ANDROID_CPU_FAMILY_ARM64) {
83  return (*env)->NewStringUTF(env, ABI_ARM64_V8A);
84  } else if (family == ANDROID_CPU_FAMILY_X86) {
85  return (*env)->NewStringUTF(env, ABI_X86);
86  } else if (family == ANDROID_CPU_FAMILY_X86_64) {
87  return (*env)->NewStringUTF(env, ABI_X86_64);
88  } else {
89  return (*env)->NewStringUTF(env, ABI_UNKNOWN);
90  }
91 }
JNIEXPORT jstring JNICALL Java_com_arthenica_mobileffmpeg_AbiDetect_getAbi(JNIEnv *env, jclass object)
Definition: abidetect.c:66
#define ABI_ARM
Definition: abidetect.h:33
#define ABI_X86
Definition: abidetect.h:36
#define ABI_ARMV7A
Definition: abidetect.h:30
#define LOGE(...)
Definition: log.h:45
#define ABI_ARM64_V8A
Definition: abidetect.h:42
#define ABI_ARMV7A_NEON
Definition: abidetect.h:27
const char * abiDetectClassName
Definition: abidetect.c:24
#define ABI_X86_64
Definition: abidetect.h:39
JNINativeMethod abiDetectMethods[]
Definition: abidetect.c:27
jint JNI_OnLoad(JavaVM *vm, void *reserved)
Definition: abidetect.c:38
#define ABI_UNKNOWN
Definition: abidetect.h:45