override fun drawFrame()

in app/src/main/java/com/amazonaws/services/chime/sdkdemo/utils/BlackAndWhiteGlVideoFrameDrawer.kt [35:83]


    override fun drawFrame(
        frame: VideoFrame,
        viewportX: Int,
        viewportY: Int,
        viewportWidth: Int,
        viewportHeight: Int,
        additionalRenderMatrix: Matrix?
    ) {
        val isTextureFrame = frame.buffer is VideoFrameTextureBuffer
        val textureBuffer = frame.buffer as VideoFrameTextureBuffer
        if (!isTextureFrame || textureBuffer.type != VideoFrameTextureBuffer.Type.TEXTURE_OES) {
            throw InvalidParameterException("Only OES texture frames are expected")
        }

        // Set up and account for transformation
        val width: Int = frame.getRotatedWidth()
        val height: Int = frame.getRotatedHeight()
        calculateTransformedRenderSize(width, height, additionalRenderMatrix)
        if (renderWidth <= 0 || renderHeight <= 0) {
            return
        }
        renderMatrix.reset()
        // Need to translate origin before rotating
        renderMatrix.preTranslate(0.5f, 0.5f)
        renderMatrix.preRotate(frame.rotation.degrees.toFloat())
        // Translate back
        renderMatrix.preTranslate(-0.5f, -0.5f)
        // Apply additional matrix
        additionalRenderMatrix?.let { renderMatrix.preConcat(it) }

        // Apply texture frame matrix
        val finalMatrix = Matrix(textureBuffer.transformMatrix)
        finalMatrix.preConcat(renderMatrix)
        val finalGlMatrix = GlUtil.convertToGlTransformMatrix(finalMatrix)

        prepareShader(finalGlMatrix)

        // Bind the texture.
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0)
        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureBuffer.textureId)

        // Draw the texture.
        GLES20.glViewport(viewportX, viewportY, viewportWidth, viewportHeight)
        GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4)
        GlUtil.checkGlError("Failed to draw OES texture")

        // Reset texture back to default texture
        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0)
    }