Sub topic 11
How Adaptive Bitrate Playback Works
This chapter assumes you know HTTP range and caching basics, and that you have read the earlier chapters on bitrate ladders and HLS/DASH packaging. Here we look at what the player does: how it picks a rendition for each segment and what goes wrong when it picks badly.
The player is in charge
In HLS and DASH the server is a plain file server. It does not decide quality. The player downloads the playlist, then requests segments one at a time over HTTP. Before each request it chooses which rendition to fetch. Because every rendition has keyframe-aligned segments of the same duration, the player can switch at any segment boundary without a visible glitch.
Throughput-based selection
The simplest rule measures how fast the last segment arrived and picks the highest rendition that fits. Throughput is segment size in bits divided by download time. A safety factor leaves headroom, because the measurement is noisy.
def pick_rendition(renditions, throughput_bps, safety=0.8):
"""renditions: list of dicts sorted by ascending 'bandwidth' (bits per second)."""
usable = throughput_bps * safety
best = renditions[0]
for r in renditions:
if r["bandwidth"] <= usable:
best = r
return best
ladder = [
{"name": "360p", "bandwidth": 800_000},
{"name": "720p", "bandwidth": 3_000_000},
{"name": "1080p", "bandwidth": 6_000_000},
]
print(pick_rendition(ladder, 4_500_000)["name"]) # 720pWith 4.5 Mbps measured, the usable budget is 3.6 Mbps. The 720p rendition (3 Mbps) fits and 1080p (6 Mbps) does not. If nothing fits, the function falls back to the lowest rendition, because a low-quality picture is better than a stall.
Buffer-based selection
Throughput estimates swing widely on mobile and Wi-Fi networks. Many players therefore also look at the buffer, which is the number of seconds of video downloaded but not yet played.
- A buffer below a low threshold (for example 5 seconds) means a stall is close. Switch down.
- A buffer above a high threshold (for example 30 seconds) means there is slack. Switch up.
- Between the thresholds, hold the current rendition.
Production players combine both signals. Throughput drives the decision when the buffer is small, such as at startup. The buffer takes over once it is healthy.
Startup and switching behavior
At startup there is no measurement. Players usually begin with a low or mid rendition so the first segment arrives quickly, then step up. This trades a few seconds of lower quality for a faster time to first frame.
Switching up should be cautious and switching down should be fast. If the player switches up on one lucky measurement, it risks a stall. Common safeguards are:
- Require several good measurements before switching up.
- Allow at most one step up at a time.
- Switch down immediately when the buffer drains.
- Enforce a minimum time between switches, to avoid oscillation.
Common errors
| Symptom | Likely cause |
|---|---|
| Repeated stalls on a stable connection | Safety factor too low, or the ladder top is too close to real throughput |
| Quality flips every few seconds | No hysteresis or minimum switch interval |
| Stuck on the lowest rendition | Throughput measured on tiny segments or cache misses that inflate download time |
| Visible glitch at switches | Keyframes not aligned across renditions |
| Slow start | Initial rendition too high, or segments too long |
What this means for the design
The CDN affects what the player measures. A cache hit gives high throughput and a cache miss to the origin gives low throughput. Warm popular segments in the CDN so the player's estimates reflect the network and not your origin.
Exercise
A player measures 2.0 Mbps throughput with a safety factor of 0.8, using the ladder 360p at 0.8 Mbps, 720p at 3 Mbps, and 1080p at 6 Mbps. Which rendition does pick_rendition choose, and why might a buffer-based rule override it?
Show answer
Usable bandwidth is 2.0 × 0.8 = 1.6 Mbps. Only 360p (0.8 Mbps) fits, so it chooses 360p. A buffer-based rule could override this: if the buffer is very full (for example above 30 seconds), the player has slack to try 720p, because a single slow measurement will not cause a stall soon.