Skip to content

Commit

Permalink
Propagate playlist loading error if it prevents playback
Browse files Browse the repository at this point in the history
This imitates DashMediaSource's behavior.

Issue:#2623

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=155485738
  • Loading branch information
AquilesCanta authored and ojw28 committed May 11, 2017
1 parent 51132f5 commit 70b6285
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public void clear() {
private boolean isTimestampMaster;
private byte[] scratchSpace;
private IOException fatalError;
private HlsUrl expectedPlaylistUrl;

private Uri encryptionKeyUri;
private byte[] encryptionKey;
Expand Down Expand Up @@ -143,6 +144,9 @@ public void maybeThrowError() throws IOException {
if (fatalError != null) {
throw fatalError;
}
if (expectedPlaylistUrl != null) {
playlistTracker.maybeThrowPlaylistRefreshError(expectedPlaylistUrl);
}
}

/**
Expand Down Expand Up @@ -195,6 +199,7 @@ public void setIsTimestampMaster(boolean isTimestampMaster) {
public void getNextChunk(HlsMediaChunk previous, long playbackPositionUs, HlsChunkHolder out) {
int oldVariantIndex = previous == null ? C.INDEX_UNSET
: trackGroup.indexOf(previous.trackFormat);
expectedPlaylistUrl = null;
// Use start time of the previous chunk rather than its end time because switching format will
// require downloading overlapping segments.
long bufferedDurationUs = previous == null ? 0
Expand All @@ -208,6 +213,7 @@ public void getNextChunk(HlsMediaChunk previous, long playbackPositionUs, HlsChu
HlsUrl selectedUrl = variants[selectedVariantIndex];
if (!playlistTracker.isSnapshotValid(selectedUrl)) {
out.playlist = selectedUrl;
expectedPlaylistUrl = selectedUrl;
// Retry when playlist is refreshed.
return;
}
Expand Down Expand Up @@ -247,6 +253,7 @@ public void getNextChunk(HlsMediaChunk previous, long playbackPositionUs, HlsChu
out.endOfStream = true;
} else /* Live */ {
out.playlist = selectedUrl;
expectedPlaylistUrl = selectedUrl;
}
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener l

@Override
public void maybeThrowSourceInfoRefreshError() throws IOException {
playlistTracker.maybeThrowPlaylistRefreshError();
playlistTracker.maybeThrowPrimaryPlaylistRefreshError();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,29 @@ public void release() {
}

/**
* If the tracker is having trouble refreshing the primary playlist or loading an irreplaceable
* playlist, this method throws the underlying error. Otherwise, does nothing.
* If the tracker is having trouble refreshing the master playlist or the primary playlist, this
* method throws the underlying error. Otherwise, does nothing.
*
* @throws IOException The underlying error.
*/
public void maybeThrowPlaylistRefreshError() throws IOException {
public void maybeThrowPrimaryPlaylistRefreshError() throws IOException {
initialPlaylistLoader.maybeThrowError();
if (primaryHlsUrl != null) {
playlistBundles.get(primaryHlsUrl).mediaPlaylistLoader.maybeThrowError();
maybeThrowPlaylistRefreshError(primaryHlsUrl);
}
}

/**
* If the playlist is having trouble loading the playlist referenced by the given {@link HlsUrl},
* this method throws the underlying error.
*
* @param url The {@link HlsUrl}.
* @throws IOException The underyling error.
*/
public void maybeThrowPlaylistRefreshError(HlsUrl url) throws IOException {
playlistBundles.get(url).mediaPlaylistLoader.maybeThrowError();
}

/**
* Triggers a playlist refresh and whitelists it.
*
Expand Down

0 comments on commit 70b6285

Please sign in to comment.