Skip to content

Commit

Permalink
fix: clamp seekable end (#1433)
Browse files Browse the repository at this point in the history
* fix seekable end

* fix eslint error

---------

Co-authored-by: Dzianis Dashkevich <[email protected]>
  • Loading branch information
dzianis-dashkevich and Dzianis Dashkevich authored Oct 12, 2023
1 parent dd5e2af commit 53edf72
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,17 @@ export const playlistEnd = function(playlist, expired, useSafeLiveEnd, liveEdgeP
export const seekable = function(playlist, expired, liveEdgePadding) {
const useSafeLiveEnd = true;
const seekableStart = expired || 0;
const seekableEnd = playlistEnd(playlist, expired, useSafeLiveEnd, liveEdgePadding);
let seekableEnd = playlistEnd(playlist, expired, useSafeLiveEnd, liveEdgePadding);

if (seekableEnd === null) {
return createTimeRanges();
}

// Clamp seekable end since it can not be less than the seekable start
if (seekableEnd < seekableStart) {
seekableEnd = seekableStart;
}

return createTimeRanges(seekableStart, seekableEnd);
};

Expand Down
39 changes: 39 additions & 0 deletions test/playlist.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,45 @@ QUnit.module('Playlist', function() {
);
assert.equal(playlistEnd, 150, 'playlist end at the last segment end');

playlist = {
targetDuration: 10,
mediaSequence: 100,
syncInfo: {
time: 50,
mediaSequence: 95
},
segments: [
{
duration: 9.01,
uri: '0.ts'
},
{
duration: 9.01,
uri: '1.ts'
},
{
duration: 9.01,
uri: '2.ts'
}
]
};

seekable = Playlist.seekable(playlist, 100);
playlistEnd = Playlist.playlistEnd(playlist, 100);

assert.ok(seekable.length, 'seekable range calculated');
assert.equal(
seekable.start(0),
100,
'estimated start time based on expired sync point'
);
assert.equal(
seekable.end(0),
100,
'seekable end is clamped to start time'
);
assert.equal(playlistEnd, 127.03, 'playlist end at the last segment end');

playlist = {
targetDuration: 10,
mediaSequence: 100,
Expand Down

0 comments on commit 53edf72

Please sign in to comment.