1. java Layer
Create GL2JNIView in the interface (the base class is GLSurfaceView ).
Create the AndroidVideoWindowImpl object and pass GL2JNIView as the parameter to the constructor. Listen to the GL2JNIView surface event (mVideoRenderingView. getHolder (). addCallback) in this object ).
When the surface changes (for example, the window size changes and the activity is covered by other programs), the callback function is triggered:
Public voidSurfaceChanged (SurfaceHolderholder,IntFormat,
IntWidth,IntHeight)
Call LinphoneManager. getLc (). setVideoWindow (Vw); Upload the androidvideow.wimpl object to the c code layer.
The corresponding function in C code in mediastreamer2 \ src \ android \ android-opengl-display.c android_display_set_window,
The procedure for calling this function is as follows:
(1) (* jenv)-> CallVoidMethod (jenv, window, ad-> set_opengles_display_id, ptr );
Window is the androidvideow.wimpl object passed through java; ad-> set_opengles_display_id is the java class androidvideo=wimpl member function setOpenGLESDisplay; ptr is the struct variable opengles_display, which stores yuv data, it will be used when each frame is displayed later.
(2) Assign androidvideow.wimpl to ad-> android_video_window
This function swaps object pointers in java and c. This is mainly because opengl must refresh each video frame by the onDrawFrame of the java layer, while the linphone video stream receives and decodes the video stream in the c layer, which must be triggered by the c function.
2. c code Layer
In the android_display_process function for each frame of the android-opengl-display.c,
Call (* jenv)-> CallVoidMethod (jenv, ad-> android_video_window, ad-> request_render_id); where ad-> android_video_window is the androidvideo1_wimpl object passed by setVideoWindow; ad-> request_render_id is the java class androidvideo=wimpl member function requestRender
This function triggers opengl to refresh a frame and calls onDrawFrame at the java layer.
The onDrawFrame function calls the render of the c code layer. The parameter is the opengles_display struct transmitted to the java layer in step (1.
The C code layer corresponds to the ogl_display_render function in mediastreamer2 \ src \ utils \ opengles_display.c. In this function, yuv data in opengles_display is drawn to opengl surface.