Skip to content

Commit

Permalink
Add availabilityWindowOverride configuration.
Browse files Browse the repository at this point in the history
This config lets you override the availability window of a live stream.
It is in config.manifest, and passed along on start.
This will let users configure the parser so that they can seek with HLS
live streams, for example.

Closes #1177
Closes #1307

Change-Id: Icd3c1d81c6b52ebdbb72137df42fc91cd73a0207
  • Loading branch information
theodab committed Jul 16, 2018
1 parent e312c3a commit b37a450
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 0 deletions.
10 changes: 10 additions & 0 deletions demo/asset_section.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,16 @@ shakaDemo.preparePlayer_ = function(asset) {
if (!isNaN(preferredAudioChannelCount)) {
config.preferredAudioChannelCount = preferredAudioChannelCount;
}
let availabilityWindowOverrideRaw =
document.getElementById('availabilityWindowOverride').value;
let availabilityWindowOverride = Number(availabilityWindowOverrideRaw);
if (!isNaN(availabilityWindowOverride) &&
availabilityWindowOverrideRaw.length) {
// Don't configure if the field contains an empty string; this is because
// Number('') evaluates to 0, which is a valid (if fairly useless) override
// value, while we would rather it mean "don't override".
config.manifest.availabilityWindowOverride = availabilityWindowOverride;
}

config.abr.enabled =
document.getElementById('enableAdaptation').checked;
Expand Down
12 changes: 12 additions & 0 deletions demo/configuration_section.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ shakaDemo.setupConfiguration_ = function() {
'input', shakaDemo.onDrmSettingsChange_);
document.getElementById('drmSettingsAudioRobustness').addEventListener(
'input', shakaDemo.onDrmSettingsChange_);
document.getElementById('availabilityWindowOverride').addEventListener(
'input', shakaDemo.onAvailabilityWindowOverrideChange_);

let robustnessSuggestions = document.getElementById('robustnessSuggestions');
if (shakaDemo.support_.drm['com.widevine.alpha']) {
Expand Down Expand Up @@ -86,6 +88,16 @@ shakaDemo.onDrmSettingsChange_ = function(event) {
};


/**
* @param {!Event} event
* @private
*/
shakaDemo.onAvailabilityWindowOverrideChange_ = function(event) {
// Change the hash, to mirror this.
shakaDemo.hashShouldChange_();
};


/**
* @param {!Event} event
* @private
Expand Down
4 changes: 4 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ <h1>Shaka Player <span id="version"></span></h1>
<label for="drmSettingsAudioRobustness">Audio Robustness:</label>
<input id="drmSettingsAudioRobustness" type="text" class="flex-grow" list="robustnessSuggestions">
</div>
<div>
<label for="availabilityWindowOverride">Availability Window Override:</label>
<input id="availabilityWindowOverride" type="number" step="30" min="0">
</div>
<datalist id="robustnessSuggestions"></datalist>
</details>

Expand Down
9 changes: 9 additions & 0 deletions demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ shakaDemo.preBrowserCheckParams_ = function(params) {
if ('certificate' in params) {
document.getElementById('certificateInput').value = params['certificate'];
}
if ('availabilityWindowOverride' in params) {
document.getElementById('availabilityWindowOverride').value =
params['availabilityWindowOverride'];
}
if ('logtoscreen' in params) {
document.getElementById('logToScreen').checked = true;
// Call onLogChange_ manually, because setting checked
Expand Down Expand Up @@ -581,6 +585,11 @@ shakaDemo.hashShouldChange_ = function() {
if (document.getElementById('showNative').checked) {
params.push('nativecontrols');
}
let availabilityWindowOverride =
document.getElementById('availabilityWindowOverride').value;
if (availabilityWindowOverride) {
params.push('availabilityWindowOverride=' + availabilityWindowOverride);
}
if (shaka.log) {
let logLevelList = document.getElementById('logLevelList');
let logLevel = logLevelList[logLevelList.selectedIndex].value;
Expand Down
4 changes: 4 additions & 0 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,15 @@ shaka.extern.DashManifestConfiguration;
/**
* @typedef {{
* retryParameters: shaka.extern.RetryParameters,
* availabilityWindowOverride: number,
* dash: shaka.extern.DashManifestConfiguration
* }}
*
* @property {shaka.extern.RetryParameters} retryParameters
* Retry parameters for manifest requests.
* @property (number) availabilityWindowOverride
* A number, in seconds, that overrides the availability window in the
* manifest, or NaN if the default value should be used.
* @property {shaka.extern.DashManifestConfiguration} dash
* Advanced parameters used by the DASH manifest parser.
*
Expand Down
6 changes: 6 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,11 @@ shaka.Player.prototype.load = async function(

if (cancelValue) throw cancelValue;

if (!isNaN(this.config_.manifest.availabilityWindowOverride)) {
this.manifest_.presentationTimeline.setSegmentAvailabilityDuration(
this.config_.manifest.availabilityWindowOverride);
}

this.filterManifestForAVVariants_();

this.drmEngine_ = this.createDrmEngine();
Expand Down Expand Up @@ -2290,6 +2295,7 @@ shaka.Player.prototype.defaultConfig_ = function() {
},
manifest: {
retryParameters: shaka.net.NetworkingEngine.defaultRetryParameters(),
availabilityWindowOverride: NaN,
dash: {
customScheme: function(node) {
// Reference node to keep closure from removing it.
Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_content_protection_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('DashParser ContentProtection', function() {
callback = callback || function(node) { return null; };
dashParser.configure({
retryParameters: retry,
availabilityWindowOverride: NaN,
dash: {
clockSyncUri: '',
customScheme: callback,
Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_live_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('DashParser Live', function() {
parser = new shaka.dash.DashParser();
parser.configure({
retryParameters: retry,
availabilityWindowOverride: NaN,
dash: {
clockSyncUri: '',
customScheme: function(node) { return null; },
Expand Down
1 change: 1 addition & 0 deletions test/hls/hls_live_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ describe('HlsParser live', function() {
let retry = shaka.net.NetworkingEngine.defaultRetryParameters();
config = {
retryParameters: retry,
availabilityWindowOverride: NaN,
dash: {
customScheme: function(node) { return null; },
clockSyncUri: '',
Expand Down
1 change: 1 addition & 0 deletions test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ describe('HlsParser', function() {
let retry = shaka.net.NetworkingEngine.defaultRetryParameters();
config = {
retryParameters: retry,
availabilityWindowOverride: NaN,
dash: {
customScheme: function(node) { return null; },
clockSyncUri: '',
Expand Down
39 changes: 39 additions & 0 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3135,6 +3135,45 @@ describe('Player', function() {
});
});

describe('live', function() {
function availabilityWindowTest(expectedAvailabilityWindow) {
// Create a live timeline and manifest.
let timeline = new shaka.media.PresentationTimeline(300, 0);
timeline.setStatic(false);
timeline.setSegmentAvailabilityDuration(100);

manifest = new shaka.test.ManifestGenerator()
.setTimeline(timeline)
.addPeriod(0)
.addVariant(0)
.addVideo(1)
.build();

let parser = new shaka.test.FakeManifestParser(manifest);
let parserFactory = function() { return parser; };

return player.load('', /* startTime */ 0, parserFactory).then(() => {
// Availability window can be determined by finding the time difference
// between the avalability end and start. Thus, we can compare the
// expected and actual window.
let end = timeline.getSegmentAvailabilityEnd();
expect(end - timeline.getSegmentAvailabilityStart())
.toBeCloseTo(expectedAvailabilityWindow, 1);
});
}

it('uses normal availability window when not overridden', async () => {
// The availability start should be what was in the timeline (100).
await availabilityWindowTest(100);
});

it('honors availabilityWindowOverride', async () => {
player.configure({manifest: {availabilityWindowOverride: 200}});
// The availability start should be what was configured (200).
await availabilityWindowTest(200);
});
});

describe('language methods', function() {
let videoOnlyManifest;
let parserFactory = function() {
Expand Down
1 change: 1 addition & 0 deletions test/test/util/dash_parser_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ shaka.test.Dash.makeDashParser = function() {
let parser = new shaka.dash.DashParser();
parser.configure({
retryParameters: retry,
availabilityWindowOverride: NaN,
dash: {
customScheme: function(node) { return null; },
clockSyncUri: '',
Expand Down

0 comments on commit b37a450

Please sign in to comment.