Skip to content

Commit

Permalink
clamp seekable end to start in cases where liveEdgeDelay would make i…
Browse files Browse the repository at this point in the history
…t less than
  • Loading branch information
alex-barstow committed Jan 31, 2025
1 parent fef62d9 commit 8bef6d1
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
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

0 comments on commit 8bef6d1

Please sign in to comment.