From 18ec2b75feb88356137b8ceae809557c36494f44 Mon Sep 17 00:00:00 2001 From: Rob Walch Date: Thu, 27 May 2021 22:33:56 -0400 Subject: [PATCH] Apply and clamp EXT-X-START: TIME-OFFSET according to spec with regards to live window #3913 --- src/controller/base-stream-controller.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/controller/base-stream-controller.ts b/src/controller/base-stream-controller.ts index c30a93d87f5..1a84567ee13 100644 --- a/src/controller/base-stream-controller.ts +++ b/src/controller/base-stream-controller.ts @@ -1122,20 +1122,25 @@ export default class BaseStreamController protected setStartPosition(details: LevelDetails, sliding: number) { // compute start position if set to -1. use it straight away if value is defined let startPosition = this.startPosition; - if (this.startPosition === -1 || this.lastCurrentTime === -1) { + if (startPosition < sliding) { + startPosition = -1; + } + if (startPosition === -1 || this.lastCurrentTime === -1) { // first, check if start time offset has been set in playlist, if yes, use this value - let startTimeOffset = details.startTimeOffset!; + const startTimeOffset = details.startTimeOffset!; if (Number.isFinite(startTimeOffset)) { + startPosition = sliding + startTimeOffset; if (startTimeOffset < 0) { - this.log( - `Negative start time offset ${startTimeOffset}, count from end of last fragment` - ); - startTimeOffset = sliding + details.totalduration + startTimeOffset; + startPosition += details.totalduration; } + startPosition = Math.min( + Math.max(sliding, startPosition), + sliding + details.totalduration + ); this.log( - `Start time offset found in playlist, adjust startPosition to ${startTimeOffset}` + `Start time offset ${startTimeOffset} found in playlist, adjust startPosition to ${startPosition}` ); - this.startPosition = startPosition = startTimeOffset; + this.startPosition = startPosition; } else if (details.live) { // Leave this.startPosition at -1, so that we can use `getInitialLiveFragment` logic when startPosition has // not been specified via the config or an as an argument to startLoad (#3736).