Skip to main content

You are looking at Interactive Live Streaming v3.x Docs. The newest version is  Interactive Live Streaming 4.x

Android
iOS
macOS
Windows C++
Windows C#
Unity
Flutter
React Native
Electron
Cocos Creator
Cocos2d-x

Video Stream Fallback

Introduction

The audio and video quality of interactive live video streaming or a video call deteriorates under poor network conditions. To improve the efficiency of interactive live video streaming or a video call, the setLocalPublishFallbackOption and setRemoteSubscribeFallbackOption methods are used for the SDK to automatically switch the high-video stream to low-video stream and disable the video stream under these conditions.

Implementation

Before proceeding, ensure that you implement interactive live video streaming or a video call in your project. See Start Live Interactive Video Streaming or Start a Call for details.

Refer to the following steps to set the stream fallback under poor network conditions:

  1. After joining the channel, the publisher calls the enableDualStreamMode method to enable dual stream mode.

  2. The publisher calls the setLocalPublishFallbackOption method and set AUDIO_ONLY (2) to enable the fallback option for the locally published media stream based on the network conditions. The SDK will disable the upstream video and enable audio only when the network conditions deteriorate and cannot support both video and audio streams.

    Agora does not recommend using this method for Media Push, because the remote CDN live user will have a noticeable lag when the locally published video stream falls back to audio only.

    When the local video stream falls back to audio only or when the audio-only stream switches back to the video, the SDK triggers the onLocalPublishFallbackToAudioOnly callback to report current stream state to the local publisher.

  3. The subscriber in the channel calls the setRemoteSubscribeFallbackOption method to set the subscribed stream fallback under poor network conditions.

    • Sets STREAM_LOW (1) to only subscribe to the low-video stream sent from the publisher under poor network conditions.
    • Sets AUDIO_ONLY (2) to subscribe to the low-video stream sent or even audio stream from the publisher under poor network conditions.

    Once the remote media stream is switched to the low stream due to poor network conditions, you can monitor the stream change between a high and low stream in the onRemoteVideoStats callback. When the remotely subscribed video stream falls back to audio only or when the audio-only stream switches back to the video stream, the SDK triggers the onRemoteSubscribeFallbackToAudioOnly callback.

Sample code


_9
//Java
_9
// Enable the dual-stream mode (Configuration for the local).
_9
rtcEngine.enableDualStreamMode(true);
_9
_9
// Configuration for the publisher. When the network condition is poor, send audio only.
_9
rtcEngine.setLocalPublishFallbackOption(Constants.STREAM_FALLBACK_OPTION_AUDIO_ONLY);
_9
_9
// Configuration for the subscriber. Try to receive low stream under poor network conditions. When the current network conditions are not sufficient for video streams, receive audio stream only.
_9
rtcEngine.setRemoteSubscribeFallbackOption(Constants.STREAM_FALLBACK_OPTION_AUDIO_ONLY);

API reference

Interactive Live Streaming