fun getByteBufferFromInputVideoFrame()

in amazon-chime-sdk/src/main/java/com/amazonaws/services/chime/sdk/meetings/audiovideo/video/backgroundfilter/BackgroundFilterVideoFrameProcessor.kt [71:105]


    fun getByteBufferFromInputVideoFrame(frame: VideoFrame): ByteBuffer {
        // Note: This processor assumes that the incoming call will be on a valid EGL context.
        textureFrameBuffer.setSize(frame.getRotatedWidth(), frame.getRotatedHeight())
        GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, textureFrameBuffer.frameBufferId)

        val matrix = Matrix()
        matrix.preTranslate(0.5f, 0.5f)
        matrix.preScale(1f, -1f)
        matrix.preTranslate(-0.5f, -0.5f)

        // Note the draw call will account for any rotation, so we need to account for that in viewport width/height.
        rectDrawer.drawFrame(
            frame,
            0,
            0,
            frame.getRotatedWidth(),
            frame.getRotatedHeight(),
            matrix
        )

        // Read RGBA data to native byte buffer.
        val rgbaData =
            JniUtil.nativeAllocateByteBuffer(frame.getRotatedWidth() * frame.getRotatedHeight() * channels)
        GLES20.glReadPixels(
            0,
            0,
            frame.getRotatedWidth(),
            frame.getRotatedHeight(),
            GLES20.GL_RGBA,
            GLES20.GL_UNSIGNED_BYTE,
            rgbaData
        )
        GlUtil.checkGlError("glReadPixels")
        return rgbaData
    }