Skip to content

Commit

Permalink
Don't allow cancelation of non-cancelable loads
Browse files Browse the repository at this point in the history
Issue: google#3441

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=175011804
  • Loading branch information
ojw28 committed Nov 13, 2017
1 parent e1b3fed commit 86c0198
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,6 +40,8 @@
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;
Expand Down Expand Up @@ -318,16 +322,20 @@ public int onLoadError(Chunk loadable, long elapsedRealtimeMs, long loadDuration
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;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ void getNextChunk(MediaChunk previous, long playbackPositionUs, long loadPositio
* @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);

Expand Down

0 comments on commit 86c0198

Please sign in to comment.