mirror of
https://github.com/samsonjs/media.git
synced 2026-04-10 12:05:47 +00:00
Add configurable retry count to ChunkSampleSource
This commit is contained in:
parent
eccf8d7924
commit
1653e81687
1 changed files with 19 additions and 6 deletions
|
|
@ -140,6 +140,8 @@ public class ChunkSampleSource implements SampleSource, Loader.Callback {
|
|||
|
||||
private static final int NO_RESET_PENDING = -1;
|
||||
|
||||
private static final int DEFAULT_MIN_LOADABLE_RETRY_COUNT = 1;
|
||||
|
||||
private final int eventSourceId;
|
||||
private final LoadControl loadControl;
|
||||
private final ChunkSource chunkSource;
|
||||
|
|
@ -150,6 +152,7 @@ public class ChunkSampleSource implements SampleSource, Loader.Callback {
|
|||
private final boolean frameAccurateSeeking;
|
||||
private final Handler eventHandler;
|
||||
private final EventListener eventListener;
|
||||
private final int minLoadableRetryCount;
|
||||
|
||||
private int state;
|
||||
private long downstreamPositionUs;
|
||||
|
|
@ -175,6 +178,13 @@ public class ChunkSampleSource implements SampleSource, Loader.Callback {
|
|||
public ChunkSampleSource(ChunkSource chunkSource, LoadControl loadControl,
|
||||
int bufferSizeContribution, boolean frameAccurateSeeking, Handler eventHandler,
|
||||
EventListener eventListener, int eventSourceId) {
|
||||
this(chunkSource, loadControl, bufferSizeContribution, frameAccurateSeeking, eventHandler,
|
||||
eventListener, eventSourceId, DEFAULT_MIN_LOADABLE_RETRY_COUNT);
|
||||
}
|
||||
|
||||
public ChunkSampleSource(ChunkSource chunkSource, LoadControl loadControl,
|
||||
int bufferSizeContribution, boolean frameAccurateSeeking, Handler eventHandler,
|
||||
EventListener eventListener, int eventSourceId, int minLoadableRetryCount) {
|
||||
this.chunkSource = chunkSource;
|
||||
this.loadControl = loadControl;
|
||||
this.bufferSizeContribution = bufferSizeContribution;
|
||||
|
|
@ -182,6 +192,7 @@ public class ChunkSampleSource implements SampleSource, Loader.Callback {
|
|||
this.eventHandler = eventHandler;
|
||||
this.eventListener = eventListener;
|
||||
this.eventSourceId = eventSourceId;
|
||||
this.minLoadableRetryCount = minLoadableRetryCount;
|
||||
currentLoadableHolder = new ChunkOperationHolder();
|
||||
mediaChunks = new LinkedList<MediaChunk>();
|
||||
readOnlyMediaChunks = Collections.unmodifiableList(mediaChunks);
|
||||
|
|
@ -287,9 +298,7 @@ public class ChunkSampleSource implements SampleSource, Loader.Callback {
|
|||
|
||||
downstreamPositionUs = positionUs;
|
||||
if (isPendingReset()) {
|
||||
if (currentLoadableException != null) {
|
||||
throw currentLoadableException;
|
||||
}
|
||||
maybeThrowLoadableException();
|
||||
IOException chunkSourceException = chunkSource.getError();
|
||||
if (chunkSourceException != null) {
|
||||
throw chunkSourceException;
|
||||
|
|
@ -342,9 +351,7 @@ public class ChunkSampleSource implements SampleSource, Loader.Callback {
|
|||
onSampleRead(mediaChunk, sampleHolder);
|
||||
return SAMPLE_READ;
|
||||
} else {
|
||||
if (currentLoadableException != null) {
|
||||
throw currentLoadableException;
|
||||
}
|
||||
maybeThrowLoadableException();
|
||||
return NOTHING_READ;
|
||||
}
|
||||
}
|
||||
|
|
@ -369,6 +376,12 @@ public class ChunkSampleSource implements SampleSource, Loader.Callback {
|
|||
}
|
||||
}
|
||||
|
||||
private void maybeThrowLoadableException() throws IOException {
|
||||
if (currentLoadableException != null && currentLoadableExceptionCount > minLoadableRetryCount) {
|
||||
throw currentLoadableException;
|
||||
}
|
||||
}
|
||||
|
||||
private MediaChunk getMediaChunk(long positionUs) {
|
||||
Iterator<MediaChunk> mediaChunkIterator = mediaChunks.iterator();
|
||||
while (mediaChunkIterator.hasNext()) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue