【发布时间】:2014-04-17 11:06:39
【问题描述】:
我正在努力提高我们视频会议项目在 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;
}
所有初始化都在之前完成。 该代码适用于较低的分辨率。但是当显示 640 X 480 等更高分辨率时,glTexSubImage2D 本身需要大约 35 - 40 毫秒,整个显示时间超过每帧 50 毫秒。但我需要 30 fps。
有人可以帮助您提出建议吗?
【问题讨论】:
-
哪个设备和 Android 版本?你的视频帧有多大? Grafika 中有纹理上传速度测试(github.com/google/grafika);你从中获得了什么价值?
-
@fadden 以上数据来自amazone kindle fire hdx with android 4.2.2。而且我无法运行您的graphika,因为它需要4.3。我在摩托罗拉 moto G 中使用 4.4.2 进行了测试,glTexSubImage2D 每帧耗时超过 50 - 65 毫秒,纹理上传速度测试为 3807 us 每次迭代......
-
sdk 版本 9 支持我的应用
-
@fadden 有没有其他方法可以加快帧显示速度......
-
上传速度测试使用 512x512 RGBA 纹理。你从中得到的数字是合理的(我在 N5/N10 上得到 1600us)。您是否正在创建二次幂纹理并将帧数据加载到其中? (我想知道 glTexImage2D 是否比 glTexSubImage2D 提供速度优势......但你必须先将帧复制到 POT 缓冲区。)