OLD | NEW |
---|---|
1 var consoleDiv = null; | 1 var consoleDiv = null; |
2 | 2 |
3 function consoleWrite(text) | 3 function consoleWrite(text) |
4 { | 4 { |
5 if (!consoleDiv && document.body) { | 5 if (!consoleDiv && document.body) { |
6 consoleDiv = document.createElement('div'); | 6 consoleDiv = document.createElement('div'); |
7 document.body.appendChild(consoleDiv); | 7 document.body.appendChild(consoleDiv); |
8 } | 8 } |
9 var span = document.createElement('span'); | 9 var span = document.createElement('span'); |
10 span.appendChild(document.createTextNode(text)); | 10 span.appendChild(document.createTextNode(text)); |
11 span.appendChild(document.createElement('br')); | 11 span.appendChild(document.createElement('br')); |
12 consoleDiv.appendChild(span); | 12 consoleDiv.appendChild(span); |
13 } | 13 } |
14 | 14 |
15 // Returns a promise that is fulfilled with true if |initDataType| is supported, | 15 // Returns a promise that is fulfilled with true if |initDataType| is supported, |
16 // or false if not. | 16 // or false if not. |
17 function isInitDataTypeSupported(initDataType) | 17 function isInitDataTypeSupported(initDataType) |
18 { | 18 { |
19 return navigator.requestMediaKeySystemAccess( | 19 return navigator.requestMediaKeySystemAccess( |
20 "org.w3.clearkey", [{ initDataTypes : [initDataType] }] ) | 20 "org.w3.clearkey", simpleConfigurationForInitDataType(i nitDataType)) |
21 .then(function() { return(true); }, function() { return(false); }); | 21 .then(function() { return(true); }, function() { return(false); }); |
22 } | 22 } |
23 | 23 |
24 // Returns a promise that is fulfilled with an initDataType that is supported, | 24 // Returns a promise that is fulfilled with an initDataType that is supported, |
25 // rejected if none are supported. | 25 // rejected if none are supported. |
26 function getSupportedInitDataType() | 26 function getSupportedInitDataType() |
ddorwin
2016/06/24 03:05:23
We may not actually need this anymore if we follow
jrummell
2016/06/28 23:04:26
Done.
| |
27 { | 27 { |
28 var configuration = [{ initDataTypes : [ 'webm', 'cenc', 'keyids' ] }]; | 28 var configuration = [ { |
29 initDataTypes : [ 'webm', 'cenc', 'keyids' ], | |
30 audioCapabilities: [ { contentType: 'audio/webm; codecs="vorbis"' } ] | |
ddorwin
2016/06/24 03:05:23
We should add a note that one would need to includ
jrummell
2016/06/28 23:04:26
Done.
| |
31 } ]; | |
29 return navigator.requestMediaKeySystemAccess('org.w3.clearkey', configuratio n) | 32 return navigator.requestMediaKeySystemAccess('org.w3.clearkey', configuratio n) |
30 .then(function(access) { | 33 .then(function(access) { |
31 var initDataTypes = access.getConfiguration().initDataTypes; | 34 var initDataTypes = access.getConfiguration().initDataTypes; |
32 assert_greater_than(initDataTypes.length, 0); | 35 assert_greater_than(initDataTypes.length, 0); |
33 return Promise.resolve(initDataTypes[0]); | 36 return Promise.resolve(initDataTypes[0]); |
34 }, function(error) { | 37 }, function(error) { |
35 return Promise.reject('No supported initDataType.'); | 38 return Promise.reject('No supported initDataType.'); |
36 }); | 39 }); |
37 } | 40 } |
38 | 41 |
(...skipping 25 matching lines...) Expand all Loading... | |
64 var keyId = new Uint8Array([ | 67 var keyId = new Uint8Array([ |
65 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 68 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
66 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F | 69 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F |
67 ]); | 70 ]); |
68 return stringToUint8Array(createKeyIDs(keyId)); | 71 return stringToUint8Array(createKeyIDs(keyId)); |
69 } | 72 } |
70 | 73 |
71 throw 'initDataType ' + initDataType + ' not supported.'; | 74 throw 'initDataType ' + initDataType + ' not supported.'; |
72 } | 75 } |
73 | 76 |
77 // Returns a trivial MediaKeySystemConfiguration. Since Chromium only | |
78 // supports WebM by default, use an audio codec so that at least one | |
79 // capability is specified. | |
80 // NOTE: Supporting user agents that don't support WebM and/or Vorbis would | |
81 // require passing in an audio content type. | |
82 function simpleConfiguration() | |
83 { | |
84 return [ { | |
85 audioCapabilities: [ { contentType: 'audio/webm; codecs="vorbis"' } ] | |
ddorwin
2016/06/24 03:05:23
Actually, that might work here too. We just need o
jrummell
2016/06/28 23:04:26
Done.
| |
86 } ]; | |
87 } | |
88 | |
89 // Returns a MediaKeySystemConfiguration for |initDataType|. Since Chromium | |
90 // only supports WebM by default, use an audio codec so that at least one | |
91 // capability is specified. | |
92 // NOTE: Supporting user agents that don't support WebM and/or Vorbis would | |
93 // require passing in an audio content type. | |
94 function simpleConfigurationForInitDataType(initDataType) | |
95 { | |
96 return [ { | |
97 initDataTypes: [ initDataType ], | |
98 audioCapabilities: [ { contentType: 'audio/webm; codecs="vorbis"' } ] | |
99 } ]; | |
100 } | |
101 | |
102 // Returns a MediaKeySystemConfiguration for |initDataType| that specifies | |
103 // both audio and video capabilities. | |
104 function avConfiguration(initDataType) | |
ddorwin
2016/06/24 03:05:23
Passing the IDT isn't strictly correct. Also, FTR,
jrummell
2016/06/28 23:04:26
Renamed the parameter since it is really the media
| |
105 { | |
106 if (initDataType == 'webm') { | |
107 return [ { | |
ddorwin
2016/06/24 21:24:56
(Especially for cases where more than one configur
jrummell
2016/06/28 23:04:26
Acknowledged. Doesn't look like we need to handle
| |
108 initDataTypes: [ 'webm' ], | |
109 audioCapabilities: [ { contentType: 'audio/webm; codecs="vorbis"' } ], | |
110 videoCapabilities: [ { contentType: 'video/webm; codecs="vp8"' } ] | |
111 } ]; | |
112 } | |
113 | |
114 // NOTE: Supporting other initDataTypes not currently implemented as | |
115 // Chromium only tests with WebM files. | |
116 throw 'initDataType ' + initDataType + ' not supported.'; | |
117 } | |
118 | |
74 function waitForEventAndRunStep(eventName, element, func, stepTest) | 119 function waitForEventAndRunStep(eventName, element, func, stepTest) |
75 { | 120 { |
76 var eventCallback = function(event) { | 121 var eventCallback = function(event) { |
77 if (func) | 122 if (func) |
78 func(event); | 123 func(event); |
79 } | 124 } |
80 if (stepTest) | 125 if (stepTest) |
81 eventCallback = stepTest.step_func(eventCallback); | 126 eventCallback = stepTest.step_func(eventCallback); |
82 | 127 |
83 element.addEventListener(eventName, eventCallback, true); | 128 element.addEventListener(eventName, eventCallback, true); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 // Create a MediaKeys object for Clear Key with 1 session. KeyId and key | 306 // Create a MediaKeys object for Clear Key with 1 session. KeyId and key |
262 // required for the video are already known and provided. Returns a promise | 307 // required for the video are already known and provided. Returns a promise |
263 // that resolves to the MediaKeys object created. | 308 // that resolves to the MediaKeys object created. |
264 function createMediaKeys(keyId, key) | 309 function createMediaKeys(keyId, key) |
265 { | 310 { |
266 var mediaKeys; | 311 var mediaKeys; |
267 var mediaKeySession; | 312 var mediaKeySession; |
268 var request = stringToUint8Array(createKeyIDs(keyId)); | 313 var request = stringToUint8Array(createKeyIDs(keyId)); |
269 var jwkSet = stringToUint8Array(createJWKSet(createJWK(keyId, key))); | 314 var jwkSet = stringToUint8Array(createJWKSet(createJWK(keyId, key))); |
270 | 315 |
271 return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).then(f unction(access) { | 316 return navigator.requestMediaKeySystemAccess('org.w3.clearkey', simpleConfig urationForInitDataType('keyids')).then(function(access) { |
272 return access.createMediaKeys(); | 317 return access.createMediaKeys(); |
273 }).then(function(result) { | 318 }).then(function(result) { |
274 mediaKeys = result; | 319 mediaKeys = result; |
275 mediaKeySession = mediaKeys.createSession(); | 320 mediaKeySession = mediaKeys.createSession(); |
276 return mediaKeySession.generateRequest('keyids', request); | 321 return mediaKeySession.generateRequest('keyids', request); |
277 }).then(function() { | 322 }).then(function() { |
278 return mediaKeySession.update(jwkSet); | 323 return mediaKeySession.update(jwkSet); |
279 }).then(function() { | 324 }).then(function() { |
280 return Promise.resolve(mediaKeys); | 325 return Promise.resolve(mediaKeys); |
281 }); | 326 }); |
282 } | 327 } |
283 | 328 |
284 // Play the specified |content| on |video|. Returns a promise that is resolved | 329 // Play the specified |content| on |video|. Returns a promise that is resolved |
285 // after the video plays for |duration| seconds. | 330 // after the video plays for |duration| seconds. |
286 function playVideoAndWaitForTimeupdate(video, content, duration) | 331 function playVideoAndWaitForTimeupdate(video, content, duration) |
287 { | 332 { |
288 video.src = content; | 333 video.src = content; |
289 video.play(); | 334 video.play(); |
290 return new Promise(function(resolve) { | 335 return new Promise(function(resolve) { |
291 video.addEventListener('timeupdate', function listener(event) { | 336 video.addEventListener('timeupdate', function listener(event) { |
292 if (event.target.currentTime < duration) | 337 if (event.target.currentTime < duration) |
293 return; | 338 return; |
294 video.removeEventListener('timeupdate', listener); | 339 video.removeEventListener('timeupdate', listener); |
295 resolve('success'); | 340 resolve('success'); |
296 }); | 341 }); |
297 }); | 342 }); |
298 } | 343 } |
OLD | NEW |