Custom fields in Widevine/EME/CDM license request

3,750 views
Skip to first unread message

Roberto Celestino

unread,
May 13, 2015, 10:29:56 AM5/13/15
to shaka-pla...@googlegroups.com
Hello,

We are using the shaka player  as our html5 player to support widevine & dash in Chrome.
We have a doubt about how to send custom fields in the Widevine license request.
In pr the player allows you to send customdata, that practically it is an string where you cant put a simple value or a json-encoded value (base64).

Is Shaka supporting some event/pre-processs callback to customize the parameter to be sent to the Widevine licenser into the license request?

What about initialization data? Is it used only to configure EME/CDM? Can I include additional parameters there?

Thanks in advance.

roberto.

Joey Parrish

unread,
May 21, 2015, 1:45:29 PM5/21/15
to Roberto Celestino, shaka-pla...@googlegroups.com
Hi Roberto,

We do have plans for a preprocess callback in v1.4.0.  You can track progress and see the discussion so far at https://github.com/google/shaka-player/issues/62 .

From the EME perspective, you can wrap the CDM-generated license request however you like, but AFAIK there isn't a generic way through EME to pass custom data through the CDM itself.  This concept is not part of the EME spec, and since it is not required by EME, CDMs in general may not support this anyway.

Initialization data comes in a few different forms.  The init data, in whatever format, is used by the CDM to generate the key request.  (Not all CDMs support all formats, and so there's some negotiation done.)

In ISO BMFF (MP4) files, it's a set of concatenated PSSH boxes.  The PSSH box contains an opaque blob at the end, and this blob's format differs per DRM system.  There's not any general way to put extra information into this.

In WebM files, init data is just a single key ID.  There's also a "key IDs" format (https://w3c.github.io/encrypted-media/keyids-format.html), a JSON structure which is used by the ClearKey CDM.  These formats do not allow for extra information, either.

As far as I can tell, the only general way to pass extra information to your license server through EME is by wrapping the generated license request and unwrapping it again in the server.

Does that answer your questions?

Thanks,
Joey


--
You received this message because you are subscribed to the Google Groups "Shaka Player Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shaka-player-us...@googlegroups.com.
To post to this group, send email to shaka-pla...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shaka-player-users/cb0c1dd6-20b9-4238-8ab2-afb7bdfb8b95%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrea Pastori

unread,
Jul 17, 2015, 6:24:53 AM7/17/15
to shaka-pla...@googlegroups.com, rcele...@gmail.com
Hi Joey

understand your answer. I would like to add some to this discussion. I have the following need: Integrate a proxy api and some parameter to the request. Moreover the back-end api is designed "in custom way" (I mean with some extra information in addition to the license). If I understood well we can use opt_licensePreProcessor and opt_licensePostProcessor to manage it but I'm not able to understand how. Could you share some few line of code to help me? If I'm not wrong we need to provide a proper callbacks to the DrmSchemeInfo before use it. 

Thanks in advance
Andrea

tdr...@google.com

unread,
Jul 22, 2015, 9:42:03 PM7/22/15
to Shaka Player Users, rcele...@gmail.com
Hi,

You can use the license pre-processor to modify the body of the license request and to add headers to the license request. At the moment you cannot modify the license server URL (e.g., to add query parameters); however, we are adding support for this (see issue https://github.com/google/shaka-player/issues/135).

You can use the license post-processor to extract the raw license, which gets ingested by the browser, from the response from the server.

For example, if your server response has the format:
custom_response_field1;license_data

And your license server expects the format:
custom_request_data1;custom_request_data2;license_request

You can use the post-processor and pre-processor as follows,

// Returns the raw license.
var postProcess = function(response) {
  // Convert the server's response into a string.
  var responseString = String.fromCharCode.apply(null, response);
  // Extract the license part.
  var licenseString = responseString.split(';').pop();
  // Re-encode the license as an array of bytes.
  var license = new Uint8Array(licenseString.split('').map(function(char) { return char.charCodeAt(0); }));
  return license; 
}

// Modifies |info| in-place.
var preProcess = function(info) {
  // Extract license request from the body.
  var licenseRequest = info.body.slice(0);
  // Construct new license request.
  var licenseRequestString = 'header1_value;header2_value;' + String.fromCharCode.apply(null, licenseRequest);
  info.body = licenseRequestString;
};

These functions would be passed to the DrmSchemeInfo constructor in your interpretContentProtection callback. Note in practice you'd probably want to encode the license and license request as base64.

I hope this helps, and I'm happy to answer any further questions.

P.S.: We've identified the need to improve our documentation around license pre-processing and license post-processing; we are aiming to improve this documentation for v1.5.0!

Andrea Pastori

unread,
Jul 23, 2015, 8:29:32 AM7/23/15
to Shaka Player Users, rcele...@gmail.com, tdr...@google.com
Hi

first of all thanks for your answer. I tried the code that you shared and it works :) (cool!). Only a clarification: for the pre-precessing part I fixed with:
....
 var licenseRequestString = 'header1_value;header2_value;' + String.fromCharCode.apply(null, new Uint8Array(licenseRequest));
.....

since otherwise I get only header1_value;header2_value; in the request followed by empty string.

Andrea Pastori

unread,
Aug 7, 2015, 12:25:46 PM8/7/15
to Shaka Player Users, rcele...@gmail.com, tdr...@google.com
Hi

could you paste an example of how to set an header on the request? We have the following issue: default content type of the license request from Shaka is "text/plain" and we need to override to "www-form-urlencoded"

Thanks in advance
 
Andrea

tdr...@google.com

unread,
Aug 7, 2015, 12:54:08 PM8/7/15
to Shaka Player Users, rcele...@gmail.com, tdr...@google.com
Hi,

In your pre-processor function you can add

var preProcess = function(info) {
  info.headers['Content-Type'] = 'application/x-www-form-urlencoded';
};

Giovanni Delli Carpini

unread,
Sep 3, 2015, 12:15:39 PM9/3/15
to Shaka Player Users, rcele...@gmail.com, tdr...@google.com
Hi,
I am colleague of Andrea. Thanks for the support, now we receive response from widevine proxy.
We are receiving the following error client side --> Error shaka PlayerTypeError: Failed to execute 'update' on 'MediaKeySession': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'
We are using the following instruction:


    var license = new Uint8Array(licenseString.split('').map(function(char) { return char.charCodeAt(0); })); 
    return license;
In our environment we receive "licenseString" in encoded  BASE64  format, is it correct to pass this string to shakaPlayer?
Please have you further information about above error?

Regards
Giovanni

Joey Parrish

unread,
Sep 3, 2015, 2:22:33 PM9/3/15
to Giovanni Delli Carpini, Shaka Player Users, Roberto Celestino, Timothy Drews
Hi Giovanni,

The error you showed me does not appear to be from the widevine proxy.  It appears to be a JavaScript error.

Can you share your complete application code?  If not, can you share your usage of Player, DashVideoSource, your ContentProtection callbacks, and your license pre- and post-processing callbacks?

Also, what browser and version are you using?

Thanks,
Joey


--
You received this message because you are subscribed to the Google Groups "Shaka Player Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shaka-player-us...@googlegroups.com.
To post to this group, send email to shaka-pla...@googlegroups.com.

Giovanni Delli Carpini

unread,
Sep 4, 2015, 3:27:24 AM9/4/15
to Shaka Player Users, giovannide...@gmail.com, rcele...@gmail.com, tdr...@google.com
Hi Joey,
thanks for quickly response, the error is side client JavaScript.
following the code:

  1. Dash Video Source
var mpdUrl = _url;  // input paramiter mpd manifest file
var estimator = new shaka.util.EWMABandwidthEstimator();
var source = new shaka.player.DashVideoSource(mpdUrl, interpretContentProtection, estimator);
  1. Content Protection Callbacks
function interpretContentProtection(contentProtection) {
var appLicenserQLatency = currentDate.getTime();
if (contentProtection.schemeIdUri == 'urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed') {
var licenseServerUrl = configurationManager.getProperty("app.w3c.widevine.proxyUrl");
var keySystem = 'com.widevine.alpha'; 
var licensePreProcessor = function(licenseRequestInfo) {
var licenseRequest = licenseRequestInfo.body.slice(0);
customData = MediaManager.customData;
var newLicenseRequest = String.fromCharCode.apply(null, new Uint8Array(licenseRequest));
console.log('license request non encoded: ' + newLicenseRequest);
var base64Request = window.btoa(newLicenseRequest);
licenseRequestInfo.body = customData+'&payload='+ encodeURIComponent(base64Request);
console.log('request: ' + licenseRequestInfo.body);
licenseRequestInfo.headers["Content-Type"]='application/x-www-form-urlencoded';
};

var licensePostProcessor = function(response) {
var Uint8ArrayUtils = shaka.util.Uint8ArrayUtils;
var str = String.fromCharCode.apply(null, response);
var responseStr = Uint8ArrayUtils.toString(response);
console.log('licensePostProcessor1: ' + shaka.util.Uint8ArrayUtils.toString(response));
var callBackOK = function(object){
//Manage OK return License
console.log('OK: ' + object.bean.license);
var lic =  window.atob(object.bean.license);
var licJqDecoded =  AVSJQ.base64Encode(object.bean.license);
console.log('License cleary: ' + lic);
var license = new Uint8Array(object.bean.license.split('').map(function(char) { return char.charCodeAt(0); }));
return license;
//return Uint8ArrayUtils.fromBase64(JSON.parse(responseStr).resultObj.license);


};
     var callBackError=function(object){
      console.log('ERROR: ' + object.avsResp.message);
     };
ManagerBO.checkResultBE(JSON.parse(str), callBackOK, callBackError);
};

return new shaka.player.DrmSchemeInfo(keySystem, licenseServerUrl,
false /* withCredentials */, null /* initData */,
licensePostProcessor, licensePreProcessor);
}

console.warn('Unrecognized scheme: ' + contentProtection.schemeIdUri);
return null;
};

I'm using Chrome Version 43.0.2357.134  and Chrome 44

I have downloaded shaka player  1.3.0   from this repository : https://tools-static.wmflabs.org/cdnjs/ajax/libs/shaka-player/

Thanks in advance
Giovanni


To unsubscribe from this group and stop receiving emails from it, send an email to shaka-player-users+unsub...@googlegroups.com.

To post to this group, send email to shaka-pla...@googlegroups.com.

Giovanni Delli Carpini

unread,
Sep 4, 2015, 4:05:48 AM9/4/15
to Shaka Player Users, giovannide...@gmail.com, rcele...@gmail.com, tdr...@google.com
HI,
i receive the same error with license not in Base64 encoded:
var lic =  window.atob(object.bean.license);
var license = new Uint8Array(lic.split('').map(function(char) { return char.charCodeAt(0); }));

where  "object.bean.license" is the value  about license.
the error is :
Error shaka PlayerTypeError: Failed to execute 'update' on 'MediaKeySession': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'

thanks
Giovanni

Joey Parrish

unread,
Sep 4, 2015, 4:49:05 PM9/4/15
to Giovanni Delli Carpini, Shaka Player Users, Roberto Celestino, Timothy Drews
I see the problem.  You must return the license from the post-processor callback, but you are not returning anything.  Here's a simplified version of what you are using, to make it easier to spot the mistake:

var licensePostProcessorCallback = function(response) {
  var innerCallback = function(object){
  return new Uint8Array(doSomeTransformation(response));
  };

  doSomethingElseThenCall(callback);
  // NOTE that the license must be returned here from the postprocessor callback.
};


To unsubscribe from this group and stop receiving emails from it, send an email to shaka-player-us...@googlegroups.com.

To post to this group, send email to shaka-pla...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Shaka Player Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shaka-player-us...@googlegroups.com.

To post to this group, send email to shaka-pla...@googlegroups.com.

Giovanni Delli Carpini

unread,
Sep 7, 2015, 9:48:08 AM9/7/15
to Shaka Player Users, giovannide...@gmail.com, rcele...@gmail.com, tdr...@google.com
Hi,
thanks for the correction. I have downloaded the project from gitHub "https://github.com/google/shaka-player.git" and modified  the script app.js with the following code.
I do not receive error but the player not start.
In attach the file of log. 
Thanks in advance
Giovanni

var licensePreProcessor = function(licenseRequestInfo) {
//licenseRequestInfo.body = "licenseRequestInfo.bodyCustomReq";
var licenseRequest = licenseRequestInfo.body.slice(0);
customData = "channel=CHROME_HTML5&contentId=1200003112&type=VOD&persistent=N" ;//MediaManager.customData;
///////////////// remove!! valid only for test
//customData = 'channel=CHROME_HTML5&contentId=1000000110&type=VOD';
////////////////
// create LicenseRequst ex. 'channel=PCTV&contentId=1200000415&type=VOD' + lilcenseRequest present into body
var newLicenseRequest = String.fromCharCode.apply(null, new Uint8Array(licenseRequest));
console.log('license request non encoded: ' + newLicenseRequest);
//var urlEncoded=fixedEncodeURIComponent(newLicenseRequest);
var base64Request = window.btoa(newLicenseRequest);
//var base64Request = AVSJQ.base64Encode(newLicenseRequest);
//licenseRequestInfo.body = customData+'&payload='+ urlEncoded.replace(/%20/g, "+");
licenseRequestInfo.body = customData+'&payload='+ encodeURIComponent(base64Request);
console.log('request: ' + licenseRequestInfo.body);
licenseRequestInfo.headers["Content-Type"]='application/x-www-form-urlencoded';
};

var licensePostProcessor = function(response) {
var Uint8ArrayUtils = shaka.util.Uint8ArrayUtils;
//var responseApp='{"errorDescription":"","message":"","resultCode":"OK","resultObj":{"license":"NjU2MjM1MzY1Ng=="},"systemTime":1349265875}';
var str = String.fromCharCode.apply(null, response);
var json=JSON.parse(str);
var responseStr = Uint8ArrayUtils.toString(response);
console.log('licensePostProcessor1: ' + shaka.util.Uint8ArrayUtils.toString(response));
console.log('OK: ' + json.resultObj.license);
var lic =  window.atob(json.resultObj.license);
console.log('License cleary: ' + lic);
var license = new Uint8Array(lic.split('').map(function(char) { return char.charCodeAt(0); }));
return license;
};

return new shaka.player.DrmSchemeInfo(keySystem, licenseServerUrl,
false /* withCredentials */, null /* initData */,
licensePostProcessor, licensePreProcessor);



To unsubscribe from this group and stop receiving emails from it, send an email to shaka-player-users+unsub...@googlegroups.com.

To post to this group, send email to shaka-pla...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Shaka Player Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shaka-player-users+unsub...@googlegroups.com.

To post to this group, send email to shaka-pla...@googlegroups.com.
log_shaka.png
shakaPlayer-encryptedContent-1441630582019.txt

Giovanni Delli Carpini

unread,
Sep 8, 2015, 11:28:19 AM9/8/15
to Shaka Player Users, giovannide...@gmail.com, rcele...@gmail.com, tdr...@google.com
Hi,
now occur  a problem before the call of license server.
The player, i think, tries to start the video end at the sent the errors:
  1. Assertion failed -->   source_buffer_manager.js:245
  2. Player error  --> app.js 961 detail: DOMException: Failed to execute 'start' on 'TimeRanges': The index provided (0) is greater than or equal to the maximum bound (0). at Error (native) at null.<anonymous>
  3. Player error  --> app.js 961 detail: Error: The browser failed to decode the media content.    at shaka.player.Player.onError_ (http://localhost:8080/shaka-player_1_4/lib/player/player.js:380:15)
In attach the image of log.
The problem is on the description file (mdp) ? or side code?
the version 1.4 form git is correct?

Thanks in advance
Giovanni
log_shaka_player.jpg

Giovanni Delli Carpini

unread,
Sep 12, 2015, 1:37:51 PM9/12/15
to Shaka Player Users, giovannide...@gmail.com, rcele...@gmail.com, tdr...@google.com
Hi,
the player work fine but only with Chrome version 46 Beta.
With previous version of chrome we receive different errors about  MediaKeySystem or Failed to buffer segment
In attach the mdp files used and log of chrome (version 45.0.2454.85 or version 45.0.2454.85m)
Where do you think is the problem: code side or content mdp side files? 

Thanks so mach in advance
Giovanni
shaka Player error.zip

tdr...@google.com

unread,
Sep 15, 2015, 2:03:51 PM9/15/15
to Shaka Player Users, giovannide...@gmail.com, rcele...@gmail.com, tdr...@google.com
Hi,

The error
DOMException: Failed to execute 'start' on 'TimeRanges': The index provided (0) is greater than or equal to the maximum bound (0).
may be caused by several issue. We've improved error logging and begun utilizing cenc:default_KID to monitor key statuses for v1.5.0, so
can you try your content with the master branch on github with debug logging enabled [call shaka.log.setLevel(shaka.log.Level.DEBUG])?

Also, are you able to play the content unencrypted?

Giovanni Delli Carpini

unread,
Sep 17, 2015, 11:58:09 AM9/17/15
to Shaka Player Users, giovannide...@gmail.com, rcele...@gmail.com, tdr...@google.com, Joey Parrish
Hi,
I have download master branch from url : "https://github.com/google/shaka-player.git"
I use the key system 'com.widevine.alpha'.
In attach the log with debug logging enabled.
I don't have problem with content unencrypted, but only with  contents encrypted played on Chrome browser version less then 46.
Thanks in advance

Giovani
log shaka encrypted-1442504043687.txt

David Dorwin

unread,
Sep 17, 2015, 12:13:42 PM9/17/15
to Giovanni Delli Carpini, Shaka Player Users, rcele...@gmail.com, Timothy Drews, Joey Parrish
Are you saying it works in Chrome 46 and later? If so, it might be related to the content. For example, https://code.google.com/p/chromium/issues/detail?id=461061 was fixed in Chrome 46. chrome://media-internals might also be helpful to determine the cause of failures.

David

Giovani
Hi,

The error
To unsubscribe from this group and stop receiving emails from it, send an email to shaka-player-us...@googlegroups.com.

To post to this group, send email to shaka-pla...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Shaka Player Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shaka-player-us...@googlegroups.com.

To post to this group, send email to shaka-pla...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Shaka Player Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shaka-player-us...@googlegroups.com.

To post to this group, send email to shaka-pla...@googlegroups.com.

Giovanni Delli Carpini

unread,
Sep 23, 2015, 9:22:20 AM9/23/15
to Shaka Player Users, giovannide...@gmail.com, rcele...@gmail.com, tdr...@google.com, joeyp...@google.com
HI,
thanks for the hint, now video works fine.
thanks so much

Giovanni
Giovani
Hi,

The error
To unsubscribe from this group and stop receiving emails from it, send an email to shaka-player-users+unsub...@googlegroups.com.

To post to this group, send email to shaka-pla...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Shaka Player Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shaka-player-users+unsub...@googlegroups.com.

To post to this group, send email to shaka-pla...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Shaka Player Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shaka-player-users+unsub...@googlegroups.com.

To post to this group, send email to shaka-pla...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages