How WebRTC Bandwidth Estimation Works

Real-time communication relies heavily on adapting to fluctuating network conditions to maintain clear audio and video. This article provides a comprehensive look at how WebRTC continuously calculates and utilizes internal Bandwidth Estimation (BWE) to prevent network congestion. We will break down the transition from receiver-side to sender-side estimation, explain the delay-based and loss-based algorithms used for calculations, and explore how WebRTC dynamically adjusts media bitrates in real time.

The Role of Bandwidth Estimation in WebRTC

Bandwidth Estimation (BWE) is the mechanism WebRTC uses to determine the maximum amount of data it can transmit over a network path without causing congestion. Because consumer internet connections (especially Wi-Fi and mobile networks) experience constant fluctuations in capacity, WebRTC must continuously probe the network, calculate available capacity, and adapt its media stream bitrate on the fly.

If the estimate is too high, the network buffers overflow, leading to packet loss, high latency, and frozen video. If the estimate is too low, the video quality becomes needlessly poor.

Shift to Sender-Side Bandwidth Estimation

Historically, WebRTC relied on receiver-side estimation, where the receiver calculated the bandwidth and sent a Receiver Estimated Maximum Bitrate (REMB) message back to the sender.

Modern WebRTC implementations have shifted to Sender-Side Bandwidth Estimation. In this architecture, the receiver acts as a simple feedback agent, while the sender does the heavy lifting. The key protocol enabling this is Transport-Wide Congestion Control (TWCC).

With TWCC, the sender attaches a transport-wide sequence number to every outgoing packet. The receiver keeps track of when these packets arrive and sends back feedback packets containing a map of packet arrival times. Armed with this precise timing data, the sender calculates the network state.

How WebRTC Calculates Bandwidth

The sender-side BWE engine calculates the target bitrate by combining two distinct mathematical models: delay-based estimation and loss-based estimation.

1. Delay-Based Estimation

Delay-based estimation acts as an early warning system. It detects network congestion before packets are actually dropped by measuring changes in packet transit delay, known as one-way delay variation.

2. Loss-Based Estimation

Loss-based estimation is a reactive backup mechanism. It relies on explicit packet loss percentages reported via RTCP feedback or TWCC.

The final bandwidth estimate is typically the minimum value calculated by these two controllers (Delay-Based and Loss-Based), ensuring a conservative and highly responsive approach to network congestion.

How WebRTC Utilizes the Estimated Bandwidth

Once the BWE engine calculates a new bandwidth limit, WebRTC immediately utilizes this estimate to modify the outgoing media streams through several layers of adaptation: