Media statistics
WebPlanetKit provides an API to get recent media statistics. This page describe how to use the API and what type of information is provided for each media stream type.
Overview of media statistics
You can use the getCurrentStats()
method to get some of the statistics from WebRTC statistics.
For more information on WebRTC statistics, see RTCStatsReport of the Mozilla documentation.
The getCurrentStats()
method returns a WebPlanetKitStatistics
object, which represents the statistics at the time of the API call. A WebPlanetKitStatistics
object consists of OutboundRtpStats
(outbound-rtp
statistics) and InboundRtpStats
(inbound-rtp
statistics).
- The
outbound-rtp
statistics include the audio and video statistics of the local user. - The
inbound-rtp
statistics include the audio and video statistics of one or more peers.
Detailed description of media statistics
The following statistical information is provided for each media stream type.
- For more information on each of
outbound-rtp
statistics, see RTCOutboundRtpStreamStats. - For more information on each of
inbound-rtp
statistics, see RTCInboundRtpStreamStats.
Outbound audio streams
For outbound audio streams (outbound-rtp
audio), the following information is provided. You can find more detailed description in the links of each property.
Property | Description |
---|---|
kind | The media type of this stream |
ssrc | The identifier of this stream |
packetsSent | The total number of packets sent on this stream |
bytesSent | The total number of bytes sent on this stream |
Outbound video streams
For outbound video streams (outbound-rtp
video), the following information is provided. You can find more detailed description in the links of each property.
Property | Description |
---|---|
kind | The media type of this stream |
ssrc | The identifier of this stream |
rid | The video resolution level in a group call |
contentType | If this stream is for screen share, the value of this property will be screenshare . Otherwise, this property will not exist. |
packetsSent | The total number of packets sent on this stream |
bytesSent | The total number of bytes sent on this stream |
firCount | The total number of Full Intra Request (FIR) packets on this stream |
pliCount | The total number of Picture Loss Indication (PLI) packets on this stream |
nackCount | The total number of Negative Acknowledgement (NACK) packets on this stream |
frameWidth | The width of the video frame |
frameHeight | The height of the video frame |
framesSent | The total number of frames sent on this stream |
framesPerSecond | The number of encoded frames during the last second |
targetBitrate | The target bitrate for this stream |
Inbound audio streams
For inbound audio streams (inbound-rtp
audio), the following information is provided. You can find more detailed description in the links of each property.
Property | Description |
---|---|
kind | The media type of this stream |
ssrc | The identifier of this stream |
packetsReceived | The total number of packets received on this stream |
bytesReceived | The total number of bytes received on this stream |
packetsLost | The total number of packets lost on this stream |
jitter | The variation in the delay of received packets |
Inbound video streams
For inbound video streams (inbound-rtp
video), the following information is provided. You can find more detailed description in the links of each property.
Property | Description |
---|---|
kind | The media type of this stream |
ssrc | The identifier of this stream |
packetsReceived | The total number of packets received on this stream |
bytesReceived | The total number of bytes received on this stream |
packetsLost | The total number of packets lost on this stream |
jitter | The variation in the delay of received packets |
firCount | The total number of FIR packets on this stream |
pliCount | The total number of PLI packets on this stream |
nackCount | The total number of NACK packets on this stream |
frameWidth | The width of the video frame |
frameHeight | The height of the video frame |
framesReceived | The total number of frames received on this stream |
framesDecoded | The total number of frames decoded on this stream |
framesDropped | The total number of frames dropped on this stream |
framesPerSecond | The number of decoded frames in the last second |
Media statistics by call type
This section describes what type of statistics are provided for each call type.
1-to-1 call
OutboundRtpStats
contains one audio stream statistic for the local user's audio transmission and one video stream statistic for the local user's video transmission. If the local user is doing screen share, OutboundRtpStats
contains another video stream statistic for the local user's screen share.
InboundRtpStats
contains one audio stream statistic and multiple video stream statistics for the peer.
Group call
OutboundRtpStats
contains an audio stream statistic for the local user's audio transmission and three video stream statistics (one for each resolution level). If the local user is doing screen share, OutboundRtpStats
contains another video stream statistic for the local user's screen share.
InboundRtpStats
contains an audio stream statistic for the room and multiple video stream statistics for each peer.
Statistics for screen share
The statistics for screen share are included in OutboundRtpStats
or InboundRtpStats
as a video stream statistic.
Statistic of the local user's screen share
The statistic for the local user's screen share is included in OutboundRtpStats
. Among video stream statistics, only the screen share statistic has contentType
property and its value is screenshare
.
Therefore, to obtain the statistics for the local user's screen share, get an object among OutboundRtpStats
whose kind
property is video
and whose contentType
property is screenshare
.
planetKit.getCurrentStats().then((stats) => {
const outboundRtpStats = stats['outbound-rtp'];
outboundRtpStats.forEach((outboundRtpStat) => {
if (outboundRtpStat.kind === 'video' && outboundRtpStat.contentType === 'screenshare') {
// This outboundRtpStat is the statistics for the local user's screen share
}
});
})
Statistic of a peer's screen share
The statistics for one or more peers' screen share are included in InboundRtpStats
.
In a 1-to-1 call, you can distinguish the statistics because the peer is specified, but in a group call, you must distinguish the statistics by ssrc
.
In group calls, each peer has their own state information as PeerInfo
, which includes properties such as vSsrc
for video stream identifier and dSsrc
for screen share identifier.
To obtain the statistics for a peer's screen share, get an object among InboundRtpStats
whose kind
property is video
and whose ssrc
property matches the peer's dSsrc
value.
The following example code is the sample code for group calls.
planetKit.getCurrentStats().then((stats) => {
const inboundRtpStats = stats['inbound-rtp'];
const samplePeerInfo = planetKit.getPeerInfo('testPeerId');
inboundRtpStats.forEach((inboundRtpStat) => {
if (inboundRtpStat.kind === 'video' && inboundRtpStat.ssrc === samplePeerInfo.dSsrc) {
// This inboundRtpStat is the statistics for a peer's screen share
}
});
})
Related API
APIs related to media statistics are as follows: