forked from video-dev/hls.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput-filter.ts
46 lines (39 loc) · 1.21 KB
/
output-filter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import type { TimelineController } from '../controller/timeline-controller';
import type { CaptionScreen } from './cea-608-parser';
export default class OutputFilter {
private timelineController: TimelineController;
private cueRanges: Array<[number, number]> = [];
private trackName: string;
private startTime: number | null = null;
private endTime: number | null = null;
private screen: CaptionScreen | null = null;
constructor(timelineController: TimelineController, trackName: string) {
this.timelineController = timelineController;
this.trackName = trackName;
}
dispatchCue() {
if (this.startTime === null) {
return;
}
this.timelineController.addCues(
this.trackName,
this.startTime,
this.endTime as number,
this.screen as CaptionScreen,
this.cueRanges
);
this.startTime = null;
}
newCue(startTime: number, endTime: number, screen: CaptionScreen) {
if (this.startTime === null || this.startTime > startTime) {
this.startTime = startTime;
}
this.endTime = endTime;
this.screen = screen;
this.timelineController.createCaptionsTrack(this.trackName);
}
reset() {
this.cueRanges = [];
this.startTime = null;
}
}