Skip to content

Commit

Permalink
Add support-testing framework.
Browse files Browse the repository at this point in the history
Support testing is hierarchical.  Player.support returns an object
mapping out the support present in various parts of the system.

This creates a shell for Player and DrmEngine, and introduces support
tests for MediaSourceEngine, ManifestParser, and DrmEngine.

This also adjusts the way support checks are done for text types, to
allow for expansion into MP4-embedded text types and other segmented
subtitle types.

Text changes related to #150 and #146

Change-Id: I707f01ba52cba6262ee89bee2c1f28d24aca4655
  • Loading branch information
joeyparrish committed Dec 10, 2015
1 parent 3e7014d commit c9235f8
Show file tree
Hide file tree
Showing 8 changed files with 403 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build/checkversion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ NPM_VERSION=$(
cut -f 2 -d : | sed -e 's/.*"\(.*\)".*/\1/'
)
PLAYER_VERSION=$(
grep GIT_VERSION "$dir"/lib/player/player.js | grep goog.define |
grep GIT_VERSION "$dir"/lib/player.js | grep goog.define |
cut -f 2 -d , | sed -e "s/.*'\\(.*\\)'.*/\\1/"
)
CHANGELOG_VERSION=$(
Expand Down
88 changes: 88 additions & 0 deletions lib/media/drm_engine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* @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.
*/

goog.provide('shaka.media.DrmEngine');

goog.require('shaka.asserts');
goog.require('shaka.log');
goog.require('shaka.media.Manifest');
goog.require('shaka.util.IDestroyable');



/**
* @constructor
* @struct
* @implements {shaka.util.IDestroyable}
*/
shaka.media.DrmEngine = function() {
// TODO
};


/**
* @override
*/
shaka.media.DrmEngine.prototype.destroy = function() {
// TODO
};


/**
* Returns a Promise to map of EME support for well-known key systems.
*
* @return {!Promise.<!Object.<string, boolean>>}
*/
shaka.media.DrmEngine.support = function() {
// Every object in the support hierarchy has a "basic" member.
// All "basic" members must be true for the library to be usable.
var basic =
!!window.MediaKeys &&
!!window.navigator &&
!!window.navigator.requestMediaKeySystemAccess &&
!!window.MediaKeySystemAccess &&
!!window.MediaKeySystemAccess.prototype.getConfiguration;

var support = {'basic': basic};

var tests = [];
if (support['basic']) {
var testKeySystems = [
'org.w3.clearkey',
'com.widevine.alpha',
'com.microsoft.playready',
'com.apple.fps.2_0',
'com.apple.fps.1_0',
'com.apple.fps',
'com.adobe.primetime'
];

testKeySystems.forEach(function(keySystem) {
var p = navigator.requestMediaKeySystemAccess(keySystem, [{}])
.then(function() {
support[keySystem] = true;
}, function() {
support[keySystem] = false;
});
tests.push(p);
});
}

return Promise.all(tests).then(function() {
return support;
});
};
49 changes: 49 additions & 0 deletions lib/media/manifest_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,55 @@ shaka.media.ManifestParser.registerParserByMime = function(
};


/**
* Returns a map of manifest support for well-known types.
*
* @return {!Object.<string, boolean>}
*/
shaka.media.ManifestParser.support = function() {
// Every object in the support hierarchy has a "basic" member.
// All "basic" members must be true for the library to be usable.
var support = {'basic': true};

// Make sure all registered parsers are shown.
for (var type in shaka.media.ManifestParser.parsersByMime) {
support[type] = true;
}
for (var type in shaka.media.ManifestParser.parsersByExtension) {
support[type] = true;
}

// Make sure all well-known types are tested as well, just to show an explicit
// false for things people might be expecting.
var testMimeTypes = [
// DASH
'application/dash+xml',
// HLS
'application/x-mpegurl',
'application/vnd.apple.mpegurl',
// SmoothStreaming
'application/vnd.ms-sstr+xml'
];
var testExtensions = [
// DASH
'mpd',
// HLS
'm3u8',
// SmoothStreaming
'ism'
];

testMimeTypes.forEach(function(type) {
support[type] = !!shaka.media.ManifestParser.parsersByMime[type];
});
testExtensions.forEach(function(type) {
support[type] = !!shaka.media.ManifestParser.parsersByExtension[type];
});

return support;
};


/**
* Parses the given manifest data into a Manifest object and starts any
* background timers that are needed. This will only be called once.
Expand Down
47 changes: 43 additions & 4 deletions lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,50 @@ shaka.media.MediaSourceEngine.Operation;
* @return {boolean}
*/
shaka.media.MediaSourceEngine.isTypeSupported = function(mimeType) {
var contentType = mimeType.split('/')[0];
if (contentType == 'text') {
return shaka.media.TextSourceBuffer.isTypeSupported(mimeType);
return shaka.media.TextSourceBuffer.isTypeSupported(mimeType) ||
MediaSource.isTypeSupported(mimeType);
};


/**
* Returns a map of MediaSource support for well-known types.
*
* @return {!Object.<string, boolean>}
*/
shaka.media.MediaSourceEngine.support = function() {
// Every object in the support hierarchy has a "basic" member.
// All "basic" members must be true for the library to be usable.
var support = {'basic': !!window.MediaSource};

if (support['basic']) {
var testMimeTypes = [
// MP4 types
'video/mp4; codecs="avc1.42E01E"',
'audio/mp4; codecs="mp4a.40.2"',
// WebM types
'video/webm; codecs="vp8"',
'video/webm; codecs="vp9"',
'audio/webm; codecs="vorbis"',
'audio/webm; codecs="opus"',
// MPEG2 TS types (video/ is also used for audio: http://goo.gl/tYHXiS)
'video/mp2t; codecs="avc1.42E01E"',
'video/mp2t; codecs="mp4a.40.2"',
// WebVTT types
'text/vtt',
'application/mp4; codecs="wvtt"',
// TTML types
'application/ttml+xml',
'application/mp4; codecs="stpp"'
];

testMimeTypes.forEach(function(type) {
support[type] = shaka.media.MediaSourceEngine.isTypeSupported(type);
var basicType = type.split(';')[0];
support[basicType] = support[basicType] || support[type];
});
}
return MediaSource.isTypeSupported(mimeType);

return support;
};


Expand Down
19 changes: 8 additions & 11 deletions lib/media/text_source_buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ goog.require('shaka.util.PublicPromise');
shaka.media.TextSourceBuffer = function(track, mimeType) {
shaka.util.FakeEventTarget.call(this, null);

var basicMimeType = mimeType.split(';')[0];

/** @private {shaka.media.TextSourceBuffer.TextParser} */
this.parser_ = shaka.media.TextSourceBuffer.parserMap_[basicMimeType];
this.parser_ = shaka.media.TextSourceBuffer.parserMap_[mimeType];

// A more accurate work-alike would throw NotSupportedError here, but this
// should not happen if type-negotiation is working as it should.
Expand Down Expand Up @@ -89,21 +87,21 @@ shaka.media.TextSourceBuffer.parserMap_ = {};


/**
* @param {string} basicMimeType
* @param {string} mimeType
* @param {!shaka.media.TextSourceBuffer.TextParser} parser
* @export
*/
shaka.media.TextSourceBuffer.registerParser = function(basicMimeType, parser) {
shaka.media.TextSourceBuffer.parserMap_[basicMimeType] = parser;
shaka.media.TextSourceBuffer.registerParser = function(mimeType, parser) {
shaka.media.TextSourceBuffer.parserMap_[mimeType] = parser;
};


/**
* @param {string} basicMimeType
* @param {string} mimeType
* @export
*/
shaka.media.TextSourceBuffer.unregisterParser = function(basicMimeType) {
delete shaka.media.TextSourceBuffer.parserMap_[basicMimeType];
shaka.media.TextSourceBuffer.unregisterParser = function(mimeType) {
delete shaka.media.TextSourceBuffer.parserMap_[mimeType];
};


Expand All @@ -112,8 +110,7 @@ shaka.media.TextSourceBuffer.unregisterParser = function(basicMimeType) {
* @return {boolean}
*/
shaka.media.TextSourceBuffer.isTypeSupported = function(mimeType) {
var basicMimeType = mimeType.split(';')[0];
return !!shaka.media.TextSourceBuffer.parserMap_[basicMimeType];
return !!shaka.media.TextSourceBuffer.parserMap_[mimeType];
};


Expand Down
100 changes: 100 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* @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.
*/

goog.provide('shaka.Player');

goog.require('shaka.media.DrmEngine');
goog.require('shaka.media.ManifestParser');
goog.require('shaka.media.MediaSourceEngine');
goog.require('shaka.util.IDestroyable');



/**
* @constructor
* @struct
* @implements {shaka.util.IDestroyable}
* @export
*/
shaka.Player = function() {
// TODO
};


/**
* @override
*/
shaka.Player.prototype.destroy = function() {
// TODO
};


/**
* @define {string} A version number taken from git at compile time.
*/
goog.define('GIT_VERSION', 'v1.9.9-alpha-debug');


/**
* @const {string}
* @export
*/
shaka.Player.version = GIT_VERSION;


/**
* @typedef {{
* manifest: (!Object.<string, boolean>|undefined),
* media: (!Object.<string, boolean>|undefined),
* drm: (!Object.<string, boolean>|undefined),
* supported: boolean
* }}
* @exportDoc
*/
shaka.Player.SupportType;


/**
* @return {!Promise.<!shaka.Player.SupportType>}
* @export
*/
shaka.Player.support = function() {
// Basic features needed for the library to be usable.
var basic = !!window.Promise && !!window.Uint8Array &&
!!Array.prototype.forEach;

if (basic) {
var manifest = shaka.media.ManifestParser.support();
var media = shaka.media.MediaSourceEngine.support();
return shaka.media.DrmEngine.support().then(function(drm) {
return {
'manifest': manifest,
'media': media,
'drm': drm,
'supported': manifest['basic'] && media['basic'] && drm['basic']
};
});
} else {
// Return something Promise-like so that the application can still check
// for support.
return /** @type {!Promise.<!shaka.Player.SupportType>} */({
'then': function(fn) {
fn({'supported': false});
}
});
}
};
34 changes: 34 additions & 0 deletions shaka-player.uncompiled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @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.
*/

// Require all exported classes.
goog.require('shaka.Player');
goog.require('shaka.media.ManifestParser');
goog.require('shaka.media.PresentationTimeline');
goog.require('shaka.media.TextSourceBuffer');
goog.require('shaka.polyfill.installAll');
goog.require('shaka.util.Error');
goog.require('shaka.util.StringUtils');
goog.require('shaka.util.Uint8ArrayUtils');

// Require logging.
goog.require('shaka.log');

// Require standard plugins.
goog.require('shaka.media.VttTextParser');
goog.require('shaka.net.DataUriPlugin');
goog.require('shaka.net.HttpPlugin');
Loading

0 comments on commit c9235f8

Please sign in to comment.