ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

HLS: Avoid loading first #EXT-X-STREAM-INF URL at start of playback

Open sruditsky opened this issue 4 years ago • 2 comments

ExoPlayer is given an HLS master playlist and it downloads it. The next step seems to always be to download the very first media playlist in this master playlist. I am referring to the code in DefaultHlsPlaylistTracker.onLoadCompleted() starting with:

  primaryMediaPlaylistUrl = masterPlaylist.variants.get(0).url;

Code seems to await for this download to complete and only then starts downloading the "real" media playlists corresponding to the variant selected by the ABR algorithm. It does not look like this initial playlist is used (at least it is not used for downloading media segments).

I checked with RFC-8216 and it looks like the only special meaning which this first #EXT-X-STREAM-INF URL has is being a default for systems which do not support multiple #EXT-X-STREAM-INF tags, which is not the case with ExoPlayer.

While in general downloading and discarding this playlist does not change the player behavior, when media playlist is long this additional download and processing may be quite "costly".

So the question is why to use variants.get(0) (and not start directly from the playlist selected by the ABR algorithm)?

sruditsky avatar Apr 19 '21 02:04 sruditsky

This is an implementation detail where a component of the player is trying to establish the media timeline, but doesn't have the track selection yet. Hence it picks the first media playlist (arbitrarily) to do so. This is a known inefficiency with ExoPlayer's HLS implementation.

It would be better if the implementation could wait for the track selection, and then use the media playlist that it's actually going to use to start playback. This does come at the cost of additional complexity, however. Marking as an enhancement to track implementing this optimization.

ojw28 avatar Apr 19 '21 07:04 ojw28

@tianyif any idea when will this enhancement get prioritised? Also, Possible to share some high level details on how are you planning to do this?

mayurk2 avatar May 21 '24 08:05 mayurk2