Search in sources :

Example 1 with DefaultExtractorInput

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

the class DefaultExtractorInputTest method testSkipFullyWithFailingDataSource.

public void testSkipFullyWithFailingDataSource() 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.
    assertEquals(0, input.getPosition());
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) IOException(java.io.IOException)

Example 2 with DefaultExtractorInput

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

the class DefaultExtractorInputTest method testReadFullyWithFailingDataSource.

public void testReadFullyWithFailingDataSource() throws Exception {
    FakeDataSource testDataSource = buildFailingDataSource();
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
    try {
        byte[] target = new byte[TEST_DATA.length];
        input.readFully(target, 0, TEST_DATA.length);
        fail();
    } catch (IOException e) {
    // Expected.
    }
    // The position should not have advanced.
    assertEquals(0, input.getPosition());
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) IOException(java.io.IOException)

Example 3 with DefaultExtractorInput

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

the class DefaultExtractorInputTest method testInitialPosition.

public void testInitialPosition() throws Exception {
    FakeDataSource testDataSource = buildDataSource();
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 123, C.LENGTH_UNSET);
    assertEquals(123, input.getPosition());
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource)

Example 4 with DefaultExtractorInput

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

the class DefaultExtractorInputTest method testSkipFullyLarge.

public void testSkipFullyLarge() throws Exception {
    // Tests skipping an amount of data that's larger than any internal scratch space.
    int largeSkipSize = 1024 * 1024;
    FakeDataSource.Builder builder = new FakeDataSource.Builder();
    builder.appendReadData(new byte[largeSkipSize]);
    FakeDataSource testDataSource = builder.build();
    testDataSource.open(new DataSpec(Uri.parse(TEST_URI)));
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
    input.skipFully(largeSkipSize);
    assertEquals(largeSkipSize, input.getPosition());
    // 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)

Example 5 with DefaultExtractorInput

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

the class DefaultExtractorInputTest method testSkip.

public void testSkip() throws Exception {
    FakeDataSource testDataSource = buildDataSource();
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
    // We expect to perform three skips of three bytes, as setup in buildTestDataSource.
    for (int i = 0; i < 3; i++) {
        assertEquals(3, input.skip(TEST_DATA.length));
    }
    // Check we're now indicated that the end of input is reached.
    int expectedEndOfInput = input.skip(TEST_DATA.length);
    assertEquals(C.RESULT_END_OF_INPUT, expectedEndOfInput);
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource)

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