Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

handle dynamic buffer sizes (4k support) #1416

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export default {
// How much of the buffer must be filled before we consider upswitching
BUFFER_LOW_WATER_LINE: 0,
MAX_BUFFER_LOW_WATER_LINE: 30,
BUFFER_LOW_WATER_LINE_RATE: 1
BUFFER_LOW_WATER_LINE_RATE: 1,
BACK_BUFFER_LENGTH: 30

Choose a reason for hiding this comment

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

does this mean we'll have a total buffer length of 60? (GOAL_BUFFER_LENGTH being the forward buffer)?

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 forward buffer scales with time, so at the beginning it would be 60 (GOAL_BUFFER_LENGTH + BACK_BUFFER_LENGTH) and after playing for a bit it would be 90 (MAX_GOAL_BUFFER_LENGTH + BACK_BUFFER_LENGTH).

The constants could probably use some renaming to make them more clear :)

Choose a reason for hiding this comment

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

hmm. Ok, curious if we should consider tweaking these values, but that's just curiosity... 🙃

Copy link
Contributor Author

@squarebracket squarebracket Jul 20, 2018

Choose a reason for hiding this comment

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

Indeed! I just used the values that were already in the code.

Choose a reason for hiding this comment

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

👍 probably fine for now

};
45 changes: 35 additions & 10 deletions src/master-playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ export class MasterPlaylistController extends videojs.EventTarget {
this.useCueTags_ = useCueTags;
this.blacklistDuration = blacklistDuration;
this.enableLowInitialPlaylist = enableLowInitialPlaylist;
this.goalBufferLength_ = Config.GOAL_BUFFER_LENGTH;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactor to use the properties on Hls (see this)

this.maxGoalBufferLength_ = Config.MAX_GOAL_BUFFER_LENGTH;
this.backBufferLength_ = Config.BACK_BUFFER_LENGTH;

if (this.useCueTags_) {
this.cueTagsTrack_ = this.tech_.addTextTrack('metadata',
Expand Down Expand Up @@ -299,7 +302,9 @@ export class MasterPlaylistController extends videojs.EventTarget {
seeking: () => this.tech_.seeking(),
duration: () => this.mediaSource.duration,
hasPlayed: () => this.hasPlayed_(),
goalBufferLength: () => this.goalBufferLength(),
goalBufferLength: this.goalBufferLength.bind(this),
maxGoalBufferLength: () => this.maxGoalBufferLength_,
backBufferLength: this.backBufferLength.bind(this),
bandwidth,
syncController: this.syncController_,
decrypter: this.decrypter_
Expand Down Expand Up @@ -584,6 +589,8 @@ export class MasterPlaylistController extends videojs.EventTarget {
if (!currentPlaylist.endList ||
// For the same reason as LIVE, we ignore the low water line when the VOD
// duration is below the max potential low water line
// TODO: This probably needs changing? Not sure what to change it to though.
// Maybe just this.bufferLowWaterLine() ?

Choose a reason for hiding this comment

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

I think this should technically remain the same as the intention was to allow rendition switching on shorter videos (those shorter than the max low water line). Also, we should remove this TODO since we didn't actually change the value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I guess since the bufferLowWaterLine is never used for media that's shorter than the max, a smaller water line due to a QuotaExceededError would be irrelevant.

Choose a reason for hiding this comment

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

Yep, exactly

this.duration() < Config.MAX_BUFFER_LOW_WATER_LINE ||
// we want to switch down to lower resolutions quickly to continue playback, but
nextPlaylist.attributes.BANDWIDTH < currentPlaylist.attributes.BANDWIDTH ||
Expand Down Expand Up @@ -1235,17 +1242,35 @@ export class MasterPlaylistController extends videojs.EventTarget {
}

/**
* Calculates the desired forward buffer length based on current time
* Calculates or sets the desired forward buffer length based on current time
*
* @return {Number} Desired forward buffer length in seconds
* @param {Number=} Desired forward buffer length in seconds

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

* @return {Number} Current forward buffer target length
*/
goalBufferLength() {
const currentTime = this.tech_.currentTime();
const initial = Config.GOAL_BUFFER_LENGTH;
const rate = Config.GOAL_BUFFER_LENGTH_RATE;
const max = Math.max(initial, Config.MAX_GOAL_BUFFER_LENGTH);
goalBufferLength(value) {
if (value === undefined) {
const currentTime = this.tech_.currentTime();
const initial = this.goalBufferLength_;
const rate = Config.GOAL_BUFFER_LENGTH_RATE;
const max = Math.max(initial, this.maxGoalBufferLength_);

return Math.min(initial + currentTime * rate, max);
}
this.goalBufferLength_ = Math.min(this.goalBufferLength_, value);

This comment was marked as resolved.

This comment was marked as resolved.

this.maxGoalBufferLength_ = Math.min(this.maxGoalBufferLength_, value);

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as outdated.

}

return Math.min(initial + currentTime * rate, max);
/**
* Set or return the back buffer length
*
* @param {Number=} Desired back buffer length in seconds
* @return {Number} Current back buffer target length
*/
backBufferLength(value) {
if (value === undefined) {
return this.backBufferLength_;
}
this.backBufferLength_ = Math.min(this.backBufferLength_, value);

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

Copy link
Contributor Author

@squarebracket squarebracket Jul 25, 2018

Choose a reason for hiding this comment

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

Even if another part of the code tries to make the buffers larger, the Math.min will prevent it. This is what should be happening. While it's true that you'd expect an actual setter to always set the value, this is not an actual property setter.

If your argument is semantic -- that a thing that looks and sounds like a setter should behave like a setter -- then I understand where you're coming from. They could, I suppose, be split into functions like getGoalBufferLength and safelySetGoalBufferLength (or better named versions) to break the semantic paradigm, if you think that would avoid any confusion. However, I don't think changing the actual underlying behaviour would be beneficial -- that safety is important for proper functioning.

Choose a reason for hiding this comment

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

I believe that only goalBufferLength() already exists in master and backBufferLength() is new in this PR, right? If so, then we could probably rename backBufferLength() to be closer to its purpose?

}

/**
Expand All @@ -1259,6 +1284,6 @@ export class MasterPlaylistController extends videojs.EventTarget {
const rate = Config.BUFFER_LOW_WATER_LINE_RATE;
const max = Math.max(initial, Config.MAX_BUFFER_LOW_WATER_LINE);

return Math.min(initial + currentTime * rate, max);
return Math.min(initial + currentTime * rate, max, this.goalBufferLength());

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as outdated.

This comment was marked as resolved.

}
}
Loading