- JNI: Java Native Interface
1. JNI in the system source code
2. JNI in MediaRecorder framework
MediaRecorder, for audio and video recording.
2.1 Java Framework layer MediaRecorder
2.2 JNI layer of MediaRecorder
2.3 Native Method Registration
Native registration method is divided into static registration and dynamic registration. The static registration is mostly used for NDK development, while the dynamic registration is mostly used for Framework development.
2.3.1 Static Registration
Static registration means that Java Native methods are associated with JNI through method Pointers. If Java Native methods know their corresponding function Pointers in JNI, they can avoid the disadvantages mentioned above. This is called dynamic registration.
2.3.2 Dynamic Registration
3. Conversion of data types
Java data types in the JNI layer need to be converted to JNI layer data types.
3.1 Conversion of basic data types
3.2 Conversion of reference data types
4. Method signature
The JNI method signature format is: (Parameter signature format…) Return value signature format
Analytical JNIEnv. 5
- JNIEnv
- Java VM
- JNINativeInterface
- JNIInvokeInterface
- AttachCurrentThread
- DetachCurrentThread
5.1 jfieldID and jmethodID
5.2 Use jfieldID and jmethodID
6. Reference type
- Local References
- Global References
- Weak Global References
6.1 Local Reference
- FindClass
- DeleteLocalRef
6.2 Global Reference
A global reference is almost the opposite of a local reference. It has the following characteristics:
- NewGlobalRef
- DeleteGlobalRef
6.3 Weak global references
- NewWeakGlobalRef
- DeleteWeakGlobalRef
- IsSameObject