UNPKG

1.95 kBMarkdownView Raw
1# Adaptive Switching Behavior
2The HLS tech tries to ensure the highest-quality viewing experience
3possible, given the available bandwidth and encodings. This doesn't
4always mean using the highest-bitrate rendition available-- if the player
5is 300px by 150px, it would be a big waste of bandwidth to download a 4k
6stream. By default, the player attempts to load the highest-bitrate
7variant that is less than the most recently detected segment bandwidth,
8with one condition: if there are multiple variants with dimensions greater
9than the current player size, it will only switch up one size greater
10than the current player size.
11
12If you're the visual type, the whole process is illustrated
13below. Whenever a new segment is downloaded, we calculate the download
14bitrate based on the size of the segment and the time it took to
15download:
16
17![New bitrate info is available](images/bitrate-switching-1.png)
18
19First, we filter out all the renditions that have a higher bitrate
20than the new measurement:
21
22![Bitrate filtering](images/bitrate-switching-2.png)
23
24Then we get rid of any renditions that are bigger than the current
25player dimensions:
26
27![Resolution filtering](images/bitrate-switching-3.png)
28
29We don't want to signficant quality drop just because your player is
30one pixel too small, so we add back in the next highest
31resolution. The highest bitrate rendition that remains is the one that
32gets used:
33
34![Final selection](images/bitrate-switching-4.png)
35
36If it turns out no rendition is acceptable based on the filtering
37described above, the first encoding listed in the master playlist will
38be used.
39
40If you'd like your player to use a different set of priorities, it's
41possible to completely replace the rendition selection logic. For
42instance, you could always choose the most appropriate rendition by
43resolution, even though this might mean more stalls during playback.
44See the documentation on `player.vhs.selectPlaylist` for more details.