如何提高android中opengl es的显示性能

Kev*_*n K 3 android opengl-es

我正在努力提高我们的视频会议项目在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。

有人可以帮助您提供建议吗?

Cla*_*ery 5

glTexSubImage2D() 对于视频帧速率来说太慢。使用 OpenGL ES 1.1 和本机代码,您可以通过避免这种情况并使用 EGL 图像扩展来更快地将视频帧加载到纹理中。本文将通过示例代码对其进行讨论。

使用 OpenGL ES 2.0,您还可以在着色器代码中执行 YUV 到 RGB 颜色空间转换,这也是视频性能的重大改进。我之前在 StackOverflow 上发布过这样的示例。