com.google.android.exoplayer.testutil.FakeExtractorInput

Here are the examples of the java api class com.google.android.exoplayer.testutil.FakeExtractorInput taken from open source projects.

1. OggParserTest#testReadGranuleOfLastPage()

Project: ExoPlayer
Source File: OggParserTest.java
View license
public void testReadGranuleOfLastPage() throws IOException, InterruptedException {
    FakeExtractorInput input = TestData.createInput(TestUtil.joinByteArrays(TestUtil.buildTestData(100, random), TestData.buildOggHeader(0x00, 20000, 66, 3), // laces
    TestUtil.createByteArray(254, 254, 254), TestUtil.buildTestData(3 * 254, random), TestData.buildOggHeader(0x00, 40000, 67, 3), // laces
    TestUtil.createByteArray(254, 254, 254), TestUtil.buildTestData(3 * 254, random), TestData.buildOggHeader(0x05, 60000, 68, 3), // laces
    TestUtil.createByteArray(254, 254, 254), TestUtil.buildTestData(3 * 254, random)), false);
    assertReadGranuleOfLastPage(input, 60000);
}

2. OggUtilTest#testPopulatePageHeaderQuiteOnExceptionNotOgg()

Project: ExoPlayer
Source File: OggUtilTest.java
View license
public void testPopulatePageHeaderQuiteOnExceptionNotOgg() throws IOException, InterruptedException {
    byte[] headerBytes = TestUtil.joinByteArrays(TestData.buildOggHeader(0x01, 123456, 4, 2), TestUtil.createByteArray(2, 2));
    // change from 'O' to 'o'
    headerBytes[0] = 'o';
    FakeExtractorInput input = TestData.createInput(headerBytes, false);
    OggUtil.PageHeader header = new OggUtil.PageHeader();
    ParsableByteArray byteArray = new ParsableByteArray(27 + 2);
    assertFalse(populatePageHeader(input, header, byteArray, true));
}

3. OggUtilTest#testPopulatePageHeaderQuiteOnExceptionWrongRevision()

Project: ExoPlayer
Source File: OggUtilTest.java
View license
public void testPopulatePageHeaderQuiteOnExceptionWrongRevision() throws IOException, InterruptedException {
    byte[] headerBytes = TestUtil.joinByteArrays(TestData.buildOggHeader(0x01, 123456, 4, 2), TestUtil.createByteArray(2, 2));
    // change revision from 0 to 1
    headerBytes[4] = 0x01;
    FakeExtractorInput input = TestData.createInput(headerBytes, false);
    OggUtil.PageHeader header = new OggUtil.PageHeader();
    ParsableByteArray byteArray = new ParsableByteArray(27 + 2);
    assertFalse(populatePageHeader(input, header, byteArray, true));
}

4. OggUtilTest#testPopulatePageHeader()

Project: ExoPlayer
Source File: OggUtilTest.java
View license
public void testPopulatePageHeader() throws IOException, InterruptedException {
    FakeExtractorInput input = TestData.createInput(TestUtil.joinByteArrays(TestData.buildOggHeader(0x01, 123456, 4, 2), TestUtil.createByteArray(2, 2)), true);
    OggUtil.PageHeader header = new OggUtil.PageHeader();
    ParsableByteArray byteArray = new ParsableByteArray(27 + 2);
    populatePageHeader(input, header, byteArray, false);
    assertEquals(0x01, header.type);
    assertEquals(27 + 2, header.headerSize);
    assertEquals(4, header.bodySize);
    assertEquals(2, header.pageSegmentCount);
    assertEquals(123456, header.granulePosition);
    assertEquals(4, header.pageSequenceNumber);
    assertEquals(0x1000, header.streamSerialNumber);
    assertEquals(0x100000, header.pageChecksum);
    assertEquals(0, header.revision);
}

5. OggSeekerTest#testGetNextSeekPositionTooHighDistanceLower48000()

Project: ExoPlayer
Source File: OggSeekerTest.java
View license
public void testGetNextSeekPositionTooHighDistanceLower48000() throws IOException, InterruptedException {
    long targetGranule = 199999;
    long headerGranule = 200000;
    FakeExtractorInput input = TestData.createInput(TestUtil.joinByteArrays(TestData.buildOggHeader(0x00, headerGranule, 22, 2), // laces
    TestUtil.createByteArray(54, 55)), false);
    long doublePageSize = 2 * (input.getLength() + 54 + 55);
    long expectedPosition = -doublePageSize - 1;
    assertGetNextSeekPosition(expectedPosition, targetGranule, input);
}

6. OggParserTest#testSkipToPageOfGranuleAfterTargetPage()

