【发布时间】:2016-04-13 10:00:07
【问题描述】:
我指的是SurfaceTexture.detachFromGLContext,它提到,“OpenGL ES 纹理对象将因为这个调用而被删除。”
请解释一下为什么框架在调用分离时需要删除这个纹理对象,因为纹理是在 SurfaceTexture 之外创建并提供给构造函数的。所以,我希望即使在分离之后也能使用纹理,并且创建者应该能够控制它的生命周期。
我们正在尝试将其与附加方法和 MediaCodec 的组合使用。在我们的用例中,我们需要复制视频帧纹理以备将来使用。
以下是创建 SurfaceTexture 的示例代码:
int[] textures = new int[1];
GLES20.glGenTextures(1, textures, 0);
SurfaceTexture surfaceTexture = new SurfaceTexture(textures[0]);
然后将创建一个表面并按照以下代码示例传递给 MediaCodec
Surface surface = new Surface(surfaceTexture);
MediaCodec videoDecoder.configure(..., surface, null, 0);
在执行解码时,一旦将视频帧解码为纹理,我会尝试保留纹理并为 SurfaceTexture 分配不同的纹理,以便以后可以使用它,解码器可以将另一帧解码为新纹理。
surfaceTexture.detachFromGLContext();
surfaceTexture.attachToGLContext(newTexture);
但问题是android框架删除了纹理。我的观点是它应该是一个错误,或者应该有理由删除纹理。
【问题讨论】: