我正在努力提高我们的视频会议项目在android中的视频显示效率。视频显示是用原生opengl代码实现的。opengl 代码是在 opengl 版本 1 中以本机实现的。下面给出的代码用于显示视频的每一帧。
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;
}
Run Code Online (Sandbox Code Playgroud)
所有初始化都已完成。该代码适用于较低分辨率。但是,当显示更高分辨率(如 640 X 480)时,glTexSubImage2D 本身大约需要 35 - 40 毫秒,整个显示时间每帧超过 50 毫秒。但我需要 30 fps。
有人可以帮助您提供建议吗?
| 归档时间: |
|
| 查看次数: |
5159 次 |
| 最近记录: |