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: checkBuffer_/fillBuffer_/generateSegmentInfo #1097

Merged
merged 18 commits into from
Apr 26, 2021

Conversation

brandonocasey
Copy link
Contributor

Refactor segment selection logic into (mostly) one place.

@codecov
Copy link

codecov bot commented Mar 12, 2021

Codecov Report

Merging #1097 (a4c9a0f) into main (92f1333) will increase coverage by 0.11%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1097      +/-   ##
==========================================
+ Coverage   86.40%   86.52%   +0.11%     
==========================================
  Files          39       39              
  Lines        9631     9637       +6     
  Branches     2177     2182       +5     
==========================================
+ Hits         8322     8338      +16     
+ Misses       1309     1299      -10     
Impacted Files Coverage Δ
src/ranges.js 99.27% <100.00%> (+0.02%) ⬆️
src/segment-loader.js 95.81% <100.00%> (+0.47%) ⬆️
src/vtt-segment-loader.js 81.00% <100.00%> (+1.00%) ⬆️
src/source-updater.js 95.48% <0.00%> (+1.29%) ⬆️

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 92f1333...a4c9a0f. Read the comment docs.

Copy link
Member

@gkatsev gkatsev left a comment

Choose a reason for hiding this comment

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

Looks like there's a merge conflict.
Most of my comments are around code coverage being missing. We should try and add tests if we can, if it's complicated to test a line, we can discuss it. It's definitely ok not to appease the code coverage just because if it's going to be a lot of work.


if (buffered.length) {
lastBufferedEnd = buffered.end(buffered.length - 1);
getSyncSegmentCandidate_(playlist) {
Copy link
Member

Choose a reason for hiding this comment

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

I think it's worth looking and seeing whether we can/should add tests for the two items that codecov says aren't covered by tests. If they can never be hit, maybe just remove those lines.
The case of currentTimeline_ === -1 and the default case.

// 2. end of stream has been called on the media source already
// 3. the player is not seeking
if (next.mediaIndex >= (segments.length - 1) && ended && !this.seeking_()) {
return null;
Copy link
Member

Choose a reason for hiding this comment

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

Another place it's worth adding a test for

Comment on lines +1476 to +1495
const audioBufferedEnd = lastBufferedEnd(this.sourceUpdater_.audioBuffered());

if (typeof audioBufferedEnd === 'number') {
Copy link
Member

Choose a reason for hiding this comment

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

why did the logic for this part change?

Copy link
Member

Choose a reason for hiding this comment

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

ah, I see. lastBufferedEnd already does a null check and so if we don't get a number from it, we don't have audio buffered but if we do we can just use that value directly in the next step.

segmentInfo.isSyncRequest
);
// stop at the last possible segmentInfo
if (segmentInfo.mediaIndex + 1 >= segmentInfo.playlist.segments.length) {
Copy link
Member

Choose a reason for hiding this comment

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

Looks like codecov is saying both these changes aren't covered by tests? Do we have any tests for this piece?

Base automatically changed from feat/llhls-2 to main April 5, 2021 16:17
@brandonocasey brandonocasey force-pushed the refactor/choose-next-request branch from 6f3ef44 to 5ae7b43 Compare April 5, 2021 21:08
const buffered = this.buffered_();

if (typeof segmentInfo.timestampOffset === 'number') {
// The timestamp offset needs to be regenerated, as the buffer most likely
Copy link
Contributor Author

Choose a reason for hiding this comment

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

generateSegmentInfo, already did all of this.


// regenerate the audioAppendStart, timestampOffset, etc as they
// may have changed since this function was added to the queue.
this.isPendingTimestampOffset_ = true;
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 a specific reason for adding this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to force timestampoffset to regenerate in generateSegmentInfo.

Copy link
Contributor

Choose a reason for hiding this comment

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

It feels a bit strange to set the property here and then clear it as a side effect of generateSegmentInfo (we definitely had side effects before, but in the interest of keeping the new function as side effect free as possible). I wonder if it would be better to set isPendingTimestampOffset_ to false in updateTransmuxerAndRequestSegment_ and then to have another option that can be passed into generateSegmentInfo_ to regenerate relevant timing info.

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 was a bit more complicated than I thought, but I generally agreed with your points here. There were two considerations: vtt-segment-loader never wants to set timestamp offsets on generated segment info. I got around that by making a member function that vtt-segment-loader will inherit and override to return null.

Second was that whenever timestampOffset is set using the timestampOffsetForSegment function we expect to set isPendingTimestampOffset_ to false. So we will still have a small side effect no matter what we do, as our code currently expects us to do that. That being said I did add an option to force a timestamp update so that we don't have to set isPendingTimestampOffset_ where the original comment was.


// if timestampoffset was set then we no longer have a timestampoffset
if (typeof segmentInfo.timestampOffset === 'number') {
this.isPendingTimestampOffset_ = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be worth moving this out of the function too to make the function have no side effects. I think generateSegmentInfo will only be used on chooseNextRequest (as part of fillBuffer), which has a check for timestampOffset right after, and in loadSegment_ as part of the queue callback, where it was forced to update.

@brandonocasey brandonocasey merged commit b8a5aa5 into main Apr 26, 2021
@brandonocasey brandonocasey deleted the refactor/choose-next-request branch April 26, 2021 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants