Skip to content

Commit

Permalink
Fix regression introduced with #5689 Lazy init CEA608 parsers found in
Browse files Browse the repository at this point in the history
  • Loading branch information
robwalch committed Nov 21, 2023
1 parent 161da8b commit 19d1edc
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions src/controller/timeline-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ export class TimelineController implements ComponentAPI {
hls.on(Events.BUFFER_FLUSHING, this.onBufferFlushing, this);
}

private initCea608Parsers() {
const { cea608Parser1, cea608Parser2 } = this;
if (this.config.enableCEA708Captions && !(cea608Parser1 && cea608Parser2)) {
const channel1 = new OutputFilter(this, 'textTrack1');
const channel2 = new OutputFilter(this, 'textTrack2');
const channel3 = new OutputFilter(this, 'textTrack3');
const channel4 = new OutputFilter(this, 'textTrack4');
this.cea608Parser1 = new Cea608Parser(1, channel1, channel2);
this.cea608Parser2 = new Cea608Parser(3, channel3, channel4);
}
}

public destroy(): void {
const { hls } = this;
hls.off(Events.MEDIA_ATTACHING, this.onMediaAttaching, this);
Expand All @@ -131,21 +143,8 @@ export class TimelineController implements ComponentAPI {
hls.off(Events.SUBTITLE_TRACKS_CLEARED, this.onSubtitleTracksCleared, this);
hls.off(Events.BUFFER_FLUSHING, this.onBufferFlushing, this);
// @ts-ignore
this.hls = this.config = this.cea608Parser1 = this.cea608Parser2 = null;
}

private lazyInit608() {
if (
this.config.enableCEA708Captions &&
(!this.cea608Parser1 || !this.cea608Parser2)
) {
const channel1 = new OutputFilter(this, 'textTrack1');
const channel2 = new OutputFilter(this, 'textTrack2');
const channel3 = new OutputFilter(this, 'textTrack3');
const channel4 = new OutputFilter(this, 'textTrack4');
this.cea608Parser1 = new Cea608Parser(1, channel1, channel2);
this.cea608Parser2 = new Cea608Parser(3, channel3, channel4);
}
this.hls = this.config = null;
this.cea608Parser1 = this.cea608Parser2 = undefined;
}

public addCues(
Expand Down Expand Up @@ -467,6 +466,7 @@ export class TimelineController implements ComponentAPI {
}

private onFragLoading(event: Events.FRAG_LOADING, data: FragLoadingData) {
this.initCea608Parsers();
const { cea608Parser1, cea608Parser2, lastCc, lastSn, lastPartIndex } =
this;
if (!this.enabled || !(cea608Parser1 && cea608Parser2)) {
Expand Down Expand Up @@ -667,7 +667,9 @@ export class TimelineController implements ComponentAPI {
event: Events.FRAG_PARSING_USERDATA,
data: FragParsingUserdataData,
) {
if (!this.enabled) {
this.initCea608Parsers();
const { cea608Parser1, cea608Parser2 } = this;
if (!this.enabled || !(cea608Parser1 && cea608Parser2)) {
return;
}
const { frag, samples } = data;
Expand All @@ -677,11 +679,6 @@ export class TimelineController implements ComponentAPI {
) {
return;
}
this.lazyInit608();
const { cea608Parser1, cea608Parser2 } = this;
if (!cea608Parser1 || !cea608Parser2) {
return;
}
// If the event contains captions (found in the bytes property), push all bytes into the parser immediately
// It will create the proper timestamps based on the PTS value
for (let i = 0; i < samples.length; i++) {
Expand Down

0 comments on commit 19d1edc

Please sign in to comment.