Project: ExoPlayer
Source File: OggParserTest.java
View license
public void testSkipToPageOfGranuleAfterTargetPage() throws IOException, InterruptedException {
    byte[] packet = TestUtil.buildTestData(3 * 254, random);
    FakeExtractorInput input = TestData.createInput(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), false);
    try {
        skipToPageOfGranule(input, 10000, 20000);
        fail();
    } catch (ParserException e) {
    }
    assertEquals(0, input.getPosition());
}

7. OggParserTest#testSkipToPageOfGranulePreciseMatch()

Project: ExoPlayer
Source File: OggParserTest.java
View license
public void testSkipToPageOfGranulePreciseMatch() throws IOException, InterruptedException {
    byte[] packet = TestUtil.buildTestData(3 * 254, random);
    FakeExtractorInput input = TestData.createInput(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), false);
    skipToPageOfGranule(input, 40000, 20000);
    // expect to be at the start of the second page
    assertEquals((30 + (3 * 254)), input.getPosition());
}

8. OggParserTest#testSkipToPageOfGranule()

Project: ExoPlayer
Source File: OggParserTest.java
View license
public void testSkipToPageOfGranule() throws IOException, InterruptedException {
    byte[] packet = TestUtil.buildTestData(3 * 254, random);
    FakeExtractorInput input = TestData.createInput(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), false);
    // 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());
}

9. OggParserTest#testReadZeroSizedPacketsAtEndOfStream()

Project: ExoPlayer
Source File: OggParserTest.java
View license
public void testReadZeroSizedPacketsAtEndOfStream() throws Exception {
    byte[] firstPacket = TestUtil.buildTestData(8, random);
    byte[] secondPacket = TestUtil.buildTestData(8, random);
    byte[] thirdPacket = TestUtil.buildTestData(8, random);
    FakeExtractorInput input = TestData.createInput(TestUtil.joinByteArrays(TestData.buildOggHeader(0x02, 0, 1000, 0x01), // Laces.
    TestUtil.createByteArray(0x08), firstPacket, TestData.buildOggHeader(0x04, 0, 1001, 0x03), // Laces.
    TestUtil.createByteArray(0x08, 0x00, 0x00), secondPacket, TestData.buildOggHeader(0x04, 0, 1002, 0x03), // Laces.
    TestUtil.createByteArray(0x08, 0x00, 0x00), thirdPacket), true);
    assertReadPacket(input, firstPacket);
    assertReadPacket(input, secondPacket);
    assertReadPacket(input, thirdPacket);
    assertReadEof(input);
}

10. OggParserTest#testReadDiscardContinuedPacketAtStart()

Project: ExoPlayer
Source File: OggParserTest.java
View license
public void testReadDiscardContinuedPacketAtStart() throws Exception {
    byte[] pageBody = TestUtil.buildTestData(256 + 8);
    FakeExtractorInput input = TestData.createInput(TestUtil.joinByteArrays(// Page with a continued packet at start.
    TestData.buildOggHeader(0x01, 10, 1001, 0x03), // Laces.
    TestUtil.createByteArray(255, 1, 8), pageBody), true);
    // Expect the first partial packet to be discarded.
    assertReadPacket(input, Arrays.copyOfRange(pageBody, 256, 256 + 8));
    assertReadEof(input);
}

11. OggParserTest#testReadContinuedPacketOverTwoPages()

Project: ExoPlayer
Source File: OggParserTest.java
View license
public void testReadContinuedPacketOverTwoPages() throws Exception {
    byte[] firstPacket = TestUtil.buildTestData(518);
    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(0x05, 10, 1001, 0x01), // Laces.
    TestUtil.createByteArray(0x08), Arrays.copyOfRange(firstPacket, 510, 510 + 8)), true);
    assertReadPacket(input, firstPacket);
    assertTrue((oggParser.getPageHeader().type & 0x04) == 0x04);
    assertFalse((oggParser.getPageHeader().type & 0x02) == 0x02);
    assertEquals(1001, oggParser.getPageHeader().pageSequenceNumber);
    assertReadEof(input);
}

12. OggParserTest#testReadPacketWithZeroSizeTerminator()

Project: ExoPlayer
Source File: OggParserTest.java
View license
public void testReadPacketWithZeroSizeTerminator() throws Exception {
    byte[] firstPacket = TestUtil.buildTestData(255, random);
    byte[] secondPacket = TestUtil.buildTestData(8, random);
    FakeExtractorInput input = TestData.createInput(TestUtil.joinByteArrays(TestData.buildOggHeader(0x06, 0, 1000, 0x04), // Laces.
    TestUtil.createByteArray(0xFF, 0x00, 0x00, 0x08), firstPacket, secondPacket), true);
    assertReadPacket(input, firstPacket);
    assertReadPacket(input, secondPacket);
    assertReadEof(input);
}

