logo
Live Streaming
On this page

Stream Quality Monitoring

2024-01-12

Feature Overview

When using ZEGOCLOUD Express SDK for calls, users may experience poor network conditions. You can use relevant callbacks to monitor changes in current call network quality and audio/video information.

For example, in multi-person audio/video calls or multi-person singing scenarios, if you need to display user network quality in real-time, you can refer to this document to implement the corresponding functionality.

Example Source Code Download

Please refer to Download Example Source Code to obtain the source code.

For relevant source code, please view files in the "src/Examples/AdvancedStreaming/StreamMonitoring" directory.

Prerequisites

Before monitoring stream quality, ensure that:

Basic Network Quality Report

You can listen to the networkQuality callback to receive upstream and downstream network quality for users (including yourself). This callback is triggered every two seconds. For network quality levels, please refer to QualityGrade.

networkQuality callback logic:

  • You will receive your own network quality callback as long as you publish or play streams.
  • You will receive other users' network quality callbacks only when you are playing audio/video streams published by other users and those users are in your room.
  • When "userID" is "" (empty string), it represents your own network quality. When "userID" is not "" (empty string), it represents reports for other users in the room.
  • You can estimate the network status of remote publishing users. If a remote publishing user's heartbeat is lost once, their network quality will be reported as "unknown". If the heartbeat is lost 3 times, their network quality will be reported as "die".
Warning

networkQuality is not applicable for live streaming scenarios using CDN.

zg.on("networkQuality", (userID, upstreamQuality, downstreamQuality) => {
        console.log("networkQuality", userID, upstreamQuality, downstreamQuality)
})

Advanced Quality Report

If the basic network quality report above does not meet your needs, ZEGOCLOUD also provides more detailed stream publishing quality reports, stream playing quality reports, and other related information.

Stream Publishing Quality Report

The stream publishing quality report describes the quality of the process where users push audio/video streams to the ZEGOCLOUD server. It includes the frame rates of audio/video streams during the capture and encoding phases, as well as the frame rate, bitrate, latency, and packet loss rate of the transmitted (sent) audio/video streams.

You can register publishQualityUpdate to receive stream publishing quality callbacks. This callback is received every three seconds after successful stream publishing. You can use the stats (ZegoPublishStats) parameter to understand the health status of published audio/video streams in real-time.

  • In most cases, you only need to pay attention to the videoQuality parameter of video and the audioQuality parameter of audio. You can determine the overall quality of stream publishing through the enumeration values of these two parameters.
  • If you want to focus on more detailed stream publishing quality parameters, please refer to ZegoPublishStats.
zg.on('publishQualityUpdate', (streamId, stats) => {
    console.log('publishQualityUpdate', streamId, stats);
})

Stream Publishing Quality Details

Stream publishing quality includes video quality and audio quality during publishing, such as video bitrate, audio bitrate, video frame rate, etc.

Video Quality

The relevant parameters for video quality ZegoPublishVideoStats data during stream publishing are as follows:

Parameter NameDescription

frameHeight

Captured video height.

frameWidthCaptured video width.
googCodecNameVideo encoding format.
muteStateWhether the video track is muted.
videoBitrateVideo bitrate, in kbps.
videoFPSVideo encoding frame rate, in f/s.
videoPacketsLostNumber of video packets lost.
videoPacketsLostRateVideo packet loss rate, in percentage, ranging from 0.0 to 1.0.
videoTransferFPSVideo sending frame rate, in f/s.
videoQualityStream publishing video quality:
  • -1: Unknown
  • 0: Excellent
  • 1: Good
  • 2: Fair  
  • 3: Poor  
  • 4: Very poor

Audio Quality

The relevant parameters for audio quality ZegoPublishAudioStats during stream publishing are as follows:

Parameter NameDescription

 audioBitrate

Audio bitrate, in kbps.
audioPacketsLostNumber of audio packets lost.
audioPacketsLostRateAudio packet loss rate, in percentage, ranging from 0.0 to 1.0.
googCodecNameAudio encoding format.
muteStateWhether the audio track is muted.
audioFPSAudio frame rate, in f/s.
audioQualityStream publishing audio quality:
  • -1: Unknown
  • 0: Excellent
  • 1: Good
  • 2: Fair
  • 3: Poor
  • 4: Very poor

Stream Playing Quality Report

The stream playing quality report describes the quality of the process where users play audio/video streams. It includes the frame rate, bitrate, latency, and packet loss rate of received audio/video streams, as well as the frame rate during the decoding phase and the overall audio/video quality.

