Throw more appropriate exceptions from extractors

PiperOrigin-RevId: 286581465
This commit is contained in:
olly 2019-12-20 16:18:38 +00:00 committed by Oliver Woodman
parent 7bea558b31
commit da121a0805
6 changed files with 13 additions and 9 deletions

View file

@ -174,7 +174,8 @@ public abstract class BinarySearchSeeker {
public int handlePendingSeek(ExtractorInput input, PositionHolder seekPositionHolder)
throws InterruptedException, IOException {
while (true) {
SeekOperationParams seekOperationParams = Assertions.checkNotNull(this.seekOperationParams);
SeekOperationParams seekOperationParams =
Assertions.checkStateNotNull(this.seekOperationParams);
long floorPosition = seekOperationParams.getFloorBytePosition();
long ceilingPosition = seekOperationParams.getCeilingBytePosition();
long searchPosition = seekOperationParams.getNextSearchBytePosition();

View file

@ -52,7 +52,7 @@ public final class FlacSeekTableSeekMap implements SeekMap {
@Override
public SeekPoints getSeekPoints(long timeUs) {
Assertions.checkNotNull(flacStreamMetadata.seekTable);
Assertions.checkStateNotNull(flacStreamMetadata.seekTable);
long[] pointSampleNumbers = flacStreamMetadata.seekTable.pointSampleNumbers;
long[] pointOffsets = flacStreamMetadata.seekTable.pointOffsets;

View file

@ -80,7 +80,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
@Override
public boolean read(ExtractorInput input) throws IOException, InterruptedException {
Assertions.checkNotNull(processor);
Assertions.checkStateNotNull(processor);
while (true) {
MasterElement head = masterElementsStack.peek();
if (head != null && input.getPosition() >= head.elementEndPosition) {

View file

@ -133,7 +133,7 @@ import com.google.android.exoplayer2.util.Util;
scaledPosition = 256;
} else {
int prevTableIndex = (int) percent;
long[] tableOfContents = Assertions.checkNotNull(this.tableOfContents);
long[] tableOfContents = Assertions.checkStateNotNull(this.tableOfContents);
double prevScaledPosition = tableOfContents[prevTableIndex];
double nextScaledPosition = prevTableIndex == 99 ? 256 : tableOfContents[prevTableIndex + 1];
// Linearly interpolate between the two scaled positions.
@ -153,7 +153,7 @@ import com.google.android.exoplayer2.util.Util;
if (!isSeekable() || positionOffset <= xingFrameSize) {
return 0L;
}
long[] tableOfContents = Assertions.checkNotNull(this.tableOfContents);
long[] tableOfContents = Assertions.checkStateNotNull(this.tableOfContents);
double scaledPosition = (positionOffset * 256d) / dataSize;
int prevTableIndex = Util.binarySearchFloor(tableOfContents, (long) scaledPosition, true, true);
long prevTimeUs = getTimeUsForTableIndex(prevTableIndex);

View file

@ -177,7 +177,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
}
if (!seekMapSet) {
SeekMap seekMap = Assertions.checkNotNull(oggSeeker.createSeekMap());
SeekMap seekMap = Assertions.checkStateNotNull(oggSeeker.createSeekMap());
extractorOutput.seekMap(seekMap);
seekMapSet = true;
}

View file

@ -20,7 +20,6 @@ import static com.google.android.exoplayer2.metadata.id3.Id3Decoder.ID3_HEADER_L
import static com.google.android.exoplayer2.metadata.id3.Id3Decoder.ID3_TAG;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.extractor.ConstantBitrateSeekMap;
@ -39,6 +38,8 @@ import java.io.IOException;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
/**
* Extracts data from AAC bit streams with ADTS framing.
@ -86,7 +87,7 @@ public final class AdtsExtractor implements Extractor {
private final ParsableByteArray scratch;
private final ParsableBitArray scratchBits;
@Nullable private ExtractorOutput extractorOutput;
@MonotonicNonNull private ExtractorOutput extractorOutput;
private long firstSampleTimestampUs;
private long firstFramePosition;
@ -180,6 +181,8 @@ public final class AdtsExtractor implements Extractor {
@Override
public int read(ExtractorInput input, PositionHolder seekPosition)
throws IOException, InterruptedException {
Assertions.checkStateNotNull(extractorOutput); // Asserts that init has been called.
long inputLength = input.getLength();
boolean canUseConstantBitrateSeeking =
(flags & FLAG_ENABLE_CONSTANT_BITRATE_SEEKING) != 0 && inputLength != C.LENGTH_UNSET;
@ -230,6 +233,7 @@ public final class AdtsExtractor implements Extractor {
return firstFramePosition;
}
@RequiresNonNull("extractorOutput")
private void maybeOutputSeekMap(
long inputLength, boolean canUseConstantBitrateSeeking, boolean readEndOfStream) {
if (hasOutputSeekMap) {
@ -244,7 +248,6 @@ public final class AdtsExtractor implements Extractor {
return;
}
ExtractorOutput extractorOutput = Assertions.checkNotNull(this.extractorOutput);
if (useConstantBitrateSeeking && reader.getSampleDurationUs() != C.TIME_UNSET) {
extractorOutput.seekMap(getConstantBitrateSeekMap(inputLength));
} else {