我可以在发布使用它的媒体编解码器后在表面视图上绘制吗?



我目前正在使用媒体编解码器进行实时视图硬件解码。代码如下所示

mMediaCodecDecoder = MediaCodec.createDecoderByType(MIME_TYPE);
format = MediaFormat.createVideoFormat(MIME_TYPE, mLiveViewBuff.frameData.picWidth, mLiveViewBuff.frameData.picHeight);
if (mSurfaceHolder.getSurface().isValid()) {
    mMediaCodecDecoder.configure(format, mSurfaceHolder.getSurface(), null, 0);
}
mMediaCodecDecoder.start();
decoderInputBuffers = mMediaCodecDecoder.getInputBuffers();
decoderOutputBuffers = mMediaCodecDecoder.getOutputBuffers();
decoderConfigured = true;

在某个阶段,我决定像这样发布媒体编解码器

mMediaCodecDecoder.stop();
mMediaCodecDecoder.release();
mMediaCodecDecoder = null;

然后,我想通过执行此操作来清除表面视图,然后再为另一个实时视图硬件解码创建另一个媒体编解码器。

Canvas canvas = mSurfaceHolder.lockCanvas();
canvas.drawColor(getResources().getColor(R.color.WHITE));
mSurfaceHolder.unlockCanvasAndPost(canvas);

但我得到了一些connect(P): already connected错误

长话短说

所以基本上,我有 2 个 h264 实时馈送来使用媒体编解码器进行硬件解码并在 surfaceview 上播放。 在播放它们之间,我喜欢通过在画布上绘制纯黑色来清除表面视图。

请给我一些建议谢谢

我在这里得到类似的问题,并在这里回答答案 https://stackoverflow.com/a/29243067/849715

private void clearSurface(SurfaceTexture texture) {
        EGL10 egl = (EGL10) EGLContext.getEGL();
        EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
        egl.eglInitialize(display, null);
        int[] attribList = {
                EGL10.EGL_RED_SIZE, 8,
                EGL10.EGL_GREEN_SIZE, 8,
                EGL10.EGL_BLUE_SIZE, 8,
                EGL10.EGL_ALPHA_SIZE, 8,
                EGL10.EGL_RENDERABLE_TYPE, EGL10.EGL_WINDOW_BIT,
                EGL10.EGL_NONE, 0,      // placeholder for recordable [@-3]
                EGL10.EGL_NONE
        };
        EGLConfig[] configs = new EGLConfig[1];
        int[] numConfigs = new int[1];
        egl.eglChooseConfig(display, attribList, configs, configs.length, numConfigs);
        EGLConfig config = configs[0];
        EGLContext context = egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT, new int[]{
                12440, 2,
                EGL10.EGL_NONE
        });
        EGLSurface eglSurface = egl.eglCreateWindowSurface(display, config, texture,
                new int[]{
                        EGL10.EGL_NONE
                });
        egl.eglMakeCurrent(display, eglSurface, eglSurface, context);
        GLES20.glClearColor(0, 0, 0, 1);
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
        egl.eglSwapBuffers(display, eglSurface);
        egl.eglDestroySurface(display, eglSurface);
        egl.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE,
                EGL10.EGL_NO_CONTEXT);
        egl.eglDestroyContext(display, context);
        egl.eglTerminate(display);
    }

最新更新