From ccab4423d761439e866a20049206553692c042f1 Mon Sep 17 00:00:00 2001 From: Rob Walch Date: Thu, 8 Jun 2023 17:20:44 -0700 Subject: [PATCH] Clear CEA-608 captions on discontinuity --- src/controller/timeline-controller.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/controller/timeline-controller.ts b/src/controller/timeline-controller.ts index d8c2a5b1f5a..c9a87c6bd27 100644 --- a/src/controller/timeline-controller.ts +++ b/src/controller/timeline-controller.ts @@ -62,9 +62,10 @@ export class TimelineController implements ComponentAPI { private nonNativeCaptionsTracks: Record = {}; private cea608Parser1!: Cea608Parser; private cea608Parser2!: Cea608Parser; - private lastSn: number = -1; - private lastPartIndex: number = -1; - private prevCC: number = -1; + private lastCc: number = -1; // Last video (CEA-608) fragment CC + private lastSn: number = -1; // Last video (CEA-608) fragment MSN + private lastPartIndex: number = -1; // Last video (CEA-608) fragment Part Index + private prevCC: number = -1; // Last subtitle fragment CC private vttCCs: VTTCCs = newVTTCCs(); private captionsProperties: { textTrack1: TrackProperties; @@ -295,10 +296,14 @@ export class TimelineController implements ComponentAPI { } private onManifestLoading() { - this.lastSn = -1; // Detect discontinuity in fragment parsing + // Detect discontinuity in video fragment (CEA-608) parsing + this.lastCc = -1; + this.lastSn = -1; this.lastPartIndex = -1; + // Detect discontinuity in subtitle manifests this.prevCC = -1; - this.vttCCs = newVTTCCs(); // Detect discontinuity in subtitle manifests + this.vttCCs = newVTTCCs(); + // Reset tracks this._cleanTracks(); this.tracks = []; this.captionsTracks = {}; @@ -450,23 +455,26 @@ export class TimelineController implements ComponentAPI { } private onFragLoading(event: Events.FRAG_LOADING, data: FragLoadingData) { - const { cea608Parser1, cea608Parser2, lastSn, lastPartIndex } = this; + const { cea608Parser1, cea608Parser2, lastCc, lastSn, lastPartIndex } = + this; 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 if (data.frag.type === PlaylistLevelType.MAIN) { - const sn = data.frag.sn; + const { cc, sn } = data.frag; const partIndex = data?.part?.index ?? -1; if ( !( sn === lastSn + 1 || - (sn === lastSn && partIndex === lastPartIndex + 1) + (sn === lastSn && partIndex === lastPartIndex + 1) || + cc === lastCc ) ) { cea608Parser1.reset(); cea608Parser2.reset(); } + this.lastCc = cc as number; this.lastSn = sn as number; this.lastPartIndex = partIndex; }