mirror of
https://github.com/samsonjs/media.git
synced 2026-04-16 13:05:46 +00:00
Throw more appropriate exceptions from extractors
PiperOrigin-RevId: 286581465
This commit is contained in:
parent
7bea558b31
commit
da121a0805
6 changed files with 13 additions and 9 deletions
|
|
@ -174,7 +174,8 @@ public abstract class BinarySearchSeeker {
|
||||||
public int handlePendingSeek(ExtractorInput input, PositionHolder seekPositionHolder)
|
public int handlePendingSeek(ExtractorInput input, PositionHolder seekPositionHolder)
|
||||||
throws InterruptedException, IOException {
|
throws InterruptedException, IOException {
|
||||||
while (true) {
|
while (true) {
|
||||||
SeekOperationParams seekOperationParams = Assertions.checkNotNull(this.seekOperationParams);
|
SeekOperationParams seekOperationParams =
|
||||||
|
Assertions.checkStateNotNull(this.seekOperationParams);
|
||||||
long floorPosition = seekOperationParams.getFloorBytePosition();
|
long floorPosition = seekOperationParams.getFloorBytePosition();
|
||||||
long ceilingPosition = seekOperationParams.getCeilingBytePosition();
|
long ceilingPosition = seekOperationParams.getCeilingBytePosition();
|
||||||
long searchPosition = seekOperationParams.getNextSearchBytePosition();
|
long searchPosition = seekOperationParams.getNextSearchBytePosition();
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ public final class FlacSeekTableSeekMap implements SeekMap {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SeekPoints getSeekPoints(long timeUs) {
|
public SeekPoints getSeekPoints(long timeUs) {
|
||||||
Assertions.checkNotNull(flacStreamMetadata.seekTable);
|
Assertions.checkStateNotNull(flacStreamMetadata.seekTable);
|
||||||
long[] pointSampleNumbers = flacStreamMetadata.seekTable.pointSampleNumbers;
|
long[] pointSampleNumbers = flacStreamMetadata.seekTable.pointSampleNumbers;
|
||||||
long[] pointOffsets = flacStreamMetadata.seekTable.pointOffsets;
|
long[] pointOffsets = flacStreamMetadata.seekTable.pointOffsets;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean read(ExtractorInput input) throws IOException, InterruptedException {
|
public boolean read(ExtractorInput input) throws IOException, InterruptedException {
|
||||||
Assertions.checkNotNull(processor);
|
Assertions.checkStateNotNull(processor);
|
||||||
while (true) {
|
while (true) {
|
||||||
MasterElement head = masterElementsStack.peek();
|
MasterElement head = masterElementsStack.peek();
|
||||||
if (head != null && input.getPosition() >= head.elementEndPosition) {
|
if (head != null && input.getPosition() >= head.elementEndPosition) {
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ import com.google.android.exoplayer2.util.Util;
|
||||||
scaledPosition = 256;
|
scaledPosition = 256;
|
||||||
} else {
|
} else {
|
||||||
int prevTableIndex = (int) percent;
|
int prevTableIndex = (int) percent;
|
||||||
long[] tableOfContents = Assertions.checkNotNull(this.tableOfContents);
|
long[] tableOfContents = Assertions.checkStateNotNull(this.tableOfContents);
|
||||||
double prevScaledPosition = tableOfContents[prevTableIndex];
|
double prevScaledPosition = tableOfContents[prevTableIndex];
|
||||||
double nextScaledPosition = prevTableIndex == 99 ? 256 : tableOfContents[prevTableIndex + 1];
|
double nextScaledPosition = prevTableIndex == 99 ? 256 : tableOfContents[prevTableIndex + 1];
|
||||||
// Linearly interpolate between the two scaled positions.
|
// Linearly interpolate between the two scaled positions.
|
||||||
|
|
@ -153,7 +153,7 @@ import com.google.android.exoplayer2.util.Util;
|
||||||
if (!isSeekable() || positionOffset <= xingFrameSize) {
|
if (!isSeekable() || positionOffset <= xingFrameSize) {
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
long[] tableOfContents = Assertions.checkNotNull(this.tableOfContents);
|
long[] tableOfContents = Assertions.checkStateNotNull(this.tableOfContents);
|
||||||
double scaledPosition = (positionOffset * 256d) / dataSize;
|
double scaledPosition = (positionOffset * 256d) / dataSize;
|
||||||
int prevTableIndex = Util.binarySearchFloor(tableOfContents, (long) scaledPosition, true, true);
|
int prevTableIndex = Util.binarySearchFloor(tableOfContents, (long) scaledPosition, true, true);
|
||||||
long prevTimeUs = getTimeUsForTableIndex(prevTableIndex);
|
long prevTimeUs = getTimeUsForTableIndex(prevTableIndex);
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!seekMapSet) {
|
if (!seekMapSet) {
|
||||||
SeekMap seekMap = Assertions.checkNotNull(oggSeeker.createSeekMap());
|
SeekMap seekMap = Assertions.checkStateNotNull(oggSeeker.createSeekMap());
|
||||||
extractorOutput.seekMap(seekMap);
|
extractorOutput.seekMap(seekMap);
|
||||||
seekMapSet = true;
|
seekMapSet = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 static com.google.android.exoplayer2.metadata.id3.Id3Decoder.ID3_TAG;
|
||||||
|
|
||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.ParserException;
|
import com.google.android.exoplayer2.ParserException;
|
||||||
import com.google.android.exoplayer2.extractor.ConstantBitrateSeekMap;
|
import com.google.android.exoplayer2.extractor.ConstantBitrateSeekMap;
|
||||||
|
|
@ -39,6 +38,8 @@ import java.io.IOException;
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
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.
|
* 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 ParsableByteArray scratch;
|
||||||
private final ParsableBitArray scratchBits;
|
private final ParsableBitArray scratchBits;
|
||||||
|
|
||||||
@Nullable private ExtractorOutput extractorOutput;
|
@MonotonicNonNull private ExtractorOutput extractorOutput;
|
||||||
|
|
||||||
private long firstSampleTimestampUs;
|
private long firstSampleTimestampUs;
|
||||||
private long firstFramePosition;
|
private long firstFramePosition;
|
||||||
|
|
@ -180,6 +181,8 @@ public final class AdtsExtractor implements Extractor {
|
||||||
@Override
|
@Override
|
||||||
public int read(ExtractorInput input, PositionHolder seekPosition)
|
public int read(ExtractorInput input, PositionHolder seekPosition)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
|
Assertions.checkStateNotNull(extractorOutput); // Asserts that init has been called.
|
||||||
|
|
||||||
long inputLength = input.getLength();
|
long inputLength = input.getLength();
|
||||||
boolean canUseConstantBitrateSeeking =
|
boolean canUseConstantBitrateSeeking =
|
||||||
(flags & FLAG_ENABLE_CONSTANT_BITRATE_SEEKING) != 0 && inputLength != C.LENGTH_UNSET;
|
(flags & FLAG_ENABLE_CONSTANT_BITRATE_SEEKING) != 0 && inputLength != C.LENGTH_UNSET;
|
||||||
|
|
@ -230,6 +233,7 @@ public final class AdtsExtractor implements Extractor {
|
||||||
return firstFramePosition;
|
return firstFramePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresNonNull("extractorOutput")
|
||||||
private void maybeOutputSeekMap(
|
private void maybeOutputSeekMap(
|
||||||
long inputLength, boolean canUseConstantBitrateSeeking, boolean readEndOfStream) {
|
long inputLength, boolean canUseConstantBitrateSeeking, boolean readEndOfStream) {
|
||||||
if (hasOutputSeekMap) {
|
if (hasOutputSeekMap) {
|
||||||
|
|
@ -244,7 +248,6 @@ public final class AdtsExtractor implements Extractor {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExtractorOutput extractorOutput = Assertions.checkNotNull(this.extractorOutput);
|
|
||||||
if (useConstantBitrateSeeking && reader.getSampleDurationUs() != C.TIME_UNSET) {
|
if (useConstantBitrateSeeking && reader.getSampleDurationUs() != C.TIME_UNSET) {
|
||||||
extractorOutput.seekMap(getConstantBitrateSeekMap(inputLength));
|
extractorOutput.seekMap(getConstantBitrateSeekMap(inputLength));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue