DataReader: replace InterruptedException with InterruptedIOException
PiperOrigin-RevId: 299092243
This commit is contained in:
parent
fbf865726c
commit
47b62e8c02
@ -49,8 +49,7 @@ public final class FlacExtractorSeekTest {
|
||||
.createDataSource();
|
||||
|
||||
@Test
|
||||
public void flacExtractorReads_seekTable_returnSeekableSeekMap()
|
||||
throws IOException, InterruptedException {
|
||||
public void flacExtractorReads_seekTable_returnSeekableSeekMap() throws IOException {
|
||||
Uri fileUri = TestUtil.buildAssetUri(TEST_FILE_SEEK_TABLE);
|
||||
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -61,7 +60,7 @@ public final class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_seekTable_handlesSeekToZero() throws IOException, InterruptedException {
|
||||
public void seeking_seekTable_handlesSeekToZero() throws IOException {
|
||||
String fileName = TEST_FILE_SEEK_TABLE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -78,7 +77,7 @@ public final class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_seekTable_handlesSeekToEoF() throws IOException, InterruptedException {
|
||||
public void seeking_seekTable_handlesSeekToEoF() throws IOException {
|
||||
String fileName = TEST_FILE_SEEK_TABLE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -95,7 +94,7 @@ public final class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_seekTable_handlesSeekingBackward() throws IOException, InterruptedException {
|
||||
public void seeking_seekTable_handlesSeekingBackward() throws IOException {
|
||||
String fileName = TEST_FILE_SEEK_TABLE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -114,7 +113,7 @@ public final class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_seekTable_handlesSeekingForward() throws IOException, InterruptedException {
|
||||
public void seeking_seekTable_handlesSeekingForward() throws IOException {
|
||||
String fileName = TEST_FILE_SEEK_TABLE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -133,8 +132,7 @@ public final class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flacExtractorReads_binarySearch_returnSeekableSeekMap()
|
||||
throws IOException, InterruptedException {
|
||||
public void flacExtractorReads_binarySearch_returnSeekableSeekMap() throws IOException {
|
||||
Uri fileUri = TestUtil.buildAssetUri(TEST_FILE_BINARY_SEARCH);
|
||||
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -145,7 +143,7 @@ public final class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_binarySearch_handlesSeekToZero() throws IOException, InterruptedException {
|
||||
public void seeking_binarySearch_handlesSeekToZero() throws IOException {
|
||||
String fileName = TEST_FILE_BINARY_SEARCH;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -162,7 +160,7 @@ public final class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_binarySearch_handlesSeekToEoF() throws IOException, InterruptedException {
|
||||
public void seeking_binarySearch_handlesSeekToEoF() throws IOException {
|
||||
String fileName = TEST_FILE_BINARY_SEARCH;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -179,8 +177,7 @@ public final class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_binarySearch_handlesSeekingBackward()
|
||||
throws IOException, InterruptedException {
|
||||
public void seeking_binarySearch_handlesSeekingBackward() throws IOException {
|
||||
String fileName = TEST_FILE_BINARY_SEARCH;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -199,8 +196,7 @@ public final class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_binarySearch_handlesSeekingForward()
|
||||
throws IOException, InterruptedException {
|
||||
public void seeking_binarySearch_handlesSeekingForward() throws IOException {
|
||||
String fileName = TEST_FILE_BINARY_SEARCH;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -219,8 +215,7 @@ public final class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flacExtractorReads_unseekable_returnUnseekableSeekMap()
|
||||
throws IOException, InterruptedException {
|
||||
public void flacExtractorReads_unseekable_returnUnseekableSeekMap() throws IOException {
|
||||
Uri fileUri = TestUtil.buildAssetUri(TEST_FILE_UNSEEKABLE);
|
||||
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -235,7 +230,7 @@ public final class FlacExtractorSeekTest {
|
||||
FakeTrackOutput trackOutput,
|
||||
long targetSeekTimeUs,
|
||||
int firstFrameIndexAfterSeek)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
FakeTrackOutput expectedTrackOutput = getExpectedTrackOutput(fileName);
|
||||
int expectedFrameIndex = getFrameIndex(expectedTrackOutput, targetSeekTimeUs);
|
||||
|
||||
@ -252,7 +247,7 @@ public final class FlacExtractorSeekTest {
|
||||
FakeTrackOutput trackOutput,
|
||||
long targetSeekTimeUs,
|
||||
int firstFrameIndexAfterSeek)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
FakeTrackOutput expectedTrackOutput = getExpectedTrackOutput(fileName);
|
||||
int maxFrameIndex = getFrameIndex(expectedTrackOutput, targetSeekTimeUs);
|
||||
|
||||
@ -276,8 +271,7 @@ public final class FlacExtractorSeekTest {
|
||||
assertThat(frameFound).isTrue();
|
||||
}
|
||||
|
||||
private static FakeTrackOutput getExpectedTrackOutput(String fileName)
|
||||
throws IOException, InterruptedException {
|
||||
private static FakeTrackOutput getExpectedTrackOutput(String fileName) throws IOException {
|
||||
return TestUtil.extractAllSamplesFromFile(
|
||||
new FlacExtractor(), ApplicationProvider.getApplicationContext(), fileName)
|
||||
.trackOutputs
|
||||
|
@ -100,7 +100,7 @@ import java.nio.ByteBuffer;
|
||||
|
||||
@Override
|
||||
public TimestampSearchResult searchForTimestamp(ExtractorInput input, long targetSampleIndex)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
ByteBuffer outputBuffer = outputFrameHolder.byteBuffer;
|
||||
long searchPosition = input.getPosition();
|
||||
decoderJni.reset(searchPosition);
|
||||
|
@ -63,7 +63,7 @@ import java.util.List;
|
||||
streamMetadata = decoderJni.decodeStreamMetadata();
|
||||
} catch (ParserException e) {
|
||||
throw new FlacDecoderException("Failed to decode StreamInfo", e);
|
||||
} catch (IOException | InterruptedException e) {
|
||||
} catch (IOException e) {
|
||||
// Never happens.
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
@ -107,7 +107,7 @@ import java.util.List;
|
||||
decoderJni.decodeSample(outputData);
|
||||
} catch (FlacDecoderJni.FlacFrameDecodeException e) {
|
||||
return new FlacDecoderException("Frame decoding failed", e);
|
||||
} catch (IOException | InterruptedException e) {
|
||||
} catch (IOException e) {
|
||||
// Never happens.
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ import java.nio.ByteBuffer;
|
||||
* read from the source, then 0 is returned.
|
||||
*/
|
||||
@SuppressWarnings("unused") // Called from native code.
|
||||
public int read(ByteBuffer target) throws IOException, InterruptedException {
|
||||
public int read(ByteBuffer target) throws IOException {
|
||||
int byteCount = target.remaining();
|
||||
if (byteBufferData != null) {
|
||||
byteCount = Math.min(byteCount, byteBufferData.remaining());
|
||||
@ -145,7 +145,7 @@ import java.nio.ByteBuffer;
|
||||
}
|
||||
|
||||
/** Decodes and consumes the metadata from the FLAC stream. */
|
||||
public FlacStreamMetadata decodeStreamMetadata() throws IOException, InterruptedException {
|
||||
public FlacStreamMetadata decodeStreamMetadata() throws IOException {
|
||||
FlacStreamMetadata streamMetadata = flacDecodeMetadata(nativeDecoderContext);
|
||||
if (streamMetadata == null) {
|
||||
throw new ParserException("Failed to decode stream metadata");
|
||||
@ -161,7 +161,7 @@ import java.nio.ByteBuffer;
|
||||
* @param retryPosition If any error happens, the input will be rewound to {@code retryPosition}.
|
||||
*/
|
||||
public void decodeSampleWithBacktrackPosition(ByteBuffer output, long retryPosition)
|
||||
throws InterruptedException, IOException, FlacFrameDecodeException {
|
||||
throws IOException, FlacFrameDecodeException {
|
||||
try {
|
||||
decodeSample(output);
|
||||
} catch (IOException e) {
|
||||
@ -177,8 +177,7 @@ import java.nio.ByteBuffer;
|
||||
|
||||
/** Decodes and consumes the next sample from the FLAC stream into the given byte buffer. */
|
||||
@SuppressWarnings("ByteBufferBackingArray")
|
||||
public void decodeSample(ByteBuffer output)
|
||||
throws IOException, InterruptedException, FlacFrameDecodeException {
|
||||
public void decodeSample(ByteBuffer output) throws IOException, FlacFrameDecodeException {
|
||||
output.clear();
|
||||
int frameSize =
|
||||
output.isDirect()
|
||||
@ -266,8 +265,7 @@ import java.nio.ByteBuffer;
|
||||
}
|
||||
|
||||
private int readFromExtractorInput(
|
||||
ExtractorInput extractorInput, byte[] tempBuffer, int offset, int length)
|
||||
throws IOException, InterruptedException {
|
||||
ExtractorInput extractorInput, byte[] tempBuffer, int offset, int length) throws IOException {
|
||||
int read = extractorInput.read(tempBuffer, offset, length);
|
||||
if (read == C.RESULT_END_OF_INPUT) {
|
||||
endOfExtractorInput = true;
|
||||
@ -278,14 +276,11 @@ import java.nio.ByteBuffer;
|
||||
|
||||
private native long flacInit();
|
||||
|
||||
private native FlacStreamMetadata flacDecodeMetadata(long context)
|
||||
throws IOException, InterruptedException;
|
||||
private native FlacStreamMetadata flacDecodeMetadata(long context) throws IOException;
|
||||
|
||||
private native int flacDecodeToBuffer(long context, ByteBuffer outputBuffer)
|
||||
throws IOException, InterruptedException;
|
||||
private native int flacDecodeToBuffer(long context, ByteBuffer outputBuffer) throws IOException;
|
||||
|
||||
private native int flacDecodeToArray(long context, byte[] outputArray)
|
||||
throws IOException, InterruptedException;
|
||||
private native int flacDecodeToArray(long context, byte[] outputArray) throws IOException;
|
||||
|
||||
private native long flacGetDecodePosition(long context);
|
||||
|
||||
|
@ -113,14 +113,13 @@ public final class FlacExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public boolean sniff(ExtractorInput input) throws IOException {
|
||||
id3Metadata = FlacMetadataReader.peekId3Metadata(input, /* parseData= */ !id3MetadataDisabled);
|
||||
return FlacMetadataReader.checkAndPeekStreamMarker(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(final ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException, InterruptedException {
|
||||
public int read(final ExtractorInput input, PositionHolder seekPosition) throws IOException {
|
||||
if (input.getPosition() == 0 && !id3MetadataDisabled && id3Metadata == null) {
|
||||
id3Metadata = FlacMetadataReader.peekId3Metadata(input, /* parseData= */ true);
|
||||
}
|
||||
@ -185,7 +184,7 @@ public final class FlacExtractor implements Extractor {
|
||||
@RequiresNonNull({"decoderJni", "extractorOutput", "trackOutput"}) // Requires initialized.
|
||||
@EnsuresNonNull({"streamMetadata", "outputFrameHolder"}) // Ensures stream metadata decoded.
|
||||
@SuppressWarnings({"contracts.postcondition.not.satisfied"})
|
||||
private void decodeStreamMetadata(ExtractorInput input) throws InterruptedException, IOException {
|
||||
private void decodeStreamMetadata(ExtractorInput input) throws IOException {
|
||||
if (streamMetadataDecoded) {
|
||||
return;
|
||||
}
|
||||
@ -225,7 +224,7 @@ public final class FlacExtractor implements Extractor {
|
||||
ParsableByteArray outputBuffer,
|
||||
OutputFrameHolder outputFrameHolder,
|
||||
TrackOutput trackOutput)
|
||||
throws InterruptedException, IOException {
|
||||
throws IOException {
|
||||
int seekResult = binarySearchSeeker.handlePendingSeek(input, seekPosition);
|
||||
ByteBuffer outputByteBuffer = outputFrameHolder.byteBuffer;
|
||||
if (seekResult == RESULT_CONTINUE && outputByteBuffer.limit() > 0) {
|
||||
|
@ -30,7 +30,6 @@ public interface DataReader {
|
||||
* may be less than {@code length} because the end of the input (or available data) was
|
||||
* reached, the method was interrupted, or the operation was aborted early for another reason.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread has been interrupted.
|
||||
*/
|
||||
int read(byte[] target, int offset, int length) throws IOException, InterruptedException;
|
||||
int read(byte[] target, int offset, int length) throws IOException;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ import java.io.IOException;
|
||||
|
||||
@Override
|
||||
public void init(DataSource dataSource, long position, long length, ExtractorOutput output)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
extractorInput = new DefaultExtractorInput(dataSource, position, length);
|
||||
if (extractor != null) {
|
||||
return;
|
||||
@ -109,7 +109,7 @@ import java.io.IOException;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(PositionHolder positionHolder) throws IOException, InterruptedException {
|
||||
public int read(PositionHolder positionHolder) throws IOException {
|
||||
return Assertions.checkNotNull(extractor)
|
||||
.read(Assertions.checkNotNull(extractorInput), positionHolder);
|
||||
}
|
||||
|
@ -35,10 +35,9 @@ import java.io.IOException;
|
||||
* extractor.
|
||||
* @throws UnrecognizedInputFormatException Thrown if the input format could not be detected.
|
||||
* @throws IOException Thrown if the input could not be read.
|
||||
* @throws InterruptedException Thrown if the thread was interrupted.
|
||||
*/
|
||||
void init(DataSource dataSource, long position, long length, ExtractorOutput output)
|
||||
throws IOException, InterruptedException;
|
||||
throws IOException;
|
||||
|
||||
/** Releases any held resources. */
|
||||
void release();
|
||||
@ -71,7 +70,6 @@ import java.io.IOException;
|
||||
* hold the position of the required data.
|
||||
* @return One of the {@link Extractor}{@code .RESULT_*} values.
|
||||
* @throws IOException If an error occurred reading from the input.
|
||||
* @throws InterruptedException If the thread was interrupted.
|
||||
*/
|
||||
int read(PositionHolder positionHolder) throws IOException, InterruptedException;
|
||||
int read(PositionHolder positionHolder) throws IOException;
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -950,7 +951,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() throws IOException, InterruptedException {
|
||||
public void load() throws IOException {
|
||||
int result = Extractor.RESULT_CONTINUE;
|
||||
while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
|
||||
try {
|
||||
@ -978,7 +979,11 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
pendingExtractorSeek = false;
|
||||
}
|
||||
while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
|
||||
loadCondition.block();
|
||||
try {
|
||||
loadCondition.block();
|
||||
} catch (InterruptedException e) {
|
||||
throw new InterruptedIOException();
|
||||
}
|
||||
result = progressiveMediaExtractor.read(positionHolder);
|
||||
long currentInputPosition = progressiveMediaExtractor.getCurrentInputPosition();
|
||||
if (currentInputPosition > position + continueLoadingCheckIntervalBytes) {
|
||||
|
@ -177,8 +177,7 @@ import java.util.Arrays;
|
||||
return totalBytesWritten;
|
||||
}
|
||||
|
||||
public int sampleData(DataReader input, int length, boolean allowEndOfInput)
|
||||
throws IOException, InterruptedException {
|
||||
public int sampleData(DataReader input, int length, boolean allowEndOfInput) throws IOException {
|
||||
length = preAppend(length);
|
||||
int bytesAppended =
|
||||
input.read(
|
||||
|
@ -470,7 +470,7 @@ public class SampleQueue implements TrackOutput {
|
||||
|
||||
@Override
|
||||
public final int sampleData(DataReader input, int length, boolean allowEndOfInput)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
return sampleDataQueue.sampleData(input, length, allowEndOfInput);
|
||||
}
|
||||
|
||||
|
@ -204,7 +204,7 @@ public final class ChunkExtractorWrapper implements ExtractorOutput {
|
||||
|
||||
@Override
|
||||
public int sampleData(DataReader input, int length, boolean allowEndOfInput)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
return castNonNull(trackOutput).sampleData(input, length, allowEndOfInput);
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ public class ContainerMediaChunk extends BaseMediaChunk {
|
||||
|
||||
@SuppressWarnings("NonAtomicVolatileUpdate")
|
||||
@Override
|
||||
public final void load() throws IOException, InterruptedException {
|
||||
public final void load() throws IOException {
|
||||
if (nextLoadPosition == 0) {
|
||||
// Configure the output and set it as the target for the extractor wrapper.
|
||||
BaseMediaChunkOutput output = getOutput();
|
||||
|
@ -77,7 +77,7 @@ public abstract class DataChunk extends Chunk {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void load() throws IOException, InterruptedException {
|
||||
public final void load() throws IOException {
|
||||
try {
|
||||
dataSource.open(dataSpec);
|
||||
int limit = 0;
|
||||
|
@ -83,7 +83,7 @@ public final class InitializationChunk extends Chunk {
|
||||
|
||||
@SuppressWarnings("NonAtomicVolatileUpdate")
|
||||
@Override
|
||||
public void load() throws IOException, InterruptedException {
|
||||
public void load() throws IOException {
|
||||
if (nextLoadPosition == 0) {
|
||||
extractorWrapper.init(
|
||||
trackOutputProvider, /* startTimeUs= */ C.TIME_UNSET, /* endTimeUs= */ C.TIME_UNSET);
|
||||
|
@ -91,7 +91,7 @@ public final class SingleSampleMediaChunk extends BaseMediaChunk {
|
||||
|
||||
@SuppressWarnings("NonAtomicVolatileUpdate")
|
||||
@Override
|
||||
public void load() throws IOException, InterruptedException {
|
||||
public void load() throws IOException {
|
||||
BaseMediaChunkOutput output = getOutput();
|
||||
output.setSampleOffsetUs(0);
|
||||
TrackOutput trackOutput = output.track(0, trackType);
|
||||
|
@ -63,10 +63,8 @@ public final class Loader implements LoaderErrorThrower {
|
||||
* Performs the load, returning on completion or cancellation.
|
||||
*
|
||||
* @throws IOException If the input could not be loaded.
|
||||
* @throws InterruptedException If the thread was interrupted.
|
||||
*/
|
||||
void load() throws IOException, InterruptedException;
|
||||
|
||||
void load() throws IOException;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -400,12 +398,6 @@ public final class Loader implements LoaderErrorThrower {
|
||||
if (!released) {
|
||||
obtainMessage(MSG_IO_EXCEPTION, e).sendToTarget();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// The load was canceled.
|
||||
Assertions.checkState(canceled);
|
||||
if (!released) {
|
||||
sendEmptyMessage(MSG_END_OF_SOURCE);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// This should never happen, but handle it anyway.
|
||||
Log.e(TAG, "Unexpected exception loading stream", e);
|
||||
|
@ -80,11 +80,10 @@ public final class DashUtil {
|
||||
* @param period The {@link Period}.
|
||||
* @return The loaded {@link DrmInitData}, or null if none is defined.
|
||||
* @throws IOException Thrown when there is an error while loading.
|
||||
* @throws InterruptedException Thrown if the thread was interrupted.
|
||||
*/
|
||||
@Nullable
|
||||
public static DrmInitData loadDrmInitData(DataSource dataSource, Period period)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
int primaryTrackType = C.TRACK_TYPE_VIDEO;
|
||||
Representation representation = getFirstRepresentation(period, primaryTrackType);
|
||||
if (representation == null) {
|
||||
@ -110,12 +109,10 @@ public final class DashUtil {
|
||||
* @param representation The representation which initialization chunk belongs to.
|
||||
* @return the sample {@link Format} of the given representation.
|
||||
* @throws IOException Thrown when there is an error while loading.
|
||||
* @throws InterruptedException Thrown if the thread was interrupted.
|
||||
*/
|
||||
@Nullable
|
||||
public static Format loadSampleFormat(
|
||||
DataSource dataSource, int trackType, Representation representation)
|
||||
throws IOException, InterruptedException {
|
||||
DataSource dataSource, int trackType, Representation representation) throws IOException {
|
||||
ChunkExtractorWrapper extractorWrapper = loadInitializationData(dataSource, trackType,
|
||||
representation, false);
|
||||
return extractorWrapper == null
|
||||
@ -134,12 +131,10 @@ public final class DashUtil {
|
||||
* @return The {@link ChunkIndex} of the given representation, or null if no initialization or
|
||||
* index data exists.
|
||||
* @throws IOException Thrown when there is an error while loading.
|
||||
* @throws InterruptedException Thrown if the thread was interrupted.
|
||||
*/
|
||||
@Nullable
|
||||
public static ChunkIndex loadChunkIndex(
|
||||
DataSource dataSource, int trackType, Representation representation)
|
||||
throws IOException, InterruptedException {
|
||||
DataSource dataSource, int trackType, Representation representation) throws IOException {
|
||||
ChunkExtractorWrapper extractorWrapper = loadInitializationData(dataSource, trackType,
|
||||
representation, true);
|
||||
return extractorWrapper == null ? null : (ChunkIndex) extractorWrapper.getSeekMap();
|
||||
@ -157,12 +152,11 @@ public final class DashUtil {
|
||||
* @return A {@link ChunkExtractorWrapper} for the {@code representation}, or null if no
|
||||
* initialization or (if requested) index data exists.
|
||||
* @throws IOException Thrown when there is an error while loading.
|
||||
* @throws InterruptedException Thrown if the thread was interrupted.
|
||||
*/
|
||||
@Nullable
|
||||
private static ChunkExtractorWrapper loadInitializationData(
|
||||
DataSource dataSource, int trackType, Representation representation, boolean loadIndex)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
RangedUri initializationUri = representation.getInitializationUri();
|
||||
if (initializationUri == null) {
|
||||
return null;
|
||||
@ -188,9 +182,12 @@ public final class DashUtil {
|
||||
return extractorWrapper;
|
||||
}
|
||||
|
||||
private static void loadInitializationData(DataSource dataSource,
|
||||
Representation representation, ChunkExtractorWrapper extractorWrapper, RangedUri requestUri)
|
||||
throws IOException, InterruptedException {
|
||||
private static void loadInitializationData(
|
||||
DataSource dataSource,
|
||||
Representation representation,
|
||||
ChunkExtractorWrapper extractorWrapper,
|
||||
RangedUri requestUri)
|
||||
throws IOException {
|
||||
DataSpec dataSpec = DashUtil.buildDataSpec(representation, requestUri);
|
||||
InitializationChunk initializationChunk = new InitializationChunk(dataSource, dataSpec,
|
||||
representation.format, C.SELECTION_REASON_UNKNOWN, null /* trackSelectionData */,
|
||||
|
@ -296,7 +296,7 @@ public final class PlayerEmsgHandler implements Handler.Callback {
|
||||
|
||||
@Override
|
||||
public int sampleData(DataReader input, int length, boolean allowEndOfInput)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
return sampleQueue.sampleData(input, length, allowEndOfInput);
|
||||
}
|
||||
|
||||
|
@ -49,10 +49,9 @@ public abstract class BinarySearchSeeker {
|
||||
* @param targetTimestamp The target timestamp.
|
||||
* @return A {@link TimestampSearchResult} that describes the result of the search.
|
||||
* @throws IOException If an error occurred reading from the input.
|
||||
* @throws InterruptedException If the thread was interrupted.
|
||||
*/
|
||||
TimestampSearchResult searchForTimestamp(ExtractorInput input, long targetTimestamp)
|
||||
throws IOException, InterruptedException;
|
||||
throws IOException;
|
||||
|
||||
/** Called when a seek operation finishes. */
|
||||
default void onSeekFinished() {}
|
||||
@ -169,10 +168,9 @@ public abstract class BinarySearchSeeker {
|
||||
* to hold the position of the required seek.
|
||||
* @return One of the {@code RESULT_} values defined in {@link Extractor}.
|
||||
* @throws IOException If an error occurred reading from the input.
|
||||
* @throws InterruptedException If the thread was interrupted.
|
||||
*/
|
||||
public int handlePendingSeek(ExtractorInput input, PositionHolder seekPositionHolder)
|
||||
throws InterruptedException, IOException {
|
||||
throws IOException {
|
||||
while (true) {
|
||||
SeekOperationParams seekOperationParams =
|
||||
Assertions.checkStateNotNull(this.seekOperationParams);
|
||||
@ -241,7 +239,7 @@ public abstract class BinarySearchSeeker {
|
||||
}
|
||||
|
||||
protected final boolean skipInputUntilPosition(ExtractorInput input, long position)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
long bytesToSkip = position - input.getPosition();
|
||||
if (bytesToSkip >= 0 && bytesToSkip <= MAX_SKIP_BYTES) {
|
||||
input.skipFully((int) bytesToSkip);
|
||||
|
@ -21,6 +21,7 @@ import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
@ -55,7 +56,7 @@ public final class DefaultExtractorInput implements ExtractorInput {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] target, int offset, int length) throws IOException, InterruptedException {
|
||||
public int read(byte[] target, int offset, int length) throws IOException {
|
||||
int bytesRead = readFromPeekBuffer(target, offset, length);
|
||||
if (bytesRead == 0) {
|
||||
bytesRead =
|
||||
@ -68,7 +69,7 @@ public final class DefaultExtractorInput implements ExtractorInput {
|
||||
|
||||
@Override
|
||||
public boolean readFully(byte[] target, int offset, int length, boolean allowEndOfInput)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
int bytesRead = readFromPeekBuffer(target, offset, length);
|
||||
while (bytesRead < length && bytesRead != C.RESULT_END_OF_INPUT) {
|
||||
bytesRead = readFromDataSource(target, offset, length, bytesRead, allowEndOfInput);
|
||||
@ -78,13 +79,12 @@ public final class DefaultExtractorInput implements ExtractorInput {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFully(byte[] target, int offset, int length)
|
||||
throws IOException, InterruptedException {
|
||||
public void readFully(byte[] target, int offset, int length) throws IOException {
|
||||
readFully(target, offset, length, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int length) throws IOException, InterruptedException {
|
||||
public int skip(int length) throws IOException {
|
||||
int bytesSkipped = skipFromPeekBuffer(length);
|
||||
if (bytesSkipped == 0) {
|
||||
bytesSkipped =
|
||||
@ -95,8 +95,7 @@ public final class DefaultExtractorInput implements ExtractorInput {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean skipFully(int length, boolean allowEndOfInput)
|
||||
throws IOException, InterruptedException {
|
||||
public boolean skipFully(int length, boolean allowEndOfInput) throws IOException {
|
||||
int bytesSkipped = skipFromPeekBuffer(length);
|
||||
while (bytesSkipped < length && bytesSkipped != C.RESULT_END_OF_INPUT) {
|
||||
int minLength = Math.min(length, bytesSkipped + scratchSpace.length);
|
||||
@ -108,12 +107,12 @@ public final class DefaultExtractorInput implements ExtractorInput {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void skipFully(int length) throws IOException, InterruptedException {
|
||||
public void skipFully(int length) throws IOException {
|
||||
skipFully(length, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int peek(byte[] target, int offset, int length) throws IOException, InterruptedException {
|
||||
public int peek(byte[] target, int offset, int length) throws IOException {
|
||||
ensureSpaceForPeek(length);
|
||||
int peekBufferRemainingBytes = peekBufferLength - peekBufferPosition;
|
||||
int bytesPeeked;
|
||||
@ -139,7 +138,7 @@ public final class DefaultExtractorInput implements ExtractorInput {
|
||||
|
||||
@Override
|
||||
public boolean peekFully(byte[] target, int offset, int length, boolean allowEndOfInput)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
if (!advancePeekPosition(length, allowEndOfInput)) {
|
||||
return false;
|
||||
}
|
||||
@ -148,14 +147,12 @@ public final class DefaultExtractorInput implements ExtractorInput {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void peekFully(byte[] target, int offset, int length)
|
||||
throws IOException, InterruptedException {
|
||||
public void peekFully(byte[] target, int offset, int length) throws IOException {
|
||||
peekFully(target, offset, length, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean advancePeekPosition(int length, boolean allowEndOfInput)
|
||||
throws IOException, InterruptedException {
|
||||
public boolean advancePeekPosition(int length, boolean allowEndOfInput) throws IOException {
|
||||
ensureSpaceForPeek(length);
|
||||
int bytesPeeked = peekBufferLength - peekBufferPosition;
|
||||
while (bytesPeeked < length) {
|
||||
@ -171,7 +168,7 @@ public final class DefaultExtractorInput implements ExtractorInput {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void advancePeekPosition(int length) throws IOException, InterruptedException {
|
||||
public void advancePeekPosition(int length) throws IOException {
|
||||
advancePeekPosition(length, false);
|
||||
}
|
||||
|
||||
@ -271,18 +268,18 @@ public final class DefaultExtractorInput implements ExtractorInput {
|
||||
* @param allowEndOfInput True if encountering the end of the input having read no data is
|
||||
* allowed, and should result in {@link C#RESULT_END_OF_INPUT} being returned. False if it
|
||||
* should be considered an error, causing an {@link EOFException} to be thrown.
|
||||
* @return The total number of bytes read so far, or {@link C#RESULT_END_OF_INPUT} if
|
||||
* {@code allowEndOfInput} is true and the input has ended having read no bytes.
|
||||
* @return The total number of bytes read so far, or {@link C#RESULT_END_OF_INPUT} if {@code
|
||||
* allowEndOfInput} is true and the input has ended having read no bytes.
|
||||
* @throws EOFException If the end of input was encountered having partially satisfied the read
|
||||
* (i.e. having read at least one byte, but fewer than {@code length}), or if no bytes were
|
||||
* read and {@code allowEndOfInput} is false.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
private int readFromDataSource(byte[] target, int offset, int length, int bytesAlreadyRead,
|
||||
boolean allowEndOfInput) throws InterruptedException, IOException {
|
||||
private int readFromDataSource(
|
||||
byte[] target, int offset, int length, int bytesAlreadyRead, boolean allowEndOfInput)
|
||||
throws IOException {
|
||||
if (Thread.interrupted()) {
|
||||
throw new InterruptedException();
|
||||
throw new InterruptedIOException();
|
||||
}
|
||||
int bytesRead = dataSource.read(target, offset + bytesAlreadyRead, length - bytesAlreadyRead);
|
||||
if (bytesRead == C.RESULT_END_OF_INPUT) {
|
||||
|
@ -43,8 +43,7 @@ public final class DummyTrackOutput implements TrackOutput {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int sampleData(DataReader input, int length, boolean allowEndOfInput)
|
||||
throws IOException, InterruptedException {
|
||||
public int sampleData(DataReader input, int length, boolean allowEndOfInput) throws IOException {
|
||||
int bytesToSkipByReading = Math.min(readBuffer.length, length);
|
||||
int bytesSkipped = input.read(readBuffer, /* offset= */ 0, bytesToSkipByReading);
|
||||
if (bytesSkipped == C.RESULT_END_OF_INPUT) {
|
||||
|
@ -57,16 +57,15 @@ public interface Extractor {
|
||||
/**
|
||||
* Returns whether this extractor can extract samples from the {@link ExtractorInput}, which must
|
||||
* provide data from the start of the stream.
|
||||
* <p>
|
||||
* If {@code true} is returned, the {@code input}'s reading position may have been modified.
|
||||
*
|
||||
* <p>If {@code true} is returned, the {@code input}'s reading position may have been modified.
|
||||
* Otherwise, only its peek position may have been modified.
|
||||
*
|
||||
* @param input The {@link ExtractorInput} from which data should be peeked/read.
|
||||
* @return Whether this extractor can read the provided input.
|
||||
* @throws IOException If an error occurred reading from the input.
|
||||
* @throws InterruptedException If the thread was interrupted.
|
||||
*/
|
||||
boolean sniff(ExtractorInput input) throws IOException, InterruptedException;
|
||||
boolean sniff(ExtractorInput input) throws IOException;
|
||||
|
||||
/**
|
||||
* Initializes the extractor with an {@link ExtractorOutput}. Called at most once.
|
||||
@ -89,20 +88,18 @@ public interface Extractor {
|
||||
* {@link #RESULT_SEEK} is returned. If the extractor reached the end of the data provided by the
|
||||
* {@link ExtractorInput}, then {@link #RESULT_END_OF_INPUT} is returned.
|
||||
*
|
||||
* <p>When this method throws an {@link IOException} or an {@link InterruptedException},
|
||||
* extraction may continue by providing an {@link ExtractorInput} with an unchanged {@link
|
||||
* ExtractorInput#getPosition() read position} to a subsequent call to this method.
|
||||
* <p>When this method throws an {@link IOException}, extraction may continue by providing an
|
||||
* {@link ExtractorInput} with an unchanged {@link ExtractorInput#getPosition() read position} to
|
||||
* a subsequent call to this method.
|
||||
*
|
||||
* @param input The {@link ExtractorInput} from which data should be read.
|
||||
* @param seekPosition If {@link #RESULT_SEEK} is returned, this holder is updated to hold the
|
||||
* position of the required data.
|
||||
* @return One of the {@code RESULT_} values defined in this interface.
|
||||
* @throws IOException If an error occurred reading from the input.
|
||||
* @throws InterruptedException If the thread was interrupted.
|
||||
*/
|
||||
@ReadResult
|
||||
int read(ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException, InterruptedException;
|
||||
int read(ExtractorInput input, PositionHolder seekPosition) throws IOException;
|
||||
|
||||
/**
|
||||
* Notifies the extractor that a seek has occurred.
|
||||
|
@ -68,8 +68,8 @@ public interface ExtractorInput extends DataReader {
|
||||
|
||||
/**
|
||||
* Reads up to {@code length} bytes from the input and resets the peek position.
|
||||
* <p>
|
||||
* This method blocks until at least one byte of data can be read, the end of the input is
|
||||
*
|
||||
* <p>This method blocks until at least one byte of data can be read, the end of the input is
|
||||
* detected, or an exception is thrown.
|
||||
*
|
||||
* @param target A target array into which data should be written.
|
||||
@ -77,9 +77,9 @@ public interface ExtractorInput extends DataReader {
|
||||
* @param length The maximum number of bytes to read from the input.
|
||||
* @return The number of bytes read, or {@link C#RESULT_END_OF_INPUT} if the input has ended.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread has been interrupted.
|
||||
*/
|
||||
int read(byte[] target, int offset, int length) throws IOException, InterruptedException;
|
||||
@Override
|
||||
int read(byte[] target, int offset, int length) throws IOException;
|
||||
|
||||
/**
|
||||
* Like {@link #read(byte[], int, int)}, but reads the requested {@code length} in full.
|
||||
@ -97,10 +97,9 @@ public interface ExtractorInput extends DataReader {
|
||||
* (i.e. having read at least one byte, but fewer than {@code length}), or if no bytes were
|
||||
* read and {@code allowEndOfInput} is false.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread has been interrupted.
|
||||
*/
|
||||
boolean readFully(byte[] target, int offset, int length, boolean allowEndOfInput)
|
||||
throws IOException, InterruptedException;
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link #readFully(byte[], int, int, boolean) readFully(target, offset, length,
|
||||
@ -111,9 +110,8 @@ public interface ExtractorInput extends DataReader {
|
||||
* @param length The number of bytes to read from the input.
|
||||
* @throws EOFException If the end of input was encountered.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
void readFully(byte[] target, int offset, int length) throws IOException, InterruptedException;
|
||||
void readFully(byte[] target, int offset, int length) throws IOException;
|
||||
|
||||
/**
|
||||
* Like {@link #read(byte[], int, int)}, except the data is skipped instead of read.
|
||||
@ -121,9 +119,8 @@ public interface ExtractorInput extends DataReader {
|
||||
* @param length The maximum number of bytes to skip from the input.
|
||||
* @return The number of bytes skipped, or {@link C#RESULT_END_OF_INPUT} if the input has ended.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread has been interrupted.
|
||||
*/
|
||||
int skip(int length) throws IOException, InterruptedException;
|
||||
int skip(int length) throws IOException;
|
||||
|
||||
/**
|
||||
* Like {@link #readFully(byte[], int, int, boolean)}, except the data is skipped instead of read.
|
||||
@ -139,22 +136,20 @@ public interface ExtractorInput extends DataReader {
|
||||
* (i.e. having skipped at least one byte, but fewer than {@code length}), or if no bytes were
|
||||
* skipped and {@code allowEndOfInput} is false.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread has been interrupted.
|
||||
*/
|
||||
boolean skipFully(int length, boolean allowEndOfInput) throws IOException, InterruptedException;
|
||||
boolean skipFully(int length, boolean allowEndOfInput) throws IOException;
|
||||
|
||||
/**
|
||||
* Like {@link #readFully(byte[], int, int)}, except the data is skipped instead of read.
|
||||
* <p>
|
||||
* Encountering the end of input is always considered an error, and will result in an
|
||||
* {@link EOFException} being thrown.
|
||||
*
|
||||
* <p>Encountering the end of input is always considered an error, and will result in an {@link
|
||||
* EOFException} being thrown.
|
||||
*
|
||||
* @param length The number of bytes to skip from the input.
|
||||
* @throws EOFException If the end of input was encountered.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
void skipFully(int length) throws IOException, InterruptedException;
|
||||
void skipFully(int length) throws IOException;
|
||||
|
||||
/**
|
||||
* Peeks up to {@code length} bytes from the peek position. The current read position is left
|
||||
@ -172,9 +167,8 @@ public interface ExtractorInput extends DataReader {
|
||||
* @param length The maximum number of bytes to peek from the input.
|
||||
* @return The number of bytes peeked, or {@link C#RESULT_END_OF_INPUT} if the input has ended.
|
||||
* @throws IOException If an error occurs peeking from the input.
|
||||
* @throws InterruptedException If the thread has been interrupted.
|
||||
*/
|
||||
int peek(byte[] target, int offset, int length) throws IOException, InterruptedException;
|
||||
int peek(byte[] target, int offset, int length) throws IOException;
|
||||
|
||||
/**
|
||||
* Like {@link #peek(byte[], int, int)}, but peeks the requested {@code length} in full.
|
||||
@ -192,10 +186,9 @@ public interface ExtractorInput extends DataReader {
|
||||
* (i.e. having peeked at least one byte, but fewer than {@code length}), or if no bytes were
|
||||
* peeked and {@code allowEndOfInput} is false.
|
||||
* @throws IOException If an error occurs peeking from the input.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
boolean peekFully(byte[] target, int offset, int length, boolean allowEndOfInput)
|
||||
throws IOException, InterruptedException;
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link #peekFully(byte[], int, int, boolean) peekFully(target, offset, length,
|
||||
@ -206,9 +199,8 @@ public interface ExtractorInput extends DataReader {
|
||||
* @param length The number of bytes to peek from the input.
|
||||
* @throws EOFException If the end of input was encountered.
|
||||
* @throws IOException If an error occurs peeking from the input.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
void peekFully(byte[] target, int offset, int length) throws IOException, InterruptedException;
|
||||
void peekFully(byte[] target, int offset, int length) throws IOException;
|
||||
|
||||
/**
|
||||
* Advances the peek position by {@code length} bytes. Like {@link #peekFully(byte[], int, int,
|
||||
@ -225,10 +217,8 @@ public interface ExtractorInput extends DataReader {
|
||||
* advanced by at least one byte, but fewer than {@code length}), or if the end of input was
|
||||
* encountered before advancing and {@code allowEndOfInput} is false.
|
||||
* @throws IOException If an error occurs advancing the peek position.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
boolean advancePeekPosition(int length, boolean allowEndOfInput)
|
||||
throws IOException, InterruptedException;
|
||||
boolean advancePeekPosition(int length, boolean allowEndOfInput) throws IOException;
|
||||
|
||||
/**
|
||||
* Advances the peek position by {@code length} bytes. Like {@link #peekFully(byte[], int, int)}
|
||||
@ -237,9 +227,8 @@ public interface ExtractorInput extends DataReader {
|
||||
* @param length The number of bytes to peek from the input.
|
||||
* @throws EOFException If the end of input was encountered.
|
||||
* @throws IOException If an error occurs peeking from the input.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
void advancePeekPosition(int length) throws IOException, InterruptedException;
|
||||
void advancePeekPosition(int length) throws IOException;
|
||||
|
||||
/**
|
||||
* Resets the peek position to equal the current read position.
|
||||
|
@ -33,10 +33,9 @@ import java.io.IOException;
|
||||
* @param length The maximum number of bytes to peek from the input.
|
||||
* @return The number of bytes peeked.
|
||||
* @throws IOException If an error occurs peeking from the input.
|
||||
* @throws InterruptedException If the thread has been interrupted.
|
||||
*/
|
||||
public static int peekToLength(ExtractorInput input, byte[] target, int offset, int length)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
int totalBytesPeeked = 0;
|
||||
while (totalBytesPeeked < length) {
|
||||
int bytesPeeked = input.peek(target, offset + totalBytesPeeked, length - totalBytesPeeked);
|
||||
|
@ -93,7 +93,7 @@ public final class FlacFrameReader {
|
||||
FlacStreamMetadata flacStreamMetadata,
|
||||
int frameStartMarker,
|
||||
SampleNumberHolder sampleNumberHolder)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
long originalPeekPosition = input.getPeekPosition();
|
||||
|
||||
byte[] frameStartBytes = new byte[2];
|
||||
@ -132,11 +132,9 @@ public final class FlacFrameReader {
|
||||
* @return The frame first sample number.
|
||||
* @throws ParserException If an error occurs parsing the sample number.
|
||||
* @throws IOException If peeking from the input fails.
|
||||
* @throws InterruptedException If interrupted while peeking from input.
|
||||
*/
|
||||
public static long getFirstSampleNumber(
|
||||
ExtractorInput input, FlacStreamMetadata flacStreamMetadata)
|
||||
throws IOException, InterruptedException {
|
||||
ExtractorInput input, FlacStreamMetadata flacStreamMetadata) throws IOException {
|
||||
input.resetPeekPosition();
|
||||
input.advancePeekPosition(1);
|
||||
byte[] blockingStrategyByte = new byte[1];
|
||||
|
@ -60,12 +60,10 @@ public final class FlacMetadataReader {
|
||||
* is {@code false}.
|
||||
* @throws IOException If peeking from the input fails. In this case, there is no guarantee on the
|
||||
* peek position.
|
||||
* @throws InterruptedException If interrupted while peeking from input. In this case, there is no
|
||||
* guarantee on the peek position.
|
||||
*/
|
||||
@Nullable
|
||||
public static Metadata peekId3Metadata(ExtractorInput input, boolean parseData)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
@Nullable
|
||||
Id3Decoder.FramePredicate id3FramePredicate = parseData ? null : Id3Decoder.NO_FRAMES_PREDICATE;
|
||||
@Nullable Metadata id3Metadata = new Id3Peeker().peekId3Data(input, id3FramePredicate);
|
||||
@ -79,11 +77,8 @@ public final class FlacMetadataReader {
|
||||
* @return Whether the data peeked is the FLAC stream marker.
|
||||
* @throws IOException If peeking from the input fails. In this case, the peek position is left
|
||||
* unchanged.
|
||||
* @throws InterruptedException If interrupted while peeking from input. In this case, the peek
|
||||
* position is left unchanged.
|
||||
*/
|
||||
public static boolean checkAndPeekStreamMarker(ExtractorInput input)
|
||||
throws IOException, InterruptedException {
|
||||
public static boolean checkAndPeekStreamMarker(ExtractorInput input) throws IOException {
|
||||
ParsableByteArray scratch = new ParsableByteArray(FlacConstants.STREAM_MARKER_SIZE);
|
||||
input.peekFully(scratch.data, 0, FlacConstants.STREAM_MARKER_SIZE);
|
||||
return scratch.readUnsignedInt() == STREAM_MARKER;
|
||||
@ -101,12 +96,10 @@ public final class FlacMetadataReader {
|
||||
* is {@code false}.
|
||||
* @throws IOException If reading from the input fails. In this case, the read position is left
|
||||
* unchanged and there is no guarantee on the peek position.
|
||||
* @throws InterruptedException If interrupted while reading from input. In this case, the read
|
||||
* position is left unchanged and there is no guarantee on the peek position.
|
||||
*/
|
||||
@Nullable
|
||||
public static Metadata readId3Metadata(ExtractorInput input, boolean parseData)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
input.resetPeekPosition();
|
||||
long startingPeekPosition = input.getPeekPosition();
|
||||
@Nullable Metadata id3Metadata = peekId3Metadata(input, parseData);
|
||||
@ -123,11 +116,8 @@ public final class FlacMetadataReader {
|
||||
* position of {@code input} is advanced by {@link FlacConstants#STREAM_MARKER_SIZE} bytes.
|
||||
* @throws IOException If reading from the input fails. In this case, the position is left
|
||||
* unchanged.
|
||||
* @throws InterruptedException If interrupted while reading from input. In this case, the
|
||||
* position is left unchanged.
|
||||
*/
|
||||
public static void readStreamMarker(ExtractorInput input)
|
||||
throws IOException, InterruptedException {
|
||||
public static void readStreamMarker(ExtractorInput input) throws IOException {
|
||||
ParsableByteArray scratch = new ParsableByteArray(FlacConstants.STREAM_MARKER_SIZE);
|
||||
input.readFully(scratch.data, 0, FlacConstants.STREAM_MARKER_SIZE);
|
||||
if (scratch.readUnsignedInt() != STREAM_MARKER) {
|
||||
@ -153,13 +143,9 @@ public final class FlacMetadataReader {
|
||||
* start of a metadata block and there is no guarantee on the peek position.
|
||||
* @throws IOException If reading from the input fails. In this case, the read position will be at
|
||||
* the start of a metadata block and there is no guarantee on the peek position.
|
||||
* @throws InterruptedException If interrupted while reading from input. In this case, the read
|
||||
* position will be at the start of a metadata block and there is no guarantee on the peek
|
||||
* position.
|
||||
*/
|
||||
public static boolean readMetadataBlock(
|
||||
ExtractorInput input, FlacStreamMetadataHolder metadataHolder)
|
||||
throws IOException, InterruptedException {
|
||||
ExtractorInput input, FlacStreamMetadataHolder metadataHolder) throws IOException {
|
||||
input.resetPeekPosition();
|
||||
ParsableBitArray scratch = new ParsableBitArray(new byte[4]);
|
||||
input.peekFully(scratch.data, 0, FlacConstants.METADATA_BLOCK_HEADER_SIZE);
|
||||
@ -239,10 +225,8 @@ public final class FlacMetadataReader {
|
||||
* @return The frame start marker (which must be the same for all the frames in the stream).
|
||||
* @throws ParserException If an error occurs parsing the frame start marker.
|
||||
* @throws IOException If peeking from the input fails.
|
||||
* @throws InterruptedException If interrupted while peeking from input.
|
||||
*/
|
||||
public static int getFrameStartMarker(ExtractorInput input)
|
||||
throws IOException, InterruptedException {
|
||||
public static int getFrameStartMarker(ExtractorInput input) throws IOException {
|
||||
input.resetPeekPosition();
|
||||
ParsableByteArray scratch = new ParsableByteArray(2);
|
||||
input.peekFully(scratch.data, 0, 2);
|
||||
@ -258,8 +242,7 @@ public final class FlacMetadataReader {
|
||||
return frameStartMarker;
|
||||
}
|
||||
|
||||
private static FlacStreamMetadata readStreamInfoBlock(ExtractorInput input)
|
||||
throws IOException, InterruptedException {
|
||||
private static FlacStreamMetadata readStreamInfoBlock(ExtractorInput input) throws IOException {
|
||||
byte[] scratchData = new byte[FlacConstants.STREAM_INFO_BLOCK_SIZE];
|
||||
input.readFully(scratchData, 0, FlacConstants.STREAM_INFO_BLOCK_SIZE);
|
||||
return new FlacStreamMetadata(
|
||||
@ -267,14 +250,14 @@ public final class FlacMetadataReader {
|
||||
}
|
||||
|
||||
private static FlacStreamMetadata.SeekTable readSeekTableMetadataBlock(
|
||||
ExtractorInput input, int length) throws IOException, InterruptedException {
|
||||
ExtractorInput input, int length) throws IOException {
|
||||
ParsableByteArray scratch = new ParsableByteArray(length);
|
||||
input.readFully(scratch.data, 0, length);
|
||||
return readSeekTableMetadataBlock(scratch);
|
||||
}
|
||||
|
||||
private static List<String> readVorbisCommentMetadataBlock(ExtractorInput input, int length)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
ParsableByteArray scratch = new ParsableByteArray(length);
|
||||
input.readFully(scratch.data, 0, length);
|
||||
scratch.skipBytes(FlacConstants.METADATA_BLOCK_HEADER_SIZE);
|
||||
@ -285,7 +268,7 @@ public final class FlacMetadataReader {
|
||||
}
|
||||
|
||||
private static PictureFrame readPictureMetadataBlock(ExtractorInput input, int length)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
ParsableByteArray scratch = new ParsableByteArray(length);
|
||||
input.readFully(scratch.data, 0, length);
|
||||
scratch.skipBytes(FlacConstants.METADATA_BLOCK_HEADER_SIZE);
|
||||
|
@ -43,12 +43,11 @@ public final class Id3Peeker {
|
||||
* @return The first ID3 tag decoded into a {@link Metadata} object. May be null if ID3 tag is not
|
||||
* present in the input.
|
||||
* @throws IOException If an error occurred peeking from the input.
|
||||
* @throws InterruptedException If the thread was interrupted.
|
||||
*/
|
||||
@Nullable
|
||||
public Metadata peekId3Data(
|
||||
ExtractorInput input, @Nullable Id3Decoder.FramePredicate id3FramePredicate)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
int peekedId3Bytes = 0;
|
||||
@Nullable Metadata metadata = null;
|
||||
while (true) {
|
||||
|
@ -111,10 +111,8 @@ public interface TrackOutput {
|
||||
* should be considered an error, causing an {@link EOFException} to be thrown.
|
||||
* @return The number of bytes appended.
|
||||
* @throws IOException If an error occurred reading from the input.
|
||||
* @throws InterruptedException If the thread was interrupted.
|
||||
*/
|
||||
int sampleData(DataReader input, int length, boolean allowEndOfInput)
|
||||
throws IOException, InterruptedException;
|
||||
int sampleData(DataReader input, int length, boolean allowEndOfInput) throws IOException;
|
||||
|
||||
/**
|
||||
* Called to write sample data to the output.
|
||||
|
@ -160,7 +160,7 @@ public final class AmrExtractor implements Extractor {
|
||||
// Extractor implementation.
|
||||
|
||||
@Override
|
||||
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public boolean sniff(ExtractorInput input) throws IOException {
|
||||
return readAmrHeader(input);
|
||||
}
|
||||
|
||||
@ -172,8 +172,7 @@ public final class AmrExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException, InterruptedException {
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException {
|
||||
assertInitialized();
|
||||
if (input.getPosition() == 0) {
|
||||
if (!readAmrHeader(input)) {
|
||||
@ -227,7 +226,7 @@ public final class AmrExtractor implements Extractor {
|
||||
* @param input The {@link ExtractorInput} from which data should be peeked/read.
|
||||
* @return Whether the AMR header has been read.
|
||||
*/
|
||||
private boolean readAmrHeader(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private boolean readAmrHeader(ExtractorInput input) throws IOException {
|
||||
if (peekAmrSignature(input, amrSignatureNb)) {
|
||||
isWideBand = false;
|
||||
input.skipFully(amrSignatureNb.length);
|
||||
@ -241,8 +240,8 @@ public final class AmrExtractor implements Extractor {
|
||||
}
|
||||
|
||||
/** Peeks from the beginning of the input to see if the given AMR signature exists. */
|
||||
private boolean peekAmrSignature(ExtractorInput input, byte[] amrSignature)
|
||||
throws IOException, InterruptedException {
|
||||
private static boolean peekAmrSignature(ExtractorInput input, byte[] amrSignature)
|
||||
throws IOException {
|
||||
input.resetPeekPosition();
|
||||
byte[] header = new byte[amrSignature.length];
|
||||
input.peekFully(header, 0, amrSignature.length);
|
||||
@ -266,7 +265,7 @@ public final class AmrExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@RequiresNonNull("trackOutput")
|
||||
private int readSample(ExtractorInput extractorInput) throws IOException, InterruptedException {
|
||||
private int readSample(ExtractorInput extractorInput) throws IOException {
|
||||
if (currentSampleBytesRemaining == 0) {
|
||||
try {
|
||||
currentSampleSize = peekNextSampleSize(extractorInput);
|
||||
@ -304,8 +303,7 @@ public final class AmrExtractor implements Extractor {
|
||||
return RESULT_CONTINUE;
|
||||
}
|
||||
|
||||
private int peekNextSampleSize(ExtractorInput extractorInput)
|
||||
throws IOException, InterruptedException {
|
||||
private int peekNextSampleSize(ExtractorInput extractorInput) throws IOException {
|
||||
extractorInput.resetPeekPosition();
|
||||
extractorInput.peekFully(scratch, /* offset= */ 0, /* length= */ 1);
|
||||
|
||||
|
@ -73,7 +73,7 @@ import java.io.IOException;
|
||||
|
||||
@Override
|
||||
public TimestampSearchResult searchForTimestamp(ExtractorInput input, long targetSampleNumber)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
long searchPosition = input.getPosition();
|
||||
|
||||
// Find left frame.
|
||||
@ -110,10 +110,8 @@ import java.io.IOException;
|
||||
* the stream if no frame was found.
|
||||
* @throws IOException If peeking from the input fails. In this case, there is no guarantee on
|
||||
* the peek position.
|
||||
* @throws InterruptedException If interrupted while peeking from input. In this case, there is
|
||||
* no guarantee on the peek position.
|
||||
*/
|
||||
private long findNextFrame(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private long findNextFrame(ExtractorInput input) throws IOException {
|
||||
while (input.getPeekPosition() < input.getLength() - FlacConstants.MIN_FRAME_HEADER_SIZE
|
||||
&& !FlacFrameReader.checkFrameHeaderFromPeek(
|
||||
input, flacStreamMetadata, frameStartMarker, sampleNumberHolder)) {
|
||||
|
@ -134,7 +134,7 @@ public final class FlacExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public boolean sniff(ExtractorInput input) throws IOException {
|
||||
FlacMetadataReader.peekId3Metadata(input, /* parseData= */ false);
|
||||
return FlacMetadataReader.checkAndPeekStreamMarker(input);
|
||||
}
|
||||
@ -148,7 +148,7 @@ public final class FlacExtractor implements Extractor {
|
||||
|
||||
@Override
|
||||
public @ReadResult int read(ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
switch (state) {
|
||||
case STATE_READ_ID3_METADATA:
|
||||
readId3Metadata(input);
|
||||
@ -191,24 +191,23 @@ public final class FlacExtractor implements Extractor {
|
||||
|
||||
// Private methods.
|
||||
|
||||
private void readId3Metadata(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private void readId3Metadata(ExtractorInput input) throws IOException {
|
||||
id3Metadata = FlacMetadataReader.readId3Metadata(input, /* parseData= */ !id3MetadataDisabled);
|
||||
state = STATE_GET_STREAM_MARKER_AND_INFO_BLOCK_BYTES;
|
||||
}
|
||||
|
||||
private void getStreamMarkerAndInfoBlockBytes(ExtractorInput input)
|
||||
throws IOException, InterruptedException {
|
||||
private void getStreamMarkerAndInfoBlockBytes(ExtractorInput input) throws IOException {
|
||||
input.peekFully(streamMarkerAndInfoBlock, 0, streamMarkerAndInfoBlock.length);
|
||||
input.resetPeekPosition();
|
||||
state = STATE_READ_STREAM_MARKER;
|
||||
}
|
||||
|
||||
private void readStreamMarker(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private void readStreamMarker(ExtractorInput input) throws IOException {
|
||||
FlacMetadataReader.readStreamMarker(input);
|
||||
state = STATE_READ_METADATA_BLOCKS;
|
||||
}
|
||||
|
||||
private void readMetadataBlocks(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private void readMetadataBlocks(ExtractorInput input) throws IOException {
|
||||
boolean isLastMetadataBlock = false;
|
||||
FlacMetadataReader.FlacStreamMetadataHolder metadataHolder =
|
||||
new FlacMetadataReader.FlacStreamMetadataHolder(flacStreamMetadata);
|
||||
@ -226,7 +225,7 @@ public final class FlacExtractor implements Extractor {
|
||||
state = STATE_GET_FRAME_START_MARKER;
|
||||
}
|
||||
|
||||
private void getFrameStartMarker(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private void getFrameStartMarker(ExtractorInput input) throws IOException {
|
||||
frameStartMarker = FlacMetadataReader.getFrameStartMarker(input);
|
||||
castNonNull(extractorOutput)
|
||||
.seekMap(
|
||||
@ -238,7 +237,7 @@ public final class FlacExtractor implements Extractor {
|
||||
}
|
||||
|
||||
private @ReadResult int readFrames(ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
Assertions.checkNotNull(trackOutput);
|
||||
Assertions.checkNotNull(flacStreamMetadata);
|
||||
|
||||
|
@ -96,7 +96,7 @@ public final class FlvExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public boolean sniff(ExtractorInput input) throws IOException {
|
||||
// Check if file starts with "FLV" tag
|
||||
input.peekFully(scratch.data, 0, 3);
|
||||
scratch.setPosition(0);
|
||||
@ -144,8 +144,7 @@ public final class FlvExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException,
|
||||
InterruptedException {
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException {
|
||||
Assertions.checkStateNotNull(extractorOutput); // Asserts that init has been called.
|
||||
while (true) {
|
||||
switch (state) {
|
||||
@ -180,10 +179,9 @@ public final class FlvExtractor implements Extractor {
|
||||
* @param input The {@link ExtractorInput} from which to read.
|
||||
* @return True if header was read successfully. False if the end of stream was reached.
|
||||
* @throws IOException If an error occurred reading or parsing data from the source.
|
||||
* @throws InterruptedException If the thread was interrupted.
|
||||
*/
|
||||
@RequiresNonNull("extractorOutput")
|
||||
private boolean readFlvHeader(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private boolean readFlvHeader(ExtractorInput input) throws IOException {
|
||||
if (!input.readFully(headerBuffer.data, 0, FLV_HEADER_SIZE, true)) {
|
||||
// We've reached the end of the stream.
|
||||
return false;
|
||||
@ -215,9 +213,8 @@ public final class FlvExtractor implements Extractor {
|
||||
*
|
||||
* @param input The {@link ExtractorInput} from which to read.
|
||||
* @throws IOException If an error occurred skipping data from the source.
|
||||
* @throws InterruptedException If the thread was interrupted.
|
||||
*/
|
||||
private void skipToTagHeader(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private void skipToTagHeader(ExtractorInput input) throws IOException {
|
||||
input.skipFully(bytesToNextTagHeader);
|
||||
bytesToNextTagHeader = 0;
|
||||
state = STATE_READING_TAG_HEADER;
|
||||
@ -229,9 +226,8 @@ public final class FlvExtractor implements Extractor {
|
||||
* @param input The {@link ExtractorInput} from which to read.
|
||||
* @return True if tag header was read successfully. Otherwise, false.
|
||||
* @throws IOException If an error occurred reading or parsing data from the source.
|
||||
* @throws InterruptedException If the thread was interrupted.
|
||||
*/
|
||||
private boolean readTagHeader(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private boolean readTagHeader(ExtractorInput input) throws IOException {
|
||||
if (!input.readFully(tagHeaderBuffer.data, 0, FLV_TAG_HEADER_SIZE, true)) {
|
||||
// We've reached the end of the stream.
|
||||
return false;
|
||||
@ -253,10 +249,9 @@ public final class FlvExtractor implements Extractor {
|
||||
* @param input The {@link ExtractorInput} from which to read.
|
||||
* @return True if the data was consumed by a reader. False if it was skipped.
|
||||
* @throws IOException If an error occurred reading or parsing data from the source.
|
||||
* @throws InterruptedException If the thread was interrupted.
|
||||
*/
|
||||
@RequiresNonNull("extractorOutput")
|
||||
private boolean readTagData(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private boolean readTagData(ExtractorInput input) throws IOException {
|
||||
boolean wasConsumed = true;
|
||||
boolean wasSampleOutput = false;
|
||||
long timestampUs = getCurrentTimestampUs();
|
||||
@ -287,8 +282,7 @@ public final class FlvExtractor implements Extractor {
|
||||
return wasConsumed;
|
||||
}
|
||||
|
||||
private ParsableByteArray prepareTagData(ExtractorInput input) throws IOException,
|
||||
InterruptedException {
|
||||
private ParsableByteArray prepareTagData(ExtractorInput input) throws IOException {
|
||||
if (tagDataSize > tagData.capacity()) {
|
||||
tagData.reset(new byte[Math.max(tagData.capacity() * 2, tagDataSize)], 0);
|
||||
} else {
|
||||
|
@ -79,7 +79,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean read(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public boolean read(ExtractorInput input) throws IOException {
|
||||
Assertions.checkStateNotNull(processor);
|
||||
while (true) {
|
||||
MasterElement head = masterElementsStack.peek();
|
||||
@ -160,11 +160,9 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
* @throws EOFException If the end of input was encountered when searching for the next level 1
|
||||
* element.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
@RequiresNonNull("processor")
|
||||
private long maybeResyncToNextLevel1Element(ExtractorInput input)
|
||||
throws IOException, InterruptedException {
|
||||
private long maybeResyncToNextLevel1Element(ExtractorInput input) throws IOException {
|
||||
input.resetPeekPosition();
|
||||
while (true) {
|
||||
input.peekFully(scratch, 0, MAX_ID_BYTES);
|
||||
@ -187,10 +185,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
* @param byteLength The length of the integer being read.
|
||||
* @return The read integer value.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
private long readInteger(ExtractorInput input, int byteLength)
|
||||
throws IOException, InterruptedException {
|
||||
private long readInteger(ExtractorInput input, int byteLength) throws IOException {
|
||||
input.readFully(scratch, 0, byteLength);
|
||||
long value = 0;
|
||||
for (int i = 0; i < byteLength; i++) {
|
||||
@ -206,10 +202,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
* @param byteLength The length of the float being read.
|
||||
* @return The read float value.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
private double readFloat(ExtractorInput input, int byteLength)
|
||||
throws IOException, InterruptedException {
|
||||
private double readFloat(ExtractorInput input, int byteLength) throws IOException {
|
||||
long integerValue = readInteger(input, byteLength);
|
||||
double floatValue;
|
||||
if (byteLength == VALID_FLOAT32_ELEMENT_SIZE_BYTES) {
|
||||
@ -228,10 +222,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
* @param byteLength The length of the string being read, including zero padding.
|
||||
* @return The read string value.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
private String readString(ExtractorInput input, int byteLength)
|
||||
throws IOException, InterruptedException {
|
||||
private static String readString(ExtractorInput input, int byteLength) throws IOException {
|
||||
if (byteLength == 0) {
|
||||
return "";
|
||||
}
|
||||
|
@ -130,21 +130,18 @@ public interface EbmlProcessor {
|
||||
|
||||
/**
|
||||
* Called when a binary element is encountered.
|
||||
* <p>
|
||||
* The element header (containing the element ID and content size) will already have been read.
|
||||
* Implementations are required to consume the whole remainder of the element, which is
|
||||
* {@code contentSize} bytes in length, before returning. Implementations are permitted to fail
|
||||
* (by throwing an exception) having partially consumed the data, however if they do this, they
|
||||
* must consume the remainder of the content when called again.
|
||||
*
|
||||
* <p>The element header (containing the element ID and content size) will already have been read.
|
||||
* Implementations are required to consume the whole remainder of the element, which is {@code
|
||||
* contentSize} bytes in length, before returning. Implementations are permitted to fail (by
|
||||
* throwing an exception) having partially consumed the data, however if they do this, they must
|
||||
* consume the remainder of the content when called again.
|
||||
*
|
||||
* @param id The element ID.
|
||||
* @param contentsSize The element's content size.
|
||||
* @param input The {@link ExtractorInput} from which data should be read.
|
||||
* @throws ParserException If a parsing error occurs.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
void binaryElement(int id, int contentsSize, ExtractorInput input)
|
||||
throws IOException, InterruptedException;
|
||||
|
||||
void binaryElement(int id, int contentsSize, ExtractorInput input) throws IOException;
|
||||
}
|
||||
|
@ -50,8 +50,6 @@ import java.io.IOException;
|
||||
* @return True if data can continue to be read. False if the end of the input was encountered.
|
||||
* @throws ParserException If parsing fails.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
boolean read(ExtractorInput input) throws IOException, InterruptedException;
|
||||
|
||||
boolean read(ExtractorInput input) throws IOException;
|
||||
}
|
||||
|
@ -420,7 +420,7 @@ public class MatroskaExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public final boolean sniff(ExtractorInput input) throws IOException {
|
||||
return new Sniffer().sniff(input);
|
||||
}
|
||||
|
||||
@ -448,8 +448,7 @@ public class MatroskaExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int read(ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException, InterruptedException {
|
||||
public final int read(ExtractorInput input, PositionHolder seekPosition) throws IOException {
|
||||
haveOutputSample = false;
|
||||
boolean continueReading = true;
|
||||
while (continueReading && !haveOutputSample) {
|
||||
@ -1051,8 +1050,7 @@ public class MatroskaExtractor implements Extractor {
|
||||
* @see EbmlProcessor#binaryElement(int, int, ExtractorInput)
|
||||
*/
|
||||
@CallSuper
|
||||
protected void binaryElement(int id, int contentSize, ExtractorInput input)
|
||||
throws IOException, InterruptedException {
|
||||
protected void binaryElement(int id, int contentSize, ExtractorInput input) throws IOException {
|
||||
switch (id) {
|
||||
case ID_SEEK_ID:
|
||||
Arrays.fill(seekEntryIdBytes.data, (byte) 0);
|
||||
@ -1231,7 +1229,7 @@ public class MatroskaExtractor implements Extractor {
|
||||
|
||||
protected void handleBlockAdditionalData(
|
||||
Track track, int blockAdditionalId, ExtractorInput input, int contentSize)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
if (blockAdditionalId == BLOCK_ADDITIONAL_ID_VP9_ITU_T_35
|
||||
&& CODEC_ID_VP9.equals(track.codecId)) {
|
||||
blockAdditionalData.reset(contentSize);
|
||||
@ -1282,8 +1280,7 @@ public class MatroskaExtractor implements Extractor {
|
||||
* Ensures {@link #scratch} contains at least {@code requiredLength} bytes of data, reading from
|
||||
* the extractor input if necessary.
|
||||
*/
|
||||
private void readScratch(ExtractorInput input, int requiredLength)
|
||||
throws IOException, InterruptedException {
|
||||
private void readScratch(ExtractorInput input, int requiredLength) throws IOException {
|
||||
if (scratch.limit() >= requiredLength) {
|
||||
return;
|
||||
}
|
||||
@ -1303,10 +1300,8 @@ public class MatroskaExtractor implements Extractor {
|
||||
* @param size The size of the sample data on the input side.
|
||||
* @return The final size of the written sample.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
private int writeSampleData(ExtractorInput input, Track track, int size)
|
||||
throws IOException, InterruptedException {
|
||||
private int writeSampleData(ExtractorInput input, Track track, int size) throws IOException {
|
||||
if (CODEC_ID_SUBRIP.equals(track.codecId)) {
|
||||
writeSubtitleSampleData(input, SUBRIP_PREFIX, size);
|
||||
return finishWriteSampleData();
|
||||
@ -1506,7 +1501,7 @@ public class MatroskaExtractor implements Extractor {
|
||||
}
|
||||
|
||||
private void writeSubtitleSampleData(ExtractorInput input, byte[] samplePrefix, int size)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
int sizeWithPrefix = samplePrefix.length + size;
|
||||
if (subtitleSample.capacity() < sizeWithPrefix) {
|
||||
// Initialize subripSample to contain the required prefix and have space to hold a subtitle
|
||||
@ -1581,7 +1576,7 @@ public class MatroskaExtractor implements Extractor {
|
||||
* pending {@link #sampleStrippedBytes} and any remaining data read from {@code input}.
|
||||
*/
|
||||
private void writeToTarget(ExtractorInput input, byte[] target, int offset, int length)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
int pendingStrippedBytes = Math.min(length, sampleStrippedBytes.bytesLeft());
|
||||
input.readFully(target, offset + pendingStrippedBytes, length - pendingStrippedBytes);
|
||||
if (pendingStrippedBytes > 0) {
|
||||
@ -1594,7 +1589,7 @@ public class MatroskaExtractor implements Extractor {
|
||||
* {@link #sampleStrippedBytes} or data read from {@code input}.
|
||||
*/
|
||||
private int writeToOutput(ExtractorInput input, TrackOutput output, int length)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
int bytesWritten;
|
||||
int strippedBytesLeft = sampleStrippedBytes.bytesLeft();
|
||||
if (strippedBytesLeft > 0) {
|
||||
@ -1774,8 +1769,7 @@ public class MatroskaExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void binaryElement(int id, int contentsSize, ExtractorInput input)
|
||||
throws IOException, InterruptedException {
|
||||
public void binaryElement(int id, int contentsSize, ExtractorInput input) throws IOException {
|
||||
MatroskaExtractor.this.binaryElement(id, contentsSize, input);
|
||||
}
|
||||
}
|
||||
@ -1803,7 +1797,7 @@ public class MatroskaExtractor implements Extractor {
|
||||
chunkSampleCount = 0;
|
||||
}
|
||||
|
||||
public void startSample(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public void startSample(ExtractorInput input) throws IOException {
|
||||
if (foundSyncframe) {
|
||||
return;
|
||||
}
|
||||
|
@ -39,10 +39,8 @@ import java.io.IOException;
|
||||
scratch = new ParsableByteArray(8);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.google.android.exoplayer2.extractor.Extractor#sniff(ExtractorInput)
|
||||
*/
|
||||
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
||||
/** @see com.google.android.exoplayer2.extractor.Extractor#sniff(ExtractorInput) */
|
||||
public boolean sniff(ExtractorInput input) throws IOException {
|
||||
long inputLength = input.getLength();
|
||||
int bytesToSearch = (int) (inputLength == C.LENGTH_UNSET || inputLength > SEARCH_LENGTH
|
||||
? SEARCH_LENGTH : inputLength);
|
||||
@ -86,10 +84,8 @@ import java.io.IOException;
|
||||
return peekLength == headerStart + headerSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Peeks a variable-length unsigned EBML integer from the input.
|
||||
*/
|
||||
private long readUint(ExtractorInput input) throws IOException, InterruptedException {
|
||||
/** Peeks a variable-length unsigned EBML integer from the input. */
|
||||
private long readUint(ExtractorInput input) throws IOException {
|
||||
input.peekFully(scratch.data, 0, 1);
|
||||
int value = scratch.data[0] & 0xFF;
|
||||
if (value == 0) {
|
||||
|
@ -56,15 +56,15 @@ import java.io.IOException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an EBML variable-length integer (varint) from an {@link ExtractorInput} such that
|
||||
* reading can be resumed later if an error occurs having read only some of it.
|
||||
* <p>
|
||||
* If an value is successfully read, then the reader will automatically reset itself ready to
|
||||
* Reads an EBML variable-length integer (varint) from an {@link ExtractorInput} such that reading
|
||||
* can be resumed later if an error occurs having read only some of it.
|
||||
*
|
||||
* <p>If an value is successfully read, then the reader will automatically reset itself ready to
|
||||
* read another value.
|
||||
* <p>
|
||||
* If an {@link IOException} or {@link InterruptedException} is throw, the read can be resumed
|
||||
* later by calling this method again, passing an {@link ExtractorInput} providing data starting
|
||||
* where the previous one left off.
|
||||
*
|
||||
* <p>If an {@link IOException} is thrown, the read can be resumed later by calling this method
|
||||
* again, passing an {@link ExtractorInput} providing data starting where the previous one left
|
||||
* off.
|
||||
*
|
||||
* @param input The {@link ExtractorInput} from which the integer should be read.
|
||||
* @param allowEndOfInput True if encountering the end of the input having read no data is
|
||||
@ -76,10 +76,13 @@ import java.io.IOException;
|
||||
* and the end of the input was encountered, or {@link C#RESULT_MAX_LENGTH_EXCEEDED} if the
|
||||
* length of the varint exceeded maximumAllowedLength.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
public long readUnsignedVarint(ExtractorInput input, boolean allowEndOfInput,
|
||||
boolean removeLengthMask, int maximumAllowedLength) throws IOException, InterruptedException {
|
||||
public long readUnsignedVarint(
|
||||
ExtractorInput input,
|
||||
boolean allowEndOfInput,
|
||||
boolean removeLengthMask,
|
||||
int maximumAllowedLength)
|
||||
throws IOException {
|
||||
if (state == STATE_BEGIN_READING) {
|
||||
// Read the first byte to establish the length.
|
||||
if (!input.readFully(scratch, 0, 1, allowEndOfInput)) {
|
||||
|
@ -182,7 +182,7 @@ public final class Mp3Extractor implements Extractor {
|
||||
// Extractor implementation.
|
||||
|
||||
@Override
|
||||
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public boolean sniff(ExtractorInput input) throws IOException {
|
||||
return synchronize(input, true);
|
||||
}
|
||||
|
||||
@ -213,8 +213,7 @@ public final class Mp3Extractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException, InterruptedException {
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException {
|
||||
assertInitialized();
|
||||
int readResult = readInternal(input);
|
||||
if (readResult == RESULT_END_OF_INPUT && seeker instanceof IndexSeeker) {
|
||||
@ -240,7 +239,7 @@ public final class Mp3Extractor implements Extractor {
|
||||
// Internal methods.
|
||||
|
||||
@RequiresNonNull({"extractorOutput", "currentTrackOutput", "realTrackOutput"})
|
||||
private int readInternal(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private int readInternal(ExtractorInput input) throws IOException {
|
||||
if (synchronizedHeaderData == 0) {
|
||||
try {
|
||||
synchronize(input, false);
|
||||
@ -273,7 +272,7 @@ public final class Mp3Extractor implements Extractor {
|
||||
}
|
||||
|
||||
@RequiresNonNull({"currentTrackOutput", "realTrackOutput", "seeker"})
|
||||
private int readSample(ExtractorInput extractorInput) throws IOException, InterruptedException {
|
||||
private int readSample(ExtractorInput extractorInput) throws IOException {
|
||||
if (sampleBytesRemaining == 0) {
|
||||
extractorInput.resetPeekPosition();
|
||||
if (peekEndOfStreamOrHeader(extractorInput)) {
|
||||
@ -329,8 +328,7 @@ public final class Mp3Extractor implements Extractor {
|
||||
return basisTimeUs + samplesRead * C.MICROS_PER_SECOND / synchronizedHeader.sampleRate;
|
||||
}
|
||||
|
||||
private boolean synchronize(ExtractorInput input, boolean sniffing)
|
||||
throws IOException, InterruptedException {
|
||||
private boolean synchronize(ExtractorInput input, boolean sniffing) throws IOException {
|
||||
int validFrameCount = 0;
|
||||
int candidateSynchronizedHeaderData = 0;
|
||||
int peekedId3Bytes = 0;
|
||||
@ -407,8 +405,7 @@ public final class Mp3Extractor implements Extractor {
|
||||
* Returns whether the extractor input is peeking the end of the stream. If {@code false},
|
||||
* populates the scratch buffer with the next four bytes.
|
||||
*/
|
||||
private boolean peekEndOfStreamOrHeader(ExtractorInput extractorInput)
|
||||
throws IOException, InterruptedException {
|
||||
private boolean peekEndOfStreamOrHeader(ExtractorInput extractorInput) throws IOException {
|
||||
if (seeker != null) {
|
||||
long dataEndPosition = seeker.getDataEndPosition();
|
||||
if (dataEndPosition != C.POSITION_UNSET
|
||||
@ -424,7 +421,7 @@ public final class Mp3Extractor implements Extractor {
|
||||
}
|
||||
}
|
||||
|
||||
private Seeker computeSeeker(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private Seeker computeSeeker(ExtractorInput input) throws IOException {
|
||||
// Read past any seek frame and set the seeker based on metadata or a seek frame. Metadata
|
||||
// takes priority as it can provide greater precision.
|
||||
Seeker seekFrameSeeker = maybeReadSeekFrame(input);
|
||||
@ -471,11 +468,9 @@ public final class Mp3Extractor implements Extractor {
|
||||
* @return A {@link Seeker} if seeking metadata was present and valid, or {@code null} otherwise.
|
||||
* @throws IOException Thrown if there was an error reading from the stream. Not expected if the
|
||||
* next two frames were already peeked during synchronization.
|
||||
* @throws InterruptedException Thrown if reading from the stream was interrupted. Not expected if
|
||||
* the next two frames were already peeked during synchronization.
|
||||
*/
|
||||
@Nullable
|
||||
private Seeker maybeReadSeekFrame(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private Seeker maybeReadSeekFrame(ExtractorInput input) throws IOException {
|
||||
ParsableByteArray frame = new ParsableByteArray(synchronizedHeader.frameSize);
|
||||
input.peekFully(frame.data, 0, synchronizedHeader.frameSize);
|
||||
int xingBase = (synchronizedHeader.version & 1) != 0
|
||||
@ -509,11 +504,8 @@ public final class Mp3Extractor implements Extractor {
|
||||
return seeker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Peeks the next frame and returns a {@link ConstantBitrateSeeker} based on its bitrate.
|
||||
*/
|
||||
private Seeker getConstantBitrateSeeker(ExtractorInput input)
|
||||
throws IOException, InterruptedException {
|
||||
/** Peeks the next frame and returns a {@link ConstantBitrateSeeker} based on its bitrate. */
|
||||
private Seeker getConstantBitrateSeeker(ExtractorInput input) throws IOException {
|
||||
input.peekFully(scratch.data, 0, 4);
|
||||
scratch.setPosition(0);
|
||||
synchronizedHeader.setForHeaderData(scratch.readInt());
|
||||
|
@ -268,7 +268,7 @@ public class FragmentedMp4Extractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public boolean sniff(ExtractorInput input) throws IOException {
|
||||
return Sniffer.sniffFragmented(input);
|
||||
}
|
||||
|
||||
@ -303,8 +303,7 @@ public class FragmentedMp4Extractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException, InterruptedException {
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException {
|
||||
while (true) {
|
||||
switch (parserState) {
|
||||
case STATE_READING_ATOM_HEADER:
|
||||
@ -331,7 +330,7 @@ public class FragmentedMp4Extractor implements Extractor {
|
||||
atomHeaderBytesRead = 0;
|
||||
}
|
||||
|
||||
private boolean readAtomHeader(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private boolean readAtomHeader(ExtractorInput input) throws IOException {
|
||||
if (atomHeaderBytesRead == 0) {
|
||||
// Read the standard length atom header.
|
||||
if (!input.readFully(atomHeader.data, 0, Atom.HEADER_SIZE, true)) {
|
||||
@ -419,7 +418,7 @@ public class FragmentedMp4Extractor implements Extractor {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void readAtomPayload(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private void readAtomPayload(ExtractorInput input) throws IOException {
|
||||
int atomPayloadSize = (int) atomSize - atomHeaderBytesRead;
|
||||
if (atomData != null) {
|
||||
input.readFully(atomData.data, Atom.HEADER_SIZE, atomPayloadSize);
|
||||
@ -1170,7 +1169,7 @@ public class FragmentedMp4Extractor implements Extractor {
|
||||
new ChunkIndex(sizes, offsets, durationsUs, timesUs));
|
||||
}
|
||||
|
||||
private void readEncryptionData(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private void readEncryptionData(ExtractorInput input) throws IOException {
|
||||
TrackBundle nextTrackBundle = null;
|
||||
long nextDataOffset = Long.MAX_VALUE;
|
||||
int trackBundlesSize = trackBundles.size();
|
||||
@ -1208,9 +1207,8 @@ public class FragmentedMp4Extractor implements Extractor {
|
||||
* @return Whether a sample was read. The read sample may have been output or skipped. False
|
||||
* indicates that there are no samples left to read in the current mdat.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
private boolean readSample(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private boolean readSample(ExtractorInput input) throws IOException {
|
||||
if (parserState == STATE_READING_SAMPLE_START) {
|
||||
if (currentTrackBundle == null) {
|
||||
@Nullable TrackBundle currentTrackBundle = getNextFragmentRun(trackBundles);
|
||||
|
@ -146,7 +146,7 @@ public final class Mp4Extractor implements Extractor, SeekMap {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public boolean sniff(ExtractorInput input) throws IOException {
|
||||
return Sniffer.sniffUnfragmented(input);
|
||||
}
|
||||
|
||||
@ -176,8 +176,7 @@ public final class Mp4Extractor implements Extractor, SeekMap {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException, InterruptedException {
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException {
|
||||
while (true) {
|
||||
switch (parserState) {
|
||||
case STATE_READING_ATOM_HEADER:
|
||||
@ -270,7 +269,7 @@ public final class Mp4Extractor implements Extractor, SeekMap {
|
||||
atomHeaderBytesRead = 0;
|
||||
}
|
||||
|
||||
private boolean readAtomHeader(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private boolean readAtomHeader(ExtractorInput input) throws IOException {
|
||||
if (atomHeaderBytesRead == 0) {
|
||||
// Read the standard length atom header.
|
||||
if (!input.readFully(atomHeader.data, 0, Atom.HEADER_SIZE, true)) {
|
||||
@ -341,7 +340,7 @@ public final class Mp4Extractor implements Extractor, SeekMap {
|
||||
* restart loading at the position in {@code positionHolder}. Otherwise, the atom is read/skipped.
|
||||
*/
|
||||
private boolean readAtomPayload(ExtractorInput input, PositionHolder positionHolder)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
long atomPayloadSize = atomSize - atomHeaderBytesRead;
|
||||
long atomEndPosition = input.getPosition() + atomPayloadSize;
|
||||
boolean seekRequired = false;
|
||||
@ -485,22 +484,20 @@ public final class Mp4Extractor implements Extractor, SeekMap {
|
||||
|
||||
/**
|
||||
* Attempts to extract the next sample in the current mdat atom for the specified track.
|
||||
* <p>
|
||||
* Returns {@link #RESULT_SEEK} if the source should be reloaded from the position in
|
||||
* {@code positionHolder}.
|
||||
* <p>
|
||||
* Returns {@link #RESULT_END_OF_INPUT} if no samples are left. Otherwise, returns
|
||||
* {@link #RESULT_CONTINUE}.
|
||||
*
|
||||
* <p>Returns {@link #RESULT_SEEK} if the source should be reloaded from the position in {@code
|
||||
* positionHolder}.
|
||||
*
|
||||
* <p>Returns {@link #RESULT_END_OF_INPUT} if no samples are left. Otherwise, returns {@link
|
||||
* #RESULT_CONTINUE}.
|
||||
*
|
||||
* @param input The {@link ExtractorInput} from which to read data.
|
||||
* @param positionHolder If {@link #RESULT_SEEK} is returned, this holder is updated to hold the
|
||||
* position of the required data.
|
||||
* @return One of the {@code RESULT_*} flags in {@link Extractor}.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
private int readSample(ExtractorInput input, PositionHolder positionHolder)
|
||||
throws IOException, InterruptedException {
|
||||
private int readSample(ExtractorInput input, PositionHolder positionHolder) throws IOException {
|
||||
long inputPosition = input.getPosition();
|
||||
if (sampleTrackIndex == C.INDEX_UNSET) {
|
||||
sampleTrackIndex = getTrackIndexOfNextReadSample(inputPosition);
|
||||
@ -663,8 +660,7 @@ public final class Mp4Extractor implements Extractor, SeekMap {
|
||||
* we can't rely on the file type though. Instead we must check the 8 bytes after the common
|
||||
* header bytes ourselves.
|
||||
*/
|
||||
private void maybeSkipRemainingMetaAtomHeaderBytes(ExtractorInput input)
|
||||
throws IOException, InterruptedException {
|
||||
private void maybeSkipRemainingMetaAtomHeaderBytes(ExtractorInput input) throws IOException {
|
||||
scratch.reset(8);
|
||||
// Peek the next 8 bytes which can be either
|
||||
// (iso) [1 byte version + 3 bytes flags][4 byte size of next atom]
|
||||
|
@ -66,10 +66,8 @@ import java.io.IOException;
|
||||
* @param input The extractor input from which to peek data. The peek position will be modified.
|
||||
* @return Whether the input appears to be in the fragmented MP4 format.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread has been interrupted.
|
||||
*/
|
||||
public static boolean sniffFragmented(ExtractorInput input)
|
||||
throws IOException, InterruptedException {
|
||||
public static boolean sniffFragmented(ExtractorInput input) throws IOException {
|
||||
return sniffInternal(input, true);
|
||||
}
|
||||
|
||||
@ -80,15 +78,13 @@ import java.io.IOException;
|
||||
* @param input The extractor input from which to peek data. The peek position will be modified.
|
||||
* @return Whether the input appears to be in the unfragmented MP4 format.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread has been interrupted.
|
||||
*/
|
||||
public static boolean sniffUnfragmented(ExtractorInput input)
|
||||
throws IOException, InterruptedException {
|
||||
public static boolean sniffUnfragmented(ExtractorInput input) throws IOException {
|
||||
return sniffInternal(input, false);
|
||||
}
|
||||
|
||||
private static boolean sniffInternal(ExtractorInput input, boolean fragmented)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
long inputLength = input.getLength();
|
||||
int bytesToSearch = (int) (inputLength == C.LENGTH_UNSET || inputLength > SEARCH_LENGTH
|
||||
? SEARCH_LENGTH : inputLength);
|
||||
|
@ -169,7 +169,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
*
|
||||
* @param input An {@link ExtractorInput} from which to read the encryption data.
|
||||
*/
|
||||
public void fillEncryptionData(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public void fillEncryptionData(ExtractorInput input) throws IOException {
|
||||
input.readFully(sampleEncryptionData.data, 0, sampleEncryptionData.limit());
|
||||
sampleEncryptionData.setPosition(0);
|
||||
sampleEncryptionDataNeedsFill = false;
|
||||
|
@ -88,7 +88,7 @@ import java.io.IOException;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long read(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public long read(ExtractorInput input) throws IOException {
|
||||
switch (state) {
|
||||
case STATE_IDLE:
|
||||
return -1;
|
||||
@ -148,9 +148,8 @@ import java.io.IOException;
|
||||
* @return The byte position from which data should be provided for the next step, or {@link
|
||||
* C#POSITION_UNSET} if the search has converged.
|
||||
* @throws IOException If reading from the input fails.
|
||||
* @throws InterruptedException If interrupted while reading from the input.
|
||||
*/
|
||||
private long getNextSeekPosition(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private long getNextSeekPosition(ExtractorInput input) throws IOException {
|
||||
if (start == end) {
|
||||
return C.POSITION_UNSET;
|
||||
}
|
||||
@ -199,10 +198,8 @@ import java.io.IOException;
|
||||
* @param input The {@link ExtractorInput} to read from.
|
||||
* @throws ParserException If populating the page header fails.
|
||||
* @throws IOException If reading from the input fails.
|
||||
* @throws InterruptedException If interrupted while reading from the input.
|
||||
*/
|
||||
private void skipToPageOfTargetGranule(ExtractorInput input)
|
||||
throws IOException, InterruptedException {
|
||||
private void skipToPageOfTargetGranule(ExtractorInput input) throws IOException {
|
||||
pageHeader.populate(input, /* quiet= */ false);
|
||||
while (pageHeader.granulePosition <= targetGranule) {
|
||||
input.skipFully(pageHeader.headerSize + pageHeader.bodySize);
|
||||
@ -218,11 +215,10 @@ import java.io.IOException;
|
||||
*
|
||||
* @param input The {@code ExtractorInput} to skip to the next page.
|
||||
* @throws IOException If peeking/reading from the input fails.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
* @throws EOFException If the next page can't be found before the end of the input.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
void skipToNextPage(ExtractorInput input) throws IOException, InterruptedException {
|
||||
void skipToNextPage(ExtractorInput input) throws IOException {
|
||||
if (!skipToNextPage(input, payloadEndPosition)) {
|
||||
// Not found until eof.
|
||||
throw new EOFException();
|
||||
@ -236,10 +232,8 @@ import java.io.IOException;
|
||||
* @param limit The limit up to which the search should take place.
|
||||
* @return Whether the next page was found.
|
||||
* @throws IOException If peeking/reading from the input fails.
|
||||
* @throws InterruptedException If interrupted while peeking/reading from the input.
|
||||
*/
|
||||
private boolean skipToNextPage(ExtractorInput input, long limit)
|
||||
throws IOException, InterruptedException {
|
||||
private boolean skipToNextPage(ExtractorInput input, long limit) throws IOException {
|
||||
limit = Math.min(limit + 3, payloadEndPosition);
|
||||
byte[] buffer = new byte[2048];
|
||||
int peekLength = buffer.length;
|
||||
@ -275,10 +269,9 @@ import java.io.IOException;
|
||||
* @param input The {@link ExtractorInput} to read from.
|
||||
* @return The total number of samples of this input.
|
||||
* @throws IOException If reading from the input fails.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
long readGranuleOfLastPage(ExtractorInput input) throws IOException, InterruptedException {
|
||||
long readGranuleOfLastPage(ExtractorInput input) throws IOException {
|
||||
skipToNextPage(input);
|
||||
pageHeader.reset();
|
||||
while ((pageHeader.type & 0x04) != 0x04 && input.getPosition() < payloadEndPosition) {
|
||||
|
@ -44,7 +44,7 @@ public class OggExtractor implements Extractor {
|
||||
private boolean streamReaderInitialized;
|
||||
|
||||
@Override
|
||||
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public boolean sniff(ExtractorInput input) throws IOException {
|
||||
try {
|
||||
return sniffInternal(input);
|
||||
} catch (ParserException e) {
|
||||
@ -70,8 +70,7 @@ public class OggExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException, InterruptedException {
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException {
|
||||
Assertions.checkStateNotNull(output); // Asserts that init has been called.
|
||||
if (streamReader == null) {
|
||||
if (!sniffInternal(input)) {
|
||||
@ -89,7 +88,7 @@ public class OggExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@EnsuresNonNullIf(expression = "streamReader", result = true)
|
||||
private boolean sniffInternal(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private boolean sniffInternal(ExtractorInput input) throws IOException {
|
||||
OggPageHeader header = new OggPageHeader();
|
||||
if (!header.populate(input, true) || (header.type & 0x02) != 0x02) {
|
||||
return false;
|
||||
|
@ -55,9 +55,8 @@ import java.util.Arrays;
|
||||
* @return {@code true} if the read was successful. The read fails if the end of the input is
|
||||
* encountered without reading data.
|
||||
* @throws IOException If reading from the input fails.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
public boolean populate(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public boolean populate(ExtractorInput input) throws IOException {
|
||||
Assertions.checkState(input != null);
|
||||
|
||||
if (populated) {
|
||||
|
@ -82,10 +82,8 @@ import java.io.IOException;
|
||||
* @return Whether the read was successful. The read fails if the end of the input is encountered
|
||||
* without reading data.
|
||||
* @throws IOException If reading data fails or the stream is invalid.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
public boolean populate(ExtractorInput input, boolean quiet)
|
||||
throws IOException, InterruptedException {
|
||||
public boolean populate(ExtractorInput input, boolean quiet) throws IOException {
|
||||
scratch.reset();
|
||||
reset();
|
||||
boolean hasEnoughBytes = input.getLength() == C.LENGTH_UNSET
|
||||
|
@ -43,17 +43,15 @@ import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Reads data from the {@link ExtractorInput} to build the {@link SeekMap} or to continue a seek.
|
||||
* <p/>
|
||||
* If more data is required or if the position of the input needs to be modified then a position
|
||||
* from which data should be provided is returned. Else a negative value is returned. If a seek
|
||||
* has been completed then the value returned is -(currentGranule + 2). Else it is -1.
|
||||
*
|
||||
* <p>If more data is required or if the position of the input needs to be modified then a
|
||||
* position from which data should be provided is returned. Else a negative value is returned. If
|
||||
* a seek has been completed then the value returned is -(currentGranule + 2). Else it is -1.
|
||||
*
|
||||
* @param input The {@link ExtractorInput} to read from.
|
||||
* @return A non-negative position to seek the {@link ExtractorInput} to, or -(currentGranule + 2)
|
||||
* if the progressive seek has completed, or -1 otherwise.
|
||||
* @throws IOException If reading from the {@link ExtractorInput} fails.
|
||||
* @throws InterruptedException If the thread is interrupted.
|
||||
*/
|
||||
long read(ExtractorInput input) throws IOException, InterruptedException;
|
||||
|
||||
long read(ExtractorInput input) throws IOException;
|
||||
}
|
||||
|
@ -101,11 +101,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Extractor#read(ExtractorInput, PositionHolder)
|
||||
*/
|
||||
final int read(ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException, InterruptedException {
|
||||
/** @see Extractor#read(ExtractorInput, PositionHolder) */
|
||||
final int read(ExtractorInput input, PositionHolder seekPosition) throws IOException {
|
||||
switch (state) {
|
||||
case STATE_READ_HEADERS:
|
||||
return readHeaders(input);
|
||||
@ -121,7 +118,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
}
|
||||
}
|
||||
|
||||
private int readHeaders(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private int readHeaders(ExtractorInput input) throws IOException {
|
||||
boolean readingHeaders = true;
|
||||
while (readingHeaders) {
|
||||
if (!oggPacket.populate(input)) {
|
||||
@ -166,8 +163,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
return Extractor.RESULT_CONTINUE;
|
||||
}
|
||||
|
||||
private int readPayload(ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException, InterruptedException {
|
||||
private int readPayload(ExtractorInput input, PositionHolder seekPosition) throws IOException {
|
||||
long position = oggSeeker.read(input);
|
||||
if (position >= 0) {
|
||||
seekPosition.position = position;
|
||||
@ -238,8 +234,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
* @param setupData Setup data to be filled.
|
||||
* @return Whether the packet contains header data.
|
||||
*/
|
||||
protected abstract boolean readHeaders(ParsableByteArray packet, long position,
|
||||
SetupData setupData) throws IOException, InterruptedException;
|
||||
protected abstract boolean readHeaders(
|
||||
ParsableByteArray packet, long position, SetupData setupData) throws IOException;
|
||||
|
||||
/**
|
||||
* Called on end of seeking.
|
||||
|
@ -71,15 +71,14 @@ public final class RawCcExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public boolean sniff(ExtractorInput input) throws IOException {
|
||||
dataScratch.reset();
|
||||
input.peekFully(dataScratch.data, 0, HEADER_SIZE);
|
||||
return dataScratch.readInt() == HEADER_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException, InterruptedException {
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException {
|
||||
Assertions.checkStateNotNull(trackOutput); // Asserts that init has been called.
|
||||
while (true) {
|
||||
switch (parserState) {
|
||||
@ -118,7 +117,7 @@ public final class RawCcExtractor implements Extractor {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
private boolean parseHeader(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private boolean parseHeader(ExtractorInput input) throws IOException {
|
||||
dataScratch.reset();
|
||||
if (input.readFully(dataScratch.data, 0, HEADER_SIZE, true)) {
|
||||
if (dataScratch.readInt() != HEADER_ID) {
|
||||
@ -132,8 +131,7 @@ public final class RawCcExtractor implements Extractor {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean parseTimestampAndSampleCount(ExtractorInput input) throws IOException,
|
||||
InterruptedException {
|
||||
private boolean parseTimestampAndSampleCount(ExtractorInput input) throws IOException {
|
||||
dataScratch.reset();
|
||||
if (version == 0) {
|
||||
if (!input.readFully(dataScratch.data, 0, TIMESTAMP_SIZE_V0 + 1, true)) {
|
||||
@ -156,7 +154,7 @@ public final class RawCcExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@RequiresNonNull("trackOutput")
|
||||
private void parseSamples(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private void parseSamples(ExtractorInput input) throws IOException {
|
||||
for (; remainingSampleCount > 0; remainingSampleCount--) {
|
||||
dataScratch.reset();
|
||||
input.readFully(dataScratch.data, 0, 3);
|
||||
|
@ -61,7 +61,7 @@ public final class Ac3Extractor implements Extractor {
|
||||
// Extractor implementation.
|
||||
|
||||
@Override
|
||||
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public boolean sniff(ExtractorInput input) throws IOException {
|
||||
// Skip any ID3 headers.
|
||||
ParsableByteArray scratch = new ParsableByteArray(ID3_HEADER_LENGTH);
|
||||
int startPosition = 0;
|
||||
@ -124,8 +124,7 @@ public final class Ac3Extractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException,
|
||||
InterruptedException {
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException {
|
||||
int bytesRead = input.read(sampleData.data, 0, MAX_SYNC_FRAME_SIZE);
|
||||
if (bytesRead == C.RESULT_END_OF_INPUT) {
|
||||
return RESULT_END_OF_INPUT;
|
||||
|
@ -68,7 +68,7 @@ public final class Ac4Extractor implements Extractor {
|
||||
// Extractor implementation.
|
||||
|
||||
@Override
|
||||
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public boolean sniff(ExtractorInput input) throws IOException {
|
||||
// Skip any ID3 headers.
|
||||
ParsableByteArray scratch = new ParsableByteArray(ID3_HEADER_LENGTH);
|
||||
int startPosition = 0;
|
||||
@ -132,8 +132,7 @@ public final class Ac4Extractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException, InterruptedException {
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException {
|
||||
int bytesRead = input.read(sampleData.data, /* offset= */ 0, /* length= */ READ_BUFFER_SIZE);
|
||||
if (bytesRead == C.RESULT_END_OF_INPUT) {
|
||||
return RESULT_END_OF_INPUT;
|
||||
|
@ -120,7 +120,7 @@ public final class AdtsExtractor implements Extractor {
|
||||
// Extractor implementation.
|
||||
|
||||
@Override
|
||||
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public boolean sniff(ExtractorInput input) throws IOException {
|
||||
// Skip any ID3 headers.
|
||||
int startPosition = peekId3Header(input);
|
||||
|
||||
@ -179,8 +179,7 @@ public final class AdtsExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException, InterruptedException {
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException {
|
||||
Assertions.checkStateNotNull(extractorOutput); // Asserts that init has been called.
|
||||
|
||||
long inputLength = input.getLength();
|
||||
@ -212,7 +211,7 @@ public final class AdtsExtractor implements Extractor {
|
||||
return RESULT_CONTINUE;
|
||||
}
|
||||
|
||||
private int peekId3Header(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private int peekId3Header(ExtractorInput input) throws IOException {
|
||||
int firstFramePosition = 0;
|
||||
while (true) {
|
||||
input.peekFully(scratch.data, /* offset= */ 0, ID3_HEADER_LENGTH);
|
||||
@ -256,8 +255,7 @@ public final class AdtsExtractor implements Extractor {
|
||||
hasOutputSeekMap = true;
|
||||
}
|
||||
|
||||
private void calculateAverageFrameSize(ExtractorInput input)
|
||||
throws IOException, InterruptedException {
|
||||
private void calculateAverageFrameSize(ExtractorInput input) throws IOException {
|
||||
if (hasCalculatedAverageFrameSize) {
|
||||
return;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ import java.io.IOException;
|
||||
|
||||
@Override
|
||||
public TimestampSearchResult searchForTimestamp(ExtractorInput input, long targetTimestamp)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
long inputPosition = input.getPosition();
|
||||
int bytesToSearch = (int) Math.min(TIMESTAMP_SEARCH_BYTES, input.getLength() - inputPosition);
|
||||
|
||||
|
@ -81,11 +81,9 @@ import java.io.IOException;
|
||||
* to hold the position of the required seek.
|
||||
* @return One of the {@code RESULT_} values defined in {@link Extractor}.
|
||||
* @throws IOException If an error occurred reading from the input.
|
||||
* @throws InterruptedException If the thread was interrupted.
|
||||
*/
|
||||
public @Extractor.ReadResult int readDuration(
|
||||
ExtractorInput input, PositionHolder seekPositionHolder)
|
||||
throws IOException, InterruptedException {
|
||||
ExtractorInput input, PositionHolder seekPositionHolder) throws IOException {
|
||||
if (!isLastScrValueRead) {
|
||||
return readLastScrValue(input, seekPositionHolder);
|
||||
}
|
||||
@ -137,7 +135,7 @@ import java.io.IOException;
|
||||
}
|
||||
|
||||
private int readFirstScrValue(ExtractorInput input, PositionHolder seekPositionHolder)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
int bytesToSearch = (int) Math.min(TIMESTAMP_SEARCH_BYTES, input.getLength());
|
||||
int searchStartPosition = 0;
|
||||
if (input.getPosition() != searchStartPosition) {
|
||||
@ -173,7 +171,7 @@ import java.io.IOException;
|
||||
}
|
||||
|
||||
private int readLastScrValue(ExtractorInput input, PositionHolder seekPositionHolder)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
long inputLength = input.getLength();
|
||||
int bytesToSearch = (int) Math.min(TIMESTAMP_SEARCH_BYTES, inputLength);
|
||||
long searchStartPosition = inputLength - bytesToSearch;
|
||||
|
@ -89,7 +89,7 @@ public final class PsExtractor implements Extractor {
|
||||
// Extractor implementation.
|
||||
|
||||
@Override
|
||||
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public boolean sniff(ExtractorInput input) throws IOException {
|
||||
byte[] scratch = new byte[14];
|
||||
input.peekFully(scratch, 0, 14);
|
||||
|
||||
@ -162,8 +162,7 @@ public final class PsExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException, InterruptedException {
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException {
|
||||
Assertions.checkStateNotNull(output); // Asserts init has been called.
|
||||
|
||||
long inputLength = input.getLength();
|
||||
|
@ -74,7 +74,7 @@ import java.io.IOException;
|
||||
|
||||
@Override
|
||||
public TimestampSearchResult searchForTimestamp(ExtractorInput input, long targetTimestamp)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
long inputPosition = input.getPosition();
|
||||
int bytesToSearch = (int) Math.min(TIMESTAMP_SEARCH_BYTES, input.getLength() - inputPosition);
|
||||
|
||||
|
@ -74,11 +74,9 @@ import java.io.IOException;
|
||||
* @param pcrPid The PID of the packet stream within this TS stream that contains PCR values.
|
||||
* @return One of the {@code RESULT_} values defined in {@link Extractor}.
|
||||
* @throws IOException If an error occurred reading from the input.
|
||||
* @throws InterruptedException If the thread was interrupted.
|
||||
*/
|
||||
public @Extractor.ReadResult int readDuration(
|
||||
ExtractorInput input, PositionHolder seekPositionHolder, int pcrPid)
|
||||
throws IOException, InterruptedException {
|
||||
ExtractorInput input, PositionHolder seekPositionHolder, int pcrPid) throws IOException {
|
||||
if (pcrPid <= 0) {
|
||||
return finishReadDuration(input);
|
||||
}
|
||||
@ -124,7 +122,7 @@ import java.io.IOException;
|
||||
}
|
||||
|
||||
private int readFirstPcrValue(ExtractorInput input, PositionHolder seekPositionHolder, int pcrPid)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
int bytesToSearch = (int) Math.min(TIMESTAMP_SEARCH_BYTES, input.getLength());
|
||||
int searchStartPosition = 0;
|
||||
if (input.getPosition() != searchStartPosition) {
|
||||
@ -159,7 +157,7 @@ import java.io.IOException;
|
||||
}
|
||||
|
||||
private int readLastPcrValue(ExtractorInput input, PositionHolder seekPositionHolder, int pcrPid)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
long inputLength = input.getLength();
|
||||
int bytesToSearch = (int) Math.min(TIMESTAMP_SEARCH_BYTES, inputLength);
|
||||
long searchStartPosition = inputLength - bytesToSearch;
|
||||
|
@ -190,7 +190,7 @@ public final class TsExtractor implements Extractor {
|
||||
// Extractor implementation.
|
||||
|
||||
@Override
|
||||
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public boolean sniff(ExtractorInput input) throws IOException {
|
||||
byte[] buffer = tsPacketBuffer.data;
|
||||
input.peekFully(buffer, 0, TS_PACKET_SIZE * SNIFF_TS_PACKET_COUNT);
|
||||
for (int startPosCandidate = 0; startPosCandidate < TS_PACKET_SIZE; startPosCandidate++) {
|
||||
@ -253,7 +253,7 @@ public final class TsExtractor implements Extractor {
|
||||
|
||||
@Override
|
||||
public @ReadResult int read(ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
long inputLength = input.getLength();
|
||||
if (tracksEnded) {
|
||||
boolean canReadDuration = inputLength != C.LENGTH_UNSET && mode != MODE_HLS;
|
||||
@ -372,8 +372,7 @@ public final class TsExtractor implements Extractor {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean fillBufferWithAtLeastOnePacket(ExtractorInput input)
|
||||
throws IOException, InterruptedException {
|
||||
private boolean fillBufferWithAtLeastOnePacket(ExtractorInput input) throws IOException {
|
||||
byte[] data = tsPacketBuffer.data;
|
||||
// Shift bytes to the start of the buffer if there isn't enough space left at the end.
|
||||
if (BUFFER_SIZE - tsPacketBuffer.getPosition() < TS_PACKET_SIZE) {
|
||||
|
@ -61,7 +61,7 @@ public final class WavExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public boolean sniff(ExtractorInput input) throws IOException {
|
||||
return WavHeaderReader.peek(input) != null;
|
||||
}
|
||||
|
||||
@ -85,8 +85,7 @@ public final class WavExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException, InterruptedException {
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException {
|
||||
assertInitialized();
|
||||
if (outputWriter == null) {
|
||||
WavHeader header = WavHeaderReader.peek(input);
|
||||
@ -176,10 +175,8 @@ public final class WavExtractor implements Extractor {
|
||||
* @param bytesLeft The number of sample data bytes left to be read from the input.
|
||||
* @return Whether the end of the sample data has been reached.
|
||||
* @throws IOException If an error occurs reading from the input.
|
||||
* @throws InterruptedException If the thread has been interrupted.
|
||||
*/
|
||||
boolean sampleData(ExtractorInput input, long bytesLeft)
|
||||
throws IOException, InterruptedException;
|
||||
boolean sampleData(ExtractorInput input, long bytesLeft) throws IOException;
|
||||
}
|
||||
|
||||
private static final class PassthroughOutputWriter implements OutputWriter {
|
||||
@ -253,8 +250,7 @@ public final class WavExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sampleData(ExtractorInput input, long bytesLeft)
|
||||
throws IOException, InterruptedException {
|
||||
public boolean sampleData(ExtractorInput input, long bytesLeft) throws IOException {
|
||||
// Write sample data until we've reached the target sample size, or the end of the data.
|
||||
boolean endOfSampleData = bytesLeft == 0;
|
||||
while (!endOfSampleData && pendingOutputBytes < targetSampleSizeBytes) {
|
||||
@ -397,8 +393,7 @@ public final class WavExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sampleData(ExtractorInput input, long bytesLeft)
|
||||
throws IOException, InterruptedException {
|
||||
public boolean sampleData(ExtractorInput input, long bytesLeft) throws IOException {
|
||||
// Calculate the number of additional frames that we need on the output side to complete a
|
||||
// sample of the target size.
|
||||
int targetFramesRemaining =
|
||||
|
@ -38,12 +38,11 @@ import java.io.IOException;
|
||||
* @param input Input stream to peek the WAV header from.
|
||||
* @throws ParserException If the input file is an incorrect RIFF WAV.
|
||||
* @throws IOException If peeking from the input fails.
|
||||
* @throws InterruptedException If interrupted while peeking from input.
|
||||
* @return A new {@code WavHeader} peeked from {@code input}, or null if the input is not a
|
||||
* supported WAV format.
|
||||
*/
|
||||
@Nullable
|
||||
public static WavHeader peek(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public static WavHeader peek(ExtractorInput input) throws IOException {
|
||||
Assertions.checkNotNull(input);
|
||||
|
||||
// Allocate a scratch buffer large enough to store the format chunk.
|
||||
@ -108,10 +107,8 @@ import java.io.IOException;
|
||||
* @return The byte positions at which the data starts (inclusive) and ends (exclusive).
|
||||
* @throws ParserException If an error occurs parsing chunks.
|
||||
* @throws IOException If reading from the input fails.
|
||||
* @throws InterruptedException If interrupted while reading from input.
|
||||
*/
|
||||
public static Pair<Long, Long> skipToData(ExtractorInput input)
|
||||
throws IOException, InterruptedException {
|
||||
public static Pair<Long, Long> skipToData(ExtractorInput input) throws IOException {
|
||||
Assertions.checkNotNull(input);
|
||||
|
||||
// Make sure the peek position is set to the read position before we peek the first header.
|
||||
@ -174,11 +171,10 @@ import java.io.IOException;
|
||||
* @param input Input stream to peek the chunk header from.
|
||||
* @param scratch Buffer for temporary use.
|
||||
* @throws IOException If peeking from the input fails.
|
||||
* @throws InterruptedException If interrupted while peeking from input.
|
||||
* @return A new {@code ChunkHeader} peeked from {@code input}.
|
||||
*/
|
||||
public static ChunkHeader peek(ExtractorInput input, ParsableByteArray scratch)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
input.peekFully(scratch.data, /* offset= */ 0, /* length= */ SIZE_IN_BYTES);
|
||||
scratch.setPosition(0);
|
||||
|
||||
|
@ -307,8 +307,7 @@ public class FlacFrameReaderTest {
|
||||
}
|
||||
|
||||
private ExtractorInput buildExtractorInputReadingFromFirstFrame(
|
||||
String file, FlacStreamMetadataHolder streamMetadataHolder)
|
||||
throws IOException, InterruptedException {
|
||||
String file, FlacStreamMetadataHolder streamMetadataHolder) throws IOException {
|
||||
ExtractorInput input = buildExtractorInput(file);
|
||||
|
||||
input.skipFully(FlacConstants.STREAM_MARKER_SIZE);
|
||||
|
@ -35,8 +35,7 @@ import org.junit.runner.RunWith;
|
||||
public final class Id3PeekerTest {
|
||||
|
||||
@Test
|
||||
public void peekId3Data_returnNull_ifId3TagNotPresentAtBeginningOfInput()
|
||||
throws IOException, InterruptedException {
|
||||
public void peekId3Data_returnNull_ifId3TagNotPresentAtBeginningOfInput() throws IOException {
|
||||
Id3Peeker id3Peeker = new Id3Peeker();
|
||||
FakeExtractorInput input =
|
||||
new FakeExtractorInput.Builder()
|
||||
@ -48,7 +47,7 @@ public final class Id3PeekerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void peekId3Data_returnId3Tag_ifId3TagPresent() throws IOException, InterruptedException {
|
||||
public void peekId3Data_returnId3Tag_ifId3TagPresent() throws IOException {
|
||||
Id3Peeker id3Peeker = new Id3Peeker();
|
||||
FakeExtractorInput input =
|
||||
new FakeExtractorInput.Builder()
|
||||
@ -69,7 +68,7 @@ public final class Id3PeekerTest {
|
||||
|
||||
@Test
|
||||
public void peekId3Data_returnId3TagAccordingToGivenPredicate_ifId3TagPresent()
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
Id3Peeker id3Peeker = new Id3Peeker();
|
||||
FakeExtractorInput input =
|
||||
new FakeExtractorInput.Builder()
|
||||
|
@ -56,8 +56,7 @@ public final class AmrExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void amrExtractorReads_returnSeekableSeekMap_forNarrowBandAmr()
|
||||
throws IOException, InterruptedException {
|
||||
public void amrExtractorReads_returnSeekableSeekMap_forNarrowBandAmr() throws IOException {
|
||||
String fileName = NARROW_BAND_AMR_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
expectedTrackOutput =
|
||||
@ -77,7 +76,7 @@ public final class AmrExtractorSeekTest {
|
||||
|
||||
@Test
|
||||
public void seeking_handlesSeekingToPositionInFile_extractsCorrectFrame_forNarrowBandAmr()
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
String fileName = NARROW_BAND_AMR_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
expectedTrackOutput =
|
||||
@ -103,8 +102,7 @@ public final class AmrExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_handlesSeekToEoF_extractsLastFrame_forNarrowBandAmr()
|
||||
throws IOException, InterruptedException {
|
||||
public void seeking_handlesSeekToEoF_extractsLastFrame_forNarrowBandAmr() throws IOException {
|
||||
String fileName = NARROW_BAND_AMR_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
expectedTrackOutput =
|
||||
@ -131,7 +129,7 @@ public final class AmrExtractorSeekTest {
|
||||
|
||||
@Test
|
||||
public void seeking_handlesSeekingBackward_extractsCorrectFrames_forNarrowBandAmr()
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
String fileName = NARROW_BAND_AMR_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
expectedTrackOutput =
|
||||
@ -160,7 +158,7 @@ public final class AmrExtractorSeekTest {
|
||||
|
||||
@Test
|
||||
public void seeking_handlesSeekingForward_extractsCorrectFrames_forNarrowBandAmr()
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
String fileName = NARROW_BAND_AMR_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
expectedTrackOutput =
|
||||
@ -189,7 +187,7 @@ public final class AmrExtractorSeekTest {
|
||||
|
||||
@Test
|
||||
public void seeking_handlesRandomSeeks_extractsCorrectFrames_forNarrowBandAmr()
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
String fileName = NARROW_BAND_AMR_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
expectedTrackOutput =
|
||||
@ -217,8 +215,7 @@ public final class AmrExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void amrExtractorReads_returnSeekableSeekMap_forWideBandAmr()
|
||||
throws IOException, InterruptedException {
|
||||
public void amrExtractorReads_returnSeekableSeekMap_forWideBandAmr() throws IOException {
|
||||
String fileName = WIDE_BAND_AMR_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
expectedTrackOutput =
|
||||
@ -238,7 +235,7 @@ public final class AmrExtractorSeekTest {
|
||||
|
||||
@Test
|
||||
public void seeking_handlesSeekingToPositionInFile_extractsCorrectFrame_forWideBandAmr()
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
String fileName = WIDE_BAND_AMR_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
expectedTrackOutput =
|
||||
@ -264,8 +261,7 @@ public final class AmrExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_handlesSeekToEoF_extractsLastFrame_forWideBandAmr()
|
||||
throws IOException, InterruptedException {
|
||||
public void seeking_handlesSeekToEoF_extractsLastFrame_forWideBandAmr() throws IOException {
|
||||
String fileName = WIDE_BAND_AMR_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
expectedTrackOutput =
|
||||
@ -292,7 +288,7 @@ public final class AmrExtractorSeekTest {
|
||||
|
||||
@Test
|
||||
public void seeking_handlesSeekingBackward_extractsCorrectFrames_forWideBandAmr()
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
String fileName = WIDE_BAND_AMR_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
expectedTrackOutput =
|
||||
|
@ -42,7 +42,7 @@ public final class AmrExtractorTest {
|
||||
private static final Random RANDOM = new Random(1234);
|
||||
|
||||
@Test
|
||||
public void sniff_nonAmrSignature_returnFalse() throws IOException, InterruptedException {
|
||||
public void sniff_nonAmrSignature_returnFalse() throws IOException {
|
||||
AmrExtractor amrExtractor = setupAmrExtractorWithOutput();
|
||||
FakeExtractorInput input = fakeExtractorInputWithData(Util.getUtf8Bytes("0#!AMR\n123"));
|
||||
|
||||
@ -51,7 +51,7 @@ public final class AmrExtractorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void read_nonAmrSignature_throwParserException() throws IOException, InterruptedException {
|
||||
public void read_nonAmrSignature_throwParserException() throws IOException {
|
||||
AmrExtractor amrExtractor = setupAmrExtractorWithOutput();
|
||||
FakeExtractorInput input = fakeExtractorInputWithData(Util.getUtf8Bytes("0#!AMR-WB\n"));
|
||||
|
||||
@ -64,8 +64,7 @@ public final class AmrExtractorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void read_amrNb_returnParserException_forInvalidFrameType()
|
||||
throws IOException, InterruptedException {
|
||||
public void read_amrNb_returnParserException_forInvalidFrameType() throws IOException {
|
||||
AmrExtractor amrExtractor = setupAmrExtractorWithOutput();
|
||||
|
||||
// Frame type 12-14 for narrow band is reserved for future usage.
|
||||
@ -82,8 +81,7 @@ public final class AmrExtractorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void read_amrWb_returnParserException_forInvalidFrameType()
|
||||
throws IOException, InterruptedException {
|
||||
public void read_amrWb_returnParserException_forInvalidFrameType() throws IOException {
|
||||
AmrExtractor amrExtractor = setupAmrExtractorWithOutput();
|
||||
|
||||
// Frame type 10-13 for wide band is reserved for future usage.
|
||||
@ -100,8 +98,7 @@ public final class AmrExtractorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void read_amrNb_returnEndOfInput_ifInputEncountersEoF()
|
||||
throws IOException, InterruptedException {
|
||||
public void read_amrNb_returnEndOfInput_ifInputEncountersEoF() throws IOException {
|
||||
AmrExtractor amrExtractor = setupAmrExtractorWithOutput();
|
||||
|
||||
byte[] amrFrame = newNarrowBandAmrFrameWithType(3);
|
||||
@ -116,8 +113,7 @@ public final class AmrExtractorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void read_amrWb_returnEndOfInput_ifInputEncountersEoF()
|
||||
throws IOException, InterruptedException {
|
||||
public void read_amrWb_returnEndOfInput_ifInputEncountersEoF() throws IOException {
|
||||
AmrExtractor amrExtractor = setupAmrExtractorWithOutput();
|
||||
|
||||
byte[] amrFrame = newWideBandAmrFrameWithType(5);
|
||||
@ -132,8 +128,7 @@ public final class AmrExtractorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void read_amrNb_returnParserException_forInvalidFrameHeader()
|
||||
throws IOException, InterruptedException {
|
||||
public void read_amrNb_returnParserException_forInvalidFrameHeader() throws IOException {
|
||||
AmrExtractor amrExtractor = setupAmrExtractorWithOutput();
|
||||
|
||||
byte[] invalidHeaderFrame = newNarrowBandAmrFrameWithType(4);
|
||||
@ -154,8 +149,7 @@ public final class AmrExtractorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void read_amrWb_returnParserException_forInvalidFrameHeader()
|
||||
throws IOException, InterruptedException {
|
||||
public void read_amrWb_returnParserException_forInvalidFrameHeader() throws IOException {
|
||||
AmrExtractor amrExtractor = setupAmrExtractorWithOutput();
|
||||
|
||||
byte[] invalidHeaderFrame = newWideBandAmrFrameWithType(6);
|
||||
|
@ -49,8 +49,7 @@ public class FlacExtractorSeekTest {
|
||||
.createDataSource();
|
||||
|
||||
@Test
|
||||
public void flacExtractorReads_seekTable_returnSeekableSeekMap()
|
||||
throws IOException, InterruptedException {
|
||||
public void flacExtractorReads_seekTable_returnSeekableSeekMap() throws IOException {
|
||||
Uri fileUri = TestUtil.buildAssetUri(TEST_FILE_SEEK_TABLE);
|
||||
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -61,7 +60,7 @@ public class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_seekTable_handlesSeekToZero() throws IOException, InterruptedException {
|
||||
public void seeking_seekTable_handlesSeekToZero() throws IOException {
|
||||
String fileName = TEST_FILE_SEEK_TABLE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -78,7 +77,7 @@ public class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_seekTable_handlesSeekToEoF() throws IOException, InterruptedException {
|
||||
public void seeking_seekTable_handlesSeekToEoF() throws IOException {
|
||||
String fileName = TEST_FILE_SEEK_TABLE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -95,7 +94,7 @@ public class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_seekTable_handlesSeekingBackward() throws IOException, InterruptedException {
|
||||
public void seeking_seekTable_handlesSeekingBackward() throws IOException {
|
||||
String fileName = TEST_FILE_SEEK_TABLE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -114,7 +113,7 @@ public class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_seekTable_handlesSeekingForward() throws IOException, InterruptedException {
|
||||
public void seeking_seekTable_handlesSeekingForward() throws IOException {
|
||||
String fileName = TEST_FILE_SEEK_TABLE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -133,8 +132,7 @@ public class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flacExtractorReads_binarySearch_returnSeekableSeekMap()
|
||||
throws IOException, InterruptedException {
|
||||
public void flacExtractorReads_binarySearch_returnSeekableSeekMap() throws IOException {
|
||||
Uri fileUri = TestUtil.buildAssetUri(TEST_FILE_BINARY_SEARCH);
|
||||
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -145,7 +143,7 @@ public class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_binarySearch_handlesSeekToZero() throws IOException, InterruptedException {
|
||||
public void seeking_binarySearch_handlesSeekToZero() throws IOException {
|
||||
String fileName = TEST_FILE_BINARY_SEARCH;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -162,7 +160,7 @@ public class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_binarySearch_handlesSeekToEoF() throws IOException, InterruptedException {
|
||||
public void seeking_binarySearch_handlesSeekToEoF() throws IOException {
|
||||
String fileName = TEST_FILE_BINARY_SEARCH;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -179,8 +177,7 @@ public class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_binarySearch_handlesSeekingBackward()
|
||||
throws IOException, InterruptedException {
|
||||
public void seeking_binarySearch_handlesSeekingBackward() throws IOException {
|
||||
String fileName = TEST_FILE_BINARY_SEARCH;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -199,8 +196,7 @@ public class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_binarySearch_handlesSeekingForward()
|
||||
throws IOException, InterruptedException {
|
||||
public void seeking_binarySearch_handlesSeekingForward() throws IOException {
|
||||
String fileName = TEST_FILE_BINARY_SEARCH;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -219,8 +215,7 @@ public class FlacExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flacExtractorReads_unseekable_returnUnseekableSeekMap()
|
||||
throws IOException, InterruptedException {
|
||||
public void flacExtractorReads_unseekable_returnUnseekableSeekMap() throws IOException {
|
||||
Uri fileUri = TestUtil.buildAssetUri(TEST_FILE_UNSEEKABLE);
|
||||
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -235,7 +230,7 @@ public class FlacExtractorSeekTest {
|
||||
FakeTrackOutput trackOutput,
|
||||
long targetSeekTimeUs,
|
||||
int firstFrameIndexAfterSeek)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
FakeTrackOutput expectedTrackOutput = getExpectedTrackOutput(fileName);
|
||||
int expectedFrameIndex = getFrameIndex(expectedTrackOutput, targetSeekTimeUs);
|
||||
|
||||
@ -252,7 +247,7 @@ public class FlacExtractorSeekTest {
|
||||
FakeTrackOutput trackOutput,
|
||||
long targetSeekTimeUs,
|
||||
int firstFrameIndexAfterSeek)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
FakeTrackOutput expectedTrackOutput = getExpectedTrackOutput(fileName);
|
||||
int maxFrameIndex = getFrameIndex(expectedTrackOutput, targetSeekTimeUs);
|
||||
|
||||
@ -276,8 +271,7 @@ public class FlacExtractorSeekTest {
|
||||
assertThat(frameFound).isTrue();
|
||||
}
|
||||
|
||||
private static FakeTrackOutput getExpectedTrackOutput(String fileName)
|
||||
throws IOException, InterruptedException {
|
||||
private static FakeTrackOutput getExpectedTrackOutput(String fileName) throws IOException {
|
||||
return TestUtil.extractAllSamplesFromFile(
|
||||
new FlacExtractor(), ApplicationProvider.getApplicationContext(), fileName)
|
||||
.trackOutputs
|
||||
|
@ -33,7 +33,7 @@ import org.junit.runner.RunWith;
|
||||
public class DefaultEbmlReaderTest {
|
||||
|
||||
@Test
|
||||
public void masterElement() throws IOException, InterruptedException {
|
||||
public void masterElement() throws IOException {
|
||||
ExtractorInput input = createTestInput(0x1A, 0x45, 0xDF, 0xA3, 0x84, 0x42, 0x85, 0x81, 0x01);
|
||||
TestProcessor expected = new TestProcessor();
|
||||
expected.startMasterElement(TestProcessor.ID_EBML, 5, 4);
|
||||
@ -43,7 +43,7 @@ public class DefaultEbmlReaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void masterElementEmpty() throws IOException, InterruptedException {
|
||||
public void masterElementEmpty() throws IOException {
|
||||
ExtractorInput input = createTestInput(0x18, 0x53, 0x80, 0x67, 0x80);
|
||||
TestProcessor expected = new TestProcessor();
|
||||
expected.startMasterElement(TestProcessor.ID_SEGMENT, 5, 0);
|
||||
@ -52,7 +52,7 @@ public class DefaultEbmlReaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unsignedIntegerElement() throws IOException, InterruptedException {
|
||||
public void unsignedIntegerElement() throws IOException {
|
||||
// 0xFE is chosen because for signed integers it should be interpreted as -2
|
||||
ExtractorInput input = createTestInput(0x42, 0xF7, 0x81, 0xFE);
|
||||
TestProcessor expected = new TestProcessor();
|
||||
@ -61,7 +61,7 @@ public class DefaultEbmlReaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unsignedIntegerElementLarge() throws IOException, InterruptedException {
|
||||
public void unsignedIntegerElementLarge() throws IOException {
|
||||
ExtractorInput input =
|
||||
createTestInput(0x42, 0xF7, 0x88, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
TestProcessor expected = new TestProcessor();
|
||||
@ -70,8 +70,7 @@ public class DefaultEbmlReaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unsignedIntegerElementTooLargeBecomesNegative()
|
||||
throws IOException, InterruptedException {
|
||||
public void unsignedIntegerElementTooLargeBecomesNegative() throws IOException {
|
||||
ExtractorInput input =
|
||||
createTestInput(0x42, 0xF7, 0x88, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
TestProcessor expected = new TestProcessor();
|
||||
@ -80,7 +79,7 @@ public class DefaultEbmlReaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringElement() throws IOException, InterruptedException {
|
||||
public void stringElement() throws IOException {
|
||||
ExtractorInput input = createTestInput(0x42, 0x82, 0x86, 0x41, 0x62, 0x63, 0x31, 0x32, 0x33);
|
||||
TestProcessor expected = new TestProcessor();
|
||||
expected.stringElement(TestProcessor.ID_DOC_TYPE, "Abc123");
|
||||
@ -96,7 +95,7 @@ public class DefaultEbmlReaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringElementEmpty() throws IOException, InterruptedException {
|
||||
public void stringElementEmpty() throws IOException {
|
||||
ExtractorInput input = createTestInput(0x42, 0x82, 0x80);
|
||||
TestProcessor expected = new TestProcessor();
|
||||
expected.stringElement(TestProcessor.ID_DOC_TYPE, "");
|
||||
@ -104,7 +103,7 @@ public class DefaultEbmlReaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void floatElementFourBytes() throws IOException, InterruptedException {
|
||||
public void floatElementFourBytes() throws IOException {
|
||||
ExtractorInput input =
|
||||
createTestInput(0x44, 0x89, 0x84, 0x3F, 0x80, 0x00, 0x00);
|
||||
TestProcessor expected = new TestProcessor();
|
||||
@ -113,7 +112,7 @@ public class DefaultEbmlReaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void floatElementEightBytes() throws IOException, InterruptedException {
|
||||
public void floatElementEightBytes() throws IOException {
|
||||
ExtractorInput input =
|
||||
createTestInput(0x44, 0x89, 0x88, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
TestProcessor expected = new TestProcessor();
|
||||
@ -122,7 +121,7 @@ public class DefaultEbmlReaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void binaryElement() throws IOException, InterruptedException {
|
||||
public void binaryElement() throws IOException {
|
||||
ExtractorInput input =
|
||||
createTestInput(0xA3, 0x88, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08);
|
||||
TestProcessor expected = new TestProcessor();
|
||||
@ -134,7 +133,7 @@ public class DefaultEbmlReaderTest {
|
||||
}
|
||||
|
||||
private static void assertEvents(ExtractorInput input, List<String> expectedEvents)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
DefaultEbmlReader reader = new DefaultEbmlReader();
|
||||
TestProcessor output = new TestProcessor();
|
||||
reader.init(output);
|
||||
@ -232,8 +231,7 @@ public class DefaultEbmlReaderTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void binaryElement(int id, int contentSize, ExtractorInput input)
|
||||
throws IOException, InterruptedException {
|
||||
public void binaryElement(int id, int contentSize, ExtractorInput input) throws IOException {
|
||||
byte[] bytes = new byte[contentSize];
|
||||
input.readFully(bytes, 0, contentSize);
|
||||
events.add(formatEvent(id, "bytes=" + Arrays.toString(bytes)));
|
||||
|
@ -85,7 +85,7 @@ public final class VarintReaderTest {
|
||||
private static final long VALUE_8_BYTE_MAX_WITH_MASK = 0x1FFFFFFFFFFFFFFL;
|
||||
|
||||
@Test
|
||||
public void readVarintEndOfInputAtStart() throws IOException, InterruptedException {
|
||||
public void readVarintEndOfInputAtStart() throws IOException {
|
||||
VarintReader reader = new VarintReader();
|
||||
// Build an input with no data.
|
||||
ExtractorInput input = new FakeExtractorInput.Builder()
|
||||
@ -104,7 +104,7 @@ public final class VarintReaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readVarintExceedsMaximumAllowedLength() throws IOException, InterruptedException {
|
||||
public void readVarintExceedsMaximumAllowedLength() throws IOException {
|
||||
VarintReader reader = new VarintReader();
|
||||
ExtractorInput input = new FakeExtractorInput.Builder()
|
||||
.setData(DATA_8_BYTE_0)
|
||||
@ -115,7 +115,7 @@ public final class VarintReaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readVarint() throws IOException, InterruptedException {
|
||||
public void readVarint() throws IOException {
|
||||
VarintReader reader = new VarintReader();
|
||||
testReadVarint(reader, true, DATA_1_BYTE_0, 1, 0);
|
||||
testReadVarint(reader, true, DATA_2_BYTE_0, 2, 0);
|
||||
@ -152,7 +152,7 @@ public final class VarintReaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readVarintFlaky() throws IOException, InterruptedException {
|
||||
public void readVarintFlaky() throws IOException {
|
||||
VarintReader reader = new VarintReader();
|
||||
testReadVarintFlaky(reader, true, DATA_1_BYTE_0, 1, 0);
|
||||
testReadVarintFlaky(reader, true, DATA_2_BYTE_0, 2, 0);
|
||||
@ -188,8 +188,9 @@ public final class VarintReaderTest {
|
||||
testReadVarintFlaky(reader, false, DATA_8_BYTE_MAX, 8, VALUE_8_BYTE_MAX_WITH_MASK);
|
||||
}
|
||||
|
||||
private static void testReadVarint(VarintReader reader, boolean removeMask, byte[] data,
|
||||
int expectedLength, long expectedValue) throws IOException, InterruptedException {
|
||||
private static void testReadVarint(
|
||||
VarintReader reader, boolean removeMask, byte[] data, int expectedLength, long expectedValue)
|
||||
throws IOException {
|
||||
ExtractorInput input = new FakeExtractorInput.Builder()
|
||||
.setData(data)
|
||||
.setSimulateUnknownLength(true)
|
||||
@ -199,8 +200,9 @@ public final class VarintReaderTest {
|
||||
assertThat(result).isEqualTo(expectedValue);
|
||||
}
|
||||
|
||||
private static void testReadVarintFlaky(VarintReader reader, boolean removeMask, byte[] data,
|
||||
int expectedLength, long expectedValue) throws IOException, InterruptedException {
|
||||
private static void testReadVarintFlaky(
|
||||
VarintReader reader, boolean removeMask, byte[] data, int expectedLength, long expectedValue)
|
||||
throws IOException {
|
||||
ExtractorInput input = new FakeExtractorInput.Builder()
|
||||
.setData(data)
|
||||
.setSimulateUnknownLength(true)
|
||||
|
@ -57,7 +57,7 @@ public class ConstantBitrateSeekerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mp3ExtractorReads_returnSeekableCbrSeeker() throws IOException, InterruptedException {
|
||||
public void mp3ExtractorReads_returnSeekableCbrSeeker() throws IOException {
|
||||
Uri fileUri = TestUtil.buildAssetUri(CONSTANT_FRAME_SIZE_TEST_FILE);
|
||||
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -68,7 +68,7 @@ public class ConstantBitrateSeekerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_handlesSeekToZero() throws IOException, InterruptedException {
|
||||
public void seeking_handlesSeekToZero() throws IOException {
|
||||
String fileName = CONSTANT_FRAME_SIZE_TEST_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -85,7 +85,7 @@ public class ConstantBitrateSeekerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_handlesSeekToEoF() throws IOException, InterruptedException {
|
||||
public void seeking_handlesSeekToEoF() throws IOException {
|
||||
String fileName = CONSTANT_FRAME_SIZE_TEST_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -102,7 +102,7 @@ public class ConstantBitrateSeekerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_handlesSeekingBackward() throws IOException, InterruptedException {
|
||||
public void seeking_handlesSeekingBackward() throws IOException {
|
||||
String fileName = CONSTANT_FRAME_SIZE_TEST_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -121,7 +121,7 @@ public class ConstantBitrateSeekerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_handlesSeekingForward() throws IOException, InterruptedException {
|
||||
public void seeking_handlesSeekingForward() throws IOException {
|
||||
String fileName = CONSTANT_FRAME_SIZE_TEST_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -140,8 +140,7 @@ public class ConstantBitrateSeekerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_variableFrameSize_seeksNearlyExactlyToCorrectFrame()
|
||||
throws IOException, InterruptedException {
|
||||
public void seeking_variableFrameSize_seeksNearlyExactlyToCorrectFrame() throws IOException {
|
||||
String fileName = VARIABLE_FRAME_SIZE_TEST_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
|
||||
@ -162,7 +161,7 @@ public class ConstantBitrateSeekerTest {
|
||||
FakeTrackOutput trackOutput,
|
||||
long targetSeekTimeUs,
|
||||
int firstFrameIndexAfterSeek)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
FakeTrackOutput expectedTrackOutput = getExpectedTrackOutput(fileName);
|
||||
int exactFrameIndex = getFrameIndex(expectedTrackOutput, targetSeekTimeUs);
|
||||
|
||||
@ -175,7 +174,7 @@ public class ConstantBitrateSeekerTest {
|
||||
FakeTrackOutput trackOutput,
|
||||
long targetSeekTimeUs,
|
||||
int firstFrameIndexAfterSeek)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
FakeTrackOutput expectedTrackOutput = getExpectedTrackOutput(fileName);
|
||||
int exactFrameIndex = getFrameIndex(expectedTrackOutput, targetSeekTimeUs);
|
||||
|
||||
@ -197,8 +196,7 @@ public class ConstantBitrateSeekerTest {
|
||||
assertThat(foundPreviousFrame || foundExactFrame || foundNextFrame).isTrue();
|
||||
}
|
||||
|
||||
private static FakeTrackOutput getExpectedTrackOutput(String fileName)
|
||||
throws IOException, InterruptedException {
|
||||
private static FakeTrackOutput getExpectedTrackOutput(String fileName) throws IOException {
|
||||
return TestUtil.extractAllSamplesFromFile(
|
||||
new Mp3Extractor(), ApplicationProvider.getApplicationContext(), fileName)
|
||||
.trackOutputs
|
||||
|
@ -157,7 +157,7 @@ public class IndexSeekerTest {
|
||||
FakeTrackOutput trackOutput,
|
||||
long targetSeekTimeUs,
|
||||
int firstFrameIndexAfterSeek)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
FakeTrackOutput expectedTrackOutput = getExpectedTrackOutput(fileName);
|
||||
int exactFrameIndex = getFrameIndex(expectedTrackOutput, targetSeekTimeUs);
|
||||
long exactFrameTimeUs = expectedTrackOutput.getSampleTimeUs(exactFrameIndex);
|
||||
@ -168,7 +168,7 @@ public class IndexSeekerTest {
|
||||
|
||||
private static void assertFirstFrameAfterSeekHasCorrectData(
|
||||
String fileName, FakeTrackOutput trackOutput, int firstFrameIndexAfterSeek)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
FakeTrackOutput expectedTrackOutput = getExpectedTrackOutput(fileName);
|
||||
long foundTimeUs = trackOutput.getSampleTimeUs(firstFrameIndexAfterSeek);
|
||||
int foundFrameIndex = getFrameIndex(expectedTrackOutput, foundTimeUs);
|
||||
@ -181,8 +181,7 @@ public class IndexSeekerTest {
|
||||
expectedTrackOutput.getSampleCryptoData(foundFrameIndex));
|
||||
}
|
||||
|
||||
private static FakeTrackOutput getExpectedTrackOutput(String fileName)
|
||||
throws IOException, InterruptedException {
|
||||
private static FakeTrackOutput getExpectedTrackOutput(String fileName) throws IOException {
|
||||
return extractAllSamplesFromFile(
|
||||
new Mp3Extractor(FLAG_ENABLE_INDEX_SEEKING),
|
||||
ApplicationProvider.getApplicationContext(),
|
||||
|
@ -170,7 +170,7 @@ public final class DefaultOggSeekerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readGranuleOfLastPage() throws IOException, InterruptedException {
|
||||
public void readGranuleOfLastPage() throws IOException {
|
||||
// This test stream has three headers with granule numbers 20000, 40000 and 60000.
|
||||
byte[] data = getByteArray(ApplicationProvider.getApplicationContext(), "ogg/three_headers");
|
||||
FakeExtractorInput input = createInput(data, /* simulateUnknownLength= */ false);
|
||||
@ -200,8 +200,7 @@ public final class DefaultOggSeekerTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static void skipToNextPage(ExtractorInput extractorInput)
|
||||
throws IOException, InterruptedException {
|
||||
private static void skipToNextPage(ExtractorInput extractorInput) throws IOException {
|
||||
DefaultOggSeeker oggSeeker =
|
||||
new DefaultOggSeeker(
|
||||
/* streamReader= */ new FlacReader(),
|
||||
@ -221,7 +220,7 @@ public final class DefaultOggSeekerTest {
|
||||
}
|
||||
|
||||
private static void assertReadGranuleOfLastPage(FakeExtractorInput input, int expected)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
DefaultOggSeeker oggSeeker =
|
||||
new DefaultOggSeeker(
|
||||
/* streamReader= */ new FlacReader(),
|
||||
@ -251,7 +250,7 @@ public final class DefaultOggSeekerTest {
|
||||
|
||||
private static long seekTo(
|
||||
FakeExtractorInput input, DefaultOggSeeker oggSeeker, long targetGranule, int initialPosition)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
long nextSeekPosition = initialPosition;
|
||||
oggSeeker.startSeek(targetGranule);
|
||||
int count = 0;
|
||||
|
@ -89,8 +89,7 @@ public final class OggExtractorTest {
|
||||
assertSniff(data, /* expectedResult= */ false);
|
||||
}
|
||||
|
||||
private void assertSniff(byte[] data, boolean expectedResult)
|
||||
throws InterruptedException, IOException {
|
||||
private void assertSniff(byte[] data, boolean expectedResult) throws IOException {
|
||||
FakeExtractorInput input =
|
||||
new FakeExtractorInput.Builder()
|
||||
.setData(data)
|
||||
|
@ -167,7 +167,7 @@ public final class OggPacketTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseRealFile() throws IOException, InterruptedException {
|
||||
public void parseRealFile() throws IOException {
|
||||
byte[] data = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), TEST_FILE);
|
||||
FakeExtractorInput input = new FakeExtractorInput.Builder().setData(data).build();
|
||||
int packetCounter = 0;
|
||||
@ -187,18 +187,17 @@ public final class OggPacketTest {
|
||||
}
|
||||
|
||||
private void assertReadPacket(FakeExtractorInput extractorInput, byte[] expected)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
assertThat(readPacket(extractorInput)).isTrue();
|
||||
ParsableByteArray payload = oggPacket.getPayload();
|
||||
assertThat(Arrays.copyOf(payload.data, payload.limit())).isEqualTo(expected);
|
||||
}
|
||||
|
||||
private void assertReadEof(FakeExtractorInput extractorInput)
|
||||
throws IOException, InterruptedException {
|
||||
private void assertReadEof(FakeExtractorInput extractorInput) throws IOException {
|
||||
assertThat(readPacket(extractorInput)).isFalse();
|
||||
}
|
||||
|
||||
private boolean readPacket(FakeExtractorInput input) throws InterruptedException, IOException {
|
||||
private boolean readPacket(FakeExtractorInput input) throws IOException {
|
||||
while (true) {
|
||||
try {
|
||||
return oggPacket.populate(input);
|
||||
|
@ -56,8 +56,7 @@ public final class VorbisReaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readSetupHeaders_withIOExceptions_readSuccess()
|
||||
throws IOException, InterruptedException {
|
||||
public void readSetupHeaders_withIOExceptions_readSuccess() throws IOException {
|
||||
// initial two pages of bytes which by spec contain the three Vorbis header packets:
|
||||
// identification, comment and setup header.
|
||||
byte[] data =
|
||||
@ -99,7 +98,7 @@ public final class VorbisReaderTest {
|
||||
}
|
||||
|
||||
private static VorbisSetup readSetupHeaders(VorbisReader reader, ExtractorInput input)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
OggPacket oggPacket = new OggPacket();
|
||||
while (true) {
|
||||
try {
|
||||
|
@ -54,7 +54,7 @@ public final class AdtsExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void adtsExtractorReads_returnSeekableSeekMap() throws IOException, InterruptedException {
|
||||
public void adtsExtractorReads_returnSeekableSeekMap() throws IOException {
|
||||
String fileName = TEST_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
expectedTrackOutput =
|
||||
@ -73,8 +73,7 @@ public final class AdtsExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_handlesSeekingToPositionInFile_extractsCorrectSample()
|
||||
throws IOException, InterruptedException {
|
||||
public void seeking_handlesSeekingToPositionInFile_extractsCorrectSample() throws IOException {
|
||||
String fileName = TEST_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
expectedTrackOutput =
|
||||
@ -100,8 +99,7 @@ public final class AdtsExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_handlesSeekToEoF_extractsLastSample()
|
||||
throws IOException, InterruptedException {
|
||||
public void seeking_handlesSeekToEoF_extractsLastSample() throws IOException {
|
||||
String fileName = TEST_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
expectedTrackOutput =
|
||||
@ -127,8 +125,7 @@ public final class AdtsExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_handlesSeekingBackward_extractsCorrectSamples()
|
||||
throws IOException, InterruptedException {
|
||||
public void seeking_handlesSeekingBackward_extractsCorrectSamples() throws IOException {
|
||||
String fileName = TEST_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
expectedTrackOutput =
|
||||
@ -156,8 +153,7 @@ public final class AdtsExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_handlesSeekingForward_extractsCorrectSamples()
|
||||
throws IOException, InterruptedException {
|
||||
public void seeking_handlesSeekingForward_extractsCorrectSamples() throws IOException {
|
||||
String fileName = TEST_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
expectedTrackOutput =
|
||||
@ -185,8 +181,7 @@ public final class AdtsExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seeking_handlesRandomSeeks_extractsCorrectSamples()
|
||||
throws IOException, InterruptedException {
|
||||
public void seeking_handlesRandomSeeks_extractsCorrectSamples() throws IOException {
|
||||
String fileName = TEST_FILE;
|
||||
Uri fileUri = TestUtil.buildAssetUri(fileName);
|
||||
expectedTrackOutput =
|
||||
|
@ -47,7 +47,7 @@ public final class PsDurationReaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readDuration_returnsCorrectDuration() throws IOException, InterruptedException {
|
||||
public void readDuration_returnsCorrectDuration() throws IOException {
|
||||
FakeExtractorInput input =
|
||||
new FakeExtractorInput.Builder()
|
||||
.setData(
|
||||
@ -66,8 +66,7 @@ public final class PsDurationReaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readDuration_midStream_returnsCorrectDuration()
|
||||
throws IOException, InterruptedException {
|
||||
public void readDuration_midStream_returnsCorrectDuration() throws IOException {
|
||||
FakeExtractorInput input =
|
||||
new FakeExtractorInput.Builder()
|
||||
.setData(
|
||||
|
@ -60,7 +60,7 @@ public final class PsExtractorSeekTest {
|
||||
private long totalInputLength;
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException, InterruptedException {
|
||||
public void setUp() throws IOException {
|
||||
expectedOutput = new FakeExtractorOutput();
|
||||
positionHolder = new PositionHolder();
|
||||
extractAllSamplesFromFileToExpectedOutput(
|
||||
@ -74,8 +74,7 @@ public final class PsExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void psExtractorReads_nonSeekTableFile_returnSeekableSeekMap()
|
||||
throws IOException, InterruptedException {
|
||||
public void psExtractorReads_nonSeekTableFile_returnSeekableSeekMap() throws IOException {
|
||||
PsExtractor extractor = new PsExtractor();
|
||||
|
||||
SeekMap seekMap = extractSeekMapAndTracks(extractor, new FakeExtractorOutput());
|
||||
@ -87,7 +86,7 @@ public final class PsExtractorSeekTest {
|
||||
|
||||
@Test
|
||||
public void handlePendingSeek_handlesSeekingToPositionInFile_extractsCorrectFrame()
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
PsExtractor extractor = new PsExtractor();
|
||||
|
||||
FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
|
||||
@ -118,8 +117,7 @@ public final class PsExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePendingSeek_handlesSeekingBackward_extractsCorrectFrame()
|
||||
throws IOException, InterruptedException {
|
||||
public void handlePendingSeek_handlesSeekingBackward_extractsCorrectFrame() throws IOException {
|
||||
PsExtractor extractor = new PsExtractor();
|
||||
|
||||
FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
|
||||
@ -138,8 +136,7 @@ public final class PsExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePendingSeek_handlesSeekingForward_extractsCorrectFrame()
|
||||
throws IOException, InterruptedException {
|
||||
public void handlePendingSeek_handlesSeekingForward_extractsCorrectFrame() throws IOException {
|
||||
PsExtractor extractor = new PsExtractor();
|
||||
|
||||
FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
|
||||
@ -158,8 +155,7 @@ public final class PsExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePendingSeek_handlesRandomSeeks_extractsCorrectFrame()
|
||||
throws IOException, InterruptedException {
|
||||
public void handlePendingSeek_handlesRandomSeeks_extractsCorrectFrame() throws IOException {
|
||||
PsExtractor extractor = new PsExtractor();
|
||||
|
||||
FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
|
||||
@ -179,7 +175,7 @@ public final class PsExtractorSeekTest {
|
||||
|
||||
@Test
|
||||
public void handlePendingSeek_handlesRandomSeeksAfterReadingFileOnce_extractsCorrectFrame()
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
PsExtractor extractor = new PsExtractor();
|
||||
|
||||
FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
|
||||
@ -216,7 +212,7 @@ public final class PsExtractorSeekTest {
|
||||
*/
|
||||
private int seekToTimeUs(
|
||||
PsExtractor psExtractor, SeekMap seekMap, long seekTimeUs, FakeTrackOutput trackOutput)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
int numSampleBeforeSeek = trackOutput.getSampleCount();
|
||||
SeekMap.SeekPoints seekPoints = seekMap.getSeekPoints(seekTimeUs);
|
||||
|
||||
@ -250,7 +246,7 @@ public final class PsExtractorSeekTest {
|
||||
}
|
||||
|
||||
private SeekMap extractSeekMapAndTracks(PsExtractor extractor, FakeExtractorOutput output)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
ExtractorInput input = getExtractorInputFromPosition(0);
|
||||
extractor.init(output);
|
||||
int readResult = Extractor.RESULT_CONTINUE;
|
||||
@ -278,7 +274,7 @@ public final class PsExtractorSeekTest {
|
||||
}
|
||||
|
||||
private void readInputFileOnce(PsExtractor extractor, FakeExtractorOutput extractorOutput)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
extractor.init(extractorOutput);
|
||||
int readResult = Extractor.RESULT_CONTINUE;
|
||||
ExtractorInput input = getExtractorInputFromPosition(0);
|
||||
@ -348,7 +344,7 @@ public final class PsExtractorSeekTest {
|
||||
}
|
||||
|
||||
private void extractAllSamplesFromFileToExpectedOutput(Context context, String fileName)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
byte[] data = TestUtil.getByteArray(context, fileName);
|
||||
|
||||
PsExtractor extractor = new PsExtractor();
|
||||
|
@ -71,8 +71,7 @@ public final class TsDurationReaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readDuration_midStream_returnsCorrectDuration()
|
||||
throws IOException, InterruptedException {
|
||||
public void readDuration_midStream_returnsCorrectDuration() throws IOException {
|
||||
FakeExtractorInput input =
|
||||
new FakeExtractorInput.Builder()
|
||||
.setData(
|
||||
|
@ -53,7 +53,7 @@ public final class TsExtractorSeekTest {
|
||||
private PositionHolder positionHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException, InterruptedException {
|
||||
public void setUp() throws IOException {
|
||||
positionHolder = new PositionHolder();
|
||||
expectedTrackOutput =
|
||||
TestUtil.extractAllSamplesFromFile(
|
||||
@ -67,8 +67,7 @@ public final class TsExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tsExtractorReads_nonSeekTableFile_returnSeekableSeekMap()
|
||||
throws IOException, InterruptedException {
|
||||
public void tsExtractorReads_nonSeekTableFile_returnSeekableSeekMap() throws IOException {
|
||||
Uri fileUri = TestUtil.buildAssetUri(TEST_FILE);
|
||||
TsExtractor extractor = new TsExtractor();
|
||||
|
||||
@ -82,7 +81,7 @@ public final class TsExtractorSeekTest {
|
||||
|
||||
@Test
|
||||
public void handlePendingSeek_handlesSeekingToPositionInFile_extractsCorrectFrame()
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
TsExtractor extractor = new TsExtractor();
|
||||
Uri fileUri = TestUtil.buildAssetUri(TEST_FILE);
|
||||
|
||||
@ -101,8 +100,7 @@ public final class TsExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePendingSeek_handlesSeekToEoF_extractsLastFrame()
|
||||
throws IOException, InterruptedException {
|
||||
public void handlePendingSeek_handlesSeekToEoF_extractsLastFrame() throws IOException {
|
||||
TsExtractor extractor = new TsExtractor();
|
||||
Uri fileUri = TestUtil.buildAssetUri(TEST_FILE);
|
||||
|
||||
@ -122,8 +120,7 @@ public final class TsExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePendingSeek_handlesSeekingBackward_extractsCorrectFrame()
|
||||
throws IOException, InterruptedException {
|
||||
public void handlePendingSeek_handlesSeekingBackward_extractsCorrectFrame() throws IOException {
|
||||
TsExtractor extractor = new TsExtractor();
|
||||
Uri fileUri = TestUtil.buildAssetUri(TEST_FILE);
|
||||
|
||||
@ -145,8 +142,7 @@ public final class TsExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePendingSeek_handlesSeekingForward_extractsCorrectFrame()
|
||||
throws IOException, InterruptedException {
|
||||
public void handlePendingSeek_handlesSeekingForward_extractsCorrectFrame() throws IOException {
|
||||
TsExtractor extractor = new TsExtractor();
|
||||
Uri fileUri = TestUtil.buildAssetUri(TEST_FILE);
|
||||
|
||||
@ -168,8 +164,7 @@ public final class TsExtractorSeekTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePendingSeek_handlesRandomSeeks_extractsCorrectFrame()
|
||||
throws IOException, InterruptedException {
|
||||
public void handlePendingSeek_handlesRandomSeeks_extractsCorrectFrame() throws IOException {
|
||||
TsExtractor extractor = new TsExtractor();
|
||||
Uri fileUri = TestUtil.buildAssetUri(TEST_FILE);
|
||||
|
||||
@ -192,7 +187,7 @@ public final class TsExtractorSeekTest {
|
||||
|
||||
@Test
|
||||
public void handlePendingSeek_handlesRandomSeeksAfterReadingFileOnce_extractsCorrectFrame()
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
TsExtractor extractor = new TsExtractor();
|
||||
Uri fileUri = TestUtil.buildAssetUri(TEST_FILE);
|
||||
|
||||
@ -217,8 +212,7 @@ public final class TsExtractorSeekTest {
|
||||
// Internal methods
|
||||
|
||||
private void readInputFileOnce(
|
||||
TsExtractor extractor, FakeExtractorOutput extractorOutput, Uri fileUri)
|
||||
throws IOException, InterruptedException {
|
||||
TsExtractor extractor, FakeExtractorOutput extractorOutput, Uri fileUri) throws IOException {
|
||||
extractor.init(extractorOutput);
|
||||
int readResult = Extractor.RESULT_CONTINUE;
|
||||
ExtractorInput input = TestUtil.getExtractorInputFromPosition(dataSource, 0, fileUri);
|
||||
|
@ -91,7 +91,7 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
|
||||
TimestampAdjuster timestampAdjuster,
|
||||
Map<String, List<String>> responseHeaders,
|
||||
ExtractorInput extractorInput)
|
||||
throws InterruptedException, IOException {
|
||||
throws IOException {
|
||||
|
||||
if (previousExtractor != null) {
|
||||
// A extractor has already been successfully used. Return one of the same type.
|
||||
@ -315,7 +315,7 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
|
||||
}
|
||||
|
||||
private static boolean sniffQuietly(Extractor extractor, ExtractorInput input)
|
||||
throws InterruptedException, IOException {
|
||||
throws IOException {
|
||||
boolean result = false;
|
||||
try {
|
||||
result = extractor.sniff(input);
|
||||
|
@ -77,7 +77,6 @@ public interface HlsExtractorFactory {
|
||||
* extractor's {@link Extractor#read(ExtractorInput, PositionHolder)}. Must only be used to
|
||||
* call {@link Extractor#sniff(ExtractorInput)}.
|
||||
* @return A {@link Result}.
|
||||
* @throws InterruptedException If the thread is interrupted while sniffing.
|
||||
* @throws IOException If an I/O error is encountered while sniffing.
|
||||
*/
|
||||
Result createExtractor(
|
||||
@ -88,5 +87,5 @@ public interface HlsExtractorFactory {
|
||||
TimestampAdjuster timestampAdjuster,
|
||||
Map<String, List<String>> responseHeaders,
|
||||
ExtractorInput sniffingExtractorInput)
|
||||
throws InterruptedException, IOException;
|
||||
throws IOException;
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ import com.google.android.exoplayer2.util.UriUtil;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@ -297,7 +298,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() throws IOException, InterruptedException {
|
||||
public void load() throws IOException {
|
||||
// output == null means init() hasn't been called.
|
||||
Assertions.checkNotNull(output);
|
||||
if (extractor == null && previousExtractor != null) {
|
||||
@ -317,7 +318,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
// Internal methods.
|
||||
|
||||
@RequiresNonNull("output")
|
||||
private void maybeLoadInitData() throws IOException, InterruptedException {
|
||||
private void maybeLoadInitData() throws IOException {
|
||||
if (!initDataLoadRequired) {
|
||||
return;
|
||||
}
|
||||
@ -330,9 +331,13 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
}
|
||||
|
||||
@RequiresNonNull("output")
|
||||
private void loadMedia() throws IOException, InterruptedException {
|
||||
private void loadMedia() throws IOException {
|
||||
if (!isMasterTimestampSource) {
|
||||
timestampAdjuster.waitUntilInitialized();
|
||||
try {
|
||||
timestampAdjuster.waitUntilInitialized();
|
||||
} catch (InterruptedException e) {
|
||||
throw new InterruptedIOException();
|
||||
}
|
||||
} else if (timestampAdjuster.getFirstSampleTimestampUs() == TimestampAdjuster.DO_NOT_OFFSET) {
|
||||
// We're the master and we haven't set the desired first sample timestamp yet.
|
||||
timestampAdjuster.setFirstSampleTimestampUs(startTimeUs);
|
||||
@ -347,8 +352,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
*/
|
||||
@RequiresNonNull("output")
|
||||
private void feedDataToExtractor(
|
||||
DataSource dataSource, DataSpec dataSpec, boolean dataIsEncrypted)
|
||||
throws IOException, InterruptedException {
|
||||
DataSource dataSource, DataSpec dataSpec, boolean dataIsEncrypted) throws IOException {
|
||||
// If we previously fed part of this chunk to the extractor, we need to skip it this time. For
|
||||
// encrypted content we need to skip the data by reading it through the source, so as to ensure
|
||||
// correct decryption of the remainder of the chunk. For clear content, we can request the
|
||||
@ -383,7 +387,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
@RequiresNonNull("output")
|
||||
@EnsuresNonNull("extractor")
|
||||
private DefaultExtractorInput prepareExtraction(DataSource dataSource, DataSpec dataSpec)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
long bytesToRead = dataSource.open(dataSpec);
|
||||
DefaultExtractorInput extractorInput =
|
||||
new DefaultExtractorInput(dataSource, dataSpec.position, bytesToRead);
|
||||
@ -421,16 +425,15 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
}
|
||||
|
||||
/**
|
||||
* Peek the presentation timestamp of the first sample in the chunk from an ID3 PRIV as defined
|
||||
* in the HLS spec, version 20, Section 3.4. Returns {@link C#TIME_UNSET} if the frame is not
|
||||
* found. This method only modifies the peek position.
|
||||
* Peek the presentation timestamp of the first sample in the chunk from an ID3 PRIV as defined in
|
||||
* the HLS spec, version 20, Section 3.4. Returns {@link C#TIME_UNSET} if the frame is not found.
|
||||
* This method only modifies the peek position.
|
||||
*
|
||||
* @param input The {@link ExtractorInput} to obtain the PRIV frame from.
|
||||
* @return The parsed, adjusted timestamp in microseconds
|
||||
* @throws IOException If an error occurred peeking from the input.
|
||||
* @throws InterruptedException If the thread was interrupted.
|
||||
*/
|
||||
private long peekId3PrivTimestamp(ExtractorInput input) throws IOException, InterruptedException {
|
||||
private long peekId3PrivTimestamp(ExtractorInput input) throws IOException {
|
||||
input.resetPeekPosition();
|
||||
try {
|
||||
input.peekFully(scratchId3Data.data, 0, Id3Decoder.ID3_HEADER_LENGTH);
|
||||
|
@ -1460,7 +1460,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
|
||||
@Override
|
||||
public int sampleData(DataReader input, int length, boolean allowEndOfInput)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
ensureBufferCapacity(bufferPosition + length);
|
||||
int numBytesRead = input.read(buffer, bufferPosition, length);
|
||||
if (numBytesRead == C.RESULT_END_OF_INPUT) {
|
||||
|
@ -72,7 +72,7 @@ public final class WebvttExtractor implements Extractor {
|
||||
// Extractor implementation.
|
||||
|
||||
@Override
|
||||
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
|
||||
public boolean sniff(ExtractorInput input) throws IOException {
|
||||
// Check whether there is a header without BOM.
|
||||
input.peekFully(
|
||||
sampleData, /* offset= */ 0, /* length= */ HEADER_MIN_LENGTH, /* allowEndOfInput= */ false);
|
||||
@ -108,8 +108,7 @@ public final class WebvttExtractor implements Extractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition)
|
||||
throws IOException, InterruptedException {
|
||||
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException {
|
||||
// output == null suggests init() hasn't been called
|
||||
Assertions.checkNotNull(output);
|
||||
int currentFileSize = (int) input.getLength();
|
||||
|
@ -31,39 +31,39 @@ import org.junit.runner.RunWith;
|
||||
public class WebvttExtractorTest {
|
||||
|
||||
@Test
|
||||
public void sniff_sniffsWebvttHeaderWithTrailingSpace() throws IOException, InterruptedException {
|
||||
public void sniff_sniffsWebvttHeaderWithTrailingSpace() throws IOException {
|
||||
byte[] data = new byte[] {'W', 'E', 'B', 'V', 'T', 'T', ' ', '\t'};
|
||||
assertThat(sniffData(data)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sniff_discardsByteOrderMark() throws IOException, InterruptedException {
|
||||
public void sniff_discardsByteOrderMark() throws IOException {
|
||||
byte[] data =
|
||||
new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF, 'W', 'E', 'B', 'V', 'T', 'T', '\n', ' '};
|
||||
assertThat(sniffData(data)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sniff_failsForIncorrectBom() throws IOException, InterruptedException {
|
||||
public void sniff_failsForIncorrectBom() throws IOException {
|
||||
byte[] data =
|
||||
new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBB, 'W', 'E', 'B', 'V', 'T', 'T', '\n'};
|
||||
assertThat(sniffData(data)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sniff_failsForIncompleteHeader() throws IOException, InterruptedException {
|
||||
public void sniff_failsForIncompleteHeader() throws IOException {
|
||||
byte[] data = new byte[] {'W', 'E', 'B', 'V', 'T', '\n'};
|
||||
assertThat(sniffData(data)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sniff_failsForIncorrectHeader() throws IOException, InterruptedException {
|
||||
public void sniff_failsForIncorrectHeader() throws IOException {
|
||||
byte[] data =
|
||||
new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF, 'W', 'e', 'B', 'V', 'T', 'T', '\n'};
|
||||
assertThat(sniffData(data)).isFalse();
|
||||
}
|
||||
|
||||
private static boolean sniffData(byte[] data) throws IOException, InterruptedException {
|
||||
private static boolean sniffData(byte[] data) throws IOException {
|
||||
ExtractorInput input = new FakeExtractorInput.Builder().setData(data).build();
|
||||
try {
|
||||
return new WebvttExtractor(/* language= */ null, new TimestampAdjuster(0)).sniff(input);
|
||||
|
@ -188,7 +188,7 @@ public final class DashWidevineOfflineTest {
|
||||
testRunner.setActionSchedule(schedule).run();
|
||||
}
|
||||
|
||||
private void downloadLicense() throws InterruptedException, DrmSessionException, IOException {
|
||||
private void downloadLicense() throws IOException {
|
||||
DataSource dataSource = httpDataSourceFactory.createDataSource();
|
||||
DashManifest dashManifest = DashUtil.loadManifest(dataSource,
|
||||
Uri.parse(DashTestData.WIDEVINE_H264_MANIFEST));
|
||||
|
@ -52,11 +52,9 @@ public final class ExtractorAsserts {
|
||||
* @param input The extractor input.
|
||||
* @param expectedResult The expected return value.
|
||||
* @throws IOException If reading from the input fails.
|
||||
* @throws InterruptedException If interrupted while reading from the input.
|
||||
*/
|
||||
public static void assertSniff(
|
||||
Extractor extractor, FakeExtractorInput input, boolean expectedResult)
|
||||
throws IOException, InterruptedException {
|
||||
Extractor extractor, FakeExtractorInput input, boolean expectedResult) throws IOException {
|
||||
while (true) {
|
||||
try {
|
||||
assertThat(extractor.sniff(input)).isEqualTo(expectedResult);
|
||||
@ -82,10 +80,8 @@ public final class ExtractorAsserts {
|
||||
* class which is to be tested.
|
||||
* @param file The path to the input sample.
|
||||
* @throws IOException If reading from the input fails.
|
||||
* @throws InterruptedException If interrupted while reading from the input.
|
||||
*/
|
||||
public static void assertBehavior(ExtractorFactory factory, String file)
|
||||
throws IOException, InterruptedException {
|
||||
public static void assertBehavior(ExtractorFactory factory, String file) throws IOException {
|
||||
assertBehavior(factory, file, ApplicationProvider.getApplicationContext());
|
||||
}
|
||||
|
||||
@ -104,10 +100,9 @@ public final class ExtractorAsserts {
|
||||
* @param file The path to the input sample.
|
||||
* @param context To be used to load the sample file.
|
||||
* @throws IOException If reading from the input fails.
|
||||
* @throws InterruptedException If interrupted while reading from the input.
|
||||
*/
|
||||
public static void assertBehavior(ExtractorFactory factory, String file, Context context)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
assertBehavior(factory, file, context, file);
|
||||
}
|
||||
|
||||
@ -127,11 +122,10 @@ public final class ExtractorAsserts {
|
||||
* @param context To be used to load the sample file.
|
||||
* @param dumpFilesPrefix The dump files prefix appended to the dump files path.
|
||||
* @throws IOException If reading from the input fails.
|
||||
* @throws InterruptedException If interrupted while reading from the input.
|
||||
*/
|
||||
public static void assertBehavior(
|
||||
ExtractorFactory factory, String file, Context context, String dumpFilesPrefix)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
// Check behavior prior to initialization.
|
||||
Extractor extractor = factory.create();
|
||||
extractor.seek(0, 0);
|
||||
@ -153,11 +147,10 @@ public final class ExtractorAsserts {
|
||||
* @param data Content of the input file.
|
||||
* @param context To be used to load the sample file.
|
||||
* @throws IOException If reading from the input fails.
|
||||
* @throws InterruptedException If interrupted while reading from the input.
|
||||
*/
|
||||
public static void assertOutput(
|
||||
ExtractorFactory factory, String dumpFilesPrefix, byte[] data, Context context)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
assertOutput(factory.create(), dumpFilesPrefix, data, context, true, false, false, false);
|
||||
assertOutput(factory.create(), dumpFilesPrefix, data, context, true, false, false, true);
|
||||
assertOutput(factory.create(), dumpFilesPrefix, data, context, true, false, true, false);
|
||||
@ -184,7 +177,6 @@ public final class ExtractorAsserts {
|
||||
* @param simulatePartialReads Whether to simulate partial reads.
|
||||
* @return The {@link FakeExtractorOutput} used in the test.
|
||||
* @throws IOException If reading from the input fails.
|
||||
* @throws InterruptedException If interrupted while reading from the input.
|
||||
*/
|
||||
public static FakeExtractorOutput assertOutput(
|
||||
Extractor extractor,
|
||||
@ -195,7 +187,7 @@ public final class ExtractorAsserts {
|
||||
boolean simulateIOErrors,
|
||||
boolean simulateUnknownLength,
|
||||
boolean simulatePartialReads)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
FakeExtractorInput input = new FakeExtractorInput.Builder().setData(data)
|
||||
.setSimulateIOErrors(simulateIOErrors)
|
||||
.setSimulateUnknownLength(simulateUnknownLength)
|
||||
@ -254,7 +246,6 @@ public final class ExtractorAsserts {
|
||||
* @param context To be used to load the sample file.
|
||||
* @param expectedThrowable Expected {@link Throwable} class.
|
||||
* @throws IOException If reading from the input fails.
|
||||
* @throws InterruptedException If interrupted while reading from the input.
|
||||
* @see #assertThrows(Extractor, byte[], Class, boolean, boolean, boolean)
|
||||
*/
|
||||
public static void assertThrows(
|
||||
@ -262,7 +253,7 @@ public final class ExtractorAsserts {
|
||||
String sampleFile,
|
||||
Context context,
|
||||
Class<? extends Throwable> expectedThrowable)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
byte[] fileData = TestUtil.getByteArray(context, sampleFile);
|
||||
assertThrows(factory, fileData, expectedThrowable);
|
||||
}
|
||||
@ -276,12 +267,11 @@ public final class ExtractorAsserts {
|
||||
* @param fileData Content of the input file.
|
||||
* @param expectedThrowable Expected {@link Throwable} class.
|
||||
* @throws IOException If reading from the input fails.
|
||||
* @throws InterruptedException If interrupted while reading from the input.
|
||||
* @see #assertThrows(Extractor, byte[], Class, boolean, boolean, boolean)
|
||||
*/
|
||||
private static void assertThrows(
|
||||
ExtractorFactory factory, byte[] fileData, Class<? extends Throwable> expectedThrowable)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
assertThrows(factory.create(), fileData, expectedThrowable, false, false, false);
|
||||
assertThrows(factory.create(), fileData, expectedThrowable, true, false, false);
|
||||
assertThrows(factory.create(), fileData, expectedThrowable, false, true, false);
|
||||
@ -302,7 +292,6 @@ public final class ExtractorAsserts {
|
||||
* @param simulateUnknownLength If true simulates unknown input length.
|
||||
* @param simulatePartialReads If true simulates partial reads.
|
||||
* @throws IOException If reading from the input fails.
|
||||
* @throws InterruptedException If interrupted while reading from the input.
|
||||
*/
|
||||
private static void assertThrows(
|
||||
Extractor extractor,
|
||||
@ -311,7 +300,7 @@ public final class ExtractorAsserts {
|
||||
boolean simulateIOErrors,
|
||||
boolean simulateUnknownLength,
|
||||
boolean simulatePartialReads)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
FakeExtractorInput input = new FakeExtractorInput.Builder().setData(fileData)
|
||||
.setSimulateIOErrors(simulateIOErrors)
|
||||
.setSimulateUnknownLength(simulateUnknownLength)
|
||||
@ -329,17 +318,22 @@ public final class ExtractorAsserts {
|
||||
|
||||
private ExtractorAsserts() {}
|
||||
|
||||
private static FakeExtractorOutput consumeTestData(Extractor extractor, FakeExtractorInput input,
|
||||
long timeUs, boolean retryFromStartIfLive) throws IOException, InterruptedException {
|
||||
private static FakeExtractorOutput consumeTestData(
|
||||
Extractor extractor, FakeExtractorInput input, long timeUs, boolean retryFromStartIfLive)
|
||||
throws IOException {
|
||||
FakeExtractorOutput output = new FakeExtractorOutput();
|
||||
extractor.init(output);
|
||||
consumeTestData(extractor, input, timeUs, output, retryFromStartIfLive);
|
||||
return output;
|
||||
}
|
||||
|
||||
private static void consumeTestData(Extractor extractor, FakeExtractorInput input, long timeUs,
|
||||
FakeExtractorOutput output, boolean retryFromStartIfLive)
|
||||
throws IOException, InterruptedException {
|
||||
private static void consumeTestData(
|
||||
Extractor extractor,
|
||||
FakeExtractorInput input,
|
||||
long timeUs,
|
||||
FakeExtractorOutput output,
|
||||
boolean retryFromStartIfLive)
|
||||
throws IOException {
|
||||
extractor.seek(input.getPosition(), timeUs);
|
||||
PositionHolder seekPositionHolder = new PositionHolder();
|
||||
int readResult = Extractor.RESULT_CONTINUE;
|
||||
|
@ -67,8 +67,7 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int sampleData(DataReader input, int length, boolean allowEndOfInput)
|
||||
throws IOException, InterruptedException {
|
||||
public int sampleData(DataReader input, int length, boolean allowEndOfInput) throws IOException {
|
||||
byte[] newData = new byte[length];
|
||||
int bytesAppended = input.read(newData, 0, length);
|
||||
if (bytesAppended == C.RESULT_END_OF_INPUT) {
|
||||
|
@ -341,11 +341,10 @@ public class TestUtil {
|
||||
* @return The extracted {@link SeekMap}.
|
||||
* @throws IOException If an error occurred reading from the input, or if the extractor finishes
|
||||
* reading from input without extracting any {@link SeekMap}.
|
||||
* @throws InterruptedException If the thread was interrupted.
|
||||
*/
|
||||
public static SeekMap extractSeekMap(
|
||||
Extractor extractor, FakeExtractorOutput output, DataSource dataSource, Uri uri)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
ExtractorInput input = getExtractorInputFromPosition(dataSource, /* position= */ 0, uri);
|
||||
extractor.init(output);
|
||||
PositionHolder positionHolder = new PositionHolder();
|
||||
@ -382,11 +381,9 @@ public class TestUtil {
|
||||
* @return The {@link FakeTrackOutput} containing the extracted samples.
|
||||
* @throws IOException If an error occurred reading from the input, or if the extractor finishes
|
||||
* reading from input without extracting any {@link SeekMap}.
|
||||
* @throws InterruptedException If the thread was interrupted.
|
||||
*/
|
||||
public static FakeExtractorOutput extractAllSamplesFromFile(
|
||||
Extractor extractor, Context context, String fileName)
|
||||
throws IOException, InterruptedException {
|
||||
Extractor extractor, Context context, String fileName) throws IOException {
|
||||
byte[] data = TestUtil.getByteArray(context, fileName);
|
||||
FakeExtractorOutput expectedOutput = new FakeExtractorOutput();
|
||||
extractor.init(expectedOutput);
|
||||
@ -428,7 +425,7 @@ public class TestUtil {
|
||||
DataSource dataSource,
|
||||
FakeTrackOutput trackOutput,
|
||||
Uri uri)
|
||||
throws IOException, InterruptedException {
|
||||
throws IOException {
|
||||
int numSampleBeforeSeek = trackOutput.getSampleCount();
|
||||
SeekMap.SeekPoints seekPoints = seekMap.getSeekPoints(seekTimeUs);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user