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 seek to live start regression in dev #4887

Merged
merged 1 commit into from
Sep 8, 2022
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
3 changes: 3 additions & 0 deletions src/controller/base-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,13 @@ export default class BaseStreamController
this.fragCurrent === this.fragPrevious
) {
this.loadedmetadata = true;
this.seekToStartPos();
}
this.tick();
}

protected seekToStartPos() {}

protected _handleFragmentLoadComplete(fragLoadedEndData: PartsLoadedData) {
const { transmuxer } = this;
if (!transmuxer) {
Expand Down
11 changes: 2 additions & 9 deletions src/controller/stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -917,13 +917,7 @@ export default class StreamController
return;
}

// Check combined buffer
const buffered = BufferHelper.getBuffered(media);

if (!this.loadedmetadata && buffered.length) {
this.loadedmetadata = true;
this.seekToStartPos();
} else {
if (this.loadedmetadata || !BufferHelper.getBuffered(media).length) {
// Resolve gaps using the main buffer, whose ranges are the intersections of the A/V sourcebuffers
const activeFrag = this.state !== State.IDLE ? this.fragCurrent : null;
gapController.poll(this.lastCurrentTime, activeFrag);
Expand Down Expand Up @@ -972,9 +966,8 @@ export default class StreamController

/**
* Seeks to the set startPosition if not equal to the mediaElement's current time.
* @private
*/
private seekToStartPos() {
protected seekToStartPos() {
const { media } = this;
if (!media) {
return;
Expand Down
12 changes: 10 additions & 2 deletions tests/unit/controller/stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,19 @@ describe('StreamController', function () {
streamController['checkBuffer']();
});

it('should seek to start pos when metadata has not yet been loaded', function () {
it('should seek to start pos when data is first loaded', function () {
const firstFrag = new Fragment(PlaylistLevelType.MAIN, '');
firstFrag.duration = 5.0;
firstFrag.level = 1;
firstFrag.start = 0;
firstFrag.sn = 1;
firstFrag.cc = 0;
// @ts-ignore
const seekStub = sandbox.stub(streamController, 'seekToStartPos');
streamController['loadedmetadata'] = false;
streamController['checkBuffer']();
streamController['fragCurrent'] = streamController['fragPrevious'] =
firstFrag;
streamController['fragBufferedComplete'](firstFrag, null);
expect(seekStub).to.have.been.calledOnce;
expect(streamController['loadedmetadata']).to.be.true;
});
Expand Down