Live SDKs Android v1
Live SDKs Android
Live SDKs
Android
Version 1

Live quality management

Copy link

When users participate in a live event, network connection may fluctuate throughout the event, affecting the streaming quality. In such case, you might want to notify users of their network quality, rather than having the event interrupted without any alert.

Sendbird Live provides functionalities to configure the quality of video streaming during a live event, and to notify the users whenever the connection quality changes throughout the event.


Video streaming settings

Copy link

When streaming video content as hosts, it is essential to consider the fluctuations in network conditions that may occur during the stream. You can allow hosts to set and adjust their video quality settings through mediaOptions.videoQualityConstraints.

Note: The video quality settings are needed only when the live event's type is set to video. Each host in the event can configure their own settings according to their preference.

While WebRTC automatically adjusts the media quality based on the available network capacity, there are instances where fine-tuning specific properties becomes necessary to align with the purpose and requirements of the event.

For example, in conference event streams, emphasis may be placed on video resolutions to ensure clear visuals, while in sport event streams, the focus might be on maintaining a higher video frame rate to capture fast-paced action accurately.

Specify videoQualityConstraints

Copy link

When starting the stream as hosts, set the following three parameters in videoQualityConstraints.

val videoQualityConstraints = VideoQualityConstraints().apply {
    this.fps = 12
    this.resolution = Resolution(width = 480, height = 680)
    this.degradationPreference = RtpParameters.DegradationPreference.MAINTAIN_RESOLUTION
}

List of the videoQualityConstraints parameters

Copy link
ParameterDescription

resolution

Specifies the video resolution that the WebRTC stream uses.

fps

Specifies the frames per second for the WebRTC Video stream.

degradationPreference

Specifies a degradation preference to prioritize a specific aspect of the stream.
- MAINTAIN_RESOLUTION: This ensures that the resolution of the video stream remains unchanged even if the network conditions deteriorate. It prioritizes maintaining a clear visual experience in compensation of smoothness of the video.

- MAINTAIN_FPS: This ensures that the frame rate of the video stream remains consistent even if the network conditions degrade. It prioritizes maintaining smooth and fluid motion in compensation of clear video quality.

- AUTO: With this option, WebRTC automatically adjusts both the resolution and frame rate based on the network conditions, finding the best balance between visual clarity and smooth motion.

Note: Before setting thess parameters, check the supported resolution or fps on your device. If you set a resolution or fps value that is not supported by the device, or don't set either of the two, the system will automatically set an approximate value.

Adjust the settings during streaming

Copy link

While the initial configuration sets the video quality constraints, it's important to note that WebRTC's adaptive nature adjusts the media quality based on network conditions as well.

However, if you find the need to make real-time adjustments to the video quality during the live event, use the updateVideoQualityConstraints() function.

This function allows you to modify the current resolution, FPS, or other quality parameters on the fly to better adapt to changing network conditions or specific event requirements. By dynamically adjusting these constraints, you can ensure a smooth streaming experience for the audience.

// Set the resolution to 720P, FPS to 12, and configure the video to maintain resolution but drop fps. 
val videoQualityConstraints = VideoQualityConstraints().apply {
    this.fps = 12
    this.resolution = Resolution(width = 720, height = 1280)
    this.degradationPreference = RtpParameters.DegradationPreference.MAINTAIN_RESOLUTION
}

liveEvent?.updateVideoQualityConstraints(videoQualityConstraints) { e ->
    if (e != null) {
        // Handle error
        return@updateVideoQualityConstraints
    }
}

Connection quality indicator

Copy link

You can notify both hosts and participants whenever there is a change in their network connection status during the live event. To do so, listen to events related to the connection quality change through ConnectionQualityListener and create an indicator to inform the status to the users.

Set ConnectionQualityListener

Copy link

To detect changes in connection quality, use the ConnectionQualityMonitor class. Set its ConnectionQualityListener and select a ConnectionQualityMonitoringMode value: either FREQUENCY or CONNECTION_QUALITY_CHANGE. Whenever there is a change in connection quality, the onConnectionQualityUpdated() method will be called according to the specified mode.

List of the monitoring modes

Copy link
ModeDescription

FREQUENCY

Monitors the connection quality every three seconds after the setConnectionQualityListener() method is called.

CONNECTION_QUALITY_CHANGE

Monitors the changes in connection quality level which can call the onConnectionQualityUpdated() method.

Remove the ConnectionQualityListener settings

Copy link

When the listener is no longer needed, set the listener to null to remove its previous configuration.

liveEvent.setConnectionQualityListener(null)

Connection metrics

Copy link

The connection quality data can vary by each host and participant in a live event, and this can be quantified and analyzed by ConnectionMetrics.

data class ConnectionMetrics (
    val packetLostRate: Double?,
    val rtt: Double?,
    val jitter: Double?,
    val resolution: Resolution?,
    val availableBitrate: Double?,
    val bandwidth: BigInteger?,
)

While you have flexibility to define connection quality value ranges that correspond to different quality levels, here’s a general guideline for interpreting these ranges and setting up the corresponding enumeration values.

How to read ConnectionMetrics

Copy link
Quality levelPacket Lost RateRound Trip Time

Excellent

0%-0.5%

0ms - 150ms

Good

0.5%-1%

150ms-200ms

Fair

1%-2.5%

200ms-250ms

Poor

2.5%-5%

250ms-300ms

Very Poor

> 5%

> 300ms

Based on the ConnectionQuality enum, you can assess the current quality of the streaming and implement appropriate actions to improve it. For example, you might display a quality degradation alert to the user if the connection quality drops below average.