13. OggUtilTest#testSkipToNextPageNoMatch()

Project: ExoPlayer
Source File: OggUtilTest.java
View license
public void testSkipToNextPageNoMatch() throws Exception {
    FakeExtractorInput extractorInput = createInput(new byte[] { 'g', 'g', 'S', 'O', 'g', 'g' }, false);
    try {
        skipToNextPage(extractorInput);
        fail();
    } catch (EOFException e) {
    }
}

14. OggUtilTest#testSkipToNextPageInputShorterThanPeekLength()

Project: ExoPlayer
Source File: OggUtilTest.java
View license
public void testSkipToNextPageInputShorterThanPeekLength() throws Exception {
    FakeExtractorInput extractorInput = createInput(TestUtil.joinByteArrays(new byte[] { 'x', 'O', 'g', 'g', 'S' }), false);
    skipToNextPage(extractorInput);
    assertEquals(1, extractorInput.getPosition());
}

15. OggUtilTest#testSkipToNextPageOverlapUnbounded()

Project: ExoPlayer
Source File: OggUtilTest.java
View license
public void testSkipToNextPageOverlapUnbounded() throws Exception {
    FakeExtractorInput extractorInput = createInput(TestUtil.joinByteArrays(TestUtil.buildTestData(2046, random), new byte[] { 'O', 'g', 'g', 'S' }, TestUtil.buildTestData(4000, random)), true);
    skipToNextPage(extractorInput);
    assertEquals(2046, extractorInput.getPosition());
}

16. OggUtilTest#testSkipToNextPageOverlap()

Project: ExoPlayer
Source File: OggUtilTest.java
View license
public void testSkipToNextPageOverlap() throws Exception {
    FakeExtractorInput extractorInput = createInput(TestUtil.joinByteArrays(TestUtil.buildTestData(2046, random), new byte[] { 'O', 'g', 'g', 'S' }, TestUtil.buildTestData(4000, random)), false);
    skipToNextPage(extractorInput);
    assertEquals(2046, extractorInput.getPosition());
}

17. OggUtilTest#testSkipToNextPageUnbounded()

Project: ExoPlayer
Source File: OggUtilTest.java
View license
public void testSkipToNextPageUnbounded() throws Exception {
    FakeExtractorInput extractorInput = createInput(TestUtil.joinByteArrays(TestUtil.buildTestData(4000, random), new byte[] { 'O', 'g', 'g', 'S' }, TestUtil.buildTestData(4000, random)), true);
    skipToNextPage(extractorInput);
    assertEquals(4000, extractorInput.getPosition());
}

18. OggUtilTest#testSkipToNextPage()

Project: ExoPlayer
Source File: OggUtilTest.java
View license
public void testSkipToNextPage() throws Exception {
    FakeExtractorInput extractorInput = createInput(TestUtil.joinByteArrays(TestUtil.buildTestData(4000, random), new byte[] { 'O', 'g', 'g', 'S' }, TestUtil.buildTestData(4000, random)), false);
    skipToNextPage(extractorInput);
    assertEquals(4000, extractorInput.getPosition());
}

19. OggParserTest#testReadPacketsWithEmptyPage()

Project: ExoPlayer
Source File: OggParserTest.java
View license
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((oggParser.getPageHeader().type & 0x02) == 0x02);
    assertFalse((oggParser.getPageHeader().type & 0x04) == 0x04);
    assertEquals(0x02, oggParser.getPageHeader().type);
    assertEquals(27 + 1, oggParser.getPageHeader().headerSize);
    assertEquals(8, oggParser.getPageHeader().bodySize);
    assertEquals(0x00, oggParser.getPageHeader().revision);
    assertEquals(1, oggParser.getPageHeader().pageSegmentCount);
    assertEquals(1000, oggParser.getPageHeader().pageSequenceNumber);
    assertEquals(4096, oggParser.getPageHeader().streamSerialNumber);
    assertEquals(0, oggParser.getPageHeader().granulePosition);
    assertReadPacket(input, secondPacket);
    assertFalse((oggParser.getPageHeader().type & 0x02) == 0x02);
    assertFalse((oggParser.getPageHeader().type & 0x04) == 0x04);
    assertEquals(0, oggParser.getPageHeader().type);
    assertEquals(27 + 2, oggParser.getPageHeader().headerSize);
    assertEquals(255 + 17, oggParser.getPageHeader().bodySize);
    assertEquals(2, oggParser.getPageHeader().pageSegmentCount);
    assertEquals(1001, oggParser.getPageHeader().pageSequenceNumber);
    assertEquals(16, oggParser.getPageHeader().granulePosition);
    assertReadPacket(input, thirdPacket);
    assertFalse((oggParser.getPageHeader().type & 0x02) == 0x02);
    assertTrue((oggParser.getPageHeader().type & 0x04) == 0x04);
    assertEquals(4, oggParser.getPageHeader().type);
    assertEquals(27 + 4, oggParser.getPageHeader().headerSize);
    assertEquals(255 + 1 + 255 + 16, oggParser.getPageHeader().bodySize);
    assertEquals(4, oggParser.getPageHeader().pageSegmentCount);
    // Page 1002 is empty, so current page is 1003.
    assertEquals(1003, oggParser.getPageHeader().pageSequenceNumber);
    assertEquals(128, oggParser.getPageHeader().granulePosition);
    assertReadPacket(input, fourthPacket);
    assertReadEof(input);
}

