Skip to content

Commit

Permalink
fix: remove default live delay
Browse files Browse the repository at this point in the history
  • Loading branch information
eirikbjornr committed Sep 12, 2023
1 parent d4bd0d3 commit 4696d75
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
44 changes: 21 additions & 23 deletions src/playbackstrategy/msestrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,29 @@ function MSEStrategy(mediaSources, windowType, mediaKind, playbackElement, isUHD
let mediaPlayer
let mediaElement

const playerSettings = Utils.merge(
{
debug: {
logLevel: 2,
},
streaming: {
blacklistExpiryTime: mediaSources.failoverResetTime(),
buffer: {
bufferToKeep: 4,
bufferTimeAtTopQuality: 12,
bufferTimeAtTopQualityLongForm: 15,
},
},
},
customPlayerSettings
)

let eventCallbacks = []
let errorCallback
let timeUpdateCallback

let timeCorrection = mediaSources.time()?.timeCorrectionSeconds || 0
const liveDelay = isNaN(playerSettings.streaming?.delay?.liveDelay) ? 0 : playerSettings.streaming?.delay?.liveDelay
let failoverTime
let failoverZeroPoint
let refreshFailoverTime
Expand All @@ -42,26 +60,6 @@ function MSEStrategy(mediaSources, windowType, mediaKind, playbackElement, isUHD
},
}

const playerSettings = Utils.merge(
{
debug: {
logLevel: 2,
},
streaming: {
blacklistExpiryTime: mediaSources.failoverResetTime(),
buffer: {
bufferToKeep: 4,
bufferTimeAtTopQuality: 12,
bufferTimeAtTopQualityLongForm: 15,
},
delay: {
liveDelay: 1.1,
},
},
},
customPlayerSettings
)

const DashJSEvents = {
LOG: "log",
ERROR: "error",
Expand Down Expand Up @@ -345,7 +343,7 @@ function MSEStrategy(mediaSources, windowType, mediaKind, playbackElement, isUHD
}

function getClampedTime(time, range) {
return Math.min(Math.max(time, range.start), range.end - playerSettings.streaming.delay.liveDelay)
return Math.min(Math.max(time, range.start), range.end - liveDelay)
}

function load(mimeType, playbackTime) {
Expand Down Expand Up @@ -412,7 +410,7 @@ function MSEStrategy(mediaSources, windowType, mediaKind, playbackElement, isUHD
if (dvrInfo) {
return {
start: dvrInfo.range.start - timeCorrection,
end: dvrInfo.range.end - timeCorrection - playerSettings.streaming.delay.liveDelay,
end: dvrInfo.range.end - timeCorrection - liveDelay,
}
}
}
Expand Down Expand Up @@ -449,7 +447,7 @@ function MSEStrategy(mediaSources, windowType, mediaKind, playbackElement, isUHD

function calculateSeekOffset(time) {
function getClampedTimeForLive(time) {
return Math.min(Math.max(time, 0), mediaPlayer.getDVRWindowSize() - playerSettings.streaming.delay.liveDelay)
return Math.min(Math.max(time, 0), mediaPlayer.getDVRWindowSize() - liveDelay)
}

if (windowType === WindowTypes.SLIDING) {
Expand Down
22 changes: 18 additions & 4 deletions src/playbackstrategy/msestrategy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,18 +762,31 @@ describe("Media Source Extensions Playback Strategy", () => {
expect(mockDashInstance.seek).toHaveBeenCalledWith(0)
})

it("should clamp the seek to 1.1s before the end of the seekable range", () => {
setUpMSE()
it("should clamp the seek to <live delay> before the end of the seekable range", () => {
const liveDelay = 1.1

setUpMSE(undefined, undefined, undefined, undefined, undefined, { streaming: { delay: { liveDelay } } })

mseStrategy.load(null, 0)

mseStrategy.setCurrentTime(101)

expect(mockDashInstance.seek).toHaveBeenCalledWith(99.9)
})

it("does not clamp the seek when live delay isn't set", () => {
setUpMSE()

mseStrategy.load(null, 0)

mseStrategy.setCurrentTime(101)

expect(mockDashInstance.seek).toHaveBeenCalledWith(101)
})

describe("sliding window", () => {
beforeEach(() => {
setUpMSE(0, WindowTypes.SLIDING, MediaKinds.VIDEO, 100, 1000)
setUpMSE(0, WindowTypes.SLIDING, MediaKinds.VIDEO, 100, 1000, { streaming: { delay: { liveDelay: 1.1 } } })
mseStrategy.load(null, 0)
mockDashInstance.play.mockReset()
})
Expand Down Expand Up @@ -843,7 +856,8 @@ describe("Media Source Extensions Playback Strategy", () => {

describe("growing window", () => {
beforeEach(() => {
setUpMSE(0, WindowTypes.GROWING)
setUpMSE(0, WindowTypes.GROWING, undefined, undefined, undefined, { streaming: { delay: { liveDelay: 1.1 } } })

mseStrategy.load(null, 0)
mediaElement.currentTime = 50
mockDashInstance.refreshManifest.mockReset()
Expand Down

0 comments on commit 4696d75

Please sign in to comment.