use of com.google.android.exoplayer2.testutil.FakeExtractorInput in project ExoPlayer by google.
the class DefaultOggSeekerUtilMethodsTest method testSkipToPageOfGranule.
public void testSkipToPageOfGranule() throws IOException, InterruptedException {
byte[] packet = TestUtil.buildTestData(3 * 254, random);
byte[] data = TestUtil.joinByteArrays(TestData.buildOggHeader(0x01, 20000, 1000, 0x03), // Laces.
TestUtil.createByteArray(254, 254, 254), packet, TestData.buildOggHeader(0x04, 40000, 1001, 0x03), // Laces.
TestUtil.createByteArray(254, 254, 254), packet, TestData.buildOggHeader(0x04, 60000, 1002, 0x03), // Laces.
TestUtil.createByteArray(254, 254, 254), packet);
FakeExtractorInput input = new FakeExtractorInput.Builder().setData(data).build();
// expect to be granule of the previous page returned as elapsedSamples
skipToPageOfGranule(input, 54000, 40000);
// expect to be at the start of the third page
assertEquals(2 * (30 + (3 * 254)), input.getPosition());
}
use of com.google.android.exoplayer2.testutil.FakeExtractorInput in project ExoPlayer by google.
the class DefaultOggSeekerUtilMethodsTest method testSkipToPageOfGranulePreciseMatch.
public void testSkipToPageOfGranulePreciseMatch() throws IOException, InterruptedException {
byte[] packet = TestUtil.buildTestData(3 * 254, random);
byte[] data = TestUtil.joinByteArrays(TestData.buildOggHeader(0x01, 20000, 1000, 0x03), // Laces.
TestUtil.createByteArray(254, 254, 254), packet, TestData.buildOggHeader(0x04, 40000, 1001, 0x03), // Laces.
TestUtil.createByteArray(254, 254, 254), packet, TestData.buildOggHeader(0x04, 60000, 1002, 0x03), // Laces.
TestUtil.createByteArray(254, 254, 254), packet);
FakeExtractorInput input = new FakeExtractorInput.Builder().setData(data).build();
skipToPageOfGranule(input, 40000, 20000);
// expect to be at the start of the second page
assertEquals((30 + (3 * 254)), input.getPosition());
}
use of com.google.android.exoplayer2.testutil.FakeExtractorInput in project ExoPlayer by google.
the class DefaultOggSeekerUtilMethodsTest method testSkipToNextPageNoMatch.
public void testSkipToNextPageNoMatch() throws Exception {
FakeExtractorInput extractorInput = TestData.createInput(new byte[] { 'g', 'g', 'S', 'O', 'g', 'g' }, false);
try {
skipToNextPage(extractorInput);
fail();
} catch (EOFException e) {
// expected
}
}
use of com.google.android.exoplayer2.testutil.FakeExtractorInput in project ExoPlayer by google.
the class OggPacketTest method testReadPacketsWithEmptyPage.
public void testReadPacketsWithEmptyPage() throws Exception {
byte[] firstPacket = TestUtil.buildTestData(8, random);
byte[] secondPacket = TestUtil.buildTestData(272, random);
byte[] thirdPacket = TestUtil.buildTestData(256, random);
byte[] fourthPacket = TestUtil.buildTestData(271, random);
FakeExtractorInput input = TestData.createInput(TestUtil.joinByteArrays(// First page with a single packet.
TestData.buildOggHeader(0x02, 0, 1000, 0x01), // Laces
TestUtil.createByteArray(0x08), firstPacket, // Second page with a single packet.
TestData.buildOggHeader(0x00, 16, 1001, 0x02), // Laces
TestUtil.createByteArray(0xFF, 0x11), secondPacket, // Third page with zero packets.
TestData.buildOggHeader(0x00, 16, 1002, 0x00), // Fourth page with two packets.
TestData.buildOggHeader(0x04, 128, 1003, 0x04), // Laces
TestUtil.createByteArray(0xFF, 0x01, 0xFF, 0x10), thirdPacket, fourthPacket), true);
assertReadPacket(input, firstPacket);
assertTrue((oggPacket.getPageHeader().type & 0x02) == 0x02);
assertFalse((oggPacket.getPageHeader().type & 0x04) == 0x04);
assertEquals(0x02, oggPacket.getPageHeader().type);
assertEquals(27 + 1, oggPacket.getPageHeader().headerSize);
assertEquals(8, oggPacket.getPageHeader().bodySize);
assertEquals(0x00, oggPacket.getPageHeader().revision);
assertEquals(1, oggPacket.getPageHeader().pageSegmentCount);
assertEquals(1000, oggPacket.getPageHeader().pageSequenceNumber);
assertEquals(4096, oggPacket.getPageHeader().streamSerialNumber);
assertEquals(0, oggPacket.getPageHeader().granulePosition);
assertReadPacket(input, secondPacket);
assertFalse((oggPacket.getPageHeader().type & 0x02) == 0x02);
assertFalse((oggPacket.getPageHeader().type & 0x04) == 0x04);
assertEquals(0, oggPacket.getPageHeader().type);
assertEquals(27 + 2, oggPacket.getPageHeader().headerSize);
assertEquals(255 + 17, oggPacket.getPageHeader().bodySize);
assertEquals(2, oggPacket.getPageHeader().pageSegmentCount);
assertEquals(1001, oggPacket.getPageHeader().pageSequenceNumber);
assertEquals(16, oggPacket.getPageHeader().granulePosition);
assertReadPacket(input, thirdPacket);
assertFalse((oggPacket.getPageHeader().type & 0x02) == 0x02);
assertTrue((oggPacket.getPageHeader().type & 0x04) == 0x04);
assertEquals(4, oggPacket.getPageHeader().type);
assertEquals(27 + 4, oggPacket.getPageHeader().headerSize);
assertEquals(255 + 1 + 255 + 16, oggPacket.getPageHeader().bodySize);
assertEquals(4, oggPacket.getPageHeader().pageSegmentCount);
// Page 1002 is empty, so current page is 1003.
assertEquals(1003, oggPacket.getPageHeader().pageSequenceNumber);
assertEquals(128, oggPacket.getPageHeader().granulePosition);
assertReadPacket(input, fourthPacket);
assertReadEof(input);
}
use of com.google.android.exoplayer2.testutil.FakeExtractorInput in project ExoPlayer by google.
the class OggPacketTest method testReadContinuedPacketOverFourPages.
public void testReadContinuedPacketOverFourPages() throws Exception {
byte[] firstPacket = TestUtil.buildTestData(1028);
FakeExtractorInput input = TestData.createInput(TestUtil.joinByteArrays(// First page.
TestData.buildOggHeader(0x02, 0, 1000, 0x02), // Laces.
TestUtil.createByteArray(0xFF, 0xFF), Arrays.copyOf(firstPacket, 510), // Second page (continued packet).
TestData.buildOggHeader(0x01, 10, 1001, 0x01), // Laces.
TestUtil.createByteArray(0xFF), Arrays.copyOfRange(firstPacket, 510, 510 + 255), // Third page (continued packet).
TestData.buildOggHeader(0x01, 10, 1002, 0x01), // Laces.
TestUtil.createByteArray(0xFF), Arrays.copyOfRange(firstPacket, 510 + 255, 510 + 255 + 255), // Fourth page (continued packet).
TestData.buildOggHeader(0x05, 10, 1003, 0x01), // Laces.
TestUtil.createByteArray(0x08), Arrays.copyOfRange(firstPacket, 510 + 255 + 255, 510 + 255 + 255 + 8)), true);
assertReadPacket(input, firstPacket);
assertTrue((oggPacket.getPageHeader().type & 0x04) == 0x04);
assertFalse((oggPacket.getPageHeader().type & 0x02) == 0x02);
assertEquals(1003, oggPacket.getPageHeader().pageSequenceNumber);
assertReadEof(input);
}
Aggregations