A modern browsers can estimate a channel bandwidth calculating a maximum available bitrate for a stream publishing with a certain resolution, bitrate and FPS. The maximum available bitrate value availableOutgoingBitrate
may be extracted from WebRTC statistics data in Chromium based browsers and in Safari. The parameter is not available in Mozilla Firefox.
The availableOutgoingBitrate
may be received with other WebRTC statistics using the Stream.getStat()
method:
stream.getStats((stats) => { if (stats) { if (stats.outboundStream && stats.outboundStream.video) { let vBitrate = (stats.outboundStream.video.bytesSent - bytesSent) * 8; setBitrate(vBitrate); bytesSent = stats.outboundStream.video.bytesSent; } if (stats.otherStats && stats.otherStats.availableOutgoingBitrate !== undefined) { setAvailableBitrate(stats.otherStats.availableOutgoingBitrate); } } });
On the screenshot below, the current publishing bitrate and the maximum available bitrate are displayed for web camera stream and screen sharing stream
Thus, the camera stream (320x240, 30 fps) may be published with bitrate up to 1.2 Mbps, and the screen sharing stream (1280x720, 5 fps) may be up to 4 Мбит/с. In both cases, the available bitrate is significantly more than current publishing bitrate. This means the publishing channel is quite good, and there is a reserve for the channel quality to fall.
But, if the maximum available bitrate is close to the publishing one, then there is no reserve and, if the channel quality drops (due to additional packet loss for example), a viewers will see a freezes and worse picture quality.