本文介绍了表面纹理updateTexImage共享2 EGLContexts - 问题在Android 4.4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我指的是这个极好的例子如何连接code相机的preVIEW帧直接进入MP4文件: http://bigflake.com/media$c$cc/CameraToMpegTest.java.txt

I am referring to this excellent example of how to encode the preview frames of the camera directly into an mp4 file:http://bigflake.com/mediacodec/CameraToMpegTest.java.txt

我已经采用了code的,我也想呈现的preVIEW图像在屏幕上的方式。因此,我得到的东西喜欢用自己的EGLContext一个GLTextureView。这个上下文然后共享EGLContext使用时,我创建了EGLContext为EN codeR渲染:

I have adopted the code in the way that I also would like to render the preview image on the screen. Therefore I got something like a GLTextureView with its own EGLContext. This Context is then used as shared EGLContext when I create the EGLContext for the encoder rendering:

mEGLContext = EGL14.eglCreateContext(mEGLDisplay, configs[0], sharedContext == null ? EGL14.EGL_NO_CONTEXT : sharedContext,
                attrib_list, 0);

在我的渲染循环我遵循法登...尖端的每一帧我做到以下几点:

In my render-loop I followed the tip of fadden... for every frame I do the following:

  1. 首先,我等待新的图像上用表面纹理awaitNewImage()
  2. 到货
  3. 然后我设置了GLTextureView的背景下当前和渲染它的框架
  4. 在我设置EN codeRS方面目前并呈现其上的框架

这看起来就像这样:

mFrameWatcher.awaitNewImage();
mSurfaceTexture.updateTexImage();
_textureView.getEGLManager().makeCurrent();
_textureView.requestRender();
mInputSurface.makeCurrent();
mInputSurface.requestRender();

这行之有效,而我测试了它只能在我的Nexus 4与Android 4.3。

This worked well while I tested it only on my Nexus 4 with Android 4.3.

然而,因为我得到了新的Nexus 5与Android 4.4的连接codeR只得到每秒2帧不同的表面纹理......但这些2帧一再提请......所以他EN​​ codeS 15次相同的帧。虽然帧渲染正确的我GLTextureView以每秒30帧的不同。我首先想到这可能是一台Nexus 5的问题 - 所以我更新了另一个的Nexus 4到Android 4.4 ...但它是对的Nexus 4一样了

However, since I got the new Nexus 5 with Android 4.4 the encoder only gets 2 different frames per second from the SurfaceTexture... but these 2 frames are repeatedly drawn... so he encodes 15 times the same frame. ALTHOUGH the frames are rendered correct to my GLTextureView with 30 different frames per second.I first thought this might be a Nexus 5 problem - so I updated another Nexus 4 to Android 4.4... but it is the same on the Nexus 4 now.

我打了一下周围 - 最后我能解决的问题,通过分离和重新附着到表面纹理的不同的上下文当我切换他们的。这看起来是这样的:

I played around a bit - and finally I was able to solve the problem, by detaching and re-attaching the SurfaceTexture to the different context's when I switch them. This looks something like this:

mFrameWatcher.awaitNewImage();
mSurfaceTexture.updateTexImage();
_textureView.getEGLManager().makeCurrent();
_textureView.requestRender();
mSurfaceTexture.detachFromGLContext();
mInputSurface.makeCurrent();
mSurfaceTexture.attachToGLContext(_textureViewRenderer.getTextureId());
mInputSurface.requestRender();
mSurfaceTexture.detachFromGLContext();
_textureView.getEGLManager().makeCurrent();
mSurfaceTexture.attachToGLContext(_textureViewRenderer.getTextureId());

我现在的问题是:这是这样做的正确方法?老实说,我想,当我使用的共享环境的重新连接的表面纹理的不应该是必要的。另外,重新连接需要相当长的时间...... 3-6毫秒与偷窥12毫秒的每一帧,这可以更好地用于渲染。我做/理解somethind错在这里?为什么它的工作像一个魅力的的Nexus 4的4.3,而无需重新连接表面纹理?

My question now is: Is this the correct way to do this? Honestly I thought the re-attaching of the SurfaceTexture should not be necessary when I use shared contexts. Also the re-attaching takes quite a long time... 3-6 ms for every frame with peeks on 12 ms, which could be better used for rendering. Am I doing/understanding somethind wrong here? Why did it work like a charm on the Nexus 4 with 4.3 without the need to re-attach the SurfaceTexture?

推荐答案

看来这其实是同一个问题的。我把一些细节存在;总之,你应该能够取消绑定和重新绑定的质感,这基本上是你做的什么尴尬的安装/拆卸序列来修复它

It appears this is in fact the same problem as this question. I put some details there; in short, you should be able to fix it by un-binding and re-binding the texture, which is essentially what you're doing with the awkward attach/detach sequence.

在我的code,我能够改变这个解决它:

In my code, I was able to fix it by changing this:

GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID);

这样:

GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0);
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID);

在我的纹理渲染。我会更新的bigflake例子了一下。

in my texture renderer. I'll update the bigflake examples in a bit.

这篇关于表面纹理updateTexImage共享2 EGLContexts - 问题在Android 4.4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 09:01