Skip to content

Commit

Permalink
Don't apply liveDelay to WindowTypes.STATIC (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiningTrapez authored Sep 23, 2024
1 parent 48bc4db commit 26eb52f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/playbackstrategy/msestrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,15 @@ function MSEStrategy(mediaSources, windowType, mediaKind, playbackElement, isUHD
}

function getClampedTime(time, range) {
return Math.min(Math.max(time, range.start), range.end - Math.max(liveDelay, seekDurationPadding))
const isStatic = windowType === WindowTypes.STATIC
const isSliding = windowType === WindowTypes.SLIDING
const clampedRange = {
start: isSliding ? 0 : range.start,
end: isSliding ? mediaPlayer.getDVRWindowSize() : range.end,
correction: isStatic ? seekDurationPadding : Math.max(liveDelay, seekDurationPadding),
}

return Math.min(Math.max(time, clampedRange.start), clampedRange.end - clampedRange.correction)
}

function load(mimeType, playbackTime) {
Expand Down Expand Up @@ -586,23 +594,20 @@ function MSEStrategy(mediaSources, windowType, mediaKind, playbackElement, isUHD
}

function calculateSeekOffset(time) {
function getClampedTimeForLive(time) {
return Math.min(Math.max(time, 0), mediaPlayer.getDVRWindowSize() - Math.max(liveDelay, seekDurationPadding))
if (windowType !== WindowTypes.SLIDING) {
return getClampedTime(time, getSeekableRange())
}

if (windowType === WindowTypes.SLIDING) {
const dvrInfo = mediaPlayer.getDashMetrics().getCurrentDVRInfo(mediaKind)
const offset = TimeUtils.calculateSlidingWindowSeekOffset(
time,
dvrInfo.range.start,
timeCorrection,
slidingWindowPausedTime
)
slidingWindowPausedTime = 0
const dvrInfo = mediaPlayer.getDashMetrics().getCurrentDVRInfo(mediaKind)
const offset = TimeUtils.calculateSlidingWindowSeekOffset(
time,
dvrInfo.range.start,
timeCorrection,
slidingWindowPausedTime
)
slidingWindowPausedTime = 0

return getClampedTimeForLive(offset)
}
return getClampedTime(time, getSeekableRange())
return getClampedTime(offset)
}

function addEventCallback(thisArg, newCallback) {
Expand Down
10 changes: 10 additions & 0 deletions src/playbackstrategy/msestrategy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ describe("Media Source Extensions Playback Strategy", () => {
expect(mockDashInstance.initialize).toHaveBeenCalledWith(mediaElement, null, true)
expect(mockDashInstance.attachSource).toHaveBeenCalledWith(`${cdnArray[0].url}#t=15`)
})

it("should clamp the seek to the end of the seekable range", () => {
const seekDurationPadding = 0

setUpMSE(undefined, undefined, undefined, undefined, undefined, { streaming: { seekDurationPadding } })
mseStrategy.load(null, 0)

mseStrategy.setCurrentTime(1000)
expect(mockDashInstance.seek).toHaveBeenCalledWith(101)
})
})

describe("for SLIDING window", () => {
Expand Down

0 comments on commit 26eb52f

Please sign in to comment.