0

I'm currently using mediacodec for liveview hardware decoding. Code looks like this

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;

And at some stage, I decide to release the Mediacodec like this

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

Then after that I would like to clear the surface view by doing this before I want to create another mediacodec for another liveview hardware decoding.

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

but I got some connect(P): already connected error

Long story short

So basically, I have 2 h264 livefeed to use mediacodec to do hardware decode and play on surfaceview. between playing them, I woule like to clear the surfaceview by drawing pure black onto the canvas.

Please give me some advice Thanks

Xiaogegexiao
  • 111
  • 1
  • 5

1 Answers1

0

I get similar question here and answer answer here 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);
    }
Community
  • 1
  • 1
Xiaogegexiao
  • 111
  • 1
  • 5