Skip to content

Commit

Permalink
Merge pull request #5623 from video-dev/enhancement/append-errors-per…
Browse files Browse the repository at this point in the history
…-source-buffer-type

Handle mixed sourcebuffer errors
  • Loading branch information
robwalch authored Jul 5, 2023
2 parents d2456f0 + 3673ce0 commit b71f61d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
10 changes: 9 additions & 1 deletion api-extractor/report/hls.js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,11 @@ export class BufferController implements ComponentAPI {
// (undocumented)
protected appendChangeType(type: any, mimeType: any): void;
// (undocumented)
appendError: number;
appendErrors: {
audio: number;
video: number;
audiovideo: number;
};
// (undocumented)
bufferCodecEventsExpected: number;
// (undocumented)
Expand Down Expand Up @@ -977,10 +981,14 @@ export interface ErrorData {
// (undocumented)
parent?: PlaylistLevelType;
// (undocumented)
part?: Part | null;
// (undocumented)
reason?: string;
// (undocumented)
response?: LoaderResponse;
// (undocumented)
sourceBufferName?: SourceBufferName;
// (undocumented)
stats?: LoaderStats;
// (undocumented)
type: ErrorTypes;
Expand Down
24 changes: 16 additions & 8 deletions src/controller/buffer-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
BufferFlushingData,
FragParsedData,
FragChangedData,
ErrorData,
} from '../types/events';
import type { ComponentAPI } from '../types/component-api';
import type { ChunkMetadata } from '../types/transmuxer';
Expand Down Expand Up @@ -61,7 +62,11 @@ export default class BufferController implements ComponentAPI {
private lastMpegAudioChunk: ChunkMetadata | null = null;

// counters
public appendError: number = 0;
public appendErrors = {
audio: 0,
video: 0,
audiovideo: 0,
};

public tracks: TrackSet = {};
public pendingTracks: TrackSet = {};
Expand Down Expand Up @@ -400,7 +405,7 @@ export default class BufferController implements ComponentAPI {
for (const type in sourceBuffer) {
timeRanges[type] = BufferHelper.getBuffered(sourceBuffer[type]);
}
this.appendError = 0;
this.appendErrors[type] = 0;
this.hls.trigger(Events.BUFFER_APPENDED, {
type,
frag,
Expand All @@ -412,10 +417,11 @@ export default class BufferController implements ComponentAPI {
},
onError: (err) => {
// in case any error occured while appending, put back segment in segments table
const event = {
const event: ErrorData = {
type: ErrorTypes.MEDIA_ERROR,
parent: frag.type,
details: ErrorDetails.BUFFER_APPEND_ERROR,
sourceBufferName: type,
frag,
part,
chunkMeta,
Expand All @@ -429,15 +435,15 @@ export default class BufferController implements ComponentAPI {
// let's stop appending any segments, and report BUFFER_FULL_ERROR error
event.details = ErrorDetails.BUFFER_FULL_ERROR;
} else {
this.appendError++;
const appendErrorCount = ++this.appendErrors[type];
event.details = ErrorDetails.BUFFER_APPEND_ERROR;
/* with UHD content, we could get loop of quota exceeded error until
browser is able to evict some data from sourcebuffer. Retrying can help recover.
*/
if (this.appendError > hls.config.appendErrorMaxRetry) {
this.error(
`Failed ${hls.config.appendErrorMaxRetry} times to append segment in sourceBuffer`
);
this.warn(
`Failed ${appendErrorCount}/${hls.config.appendErrorMaxRetry} times to append segment in "${type}" sourceBuffer`
);
if (appendErrorCount > hls.config.appendErrorMaxRetry) {
event.fatal = true;
}
}
Expand Down Expand Up @@ -779,6 +785,7 @@ export default class BufferController implements ComponentAPI {
details: ErrorDetails.BUFFER_ADD_CODEC_ERROR,
fatal: false,
error: err,
sourceBufferName: trackName as SourceBufferName,
mimeType: mimeType,
});
}
Expand Down Expand Up @@ -841,6 +848,7 @@ export default class BufferController implements ComponentAPI {
this.hls.trigger(Events.ERROR, {
type: ErrorTypes.MEDIA_ERROR,
details: ErrorDetails.BUFFER_APPENDING_ERROR,
sourceBufferName: type,
error,
fatal: false,
});
Expand Down
2 changes: 2 additions & 0 deletions src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export interface ErrorData {
context?: PlaylistLoaderContext;
event?: keyof HlsListeners | 'demuxerWorker';
frag?: Fragment;
part?: Part | null;
level?: number | undefined;
levelRetry?: boolean;
loader?: Loader<LoaderContext>;
Expand All @@ -243,6 +244,7 @@ export interface ErrorData {
response?: LoaderResponse;
url?: string;
parent?: PlaylistLevelType;
sourceBufferName?: SourceBufferName;
/**
* @deprecated Use ErrorData.error
*/
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/controller/buffer-controller-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ describe('BufferController', function () {
).to.have.been.calledWith(Events.ERROR, {
type: ErrorTypes.MEDIA_ERROR,
details: ErrorDetails.BUFFER_APPENDING_ERROR,
sourceBufferName: triggerSpy.getCall(0).lastArg.sourceBufferName,
error: triggerSpy.getCall(0).lastArg.error,
fatal: false,
});
Expand Down Expand Up @@ -251,6 +252,7 @@ describe('BufferController', function () {
).to.have.been.calledWith(Events.ERROR, {
type: ErrorTypes.MEDIA_ERROR,
details: ErrorDetails.BUFFER_APPEND_ERROR,
sourceBufferName: triggerSpy.getCall(0).lastArg.sourceBufferName,
parent: 'main',
frag,
part: undefined,
Expand Down

0 comments on commit b71f61d

Please sign in to comment.