OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <html> | |
3 <head> | |
4 <title>Clear Key Playback with Multiple Sessions</title> | |
5 <script src="encrypted-media-utils.js"></script> | |
6 <script src="../w3c-media-utils.js"></script> | |
7 <script src="../../resources/testharness.js"></script> | |
8 <script src="../../resources/testharnessreport.js"></script> | |
9 </head> | |
10 <body> | |
11 <video id="testVideo"></video> | |
12 <div id="log"></div> | |
13 <p>Test playback of encrypted media using Clear Key key system with mult iple sessions.</p> | |
14 <script> | |
15 setup({ timeout: 60000 }); // Timeout for all tests to run. | |
16 | |
17 async_test(function(test) | |
18 { | |
19 var video = document.getElementById("testVideo"); | |
20 var mediaKeys = new MediaKeys("org.w3.clearkey"); | |
21 var audioMediaKeySession = null; | |
22 var videoMediaKeySession = null; | |
23 var audioKeyProvided = false; | |
24 var videoKeyProvided = false; | |
25 | |
26 // The 2 streams use different key ids and different keys. | |
27 var audioKeyId = "1234567890123456"; | |
28 var audioKey = new Uint8Array([0x30, 0x30, 0x62, 0xF1, 0x68, 0x1 4, 0xD2, 0x7B, | |
29 0x68, 0xEF, 0x12, 0x2A, 0xFC, 0xE 4, 0xAE, 0x0A]); | |
30 var videoKeyId = "0123456789012345"; | |
31 var videoKey = new Uint8Array([0x7A, 0x7A, 0x62, 0xF1, 0x68, 0x1 4, 0xD2, 0x7B, | |
32 0x68, 0xEF, 0x12, 0x2A, 0xFC, 0xE 4, 0xAE, 0x0A]); | |
33 | |
34 function onNeedKey(event) | |
35 { | |
36 var keyId = String.fromCharCode.apply(null, event.initData); | |
37 var newSession = mediaKeys.createSession(event.contentType, event.initData); | |
38 if (keyId == videoKeyId) { | |
39 assert_equals(videoMediaKeySession, null); | |
40 videoMediaKeySession = newSession; | |
41 } else { | |
42 assert_equals(keyId, audioKeyId); | |
43 assert_equals(audioMediaKeySession, null); | |
44 audioMediaKeySession = newSession; | |
45 } | |
46 waitForEventAndRunStep("message", newSession, onMessage, tes t); | |
47 } | |
48 | |
49 function onMessage(event) | |
50 { | |
51 var keyId = event.message; | |
52 if (event.target == videoMediaKeySession) { | |
53 assert_equals(String.fromCharCode.apply(null, keyId), vi deoKeyId); | |
54 var jwkSet = stringToUint8Array(createJWKSet(createJWK(k eyId, videoKey))); | |
55 videoMediaKeySession.update(jwkSet); | |
56 videoKeyProvided = true; | |
57 waitForEventAndRunStep("ready", videoMediaKeySession, on Ready, test); | |
ddorwin
2014/03/21 19:04:23
nit: This line could be shared by using event.targ
jrummell
2014/03/21 20:20:39
Removed.
| |
58 } else { | |
59 assert_equals(event.target, audioMediaKeySession); | |
60 assert_equals(String.fromCharCode.apply(null, keyId), au dioKeyId); | |
61 var jwkSet = stringToUint8Array(createJWKSet(createJWK(k eyId, audioKey))); | |
62 audioMediaKeySession.update(jwkSet); | |
63 audioKeyProvided = true; | |
64 waitForEventAndRunStep("ready", audioMediaKeySession, on Ready, test); | |
65 } | |
66 } | |
67 | |
68 function onReady(event) | |
ddorwin
2014/03/21 19:04:23
Remove then?
jrummell
2014/03/21 20:20:39
Done.
| |
69 { | |
70 } | |
71 | |
72 function onPlaying(event) | |
73 { | |
74 // Video should not start playing until both audio and | |
75 // video keys have been provided. | |
76 assert_true(audioKeyProvided); | |
ddorwin
2014/03/21 19:04:23
nit: All other functions process video then audio.
jrummell
2014/03/21 20:20:39
Done.
| |
77 assert_true(videoKeyProvided); | |
78 | |
79 // Not using waitForEventAndRunStep() to avoid too many EVEN T(onTimeUpdate) logs. | |
80 video.addEventListener("timeupdate", onTimeUpdate, true); | |
81 } | |
82 | |
83 function onTimeUpdate(event) | |
84 { | |
85 if (event.target.currentTime < 0.2) | |
86 return; | |
87 | |
88 test.done(); | |
89 } | |
90 | |
91 waitForEventAndRunStep("needkey", video, onNeedKey, test); | |
92 waitForEventAndRunStep("playing", video, onPlaying, test); | |
93 | |
94 video.src = "../content/test-encrypted-different-av-keys.webm"; | |
95 video.setMediaKeys(mediaKeys); | |
96 video.play(); | |
97 }, "Playback using Clear Key key system with multiple sessions.", | |
98 { timeout: 60000 }); | |
99 </script> | |
100 </body> | |
101 </html> | |
OLD | NEW |