Commit 5c0745ce by Oliver Woodman

Add some generally useful error propagation logic for HLS.

Issue #765
parent fb8f0113
...@@ -138,6 +138,7 @@ public class HlsChunkSource { ...@@ -138,6 +138,7 @@ public class HlsChunkSource {
private byte[] scratchSpace; private byte[] scratchSpace;
private boolean live; private boolean live;
private long durationUs; private long durationUs;
private IOException fatalError;
private Uri encryptionKeyUri; private Uri encryptionKeyUri;
private byte[] encryptionKey; private byte[] encryptionKey;
...@@ -224,6 +225,18 @@ public class HlsChunkSource { ...@@ -224,6 +225,18 @@ public class HlsChunkSource {
} }
/** /**
* If the source is currently having difficulty providing chunks, then this method throws the
* underlying error. Otherwise does nothing.
*
* @throws IOException The underlying error.
*/
public void maybeThrowError() throws IOException {
if (fatalError != null) {
throw fatalError;
}
}
/**
* Returns the next {@link Chunk} that should be loaded. * Returns the next {@link Chunk} that should be loaded.
* *
* @param previousTsChunk The previously loaded chunk that the next chunk should follow. * @param previousTsChunk The previously loaded chunk that the next chunk should follow.
...@@ -262,9 +275,15 @@ public class HlsChunkSource { ...@@ -262,9 +275,15 @@ public class HlsChunkSource {
chunkMediaSequence = switchingVariantSpliced chunkMediaSequence = switchingVariantSpliced
? previousTsChunk.chunkIndex : previousTsChunk.chunkIndex + 1; ? previousTsChunk.chunkIndex : previousTsChunk.chunkIndex + 1;
if (chunkMediaSequence < mediaPlaylist.mediaSequence) { if (chunkMediaSequence < mediaPlaylist.mediaSequence) {
// TODO: Decide what we want to do with: https://github.com/google/ExoPlayer/issues/765
// if (allowSkipAhead) {
// If the chunk is no longer in the playlist. Skip ahead and start again. // If the chunk is no longer in the playlist. Skip ahead and start again.
chunkMediaSequence = getLiveStartChunkMediaSequence(nextVariantIndex); chunkMediaSequence = getLiveStartChunkMediaSequence(nextVariantIndex);
liveDiscontinuity = true; liveDiscontinuity = true;
// } else {
// fatalError = new BehindLiveWindowException();
// return null;
// }
} }
} }
} else { } else {
...@@ -414,6 +433,10 @@ public class HlsChunkSource { ...@@ -414,6 +433,10 @@ public class HlsChunkSource {
return false; return false;
} }
public void reset() {
fatalError = null;
}
private int getNextVariantIndex(TsChunk previousTsChunk, long playbackPositionUs) { private int getNextVariantIndex(TsChunk previousTsChunk, long playbackPositionUs) {
clearStaleBlacklistedVariants(); clearStaleBlacklistedVariants();
long bitrateEstimate = bandwidthMeter.getBitrateEstimate(); long bitrateEstimate = bandwidthMeter.getBitrateEstimate();
......
...@@ -206,6 +206,7 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader, ...@@ -206,6 +206,7 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader,
enabledTrackCount--; enabledTrackCount--;
trackEnabledStates[track] = false; trackEnabledStates[track] = false;
if (enabledTrackCount == 0) { if (enabledTrackCount == 0) {
chunkSource.reset();
downstreamPositionUs = Long.MIN_VALUE; downstreamPositionUs = Long.MIN_VALUE;
if (loadControlRegistered) { if (loadControlRegistered) {
loadControl.unregister(this); loadControl.unregister(this);
...@@ -317,6 +318,8 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader, ...@@ -317,6 +318,8 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader,
public void maybeThrowError() throws IOException { public void maybeThrowError() throws IOException {
if (currentLoadableException != null && currentLoadableExceptionCount > minLoadableRetryCount) { if (currentLoadableException != null && currentLoadableExceptionCount > minLoadableRetryCount) {
throw currentLoadableException; throw currentLoadableException;
} else if (currentLoadable == null) {
chunkSource.maybeThrowError();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment