Merge "Remove InterruptedException from MediaParser" into rvc-dev

This commit is contained in:
Santiago Seifert
2020-03-05 10:58:38 +00:00
committed by Android (Google) Code Review
2 changed files with 30 additions and 27 deletions

View File

@@ -54,6 +54,7 @@ import com.google.android.exoplayer2.video.ColorInfo;
import java.io.EOFException;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.HashMap;
@@ -119,7 +120,7 @@ import java.util.Map;
*
* @Override
* public void onSampleData(int trackIndex, @NonNull InputReader inputReader)
* throws IOException, InterruptedException {
* throws IOException {
* int numberOfBytesToRead = (int) inputReader.getLength();
* if (videoTrackIndex != trackIndex) {
* // Discard contents.
@@ -310,8 +311,7 @@ public final class MediaParser {
* of the input has been reached.
* @throws java.io.IOException If an error occurs reading from the source.
*/
int read(@NonNull byte[] buffer, int offset, int readLength)
throws IOException, InterruptedException;
int read(@NonNull byte[] buffer, int offset, int readLength) throws IOException;
/** Returns the current read position (byte offset) in the stream. */
long getPosition();
@@ -373,11 +373,8 @@ public final class MediaParser {
* @param trackIndex The index of the track to which the sample data corresponds.
* @param inputReader The {@link InputReader} from which to read the data.
* @throws IOException If an exception occurs while reading from {@code inputReader}.
* @throws InterruptedException If an interruption occurs while reading from {@code
* inputReader}.
*/
void onSampleData(int trackIndex, @NonNull InputReader inputReader)
throws IOException, InterruptedException;
void onSampleData(int trackIndex, @NonNull InputReader inputReader) throws IOException;
/**
* Called once all the data of a sample has been passed to {@link #onSampleData}.
@@ -717,8 +714,7 @@ public final class MediaParser {
* @throws UnrecognizedInputFormatException If the format cannot be recognized by any of the
* underlying parser implementations.
*/
public boolean advance(@NonNull SeekableInputReader seekableInputReader)
throws IOException, InterruptedException {
public boolean advance(@NonNull SeekableInputReader seekableInputReader) throws IOException {
if (mExtractorInput == null) {
// TODO: For efficiency, the same implementation should be used, by providing a
// clearBuffers() method, or similar.
@@ -748,8 +744,10 @@ public final class MediaParser {
}
} catch (EOFException e) {
// Do nothing.
} catch (IOException | InterruptedException e) {
throw new IllegalStateException(e);
} catch (InterruptedException e) {
// TODO: Remove this exception replacement once we update the ExoPlayer
// version.
throw new InterruptedIOException();
} finally {
mExtractorInput.resetPeekPosition();
}
@@ -767,7 +765,13 @@ public final class MediaParser {
}
mPositionHolder.position = seekableInputReader.getPosition();
int result = mExtractor.read(mExtractorInput, mPositionHolder);
int result = 0;
try {
result = mExtractor.read(mExtractorInput, mPositionHolder);
} catch (InterruptedException e) {
// TODO: Remove this exception replacement once we update the ExoPlayer version.
throw new InterruptedIOException();
}
if (result == Extractor.RESULT_END_OF_INPUT) {
return false;
}
@@ -853,13 +857,7 @@ public final class MediaParser {
@Override
public int read(byte[] buffer, int offset, int readLength) throws IOException {
// TODO: Reevaluate interruption in Input.
try {
return mInputReader.read(buffer, offset, readLength);
} catch (InterruptedException e) {
// TODO: Remove.
throw new RuntimeException();
}
return mInputReader.read(buffer, offset, readLength);
}
@Override
@@ -926,7 +924,7 @@ public final class MediaParser {
@Override
public int sampleData(ExtractorInput input, int length, boolean allowEndOfInput)
throws IOException, InterruptedException {
throws IOException {
mScratchExtractorInputAdapter.setExtractorInput(input, length);
long positionBeforeReading = mScratchExtractorInputAdapter.getPosition();
mOutputConsumer.onSampleData(mTrackIndex, mScratchExtractorInputAdapter);
@@ -938,7 +936,7 @@ public final class MediaParser {
mScratchParsableByteArrayAdapter.resetWithByteArray(data, length);
try {
mOutputConsumer.onSampleData(mTrackIndex, mScratchParsableByteArrayAdapter);
} catch (IOException | InterruptedException e) {
} catch (IOException e) {
// Unexpected.
throw new RuntimeException(e);
}
@@ -967,9 +965,14 @@ public final class MediaParser {
// Input implementation.
@Override
public int read(byte[] buffer, int offset, int readLength)
throws IOException, InterruptedException {
int readBytes = mExtractorInput.read(buffer, offset, readLength);
public int read(byte[] buffer, int offset, int readLength) throws IOException {
int readBytes = 0;
try {
readBytes = mExtractorInput.read(buffer, offset, readLength);
} catch (InterruptedException e) {
// TODO: Remove this exception replacement once we update the ExoPlayer version.
throw new InterruptedIOException();
}
mCurrentPosition += readBytes;
return readBytes;
}

View File

@@ -26403,7 +26403,7 @@ package android.media {
}
public final class MediaParser {
method public boolean advance(@NonNull android.media.MediaParser.SeekableInputReader) throws java.io.IOException, java.lang.InterruptedException;
method public boolean advance(@NonNull android.media.MediaParser.SeekableInputReader) throws java.io.IOException;
method @NonNull public static android.media.MediaParser create(@NonNull android.media.MediaParser.OutputConsumer, @NonNull java.lang.String...);
method @NonNull public static android.media.MediaParser createByName(@NonNull String, @NonNull android.media.MediaParser.OutputConsumer);
method @Nullable public String getParserName();
@@ -26435,12 +26435,12 @@ package android.media {
public static interface MediaParser.InputReader {
method public long getLength();
method public long getPosition();
method public int read(@NonNull byte[], int, int) throws java.io.IOException, java.lang.InterruptedException;
method public int read(@NonNull byte[], int, int) throws java.io.IOException;
}
public static interface MediaParser.OutputConsumer {
method public void onSampleCompleted(int, long, int, int, int, @Nullable android.media.MediaCodec.CryptoInfo);
method public void onSampleData(int, @NonNull android.media.MediaParser.InputReader) throws java.io.IOException, java.lang.InterruptedException;
method public void onSampleData(int, @NonNull android.media.MediaParser.InputReader) throws java.io.IOException;
method public void onSeekMap(@NonNull android.media.MediaParser.SeekMap);
method public void onTrackData(int, @NonNull android.media.MediaParser.TrackData);
method public void onTracksFound(int);