Skip to content

Commit 7b363e5

Browse files
committed
Fix gap jump over waiting for data stall when buffer length is larger than maxBufferHole but less than one second
1 parent 1339763 commit 7b363e5

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

src/controller/gap-controller.ts

+16-19
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,9 @@ export default class GapController {
131131
const maxStartGapJump = isLive
132132
? level!.details!.targetduration * 2
133133
: MAX_START_GAP_JUMP;
134-
if (
135-
startJump > 0 &&
136-
(startJump <= maxStartGapJump ||
137-
this.fragmentTracker.getPartialFragment(0))
138-
) {
139-
this._trySkipBufferHole(null);
134+
const partialOrGap = this.fragmentTracker.getPartialFragment(currentTime);
135+
if (startJump > 0 && (startJump <= maxStartGapJump || partialOrGap)) {
136+
this._trySkipBufferHole(partialOrGap);
140137
return;
141138
}
142139
}
@@ -187,7 +184,7 @@ export default class GapController {
187184
// This method isn't limited by the size of the gap between buffered ranges
188185
const targetTime = this._trySkipBufferHole(partial);
189186
// we return here in this case, meaning
190-
// the branch below only executes when we don't handle a partial fragment
187+
// the branch below only executes when we haven't seeked to a new position
191188
if (targetTime || !this.media) {
192189
return;
193190
}
@@ -248,27 +245,28 @@ export default class GapController {
248245
if (media === null) {
249246
return 0;
250247
}
251-
const currentTime = media.currentTime;
252-
let lastEndTime = 0;
248+
253249
// Check if currentTime is between unbuffered regions of partial fragments
254-
const buffered = BufferHelper.getBuffered(media);
255-
for (let i = 0; i < buffered.length; i++) {
256-
const startTime = buffered.start(i);
257-
if (
258-
currentTime + config.maxBufferHole >= lastEndTime &&
259-
currentTime < startTime
260-
) {
250+
const currentTime = media.currentTime;
251+
const bufferInfo = BufferHelper.bufferInfo(media, currentTime, 0);
252+
const startTime =
253+
currentTime < bufferInfo.start ? bufferInfo.start : bufferInfo.nextStart;
254+
if (startTime) {
255+
const bufferStarved = bufferInfo.len <= config.maxBufferHole;
256+
const waiting =
257+
bufferInfo.len > 0 && bufferInfo.len < 1 && media.readyState < 3;
258+
if (currentTime < startTime && (bufferStarved || waiting)) {
261259
const targetTime = Math.max(
262260
startTime + SKIP_BUFFER_RANGE_START,
263-
media.currentTime + SKIP_BUFFER_HOLE_STEP_SECONDS
261+
currentTime + SKIP_BUFFER_HOLE_STEP_SECONDS
264262
);
265263
logger.warn(
266264
`skipping hole, adjusting currentTime from ${currentTime} to ${targetTime}`
267265
);
268266
this.moved = true;
269267
this.stalled = null;
270268
media.currentTime = targetTime;
271-
if (partial) {
269+
if (partial && !partial.gap) {
272270
const error = new Error(
273271
`fragment loaded with buffer holes, seeking from ${currentTime} to ${targetTime}`
274272
);
@@ -283,7 +281,6 @@ export default class GapController {
283281
}
284282
return targetTime;
285283
}
286-
lastEndTime = buffered.end(i);
287284
}
288285
return 0;
289286
}

0 commit comments

Comments
 (0)