Skip to content

Commit

Permalink
feat: Improve live latency on load (shaka-project#5268)
Browse files Browse the repository at this point in the history
With this change the latency is reduced in 50ms approx. Very important
for LL streams.
  • Loading branch information
avelad committed Jun 8, 2023
1 parent 2ca7d0b commit 236dacb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/media/playhead.js
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
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

0 comments on commit 236dacb

Please sign in to comment.