Search in sources :

Example 16 with DefaultExtractorInput

use of com.google.android.exoplayer2.extractor.DefaultExtractorInput in project ExoPlayer by google.

the class DefaultExtractorInputTest method initialPosition.

@Test
public void initialPosition() throws Exception {
    FakeDataSource testDataSource = buildDataSource();
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 123, C.LENGTH_UNSET);
    assertThat(input.getPosition()).isEqualTo(123);
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) Test(org.junit.Test)

Example 17 with DefaultExtractorInput

use of com.google.android.exoplayer2.extractor.DefaultExtractorInput in project ExoPlayer by google.

the class DefaultExtractorInputTest method largeSkip.

@Test
public void largeSkip() throws Exception {
    FakeDataSource testDataSource = buildLargeDataSource();
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
    // Check that skipping the entire data source succeeds.
    int bytesToSkip = LARGE_TEST_DATA_LENGTH;
    while (bytesToSkip > 0) {
        int skipped = input.skip(bytesToSkip);
        assertThat(skipped).isGreaterThan(0);
        bytesToSkip -= skipped;
    }
    assertThat(bytesToSkip).isEqualTo(0);
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) Test(org.junit.Test)

Example 18 with DefaultExtractorInput

use of com.google.android.exoplayer2.extractor.DefaultExtractorInput in project ExoPlayer by google.

the class DefaultExtractorInputTest method testLargeSkip.

public void testLargeSkip() throws Exception {
    FakeDataSource testDataSource = buildLargeDataSource();
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
    // Check that skipping the entire data source succeeds.
    int bytesToSkip = LARGE_TEST_DATA_LENGTH;
    while (bytesToSkip > 0) {
        bytesToSkip -= input.skip(bytesToSkip);
    }
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource)

Example 19 with DefaultExtractorInput

use of com.google.android.exoplayer2.extractor.DefaultExtractorInput in project ExoPlayer by google.

the class ExtractorUtilTest method peekFullyQuietly_endNotReached_isTrueAndPeeksData.

@Test
public void peekFullyQuietly_endNotReached_isTrueAndPeeksData() 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.peekFullyQuietly(input, target, offset, length, /* allowEndOfInput= */
    false);
    assertThat(hasRead).isTrue();
    assertThat(input.getPeekPosition()).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 20 with DefaultExtractorInput

use of com.google.android.exoplayer2.extractor.DefaultExtractorInput in project ExoPlayer by google.

the class ExtractorUtilTest method readFullyQuietly_endReached_isFalse.

@Test
public void readFullyQuietly_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);
    byte[] target = new byte[TEST_DATA.length];
    int offset = 0;
    int length = TEST_DATA.length + 1;
    boolean hasRead = ExtractorUtil.readFullyQuietly(input, target, offset, 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)

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