首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用MediaMuxer / MediaCodec InputSurface和GLSurfaceView?

如何使用MediaMuxer / MediaCodec InputSurface和GLSurfaceView?
EN

Stack Overflow用户
提问于 2013-10-31 06:19:28
回答 1查看 3.4K关注 0票数 6

BigFlake示例之后,有一条注释声明:

代码语言:javascript
运行
复制
// Acquire a new frame of input, and render it to the Surface.  If we had a
// GLSurfaceView we could switch EGL contexts and call drawImage() a second
// time to render it on screen.  The texture can be shared between contexts by
// passing the GLSurfaceView's EGLContext as eglCreateContext()'s share_context
// argument.

我使用EGL14.getCurrentContext()查询当前上下文并将其传递给EGL14.eglCreateContext() share_context参数,但是如何“切换EGL上下文”?

GLSurfaceView和MediaCodec.inputSurface有两个不同的曲面和两个不同的上下文,所以我假设您只是在每个集合上分别调用eglMakeCurrent(),对吗?你需要eglDestroyContext()还是eglDestroySurface()

添加了更新

谢谢Fadden,我想我发现了这个错误,而不是drawFrame,而是调用了drawImage,但是您不需要第二次更新图像,对吗?

现在,当在EOS设置好之后调用dequeueBuffer时,我得到了内存不足的错误dequeueBuffer。也许我是在录音停止后打电话给它的。谢谢你的帮助。

在EGLSurface中创建MyEGLWrapper.java

代码语言:javascript
运行
复制
saveToScreenRenderState();
mEGLContext = EGL14.eglCreateContext(mEGLDisplay, configs[0], mScreenEglContext, 
        contextAttribs, 0);
checkEglError("eglCreateContext");

// Create a window surface, and attach it to the Surface we received.
mEGLSurface = EGL14.eglCreateWindowSurface(mEGLDisplay, configs[0], mSurface,
        surfaceAttribs, 0);
checkEglError("eglCreateWindowSurface");

...

private void saveToScreenRenderState() {
    //System.arraycopy(mProjectionMatrix, 0, mSavedMatrix, 0, mProjectionMatrix.length);
    mScreenEglDisplay = EGL14.eglGetCurrentDisplay();
    mScreenEglDrawSurface = EGL14.eglGetCurrentSurface(EGL14.EGL_DRAW);
    mScreenEglReadSurface = EGL14.eglGetCurrentSurface(EGL14.EGL_READ);
    mScreenEglContext = EGL14.eglGetCurrentContext();
}

public void makeCurrent(boolean toScreen, Surface surface) {
    if (toScreen) { //as opposed to toEncoder
        makeScreenSurfaceCurrent();
        return;
    } 
    EGL14.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext);
    checkEglError("eglMakeCurrent");
}

private void makeScreenSurfaceCurrent() {
    EGL14.eglMakeCurrent(mScreenEglDisplay, mScreenEglDrawSurface, 
            mScreenEglReadSurface, mScreenEglContext);
    checkEglError("eglMakeCurrent");
}

在CaptureManager.java中

代码语言:javascript
运行
复制
private void drawFrameOnInputSurface() {
    //draw a second time for inputSurface 
    mEGLWrapper.makeCurrent(false, videoCodec.videoCodecInputSurface);
    drawFrame(false);
    //ByteBuffer frame = mStManager.drawImage();
    videoCodec.runQue(false); // clear que before posting should this be on this thread???
    mEGLWrapper.setPresentationTime(mSt.getTimestamp(),!recordingStopped);
    mEGLWrapper.swapBuffers(!recordingStopped);
    videoHandler.post(new Runnable(){
        @Override
        public void run(){
            videoCodec.updateFrame(!isRecording);
        }
    });
}

private void drawFrame(boolean updateImage){
    mStManager.drawImage(updateImage);
    mGLView.mRenderer.drawFrame();
}

在SurfaceTextureManager.java中

代码语言:javascript
运行
复制
public ByteBuffer drawImage(boolean updateImage) {
    // Latch the data.
    if (updateImage){
        mTextureRender.checkGlError("before updateTexImage");
        mSurfaceTexture.updateTexImage();
    }
    return mTextureRender.drawFrame(mSurfaceTexture);
}

SurfaceTextureManager.javamSurfaceTexture.updateTexImage();上的错误

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-31 14:55:54

是的,使用eglMakeCurrent在两个上下文之间切换。

您不需要破坏当前未使用的上下文或表面(至少在关闭之前)。

有关使用共享上下文进行两次呈现的示例,请参见bigflake 突破游戏记录器补丁

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19699651

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档