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.");
}
}
}
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());
}
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
}
}
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
}
}
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());
}
Aggregations