From f116ec803b689ef2f90c4c476a396b39f5d8cae5 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 | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/controller/timeline-controller.ts b/src/controller/timeline-controller.ts index 4fe852d8a77..dc5c05192a5 100644 --- a/src/controller/timeline-controller.ts +++ b/src/controller/timeline-controller.ts @@ -131,10 +131,11 @@ 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; + this.hls = this.config = null; + this.cea608Parser1 = this.cea608Parser2 = undefined; } - private lazyInit608() { + private initCea608Parsers() { if ( this.config.enableCEA708Captions && (!this.cea608Parser1 || !this.cea608Parser2) @@ -467,9 +468,10 @@ 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)) { + if (!this.enabled || !cea608Parser1 || !cea608Parser2) { return; } // if this frag isn't contiguous, clear the parser so cues with bad start/end times aren't added to the textTrack @@ -667,7 +669,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 +681,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++) {