The audio and video quality of a live broadcast or a video call deteriorates under poor network conditions. To improve the efficiency of a live broadcast, the
setRemoteSubscribeFallbackOption methods are used for the SDK automatically switch the high-video stream to low-video stream and disbale the video stream under these conditions.
Before proceeding, ensure that you implement a basic live broadcast in your project. See Start a Live Broadcast for details.
Refer to the following steps to set the stream fallback under poor network conditions:
After joining the channel, the host calls the
enableDualStreamModemethod to enable dual stream mode.
The host calls the
setLocalPublishFallbackOptionmethod and set
AUDIO_ONLY (2)to enable the fallback option for the locally published media stream based on the network conditions. SDK will disable the upstream video but enable audio only when the network conditions deteriorate and cannot support both video and audio stream.
Agora does not recommend using this method for CDN live streaming, 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, SDK triggers the
onLocalPublishFallbackToAudioOnlycallback to report current stream state to the local host.
Users in the channel call the
setRemoteSubscribeFallbackOptionmethod to set the subscribed stream fallback under poor network conditions.
STREAM_LOW (1)to only subscribe the low-video stream sent from the host under poor network conditions.
AUDIO_ONLY (2)to susbcribe the low-video stream sent or even audio stream from the host 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 switch between a high and low stream in the
onRemoteVideoStatscallback. 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
//Java // Enable the dual-stream mode (Configuration for the local). rtcEngine.enableDualStreamMode(true); // Configuration for the publisher. When the network condition is poor, send audio only. rtcEngine.setLocalPublishFallbackOption(Constants.STREAM_FALLBACK_OPTION_AUDIO_ONLY); // 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. rtcEngine.setRemoteSubscribeFallbackOption(Constants.STREAM_FALLBACK_OPTION_AUDIO_ONLY);