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

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

问题描述

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

我正在onFrameAvailable中设置一个标志,以便仅在需要时才从GL线程进行updateTextImage调用.目前,我在每个绘图调用时都将标志设置为true,因此跳过onFrameAvailable检查会在每一帧上载视频纹理数据.这样,一切都会按预期运行,但似乎效率很低,因为如果仍保持相同(电影帧),则无需上载新的Texturedata.

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

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

解决方案

我刚刚看到了一个类似的问题,并对其进行了调试.我和您一样,都有一个布尔型标志,指示一(或多个!)帧已准备就绪.

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

用待处理摄像机帧的整数计数器替换布尔标志对我来说解决了这个问题.也许这对您也有用吗?

(我怀疑这比仅在每一帧调用updateTexImage效率更高.至少在我的代码中,OpenGL帧花费足够长的时间跨过两个摄像机帧的情况非常少见(1-2%).)

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.

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 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.

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.

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?

(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天全站免登陆