Don't allow cancelation of non-cancelable loads

Issue: #3441

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=175011804
This commit is contained in:
olly 2017-11-08 08:45:17 -08:00 committed by Oliver Woodman
parent 367bb64ba0
commit ed2e4dd91e
2 changed files with 20 additions and 11 deletions

View File

@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.source.chunk;
import android.util.Log;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.FormatHolder;
@ -38,6 +40,8 @@ import java.util.List;
public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, SequenceableLoader,
Loader.Callback<Chunk>, Loader.ReleaseCallback {
private static final String TAG = "ChunkSampleStream";
private final int primaryTrackType;
private final int[] embeddedTrackTypes;
private final boolean[] embeddedTracksSelected;
@ -318,16 +322,20 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
boolean cancelable = bytesLoaded == 0 || !isMediaChunk || !haveReadFromLastMediaChunk();
boolean canceled = false;
if (chunkSource.onChunkLoadError(loadable, cancelable, error)) {
canceled = true;
if (isMediaChunk) {
BaseMediaChunk removed = mediaChunks.removeLast();
Assertions.checkState(removed == loadable);
primarySampleQueue.discardUpstreamSamples(removed.getFirstSampleIndex(0));
for (int i = 0; i < embeddedSampleQueues.length; i++) {
embeddedSampleQueues[i].discardUpstreamSamples(removed.getFirstSampleIndex(i + 1));
}
if (mediaChunks.isEmpty()) {
pendingResetPositionUs = lastSeekPositionUs;
if (!cancelable) {
Log.w(TAG, "Ignoring attempt to cancel non-cancelable load.");
} else {
canceled = true;
if (isMediaChunk) {
BaseMediaChunk removed = mediaChunks.removeLast();
Assertions.checkState(removed == loadable);
primarySampleQueue.discardUpstreamSamples(removed.getFirstSampleIndex(0));
for (int i = 0; i < embeddedSampleQueues.length; i++) {
embeddedSampleQueues[i].discardUpstreamSamples(removed.getFirstSampleIndex(i + 1));
}
if (mediaChunks.isEmpty()) {
pendingResetPositionUs = lastSeekPositionUs;
}
}
}
}

View File

@ -85,7 +85,8 @@ public interface ChunkSource {
* @param chunk The chunk whose load encountered the error.
* @param cancelable Whether the load can be canceled.
* @param e The error.
* @return Whether the load should be canceled.
* @return Whether the load should be canceled. Should always be false if {@code cancelable} is
* false.
*/
boolean onChunkLoadError(Chunk chunk, boolean cancelable, Exception e);