use of com.google.android.exoplayer2.extractor.DefaultExtractorInput in project ExoPlayer by google.
the class ExtractorUtilTest method skipFullyQuietly_endReached_isFalse.
@Test
public void skipFullyQuietly_endReached_isFalse() throws Exception {
FakeDataSource testDataSource = new FakeDataSource();
testDataSource.getDataSet().newDefaultData().appendReadData(Arrays.copyOf(TEST_DATA, 3));
testDataSource.open(new DataSpec(Uri.parse(TEST_URI)));
ExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
int length = TEST_DATA.length + 1;
boolean hasRead = ExtractorUtil.skipFullyQuietly(input, length);
assertThat(hasRead).isFalse();
assertThat(input.getPosition()).isEqualTo(0);
}
use of com.google.android.exoplayer2.extractor.DefaultExtractorInput in project ExoPlayer by google.
the class ExtractorUtilTest method readFullyQuietly_endNotReached_isTrueAndReadsData.
@Test
public void readFullyQuietly_endNotReached_isTrueAndReadsData() throws Exception {
FakeDataSource testDataSource = new FakeDataSource();
testDataSource.getDataSet().newDefaultData().appendReadData(Arrays.copyOf(TEST_DATA, 3)).appendReadData(Arrays.copyOfRange(TEST_DATA, 3, 6)).appendReadData(Arrays.copyOfRange(TEST_DATA, 6, 9));
testDataSource.open(new DataSpec(Uri.parse(TEST_URI)));
ExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
byte[] target = new byte[TEST_DATA.length];
int offset = 2;
int length = 4;
boolean hasRead = ExtractorUtil.readFullyQuietly(input, target, offset, length);
assertThat(hasRead).isTrue();
assertThat(input.getPosition()).isEqualTo(length);
assertThat(Arrays.copyOfRange(target, offset, offset + length)).isEqualTo(Arrays.copyOf(TEST_DATA, length));
}
use of com.google.android.exoplayer2.extractor.DefaultExtractorInput in project ExoPlayer by google.
the class DefaultExtractorInputTest method skipFullyWithFailingDataSource.
@Test
public void skipFullyWithFailingDataSource() throws Exception {
FakeDataSource testDataSource = buildFailingDataSource();
DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
try {
input.skipFully(TEST_DATA.length);
fail();
} catch (IOException e) {
// Expected.
}
// The position should not have advanced.
assertThat(input.getPosition()).isEqualTo(0);
}
use of com.google.android.exoplayer2.extractor.DefaultExtractorInput in project ExoPlayer by google.
the class DefaultExtractorInputTest method skipFullyLarge.
@Test
public void skipFullyLarge() throws Exception {
// Tests skipping an amount of data that's larger than any internal scratch space.
int largeSkipSize = 1024 * 1024;
FakeDataSource testDataSource = new FakeDataSource();
testDataSource.getDataSet().newDefaultData().appendReadData(new byte[largeSkipSize]);
testDataSource.open(new DataSpec(Uri.parse(TEST_URI)));
DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
input.skipFully(largeSkipSize);
assertThat(input.getPosition()).isEqualTo(largeSkipSize);
// Check that we fail with EOFException we skip again.
try {
input.skipFully(1);
fail();
} catch (EOFException e) {
// Expected.
}
}
use of com.google.android.exoplayer2.extractor.DefaultExtractorInput in project ExoPlayer by google.
the class HlsMediaChunk method prepareExtraction.
@RequiresNonNull("output")
@EnsuresNonNull("extractor")
private DefaultExtractorInput prepareExtraction(DataSource dataSource, DataSpec dataSpec, boolean initializeTimestampAdjuster) throws IOException {
long bytesToRead = dataSource.open(dataSpec);
if (initializeTimestampAdjuster) {
try {
timestampAdjuster.sharedInitializeOrWait(isMasterTimestampSource, startTimeUs);
} catch (InterruptedException e) {
throw new InterruptedIOException();
}
}
DefaultExtractorInput extractorInput = new DefaultExtractorInput(dataSource, dataSpec.position, bytesToRead);
if (extractor == null) {
long id3Timestamp = peekId3PrivTimestamp(extractorInput);
extractorInput.resetPeekPosition();
extractor = previousExtractor != null ? previousExtractor.recreate() : extractorFactory.createExtractor(dataSpec.uri, trackFormat, muxedCaptionFormats, timestampAdjuster, dataSource.getResponseHeaders(), extractorInput, playerId);
if (extractor.isPackedAudioExtractor()) {
output.setSampleOffsetUs(id3Timestamp != C.TIME_UNSET ? timestampAdjuster.adjustTsTimestamp(id3Timestamp) : startTimeUs);
} else {
// In case the container format changes mid-stream to non-packed-audio, we need to reset
// the timestamp offset.
output.setSampleOffsetUs(/* sampleOffsetUs= */
0L);
}
output.onNewExtractor();
extractor.init(output);
}
output.setDrmInitData(drmInitData);
return extractorInput;
}
Aggregations