From 58a63c82aa0b59e86a656cf6644781a1c4690c82 Mon Sep 17 00:00:00 2001 From: tianyifeng Date: Fri, 13 Oct 2023 13:03:47 -0700 Subject: [PATCH] Calculate HLS live playlist refresh interval accurately Previously, we calculated the next playlist reload time by adding the target duration (or half of it, depending on whether there is a real update in the new playlist snapshot) from the last load completion time, which makes the reload interval as long as `targetDuration(or half of it) + lastLoadDuration`. While still complying to the standard that "the client MUST wait for at least the target duration before attempting to reload the Playlist file again", this could cause buffering when the playback position is close to the end of live window. This change is to calculate the reload interval accurately by not adding the term `lastLoadDuration`. Issue: androidx/media#663 #minor-release PiperOrigin-RevId: 573300009 --- RELEASENOTES.md | 3 +++ .../exoplayer/hls/playlist/DefaultHlsPlaylistTracker.java | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 6779da254b..d6c3925676 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -30,6 +30,9 @@ * Cronet Extension: * RTMP Extension: * HLS Extension: + * Refresh the HLS live playlist with an interval calculated from the last + load start time rather than the last load completed time + ([#663](https://github.com/androidx/media/issues/663)). * DASH Extension: * Smooth Streaming Extension: * RTSP Extension: diff --git a/libraries/exoplayer_hls/src/main/java/androidx/media3/exoplayer/hls/playlist/DefaultHlsPlaylistTracker.java b/libraries/exoplayer_hls/src/main/java/androidx/media3/exoplayer/hls/playlist/DefaultHlsPlaylistTracker.java index b8e9db0aa8..1cf9fc71e9 100644 --- a/libraries/exoplayer_hls/src/main/java/androidx/media3/exoplayer/hls/playlist/DefaultHlsPlaylistTracker.java +++ b/libraries/exoplayer_hls/src/main/java/androidx/media3/exoplayer/hls/playlist/DefaultHlsPlaylistTracker.java @@ -761,7 +761,8 @@ public final class DefaultHlsPlaylistTracker ? playlistSnapshot.targetDurationUs : (playlistSnapshot.targetDurationUs / 2); } - earliestNextLoadTimeMs = currentTimeMs + Util.usToMs(durationUntilNextLoadUs); + earliestNextLoadTimeMs = + currentTimeMs + Util.usToMs(durationUntilNextLoadUs) - loadEventInfo.loadDurationMs; // Schedule a load if this is the primary playlist or a playlist of a low-latency stream and // it doesn't have an end tag. Else the next load will be scheduled when refreshPlaylist is // called, or when this playlist becomes the primary.