Skip to content

Commit

Permalink
Add support for UTF8 PlayReady CDM messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Rutz committed Aug 14, 2015
1 parent 8b045c7 commit f8c0ccc
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/streaming/protection/drm/KeySystem_PlayReady.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ MediaPlayer.dependencies.protection.KeySystem_PlayReady = function() {

var keySystemStr = "com.microsoft.playready",
keySystemUUID = "9a04f079-9840-4286-ab92-e65be0885f95",
messageFormat = "utf16",

getRequestHeaders = function(message) {
var msg,
xmlDoc,
headers = {},
parser = new DOMParser();
parser = new DOMParser(),
dataview = (messageFormat === "utf16") ? new Uint16Array(message.buffer) : new Uint8Array(message.buffer);

msg = String.fromCharCode.apply(null, new Uint16Array(message.buffer));
msg = String.fromCharCode.apply(null, dataview);
xmlDoc = parser.parseFromString(msg, "application/xml");

var headerNameList = xmlDoc.getElementsByTagName("name");
Expand All @@ -69,9 +71,10 @@ MediaPlayer.dependencies.protection.KeySystem_PlayReady = function() {
var msg,
xmlDoc,
parser = new DOMParser(),
licenseRequest = null;
licenseRequest = null,
dataview = (messageFormat === "utf16") ? new Uint16Array(message.buffer) : new Uint8Array(message.buffer);

msg = String.fromCharCode.apply(null, new Uint16Array(message.buffer));
msg = String.fromCharCode.apply(null, dataview);
xmlDoc = parser.parseFromString(msg, "application/xml");

if (xmlDoc.getElementsByTagName("Challenge")[0]) {
Expand Down Expand Up @@ -153,7 +156,22 @@ MediaPlayer.dependencies.protection.KeySystem_PlayReady = function() {

getRequestHeadersFromMessage: getRequestHeaders,

getLicenseRequestFromMessage: getLicenseRequest
getLicenseRequestFromMessage: getLicenseRequest,

/**
* It seems that some PlayReady implementations return their XML-based CDM
* messages using UTF16, while others return them as UTF8. Use this function
* to modify the message format to expect when parsing CDM messages.
*
* @param {string} format the expected message format. Either "utf8" or "utf16".
* @throws {Error} Specified message format is not one of "utf8" or "utf16"
*/
setPlayReadyMessageFormat: function(format) {
if (format !== "utf8" && format !== "utf16") {
throw new Error("Illegal PlayReady message format! -- " + format);
}
messageFormat = format;
}
};
};

Expand Down

4 comments on commit f8c0ccc

@goruklu
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greg,
On my environment (Linux + Chromium), new Uint8Array(message.buffer); does not work. new Uint8Array(message); works.
I'm not a JS expert but it seems like Uint8Array constructor wants the ArrayBuffer variable directly.

@greg80303
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@goruklu ee277fa should make the use of ArrayBuffer more consistent across all of the DRM system in dash.js. This commit should also fix the problem you just mentioned.

@markriley9999
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi

i know that this is a very old ticket! :)
we're looking to use DASHJS on our platform, across many different devices (TVs, STBs) - the majority of devices have a PR CDM which uses the UTF16 format, however some use UTF8.

So, one solution is to maintain a list of clients which require the UTF8 format and use the the setPlayReadyMessageFormat call accordingly.
However, creating and maintaining such a list does add complexity to a large platform.

One potential approach that I am looking at is to propose to manufacturers that they ensure that they standardise on UTF16 - however, this may be a big ask, and it's possible that some manufacturers may not meet this requirement.

Or, i'm wondering as to whether DASHJS could support an option to auto-detect (infer) the format, for example:

  • if odd number of bytes then format = UTF8 OR
  • if any 'even offset' byte != 0 then format = UTF8 (for a sample of the buffer)

this could be enabled by calling setPlayReadyMessageFormat("autodetect")

any opinions gratefully received! :)

@dsilhavy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets continue discussion here: #3896

Please sign in to comment.