Search in sources :

Example 1 with FakeExtractorInput

use of com.google.android.exoplayer2.testutil.FakeExtractorInput in project ExoPlayer by google.

the class DefaultOggSeekerTest method testSeeking.

private void testSeeking(Random random) throws IOException, InterruptedException {
    OggTestFile testFile = OggTestFile.generate(random, 1000);
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(testFile.data).build();
    TestStreamReader streamReader = new TestStreamReader();
    DefaultOggSeeker oggSeeker = new DefaultOggSeeker(0, testFile.data.length, streamReader, testFile.firstPayloadPageSize, testFile.firstPayloadPageGranulePosition);
    OggPageHeader pageHeader = new OggPageHeader();
    while (true) {
        long nextSeekPosition = oggSeeker.read(input);
        if (nextSeekPosition == -1) {
            break;
        }
        input.setPosition((int) nextSeekPosition);
    }
    // Test granule 0 from file start
    assertEquals(0, seekTo(input, oggSeeker, 0, 0));
    assertEquals(0, input.getPosition());
    // Test granule 0 from file end
    assertEquals(0, seekTo(input, oggSeeker, 0, testFile.data.length - 1));
    assertEquals(0, input.getPosition());
    {
        // Test last granule
        long currentGranule = seekTo(input, oggSeeker, testFile.lastGranule, 0);
        long position = testFile.data.length;
        assertTrue((testFile.lastGranule > currentGranule && position > input.getPosition()) || (testFile.lastGranule == currentGranule && position == input.getPosition()));
    }
    {
        // Test exact granule
        input.setPosition(testFile.data.length / 2);
        oggSeeker.skipToNextPage(input);
        assertTrue(pageHeader.populate(input, true));
        long position = input.getPosition() + pageHeader.headerSize + pageHeader.bodySize;
        long currentGranule = seekTo(input, oggSeeker, pageHeader.granulePosition, 0);
        assertTrue((pageHeader.granulePosition > currentGranule && position > input.getPosition()) || (pageHeader.granulePosition == currentGranule && position == input.getPosition()));
    }
    for (int i = 0; i < 100; i += 1) {
        long targetGranule = (long) (random.nextDouble() * testFile.lastGranule);
        int initialPosition = random.nextInt(testFile.data.length);
        long currentGranule = seekTo(input, oggSeeker, targetGranule, initialPosition);
        long currentPosition = input.getPosition();
        assertTrue("getNextSeekPosition() didn't leave input on a page start.", pageHeader.populate(input, true));
        if (currentGranule == 0) {
            assertEquals(0, currentPosition);
        } else {
            int previousPageStart = testFile.findPreviousPageStart(currentPosition);
            input.setPosition(previousPageStart);
            assertTrue(pageHeader.populate(input, true));
            assertEquals(pageHeader.granulePosition, currentGranule);
        }
        input.setPosition((int) currentPosition);
        oggSeeker.skipToPageOfGranule(input, targetGranule, -1);
        long positionDiff = Math.abs(input.getPosition() - currentPosition);
        long granuleDiff = currentGranule - targetGranule;
        if ((granuleDiff > DefaultOggSeeker.MATCH_RANGE || granuleDiff < 0) && positionDiff > DefaultOggSeeker.MATCH_BYTE_RANGE) {
            fail("granuleDiff (" + granuleDiff + ") or positionDiff (" + positionDiff + ") is more than allowed.");
        }
    }
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput)

Example 2 with FakeExtractorInput

use of com.google.android.exoplayer2.testutil.FakeExtractorInput in project ExoPlayer by google.

the class DefaultOggSeekerUtilMethodsTest method testSkipToNextPageInputShorterThanPeekLength.

public void testSkipToNextPageInputShorterThanPeekLength() throws Exception {
    FakeExtractorInput extractorInput = TestData.createInput(TestUtil.joinByteArrays(new byte[] { 'x', 'O', 'g', 'g', 'S' }), false);
    skipToNextPage(extractorInput);
    assertEquals(1, extractorInput.getPosition());
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput)

Example 3 with FakeExtractorInput

use of com.google.android.exoplayer2.testutil.FakeExtractorInput in project ExoPlayer by google.

the class DefaultOggSeekerUtilMethodsTest method testReadGranuleOfLastPageWithUnboundedLength.

public void testReadGranuleOfLastPageWithUnboundedLength() throws IOException, InterruptedException {
    FakeExtractorInput input = TestData.createInput(new byte[0], true);
    try {
        assertReadGranuleOfLastPage(input, 60000);
        fail();
    } catch (IllegalArgumentException e) {
    // ignored
    }
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput)

Example 4 with FakeExtractorInput

use of com.google.android.exoplayer2.testutil.FakeExtractorInput in project ExoPlayer by google.

the class DefaultOggSeekerUtilMethodsTest method testReadGranuleOfLastPageAfterLastHeader.

public void testReadGranuleOfLastPageAfterLastHeader() throws IOException, InterruptedException {
    FakeExtractorInput input = TestData.createInput(TestUtil.buildTestData(100, random), false);
    try {
        assertReadGranuleOfLastPage(input, 60000);
        fail();
    } catch (EOFException e) {
    // ignored
    }
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) EOFException(java.io.EOFException)

Example 5 with FakeExtractorInput

use of com.google.android.exoplayer2.testutil.FakeExtractorInput in project ExoPlayer by google.

the class DefaultOggSeekerUtilMethodsTest method testSkipToNextPageOverlap.

public void testSkipToNextPageOverlap() throws Exception {
    FakeExtractorInput extractorInput = TestData.createInput(TestUtil.joinByteArrays(TestUtil.buildTestData(2046, random), new byte[] { 'O', 'g', 'g', 'S' }, TestUtil.buildTestData(4000, random)), false);
    skipToNextPage(extractorInput);
    assertEquals(2046, extractorInput.getPosition());
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput)

Aggregations

FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)24 PositionHolder (com.google.android.exoplayer2.extractor.PositionHolder)3 FakeExtractorOutput (com.google.android.exoplayer2.testutil.FakeExtractorOutput)2 TimestampAdjuster (com.google.android.exoplayer2.util.TimestampAdjuster)2 EOFException (java.io.EOFException)2 SeekMap (com.google.android.exoplayer2.extractor.SeekMap)1 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)1 SimulatedIOException (com.google.android.exoplayer2.testutil.FakeExtractorInput.SimulatedIOException)1 FakeTrackOutput (com.google.android.exoplayer2.testutil.FakeTrackOutput)1 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)1