Skip to content

Commit

Permalink
EME: Ensure 'audioCapabilities' is always provided (#3317)
Browse files Browse the repository at this point in the history
This also lays the groundwork for user agents that support different types.

Based on Chromium commit 51111720ce9dc84fce16319a239126b2c69ca6da.
  • Loading branch information
ddorwin authored and mwatson2 committed Jul 21, 2016
1 parent 3236886 commit 5d8b6f5
Show file tree
Hide file tree
Showing 35 changed files with 179 additions and 118 deletions.
Expand Up @@ -18,11 +18,9 @@
var initDataType;
var initData;
var mediaKeySession;
getSupportedInitDataType().then(function(type) {
initDataType = type;
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
initDataType = access.getConfiguration().initDataTypes[0];
initData = getInitData(initDataType);
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]);
}).then(function(access) {
return access.createMediaKeys();
}).then(function(mediaKeys) {
mediaKeySession = mediaKeys.createSession();
Expand Down
Expand Up @@ -15,7 +15,7 @@

promise_test(function(test)
{
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).then(function(access) {
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
return access.createMediaKeys();
}).then(function(mediaKeys) {
var cert = new Uint8Array(200);
Expand Down
Expand Up @@ -17,8 +17,7 @@
if (!result)
return Promise.resolve('Not supported');

var options = [ { initDataTypes: [initDataType] } ];
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', options)
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfigurationForInitDataType(initDataType))
.then(function(access) {
return access.createMediaKeys();
}).then(function(mediaKeys) {
Expand Down
Expand Up @@ -27,11 +27,9 @@
});
}

getSupportedInitDataType().then(function(type) {
initDataType = type;
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
initDataType = access.getConfiguration().initDataTypes[0];
initData = getInitData(initDataType);
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]);
}).then(function(access) {
return access.createMediaKeys();
}).then(function(mediaKeys) {
var keySession = mediaKeys.createSession();
Expand Down
Expand Up @@ -16,6 +16,7 @@
async_test(function(test)
{
var initDataType;
var initData;
var mediaKeySession;

function processMessage(event)
Expand All @@ -34,15 +35,14 @@
});
}

getSupportedInitDataType().then(function(type) {
initDataType = type;
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]);
}).then(function(access) {
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
initDataType = access.getConfiguration().initDataTypes[0];
initData = getInitData(initDataType);
return access.createMediaKeys();
}).then(function(mediaKeys) {
mediaKeySession = mediaKeys.createSession();
waitForEventAndRunStep('message', mediaKeySession, processMessage, test);
return mediaKeySession.generateRequest(initDataType, getInitData(initDataType));
return mediaKeySession.generateRequest(initDataType, initData);
});
}, 'Clear Key update() with non-ASCII response.');
</script>
Expand Down
6 changes: 2 additions & 4 deletions encrypted-media/Google/encrypted-media-events.html
Expand Up @@ -45,11 +45,9 @@
test.done();
}

getSupportedInitDataType().then(function(type) {
initDataType = type;
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
initDataType = access.getConfiguration().initDataTypes[0];
initData = getInitData(initDataType);
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]);
}).then(function(access) {
return access.createMediaKeys();
}).then(test.step_func(function(mediaKeys) {
mediaKeySession = mediaKeys.createSession();
Expand Down
Expand Up @@ -21,7 +21,7 @@
if (!result)
return Promise.resolve('Not supported');

return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).then(function(access) {
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfigurationForInitDataType(initDataType)).then(function(access) {
return access.createMediaKeys();
}).then(function(mediaKeys) {
var mediaKeySession = mediaKeys.createSession();
Expand Down
Expand Up @@ -89,11 +89,9 @@
test.done();
}

getSupportedInitDataType().then(function(type) {
initDataType = type;
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
initDataType = access.getConfiguration().initDataTypes[0];
initData = getInitData(initDataType);
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]);
}).then(function(access) {
return access.createMediaKeys();
}).then(function(mediaKeys) {
mediaKeySession1 = mediaKeys.createSession();
Expand Down
Expand Up @@ -61,11 +61,9 @@
}
}

getSupportedInitDataType().then(function(type) {
initDataType = type;
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
initDataType = access.getConfiguration().initDataTypes[0];
initData = getInitData(initDataType);
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]);
}).then(function(access) {
return access.createMediaKeys();
}).then(function(mediaKeys) {
mediaKeySession = mediaKeys.createSession();
Expand Down
31 changes: 25 additions & 6 deletions encrypted-media/Google/encrypted-media-keystatuses.html
Expand Up @@ -15,6 +15,7 @@
var mediaKeySession;
var initDataType;
var initData;
var closed = false;

// Even though key ids are uint8, using printable values so that
// they can be verified easily.
Expand All @@ -40,7 +41,7 @@
});
}

