 Chromium Code Reviews
 Chromium Code Reviews Issue 2084053002:
  EME: Update tests so 'audioCapabilities' always provided  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 2084053002:
  EME: Update tests so 'audioCapabilities' always provided  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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", getSimpleConfigurationForInitDataType (initDataType)) | 
| 21 .then(function() { return(true); }, function() { return(false); }); | 21 .then(function() { return true; }, function() { return false; }); | 
| 22 } | |
| 23 | |
| 24 // Returns a promise that is fulfilled with an initDataType that is supported, | |
| 25 // rejected if none are supported. | |
| 26 function getSupportedInitDataType() | |
| 27 { | |
| 28 var configuration = [{ initDataTypes : [ 'webm', 'cenc', 'keyids' ] }]; | |
| 29 return navigator.requestMediaKeySystemAccess('org.w3.clearkey', configuratio n) | |
| 30 .then(function(access) { | |
| 31 var initDataTypes = access.getConfiguration().initDataTypes; | |
| 32 assert_greater_than(initDataTypes.length, 0); | |
| 33 return Promise.resolve(initDataTypes[0]); | |
| 34 }, function(error) { | |
| 35 return Promise.reject('No supported initDataType.'); | |
| 36 }); | |
| 37 } | 22 } | 
| 38 | 23 | 
| 39 function getInitData(initDataType) | 24 function getInitData(initDataType) | 
| 40 { | 25 { | 
| 41 if (initDataType == 'webm') { | 26 if (initDataType == 'webm') { | 
| 42 return new Uint8Array([ | 27 return new Uint8Array([ | 
| 43 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 28 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 
| 44 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F | 29 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F | 
| 45 ]); | 30 ]); | 
| 46 } | 31 } | 
| (...skipping 17 matching lines...) Expand all Loading... | |
| 64 var keyId = new Uint8Array([ | 49 var keyId = new Uint8Array([ | 
| 65 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 50 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 
| 66 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F | 51 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F | 
| 67 ]); | 52 ]); | 
| 68 return stringToUint8Array(createKeyIDs(keyId)); | 53 return stringToUint8Array(createKeyIDs(keyId)); | 
| 69 } | 54 } | 
| 70 | 55 | 
| 71 throw 'initDataType ' + initDataType + ' not supported.'; | 56 throw 'initDataType ' + initDataType + ' not supported.'; | 
| 72 } | 57 } | 
| 73 | 58 | 
| 59 // Returns an array of audioCapabilities that includes entries for a set of | |
| 60 // codecs that should cover all user agents. | |
| 61 function getPossibleAudioCapabilities() | |
| 62 { | |
| 63 return [ | |
| 64 { contentType: 'audio/mp4; codecs="mp4a.40.2"' }, | |
| 65 { contentType: 'audio/webm; codecs="opus"' }, | |
| 66 ]; | |
| 67 } | |
| 68 | |
| 69 // Returns a trivial MediaKeySystemConfiguration that should be accepted, | |
| 70 // possibly as a subset of the specified capabilities, by all user agents. | |
| 71 function getSimpleConfiguration() | |
| 72 { | |
| 73 return [ { | |
| 74 initDataTypes : [ 'webm', 'cenc', 'keyids' ], | |
| 75 audioCapabilities: getPossibleAudioCapabilities() | |
| 76 } ]; | |
| 77 } | |
| 78 | |
| 79 // Returns a MediaKeySystemConfiguration for |initDataType| that should be | |
| 80 // accepted, possibly as a subset of the specified capabilities, by all | |
| 81 // user agents. | |
| 82 function getSimpleConfigurationForInitDataType(initDataType) | |
| 83 { | |
| 84 return [ { | |
| 85 initDataTypes: [ initDataType ], | |
| 86 audioCapabilities: getPossibleAudioCapabilities() | |
| 87 } ]; | |
| 88 } | |
| 89 | |
| 90 // Returns a MediaKeySystemConfiguration for |mediaFile| that specifies | |
| 91 // both audio and video capabilities for the specified file.. | |
| 92 function getConfigurationForFile(mediaFile) | |
| 93 { | |
| 94 if (mediaFile.toLowerCase().endsWith('webm')) { | |
| 
ddorwin
2016/07/20 19:34:20
It would be slightly better if this was .webm.
 | |
| 95 return [ { | |
| 96 initDataTypes: [ 'webm' ], | |
| 97 audioCapabilities: [ { contentType: 'audio/webm; codecs="opus"' } ], | |
| 98 videoCapabilities: [ { contentType: 'video/webm; codecs="vp8"' } ] | |
| 99 } ]; | |
| 100 } | |
| 101 | |
| 102 // NOTE: Supporting other mediaFormats is not currently implemented as | |
| 103 // Chromium only tests with WebM files. | |
| 104 throw 'mediaFile ' + mediaFile + ' not supported.'; | |
| 105 } | |
| 106 | |
| 74 function waitForEventAndRunStep(eventName, element, func, stepTest) | 107 function waitForEventAndRunStep(eventName, element, func, stepTest) | 
| 75 { | 108 { | 
| 76 var eventCallback = function(event) { | 109 var eventCallback = function(event) { | 
| 77 if (func) | 110 if (func) | 
| 78 func(event); | 111 func(event); | 
| 79 } | 112 } | 
| 80 if (stepTest) | 113 if (stepTest) | 
| 81 eventCallback = stepTest.step_func(eventCallback); | 114 eventCallback = stepTest.step_func(eventCallback); | 
| 82 | 115 | 
| 83 element.addEventListener(eventName, eventCallback, true); | 116 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 | 294 // 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 | 295 // required for the video are already known and provided. Returns a promise | 
| 263 // that resolves to the MediaKeys object created. | 296 // that resolves to the MediaKeys object created. | 
| 264 function createMediaKeys(keyId, key) | 297 function createMediaKeys(keyId, key) | 
| 265 { | 298 { | 
| 266 var mediaKeys; | 299 var mediaKeys; | 
| 267 var mediaKeySession; | 300 var mediaKeySession; | 
| 268 var request = stringToUint8Array(createKeyIDs(keyId)); | 301 var request = stringToUint8Array(createKeyIDs(keyId)); | 
| 269 var jwkSet = stringToUint8Array(createJWKSet(createJWK(keyId, key))); | 302 var jwkSet = stringToUint8Array(createJWKSet(createJWK(keyId, key))); | 
| 270 | 303 | 
| 271 return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).then(f unction(access) { | 304 return navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleCon figurationForInitDataType('keyids')).then(function(access) { | 
| 272 return access.createMediaKeys(); | 305 return access.createMediaKeys(); | 
| 273 }).then(function(result) { | 306 }).then(function(result) { | 
| 274 mediaKeys = result; | 307 mediaKeys = result; | 
| 275 mediaKeySession = mediaKeys.createSession(); | 308 mediaKeySession = mediaKeys.createSession(); | 
| 276 return mediaKeySession.generateRequest('keyids', request); | 309 return mediaKeySession.generateRequest('keyids', request); | 
| 277 }).then(function() { | 310 }).then(function() { | 
| 278 return mediaKeySession.update(jwkSet); | 311 return mediaKeySession.update(jwkSet); | 
| 279 }).then(function() { | 312 }).then(function() { | 
| 280 return Promise.resolve(mediaKeys); | 313 return Promise.resolve(mediaKeys); | 
| 281 }); | 314 }); | 
| 282 } | 315 } | 
| 283 | 316 | 
| 284 // Play the specified |content| on |video|. Returns a promise that is resolved | 317 // Play the specified |content| on |video|. Returns a promise that is resolved | 
| 285 // after the video plays for |duration| seconds. | 318 // after the video plays for |duration| seconds. | 
| 286 function playVideoAndWaitForTimeupdate(video, content, duration) | 319 function playVideoAndWaitForTimeupdate(video, content, duration) | 
| 287 { | 320 { | 
| 288 video.src = content; | 321 video.src = content; | 
| 289 video.play(); | 322 video.play(); | 
| 290 return new Promise(function(resolve) { | 323 return new Promise(function(resolve) { | 
| 291 video.addEventListener('timeupdate', function listener(event) { | 324 video.addEventListener('timeupdate', function listener(event) { | 
| 292 if (event.target.currentTime < duration) | 325 if (event.target.currentTime < duration) | 
| 293 return; | 326 return; | 
| 294 video.removeEventListener('timeupdate', listener); | 327 video.removeEventListener('timeupdate', listener); | 
| 295 resolve('success'); | 328 resolve('success'); | 
| 296 }); | 329 }); | 
| 297 }); | 330 }); | 
| 298 } | 331 } | 
| OLD | NEW |