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: clamp seekable end to start instead of 0 #1564

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 2 additions & 6 deletions src/playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1702,12 +1702,8 @@ export class PlaylistController extends videojs.EventTarget {

const liveEdgeDelay = Vhs.Playlist.liveEdgeDelay(this.mainPlaylistLoader_.main, media);

// Make sure our seekable end is not negative
const calculatedEnd = Math.max(0, end - liveEdgeDelay);

if (calculatedEnd < start) {
return null;
}
// Make sure our seekable end is not less than the seekable start
const calculatedEnd = Math.max(start, end - liveEdgeDelay);

return createTimeRanges([[start, calculatedEnd]]);
}
Expand Down
64 changes: 64 additions & 0 deletions test/playlist-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2633,6 +2633,70 @@ QUnit.test(
}
);

QUnit.test(
'getSeekableRange_ returns a range with an end that is never less than the start',
function(assert) {
const pc = this.playlistController;

const fakeMedia = {};
const fakePlaylistLoader = {
media() {
return fakeMedia;
}
};

// Ensure mainPlaylistLoader_.main is defined (needed by liveEdgeDelay)
pc.mainPlaylistLoader_ = { main: {} };

const originalLiveEdgeDelay = Vhs.Playlist.liveEdgeDelay;

// --- Scenario 1: liveEdgeDelay = 0 ---
// With a reliable sync info of start=10 and end=15, if liveEdgeDelay is 0 then:
// calculatedEnd = Math.max(10, 15 - 0) = 15
// Expected seekable range: [10,15]
Vhs.Playlist.liveEdgeDelay = function(main, media) {
return 0;
};

pc.syncController_.getMediaSequenceSync = function(type) {
if (type === 'main') {
return {
isReliable: true,
start: 10,
end: 15
};
}
return null;
};

let seekable = pc.getSeekableRange_(fakePlaylistLoader, 'main');

timeRangesEqual(
seekable,
createTimeRanges([[10, 15]]),
'With liveEdgeDelay 0, seekable range is [10,15]'
);

// --- Scenario 2: liveEdgeDelay large enough to force clamping ---
// With the same sync info (start=10, end=15), if liveEdgeDelay = 10 then:
// calculatedEnd = Math.max(10, 15 - 10) = Math.max(10, 5) = 10
// Expected seekable range: [10,10] (the end is clamped to start)
Vhs.Playlist.liveEdgeDelay = function(main, media) {
return 10;
};

seekable = pc.getSeekableRange_(fakePlaylistLoader, 'main');

timeRangesEqual(
seekable,
createTimeRanges([[10, 10]]),
'When liveEdgeDelay forces a negative delta, seekable range is clamped to [10,10]'
);

Vhs.Playlist.liveEdgeDelay = originalLiveEdgeDelay;
}
);

QUnit.test(
'syncInfoUpdate triggers seekablechanged when seekable is updated',
function(assert) {
Expand Down
Loading