Kotlin
Creating a custom Renderer (MyRenderer)
Now you'll create a custom renderer that will actually load the frame data and pass it to OpenGL textures. It will be used to apply the inverted-color fragment shader.
Below is an outline; you will adapt shader code later.
- Create a kotlin class MyRenderer (can be internal to InvertedColorsVideoRenderer)
static class MyRenderer implements GLSurfaceView.Renderer {
private int viewportWidth;
private int viewportHeight;
ReentrantLock frameLock = new ReentrantLock();
Frame currentFrame;
public void displayFrame(Frame frame) {
frameLock.lock();
if (currentFrame != null) {
currentFrame.destroy(); // Disposes previous frame
}
currentFrame = frame;
frameLock.unlock();
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// Initialize shaders, textures, etc.
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
GLES20.glViewport(0, 0, width, height);
viewportWidth = width;
viewportHeight = height;
}
@Override
public void onDrawFrame(GL10 gl) {
// Upload YUV frame → textures
// Draw using shaders
// Implementation of YUV → RGB shader pipeline
// using inverted color math
}
}
- Let's examine the
displayFramemethod. It is important to note that the frame that the sdk sends to theRendererin theonFramemethod is now property of theRenderer. It is up to this class to destroy the frame when it is not needed anymore. That's why we destroy previous frame when a new one comes to theRenderer
public void displayFrame(Frame frame) {
frameLock.lock();
if (currentFrame != null) {
currentFrame.destroy(); // Disposes previous frame
}
currentFrame = frame;
frameLock.unlock();
}
Basic video rendering
Learn how to use a custom video renderer in Kotlin to display a black-and-white version of a video stream using the Vonage Video Android SDK.
手順
1
Introduction2
Getting Started3
Creating a new project4
Adding the Android SDK5
Setting up authentication6
Requesting permissions7
Creating the Inverted Video Renderer8
Creating a custom Renderer (MyRenderer)9
Publishing a stream to the session10
Connecting Custom Renderer to Publisher/Subscriber11
Running the app12
Conclusion