From cec658d573966fb21cb8cf57e393cebefdde0c8c Mon Sep 17 00:00:00 2001 From: eguven Date: Tue, 7 Jun 2016 07:30:34 -0700 Subject: [PATCH] ExtractorInput.setRetryPosition(): Called when reading fails and the required retry position is different from the last position. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=124242428 --- .../exoplayer/extractor/DefaultExtractorInput.java | 8 ++++++++ .../android/exoplayer/extractor/ExtractorInput.java | 11 +++++++++++ .../exoplayer/testutil/FakeExtractorInput.java | 7 +++++++ 3 files changed, 26 insertions(+) diff --git a/library/src/main/java/com/google/android/exoplayer/extractor/DefaultExtractorInput.java b/library/src/main/java/com/google/android/exoplayer/extractor/DefaultExtractorInput.java index 07264cb866..1e4937ba88 100644 --- a/library/src/main/java/com/google/android/exoplayer/extractor/DefaultExtractorInput.java +++ b/library/src/main/java/com/google/android/exoplayer/extractor/DefaultExtractorInput.java @@ -17,6 +17,7 @@ package com.google.android.exoplayer.extractor; import com.google.android.exoplayer.C; import com.google.android.exoplayer.upstream.DataSource; +import com.google.android.exoplayer.util.Assertions; import java.io.EOFException; import java.io.IOException; @@ -162,6 +163,13 @@ public final class DefaultExtractorInput implements ExtractorInput { return streamLength; } + @Override + public void setRetryPosition(long position, E e) throws E { + Assertions.checkArgument(position >= 0); + this.position = position; + throw e; + } + /** * Ensures {@code peekBuffer} is large enough to store at least {@code length} bytes from the * current peek position. diff --git a/library/src/main/java/com/google/android/exoplayer/extractor/ExtractorInput.java b/library/src/main/java/com/google/android/exoplayer/extractor/ExtractorInput.java index afe79ec806..e61e8ea03c 100644 --- a/library/src/main/java/com/google/android/exoplayer/extractor/ExtractorInput.java +++ b/library/src/main/java/com/google/android/exoplayer/extractor/ExtractorInput.java @@ -223,4 +223,15 @@ public interface ExtractorInput { */ long getLength(); + /** + * Called when reading fails and the required retry position is different from the last position. + * After setting the retry position it throws the given {@link Throwable}. + * + * @param Type of {@link Throwable} to be thrown. + * @param position The required retry position. + * @param e {@link Throwable} to be thrown. + * @throws E The given {@link Throwable} object. + */ + void setRetryPosition(long position, E e) throws E; + } diff --git a/testutils/src/main/java/com/google/android/exoplayer/testutil/FakeExtractorInput.java b/testutils/src/main/java/com/google/android/exoplayer/testutil/FakeExtractorInput.java index 1640130d18..b6f0544c19 100644 --- a/testutils/src/main/java/com/google/android/exoplayer/testutil/FakeExtractorInput.java +++ b/testutils/src/main/java/com/google/android/exoplayer/testutil/FakeExtractorInput.java @@ -191,6 +191,13 @@ public final class FakeExtractorInput implements ExtractorInput { return simulateUnknownLength ? C.LENGTH_UNBOUNDED : data.length; } + @Override + public void setRetryPosition(long position, E e) throws E { + Assert.assertTrue(position >= 0); + readPosition = (int) position; + throw e; + } + private boolean checkXFully(boolean allowEndOfInput, int position, int length, SparseBooleanArray failedPositions) throws IOException { if (simulateIOErrors && !failedPositions.get(position)) {