function processKeyStatusesChange(event)
function checkKeyStatusFor2Keys()
{
// Two keys added, so both should show up in |keyStatuses|.
assert_equals(mediaKeySession.keyStatuses.size, 2);
Expand Down Expand Up @@ -125,15 +126,33 @@
invalid6.set(key1, 0); // Last element will be 0.
assert_false(mediaKeySession.keyStatuses.has(invalid6));
assert_equals(mediaKeySession.keyStatuses.get(invalid6), undefined);
}

test.done();
function processKeyStatusesChange(event)
{
if ( !closed )
{
// The first keystatuseschange (caused by update())
// should include both keys.
checkKeyStatusFor2Keys();

mediaKeySession.close().catch(function(error) {
forceTestFailureFromPromise(test, error);
});
closed = true;
}
else
{
// The second keystatuseschange (caused by close())
// should not have any keys.
assert_equals(mediaKeySession.keyStatuses.size, 0);
test.done();
}
}

getSupportedInitDataType().then(function(type) {
initDataType = type;
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
initDataType = access.getConfiguration().initDataTypes[0];
initData = getInitData(initDataType);
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]);
}).then(function(access) {
return access.createMediaKeys();
}).then(function(mediaKeys) {
mediaKeySession = mediaKeys.createSession();
Expand Down
Expand Up @@ -32,12 +32,9 @@
}

// Create a MediaKeys object with a session.
getSupportedInitDataType().then(function(type) {
initDataType = type;
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
initDataType = access.getConfiguration().initDataTypes[0];
initData = getInitData(initDataType);
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]);
}).then(function(access) {
assert_equals(access.keySystem, 'org.w3.clearkey');
return access.createMediaKeys();
}).then(function(result) {
mediaKeys = result;
Expand Down
Expand Up @@ -13,7 +13,7 @@
async_test(function(test)
{
// Create a MediaKeys object and free immediately.
navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).then(function(access) {
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
return access.createMediaKeys();
}).then(function(result) {
// Do nothing with the created object
Expand All @@ -31,7 +31,7 @@
async_test(function(test)
{
var mediaKeys;
navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).then(function(access) {
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
return access.createMediaKeys();
}).then(function(result) {
mediaKeys = result;
Expand Down
Expand Up @@ -32,12 +32,9 @@
return window.internals.activeDOMObjectCount(document) - startingActiveDOMObjectCount;
}

getSupportedInitDataType().then(function(type) {
initDataType = type;
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
initDataType = access.getConfiguration().initDataTypes[0];
initData = getInitData(initDataType);
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]);
}).then(function(access) {
assert_equals(access.keySystem, 'org.w3.clearkey');
return access.createMediaKeys();
}).then(function(result) {
mediaKeys = result;
Expand Down
Expand Up @@ -31,11 +31,10 @@
var mediaKeys;
var mediaKeySession1;
var mediaKeySession2;
getSupportedInitDataType().then(function(type) {
initDataType = type;

navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
initDataType = access.getConfiguration().initDataTypes[0];
initData = getInitData(initDataType);
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]);
}).then(function(access) {
return access.createMediaKeys();
}).then(function(result) {
mediaKeys = result;
Expand Down
Expand Up @@ -31,11 +31,9 @@
}

// Create 2 sessions.
getSupportedInitDataType().then(function(type) {
initDataType = type;
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
initDataType = access.getConfiguration().initDataTypes[0];
initData = getInitData(initDataType);
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]);
}).then(function(access) {
return access.createMediaKeys();
}).then(function(result) {
mediaKeys = result;
Expand Down
Expand Up @@ -25,9 +25,7 @@
// with the new MediaKeys object.
function createMediaKeys()
{
return getSupportedInitDataType().then(function(type) {
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]);
}).then(function(access) {
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
return access.createMediaKeys();
}).then(function(mediaKeys) {
return mediaKeys;
Expand Down
5 changes: 3 additions & 2 deletions encrypted-media/Google/encrypted-media-lifetime-reload.html
Expand Up @@ -14,6 +14,7 @@
async_test(function(test)
{
var video = document.getElementById('testVideo');
var content = 'webm/test-encrypted.webm';
var mediaKeySession = null;
var hasSessionUpdateSucceeded = false;
var encryptedEventCount = 0;
Expand Down Expand Up @@ -81,12 +82,12 @@
location.reload();
}

navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).then(function(access) {
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getConfigurationForFile(content)).then(function(access) {
return access.createMediaKeys();
}).then(function(mediaKeys) {
waitForEventAndRunStep('encrypted', video, onEncrypted, test);
waitForEventAndRunStep('playing', video, onPlaying, test);
video.src = 'webm/test-encrypted.webm';
video.src = content;
return video.setMediaKeys(mediaKeys);
}).then(function(result) {
video.play();
Expand Down
Expand Up @@ -15,7 +15,7 @@

promise_test(function()
{
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).then(function(access) {
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
return access.createMediaKeys();
}).then(function(mediaKeys) {
var mediaKeySession = mediaKeys.createSession();
Expand All @@ -31,7 +31,7 @@

promise_test(function()
{
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).then(function(access) {
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
return access.createMediaKeys();
}).then(function(mediaKeys) {
var mediaKeySession = mediaKeys.createSession();
Expand All @@ -46,7 +46,7 @@

promise_test(function()
{
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).then(function(access) {
return navigator.requestMediaKeySystemAccess('org.w3.clearkey', getSimpleConfiguration()).then(function(access) {
return access.createMediaKeys();
}).then(function(mediaKeys) {
var mediaKeySession = mediaKeys.createSession();
Expand Down
3 changes: 2 additions & 1 deletion encrypted-media/Google/encrypted-media-onencrypted.html
Expand Up @@ -19,6 +19,7 @@
async_test(function(test)
{
var video = document.getElementById('testVideo');
var content = 'webm/test-encrypted.webm';

var onEncrypted = function(event)
{
Expand All @@ -33,7 +34,7 @@
};

waitForEventAndRunStep('encrypted', video, onEncrypted, test);
video.src = 'webm/test-encrypted.webm';
video.src = content;
}, 'encrypted fired on encrypted media file.');
</script>
</body>
Expand Down
Expand Up @@ -18,6 +18,10 @@
var encryptedEventCount = 0;
var playbackCount = 0;

// Content to be played. These files must be the same format.
var encryptedContent = 'webm/test-encrypted.webm';
var unencryptedContent = 'webm/test.webm';

var rawKey = new Uint8Array([0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c]);

Expand Down Expand Up @@ -93,18 +97,20 @@
}

function startPlayback() {
// Alternate between encrypted and unencrypted files.
if (playbackCount % 2) {
video.src = 'webm/test.webm';
// Unencrypted files don't require MediaKeys.
video.src = unencryptedContent;
video.play();
return;
}

navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).then(function(access) {
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getConfigurationForFile(encryptedContent)).then(function(access) {
return access.createMediaKeys();
}).then(function(mediaKeys) {
return video.setMediaKeys(mediaKeys);
}).then(function(result) {
video.src = 'webm/test-encrypted.webm';
video.src = encryptedContent;
assert_false(video.mediaKeys === null, "video.mediaKeys is null.");
video.play();
}).catch(function(error) {
Expand Down
Expand Up @@ -14,6 +14,7 @@
async_test(function(test)
{
var video = document.getElementById('testVideo');
var content = 'webm/test-encrypted-different-av-keys.webm';
var audioMediaKeySession = null;
var videoMediaKeySession = null;
var audioInitDataType = null;
Expand Down Expand Up @@ -121,12 +122,12 @@
test.done();
}

navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).then(function(access) {
navigator.requestMediaKeySystemAccess('org.w3.clearkey', getConfigurationForFile(content)).then(function(access) {
return access.createMediaKeys();
}).then(function(mediaKeys) {
waitForEventAndRunStep('encrypted', video, onEncrypted, test);
waitForEventAndRunStep('playing', video, onPlaying, test);
video.src = 'webm/test-encrypted-different-av-keys.webm';
video.src = content;
return video.setMediaKeys(mediaKeys);
}).then(function(result) {
video.play();
Expand Down

0 comments on commit 5d8b6f5

Please sign in to comment.