Skip to content

Commit

Permalink
Add MediaCapabilities support and release v2.0.0 (#11)
Browse files Browse the repository at this point in the history
See w3c/media-capabilities#100

The top-level export name now reflects the fact that there are two
polyfills being installed.  This is a breaking change, so we bump the
version number to 2.0.0.

Closes #1
  • Loading branch information
joeyparrish authored Dec 19, 2019
1 parent 480c393 commit 08d18a2
Show file tree
Hide file tree
Showing 11 changed files with 564 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ module.exports = {
{
// These types are browser-provided, so trust that they exist.
'definedTypes': [
'MediaCapabilities',
'MediaCapabilitiesDecodingInfo',
'MediaDecodingConfiguration',
'MediaKeySystemConfiguration',
'MediaKeySystemMediaCapability',
],
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 2.0.0 (2019-12-12)

Features:
- Added support for polyfilling MediaCapabilities, too
- https://github.com/w3c/media-capabilities/issues/100


## 1.0.3 (2019-12-05)

Bugfixes:
Expand Down
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# EME Encryption Scheme Polyfill
# EME & MediaCapabilities Encryption Scheme Polyfill

A polyfill to add support for EncryptionScheme queries in EME.
A polyfill to add support for EncryptionScheme queries in EME and
MediaCapabilities.

- https://wicg.github.io/encrypted-media-encryption-scheme/
- https://google.github.io/eme-encryption-scheme-polyfill/demo/
- https://github.com/WICG/encrypted-media-encryption-scheme/issues/13
- https://github.com/w3c/media-capabilities/issues/100

Because this polyfill can't know what schemes the UA or CDM actually support,
it assumes support for the historically-supported schemes of each well-known
Expand All @@ -15,12 +17,12 @@ the CommonJS module format. It can also be directly included via a script tag.

The minified bundle (`dist/eme-encryption-scheme-polyfill.js`) is a standalone
module compatible with the CommonJS and AMD module formats, and can also be
directly included via a script tag. It is about 3.1kB uncompressed, and gzips
to about 1.2kB.
directly included via a script tag. It is about 4.4kB uncompressed, and gzips
to about 1.5kB.

To avoid the possibility of extra user prompts, this will shim EME so long as
it exists, without checking support for `encryptionScheme` upfront. The
support check will happen on-demand the first time EME is used.
To avoid the possibility of extra user prompts, this will shim EME & MC so long
as they exist, without checking support for `encryptionScheme` upfront. The
support check will happen on-demand the first time EME/MC are used.


## Usage
Expand All @@ -34,5 +36,10 @@ npm install eme-encryption-scheme-polyfill
```

```js
// Install both EME & MC polyfills at once:
EncryptionSchemePolyfills.install();

// Install each one separately (unminified source only):
EmeEncryptionSchemePolyfill.install();
McEncryptionSchemePolyfill.install();
```
207 changes: 207 additions & 0 deletions closure-compiler-check/mediacapabilities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
/*
* @license
* Copyright 2019 The Closure Compiler authors
*
* 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 MediaCapabilities externs.
* Based on {@link https://w3c.github.io/media-capabilities/ MC draft 6 November
* 2019}.
* @externs
*/

/**
* @typedef {string}
* @see https://w3c.github.io/media-capabilities/#enumdef-hdrmetadatatype
*/
var HdrMetadataType;

/**
* @typedef {string}
* @see https://w3c.github.io/media-capabilities/#enumdef-colorgamut
*/
var ColorGamut;

/**
* @typedef {string}
* @see https://w3c.github.io/media-capabilities/#enumdef-transferfunction
*/
var TransferFunction;

/**
* @typedef {string}
* @see https://w3c.github.io/media-capabilities/#enumdef-mediadecodingtype
*/
var MediaDecodingType;

/**
* @typedef {string}
* @see https://w3c.github.io/media-capabilities/#enumdef-mediaencodingtype
*/
var MediaEncodingType;

/**
* @typedef {{
* contentType: string,
* width: number,
* height: number,
* bitrate: number,
* framerate: number,
* hasAlphaChannel: (boolean|undefined),
* hdrMetadataType: (!HdrMetadataType|undefined),
* colorGamut: (!ColorGamut|undefined),
* transferFunction: (!TransferFunction|undefined)
* }}
* @see https://w3c.github.io/media-capabilities/#dictdef-videoconfiguration
*/
var VideoConfiguration;

// NOTE: channels definition below is not yet stable in the spec as of Dec 2019.
// "The channels needs to be defined as a double (2.1, 4.1, 5.1, ...), an
// unsigned short (number of channels) or as an enum value. The current
// definition is a placeholder."
/**
* @typedef {{
* contentType: string,
* channels: (*|undefined),
* bitrate: (number|undefined),
* samplerate: (number|undefined),
* spatialRendering: (boolean|undefined)
* }}
* @see https://w3c.github.io/media-capabilities/#dictdef-audioconfiguration
*/
var AudioConfiguration;

// NOTE: encryptionScheme is not yet in the MC spec as of Dec 2019, but has
// already landed in EME and should be in MC soon.
// https://github.com/w3c/media-capabilities/issues/100
/**
* @typedef {{
* robustness: (string|undefined),
* encryptionScheme: (string|undefined)
* }}
* @see https://w3c.github.io/media-capabilities/#dictdef-keysystemtrackconfiguration
*/
var KeySystemTrackConfiguration;

/**
* @typedef {{
* keySystem: string,
* initDataType: (string|undefined),
* distinctiveIdentifier: (string|undefined),
* persistentState: (string|undefined),
* sessionTypes: (!Array<string>|undefined),
* audio: (!KeySystemTrackConfiguration|undefined),
* video: (!KeySystemTrackConfiguration|undefined)
* }}
* @see https://w3c.github.io/media-capabilities/#dictdef-mediacapabilitieskeysystemconfiguration
*/
var MediaCapabilitiesKeySystemConfiguration;

/**
* @record
* @see https://w3c.github.io/media-capabilities/#dictdef-mediaconfiguration
*/
function MediaConfiguration() {}

/** @type {!VideoConfiguration|undefined} */
MediaConfiguration.prototype.video;

/** @type {!AudioConfiguration|undefined} */
MediaConfiguration.prototype.audio;

/**
* @record
* @extends {MediaConfiguration}
* @see https://w3c.github.io/media-capabilities/#dictdef-mediadecodingconfiguration
*/
function MediaDecodingConfiguration() {}

/** @type {MediaDecodingType} */
MediaDecodingConfiguration.prototype.type;

/** @type {!MediaCapabilitiesKeySystemConfiguration|undefined} */
MediaDecodingConfiguration.prototype.keySystemConfiguration;

/**
* @record
* @extends {MediaConfiguration}
* @see https://w3c.github.io/media-capabilities/#dictdef-mediaencodingconfiguration
*/
function MediaEncodingConfiguration() {}

/** @type {MediaEncodingType} */
MediaEncodingConfiguration.prototype.type;

/**
* @record
* @see https://w3c.github.io/media-capabilities/#dictdef-mediacapabilitiesinfo
*/
function MediaCapabilitiesInfo() {}

/** @type {boolean} */
MediaCapabilitiesInfo.prototype.supported;

/** @type {boolean} */
MediaCapabilitiesInfo.prototype.smooth;

/** @type {boolean} */
MediaCapabilitiesInfo.prototype.powerEfficient;

/**
* @record
* @extends {MediaCapabilitiesInfo}
* @see https://w3c.github.io/media-capabilities/#dictdef-mediacapabilitiesdecodinginfo
*/
function MediaCapabilitiesDecodingInfo() {}

/** @type {?MediaKeySystemAccess} */
MediaCapabilitiesDecodingInfo.prototype.keySystemAccess;

/** @type {!MediaDecodingConfiguration} */
MediaCapabilitiesDecodingInfo.prototype.configuration;

/**
* @record
* @extends {MediaCapabilitiesInfo}
* @see https://w3c.github.io/media-capabilities/#dictdef-mediacapabilitiesencodinginfo
*/
function MediaCapabilitiesEncodingInfo() {}

/** @type {!MediaEncodingConfiguration} */
MediaCapabilitiesEncodingInfo.prototype.configuration;

/**
* @interface
* @see https://w3c.github.io/media-capabilities/#mediacapabilities
*/
function MediaCapabilities() {}

/**
* @param {!MediaDecodingConfiguration} configuration
* @return {!Promise<!MediaCapabilitiesDecodingInfo>}
*/
MediaCapabilities.prototype.decodingInfo = function(configuration) {};

/**
* @param {!MediaEncodingConfiguration} configuration
* @return {!Promise<!MediaCapabilitiesEncodingInfo>}
*/
MediaCapabilities.prototype.encodingInfo = function(configuration) {};

/** @const {?MediaCapabilities} */
Navigator.prototype.mediaCapabilities;

/** @const {?MediaCapabilities} */
WorkerNavigator.prototype.mediaCapabilities;
12 changes: 7 additions & 5 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

<!-- Load & install the polyfill. -->
<script src="../dist/eme-encryption-scheme-polyfill.js"></script>
<script>EmeEncryptionSchemePolyfill.install();</script>
<script>
EncryptionSchemePolyfills.install();
</script>

<!-- Load web components used in the demo. -->
<script type="module" src="https://cdn.jsdelivr.net/npm/elix@^9/define/AutoCompleteComboBox.js"></script>
Expand All @@ -39,8 +41,8 @@ <h1>EME Encryption Scheme Polyfill Demo</h1>
<h2>Test query</h2>
<div class="description">
Choose parameters like key system, encryption scheme, and media types,
then click the "run" button to see the results of the query with the
polyfill.
then click one of the "run" button to see the results of the query with
the polyfill.
</div>

<div>
Expand Down Expand Up @@ -85,15 +87,15 @@ <h2>Test query</h2>
</div>

<div>
<button id="emeRun">Run</button>
<button id="emeRun">Run EME query</button>
<button id="mcRun">Run MC query</button>
</div>

<div>
<label for="results">Results:</label>
<div id="results"></div>
</div>


<div class="divider"></div>


Expand Down
4 changes: 2 additions & 2 deletions demo/load-tests/load-as-es-module.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<script type="module" src="../../dist/eme-encryption-scheme-polyfill.js"></script>
<script>
function testLoader() {
return typeof EmeEncryptionSchemePolyfill != 'undefined' &&
checkDefinition(EmeEncryptionSchemePolyfill);
return typeof EncryptionSchemePolyfills != 'undefined' &&
checkDefinition(EncryptionSchemePolyfills);
}
</script>
<script src="test-load.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions demo/load-tests/load-raw-source-with-script-tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<script src="../../index.js"></script>
<script>
function testLoader() {
return typeof EmeEncryptionSchemePolyfill != 'undefined' &&
checkDefinition(EmeEncryptionSchemePolyfill);
return typeof EncryptionSchemePolyfills != 'undefined' &&
checkDefinition(EncryptionSchemePolyfills);
}
</script>
<script src="test-load.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions demo/load-tests/load-with-script-tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<script src="../../dist/eme-encryption-scheme-polyfill.js"></script>
<script>
function testLoader() {
return typeof EmeEncryptionSchemePolyfill != 'undefined' &&
checkDefinition(EmeEncryptionSchemePolyfill);
return typeof EncryptionSchemePolyfills != 'undefined' &&
checkDefinition(EncryptionSchemePolyfills);
}
</script>
<script src="test-load.js"></script>
Expand Down
Loading

0 comments on commit 08d18a2

Please sign in to comment.