public void testParcelable() { DrmInitData.SchemeData DRM_DATA_1 = new DrmInitData.SchemeData(WIDEVINE_UUID, VIDEO_MP4, TestUtil.buildTestData(128, 1 /* data seed */)); DrmInitData.SchemeData DRM_DATA_2 = new DrmInitData.SchemeData(C.UUID_NIL, VIDEO_WEBM, TestUtil.buildTestData(128, 1 /* data seed */)); DrmInitData drmInitData = new DrmInitData(DRM_DATA_1, DRM_DATA_2); byte[] projectionData = new byte[] {1, 2, 3}; Format formatToParcel = new Format("id", MimeTypes.VIDEO_MP4, MimeTypes.VIDEO_H264, null, 1024, 2048, 1920, 1080, 24, 90, 2, projectionData, C.STEREO_MODE_TOP_BOTTOM, 6, 44100, C.ENCODING_PCM_24BIT, 1001, 1002, 0, "und", Format.OFFSET_SAMPLE_RELATIVE, INIT_DATA, drmInitData); Parcel parcel = Parcel.obtain(); formatToParcel.writeToParcel(parcel, 0); parcel.setDataPosition(0); Format formatFromParcel = Format.CREATOR.createFromParcel(parcel); assertEquals(formatToParcel, formatFromParcel); parcel.recycle(); }
public void testIncompleteSample() throws Exception { Random random = new Random(0); byte[] fileData = TestUtil.getByteArray(getInstrumentation(), "ts/sample.ts"); ByteArrayOutputStream out = new ByteArrayOutputStream(fileData.length * 2); writeJunkData(out, random.nextInt(TS_PACKET_SIZE - 1) + 1); out.write(fileData, 0, TS_PACKET_SIZE * 5); for (int i = TS_PACKET_SIZE * 5; i < fileData.length; i += TS_PACKET_SIZE) { writeJunkData(out, random.nextInt(TS_PACKET_SIZE)); out.write(fileData, i, TS_PACKET_SIZE); } out.write(TS_SYNC_BYTE); writeJunkData(out, random.nextInt(TS_PACKET_SIZE - 1) + 1); fileData = out.toByteArray(); TestUtil.assertOutput(new TestUtil.ExtractorFactory() { @Override public Extractor create() { return new TsExtractor(); } }, "ts/sample.ts", fileData, getInstrumentation()); }
public void testCustomPesReader() throws Exception { CustomEsReaderFactory factory = new CustomEsReaderFactory(); TsExtractor tsExtractor = new TsExtractor(new TimestampAdjuster(0), factory, false); FakeExtractorInput input = new FakeExtractorInput.Builder() .setData(TestUtil.getByteArray(getInstrumentation(), "ts/sample.ts")) .setSimulateIOErrors(false) .setSimulateUnknownLength(false) .setSimulatePartialReads(false).build(); FakeExtractorOutput output = new FakeExtractorOutput(); tsExtractor.init(output); tsExtractor.seek(input.getPosition()); PositionHolder seekPositionHolder = new PositionHolder(); int readResult = Extractor.RESULT_CONTINUE; while (readResult != Extractor.RESULT_END_OF_INPUT) { readResult = tsExtractor.read(input, seekPositionHolder); } CustomEsReader reader = factory.reader; assertEquals(2, reader.packetsRead); TrackOutput trackOutput = reader.getTrackOutput(); assertTrue(trackOutput == output.trackOutputs.get(257 /* PID of audio track. */)); assertEquals( Format.createTextSampleFormat("Overriding format", "mime", null, 0, 0, "und", null, 0), ((FakeTrackOutput) trackOutput).format); }
public void testSkipBits() { VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0xF0, 0x0F)); bitArray.skipBits(10); assertEquals(10, bitArray.getPosition()); assertTrue(bitArray.readBit()); assertTrue(bitArray.readBit()); assertFalse(bitArray.readBit()); bitArray.skipBits(1); assertEquals(14, bitArray.getPosition()); assertFalse(bitArray.readBit()); assertFalse(bitArray.readBit()); try { bitArray.readBit(); fail(); } catch (IllegalStateException e) { // ignored } }
public void testReadBitsBeyondByteBoundaries() throws Exception { VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0xFF, 0x0F, 0xFF, 0x0F)); assertEquals(0x0FFF0FFF, bitArray.readBits(32)); bitArray.reset(); bitArray.skipBits(4); assertEquals(0xF0FF, bitArray.readBits(16)); bitArray.reset(); bitArray.skipBits(6); assertEquals(0xc3F, bitArray.readBits(12)); bitArray.reset(); bitArray.skipBits(6); assertTrue(bitArray.readBit()); assertTrue(bitArray.readBit()); assertEquals(24, bitArray.bitsLeft()); bitArray.reset(); bitArray.skipBits(10); assertEquals(3, bitArray.readBits(5)); assertEquals(15, bitArray.getPosition()); }
public void testReadBitsIllegalLengths() throws Exception { VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0x03, 0x22, 0x30)); // reading zero bits gets 0 without advancing position // (like a zero-bit read is defined to yield zer0) assertEquals(0, bitArray.readBits(0)); assertEquals(0, bitArray.getPosition()); bitArray.readBit(); assertEquals(1, bitArray.getPosition()); try { bitArray.readBits(24); fail(); } catch (IllegalStateException e) { assertEquals(1, bitArray.getPosition()); } }
public void testSkipToPageOfGranule() throws IOException, InterruptedException { byte[] packet = TestUtil.buildTestData(3 * 254, random); byte[] data = TestUtil.joinByteArrays( TestData.buildOggHeader(0x01, 20000, 1000, 0x03), TestUtil.createByteArray(254, 254, 254), // Laces. packet, TestData.buildOggHeader(0x04, 40000, 1001, 0x03), TestUtil.createByteArray(254, 254, 254), // Laces. packet, TestData.buildOggHeader(0x04, 60000, 1002, 0x03), TestUtil.createByteArray(254, 254, 254), // Laces. 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()); }
public void testSkipToPageOfGranulePreciseMatch() throws IOException, InterruptedException { byte[] packet = TestUtil.buildTestData(3 * 254, random); byte[] data = TestUtil.joinByteArrays( TestData.buildOggHeader(0x01, 20000, 1000, 0x03), TestUtil.createByteArray(254, 254, 254), // Laces. packet, TestData.buildOggHeader(0x04, 40000, 1001, 0x03), TestUtil.createByteArray(254, 254, 254), // Laces. packet, TestData.buildOggHeader(0x04, 60000, 1002, 0x03), TestUtil.createByteArray(254, 254, 254), // Laces. 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()); }
public void testSkipToPageOfGranuleAfterTargetPage() throws IOException, InterruptedException { byte[] packet = TestUtil.buildTestData(3 * 254, random); byte[] data = TestUtil.joinByteArrays( TestData.buildOggHeader(0x01, 20000, 1000, 0x03), TestUtil.createByteArray(254, 254, 254), // Laces. packet, TestData.buildOggHeader(0x04, 40000, 1001, 0x03), TestUtil.createByteArray(254, 254, 254), // Laces. packet, TestData.buildOggHeader(0x04, 60000, 1002, 0x03), TestUtil.createByteArray(254, 254, 254), // Laces. packet); FakeExtractorInput input = new FakeExtractorInput.Builder().setData(data).build(); skipToPageOfGranule(input, 10000, -1); assertEquals(0, input.getPosition()); }
public void testPopulatePageHeader() throws IOException, InterruptedException { FakeExtractorInput input = TestData.createInput(TestUtil.joinByteArrays( TestData.buildOggHeader(0x01, 123456, 4, 2), TestUtil.createByteArray(2, 2) ), true); OggPageHeader header = new OggPageHeader(); populatePageHeader(input, header, 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); }
public void testReadContinuedPacketOverTwoPages() throws Exception { byte[] firstPacket = TestUtil.buildTestData(518); FakeExtractorInput input = TestData.createInput( TestUtil.joinByteArrays( // First page. TestData.buildOggHeader(0x02, 0, 1000, 0x02), TestUtil.createByteArray(0xFF, 0xFF), // Laces. Arrays.copyOf(firstPacket, 510), // Second page (continued packet). TestData.buildOggHeader(0x05, 10, 1001, 0x01), TestUtil.createByteArray(0x08), // Laces. Arrays.copyOfRange(firstPacket, 510, 510 + 8)), true); assertReadPacket(input, firstPacket); assertTrue((oggPacket.getPageHeader().type & 0x04) == 0x04); assertFalse((oggPacket.getPageHeader().type & 0x02) == 0x02); assertEquals(1001, oggPacket.getPageHeader().pageSequenceNumber); assertReadEof(input); }
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), TestUtil.createByteArray(0x08), // Laces. firstPacket, TestData.buildOggHeader(0x04, 0, 1001, 0x03), TestUtil.createByteArray(0x08, 0x00, 0x00), // Laces. secondPacket, TestData.buildOggHeader(0x04, 0, 1002, 0x03), TestUtil.createByteArray(0x08, 0x00, 0x00), // Laces. thirdPacket), true); assertReadPacket(input, firstPacket); assertReadPacket(input, secondPacket); assertReadPacket(input, thirdPacket); assertReadEof(input); }
public void testDecodeNoEndTimecodes() throws IOException { SubripDecoder decoder = new SubripDecoder(); byte[] bytes = TestUtil.getByteArray(getInstrumentation(), NO_END_TIMECODES_FILE); SubripSubtitle subtitle = decoder.decode(bytes, bytes.length); // Test event count. assertEquals(3, subtitle.getEventTimeCount()); // Test first cue. assertEquals(0, subtitle.getEventTime(0)); assertEquals("SubRip doesn't technically allow missing end timecodes.", subtitle.getCues(subtitle.getEventTime(0)).get(0).text.toString()); // Test second cue. assertEquals(2345000, subtitle.getEventTime(1)); assertEquals("We interpret it to mean that a subtitle extends to the start of the next one.", subtitle.getCues(subtitle.getEventTime(1)).get(0).text.toString()); // Test third cue. assertEquals(3456000, subtitle.getEventTime(2)); assertEquals("Or to the end of the media.", subtitle.getCues(subtitle.getEventTime(2)).get(0).text.toString()); }
public void testParseMediaPresentationDescriptionWithSegmentTemplate() throws IOException { DashManifestParser parser = new DashManifestParser(); DashManifest mpd = parser.parse(Uri.parse("https://example.com/test.mpd"), TestUtil.getInputStream(getInstrumentation(), SAMPLE_MPD_3_SEGMENT_TEMPLATE)); assertEquals(1, mpd.getPeriodCount()); Period period = mpd.getPeriod(0); assertNotNull(period); assertEquals(2, period.adaptationSets.size()); for (AdaptationSet adaptationSet : period.adaptationSets) { assertNotNull(adaptationSet); for (Representation representation : adaptationSet.representations) { if (representation instanceof Representation.MultiSegmentRepresentation) { Representation.MultiSegmentRepresentation multiSegmentRepresentation = (Representation.MultiSegmentRepresentation) representation; int firstSegmentIndex = multiSegmentRepresentation.getFirstSegmentNum(); RangedUri uri = multiSegmentRepresentation.getSegmentUrl(firstSegmentIndex); assertTrue(uri.resolveUriString(representation.baseUrl).contains( "redirector.googlevideo.com")); } } } }
public void testDownloadRepresentationInSmallParts() throws Exception { FakeDataSet fakeDataSet = new FakeDataSet() .setData(TEST_MPD_URI, TEST_MPD) .setRandomData("audio_init_data", 10) .newData("audio_segment_1") .appendReadData(TestUtil.buildTestData(10)) .appendReadData(TestUtil.buildTestData(10)) .appendReadData(TestUtil.buildTestData(10)) .endData() .setRandomData("audio_segment_2", 5) .setRandomData("audio_segment_3", 6); DashDownloader dashDownloader = getDashDownloader(fakeDataSet); dashDownloader.selectRepresentations(new RepresentationKey[] {new RepresentationKey(0, 0, 0)}); dashDownloader.download(null); assertCachedData(cache, fakeDataSet); }
public void testDownloadRepresentationFailure() throws Exception { FakeDataSet fakeDataSet = new FakeDataSet() .setData(TEST_MPD_URI, TEST_MPD) .setRandomData("audio_init_data", 10) .setRandomData("audio_segment_1", 4) .newData("audio_segment_2") .appendReadData(TestUtil.buildTestData(2)) .appendReadError(new IOException()) .appendReadData(TestUtil.buildTestData(3)) .endData() .setRandomData("audio_segment_3", 6); DashDownloader dashDownloader = getDashDownloader(fakeDataSet); dashDownloader.selectRepresentations(new RepresentationKey[] {new RepresentationKey(0, 0, 0)}); // downloadRepresentations fails on the first try try { dashDownloader.download(null); fail(); } catch (IOException e) { // ignore } dashDownloader.download(null); assertCachedData(cache, fakeDataSet); }
public void testIncompleteSample() throws Exception { Random random = new Random(0); byte[] fileData = TestUtil.getByteArray(getInstrumentation(), "ts/sample.ts"); ByteArrayOutputStream out = new ByteArrayOutputStream(fileData.length * 2); writeJunkData(out, random.nextInt(TS_PACKET_SIZE - 1) + 1); out.write(fileData, 0, TS_PACKET_SIZE * 5); for (int i = TS_PACKET_SIZE * 5; i < fileData.length; i += TS_PACKET_SIZE) { writeJunkData(out, random.nextInt(TS_PACKET_SIZE)); out.write(fileData, i, TS_PACKET_SIZE); } out.write(TS_SYNC_BYTE); writeJunkData(out, random.nextInt(TS_PACKET_SIZE - 1) + 1); fileData = out.toByteArray(); ExtractorAsserts.assertOutput(new ExtractorFactory() { @Override public Extractor create() { return new TsExtractor(); } }, "ts/sample.ts", fileData, getInstrumentation()); }
public void testCustomPesReader() throws Exception { CustomTsPayloadReaderFactory factory = new CustomTsPayloadReaderFactory(true, false); TsExtractor tsExtractor = new TsExtractor(TsExtractor.MODE_MULTI_PMT, new TimestampAdjuster(0), factory); FakeExtractorInput input = new FakeExtractorInput.Builder() .setData(TestUtil.getByteArray(getInstrumentation(), "ts/sample.ts")) .setSimulateIOErrors(false) .setSimulateUnknownLength(false) .setSimulatePartialReads(false).build(); FakeExtractorOutput output = new FakeExtractorOutput(); tsExtractor.init(output); PositionHolder seekPositionHolder = new PositionHolder(); int readResult = Extractor.RESULT_CONTINUE; while (readResult != Extractor.RESULT_END_OF_INPUT) { readResult = tsExtractor.read(input, seekPositionHolder); } CustomEsReader reader = factory.esReader; assertEquals(2, reader.packetsRead); TrackOutput trackOutput = reader.getTrackOutput(); assertTrue(trackOutput == output.trackOutputs.get(257 /* PID of audio track. */)); assertEquals( Format.createTextSampleFormat("1/257", "mime", null, 0, 0, "und", null, 0), ((FakeTrackOutput) trackOutput).format); }
public void testCustomInitialSectionReader() throws Exception { CustomTsPayloadReaderFactory factory = new CustomTsPayloadReaderFactory(false, true); TsExtractor tsExtractor = new TsExtractor(TsExtractor.MODE_MULTI_PMT, new TimestampAdjuster(0), factory); FakeExtractorInput input = new FakeExtractorInput.Builder() .setData(TestUtil.getByteArray(getInstrumentation(), "ts/sample_with_sdt.ts")) .setSimulateIOErrors(false) .setSimulateUnknownLength(false) .setSimulatePartialReads(false).build(); tsExtractor.init(new FakeExtractorOutput()); PositionHolder seekPositionHolder = new PositionHolder(); int readResult = Extractor.RESULT_CONTINUE; while (readResult != Extractor.RESULT_END_OF_INPUT) { readResult = tsExtractor.read(input, seekPositionHolder); } assertEquals(1, factory.sdtReader.consumedSdts); }
public void testReadContinuedPacketOverTwoPages() throws Exception { byte[] firstPacket = TestUtil.buildTestData(518); FakeExtractorInput input = OggTestData.createInput( TestUtil.joinByteArrays( // First page. OggTestData.buildOggHeader(0x02, 0, 1000, 0x02), TestUtil.createByteArray(0xFF, 0xFF), // Laces. Arrays.copyOf(firstPacket, 510), // Second page (continued packet). OggTestData.buildOggHeader(0x05, 10, 1001, 0x01), TestUtil.createByteArray(0x08), // Laces. Arrays.copyOfRange(firstPacket, 510, 510 + 8)), true); assertReadPacket(input, firstPacket); assertTrue((oggPacket.getPageHeader().type & 0x04) == 0x04); assertFalse((oggPacket.getPageHeader().type & 0x02) == 0x02); assertEquals(1001, oggPacket.getPageHeader().pageSequenceNumber); assertReadEof(input); }
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 = OggTestData.createInput( TestUtil.joinByteArrays( OggTestData.buildOggHeader(0x02, 0, 1000, 0x01), TestUtil.createByteArray(0x08), // Laces. firstPacket, OggTestData.buildOggHeader(0x04, 0, 1001, 0x03), TestUtil.createByteArray(0x08, 0x00, 0x00), // Laces. secondPacket, OggTestData.buildOggHeader(0x04, 0, 1002, 0x03), TestUtil.createByteArray(0x08, 0x00, 0x00), // Laces. thirdPacket), true); assertReadPacket(input, firstPacket); assertReadPacket(input, secondPacket); assertReadPacket(input, thirdPacket); assertReadEof(input); }
public void testDecodeWithMultipleStyl() throws IOException, SubtitleDecoderException { Tx3gDecoder decoder = new Tx3gDecoder(Collections.<byte[]>emptyList()); byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_MULTIPLE_STYL); Subtitle subtitle = decoder.decode(bytes, bytes.length, false); SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text); assertEquals("Line 2\nLine 3", text.toString()); assertEquals(4, text.getSpans(0, text.length(), Object.class).length); StyleSpan styleSpan = findSpan(text, 0, 5, StyleSpan.class); assertEquals(Typeface.ITALIC, styleSpan.getStyle()); findSpan(text, 7, 12, UnderlineSpan.class); ForegroundColorSpan colorSpan = findSpan(text, 0, 5, ForegroundColorSpan.class); assertEquals(Color.GREEN, colorSpan.getForegroundColor()); colorSpan = findSpan(text, 7, 12, ForegroundColorSpan.class); assertEquals(Color.GREEN, colorSpan.getForegroundColor()); assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.85f); }
public void testInitializationDecodeWithStyl() throws IOException, SubtitleDecoderException { byte[] initBytes = TestUtil.getByteArray(getInstrumentation(), INITIALIZATION); Tx3gDecoder decoder = new Tx3gDecoder(Collections.singletonList(initBytes)); byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_STYL); Subtitle subtitle = decoder.decode(bytes, bytes.length, false); SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text); assertEquals("CC Test", text.toString()); assertEquals(5, text.getSpans(0, text.length(), Object.class).length); StyleSpan styleSpan = findSpan(text, 0, text.length(), StyleSpan.class); assertEquals(Typeface.BOLD_ITALIC, styleSpan.getStyle()); findSpan(text, 0, text.length(), UnderlineSpan.class); TypefaceSpan typefaceSpan = findSpan(text, 0, text.length(), TypefaceSpan.class); assertEquals(C.SERIF_NAME, typefaceSpan.getFamily()); ForegroundColorSpan colorSpan = findSpan(text, 0, text.length(), ForegroundColorSpan.class); assertEquals(Color.RED, colorSpan.getForegroundColor()); colorSpan = findSpan(text, 0, 6, ForegroundColorSpan.class); assertEquals(Color.GREEN, colorSpan.getForegroundColor()); assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.1f); }
public void testInitializationDecodeWithTbox() throws IOException, SubtitleDecoderException { byte[] initBytes = TestUtil.getByteArray(getInstrumentation(), INITIALIZATION); Tx3gDecoder decoder = new Tx3gDecoder(Collections.singletonList(initBytes)); byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_TBOX); Subtitle subtitle = decoder.decode(bytes, bytes.length, false); SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text); assertEquals("CC Test", text.toString()); assertEquals(4, text.getSpans(0, text.length(), Object.class).length); StyleSpan styleSpan = findSpan(text, 0, text.length(), StyleSpan.class); assertEquals(Typeface.BOLD_ITALIC, styleSpan.getStyle()); findSpan(text, 0, text.length(), UnderlineSpan.class); TypefaceSpan typefaceSpan = findSpan(text, 0, text.length(), TypefaceSpan.class); assertEquals(C.SERIF_NAME, typefaceSpan.getFamily()); ForegroundColorSpan colorSpan = findSpan(text, 0, text.length(), ForegroundColorSpan.class); assertEquals(Color.RED, colorSpan.getForegroundColor()); assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.1875f); }
public void testInitializationAllDefaultsDecodeWithStyl() throws IOException, SubtitleDecoderException { byte[] initBytes = TestUtil.getByteArray(getInstrumentation(), INITIALIZATION_ALL_DEFAULTS); Tx3gDecoder decoder = new Tx3gDecoder(Collections.singletonList(initBytes)); byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_STYL); Subtitle subtitle = decoder.decode(bytes, bytes.length, false); SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text); assertEquals("CC Test", text.toString()); assertEquals(3, text.getSpans(0, text.length(), Object.class).length); StyleSpan styleSpan = findSpan(text, 0, 6, StyleSpan.class); assertEquals(Typeface.BOLD_ITALIC, styleSpan.getStyle()); findSpan(text, 0, 6, UnderlineSpan.class); ForegroundColorSpan colorSpan = findSpan(text, 0, 6, ForegroundColorSpan.class); assertEquals(Color.GREEN, colorSpan.getForegroundColor()); assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.85f); }
public void testDecodeNoEndTimecodes() throws IOException { SsaDecoder decoder = new SsaDecoder(); byte[] bytes = TestUtil.getByteArray(getInstrumentation(), NO_END_TIMECODES); SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false); assertEquals(3, subtitle.getEventTimeCount()); assertEquals(0, subtitle.getEventTime(0)); assertEquals("This is the first subtitle.", subtitle.getCues(subtitle.getEventTime(0)).get(0).text.toString()); assertEquals(2340000, subtitle.getEventTime(1)); assertEquals("This is the second subtitle \nwith a newline \nand another.", subtitle.getCues(subtitle.getEventTime(1)).get(0).text.toString()); assertEquals(4560000, subtitle.getEventTime(2)); assertEquals("This is the third subtitle, with a comma.", subtitle.getCues(subtitle.getEventTime(2)).get(0).text.toString()); }
public void testDecodeNoEndTimecodes() throws IOException { SubripDecoder decoder = new SubripDecoder(); byte[] bytes = TestUtil.getByteArray(getInstrumentation(), NO_END_TIMECODES_FILE); SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false); assertEquals(3, subtitle.getEventTimeCount()); assertEquals(0, subtitle.getEventTime(0)); assertEquals("SubRip doesn't technically allow missing end timecodes.", subtitle.getCues(subtitle.getEventTime(0)).get(0).text.toString()); assertEquals(2345000, subtitle.getEventTime(1)); assertEquals("We interpret it to mean that a subtitle extends to the start of the next one.", subtitle.getCues(subtitle.getEventTime(1)).get(0).text.toString()); assertEquals(3456000, subtitle.getEventTime(2)); assertEquals("Or to the end of the media.", subtitle.getCues(subtitle.getEventTime(2)).get(0).text.toString()); }
@Test public void testReadBit() { VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0x5c, 0x50)); assertThat(bitArray.readBit()).isFalse(); assertThat(bitArray.readBit()).isFalse(); assertThat(bitArray.readBit()).isTrue(); assertThat(bitArray.readBit()).isTrue(); assertThat(bitArray.readBit()).isTrue(); assertThat(bitArray.readBit()).isFalse(); assertThat(bitArray.readBit()).isTrue(); assertThat(bitArray.readBit()).isFalse(); assertThat(bitArray.readBit()).isFalse(); assertThat(bitArray.readBit()).isFalse(); assertThat(bitArray.readBit()).isFalse(); assertThat(bitArray.readBit()).isFalse(); assertThat(bitArray.readBit()).isTrue(); assertThat(bitArray.readBit()).isFalse(); assertThat(bitArray.readBit()).isTrue(); assertThat(bitArray.readBit()).isFalse(); }
@Test public void testReadBitsBeyondByteBoundaries() throws Exception { VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0xFF, 0x0F, 0xFF, 0x0F)); assertThat(bitArray.readBits(32)).isEqualTo(0x0FFF0FFF); bitArray.reset(); bitArray.skipBits(4); assertThat(bitArray.readBits(16)).isEqualTo(0xF0FF); bitArray.reset(); bitArray.skipBits(6); assertThat(bitArray.readBits(12)).isEqualTo(0xc3F); bitArray.reset(); bitArray.skipBits(6); assertThat(bitArray.readBit()).isTrue(); assertThat(bitArray.readBit()).isTrue(); assertThat(bitArray.bitsLeft()).isEqualTo(24); bitArray.reset(); bitArray.skipBits(10); assertThat(bitArray.readBits(5)).isEqualTo(3); assertThat(bitArray.getPosition()).isEqualTo(15); }
@Test public void testSkipToPageOfGranule() throws IOException, InterruptedException { byte[] packet = TestUtil.buildTestData(3 * 254, random); byte[] data = TestUtil.joinByteArrays( OggTestData.buildOggHeader(0x01, 20000, 1000, 0x03), TestUtil.createByteArray(254, 254, 254), // Laces. packet, OggTestData.buildOggHeader(0x04, 40000, 1001, 0x03), TestUtil.createByteArray(254, 254, 254), // Laces. packet, OggTestData.buildOggHeader(0x04, 60000, 1002, 0x03), TestUtil.createByteArray(254, 254, 254), // Laces. 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 assertThat(input.getPosition()).isEqualTo(2 * (30 + (3 * 254))); }
@Test public void testSkipToPageOfGranulePreciseMatch() throws IOException, InterruptedException { byte[] packet = TestUtil.buildTestData(3 * 254, random); byte[] data = TestUtil.joinByteArrays( OggTestData.buildOggHeader(0x01, 20000, 1000, 0x03), TestUtil.createByteArray(254, 254, 254), // Laces. packet, OggTestData.buildOggHeader(0x04, 40000, 1001, 0x03), TestUtil.createByteArray(254, 254, 254), // Laces. packet, OggTestData.buildOggHeader(0x04, 60000, 1002, 0x03), TestUtil.createByteArray(254, 254, 254), // Laces. packet); FakeExtractorInput input = new FakeExtractorInput.Builder().setData(data).build(); skipToPageOfGranule(input, 40000, 20000); // expect to be at the start of the second page assertThat(input.getPosition()).isEqualTo(30 + (3 * 254)); }
@Test public void testSkipToPageOfGranuleAfterTargetPage() throws IOException, InterruptedException { byte[] packet = TestUtil.buildTestData(3 * 254, random); byte[] data = TestUtil.joinByteArrays( OggTestData.buildOggHeader(0x01, 20000, 1000, 0x03), TestUtil.createByteArray(254, 254, 254), // Laces. packet, OggTestData.buildOggHeader(0x04, 40000, 1001, 0x03), TestUtil.createByteArray(254, 254, 254), // Laces. packet, OggTestData.buildOggHeader(0x04, 60000, 1002, 0x03), TestUtil.createByteArray(254, 254, 254), // Laces. packet); FakeExtractorInput input = new FakeExtractorInput.Builder().setData(data).build(); skipToPageOfGranule(input, 10000, -1); assertThat(input.getPosition()).isEqualTo(0); }
@Test public void testReadGranuleOfLastPage() throws IOException, InterruptedException { FakeExtractorInput input = OggTestData.createInput(TestUtil.joinByteArrays( TestUtil.buildTestData(100, random), OggTestData.buildOggHeader(0x00, 20000, 66, 3), TestUtil.createByteArray(254, 254, 254), // laces TestUtil.buildTestData(3 * 254, random), OggTestData.buildOggHeader(0x00, 40000, 67, 3), TestUtil.createByteArray(254, 254, 254), // laces TestUtil.buildTestData(3 * 254, random), OggTestData.buildOggHeader(0x05, 60000, 68, 3), TestUtil.createByteArray(254, 254, 254), // laces TestUtil.buildTestData(3 * 254, random) ), false); assertReadGranuleOfLastPage(input, 60000); }
@Test public void testPopulatePageHeader() throws IOException, InterruptedException { FakeExtractorInput input = OggTestData.createInput(TestUtil.joinByteArrays( OggTestData.buildOggHeader(0x01, 123456, 4, 2), TestUtil.createByteArray(2, 2) ), true); OggPageHeader header = new OggPageHeader(); populatePageHeader(input, header, false); assertThat(header.type).isEqualTo(0x01); assertThat(header.headerSize).isEqualTo(27 + 2); assertThat(header.bodySize).isEqualTo(4); assertThat(header.pageSegmentCount).isEqualTo(2); assertThat(header.granulePosition).isEqualTo(123456); assertThat(header.pageSequenceNumber).isEqualTo(4); assertThat(header.streamSerialNumber).isEqualTo(0x1000); assertThat(header.pageChecksum).isEqualTo(0x100000); assertThat(header.revision).isEqualTo(0); }
@Test public void testCacheUnknownLengthPartialCaching() throws Exception { FakeDataSet fakeDataSet = new FakeDataSet().newData("test_data") .setSimulateUnknownLength(true) .appendReadData(TestUtil.buildTestData(100)).endData(); FakeDataSource dataSource = new FakeDataSource(fakeDataSet); Uri testUri = Uri.parse("test_data"); DataSpec dataSpec = new DataSpec(testUri, 10, 20, null); CachingCounters counters = new CachingCounters(); CacheUtil.cache(dataSpec, cache, dataSource, counters); assertCounters(counters, 0, 20, 20); CacheUtil.cache(new DataSpec(testUri), cache, dataSource, counters); assertCounters(counters, 20, 80, 100); assertCachedData(cache, fakeDataSet); }
@Test public void testCachePolling() throws Exception { final CachingCounters counters = new CachingCounters(); FakeDataSet fakeDataSet = new FakeDataSet().newData("test_data") .appendReadData(TestUtil.buildTestData(100)) .appendReadAction(new Runnable() { @Override public void run() { assertCounters(counters, 0, 100, 300); } }) .appendReadData(TestUtil.buildTestData(100)) .appendReadAction(new Runnable() { @Override public void run() { assertCounters(counters, 0, 200, 300); } }) .appendReadData(TestUtil.buildTestData(100)).endData(); FakeDataSource dataSource = new FakeDataSource(fakeDataSet); CacheUtil.cache(new DataSpec(Uri.parse("test_data")), cache, dataSource, counters); assertCounters(counters, 0, 300, 300); assertCachedData(cache, fakeDataSet); }
public void testSample() throws Exception { TestUtil.assertOutput(new TestUtil.ExtractorFactory() { @Override public Extractor create() { return new TsExtractor(); } }, "ts/sample.ts", getInstrumentation()); }
public void testSample() throws Exception { TestUtil.assertOutput(new TestUtil.ExtractorFactory() { @Override public Extractor create() { return new Ac3Extractor(); } }, "ts/sample.ac3", getInstrumentation()); }
public void testSample() throws Exception { TestUtil.assertOutput(new TestUtil.ExtractorFactory() { @Override public Extractor create() { return new AdtsExtractor(); } }, "ts/sample.adts", getInstrumentation()); }
public void testSample() throws Exception { TestUtil.assertOutput(new TestUtil.ExtractorFactory() { @Override public Extractor create() { return new PsExtractor(); } }, "ts/sample.ps", getInstrumentation()); }