Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Unified Diff: media/test/data/eme_player_js/utils.js

Issue 427993002: Implement ClearKey message format as JSON. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/test/data/eme_player_js/prefixed_clearkey_player.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/test/data/eme_player_js/utils.js
diff --git a/media/test/data/eme_player_js/utils.js b/media/test/data/eme_player_js/utils.js
index 491bac7892a7370b9d23809e7284384f3996c759..ca62cd1f7b2a1ff9662c123849eabe1975028eb9 100644
--- a/media/test/data/eme_player_js/utils.js
+++ b/media/test/data/eme_player_js/utils.js
@@ -79,6 +79,28 @@ Utils.createJWKData = function(keyId, key) {
return Utils.convertToUint8Array(createJWKSet(createJWK(keyId, key)));
};
+Utils.extractFirstLicenseKey = function(message) {
+ // Decodes data (Uint8Array) from base64 string.
+ // TODO(jrummell): Update once the EME spec is updated to say base64url
+ // encoding.
+ function base64Decode(data) {
+ return atob(data);
+ }
+
+ function convertToString(data) {
+ return String.fromCharCode.apply(null, Utils.convertToUint8Array(data));
+ }
+
+ try {
+ var json = JSON.parse(convertToString(message));
+ // Decode the first element of 'kids', return it as an Uint8Array.
+ return Utils.convertToUint8Array(base64Decode(json.kids[0]));
+ } catch (error) {
+ // Not valid JSON, so return message untouched as Uint8Array.
+ return Utils.convertToUint8Array(message);
+ }
+}
+
Utils.documentLog = function(log, success, time) {
if (!docLogs)
return;
@@ -154,13 +176,17 @@ Utils.getHexString = function(uintArray) {
return hex_str;
};
-Utils.getInitDataFromMessage = function(message, mediaType) {
- var initData = Utils.convertToUint8Array(message.message);
+Utils.getInitDataFromMessage = function(message, mediaType, decodeJSONMessage) {
+ var initData;
if (mediaType.indexOf('mp4') != -1) {
// Temporary hack for Clear Key in v0.1.
// If content uses mp4, then message.message is PSSH data. Instead of
// parsing that data we hard code the initData.
initData = Utils.convertToUint8Array(KEY_ID);
+ } else if (decodeJSONMessage) {
+ initData = Utils.extractFirstLicenseKey(message.message);
+ } else {
+ initData = Utils.convertToUint8Array(message.message);
}
return initData;
};
« no previous file with comments | « media/test/data/eme_player_js/prefixed_clearkey_player.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698