Skip to content

Commit 1339763

Browse files
committed
Cleanup FRAG_GAP error creation and inlcude current buffer length in forward gap buffer limit
1 parent b88543c commit 1339763

File tree

5 files changed

+32
-31
lines changed

5 files changed

+32
-31
lines changed

api-extractor/report/hls.js.api.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ export class BaseStreamController extends TaskLoop implements NetworkComponentAP
330330
// (undocumented)
331331
protected getFwdBufferInfo(bufferable: Bufferable | null, type: PlaylistLevelType): BufferInfo | null;
332332
// (undocumented)
333+
protected getFwdBufferInfoAtPos(bufferable: Bufferable | null, pos: number, type: PlaylistLevelType): BufferInfo | null;
334+
// (undocumented)
333335
protected getInitialLiveFragment(levelDetails: LevelDetails, fragments: Array<Fragment>): Fragment | null;
334336
// (undocumented)
335337
protected getLevelDetails(): LevelDetails | undefined;
@@ -406,7 +408,9 @@ export class BaseStreamController extends TaskLoop implements NetworkComponentAP
406408
// (undocumented)
407409
protected recoverWorkerError(data: ErrorData): void;
408410
// (undocumented)
409-
protected reduceMaxBufferLength(threshold?: number): boolean;
411+
protected reduceLengthAndFlushBuffer(data: ErrorData): boolean;
412+
// (undocumented)
413+
protected reduceMaxBufferLength(threshold: number): boolean;
410414
// (undocumented)
411415
protected resetFragmentErrors(filterType: PlaylistLevelType): void;
412416
// (undocumented)

src/controller/base-stream-controller.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1166,9 +1166,10 @@ export default class BaseStreamController
11661166
const curSNIdx = frag.sn - levelDetails.startSN;
11671167
// Move fragPrevious forward to support forcing the next fragment to load
11681168
// when the buffer catches up to a previously buffered range.
1169+
const fragState = this.fragmentTracker.getState(frag);
11691170
if (
1170-
this.fragmentTracker.getState(frag) === FragmentState.OK ||
1171-
(frag.gap && frag.stats.aborted)
1171+
fragState === FragmentState.OK ||
1172+
(fragState === FragmentState.PARTIAL && frag.gap)
11721173
) {
11731174
fragPrevious = frag;
11741175
}

src/controller/error-controller.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ export default class ErrorController implements NetworkComponentAPI {
303303
candidate !== hls.loadLevel &&
304304
levels[candidate].loadError === 0
305305
) {
306-
// Skip level switch if GAP tag is found in next level
306+
// Skip level switch if GAP tag is found in next level at same position
307307
if (data.details === ErrorDetails.FRAG_GAP && data.frag) {
308308
const levelDetails = hls.levels[candidate].details;
309309
if (levelDetails) {

src/controller/stream-controller.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,16 @@ export default class StreamController
327327
}
328328
frag = this.getNextFragment(this.nextLoadPosition, levelDetails);
329329
if (gapStart && frag && !frag.gap && bufferInfo.nextStart) {
330-
// Make sure this doesn't make the next buffer timerange exceed forward buffer length after a gap
330+
// Media buffered after GAP tags should not make the next buffer timerange exceed forward buffer length
331331
const nextbufferInfo = this.getFwdBufferInfoAtPos(
332332
this.mediaBuffer ? this.mediaBuffer : this.media,
333333
bufferInfo.nextStart,
334334
PlaylistLevelType.MAIN
335335
);
336-
if (nextbufferInfo !== null && nextbufferInfo.len > maxBufLen) {
336+
if (
337+
nextbufferInfo !== null &&
338+
bufferLen + nextbufferInfo.len >= maxBufLen
339+
) {
337340
return;
338341
}
339342
}

src/loader/fragment-loader.ts

+18-25
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,7 @@ export default class FragmentLoader {
6969
this.loader.destroy();
7070
}
7171
if (frag.gap) {
72-
frag.stats.aborted = true;
73-
frag.stats.retry++;
74-
reject(
75-
new LoadError({
76-
type: ErrorTypes.MEDIA_ERROR,
77-
details: ErrorDetails.FRAG_GAP,
78-
fatal: false,
79-
frag,
80-
error: new Error('GAP tag found'),
81-
networkDetails: null,
82-
})
83-
);
72+
reject(createGapLoadError(frag));
8473
return;
8574
}
8675
const loader =
@@ -191,19 +180,7 @@ export default class FragmentLoader {
191180
this.loader.destroy();
192181
}
193182
if (frag.gap || part.gap) {
194-
frag.stats.aborted = true;
195-
frag.stats.retry++;
196-
reject(
197-
new LoadError({
198-
type: ErrorTypes.MEDIA_ERROR,
199-
details: ErrorDetails.FRAG_GAP,
200-
fatal: false,
201-
frag,
202-
part,
203-
error: new Error(`GAP ${frag.gap ? 'tag' : 'attribute'} found`),
204-
networkDetails: null,
205-
})
206-
);
183+
reject(createGapLoadError(frag, part));
207184
return;
208185
}
209186
const loader =
@@ -373,6 +350,22 @@ function createLoaderContext(
373350
return loaderContext;
374351
}
375352

353+
function createGapLoadError(frag: Fragment, part?: Part): LoadError {
354+
const error = new Error(`GAP ${frag.gap ? 'tag' : 'attribute'} found`);
355+
const errorData: FragLoadFailResult = {
356+
type: ErrorTypes.MEDIA_ERROR,
357+
details: ErrorDetails.FRAG_GAP,
358+
fatal: false,
359+
frag,
360+
error,
361+
networkDetails: null,
362+
};
363+
if (part) {
364+
errorData.part = part;
365+
}
366+
return new LoadError(errorData);
367+
}
368+
376369
export class LoadError extends Error {
377370
public readonly data: FragLoadFailResult;
378371
constructor(data: FragLoadFailResult) {

0 commit comments

Comments
 (0)