Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Create PlaylistLoader classes that share more code and do less #1208

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

brandonocasey
Copy link
Contributor

Description

A cleaner playlist loader refactor that is in the works

@codecov
Copy link

codecov bot commented Sep 23, 2021

Codecov Report

Merging #1208 (c258254) into main (25c33ca) will increase coverage by 0.54%.
The diff coverage is 98.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1208      +/-   ##
==========================================
+ Coverage   86.42%   86.97%   +0.54%     
==========================================
  Files          39       46       +7     
  Lines        9743    10177     +434     
  Branches     2263     2373     +110     
==========================================
+ Hits         8420     8851     +431     
- Misses       1323     1326       +3     
Impacted Files Coverage Δ
src/playlist-loader/dash-media-playlist-loader.js 93.97% <93.97%> (ø)
src/playlist-loader/utils.js 99.22% <99.22%> (ø)
src/playlist-loader/dash-main-playlist-loader.js 100.00% <100.00%> (ø)
src/playlist-loader/hls-main-playlist-loader.js 100.00% <100.00%> (ø)
src/playlist-loader/hls-media-playlist-loader.js 100.00% <100.00%> (ø)
src/playlist-loader/playlist-loader.js 100.00% <100.00%> (ø)
src/util/deep-equal.js 100.00% <100.00%> (ø)
src/util/container-request.js 91.42% <0.00%> (+8.57%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 25c33ca...c258254. Read the comment docs.

@brandonocasey brandonocasey changed the title WIP: first draft refactor for hls and dash playlist loaders feat: Create PlaylistLoader classes that share more code and do less Nov 2, 2021
*
* @extends PlaylistLoader
*/
class DashMainPlaylistLoader extends PlaylistLoader {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class deals with getting the sever clock offset and merging the old main manifest into the new one.

parseManifest_(manifestString, callback) {
this.syncClientServerClock_(manifestString, (clientOffset) => {
const parsedManifest = parseMpd(manifestString, {
manifestUri: this.uri_,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that sidxMapping is not done her at all. Instead each individual DashMediaPlaylistLoader handles all of that logic on it's own.

});

// merge everything except for playlists, they will merge themselves
const mergeResult = mergeManifest(this.manifest_, parsedManifest, ['playlists', 'mediaGroups']);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not also that we do not merge the playlists or mediaGroups here, which means only the new unmerged playlists will exist after this point. We do this because each individual DashMediaPlaylistLoader merges it's own playlist (if the playlist loader is started).

const mergeResult = mergeManifest(this.manifest_, parsedManifest, ['playlists', 'mediaGroups']);

// always trigger updated, as playlists will have to update themselves
callback(mergeResult.manifest, true);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We always report updated here as we want DashMediaPlaylistLoaders to be the ones that check for stale playlist updates. The DashMainPlaylistLoader will hardly ever change substantially.

// MPD has no future validity, so a new one will need to be acquired when new
// media segments are to be made available. Thus, we use the target duration
// in this case
// TODO: can we do this in a better way? It would be much better
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anyone has a better idea for this it would make the separation between DashMediaPlaylistLoader and DashMainPlaylistLoader much more complete. It would also prevent the scenario that we currently have where an audio playlist target duration could take precedence over a video playlist.


// noop, as media playlists in dash do not have
// a uri to refresh or a manifest string
refreshManifest_() {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since dash media playlists don't refresh, parse, or have a manifest string we noop all of these.

*
* @extends PlaylistLoader
*/
class DashMediaPlaylistLoader extends PlaylistLoader {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class deals:

  1. finding it's playlist whenever DashMainPlaylistLoader triggers updated
  2. Requesting sidx and adding sidx segments
  3. Setting the media refresh time on DashMainPlaylistLoader so that it can refresh using target duration.

* @listens {PlaylistLoader#updated}
* @private
*/
refreshManifest_() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main function of most playlist loaders, called when started or when updated is triggered on itself.

* @listens {DashMainPlaylistLoader#updated}
* @private
*/
onMainUpdated_() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main function for this file. It finds the playlist this loader is associated with. Adds sidx segments (if needed) and merges with it's reference of it's old playlist.

*
* @private
*/
makeRequest_(options, callback) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A generic request function with shared error handling. This allows stop to cancel any pending request.

* @private
*/
setMediaRefreshTimeout_() {
// do nothing if disposed
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loops media refresh timeout while getMediaRefreshTime is a valid number. called when this playlist loader triggers updated.

@stale
Copy link

stale bot commented Jan 8, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the outdated label Jan 8, 2022
@gesinger gesinger removed the outdated label Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants