/** * Removes unnecessary {@link SchemeData}s with null {@link SchemeData#data}. */ private static void filterRedundantIncompleteSchemeDatas(ArrayList<SchemeData> schemeDatas) { for (int i = schemeDatas.size() - 1; i >= 0; i--) { SchemeData schemeData = schemeDatas.get(i); if (!schemeData.hasData()) { for (int j = 0; j < schemeDatas.size(); j++) { if (schemeDatas.get(j).canReplace(schemeData)) { // schemeData is incomplete, but there is another matching SchemeData which does contain // data, so we remove the incomplete one. schemeDatas.remove(i); break; } } } } }
@Test public void testParseSampleAesMethod() throws Exception { Uri playlistUri = Uri.parse("https://example.com/test.m3u8"); String playlistString = "#EXTM3U\n" + "#EXT-X-MEDIA-SEQUENCE:0\n" + "#EXTINF:8,\n" + "https://priv.example.com/1.ts\n" + "\n" + "#EXT-X-KEY:METHOD=SAMPLE-AES,URI=" + "\"data:text/plain;base64,VGhpcyBpcyBhbiBlYXN0ZXIgZWdn\"," + "IV=0x9358382AEB449EE23C3D809DA0B9CCD3,KEYFORMATVERSIONS=\"1\"," + "KEYFORMAT=\"com.widevine\",IV=0x1566B\n" + "#EXTINF:8,\n" + "https://priv.example.com/2.ts\n" + "#EXT-X-ENDLIST\n"; InputStream inputStream = new ByteArrayInputStream(Util.getUtf8Bytes(playlistString)); HlsMediaPlaylist playlist = (HlsMediaPlaylist) new HlsPlaylistParser().parse(playlistUri, inputStream); assertThat(playlist.protectionSchemes.schemeType).isEqualTo(C.CENC_TYPE_cbcs); assertThat(playlist.protectionSchemes.get(0).matches(C.WIDEVINE_UUID)).isTrue(); assertThat(playlist.protectionSchemes.get(0).hasData()).isFalse(); assertThat(playlist.segments.get(0).drmInitData).isNull(); assertThat(playlist.segments.get(1).drmInitData.get(0).matches(C.WIDEVINE_UUID)).isTrue(); assertThat(playlist.segments.get(1).drmInitData.get(0).hasData()).isTrue(); }
assertThat(playlist.protectionSchemes.get(0).hasData()).isFalse(); assertThat(playlist.protectionSchemes.get(1).matches(C.WIDEVINE_UUID)).isTrue(); assertThat(playlist.protectionSchemes.get(1).hasData()).isFalse(); assertThat(playlist.segments.get(1).drmInitData.get(0).hasData()).isTrue(); assertThat(playlist.segments.get(1).drmInitData.get(1).matches(C.WIDEVINE_UUID)).isTrue(); assertThat(playlist.segments.get(1).drmInitData.get(1).hasData()).isTrue(); .isNotEqualTo(playlist.segments.get(3).drmInitData); assertThat(playlist.segments.get(3).drmInitData.get(0).matches(C.PLAYREADY_UUID)).isTrue(); assertThat(playlist.segments.get(3).drmInitData.get(0).hasData()).isTrue(); assertThat(playlist.segments.get(3).drmInitData.get(1).matches(C.WIDEVINE_UUID)).isTrue(); assertThat(playlist.segments.get(3).drmInitData.get(1).hasData()).isTrue();
@Test public void testParseSampleAesCtrMethod() throws Exception { Uri playlistUri = Uri.parse("https://example.com/test.m3u8"); String playlistString = "#EXTM3U\n" + "#EXT-X-MEDIA-SEQUENCE:0\n" + "#EXTINF:8,\n" + "https://priv.example.com/1.ts\n" + "\n" + "#EXT-X-KEY:METHOD=SAMPLE-AES-CTR,URI=" + "\"data:text/plain;base64,VGhpcyBpcyBhbiBlYXN0ZXIgZWdn\"," + "IV=0x9358382AEB449EE23C3D809DA0B9CCD3,KEYFORMATVERSIONS=\"1\"," + "KEYFORMAT=\"com.widevine\",IV=0x1566B\n" + "#EXTINF:8,\n" + "https://priv.example.com/2.ts\n" + "#EXT-X-ENDLIST\n"; InputStream inputStream = new ByteArrayInputStream(Util.getUtf8Bytes(playlistString)); HlsMediaPlaylist playlist = (HlsMediaPlaylist) new HlsPlaylistParser().parse(playlistUri, inputStream); assertThat(playlist.protectionSchemes.schemeType).isEqualTo(C.CENC_TYPE_cenc); assertThat(playlist.protectionSchemes.get(0).matches(C.WIDEVINE_UUID)).isTrue(); assertThat(playlist.protectionSchemes.get(0).hasData()).isFalse(); }
@Test public void testParseSampleAesCencMethod() throws Exception { Uri playlistUri = Uri.parse("https://example.com/test.m3u8"); String playlistString = "#EXTM3U\n" + "#EXT-X-MEDIA-SEQUENCE:0\n" + "#EXTINF:8,\n" + "https://priv.example.com/1.ts\n" + "\n" + "#EXT-X-KEY:URI=\"data:text/plain;base64,VGhpcyBpcyBhbiBlYXN0ZXIgZWdn\"," + "IV=0x9358382AEB449EE23C3D809DA0B9CCD3,KEYFORMATVERSIONS=\"1\"," + "KEYFORMAT=\"urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed\"," + "IV=0x1566B,METHOD=SAMPLE-AES-CENC \n" + "#EXTINF:8,\n" + "https://priv.example.com/2.ts\n" + "#EXT-X-ENDLIST\n"; InputStream inputStream = new ByteArrayInputStream(Util.getUtf8Bytes(playlistString)); HlsMediaPlaylist playlist = (HlsMediaPlaylist) new HlsPlaylistParser().parse(playlistUri, inputStream); assertThat(playlist.protectionSchemes.schemeType).isEqualTo(C.CENC_TYPE_cenc); assertThat(playlist.protectionSchemes.get(0).matches(C.WIDEVINE_UUID)).isTrue(); assertThat(playlist.protectionSchemes.get(0).hasData()).isFalse(); }
/** * Returns whether this {@link SchemeData} can be used to replace {@code other}. * * @param other A {@link SchemeData}. * @return Whether this {@link SchemeData} can be used to replace {@code other}. */ public boolean canReplace(SchemeData other) { return hasData() && !other.hasData() && matches(other.uuid); }