Recently in the docking WebRTC to Android phone, there is a demand is the mobile phone horizontal screen when the other side of the image rotation, study the code of WEBRTC Video_render found that the remote video rendering using OPENGLES20 or Surfaceview implementation, Where OPENGLES20 uses hardware rendering, so performance is better, so simply add the VideoRenderOpenGles20 class in the video_render_opengles20.h to the rotation interface.
OPENGLES20 and Opengles compared to cancel the Glrotatex, such as the operation function, the rotation operation is replaced by the shader vertex rendering implementation, the rewritten shader code is as follows:
Uniform mat4 Umvpmatrix; The total transformation matrix attribute vec4 aposition; Vertex position attribute VEC2 atexturecoord;varying vec2 vtexturecoord;void Main () { gl_position = Umvpmatrix * Aposition; Calculates this vertex position based on the total transformation matrix Vtexturecoord = atexturecoord;//passes the received color to the slice shader}
Note that the transform matrix Umvpmatrix is added, which is called before drawing:
int mumvpmatrixhandle = glgetuniformlocation (Mprogram, "Umvpmatrix");
Mmmatrix.setrotate (rotate);
glUniformMatrix4fv(muMVPMatrixHandle,
1
,
false
, (float*)mMMatrix
);
Android WEBRTC Video Rotation problem