From 6fee62aecc43ad65e700840584707523d03a2280 Mon Sep 17 00:00:00 2001 From: "yair.ansbacher" Date: Sun, 8 Aug 2021 15:02:20 +0300 Subject: [PATCH 01/10] fix(FEC-11473): start of dvr window is going back and forth while start over --- src/dash-adapter.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/dash-adapter.js b/src/dash-adapter.js index a57570d6..e7c9ef14 100644 --- a/src/dash-adapter.js +++ b/src/dash-adapter.js @@ -739,6 +739,7 @@ export default class DashAdapter extends BaseMediaSourceAdapter { case shaka.net.NetworkingEngine.RequestType.MANIFEST: this._parseManifest(response.data); this._trigger(EventType.MANIFEST_LOADED, {miliSeconds: response.timeMs}); + this._seekRangeStart = null; break; } }); @@ -1297,7 +1298,8 @@ export default class DashAdapter extends BaseMediaSourceAdapter { */ getStartTimeOfDvrWindow(): number { if (this.isLive() && this._shaka) { - return this._shaka.seekRange().start + this._shaka.getConfiguration().streaming.safeSeekOffset; + this._seekRangeStart = this._seekRangeStart || this._shaka.seekRange().start; + return this._seekRangeStart + this._shaka.getConfiguration().streaming.safeSeekOffset; } return 0; } From d747ae8815784f3aa4b0b03ab2fb74b2fff8590d Mon Sep 17 00:00:00 2001 From: "yair.ansbacher" Date: Sun, 8 Aug 2021 15:10:09 +0300 Subject: [PATCH 02/10] var declare --- src/dash-adapter.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dash-adapter.js b/src/dash-adapter.js index e7c9ef14..87fd9ae8 100644 --- a/src/dash-adapter.js +++ b/src/dash-adapter.js @@ -216,6 +216,7 @@ export default class DashAdapter extends BaseMediaSourceAdapter { * @private */ _thumbnailController: ?DashThumbnailController; + _seekRangeStart: ?number; /** * Factory method to create media source adapter. From 589decad842eafbf910c035c74594b214c8339f1 Mon Sep 17 00:00:00 2001 From: "yair.ansbacher" Date: Mon, 9 Aug 2021 15:38:37 +0300 Subject: [PATCH 03/10] remove null --- src/dash-adapter.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/dash-adapter.js b/src/dash-adapter.js index 87fd9ae8..311606b0 100644 --- a/src/dash-adapter.js +++ b/src/dash-adapter.js @@ -216,7 +216,7 @@ export default class DashAdapter extends BaseMediaSourceAdapter { * @private */ _thumbnailController: ?DashThumbnailController; - _seekRangeStart: ?number; + _seekRangeStart: number; /** * Factory method to create media source adapter. @@ -740,7 +740,7 @@ export default class DashAdapter extends BaseMediaSourceAdapter { case shaka.net.NetworkingEngine.RequestType.MANIFEST: this._parseManifest(response.data); this._trigger(EventType.MANIFEST_LOADED, {miliSeconds: response.timeMs}); - this._seekRangeStart = null; + this._seekRangeStart = this._shaka.seekRange().start; break; } }); @@ -1299,7 +1299,6 @@ export default class DashAdapter extends BaseMediaSourceAdapter { */ getStartTimeOfDvrWindow(): number { if (this.isLive() && this._shaka) { - this._seekRangeStart = this._seekRangeStart || this._shaka.seekRange().start; return this._seekRangeStart + this._shaka.getConfiguration().streaming.safeSeekOffset; } return 0; From 72d7094d20eae822d8c13ecfca5beca5d60eaea9 Mon Sep 17 00:00:00 2001 From: "yair.ansbacher" Date: Wed, 11 Aug 2021 10:29:55 +0300 Subject: [PATCH 04/10] do it for start over only --- src/dash-adapter.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/dash-adapter.js b/src/dash-adapter.js index 311606b0..f7992488 100644 --- a/src/dash-adapter.js +++ b/src/dash-adapter.js @@ -216,7 +216,8 @@ export default class DashAdapter extends BaseMediaSourceAdapter { * @private */ _thumbnailController: ?DashThumbnailController; - _seekRangeStart: number; + _isStartOver: boolean = false; + _seekRangeStart: number = 0; /** * Factory method to create media source adapter. @@ -740,7 +741,6 @@ export default class DashAdapter extends BaseMediaSourceAdapter { case shaka.net.NetworkingEngine.RequestType.MANIFEST: this._parseManifest(response.data); this._trigger(EventType.MANIFEST_LOADED, {miliSeconds: response.timeMs}); - this._seekRangeStart = this._shaka.seekRange().start; break; } }); @@ -1299,7 +1299,13 @@ export default class DashAdapter extends BaseMediaSourceAdapter { */ getStartTimeOfDvrWindow(): number { if (this.isLive() && this._shaka) { - return this._seekRangeStart + this._shaka.getConfiguration().streaming.safeSeekOffset; + if (!this._isStartOver) { + if (this._seekRangeStart > this._shaka.seekRange().start) { + this._isStartOver = true; + } + this._seekRangeStart = this._shaka.seekRange().start; + } + return (this._isStartOver ? this._seekRangeStart : this._shaka.seekRange().start) + this._shaka.getConfiguration().streaming.safeSeekOffset; } return 0; } From cbd511db81fe91be56bde69c294f5965fee7c457 Mon Sep 17 00:00:00 2001 From: "yair.ansbacher" Date: Wed, 11 Aug 2021 12:13:44 +0300 Subject: [PATCH 05/10] add comment --- src/dash-adapter.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dash-adapter.js b/src/dash-adapter.js index f7992488..67a51e6e 100644 --- a/src/dash-adapter.js +++ b/src/dash-adapter.js @@ -1301,6 +1301,7 @@ export default class DashAdapter extends BaseMediaSourceAdapter { if (this.isLive() && this._shaka) { if (!this._isStartOver) { if (this._seekRangeStart > this._shaka.seekRange().start) { + // seekRange().start seeked back means this is start over this._isStartOver = true; } this._seekRangeStart = this._shaka.seekRange().start; From 493fcc01e223066d0ce1a6aef04c6ec7fed48ed6 Mon Sep 17 00:00:00 2001 From: "yair.ansbacher" Date: Wed, 11 Aug 2021 18:00:15 +0300 Subject: [PATCH 06/10] reuse --- src/dash-adapter.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/dash-adapter.js b/src/dash-adapter.js index 67a51e6e..c8c3c58e 100644 --- a/src/dash-adapter.js +++ b/src/dash-adapter.js @@ -1299,14 +1299,15 @@ export default class DashAdapter extends BaseMediaSourceAdapter { */ getStartTimeOfDvrWindow(): number { if (this.isLive() && this._shaka) { + const newSeekRangeStart = this._shaka.seekRange().start; if (!this._isStartOver) { - if (this._seekRangeStart > this._shaka.seekRange().start) { + if (this._seekRangeStart > newSeekRangeStart) { // seekRange().start seeked back means this is start over this._isStartOver = true; } - this._seekRangeStart = this._shaka.seekRange().start; + this._seekRangeStart = newSeekRangeStart; } - return (this._isStartOver ? this._seekRangeStart : this._shaka.seekRange().start) + this._shaka.getConfiguration().streaming.safeSeekOffset; + return (this._isStartOver ? this._seekRangeStart : newSeekRangeStart) + this._shaka.getConfiguration().streaming.safeSeekOffset; } return 0; } From afe69ab02078adc003e49c948e82ace12047d51b Mon Sep 17 00:00:00 2001 From: yairansbacher Date: Sun, 22 Aug 2021 15:30:30 +0300 Subject: [PATCH 07/10] save the loaded start time for start over --- src/dash-adapter.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/dash-adapter.js b/src/dash-adapter.js index c8c3c58e..b468ec3e 100644 --- a/src/dash-adapter.js +++ b/src/dash-adapter.js @@ -216,8 +216,9 @@ export default class DashAdapter extends BaseMediaSourceAdapter { * @private */ _thumbnailController: ?DashThumbnailController; - _isStartOver: boolean = false; + _isStartOver: boolean = true; _seekRangeStart: number = 0; + _startOverTimeout: number; /** * Factory method to create media source adapter. @@ -721,6 +722,7 @@ export default class DashAdapter extends BaseMediaSourceAdapter { this._eventManager.listen(this._shaka, ShakaEvent.DRM_SESSION_UPDATE, this._adapterEventsBindings.drmsessionupdate); this._eventManager.listen(this._videoElement, EventType.WAITING, this._adapterEventsBindings.waiting); this._eventManager.listen(this._videoElement, EventType.PLAYING, this._adapterEventsBindings.playing); + this._eventManager.listen(this._videoElement, EventType.LOADED_DATA, () => this._onLoadedData()); this._eventManager.listenOnce(this._videoElement, EventType.PLAYING, () => { this._eventManager.listen(this._shaka, ShakaEvent.BUFFERING, this._adapterEventsBindings.buffering); }); @@ -746,6 +748,16 @@ export default class DashAdapter extends BaseMediaSourceAdapter { }); } + _onLoadedData(): void { + const segmentDuration = this.getSegmentDuration(); + this._seekRangeStart = this._shaka.seekRange().start; + this._startOverTimeout = setTimeout(() => { + if (this._shaka.seekRange().start - this._seekRangeStart >= segmentDuration) { + this._isStartOver = false; + } + }, segmentDuration * 1000); + } + /** * Custom parser to retrieve image adaptation sets. * @param {ArrayBuffer} manifestBuffer - The array buffer manifest from the response. @@ -848,6 +860,7 @@ export default class DashAdapter extends BaseMediaSourceAdapter { this._thumbnailController = null; this._clearStallInterval(); this._clearVideoUpdateTimer(); + clearTimeout(this._startOverTimeout); if (this._eventManager) { this._eventManager.removeAll(); } @@ -1299,15 +1312,7 @@ export default class DashAdapter extends BaseMediaSourceAdapter { */ getStartTimeOfDvrWindow(): number { if (this.isLive() && this._shaka) { - const newSeekRangeStart = this._shaka.seekRange().start; - if (!this._isStartOver) { - if (this._seekRangeStart > newSeekRangeStart) { - // seekRange().start seeked back means this is start over - this._isStartOver = true; - } - this._seekRangeStart = newSeekRangeStart; - } - return (this._isStartOver ? this._seekRangeStart : newSeekRangeStart) + this._shaka.getConfiguration().streaming.safeSeekOffset; + return (this._isStartOver ? this._seekRangeStart : this._shaka.seekRange().start) + this._shaka.getConfiguration().streaming.safeSeekOffset; } return 0; } From 31600d5028aee4e3cdaa31789bfe11343c59493c Mon Sep 17 00:00:00 2001 From: yairansbacher Date: Sun, 22 Aug 2021 15:45:05 +0300 Subject: [PATCH 08/10] add a comment --- src/dash-adapter.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dash-adapter.js b/src/dash-adapter.js index 3a2c3a8c..ac46553e 100644 --- a/src/dash-adapter.js +++ b/src/dash-adapter.js @@ -753,6 +753,7 @@ export default class DashAdapter extends BaseMediaSourceAdapter { this._seekRangeStart = this._shaka.seekRange().start; this._startOverTimeout = setTimeout(() => { if (this._shaka.seekRange().start - this._seekRangeStart >= segmentDuration) { + // in start over the seekRange().start should be permanent this._isStartOver = false; } }, segmentDuration * 1000); From ae91414efd42ebffa4d76b287556cf0da6dcc6c2 Mon Sep 17 00:00:00 2001 From: yairansbacher Date: Sun, 22 Aug 2021 16:22:49 +0300 Subject: [PATCH 09/10] fix flow and tests --- karma.conf.js | 2 +- src/dash-adapter.js | 2 +- test/src/dash-adapter.spec.js | 12 +++++------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 13d13bd1..0eab1731 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -34,7 +34,7 @@ module.exports = function (config) { client: { mocha: { reporter: 'html', - timeout: 10000 + timeout: 20000 } } }; diff --git a/src/dash-adapter.js b/src/dash-adapter.js index ac46553e..416958f3 100644 --- a/src/dash-adapter.js +++ b/src/dash-adapter.js @@ -218,7 +218,7 @@ export default class DashAdapter extends BaseMediaSourceAdapter { _thumbnailController: ?DashThumbnailController; _isStartOver: boolean = true; _seekRangeStart: number = 0; - _startOverTimeout: number; + _startOverTimeout: TimeoutID; /** * Factory method to create media source adapter. diff --git a/test/src/dash-adapter.spec.js b/test/src/dash-adapter.spec.js index c0c13819..a002165e 100644 --- a/test/src/dash-adapter.spec.js +++ b/test/src/dash-adapter.spec.js @@ -1342,9 +1342,8 @@ describe('DashAdapter: getStartTimeOfDvrWindow', () => { it('should return the start time of Dvr window for live', done => { dashInstance = DashAdapter.createAdapter(video, liveSource, config); - dashInstance - .load() - .then(() => { + video.addEventListener(EventType.LOADED_DATA, () => { + setTimeout(() => { try { Math.floor(dashInstance.getStartTimeOfDvrWindow()).should.equal( Math.floor(dashInstance._shaka.seekRange().start + dashInstance._shaka.getConfiguration().streaming.safeSeekOffset) @@ -1353,10 +1352,9 @@ describe('DashAdapter: getStartTimeOfDvrWindow', () => { } catch (e) { done(e); } - }) - .catch(e => { - done(e); - }); + }, (dashInstance.getSegmentDuration() + 1) * 1000); + }); + dashInstance.load(); }); }); From a0035650bdea97e44f07aba933075a9b49f0192a Mon Sep 17 00:00:00 2001 From: yairansbacher Date: Mon, 23 Aug 2021 13:16:50 +0300 Subject: [PATCH 10/10] increase the timeout to be on the safe side --- src/dash-adapter.js | 2 +- test/src/dash-adapter.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dash-adapter.js b/src/dash-adapter.js index 416958f3..3250a61b 100644 --- a/src/dash-adapter.js +++ b/src/dash-adapter.js @@ -756,7 +756,7 @@ export default class DashAdapter extends BaseMediaSourceAdapter { // in start over the seekRange().start should be permanent this._isStartOver = false; } - }, segmentDuration * 1000); + }, (segmentDuration + 1) * 1000); } /** diff --git a/test/src/dash-adapter.spec.js b/test/src/dash-adapter.spec.js index a002165e..fb0e2ece 100644 --- a/test/src/dash-adapter.spec.js +++ b/test/src/dash-adapter.spec.js @@ -1352,7 +1352,7 @@ describe('DashAdapter: getStartTimeOfDvrWindow', () => { } catch (e) { done(e); } - }, (dashInstance.getSegmentDuration() + 1) * 1000); + }, (dashInstance.getSegmentDuration() + 2) * 1000); }); dashInstance.load(); });