Fix HLS encryption method detection

Issue:#4145

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=193494319
This commit is contained in:
aquilescanta 2018-04-19 04:09:10 -07:00 committed by Oliver Woodman
parent cdb13dd548
commit d2c6871ce6
3 changed files with 79 additions and 3 deletions

View File

@ -66,8 +66,11 @@
([#4022][https://github.com/google/ExoPlayer/issues/4022]). ([#4022][https://github.com/google/ExoPlayer/issues/4022]).
* Fix handling of 307/308 redirects when making license requests * Fix handling of 307/308 redirects when making license requests
([#4108](https://github.com/google/ExoPlayer/issues/4108)). ([#4108](https://github.com/google/ExoPlayer/issues/4108)).
* HLS: Fix playlist loading error propagation when the current selection does * HLS:
not include all of the playlist's variants. * Fix playlist loading error propagation when the current selection does
not include all of the playlist's variants.
* Fix SAMPLE-AES-CENC and SAMPLE-AES-CTR EXT-X-KEY methods
([#4145](https://github.com/google/ExoPlayer/issues/4145)).
* Fix ClearKey decryption error if the key contains a forward slash * Fix ClearKey decryption error if the key contains a forward slash
([#4075](https://github.com/google/ExoPlayer/issues/4075)). ([#4075](https://github.com/google/ExoPlayer/issues/4075)).
* Fix crash when switching surface on Huawei P9 Lite * Fix crash when switching surface on Huawei P9 Lite

View File

@ -123,7 +123,8 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
+ METHOD_SAMPLE_AES_CENC + METHOD_SAMPLE_AES_CENC
+ "|" + "|"
+ METHOD_SAMPLE_AES_CTR + METHOD_SAMPLE_AES_CTR
+ ")"); + ")"
+ "\\s*(,|$)");
private static final Pattern REGEX_KEYFORMAT = Pattern.compile("KEYFORMAT=\"(.+?)\""); private static final Pattern REGEX_KEYFORMAT = Pattern.compile("KEYFORMAT=\"(.+?)\"");
private static final Pattern REGEX_URI = Pattern.compile("URI=\"(.+?)\""); private static final Pattern REGEX_URI = Pattern.compile("URI=\"(.+?)\"");
private static final Pattern REGEX_IV = Pattern.compile("IV=([^,.*]+)"); private static final Pattern REGEX_IV = Pattern.compile("IV=([^,.*]+)");

View File

@ -140,6 +140,78 @@ public class HlsMediaPlaylistParserTest {
assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2683.ts"); assertThat(segment.url).isEqualTo("https://priv.example.com/fileSequence2683.ts");
} }
@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(playlistString.getBytes(Charset.forName(C.UTF8_NAME)));
HlsMediaPlaylist playlist =
(HlsMediaPlaylist) new HlsPlaylistParser().parse(playlistUri, inputStream);
assertThat(playlist.drmInitData.schemeType).isEqualTo(C.CENC_TYPE_cbcs);
assertThat(playlist.drmInitData.get(0).matches(C.WIDEVINE_UUID)).isTrue();
}
@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(playlistString.getBytes(Charset.forName(C.UTF8_NAME)));
HlsMediaPlaylist playlist =
(HlsMediaPlaylist) new HlsPlaylistParser().parse(playlistUri, inputStream);
assertThat(playlist.drmInitData.schemeType).isEqualTo(C.CENC_TYPE_cenc);
assertThat(playlist.drmInitData.get(0).matches(C.WIDEVINE_UUID)).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(playlistString.getBytes(Charset.forName(C.UTF8_NAME)));
HlsMediaPlaylist playlist =
(HlsMediaPlaylist) new HlsPlaylistParser().parse(playlistUri, inputStream);
assertThat(playlist.drmInitData.schemeType).isEqualTo(C.CENC_TYPE_cenc);
assertThat(playlist.drmInitData.get(0).matches(C.WIDEVINE_UUID)).isTrue();
}
@Test @Test
public void testGapTag() throws IOException { public void testGapTag() throws IOException {
Uri playlistUri = Uri.parse("https://example.com/test2.m3u8"); Uri playlistUri = Uri.parse("https://example.com/test2.m3u8");