Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for IE/Edge/PlayReady #176

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions externs/msmediakeys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/**
* @license
* Copyright 2015 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview Externs for prefixed EME v20140218 as supported by IE11/Edge
* (http://www.w3.org/TR/2014/WD-encrypted-media-20140218).
* @externs
*/



/**
* @constructor
* @param {string} keySystem
*/
function MSMediaKeys(keySystem) {}


/**
* @param {string} keySystem
* @param {string} contentType
* @return {boolean}
*/
MSMediaKeys.isTypeSupported = function(keySystem, contentType) {};


/**
* @param {string} contentType
* @param {?BufferSource} initData
* @return {!MSMediaKeySession}
*/
MSMediaKeys.prototype.createSession = function(contentType, initData) {};



/**
* @interface
* @extends {EventTarget}
*/
function MSMediaKeySession() {}


/**
* @param {?BufferSource} message
*/
MSMediaKeySession.prototype.update = function(message) {};


MSMediaKeySession.prototype.close = function() {};


/** @type {MSMediaKeyError} */
MSMediaKeySession.prototype.error;


/** @override */
MSMediaKeySession.prototype.addEventListener =
function(type, listener, useCapture) {};


/** @override */
MSMediaKeySession.prototype.removeEventListener =
function(type, listener, useCapture) {};


/** @override */
MSMediaKeySession.prototype.dispatchEvent = function(evt) {};


/**
* @param {MSMediaKeys} mediaKeys
*/
HTMLMediaElement.prototype.msSetMediaKeys = function(mediaKeys) {};



/** @constructor */
function MSMediaKeyError() {}


/** @type {number} */
MSMediaKeyError.prototype.code;


/** @type {number} */
MSMediaKeyError.prototype.systemCode;


/** @type {number} */
MSMediaKeyError.MS_MEDIA_KEYERR_UNKNOWN;


/** @type {number} */
MSMediaKeyError.MS_MEDIA_KEYERR_CLIENT;


/** @type {number} */
MSMediaKeyError.MS_MEDIA_KEYERR_SERVICE;


/** @type {number} */
MSMediaKeyError.MS_MEDIA_KEYERR_OUTPUT;


/** @type {number} */
MSMediaKeyError.MS_MEDIA_KEYERR_HARDWARECHANGE;


/** @type {number} */
MSMediaKeyError.MS_MEDIA_KEYERR_DOMAIN;
64 changes: 64 additions & 0 deletions lib/media/eme_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ shaka.media.EmeManager.prototype.requestLicense_ = function(
shaka.log.debug('requestLicense_', session, drmInfo, licenseRequestBody);

var info = this.createLicenseRequestInfo_(drmInfo, licenseRequestBody);

var licenseRequest =
new shaka.util.LicenseRequest(
/** @type {string} */(info['url']),
Expand Down Expand Up @@ -740,6 +741,64 @@ shaka.media.EmeManager.prototype.requestLicense_ = function(
};


/**
* Standard pre-processor for PlayReady license requests.
*
* @param {!shaka.player.DrmInfo.LicenseRequestInfo} info License request info.
*
* @private
*/
shaka.media.EmeManager.prototype.playReadyLicensePreProcessor_ =
function(info) {
/*
The playready license body is actually an XML string, so need to convert
info.body (which is a Uint8Array, holding UTF-16 text data) to a string

XML typically has this structure (as an example):
<PlayReadyKeyMessage type="LicenseAcquisition">
<LicenseAcquisition Version="1">
<Challenge encoding="base64encoded">
{Base64EncodedBinaryChallengeData}
</Challenge>
<HttpHeaders>
<HttpHeader>
<name>Content-Type</name>
<value>text/xml; charset=utf-8</value>
</HttpHeader>
<HttpHeader>
<name>SOAPAction</name>
<value>
"http://schemas.microsoft.com/DRM/2007/03/protocols/AcquireLicense"
</value>
</HttpHeader>
</HttpHeaders>
</LicenseAcquisition>
</PlayReadyKeyMessage>"

Only challenge data is sent in the POST body to the license server. Additional
http headers are required to be added to the XHR object in order for the
request to be processed correctly (e.g. may need to add a SOAPAction header
as in the above example)
*/

var licenseBodyXml =
String.fromCharCode.apply(null, new Uint16Array(info.body));
var licenseBodyXmlDom =
new DOMParser().parseFromString(licenseBodyXml, 'application/xml');

var headerNames = licenseBodyXmlDom.getElementsByTagName('name');
var headerValues = licenseBodyXmlDom.getElementsByTagName('value');

for (var i = 0; i < headerNames.length; i++) {
info.headers[headerNames[i].childNodes[0].nodeValue] =
headerValues[i].childNodes[0].nodeValue;
}

info.body = window.atob(licenseBodyXmlDom.getElementsByTagName('Challenge')[0]
.childNodes[0].nodeValue);
};


/**
* Creates a LicenseRequestInfo object, potentially calling a licenese request
* pre-processor.
Expand All @@ -764,6 +823,11 @@ shaka.media.EmeManager.prototype.createLicenseRequestInfo_ = function(
'headers': {}
};

// Apply common pre-processors
if (drmInfo.keySystem === 'com.microsoft.playready') {
this.playReadyLicensePreProcessor_(info);
}

if (!drmInfo.licensePreProcessor) {
return info;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/player/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ shaka.player.Player.prototype.onWatchdogTimer_ = function() {
* @private {number}
* @const
*/
shaka.player.Player.UNDERFLOW_THRESHOLD_ = 0.2;
shaka.player.Player.UNDERFLOW_THRESHOLD_ = 0.5;


/**
Expand Down
4 changes: 4 additions & 0 deletions lib/polyfill/mediakeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ goog.provide('shaka.polyfill.MediaKeys');
goog.require('shaka.log');
goog.require('shaka.polyfill.PatchedMediaKeys.nop');
goog.require('shaka.polyfill.PatchedMediaKeys.v01b');
goog.require('shaka.polyfill.PatchedMediaKeys.v20140218');


/**
Expand Down Expand Up @@ -48,6 +49,9 @@ shaka.polyfill.MediaKeys.install = function() {
} else if (HTMLMediaElement.prototype.webkitGenerateKeyRequest) {
shaka.log.info('Using prefixed EME v0.1b.');
shaka.polyfill.PatchedMediaKeys.v01b.install();
} else if (window.MSMediaKeys) {
shaka.log.info('Using EME v20140218');
shaka.polyfill.PatchedMediaKeys.v20140218.install();
} else {
shaka.log.info('EME not available.');
shaka.polyfill.PatchedMediaKeys.nop.install();
Expand Down
Loading