Menu

Expand
Rate this page:

Migrating From 5.x to 6.x

This guide provides an introduction to the 6.x Programmable Video Android SDK and a set of guidelines to migrate an application from 5.x to 6.x.

New Features

  • The SDK has been upgraded to use Chromium WebRTC 83
  • The SDK now enables Discontinuous Transmission (DTX) by default when using the Opus codec. Enabling DTX results in a lower bitrate when silent audio is detected.
  • The capturing and rendering facilities have been updated to allow developers more control, flexibility, and capabilities. This update includes the adoption of WebRTC classes.
  • The SDK includes new callbacks onParticipantReconnecting and onParticipantReconnected to Room.Listener. These callbacks will be raised when a RemoteParticipant is attempting to reconnect to a room due to a signaling network interruption.
  • Room#isRecording() API now accurately reflects the current recording state of the Room. In the previous versions of the SDK, isRecording() could return false positives. The onRecordingStarted(...) and onRecordingStopped(...) callbacks will now be invoked when recording for at least a single track in the Room has started and stopped respectively.

Adopting WebRTC Classes

The update to video capturing and rendering includes an adoption of WebRTC classes defined in libwebrtc.jar included with the Video Android SDK. In previous major releases, the SDK would define public APIs with classes defined exclusively in the com.twilio.video package. The SDK will now include public APIs with classes defined in libwebrtc.jar.

Any public APIs that reference a WebRTC class are only compatible with the libwebrtc.jar provided from the Video Android SDK. The classes provided in this artifact are defined under the tvi.webrtc package to ensure side-by-side compatibility with other WebRTC based libraries.

Adopting WebRTC classses in public APIs provides developers already familiar with WebRTC more flexibility when capturing media and rendering media.

Updated Media Models

To gain a better understanding of the 6.x changes, see the below UML diagrams to help visualize the 5.x and 6.x media APIs.

5.x

6.x

Video Capturing

6.x includes an overhaul to the video capturer facilities. LocalVideoTracks are now created with implementations of tvi.webrtc.VideoCapturer and VideoFormats. VideoCapturer remains a part of the SDK as an extension of tvi.webrtc.VideoCapturer, but VideoConstraints have been completely removed in favor of VideoFormats.

Updated Programming Model

When a caller creates a LocalVideoTrack, the following methods of a tvi.webrtc.VideoCapturer are called in the order listed.

  1. isScreencast() - The return value is used to create a tvi.webrtc.VideoSource
  2. initialize(surfaceTextureHelper, context, capturerObserver) - This method is called so the capturer can set up to capture frames. The capturer should retain a reference to the capturer observer.
  3. startCapture(width, height, framerate) - The capturer should start capturing in a format as close as possible to width x height at framerate.

When a caller releases a local video track, the following methods are then called.

  1. stopCapture() - The capturer should stop capturing frames. The SDK expects this method to block until frames have stopped being captured.
  2. dispose() - The capturer should perform any final clean up.

API Updates

  • VideoPixelFormat has been removed in favor of implementing tvi.webrtc.VideoFrame.Buffer. The SDK includes support for the following buffer types: tvi.webrtc.VideoFrame.TextureBuffer, tvi.webrtc.NV21Buffer, tvi.webrtc.NV12Buffer, and Rgba8888Buffer.
  • VideoCapturer now extends tvi.webrtc.VideoCapturer.
  • getSupportedFormats() has been removed in favor of getCaptureFormat(). This update allows a VideoCapturer to provide a default capture format. For example, the ScreenCapturer returns a capture format based on the device screen dimensions.
  • VideoConstraints has been removed. Developers can now specify a capture format when creating a local video track and the tvi.webrtc.VideoCapturer is responsible for capturing at a format as close as possible to the specified format. The VideoFormat provided to LocalVideoTrack.create(...) takes highest priority over the format returned by VideoCapturer#getCaptureFormat(). The default format for video tracks remains 640x480 at 30 FPS.
  • Removed VideoFrame in favor of tvi.webrtc.VideoFrame.
  • Removed AspectRatio.

If you are implementing a custom VideoCapturer in your application, please take a look at the the Custom Video Capturer Example.

Updating an Application

See the code snippets below to learn how to update to the latest Video Capturing API.

5.x

// Setup video constraints
VideoConstraints videoConstraints = new VideoConstraints.Builder()
    .aspectRatio(VideoConstraints.ASPECT_RATIO_16_9)
    .minVideoDimensions(VideoDimensions.CIF_VIDEO_DIMENSIONS)
    .maxVideoDimensions(VideoDimensions.HD_720P_VIDEO_DIMENSIONS)
    .minFps(5)
    .maxFps(24)
    .build();