You can register playQualityUpdate to receive stream playing quality callbacks. This callback is received every three seconds after successful stream playing. Developers can use the stats (ZegoPlayStats) parameter to understand the health status of played audio/video streams in real-time.

  • In most cases, you only need to pay attention to the videoQuality parameter of video and the audioQuality parameter of audio. You can determine the overall quality of stream playing through the enumeration values of these two parameters.
  • If you want to focus on more detailed stream playing quality parameters, please refer to ZegoPlayStats.
zg.on('playQualityUpdate', (streamId, stats) => {
    console.log('publishQualityUpdate', streamId, stats);
})

Stream Playing Quality Details

Stream playing quality includes video quality and audio quality during playing, such as video bitrate, audio bitrate, video frame rate, etc.

Video Quality

The relevant parameters for video quality ZegoPlayVideoStats data during stream playing are as follows:

Parameter NameDescription

frameHeight

Received video height.
frameWidthReceived video width.
googCodecNameVideo encoding format.
muteStateWhether the video track is muted.
videoBitrateVideo bitrate, in kbps.
videoFPSVideo decoding frame rate, in f/s.
videoPacketsLostNumber of video packets lost.
videoPacketsLostRateVideo packet loss rate, in percentage, ranging from 0.0 to 1.0.
videoTransferFPSVideo receiving frame rate, in f/s.
videoFramesDecodedTotal size of decoded video frames.
videoFramesDroppedNumber of currently received video frames dropped.
videoQualityStream playing video quality:
  • -1: Unknown
  • 0: Excellent
  • 1: Good  
  • 2: Fair  
  • 3: Poor  
  • 4: Very poor

Audio Quality

The relevant parameters for audio quality ZegoPlayAudioStats during stream playing are as follows:

Parameter NameDescription

audioBitrate

Audio bitrate, in kbps.
audioJitterNetwork jitter.
audioLevelVolume level.
audioPacketsLostNumber of packets lost.
audioPacketsLostRatePacket loss rate, in percentage, ranging from 0.0 to 1.0.
audioSamplingRateSampling rate.
muteStateWhether the audio track is muted.
audioFPSAudio frame rate, in f/s.
audioSendLevelAudio sending energy.
googCodecNameAudio encoding format.
audioQualityStream playing audio quality:
  • -1: Unknown
  • 0: Excellent
  • 1: Good
  • 2: Fair
  • 3: Poor
  • 4: Very poor

Other Information Monitoring

Stream Publishing/Playing Status Change Notification

Stream Publishing Status Callback

After successful stream publishing, you can use publisherStateUpdate to receive notifications of stream publishing status changes.

zg.on('publisherStateUpdate', result => {
    console.log('publisherStateUpdate: ', result.streamID, result.state, result);
});

You can roughly determine the user's stream publishing network status based on whether the state parameter in the callback is in the "requesting stream publishing status". The values of the state parameter correspond to user stream publishing status as follows:

Status ValueDescription
NO_PUBLISHNo stream publishing status, which is the state before stream publishing. If a stable exception occurs during the stream publishing process, such as incorrect AppID, AppSign, or Token, or if other users are already publishing streams, publishing streams with the same stream ID will fail and enter the no stream publishing status.
PUBLISH_REQUESTINGRequesting stream publishing status. After the stream publishing operation is executed successfully, it will enter the requesting stream publishing status. Usually, this status is used for UI interface display. If an interruption occurs due to poor network quality, the SDK will perform internal retry and return to the requesting stream publishing status.
PUBLISHINGPublishing stream status. Entering this status indicates that stream publishing has been successful and users can communicate normally.

Stream Playing Status Change Callback

After successful stream playing, developers can use playerStateUpdate to receive notifications of stream playing status changes.

zg.on('playerStateUpdate', result => {
        console.warn('playerStateUpdate', result.streamID, result.state);
})

Developers can roughly determine the user's stream playing network status based on whether the state parameter is in the "requesting stream playing status". The values of the state parameter correspond to user stream playing status as follows:

Status ValueDescription
NO_PLAYNo stream playing status, which is the state before stream playing. If a stable exception occurs during the stream playing process, such as incorrect AppID, AppSign, or Token, it will enter the no stream playing status.
PLAY_REQUESTINGRequesting stream playing status. After the stream playing operation is executed successfully, it will enter the requesting stream playing status. Usually, this status is used for application interface display. If an interruption occurs due to poor network quality, the SDK will perform internal retry and return to the requesting stream playing status.
PLAYINGPlaying stream status. Entering this status indicates that stream playing has been successful and users can communicate normally.

Previous

Using Token for Authentication

Next

Network Testing