From 19d1edc08041b57ef69bc8be8fb22c8edc9cae12 Mon Sep 17 00:00:00 2001 From: Rob Walch Date: Mon, 20 Nov 2023 14:14:08 -0800 Subject: [PATCH] Fix regression introduced with #5689 Lazy init CEA608 parsers found in #5953 --- src/controller/timeline-controller.ts | 39 +++++++++++++-------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/controller/timeline-controller.ts b/src/controller/timeline-controller.ts index 4fe852d8a77..c9698a035de 100644 --- a/src/controller/timeline-controller.ts +++ b/src/controller/timeline-controller.ts @@ -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); @@ -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( @@ -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)) { @@ -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; @@ -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++) {