// Add a video track with constraints
LocalVideoTrack localVideoTrack = LocalVideoTrack.create(context, true, cameraCapturer, videoConstraints);

6.x

// Setup video format
VideoFormat videoFormat = new VideoFormat(VideoDimensions.HD_720P_VIDEO_DIMENSIONS, 30);

// Add a video track with the format
LocalVideoTrack localVideoTrack = LocalVideoTrack.create(context, true, cameraCapturer, videoFormat);

Video Rendering

6.x includes updated video rendering facilities. RemoteVideoTracks and LocalVideoTracks are now rendered with a tvi.webrtc.VideoSink instead of a VideoRenderer. VideoRenderer and VideoRenderer.Listener have been removed in favor of tvi.webrtc.VideoSink and tvi.webrtc.RendererCommon.RendererEvents respectively.

API Updates

  • Removed VideoRenderer in favor of tvi.webrtc.VideoSink
  • Removed VideoRenderer.Listener in favor of tvi.webrtc.RendererCommon.RendererEvents
  • Removed VideoTrack#addRenderer in favor of VideoTrack#addSink
  • Removed VideoTrack#removeRenderer in favor of VideoTrack#removeSink
  • Updated VideoView#setListener to take a tvi.webrtc.RendererCommon.RendererEvents instead of a VideoRenderer.Listener
  • Updated VideoTextureView#setListener to take a tvi.webrtc.RendererCommon.RendererEvents instead of a VideoRenderer.Listener

If you are implementing a custom VideoRenderer in your application, you will need to now implement the tvi.webrtc.VideoSink interface. Check out the Custom Video Sink Example to see an example of a concrete implementation of tvi.webrtc.VideoSink.

Updating an Application

See the code snippets below to learn how to update to the latest Video Rendering API.

5.x

// Rendering a local video track requires an implementation of VideoRenderer
// Let's assume we have added a VideoView in our view hierarchy
VideoView videoView = (VideoView) findViewById(R.id.video_view);

// Render a local video track
localVideoTrack.addRenderer(videoView);

// Render a local video track in a custom video renderer
localVideoTrack.addRenderer(new VideoRenderer() {
    @Override
    public void renderFrame(@NonNull I420Frame frame) {}
});

// Remove renderer to stop receiving video from a local video track
localVideoTrack.removeRenderer(videoView);

// Release the video track to free native memory resources
localVideoTrack.release();

6.x

// Rendering a local video track requires an implementation of VideoSink
// Let's assume we have added a VideoView in our view hierarchy
VideoView videoView = (VideoView) findViewById(R.id.video_view);

// Render a local video track
localVideoTrack.addSink(videoView);

// Render a local video track to a custom video sink
localVideoTrack.addSink(new VideoSink() {
    @Override
    public void onFrame(VideoFrame videoFrame) {}
});

// Remove sink to stop receiving video from a local video track
localVideoTrack.removeSink(videoView)

// Release the local video track to free native memory resources
localVideoTrack.release();

General API Updates

  • Added a ParticipantState enumeration.
  • Added a getState() method to Participant.
  • Removed the RemoteParticipant.isConnected() method in favor of Participant.getState().
  • Removed IceOptions.abortOnIceServersTimeout and IceOptions.iceServersTimeout
  • Removed CameraCapturer.CameraSource. CameraCapturer instances are now created using a camera ID as a String. You can use tvi.webrtc.Camera1Enumerator#getDeviceNames() to query the list of supported camera IDs.
  • Updated CameraCapturer#switchCamera() signature to require a camera ID. Users now must specify which camera ID to switch to. This behavior is similar to the Camera2Capturer switch camera behavior.

    The snippet below demonstrates the updated use of CameraCapturer.

// Create the instance
CameraCapturer cameraCapturer = CameraCapturer(context, frontCameraId)

// Switch camera Ids
cameraCapturer.switchCamera(backCameraId)
  • Camera2Capturer.Listener implementations are now optional when creating a Camera2Capturer

Codec Support API Update

Note that checking for H.264 hardware support changed from v5.x to v6.x. See the Managing Codecs guide to learn how to use the correct syntax.

Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.

        
        
        

        Thank you for your feedback!

        We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!

        Refer us and get $10 in 3 simple steps!

        Step 1

        Get link

        Get a free personal referral link here

        Step 2

        Give $10

        Your user signs up and upgrade using link

        Step 3

        Get $10

        1,250 free SMSes
        OR 1,000 free voice mins
        OR 12,000 chats
        OR more