Adaptive Bitrate with WebRTC and TWCC

From RidgeRun Developer Wiki

Introduction

Web Real-Time Communication (WebRTC) has become a cornerstone technology for enabling direct and secure peer-to-peer audio, video, and data exchange without relying on additional plugins or third party software. Its ability to support real-time, low-latency communication makes it essential for modern use cases such as video conferencing, live streaming, online gaming, and remote collaboration. A critical factor in delivering a consistent and high-quality experience in WebRTC is adaptive bitrate (ABR). Network conditions can fluctuate significantly across devices and environments. ABR allows media streams to dynamically adjust their quality to match available bandwidth, reducing stalls, packet loss, and latency.

Bandwidth Estimation

ABR algorithms require a method for estimating the available bandwidth of a media stream in order to adjust the stream bitrate accordingly. WebRTC provides two useful feedback mechanisms that can be used to obtain bandwidth estimates for a given media stream: REMB and TWCC.

  1. REMB: Receiver Estimated Maximum Bitrate (REMB) works by having the receiver periodically estimate the maximum bitrate it can handle based on observed packet loss, jitter, and available bandwidth. It then sends this estimate back to the sender in a control message.
  2. TWCC: Transport-Wide Congestion Control (TWCC) provides fine-grained information about packet delivery. It works by having the sender assign sequence numbers to all RTP packets with precise sender-side timestamps, the receiver then adds precise receiver-side timestamps to the packets and periodically it sends these values through feedback messages back to the sender. TWCC does not directly provide a bandwidth estimate, however TWCC feedback allows the sender to build a detailed picture of network conditions, including delay trends and loss patterns.

REMB is simpler to use for ABR since it provides a bandwidth estimate out of the box, whereas TWCC requires the sender to use a separate bandwidth estimation algorithm before the data can be used for ABR. However, TWCC has a number of advantages over REMB:

  1. TWCC is more efficient than REMB since it works across all media channels, instead of requiring an estimate for each channel individually. This also provides a better understanding of the overall network quality.
  2. TWCC statistics allow detection of network congestion quicker than REMB bandwidth estimates.
  3. TWCC is agnostic to the content of the RTP packets, which allows it to work with any codec.
  4. TWCC statistics provides fine-grane detail on packet behavior. This allows the sender more flexibility in how it handles bandwidth estimation and other network congestion metrics (delay and packet loss).
  5. TWCC is available in certain complex scenarios where REMB is not available (more on this below)

Overview

This guide aims to

TWCC