20. OggUtilTest#testPopulatePageHeaderQuiteOnExceptionLessThan27Bytes()

Project: ExoPlayer
Source File: OggUtilTest.java
View license
public void testPopulatePageHeaderQuiteOnExceptionLessThan27Bytes() throws IOException, InterruptedException {
    FakeExtractorInput input = TestData.createInput(TestUtil.createByteArray(2, 2), false);
    OggUtil.PageHeader header = new OggUtil.PageHeader();
    ParsableByteArray byteArray = new ParsableByteArray(27 + 2);
    assertFalse(populatePageHeader(input, header, byteArray, true));
}

21. OggSeekerTest#testGetNextSeekPositionTooLow()

Project: ExoPlayer
Source File: OggSeekerTest.java
View license
public void testGetNextSeekPositionTooLow() throws IOException, InterruptedException {
    long headerGranule = 200000;
    FakeExtractorInput input = TestData.createInput(TestUtil.joinByteArrays(TestData.buildOggHeader(0x00, headerGranule, 22, 2), // laces
    TestUtil.createByteArray(54, 55)), false);
    long targetGranule = 300000;
    long expectedPosition = -(27 + 2 + 54 + 55) + (targetGranule - headerGranule);
    assertGetNextSeekPosition(expectedPosition, targetGranule, input);
}

22. OggSeekerTest#testGetNextSeekPositionTooHigh()

Project: ExoPlayer
Source File: OggSeekerTest.java
View license
public void testGetNextSeekPositionTooHigh() throws IOException, InterruptedException {
    long targetGranule = 100000;
    long headerGranule = 200000;
    FakeExtractorInput input = TestData.createInput(TestUtil.joinByteArrays(TestData.buildOggHeader(0x00, headerGranule, 22, 2), // laces
    TestUtil.createByteArray(54, 55)), false);
    long doublePageSize = 2 * (input.getLength() + 54 + 55);
    long expectedPosition = -doublePageSize + (targetGranule - headerGranule);
    assertGetNextSeekPosition(expectedPosition, targetGranule, input);
}

23. OggSeekerTest#testGetNextSeekPositionMatch()

Project: ExoPlayer
Source File: OggSeekerTest.java
View license
public void testGetNextSeekPositionMatch() throws IOException, InterruptedException {
    long targetGranule = 100000;
    long headerGranule = 52001;
    FakeExtractorInput input = TestData.createInput(TestUtil.joinByteArrays(TestData.buildOggHeader(0x00, headerGranule, 22, 2), // laces
    TestUtil.createByteArray(54, 55)), false);
    long expectedPosition = -1;
    assertGetNextSeekPosition(expectedPosition, targetGranule, input);
}

24. OggParserTest#testReadGranuleOfLastPageWithUnboundedLength()

Project: ExoPlayer
Source File: OggParserTest.java
View license
public void testReadGranuleOfLastPageWithUnboundedLength() throws IOException, InterruptedException {
    FakeExtractorInput input = TestData.createInput(new byte[0], true);
    try {
        assertReadGranuleOfLastPage(input, 60000);
        fail();
    } catch (IllegalArgumentException e) {
    }
}

25. OggParserTest#testReadGranuleOfLastPageAfterLastHeader()

Project: ExoPlayer
Source File: OggParserTest.java
View license
public void testReadGranuleOfLastPageAfterLastHeader() throws IOException, InterruptedException {
    FakeExtractorInput input = TestData.createInput(TestUtil.buildTestData(100, random), false);
    try {
        assertReadGranuleOfLastPage(input, 60000);
        fail();
    } catch (EOFException e) {
    }
}

26. OggParserTest#testReadContinuedPacketOverFourPages()

Project: ExoPlayer
Source File: OggParserTest.java
View license
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((oggParser.getPageHeader().type & 0x04) == 0x04);
    assertFalse((oggParser.getPageHeader().type & 0x02) == 0x02);
    assertEquals(1003, oggParser.getPageHeader().pageSequenceNumber);
    assertReadEof(input);
}