Skip to content

Commit

Permalink
Fix unnecessary media playlist requests when playing live streams
Browse files Browse the repository at this point in the history
Issue: #5059
PiperOrigin-RevId: 222803511
  • Loading branch information
ojw28 authored and andrewlewis committed Nov 26, 2018
1 parent 40c65db commit d6b6600
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### dev-v2 (not yet released) ###

* HLS: Fix issue causing unnecessary media playlist requests when playing live
streams ([#5059](https://github.com/google/ExoPlayer/issues/5059)).
* MP4: Support Opus and FLAC in the MP4 container, and in DASH
([#4883](https://github.com/google/ExoPlayer/issues/4883)).
* DASH: Fix detecting the end of live events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ public void getNextChunk(
// Retry when playlist is refreshed.
return;
}
HlsMediaPlaylist mediaPlaylist = playlistTracker.getPlaylistSnapshot(selectedUrl);
HlsMediaPlaylist mediaPlaylist =
playlistTracker.getPlaylistSnapshot(selectedUrl, /* isForPlayback= */ true);
independentSegments = mediaPlaylist.hasIndependentSegments;

updateLiveEdgeTimeUs(mediaPlaylist);
Expand All @@ -279,7 +280,7 @@ public void getNextChunk(
// behind the live window.
selectedVariantIndex = oldVariantIndex;
selectedUrl = variants[selectedVariantIndex];
mediaPlaylist = playlistTracker.getPlaylistSnapshot(selectedUrl);
mediaPlaylist = playlistTracker.getPlaylistSnapshot(selectedUrl, /* isForPlayback= */ true);
startOfPlaylistInPeriodUs =
mediaPlaylist.startTimeUs - playlistTracker.getInitialStartTimeUs();
chunkMediaSequence = previous.getNextChunkIndex();
Expand Down Expand Up @@ -435,7 +436,8 @@ public MediaChunkIterator[] createMediaChunkIterators(
chunkIterators[i] = MediaChunkIterator.EMPTY;
continue;
}
HlsMediaPlaylist playlist = playlistTracker.getPlaylistSnapshot(variantUrl);
HlsMediaPlaylist playlist =
playlistTracker.getPlaylistSnapshot(variantUrl, /* isForPlayback= */ false);
long startOfPlaylistInPeriodUs =
playlist.startTimeUs - playlistTracker.getInitialStartTimeUs();
boolean switchingVariant = variantIndex != oldVariantIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ public void removeListener(PlaylistEventListener listener) {
}

@Override
public HlsMediaPlaylist getPlaylistSnapshot(HlsUrl url) {
public HlsMediaPlaylist getPlaylistSnapshot(HlsUrl url, boolean isForPlayback) {
HlsMediaPlaylist snapshot = playlistBundles.get(url).getPlaylistSnapshot();
if (snapshot != null) {
if (snapshot != null && isForPlayback) {
maybeSetPrimaryUrl(url);
}
return snapshot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,13 @@ void start(
* HlsUrl}.
*
* @param url The {@link HlsUrl} corresponding to the requested media playlist.
* @param isForPlayback Whether the caller might use the snapshot to request media segments for
* playback. If true, the primary playlist may be updated to the one requested.
* @return The most recent snapshot of the playlist referenced by the provided {@link HlsUrl}. May
* be null if no snapshot has been loaded yet.
*/
@Nullable
HlsMediaPlaylist getPlaylistSnapshot(HlsUrl url);
HlsMediaPlaylist getPlaylistSnapshot(HlsUrl url, boolean isForPlayback);

/**
* Returns the start time of the first loaded primary playlist, or {@link C#TIME_UNSET} if no
Expand Down

0 comments on commit d6b6600

Please sign in to comment.