Skip to content

Commit

Permalink
fix(FEC-11473): start of dvr window is going back and forth while sta…
Browse files Browse the repository at this point in the history
…rt over (#165)

shaka is increasing the `seekRange.start` between manifest loadings.
so ignore this update if it's start over.

Solves FEC-11473
  • Loading branch information
yairans authored Aug 23, 2021
1 parent 1c496b5 commit d122166
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = function (config) {
client: {
mocha: {
reporter: 'html',
timeout: 10000
timeout: 20000
}
}
};
Expand Down
18 changes: 17 additions & 1 deletion src/dash-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
* @private
*/
_thumbnailController: ?DashThumbnailController;
_isStartOver: boolean = true;
_seekRangeStart: number = 0;
_startOverTimeout: TimeoutID;

/**
* Factory method to create media source adapter.
Expand Down Expand Up @@ -719,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);
});
Expand All @@ -744,6 +748,17 @@ 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) {
// in start over the seekRange().start should be permanent
this._isStartOver = false;
}
}, (segmentDuration + 1) * 1000);
}

/**
* Custom parser to retrieve image adaptation sets.
* @param {ArrayBuffer} manifestBuffer - The array buffer manifest from the response.
Expand Down Expand Up @@ -846,6 +861,7 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
this._thumbnailController = null;
this._clearStallInterval();
this._clearVideoUpdateTimer();
clearTimeout(this._startOverTimeout);
if (this._eventManager) {
this._eventManager.removeAll();
}
Expand Down Expand Up @@ -1300,7 +1316,7 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
*/
getStartTimeOfDvrWindow(): number {
if (this.isLive() && this._shaka) {
return this._shaka.seekRange().start + this._shaka.getConfiguration().streaming.safeSeekOffset;
return (this._isStartOver ? this._seekRangeStart : this._shaka.seekRange().start) + this._shaka.getConfiguration().streaming.safeSeekOffset;
}
return 0;
}
Expand Down
12 changes: 5 additions & 7 deletions test/src/dash-adapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -1353,10 +1352,9 @@ describe('DashAdapter: getStartTimeOfDvrWindow', () => {
} catch (e) {
done(e);
}
})
.catch(e => {
done(e);
});
}, (dashInstance.getSegmentDuration() + 2) * 1000);
});
dashInstance.load();
});
});

Expand Down

0 comments on commit d122166

Please sign in to comment.