Reputation: 589
I am working to improve the video display efficiency of our video conferencing project in android. Video display is implemented in native opengl code. The opengl code is implemented in native with opengl version 1. The code given below is used for displaying each frames of the video.
int ofi_vc_video_display::render_video_frame(unsigned char *frame_buffer)
{
// Check the frame is available or not. If available display the frame.
if (frame_buffer != NULL){
// Clear the screen buffers.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Bind the frame data to the texture.
glTexSubImage2D(GL_TEXTURE_2D,
0,
0,
0,
frame_width,
frame_height,
GL_RGB,
GL_UNSIGNED_BYTE,
frame_buffer);
// Check for the error status.
while ((gl_error_status=glGetError()) != GL_NO_ERROR) {
error_status = gl_error_status;
}
// Transform and rotate the texture.
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5, 0.5, 0.0);
glRotatef(180.0, 180.0, 0.0,1.0);
glTranslatef(-0.5, -0.5, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -4);
// Enable drawing texture.
glBindTexture(GL_TEXTURE_2D, mTextureId);
// Draw the frames in texture.
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
// Check for the error status.
while ((gl_error_status=glGetError()) != GL_NO_ERROR) {
error_status = gl_error_status;
}
}
return error_status;
}
All initializations are done before. The code is fine for lower resolutions. But when displaying higher resolutions like 640 X 480, glTexSubImage2D itself is taking around 35 - 40 ms and the whole display time goes above 50 ms per frame. But I need 30 fps.
Can some one help with your suggestions.
Upvotes: 3
Views: 5245
Reputation: 2832
glTexSubImage2D() is too slow for video frame rates. With OpenGL ES 1.1 and native code you can load the video frames into textures much faster by avoiding that and using the EGL Image Extensions instead. It is discussed with example code in this article.
With OpenGL ES 2.0, you could also perform the YUV to RGB color space conversion in shader code which is also a major performance improvement for video. I have posted examples of this here on StackOverflow before.
Upvotes: 5