1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
media / test / data / eme_player_js / clearkey_player.js [blame]
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// ClearKeyPlayer responsible for playing media using Clear Key key system.
function ClearKeyPlayer(video, testConfig) {
this.video = video;
this.testConfig = testConfig;
}
ClearKeyPlayer.prototype.init = function() {
// Returns a promise.
return PlayerUtils.initEMEPlayer(this);
};
ClearKeyPlayer.prototype.registerEventListeners = function() {
// Returns a promise.
return PlayerUtils.registerEMEEventListeners(this);
};
ClearKeyPlayer.prototype.onMessage = function(message) {
const mediaKeySession = message.target;
const keyId = Utils.extractFirstLicenseKeyId(message.message);
const key = Utils.getDefaultKey(this.testConfig.forceInvalidResponse);
const jwkSet = Utils.createJWKData(keyId, key);
const keySystem = this.testConfig.keySystem;
// Number of milliseconds in 100 years, which is approximately
// 100 * 365 * 24 * 60 * 60 * 1000.
// See clear_key_cdm.cc where this value is set.
const ECK_RENEWAL_EXPIRATION = 3153600000000;
Utils.timeLog('Calling update: ' + String.fromCharCode.apply(null, jwkSet));
mediaKeySession.update(jwkSet).then(function() {
// Check session expiration.
// - For CLEARKEY, expiration is not set and is the default value NaN.
// - For MESSAGE_TYPE_TEST_KEYSYSTEM, expiration is set to
// ECK_RENEWAL_EXPIRATION milliseconds after 01 January 1970 UTC.
// - For other EXTERNAL_CLEARKEY variants, expiration is explicitly set to
// NaN.
var expiration = mediaKeySession.expiration;
if (keySystem == MESSAGE_TYPE_TEST_KEYSYSTEM) {
if (isNaN(expiration) || expiration != ECK_RENEWAL_EXPIRATION) {
Utils.timeLog('Unexpected expiration: ', expiration);
Utils.failTest(error, EME_UPDATE_FAILED);
}
} else {
if (!isNaN(mediaKeySession.expiration)) {
Utils.timeLog('Unexpected expiration: ', expiration);
Utils.failTest(error, EME_UPDATE_FAILED);
}
}
}).catch(function(error) {
// Ignore the error if a crash is expected. This ensures that the decoder
// actually detects and reports the error.
if (this.testConfig.keySystem != CRASH_TEST_KEYSYSTEM) {
Utils.failTest(error, EME_UPDATE_FAILED);
}
});
};