Encapsulating Functions into the JNI
Application Scenario
Encapsulate the C++ interface functions provided by the video stream engine client into the JNI.
Encapsulate the function of the communication module for setting the IP address and port number into the JNI.
Development Process
- Encapsulate the C++ interface functions of the video stream engine client.
- Encapsulate the function of the communication module for setting the IP address and port number into the JNI.
- Create a JNI callback object of the video stream engine client.
Encoding Instance
// Encapsulate the C++ interface functions of the video stream engine client. #define VIDEO_JNI(func) Java_com_huawei_videostream_cloudphoneui_engine_VideoWrapper_##func JNIEXPORT jint JNICALL VIDEO_JNI(initialize)(JNIEnv* env, jclass cls); JNIEXPORT jint JNICALL VIDEO_JNI(start)(JNIEnv* env, jclass cls, jobject surface, jint width, jint height, jfloat densityDpi); JNIEXPORT void JNICALL VIDEO_JNI(stop)(JNIEnv* env, jclass cls); JNIEXPORT jstring JNICALL VIDEO_JNI(getStatistics)(JNIEnv* env, jclass cls); JNIEXPORT jint JNICALL VIDEO_JNI(recvData)(JNIEnv* env, jclass cls, jbyte type, jbyteArray jData, jint length); // The following is an example of encapsulating send functions. You can encapsulate interface functions as required. JNIEXPORT jboolean JNICALL VIDEO_JNI(sendTouchEvent)(JNIEnv* env, jclass cls, jbyteArray jData, jint length); JNIEXPORT jboolean JNICALL VIDEO_JNI(sendKeyEvent)(JNIEnv* env, jclass cls,jbyteArray jData, jint length); // Encapsulate the video stream engine callback event. #define CB_JNI(func) Java_com_huawei_videostream_cloudphoneui_JniCallBack_##func JNIEXPORT void JNICALL CB_JNI(setNativeCallback)(JNIEnv* env, jobject obj); // Encapsulate the communication module API. #define NET_CONFIG_JNI(func) Java_com_huawei_videostream_cloudphoneui_NetConfig_##func JNIEXPORT jboolean JNICALL NET_CONFIG_JNI(initialize)(JNIEnv* env, jclass cls); // Set the IP address and port number of the communication module. JNIEXPORT jboolean JNICALL NET_CONFIG_JNI(setNetConfig)(JNIEnv* env, jclass cls, jstring ip, jint port, jint type);
Parent topic: Development Process of the Video Stream Engine Client