Home Reference Source

src/utils/output-filter.ts

  1. import type { TimelineController } from '../controller/timeline-controller';
  2. import type { CaptionScreen } from './cea-608-parser';
  3.  
  4. export default class OutputFilter {
  5. private timelineController: TimelineController;
  6. private cueRanges: Array<[number, number]> = [];
  7. private trackName: string;
  8. private startTime: number | null = null;
  9. private endTime: number | null = null;
  10. private screen: CaptionScreen | null = null;
  11.  
  12. constructor(timelineController: TimelineController, trackName: string) {
  13. this.timelineController = timelineController;
  14. this.trackName = trackName;
  15. }
  16.  
  17. dispatchCue() {
  18. if (this.startTime === null) {
  19. return;
  20. }
  21.  
  22. this.timelineController.addCues(
  23. this.trackName,
  24. this.startTime,
  25. this.endTime as number,
  26. this.screen as CaptionScreen,
  27. this.cueRanges
  28. );
  29. this.startTime = null;
  30. }
  31.  
  32. newCue(startTime: number, endTime: number, screen: CaptionScreen) {
  33. if (this.startTime === null || this.startTime > startTime) {
  34. this.startTime = startTime;
  35. }
  36.  
  37. this.endTime = endTime;
  38. this.screen = screen;
  39. this.timelineController.createCaptionsTrack(this.trackName);
  40. }
  41.  
  42. reset() {
  43. this.cueRanges = [];
  44. this.startTime = null;
  45. }
  46. }