Skip to content

Commit a504f14

Browse files
committed
Fix PlayReady on IE and Edge
We broke PlayReady on IE and Edge in #815 when we fixed PlayReady for Tizen. This should work for both, but will still need to be tested on Tizen after merging. Closes #837 Change-Id: Iff41845ae6a4b369e8f21a80623ebb2cb5475fd6
1 parent 734ac9b commit a504f14

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

lib/media/drm_engine.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,23 +1119,9 @@ shaka.media.DrmEngine.prototype.sendLicenseRequest_ = function(event) {
11191119
* @private
11201120
*/
11211121
shaka.media.DrmEngine.prototype.unpackPlayReadyRequest_ = function(request) {
1122-
// PlayReady CDMs in some clients (e.g. IE11, Edge) wrap the license message
1123-
// in UTF-16 encoded XML which can't be directly delivered to a license
1124-
// server. However, not all clients exhibit this behaviour. The Tizen
1125-
// PlayReady CDM message is UTF-8 encoded and can be passed to the license
1126-
// server as-is. Other CDMs do not seem to need this kind of special
1127-
// handling.
1128-
var xml = String.fromCharCode.apply(null, new Uint8Array(request.body));
1129-
1130-
if (xml.indexOf('<PlayReadyKeyMessage') !== 0) {
1131-
// The message is not wrapped.
1132-
request.headers['Content-Type'] = 'text/xml; charset=utf-8';
1133-
return;
1134-
}
1135-
1136-
// The raw license message is UTF-16-encoded XML. We need to unpack the
1137-
// Challenge element (base64-encoded string containing the actual license
1138-
// request) and any HttpHeader elements (sent as request headers).
1122+
// On IE and Edge, the raw license message is UTF-16-encoded XML. We need to
1123+
// unpack the Challenge element (base64-encoded string containing the actual
1124+
// license request) and any HttpHeader elements (sent as request headers).
11391125

11401126
// Example XML:
11411127

@@ -1155,8 +1141,18 @@ shaka.media.DrmEngine.prototype.unpackPlayReadyRequest_ = function(request) {
11551141
// </LicenseAcquisition>
11561142
// </PlayReadyKeyMessage>
11571143

1158-
xml = shaka.util.StringUtils.fromUTF16(
1159-
request.body, true /* littleEndian */);
1144+
var xml = shaka.util.StringUtils.fromUTF16(
1145+
request.body, true /* littleEndian */, true /* noThrow */);
1146+
if (xml.indexOf('PlayReadyKeyMessage') == -1) {
1147+
// This does not appear to be a wrapped message as on IE and Edge. Some
1148+
// clients do not need this unwrapping, so we will assume this is one of
1149+
// them. Note that "xml" at this point probably looks like random garbage,
1150+
// since we interpreted UTF-8 as UTF-16.
1151+
shaka.log.debug('PlayReady request is already unwrapped.');
1152+
request.headers['Content-Type'] = 'text/xml; charset=utf-8';
1153+
return;
1154+
}
1155+
shaka.log.debug('Unwrapping PlayReady request.');
11601156
var dom = new DOMParser().parseFromString(xml, 'application/xml');
11611157

11621158
// Set request headers.

lib/util/string_utils.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,17 @@ shaka.util.StringUtils.fromUTF8 = function(data) {
7070
*
7171
* @param {?BufferSource} data
7272
* @param {boolean} littleEndian true to read little endian, false to read big.
73+
* @param {boolean=} opt_noThrow true to avoid throwing in cases where we may
74+
* expect invalid input. If noThrow is true and the data has an odd length,
75+
* it will be truncated.
7376
* @return {string}
7477
* @throws {shaka.util.Error}
7578
* @export
7679
*/
77-
shaka.util.StringUtils.fromUTF16 = function(data, littleEndian) {
80+
shaka.util.StringUtils.fromUTF16 = function(data, littleEndian, opt_noThrow) {
7881
if (!data) return '';
7982

80-
if (data.byteLength % 2 != 0) {
83+
if (!opt_noThrow && data.byteLength % 2 != 0) {
8184
shaka.log.error('Data has an incorrect length, must be even.');
8285
throw new shaka.util.Error(
8386
shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.TEXT,
@@ -98,7 +101,7 @@ shaka.util.StringUtils.fromUTF16 = function(data, littleEndian) {
98101
}
99102

100103
// Use a DataView to ensure correct endianness.
101-
var length = data.byteLength / 2;
104+
var length = Math.floor(data.byteLength / 2);
102105
var arr = new Uint16Array(length);
103106
var dataView = new DataView(buffer);
104107
for (var i = 0; i < length; i++) {

test/media/drm_engine_integration.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,8 @@ describe('DrmEngine', function() {
247247
}); // describe('basic flow')
248248

249249
function checkKeySystems() {
250-
// TODO: re-enable these tests for PlayReady (b/38496036)
251250
// Our test asset for this suite can use any of these key systems:
252-
if (!support['com.widevine.alpha']) {
251+
if (!support['com.widevine.alpha'] && !support['com.microsoft.playready']) {
253252
// pending() throws a special exception that Jasmine uses to skip a test.
254253
// It can only be used from inside it(), not describe() or beforeEach().
255254
pending('Skipping DrmEngine tests.');

0 commit comments

Comments
 (0)