Skip to content

Commit

Permalink
Add an option for default clock sync URI
Browse files Browse the repository at this point in the history
Applications which cannot control their manifests may need to specify
a default clock sync URI for use when UTCTiming elements are missing.

Closes #290

Change-Id: I5704b25d2d3199ceb932f8102490a9b3e8a27dac
  • Loading branch information
joeyparrish committed May 4, 2016
1 parent 2e19ebe commit 0a3d6bd
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 8 deletions.
2 changes: 2 additions & 0 deletions demo/asset_section.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ shakaDemo.load = function() {

var config = /** @type {shakaExtern.PlayerConfiguration} */(
{ abr: {}, drm: {}, manifest: { dash: {} } });
config.manifest.dash.clockSyncUri =
'//shaka-player-demo.appspot.com/time.txt';

if (!asset) {
// Use the custom fields.
Expand Down
7 changes: 6 additions & 1 deletion externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,18 @@ shakaExtern.DrmConfiguration;

/**
* @typedef {{
* customScheme: shakaExtern.DashContentProtectionCallback
* customScheme: shakaExtern.DashContentProtectionCallback,
* clockSyncUri: string
* }}
*
* @property {shakaExtern.DashContentProtectionCallback} customScheme
* If given, invoked by a DASH manifest parser to interpret custom or
* non-standard DRM schemes found in the manifest. The argument is a
* ContentProtection node. Return null if not recognized.
* @property {string} clockSyncUri
* A default clock sync URI to be used with live streams which do not
* contain any clock sync information. The "Date" header from this URI
* will be used to determine the current time.
*
* @exportDoc
*/
Expand Down
23 changes: 20 additions & 3 deletions lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1064,10 +1064,27 @@ shaka.dash.DashParser.prototype.requestForTiming_ = function(uri, method) {
* @private
*/
shaka.dash.DashParser.prototype.parseUtcTiming_ = function(elems, isLive) {
var schemesAndValues = elems.map(function(elem) {
return {
scheme: elem.getAttribute('schemeIdUri'),
value: elem.getAttribute('value')
};
});

// If there's nothing specified in the manifest, but we have a default from
// the config, use that.
var clockSyncUri = this.config_.dash.clockSyncUri;
if (isLive && !schemesAndValues.length && clockSyncUri) {
schemesAndValues.push({
scheme: 'urn:mpeg:dash:utc:http-head:2014',
value: clockSyncUri
});
}

var Functional = shaka.util.Functional;
return Functional.createFallbackPromiseChain(elems, function(elem) {
var scheme = elem.getAttribute('schemeIdUri');
var value = elem.getAttribute('value');
return Functional.createFallbackPromiseChain(schemesAndValues, function(sv) {
var scheme = sv.scheme;
var value = sv.value;
switch (scheme) {
// See DASH IOP Guidelines Section 4.7
// http://goo.gl/CQFNJT
Expand Down
3 changes: 2 additions & 1 deletion lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,8 @@ shaka.Player.prototype.defaultConfig_ = function() {
// in mergeConfigObjects_().
// TODO: Find a better solution if possible.
if (node) return null;
}
},
clockSyncUri: ''
}
},
streaming: {
Expand Down
2 changes: 1 addition & 1 deletion test/dash_parser_content_protection_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('DashParser.ContentProtection', function() {
var callback = opt_callback || function(node) { return null; };
dashParser.configure({
retryParameters: retry,
dash: { customScheme: callback }
dash: { clockSyncUri: '', customScheme: callback }
});
dashParser.start('http://example.com', netEngine, filterPeriod, fail)
.then(function(actual) { expect(actual).toEqual(expected); })
Expand Down
2 changes: 1 addition & 1 deletion test/dash_parser_live_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('DashParser.Live', function() {
parser = new shaka.dash.DashParser();
parser.configure({
retryParameters: retry,
dash: { customScheme: function(node) { return null; } }
dash: { clockSyncUri: '', customScheme: function(node) { return null; } }
});
});

Expand Down
2 changes: 2 additions & 0 deletions test/player_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ describe('Player', function() {

var config = { abr: {}, drm: {}, manifest: { dash: {} } };
config.abr.enabled = false;
config.manifest.dash.clockSyncUri =
'//shaka-player-demo.appspot.com/time.txt';
if (asset.licenseServers)
config.drm.servers = asset.licenseServers;
if (asset.drmCallback)
Expand Down
5 changes: 4 additions & 1 deletion test/util/dash_parser_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ shaka.test.Dash.makeDashParser = function() {
var parser = new shaka.dash.DashParser();
parser.configure({
retryParameters: retry,
dash: { customScheme: function(node) { return null; } }
dash: {
customScheme: function(node) { return null; },
clockSyncUri: ''
}
});
return parser;
};
Expand Down

0 comments on commit 0a3d6bd

Please sign in to comment.