WebRTC Android CapturerObserver - 它期望的格式是什么?

时间:2017-11-24 13:36:20

标签: android unity3d opengl-es webrtc libjingle

我的情况如下: 我通过WebRTC从运行Unity的Android设备运行视频流,我想发送一个自定义渲染结果,我有一个GLES20 RGB / RGBA格式纹理。

不幸的是,每当我尝试发送此纹理时,WebRTC会因1282 GL_INVALID_OPERATION错误而崩溃并使用它来关闭整个应用程序。

此外,调用glReadPixels然后发送字节缓冲区是有效的,因此纹理通过GLES20直接访问它至少是有效的,尽管格式错误的流式传输。如果它不是非常低效的实时性能,我会使用这种方法。

无论如何,代码:

public void getCameraImage(int textureID, int rotation, long timestamp)
{
    this.nTexId = textureID;
    if (!isStarted){
        isStarted = true;
        GLES20.glGenFramebuffers(1, this.genFBO, 0);
    }

    if (!newFrameReady){

            GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, genFBO[0]);
            GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, incomingTexId, 0); 
            // outputs correct values in RGBA
            GLES20.glReadPixels( 0,0, 16, 16, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, testBuffer);

            //clean up
            GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
            newFrameReady = true;
            mThread.run();
    }
}

还有线程的代码:

public void setupObserverThread(CapturerObserver capturerObserver) {
    this.capturerObserver = capturerObserver;
    mThread = new Thread(new Runnable() {
        @Override
        public void run() {
            if (newFrameReady) {
                try {
                    capturerObserver.onTextureFrameCaptured(width, height, this.nTexId, RendererCommon.identityMatrix(), mRotation, mTimestamp);
                    newFrameReady = false;
                    UnityPlayer.UnitySendMessage(gameObjectName, callbackFunction, "Captured");
                }catch( Exception e ){
                    Log.e(TAG, "run: GL ERROR ");
                }
            }
        }
    });

    mThread.start();
}

所以我的问题是 - 我能为WebRTC提供哪些能够满足它的格式要求并且不会崩溃?

这是webRTC崩溃后的stracktrace logcat。只有在它连接到对等体并且流被启动(第一帧)时才会发生。

11-24 16:01:59.673: E/org.webrtc.Logging(25509): MediaCodecVideoEncoder: encodeTexture failed
11-24 16:01:59.673: E/org.webrtc.Logging(25509): MediaCodecVideoEncoder: java.lang.RuntimeException: glUseProgram: GLES20 error: 1282
11-24 16:01:59.676: E/org.webrtc.Logging(25509): MediaCodecVideoEncoder: java.lang.RuntimeException: glUseProgram: GLES20 error: 1282
11-24 16:01:59.676: E/org.webrtc.Logging(25509):    at org.webrtc.GlUtil.checkNoGLES2Error(GlUtil.java:29)
11-24 16:01:59.676: E/org.webrtc.Logging(25509):    at org.webrtc.GlShader.useProgram(GlShader.java:110)
11-24 16:01:59.676: E/org.webrtc.Logging(25509):    at org.webrtc.GlRectDrawer.prepareShader(GlRectDrawer.java:195)
11-24 16:01:59.676: E/org.webrtc.Logging(25509):    at org.webrtc.GlRectDrawer.drawOes(GlRectDrawer.java:118)
11-24 16:01:59.676: E/org.webrtc.Logging(25509):    at org.webrtc.MediaCodecVideoEncoder.encodeTexture(MediaCodecVideoEncoder.java:592)
11-24 16:01:59.939: E/rtc(25509): #
11-24 16:01:59.939: E/rtc(25509): # Fatal error in ../../webrtc/sdk/android/src/jni/native_handle_impl.cc, line 225
11-24 16:01:59.939: E/rtc(25509): # last system error: 11
11-24 16:01:59.939: E/rtc(25509): # Check failed: !jni->ExceptionCheck()
11-24 16:01:59.939: E/rtc(25509): # textureToYUV throwed an exception
11-24 16:01:59.939: E/rtc(25509): #
11-24 16:01:59.940: A/libc(25509): Fatal signal 6 (SIGABRT), code -6 in tid 25838 (EncoderQueue - )

0 个答案:

没有答案