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: Improve live latency on load #5268

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion lib/media/playhead.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ shaka.media.MediaSourcePlayhead = class {
this.videoWrapper_ = new shaka.media.VideoWrapper(
mediaElement,
() => this.onSeeking_(),
this.getStartTime_(startTime));
() => this.getStartTime_(startTime));

/** @type {shaka.util.Timer} */
this.checkWindowTimer_ = new shaka.util.Timer(() => {
Expand Down
22 changes: 15 additions & 7 deletions lib/media/video_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,25 @@ shaka.media.VideoWrapper = class {
/**
* @param {!HTMLMediaElement} video
* @param {function()} onSeek Called when the video seeks.
* @param {number} startTime The time to start at.
* @param {function():number} getStartTime Calle to get the time to start at.
*/
constructor(video, onSeek, startTime) {
constructor(video, onSeek, getStartTime) {
/** @private {HTMLMediaElement} */
this.video_ = video;

/** @private {function()} */
this.onSeek_ = onSeek;

/** @private {number} */
this.startTime_ = startTime;
/** @private {?number} */
this.startTime_ = null;

/** @private {function():number} */
this.getStartTime_ = () => {
if (this.startTime_ == null) {
this.startTime_ = getStartTime();
}
return this.startTime_;
};

/** @private {boolean} */
this.started_ = false;
Expand All @@ -58,7 +66,7 @@ shaka.media.VideoWrapper = class {
HTMLMediaElement.HAVE_METADATA,
this.eventManager_,
() => {
this.setStartTime_(this.startTime_);
this.setStartTime_(this.getStartTime_());
});
}

Expand Down Expand Up @@ -86,7 +94,7 @@ shaka.media.VideoWrapper = class {
* @return {number}
*/
getTime() {
return this.started_ ? this.video_.currentTime : this.startTime_;
return this.started_ ? this.video_.currentTime : this.getStartTime_();
}


Expand All @@ -103,7 +111,7 @@ shaka.media.VideoWrapper = class {
HTMLMediaElement.HAVE_METADATA,
this.eventManager_,
() => {
this.setStartTime_(this.startTime_);
this.setStartTime_(this.getStartTime_());
});
}
}
Expand Down