OggPacket { public OggPageHeader getPageHeader() { return pageHeader; }  void reset(); boolean populate(ExtractorInput input); OggPageHeader getPageHeader(); ParsableByteArray getPayload(); void trimPayload();  }
@Test 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 = OggTestData.createInput( TestUtil.joinByteArrays( OggTestData.buildOggHeader(0x02, 0, 1000, 0x01), TestUtil.createByteArray(0x08), firstPacket, OggTestData.buildOggHeader(0x00, 16, 1001, 0x02), TestUtil.createByteArray(0xFF, 0x11), secondPacket, OggTestData.buildOggHeader(0x00, 16, 1002, 0x00), OggTestData.buildOggHeader(0x04, 128, 1003, 0x04), TestUtil.createByteArray(0xFF, 0x01, 0xFF, 0x10), thirdPacket, fourthPacket), true); assertReadPacket(input, firstPacket); assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isTrue(); assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isFalse(); assertThat(oggPacket.getPageHeader().type).isEqualTo(0x02); assertThat(oggPacket.getPageHeader().headerSize).isEqualTo(27 + 1); assertThat(oggPacket.getPageHeader().bodySize).isEqualTo(8); assertThat(oggPacket.getPageHeader().revision).isEqualTo(0x00); assertThat(oggPacket.getPageHeader().pageSegmentCount).isEqualTo(1); assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1000); assertThat(oggPacket.getPageHeader().streamSerialNumber).isEqualTo(4096); assertThat(oggPacket.getPageHeader().granulePosition).isEqualTo(0); assertReadPacket(input, secondPacket); assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isFalse(); assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isFalse(); assertThat(oggPacket.getPageHeader().type).isEqualTo(0); assertThat(oggPacket.getPageHeader().headerSize).isEqualTo(27 + 2); assertThat(oggPacket.getPageHeader().bodySize).isEqualTo(255 + 17); assertThat(oggPacket.getPageHeader().pageSegmentCount).isEqualTo(2); assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1001); assertThat(oggPacket.getPageHeader().granulePosition).isEqualTo(16); assertReadPacket(input, thirdPacket); assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isFalse(); assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isTrue(); assertThat(oggPacket.getPageHeader().type).isEqualTo(4); assertThat(oggPacket.getPageHeader().headerSize).isEqualTo(27 + 4); assertThat(oggPacket.getPageHeader().bodySize).isEqualTo(255 + 1 + 255 + 16); assertThat(oggPacket.getPageHeader().pageSegmentCount).isEqualTo(4); assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1003); assertThat(oggPacket.getPageHeader().granulePosition).isEqualTo(128); assertReadPacket(input, fourthPacket); assertReadEof(input); }
@Test public void testReadContinuedPacketOverTwoPages() throws Exception { byte[] firstPacket = TestUtil.buildTestData(518); FakeExtractorInput input = OggTestData.createInput( TestUtil.joinByteArrays( OggTestData.buildOggHeader(0x02, 0, 1000, 0x02), TestUtil.createByteArray(0xFF, 0xFF), Arrays.copyOf(firstPacket, 510), OggTestData.buildOggHeader(0x05, 10, 1001, 0x01), TestUtil.createByteArray(0x08), Arrays.copyOfRange(firstPacket, 510, 510 + 8)), true); assertReadPacket(input, firstPacket); assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isTrue(); assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isFalse(); assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1001); assertReadEof(input); }
@Test public void testReadContinuedPacketOverFourPages() throws Exception { byte[] firstPacket = TestUtil.buildTestData(1028); FakeExtractorInput input = OggTestData.createInput( TestUtil.joinByteArrays( OggTestData.buildOggHeader(0x02, 0, 1000, 0x02), TestUtil.createByteArray(0xFF, 0xFF), Arrays.copyOf(firstPacket, 510), OggTestData.buildOggHeader(0x01, 10, 1001, 0x01), TestUtil.createByteArray(0xFF), Arrays.copyOfRange(firstPacket, 510, 510 + 255), OggTestData.buildOggHeader(0x01, 10, 1002, 0x01), TestUtil.createByteArray(0xFF), Arrays.copyOfRange(firstPacket, 510 + 255, 510 + 255 + 255), OggTestData.buildOggHeader(0x05, 10, 1003, 0x01), TestUtil.createByteArray(0x08), Arrays.copyOfRange(firstPacket, 510 + 255 + 255, 510 + 255 + 255 + 8)), true); assertReadPacket(input, firstPacket); assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isTrue(); assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isFalse(); assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1003); assertReadEof(input); }