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

fix: computeLivePosition minimum value of media.currentTime #2506

Merged
merged 4 commits into from Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/controller/base-stream-controller.js
Expand Up @@ -128,6 +128,7 @@ export default class BaseStreamController extends TaskLoop {

computeLivePosition (sliding, levelDetails) {
let targetLatency = this.config.liveSyncDuration !== undefined ? this.config.liveSyncDuration : this.config.liveSyncDurationCount * levelDetails.targetduration;
return sliding + Math.max(0, levelDetails.totalduration - targetLatency);
jony89 marked this conversation as resolved.
Show resolved Hide resolved
const currentTime = this.media ? this.media.currentTime : null;
return Math.max(sliding + Math.max(0, levelDetails.totalduration - targetLatency), currentTime);
}
}
4 changes: 2 additions & 2 deletions src/controller/stream-controller.js
Expand Up @@ -280,9 +280,9 @@ class StreamController extends BaseStreamController {

if (bufferEnd < Math.max(start - config.maxFragLookUpTolerance, end - maxLatency)) {
let liveSyncPosition = this.liveSyncPosition = this.computeLivePosition(start, levelDetails);
logger.log(`buffer end: ${bufferEnd.toFixed(3)} is located too far from the end of live sliding playlist, reset currentTime to : ${liveSyncPosition.toFixed(3)}`);
bufferEnd = liveSyncPosition;
if (media && !media.paused && media.readyState && media.duration > liveSyncPosition) {
if (media && !media.paused && media.readyState && media.duration > liveSyncPosition && liveSyncPosition > media.currentTime) {
logger.log(`buffer end: ${bufferEnd.toFixed(3)} is located too far from the end of live sliding playlist, reset currentTime to : ${liveSyncPosition.toFixed(3)}`);
media.currentTime = liveSyncPosition;
}

Expand Down
26 changes: 26 additions & 0 deletions tests/unit/controller/stream-controller.js
Expand Up @@ -305,4 +305,30 @@ describe('StreamController', function () {
});
});
});

describe('computeLivePosition', function () {
it('should return the current live sync position according to liveSyncDuration', function () {
streamController.config.liveSyncDuration = 2;
const levelDetails = { totalduration: 20 };
const liveSyncPosition = streamController.computeLivePosition(8, levelDetails);
expect(liveSyncPosition).to.equal(26);
});

it('should return the current live sync position according to liveSyncDurationCount', function () {
streamController.config.liveSyncDurationCount = 2;
const levelDetails = { totalduration: 20, targetduration: 0.5 };
const liveSyncPosition = streamController.computeLivePosition(8, levelDetails);
expect(liveSyncPosition).to.equal(27);
});

it('should not return value that is less than the video current time', function () {
jony89 marked this conversation as resolved.
Show resolved Hide resolved
streamController.media = {
currentTime: 25
};
streamController.config.liveSyncDuration = 1;
const levelDetails = { totalduration: 14 };
const liveSyncPosition = streamController.computeLivePosition(8, levelDetails);
expect(liveSyncPosition).to.equal(25);
});
});
});