Search in sources :

Example 21 with DefaultExtractorInput

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);
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) Test(org.junit.Test)

Example 22 with DefaultExtractorInput

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));
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) Test(org.junit.Test)

Example 23 with DefaultExtractorInput

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);
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) IOException(java.io.IOException) Test(org.junit.Test)

Example 24 with DefaultExtractorInput

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.
    }
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) EOFException(java.io.EOFException) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) Test(org.junit.Test)

Example 25 with DefaultExtractorInput

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;
}
Also used : InterruptedIOException(java.io.InterruptedIOException) DefaultExtractorInput(com.google.android.exoplayer2.extractor.DefaultExtractorInput) EnsuresNonNull(org.checkerframework.checker.nullness.qual.EnsuresNonNull) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Aggregations

FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)20 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)18 Test (org.junit.Test)14 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)10 ExtractorInput (com.google.android.exoplayer2.extractor.ExtractorInput)7 IOException (java.io.IOException)4 EOFException (java.io.EOFException)3 Nullable (androidx.annotation.Nullable)1 Extractor (com.google.android.exoplayer2.extractor.Extractor)1 PositionHolder (com.google.android.exoplayer2.extractor.PositionHolder)1 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)1 Mp3Extractor (com.google.android.exoplayer2.extractor.mp3.Mp3Extractor)1 InterruptedIOException (java.io.InterruptedIOException)1 EnsuresNonNull (org.checkerframework.checker.nullness.qual.EnsuresNonNull)1 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)1