4 <title>Test Encrypted Media Extensions
</title>
5 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
7 <script type=
"text/javascript" src=
"manifest.js"></script>
8 <script type=
"text/javascript" src=
"eme.js"></script>
11 <audio controls
id=
"audio"></audio>
13 <script class=
"testbody" type=
"text/javascript">
15 // Tests that a fragmented MP4 file without a PSSH, but with valid encrypted
16 // tracks with valid TENC boxes, is able to load with EME.
17 // We setup MSE before starting up EME, so that we exercise the
"waiting for
18 // cdm" step in the MediaDecoderStateMachine.
20 SimpleTest.waitForExplicitFinish();
23 0x00,
0x00,
0x00,
0x00,
24 0x70,
0x73,
0x73,
0x68, // BMFF box header (
76 bytes, 'pssh')
25 0x01,
0x00,
0x00,
0x00, // Full box header (version =
1, flags =
0)
26 0x10,
0x77,
0xef,
0xec,
0xc0,
0xb2,
0x4d,
0x02, // SystemID
27 0xac,
0xe3,
0x3c,
0x1e,
0x52,
0xe2,
0xfb,
0x4b,
28 0x00,
0x00,
0x00,
0x01, // KID_count (
1)
29 0x2f,
0xef,
0x8a,
0xd8,
0x12,
0xdf,
0x42,
0x97,
30 0x83,
0xe9,
0xbf,
0x6e,
0x5e,
0x49,
0x3e,
0x53,
31 0x00,
0x00,
0x00,
0x00 // Size of Data (
0)
34 var audio = document.getElementById(
"audio");
39 audioType: 'audio/mp4;
codecs=
"mp4a.40.2"',
41 navigator.requestMediaKeySystemAccess(
"org.w3.clearkey", options)
42 .then((keySystemAccess) =
> {
43 return keySystemAccess.createMediaKeys();
44 }, bail(
"Failed to request key system access."))
46 .then((mediaKeys) =
> {
47 audio.setMediaKeys(mediaKeys);
48 var session = mediaKeys.createSession();
49 once(session,
"message", (message) =
> {
50 is(message.messageType, 'license-request',
"Expected a license-request");
51 var license = new TextEncoder().encode(JSON.stringify({
54 'kid':'L--K2BLfQpeD6b9uXkk-Uw',
55 'k':HexToBase64('
7f412f0575f44f718259beef56ec7771')
59 session.update(license);
61 session.generateRequest('cenc', new Uint8Array(pssh));
65 function DownloadMedia(url, type, mediaSource) {
66 return new Promise(function(resolve, reject) {
67 var sourceBuffer = mediaSource.addSourceBuffer(type);
68 fetchWithXHR(url, (response) =
> {
69 once(sourceBuffer,
"updateend", resolve);
70 sourceBuffer.appendBuffer(new Uint8Array(response));
76 var ms = new MediaSource();
77 audio.src = URL.createObjectURL(ms);
79 once(ms,
"sourceopen", ()=
>{
80 DownloadMedia('short-audio-fragmented-cenc-without-pssh.mp4', 'audio/mp4;
codecs=
"mp4a.40.2"', ms)
81 .then(() =
> { ms.endOfStream(); LoadEME();});
84 audio.addEventListener(
"loadeddata", SimpleTest.finish);