Skip to content

Commit

Permalink
Made ManifestParser.PlayerInterface.filter async.
Browse files Browse the repository at this point in the history
This is a change in preparation for the adoption of the
MediaCapabilities API.

Related to #1391

Change-Id: If0988aedafe15aa3be794fb977fd8e04e91ca10e
  • Loading branch information
theodab committed Jun 5, 2020
1 parent 39090df commit 8d65714
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions build/misspellings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@
r'(?i)wether': 'whether',
r'(?i)@returns': '@return',
r'(?i)varint': 'variant',
r'(?i)asynchronus': 'asynchronous',
}
4 changes: 3 additions & 1 deletion docs/tutorials/upgrade-manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Instead of `filterNewPeriod` and `filterAllPeriods`, there is now a single
callback: {@link shaka.extern.ManifestParser.PlayerInterface#filter}. This
should be invoked any time new text streams or variants are added to the
manifest. `ManifestParser` plugins MUST be updated to use the new callback.
Keep in mind that the new `filter` method is asynchronous, and thus it should
probably be used in conjunction with `.then()` or `await`.

```js
// v2.5:
Expand All @@ -59,7 +61,7 @@ this.playerInterface_.filterNewPeriod(someNewPeriod);

// v3.0:
// Call this after the initial parsing or after any new streams are added
this.playerInterface_.filter(manifest);
await this.playerInterface_.filter(manifest);
```


Expand Down
6 changes: 3 additions & 3 deletions externs/shaka/manifest_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ shaka.extern.ManifestParser = class {
/**
* @typedef {{
* networkingEngine: !shaka.net.NetworkingEngine,
* filter: function(shaka.extern.Manifest),
* filter: function(shaka.extern.Manifest):!Promise,
* onTimelineRegionAdded: function(shaka.extern.TimelineRegionInfo),
* onEvent: function(!Event),
* onError: function(!shaka.util.Error)
Expand All @@ -113,9 +113,9 @@ shaka.extern.ManifestParser = class {
*
* @property {!shaka.net.NetworkingEngine} networkingEngine
* The networking engine to use for network requests.
* @property {function(shaka.extern.Manifest)} filter
* @property {function(shaka.extern.Manifest):!Promise} filter
* Should be called when new variants or text streams are added to the
* Manifest.
* Manifest. Note that this operation is asynchronous.
* @property {function(shaka.extern.TimelineRegionInfo)} onTimelineRegionAdded
* Should be called when a new timeline region is added.
* @property {function(!Event)} onEvent
Expand Down
2 changes: 1 addition & 1 deletion lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ shaka.dash.DashParser = class {
}

goog.asserts.assert(this.manifest_, 'Manifest should exist by now!');
this.playerInterface_.filter(this.manifest_);
await this.playerInterface_.filter(this.manifest_);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ shaka.hls.HlsParser = class {
offlineSessionIds: [],
minBufferTime: 0,
};
this.playerInterface_.filter(this.manifest_);
await this.playerInterface_.filter(this.manifest_);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/offline/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ shaka.offline.Storage = class {

// Don't bother filtering now. We will do that later when we have all the
// information we need to filter.
filter: () => {},
filter: () => Promise.resolve(),

onTimelineRegionAdded: () => {},
onEvent: () => {},
Expand Down
5 changes: 4 additions & 1 deletion lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1559,9 +1559,11 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
}
});

// TODO (#1391): Once filterManifest_ is async, remove this eslint disable.
/* eslint-disable require-await */
const playerInterface = {
networkingEngine: networkingEngine,
filter: (manifest) => this.filterManifest_(manifest),
filter: async (manifest) => this.filterManifest_(manifest),

// Called when the parser finds a timeline region. This can be called
// before we start playback or during playback (live/in-progress
Expand All @@ -1571,6 +1573,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
onEvent: (event) => this.dispatchEvent(event),
onError: (error) => this.onError_(error),
};
/* eslint-enable require-await */

const startTime = Date.now() / 1000;

Expand Down
2 changes: 1 addition & 1 deletion test/dash/dash_parser_content_protection_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('DashParser ContentProtection', () => {

const playerInterface = {
networkingEngine: netEngine,
filter: (manifest) => {},
filter: (manifest) => Promise.resolve(),
onTimelineRegionAdded: fail, // Should not have any EventStream elements.
onEvent: fail,
onError: fail,
Expand Down
2 changes: 1 addition & 1 deletion test/dash/dash_parser_live_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('DashParser Live', () => {
parser.configure(shaka.util.PlayerConfiguration.createDefault().manifest);
playerInterface = {
networkingEngine: fakeNetEngine,
filter: (manifest) => {},
filter: (manifest) => Promise.resolve(),
onTimelineRegionAdded: fail, // Should not have any EventStream elements.
onEvent: fail,
onError: fail,
Expand Down
2 changes: 1 addition & 1 deletion test/dash/dash_parser_manifest_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('DashParser Manifest', () => {
onEventSpy = jasmine.createSpy('onEvent');
playerInterface = {
networkingEngine: fakeNetEngine,
filter: (manifest) => {},
filter: (manifest) => Promise.resolve(),
onTimelineRegionAdded: fail, // Should not have any EventStream elements.
onEvent: shaka.test.Util.spyFunc(onEventSpy),
onError: fail,
Expand Down
2 changes: 1 addition & 1 deletion test/dash/dash_parser_segment_base_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('DashParser SegmentBase', () => {

playerInterface = {
networkingEngine: fakeNetEngine,
filter: (manifest) => {},
filter: (manifest) => Promise.resolve(),
onTimelineRegionAdded: fail, // Should not have any EventStream elements.
onEvent: fail,
onError: fail,
Expand Down
2 changes: 1 addition & 1 deletion test/dash/dash_parser_segment_template_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('DashParser SegmentTemplate', () => {

playerInterface = {
networkingEngine: fakeNetEngine,
filter: (manifest) => {},
filter: (manifest) => Promise.resolve(),
onTimelineRegionAdded: fail, // Should not have any EventStream elements.
onEvent: fail,
onError: fail,
Expand Down
2 changes: 1 addition & 1 deletion test/hls/hls_live_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('HlsParser live', () => {

config = shaka.util.PlayerConfiguration.createDefault().manifest;
playerInterface = {
filter: () => {},
filter: () => Promise.resolve(),
networkingEngine: fakeNetEngine,
onError: fail,
onEvent: fail,
Expand Down
2 changes: 1 addition & 1 deletion test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('HlsParser', () => {

config = shaka.util.PlayerConfiguration.createDefault().manifest;
playerInterface = {
filter: () => {},
filter: () => Promise.resolve(),
networkingEngine: fakeNetEngine,
onError: fail,
onEvent: fail,
Expand Down

0 comments on commit 8d65714

Please sign in to comment.