From 1b193916bdcf7f415a194d6d2b703d6198df4a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Wed, 22 Jan 2025 16:10:52 +0100 Subject: [PATCH] perf: Improve GapJumpingController times (#7921) --- lib/media/gap_jumping_controller.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/media/gap_jumping_controller.js b/lib/media/gap_jumping_controller.js index 6741d53d4e..16f620f18a 100644 --- a/lib/media/gap_jumping_controller.js +++ b/lib/media/gap_jumping_controller.js @@ -53,6 +53,9 @@ shaka.media.GapJumpingController = class { /** @private {shaka.util.EventManager} */ this.eventManager_ = new shaka.util.EventManager(); + /** @private {boolean} */ + this.started_ = false; + /** @private {boolean} */ this.seekingEventReceived_ = false; @@ -90,7 +93,7 @@ shaka.media.GapJumpingController = class { */ this.gapJumpTimer_ = new shaka.util.Timer(() => { this.onPollGapJump_(); - }).tickEvery(this.config_.gapJumpTimerTime); + }); } @@ -134,16 +137,22 @@ shaka.media.GapJumpingController = class { * @param {number} startTime */ onStarted(startTime) { + this.started_ = true; if (this.video_.seeking && !this.seekingEventReceived_) { this.seekingEventReceived_ = true; this.startTime_ = startTime; } + if (this.gapJumpTimer_) { + this.gapJumpTimer_.tickEvery(this.config_.gapJumpTimerTime); + } + this.onPollGapJump_(); } /** Called when a seek has started. */ onSeeking() { this.seekingEventReceived_ = true; this.hadSegmentAppended_ = false; + this.onPollGapJump_(); } @@ -167,6 +176,10 @@ shaka.media.GapJumpingController = class { if (this.video_.readyState == 0) { return; } + // Don't gap jump before playback started + if (!this.started_) { + return; + } // Do not gap jump if seeking has begun, but the seeking event has not // yet fired for this particular seek. if (this.video_.seeking) {