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

refactor: unify sidx/master/error request logic #998

Merged
merged 2 commits into from
Nov 23, 2020

Conversation

brandonocasey
Copy link
Contributor

@brandonocasey brandonocasey commented Nov 16, 2020

Description

Third and final dash-playlist-loader refactor.
Based on #994

Specific Changes proposed

  • Merge all master playlist loader request logic into requestMaster_
  • Merge all sidx logic into addSidxSegments_
  • Merge all error logic into requestErrored_

@@ -295,6 +243,111 @@ export default class DashPlaylistLoader extends EventTarget {
}
}

requestErrored_(err, request, startingState) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

triggers a request error if it finds an error and returns true if there was an error so request functions can exit early. We used this logic in many places in the original code and we use it in two places now.

* Verify that the container of the sidx segment can be parsed
* and if it can, get and parse that segment.
*/
addSidxSegments_(playlist, startingState, cb) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of the logic from sidxRequestFinished and requestSidx merged into one because they were really doing the same things anyway. I also added some extra logic here for things that we were doing in 3+ places outside of this function, but might as well have shared.

const uri = resolveManifestRedirect(this.handleManifestRedirects, playlist.sidx.resolvedUri);
const sidxMapping = this.masterPlaylistLoader_.sidxMapping_;

sidxMapping[sidxKey] = {
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 an addition, every function that requests sidx must also update the sidx mapping.


const sidx = parseSidx(toUint8(request.response).subarray(8));

sidxMapping[sidxKey].sidx = sidx;
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 line and the line below were previously done after the sidx request, but it just didn't make sense to do it everywhere we call this function. We will always want to add sidx segments to the playlist that we request sidx for, and we will always update our sidx mapping cache.

});
})
);
this.addSidxSegments_(playlist, startingState, (sidxChanged) => {
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 this function now calls back for playlists that don't have sidx segments, we don't have to separate the logic.


this.addSidxSegments_(this.media(), this.state, (sidxChanged) => {
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 don't have to check this.media() has sidx as addSidxSegments_ will do that now, and the callback will be called.

@gkatsev gkatsev added this to the 2.4 milestone Nov 17, 2020
@brandonocasey brandonocasey force-pushed the refactor/3-unify-logic branch 2 times, most recently from 4b34420 to bf6b9a6 Compare November 17, 2020 20:41
// playlist lacks sidx or sidx segments were added to this playlist already.
if (!playlist.sidx || !sidxKey || this.masterPlaylistLoader_.sidxMapping_[sidxKey]) {
// keep this function async
this.mediaRequest_ = window.setTimeout(() => cb(false), 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

I was looking through the code to ensure that we cleared the mediaRequest_ for all callers, and we do, but it's in nested function calls after the callback. I wonder if it would be clearer to either null it before the callback, or to have the callbacks manage nulling mediaRequest_ after receiving the callbacks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I honestly wonder why we even need mediaRequest_. It seems to me like we only use it one place in the code to verify that a media change is pending. What if we just set pentingMedia_ in media() and removed mediaRequest?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm all for removing more things. Sounds good to me 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After making the change it causes a lot of tests to fail. Seems like we should do one more refactor pull request for this change to keep the size of the pull request down.

Copy link
Contributor

Choose a reason for hiding this comment

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

Was there any way to centralize the mediaRequest_ clearing (rather than removing it) without as many test failures?

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 really as clearing it out in a central location and switching to pendingMedia_ required similar changes, and had similar test failures.

src/dash-playlist-loader.js Outdated Show resolved Hide resolved
test/dash-playlist-loader.test.js Outdated Show resolved Hide resolved
src/dash-playlist-loader.js Outdated Show resolved Hide resolved
@brandonocasey brandonocasey changed the base branch from refactor/sidx-add-segments to main November 20, 2020 17:32
@brandonocasey brandonocasey merged commit fe57e60 into main Nov 23, 2020
evanfarina pushed a commit to evanfarina/http-streaming that referenced this pull request Nov 26, 2020
@brandonocasey brandonocasey deleted the refactor/3-unify-logic branch December 10, 2020 20:35
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.

3 participants