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

Seek once into buffer start when starting live #2907

Merged
merged 1 commit into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/controller/base-stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ export default class BaseStreamController extends TaskLoop {
const currentTime = media ? media.currentTime : null;
const bufferInfo = BufferHelper.bufferInfo(mediaBuffer || media, currentTime, this.config.maxBufferHole);

if (Number.isFinite(currentTime)) {
logger.log(`media seeking to ${currentTime.toFixed(3)}`);
}
logger.log(`media seeking to ${Number.isFinite(currentTime) ? currentTime.toFixed(3) : currentTime}`);

if (state === State.FRAG_LOADING) {
let fragCurrent = this.fragCurrent;
Expand Down
10 changes: 9 additions & 1 deletion src/controller/stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1336,15 +1336,23 @@ class StreamController extends BaseStreamController {
* @private
*/
_seekToStartPos () {
const { media, startPosition } = this;
const { media } = this;
const currentTime = media.currentTime;
let startPosition = this.startPosition;
// only adjust currentTime if different from startPosition or if startPosition not buffered
// at that stage, there should be only one buffered range, as we reach that code after first fragment has been buffered
if (currentTime !== startPosition && startPosition >= 0) {
if (media.seeking) {
logger.log(`could not seek to ${startPosition}, already seeking at ${currentTime}`);
return;
}
const bufferStart = media.buffered.length ? media.buffered.start(0) : 0;
const delta = bufferStart - startPosition;
if (delta > 0 && delta < this.config.maxBufferHole) {
logger.log(`adjusting start position by ${delta} to match buffer start`);
startPosition += delta;
this.startPosition = startPosition;
}
logger.log(`seek to target start position ${startPosition} from current time ${currentTime}. ready state ${media.readyState}`);
media.currentTime = startPosition;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/controller/stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,17 @@ describe('StreamController', function () {

describe('checkBuffer', function () {
const sandbox = sinon.createSandbox();
let bufStart = 5;

beforeEach(function () {
streamController.gapController = {
poll: function () {}
};
streamController.media = {
buffered: {
start () {
return bufStart;
},
length: 1
}
};
Expand Down