SurfaceTexture.OnFrameAvailableListener 停止被调用 [英] SurfaceTexture.OnFrameAvailableListener stops being called

查看:29
本文介绍了SurfaceTexture.OnFrameAvailableListener 停止被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的应用程序中实现 SurfaceTexture.OnFrameAvailableListener 接口,因此我可以将视频帧用作 OpenGL 纹理.一切都按原样进行设置,并且运行良好,但是 onFrameAvailable(SurfaceTexture surfaceTexture) 在几秒钟后停止被调用,实际上并且似乎冻结了 OpenGL 中的视频,因为没有通过 SurfaceTexture.updateTextImage 上传新的纹理数据.

I am implementing the SurfaceTexture.OnFrameAvailableListener interface in my app so I can use the video frames as an OpenGL texture. All is setup like it should and it works perfectly however onFrameAvailable(SurfaceTexture surfaceTexture) stops being called after a few seconds, effectively and seemingly freezing the video in OpenGL as no new texturedata is being uploaded through SurfaceTexture.updateTextImage.

我在 onFrameAvailable 中设置了一个标志,以便仅在需要时从 GL 线程调用 updateTextImage.目前,我在每次绘制调用时都将标志设置为 true,以便在跳过 onFrameAvailable 检查时每帧上传视频纹理数据.像这样,一切都按原样运行,但似乎效率低下,因为如果仍然相同(电影帧)就不需要上传新的纹理数据.

I am setting a flag in onFrameAvailable to do the updateTextImage call from the GL thread and only when needed. Currently I am setting the flag to true on every draw call so the video texturedata is being uploaded every frame as the onFrameAvailable check is skipped. Like this, everything runs like it should but it seems inefficient as no new texturedata needs to be uploaded if it's still the same (movie frame).

AFAIK 没有内存泄漏,并且 logcat 没有显示任何错误.此外,媒体播放器设置为循环播放,但问题发生在单次运行完成之前.

AFAIK there are no memory leaks and logcat is not showing any errors. Also, the media player is set to loop but the issue occurs before a single run has completed.

什么会导致 onFrameAvailable 在几秒钟后不再被调用?

What would cause the onFrameAvailable not being called anymore after a few seconds?

推荐答案

刚刚看到一个类似的问题,调试了一下.我和你一样,有一个布尔标志,表示一个(或多个!)帧已准备好使用.

I've just seen a similar problem, and debugged it. I, like you, had a Boolean flag which indicated that one (or more!) frames were ready to be used.

当我在一对 OpenGL 帧之间收到两个相机帧时出现问题(可能是因为我的 OpenGL 重绘处理太慢了).这意味着我设置了两次布尔标志.但是,我后来只读取了这个帧数据一次,并且似乎 updateTexImage 实现了某种排队功能.

The problem occurred when I received two camera frames between a pair of OpenGL frames (possibly because my OpenGL redraw processing was too slow). This meant that I set the Boolean flag twice. However, I then only read this frame data once, and it seems that the updateTexImage implemented some kind of queuing function.

用未决摄像机帧的整数计数器替换布尔标志为我解决了这个问题.也许这也适合你?

Replacing the Boolean flag with an integer counter of pending camera frames solved the problem for me. Maybe this would work for you too?

(我怀疑这比每帧调用 updateTexImage 更有效.至少在我的代码中,很少有(1-2%)OpenGL 帧需要足够长的时间来跨越两个相机帧.)

(I suspect this is more efficient than just calling updateTexImage every frame. At least in my code, it was very rare (1-2%) for OpenGL frames to take long enough that they spanned two camera frames.)

这篇关于SurfaceTexture.OnFrameAvailableListener 停止被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