@svta/cml-608 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,3 +13,40 @@ npm i @svta/cml-608
13
13
  ```typescript
14
14
  import { CaptionScreen, Row } from "@svta/cml-608";
15
15
  ```
16
+
17
+ ### Extracting captions from a media sample
18
+
19
+ CTA-608 captions ride inside the video elementary stream as an ATSC A/53 `cc_data()`
20
+ payload. The payload is the same for every codec; only the envelope around it differs, so
21
+ pick the extractor that matches the sample entry type:
22
+
23
+ | Sample entry | Envelope | Extractor |
24
+ | ----------------------- | --------------------------------- | ---------------------------------- |
25
+ | `avc1` / `hvc1` / `vvc1` | `itu_t_t35` SEI message in a NAL | `extractCta608DataFromSample` |
26
+ | `av01` | `metadata_itu_t_t35` OBU | `extractCta608DataFromAv1Sample` |
27
+
28
+ Both return the same `[field1, field2]` byte arrays, which `Cta608Parser` turns into
29
+ rendered caption screens:
30
+
31
+ ```typescript
32
+ import { Cta608Parser, extractCta608DataFromAv1Sample } from "@svta/cml-608";
33
+
34
+ const parser = new Cta608Parser(1, {
35
+ newCue(startTime, endTime, screen) {
36
+ console.log(startTime, endTime, screen.getDisplayText());
37
+ },
38
+ }, null);
39
+
40
+ const [field1] = extractCta608DataFromAv1Sample(view, samplePos, sampleSize);
41
+ if (field1.length) {
42
+ parser.addData(sampleTimeMs, field1);
43
+ }
44
+ ```
45
+
46
+ These are separate functions rather than one auto-detecting call because the two carriages
47
+ are framed differently and neither sample announces which it is. A NAL unit sample puts a
48
+ fixed-width big-endian length in front of each unit, and that width is only known from
49
+ `lengthSizeMinusOne` in the `avcC`/`hvcC` config. An AV1 sample uses the low-overhead
50
+ format, where each OBU carries its own `obu_size` after the header — and may omit it on
51
+ the last OBU. Either way the framing has to come from the sample entry, so pass the bytes
52
+ to the extractor that matches it.
package/dist/index.d.ts CHANGED
@@ -341,6 +341,35 @@ declare class Cta608Parser {
341
341
  */
342
342
  declare function extractCta608Data(raw: DataView, cta608Range: number[]): number[][];
343
343
  //#endregion
344
+ //#region src/extractCta608DataFromAv1Sample.d.ts
345
+ /**
346
+ * Extracts CTA-608 data from an AV1 (`av01`) sample.
347
+ *
348
+ * AV1 has no NAL units, so captions ride in an `metadata_itu_t_t35` OBU rather than in
349
+ * an SEI message. The caption payload is unchanged — the same A/53 `cc_data()` under the
350
+ * same T.35/GA94 identifier that {@link extractCta608DataFromSample} reads — so the
351
+ * returned field data feeds {@link Cta608Parser} identically.
352
+ *
353
+ * This is a separate function rather than a codec branch inside
354
+ * {@link extractCta608DataFromSample} because the two carriages are framed differently and
355
+ * neither sample is self-identifying. A NAL unit sample puts a fixed-width big-endian
356
+ * length in front of each unit, and that width is only known from `lengthSizeMinusOne` in
357
+ * the `avcC`/`hvcC` config. An AV1 sample uses the low-overhead format, where each OBU
358
+ * carries its own `obu_size` after the header — and may omit it on the last OBU. Select on
359
+ * the sample entry type (`av01`) instead.
360
+ *
361
+ * @param raw - The DataView with media data
362
+ * @param startPos - The start position of the sample within the DataView
363
+ * @param sampleSize - The size of the sample in bytes
364
+ * @returns fieldData array containing field 1 and field 2 data arrays
365
+ *
366
+ * @example
367
+ * {@includeCode ../test/extractCta608DataFromAv1Sample.test.ts#example}
368
+ *
369
+ * @public
370
+ */
371
+ declare function extractCta608DataFromAv1Sample(raw: DataView, startPos: number, sampleSize: number): number[][];
372
+ //#endregion
344
373
  //#region src/extractCta608DataFromSample.d.ts
345
374
  /**
346
375
  * Extracts CEA-608 data from a given sample.
@@ -417,5 +446,5 @@ declare class SccParser {
417
446
  getLinesParsed(): number;
418
447
  }
419
448
  //#endregion
420
- export { CaptionModes, CaptionScreen, CaptionsLogger, Cta608Channel, Cta608Parser, CueHandler, PACData, PenState, PenStyles, Row, SccParser, StyledUnicodeChar, SupportedField, VerboseLevel, extractCta608Data, extractCta608DataFromSample, findCta608Nalus };
449
+ export { CaptionModes, CaptionScreen, CaptionsLogger, Cta608Channel, Cta608Parser, CueHandler, PACData, PenState, PenStyles, Row, SccParser, StyledUnicodeChar, SupportedField, VerboseLevel, extractCta608Data, extractCta608DataFromAv1Sample, extractCta608DataFromSample, findCta608Nalus };
421
450
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/CaptionModes.ts","../src/VerboseLevel.ts","../src/CaptionsLogger.ts","../src/PACData.ts","../src/PenStyles.ts","../src/PenState.ts","../src/StyledUnicodeChar.ts","../src/Row.ts","../src/CaptionScreen.ts","../src/CueHandler.ts","../src/Cta608Channel.ts","../src/SupportedField.ts","../src/Cta608Parser.ts","../src/extractCta608Data.ts","../src/extractCta608DataFromSample.ts","../src/findCta608Nalus.ts","../src/SccParser.ts"],"sourcesContent":[],"mappings":";;;;;;;AAKA;;KAAY,YAAA;;;;;AAAZ;;;;ACKA;AAYA;cAZa;;;ECmCb,SAAa,OAAA,EAAA,CAAA;;;;ACxCb,CAAA;;;;ACAY,KHiBA,YAAA,GAAe,OGjBf,CAAA,OHiB8B,YGjB9B,CAAA;;;;;;;;;AG8CC,cLNA,cAAA,CKMA;EACE,IAAA,EAAA,MAAA,GAAA,IAAA;EAOM,YAAA,ELZC,YKYD;EAON,GAAA,CAAA,QAAA,ELjBA,YKiBA,EAAA,GAAA,EAAA,MAAA,GAAA,CAAA,GAAA,GAAA,MAAA,CAAA,CAAA,EAAA,IAAA;;;;;;;AP7Df;;KGAY,OAAA;;EFKZ,MAAa,EAAA,MAAA,GAAA,IAAA;EAYb,KAAY,EAAA,MAAA,GAAA,IAAA;;;;;;;;;ADjBZ;;KIAY,SAAA;;EHKZ,SAAa,EAAA,OAAA;EAYb,OAAY,EAAA,OAAA;;;;;;;;;;;;AM6BC,cFNA,QAAA,CEMA;EACE,UAAA,EAAA,MAAA;EAOM,SAAA,EAAA,OAAA;EAON,OAAA,EAAA,OAAA;EASF,UAAA,EAAA,MAAA;EA0HiB,KAAA,EAAA,OAAA;EAAR,K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;;;;;;AfPrC;;;;ACKA;AAYA;;;;ACuBA;;;;ACxCA;;;;ACAA;;;;ACwCA;;;;;;;;;ACAA;;AASqC,cUlBxB,SAAA,CVkBwB;EAKX,SAAA,EAAA,OAAA;EAIX,aAAA,EAAA,MAAA;EAIA,SAAA,EAAA,GAAA;EAAA,KAAA,EAAA,MAAA,GAAA,GAAA;;;;EChBf,aAAa,CAAA,OAAA,EAAA,MAAA,CAAA,EAAA,MAAA;EACE,eAAA,CAAA,CAAA,EAAA,OAAA;EAOM,QAAA,CAAA,CAAA,EAAA,MAAA,GAAA,GAAA;EAON,cAAA,CAAA,CAAA,EAAA,MAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/CaptionModes.ts","../src/VerboseLevel.ts","../src/CaptionsLogger.ts","../src/PACData.ts","../src/PenStyles.ts","../src/PenState.ts","../src/StyledUnicodeChar.ts","../src/Row.ts","../src/CaptionScreen.ts","../src/CueHandler.ts","../src/Cta608Channel.ts","../src/SupportedField.ts","../src/Cta608Parser.ts","../src/extractCta608Data.ts","../src/extractCta608DataFromAv1Sample.ts","../src/extractCta608DataFromSample.ts","../src/findCta608Nalus.ts","../src/SccParser.ts"],"sourcesContent":[],"mappings":";;;;;;;AAKA;;KAAY,YAAA;;;;;AAAZ;;;;ACKA;AAYA;cAZa;;;ECmCb,SAAa,OAAA,EAAA,CAAA;;;;ACxCb,CAAA;;;;ACAY,KHiBA,YAAA,GAAe,OGjBf,CAAA,OHiB8B,YGjB9B,CAAA;;;;;;;;;AG8CC,cLNA,cAAA,CKMA;EACE,IAAA,EAAA,MAAA,GAAA,IAAA;EAOM,YAAA,ELZC,YKYD;EAON,GAAA,CAAA,QAAA,ELjBA,YKiBA,EAAA,GAAA,EAAA,MAAA,GAAA,CAAA,GAAA,GAAA,MAAA,CAAA,CAAA,EAAA,IAAA;;;;;;;AP7Df;;KGAY,OAAA;;EFKZ,MAAa,EAAA,MAAA,GAAA,IAAA;EAYb,KAAY,EAAA,MAAA,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QAAA,UAAA;EAAR;;;;;;;;;AC9GhB;;;;AC8CA;;EAGO,cAAA,CAAA,CAAA,EAAA,MAAA,CAAA,EAAA,IAAA;;;;;;;AVnDP;;;;ACKA;AAYA;iBYXgB,iBAAA,MAAuB;;;;;;AbNvC;;;;ACKA;AAYA;;;;ACuBA;;;;ACxCA;;;;ACAA;;;;ACwCA;;AAemB,iBShCH,8BAAA,CTgCG,GAAA,EShCiC,QTgCjC,EAAA,QAAA,EAAA,MAAA,EAAA,UAAA,EAAA,MAAA,CAAA,EAAA,MAAA,EAAA,EAAA;;;;;;ALvDnB;;;;ACKA;AAYA;;iBcNgB,2BAAA,MAAiC;;;;;;AfXjD;;;;ACKA;AAYA;;iBeVgB,eAAA,MAAqB;;;;;;AhBPrC;;;;ACKA;AAYA;;;;ACuBA;;;;ACxCA;;;;ACAA;;;;ACwCA;;;;;;;;;ACAA;;AASqC,cWlBxB,SAAA,CXkBwB;EAKX,SAAA,EAAA,OAAA;EAIX,aAAA,EAAA,MAAA;EAIA,SAAA,EAAA,GAAA;EAAA,KAAA,EAAA,MAAA,GAAA,GAAA;;;;EChBf,aAAa,CAAA,OAAA,EAAA,MAAA,CAAA,EAAA,MAAA;EACE,eAAA,CAAA,CAAA,EAAA,OAAA;EAOM,QAAA,CAAA,CAAA,EAAA,MAAA,GAAA,GAAA;EAON,cAAA,CAAA,CAAA,EAAA,MAAA"}
package/dist/index.js CHANGED
@@ -621,6 +621,7 @@ var Cta608Channel = class {
621
621
  else styles.foreground = "white";
622
622
  this.logger.log(VerboseLevel.INFO, "MIDROW: " + JSON.stringify(styles));
623
623
  this.writeScreen.setPen(styles);
624
+ this.writeScreen.moveCursor(1);
624
625
  }
625
626
  outputDataUpdate(dispatch = false) {
626
627
  const time = this.logger.time;
@@ -983,6 +984,47 @@ var Cta608Parser = class {
983
984
  }
984
985
  };
985
986
 
987
+ //#endregion
988
+ //#region src/utils/parseCcData.ts
989
+ function isCCType(type) {
990
+ return type === 0 || type === 1;
991
+ }
992
+ function isNonEmptyCCData(ccData1, ccData2) {
993
+ return (ccData1 & 127) > 0 || (ccData2 & 127) > 0;
994
+ }
995
+ /**
996
+ * Parse an ATSC A/53 Part 4 `cc_data()` structure into per-field byte pairs.
997
+ *
998
+ * The payload is identical for every carriage format — an AVC/HEVC/VVC SEI message and
999
+ * an AV1 `metadata_itu_t_t35` OBU carry the same bytes under the same T.35/GA94
1000
+ * identifier — so this is the single parser shared by all of them. Only the envelope
1001
+ * around it differs.
1002
+ *
1003
+ * `cc_data()` is self-delimiting: `cc_count` states how many 3-byte constructs follow,
1004
+ * so anything after them (SEI `rbsp_trailing_bits`, an AV1 OBU `trailing_bits` byte) is
1005
+ * ignored without needing to be recognized.
1006
+ *
1007
+ * @param raw - The DataView holding the `cc_data()` structure
1008
+ * @param pos - The position of the first `cc_data()` byte, holding `cc_count`
1009
+ * @param endPos - The exclusive upper bound to read within
1010
+ * @param fieldData - Field 1 and field 2 byte arrays, appended to in place
1011
+ */
1012
+ function parseCcData(raw, pos, endPos, fieldData) {
1013
+ if (pos + 2 > endPos) return;
1014
+ const ccCount = raw.getUint8(pos) & 31;
1015
+ let cursor = pos + 2;
1016
+ const ccEnd = Math.min(cursor + ccCount * 3, endPos);
1017
+ for (; cursor + 2 < ccEnd; cursor += 3) {
1018
+ const byte = raw.getUint8(cursor);
1019
+ if (!(byte & 4)) continue;
1020
+ const ccType = byte & 3;
1021
+ if (!isCCType(ccType)) continue;
1022
+ const ccData1 = raw.getUint8(cursor + 1);
1023
+ const ccData2 = raw.getUint8(cursor + 2);
1024
+ if (isNonEmptyCCData(ccData1, ccData2)) fieldData[ccType].push(ccData1, ccData2);
1025
+ }
1026
+ }
1027
+
986
1028
  //#endregion
987
1029
  //#region src/extractCta608Data.ts
988
1030
  /**
@@ -995,29 +1037,163 @@ var Cta608Parser = class {
995
1037
  * @public
996
1038
  */
997
1039
  function extractCta608Data(raw, cta608Range) {
998
- let pos = cta608Range[0];
999
1040
  const fieldData = [[], []];
1000
- pos += 8;
1001
- const ccCount = raw.getUint8(pos) & 31;
1002
- pos += 2;
1003
- for (let i = 0; i < ccCount; i++) {
1004
- const byte = raw.getUint8(pos);
1005
- const ccValid = byte & 4;
1006
- const ccType = byte & 3;
1007
- pos++;
1008
- const ccData1 = raw.getUint8(pos);
1009
- pos++;
1010
- const ccData2 = raw.getUint8(pos);
1011
- pos++;
1012
- if (ccValid && (ccData1 & 127) + (ccData2 & 127) !== 0) {
1013
- if (ccType === 0) {
1014
- fieldData[0].push(ccData1);
1015
- fieldData[0].push(ccData2);
1016
- } else if (ccType === 1) {
1017
- fieldData[1].push(ccData1);
1018
- fieldData[1].push(ccData2);
1019
- }
1020
- }
1041
+ parseCcData(raw, cta608Range[0] + 8, cta608Range[0] + cta608Range[1], fieldData);
1042
+ return fieldData;
1043
+ }
1044
+
1045
+ //#endregion
1046
+ //#region src/utils/isCta608UserData.ts
1047
+ /**
1048
+ * The 8-byte ATSC A/53 user identifier that prefixes a `cc_data()` payload, per
1049
+ * ANSI-SCTE 128: `itu_t_t35_country_code` (0xB5, USA), `terminal_provider_code`
1050
+ * (0x0031, ATSC), `terminal_provider_oriented_code` ('GA94'), and
1051
+ * `user_data_type_code` (0x03, cc_data).
1052
+ *
1053
+ * Both carriage formats use it unchanged — an AVC/HEVC/VVC
1054
+ * `user_data_registered_itu_t_t35` SEI message and an AV1 `metadata_itu_t_t35` OBU — so
1055
+ * this identifies CTA-608 user data for either.
1056
+ *
1057
+ * @param raw - The DataView holding the T.35 payload
1058
+ * @param pos - The position of `itu_t_t35_country_code`
1059
+ * @returns true when the 8 bytes at `pos` identify CTA-608 caption data
1060
+ */
1061
+ function isCta608UserData(raw, pos) {
1062
+ return raw.getUint8(pos) === 181 && raw.getUint16(pos + 1) === 49 && raw.getUint32(pos + 3) === 1195456820 && raw.getUint8(pos + 7) === 3;
1063
+ }
1064
+
1065
+ //#endregion
1066
+ //#region src/utils/obuHelpers.ts
1067
+ /**
1068
+ * AV1 `OBU_METADATA` unit type
1069
+ */
1070
+ const OBU_METADATA = 5;
1071
+ /**
1072
+ * AV1 `METADATA_TYPE_ITUT_T35` metadata type
1073
+ */
1074
+ const METADATA_TYPE_ITUT_T35 = 4;
1075
+ /**
1076
+ * The maximum number of bytes in an AV1 leb128() value
1077
+ */
1078
+ const LEB128_MAX_BYTES = 8;
1079
+ /**
1080
+ * Read an AV1 `leb128()` variable-length integer (AV1 spec section 4.10.5): up to 8
1081
+ * bytes, 7 value bits each, least significant group first, with the high bit marking
1082
+ * continuation.
1083
+ *
1084
+ * Groups are combined by multiplication rather than by `<<`, because a leb128 value may
1085
+ * exceed the 32 bits a JavaScript shift operates on.
1086
+ *
1087
+ * @param raw - The DataView to read from
1088
+ * @param pos - The position of the first leb128 byte
1089
+ * @param endPos - The exclusive upper bound to read within
1090
+ * @returns The value and its byte length, or null when it is truncated or overlong
1091
+ */
1092
+ function readLeb128(raw, pos, endPos) {
1093
+ let value = 0;
1094
+ for (let i = 0; i < LEB128_MAX_BYTES; i++) {
1095
+ if (pos + i >= endPos) return null;
1096
+ const byte = raw.getUint8(pos + i);
1097
+ value += (byte & 127) * 2 ** (i * 7);
1098
+ if (!(byte & 128)) return {
1099
+ value,
1100
+ size: i + 1
1101
+ };
1102
+ }
1103
+ return null;
1104
+ }
1105
+ /**
1106
+ * Detects whether an AV1 OBU header starts an `OBU_METADATA` unit and locates its
1107
+ * payload.
1108
+ *
1109
+ * The header is one byte — `obu_forbidden_bit` (1), `obu_type` (4),
1110
+ * `obu_extension_flag` (1), `obu_has_size_field` (1), `obu_reserved_1bit` (1) — followed
1111
+ * by an optional extension byte and, when `obu_has_size_field` is set, `obu_size` as a
1112
+ * leb128. An OBU without `obu_size` runs to the end of the temporal unit, which mp4
1113
+ * permits only for the final OBU in a sample.
1114
+ *
1115
+ * @param raw - The DataView containing the OBU
1116
+ * @param pos - The position of the OBU header byte
1117
+ * @param endPos - The exclusive end of the enclosing sample
1118
+ * @returns The payload bounds and whether this is a metadata OBU, or null if malformed
1119
+ */
1120
+ function readObu(raw, pos, endPos) {
1121
+ const header = raw.getUint8(pos);
1122
+ if (header & 128) return null;
1123
+ let payloadStart = pos + 1;
1124
+ if (header & 4) payloadStart++;
1125
+ let payloadEnd = endPos;
1126
+ if (header & 2) {
1127
+ const obuSize = readLeb128(raw, payloadStart, endPos);
1128
+ if (!obuSize) return null;
1129
+ payloadStart += obuSize.size;
1130
+ payloadEnd = payloadStart + obuSize.value;
1131
+ if (payloadEnd > endPos) return null;
1132
+ }
1133
+ return {
1134
+ isMetadata: (header >> 3 & 15) === OBU_METADATA,
1135
+ payloadStart,
1136
+ payloadEnd
1137
+ };
1138
+ }
1139
+ /**
1140
+ * Parse CTA-608 field data out of an AV1 metadata OBU payload, ignoring metadata OBUs
1141
+ * of any other type.
1142
+ *
1143
+ * The payload is `metadata_type` as a leb128, then — for ITU-T T.35 — the 8-byte A/53
1144
+ * user identifier and the `cc_data()` structure. Unlike an SEI NAL unit an OBU carries
1145
+ * no emulation prevention, so the bytes are read verbatim.
1146
+ *
1147
+ * @param raw - The DataView containing the OBU payload
1148
+ * @param pos - The position of `metadata_type`
1149
+ * @param endPos - The exclusive end of the OBU payload
1150
+ * @param fieldData - Field 1 and field 2 byte arrays, appended to in place
1151
+ */
1152
+ function parseCta608DataFromMetadataObu(raw, pos, endPos, fieldData) {
1153
+ const metadataType = readLeb128(raw, pos, endPos);
1154
+ if (!metadataType || metadataType.value !== METADATA_TYPE_ITUT_T35) return;
1155
+ const userDataStart = pos + metadataType.size;
1156
+ if (userDataStart + 10 > endPos || !isCta608UserData(raw, userDataStart)) return;
1157
+ parseCcData(raw, userDataStart + 8, endPos, fieldData);
1158
+ }
1159
+
1160
+ //#endregion
1161
+ //#region src/extractCta608DataFromAv1Sample.ts
1162
+ /**
1163
+ * Extracts CTA-608 data from an AV1 (`av01`) sample.
1164
+ *
1165
+ * AV1 has no NAL units, so captions ride in an `metadata_itu_t_t35` OBU rather than in
1166
+ * an SEI message. The caption payload is unchanged — the same A/53 `cc_data()` under the
1167
+ * same T.35/GA94 identifier that {@link extractCta608DataFromSample} reads — so the
1168
+ * returned field data feeds {@link Cta608Parser} identically.
1169
+ *
1170
+ * This is a separate function rather than a codec branch inside
1171
+ * {@link extractCta608DataFromSample} because the two carriages are framed differently and
1172
+ * neither sample is self-identifying. A NAL unit sample puts a fixed-width big-endian
1173
+ * length in front of each unit, and that width is only known from `lengthSizeMinusOne` in
1174
+ * the `avcC`/`hvcC` config. An AV1 sample uses the low-overhead format, where each OBU
1175
+ * carries its own `obu_size` after the header — and may omit it on the last OBU. Select on
1176
+ * the sample entry type (`av01`) instead.
1177
+ *
1178
+ * @param raw - The DataView with media data
1179
+ * @param startPos - The start position of the sample within the DataView
1180
+ * @param sampleSize - The size of the sample in bytes
1181
+ * @returns fieldData array containing field 1 and field 2 data arrays
1182
+ *
1183
+ * @example
1184
+ * {@includeCode ../test/extractCta608DataFromAv1Sample.test.ts#example}
1185
+ *
1186
+ * @public
1187
+ */
1188
+ function extractCta608DataFromAv1Sample(raw, startPos, sampleSize) {
1189
+ const fieldData = [[], []];
1190
+ const endPos = Math.min(startPos + sampleSize, raw.byteLength);
1191
+ let cursor = startPos;
1192
+ while (cursor < endPos) {
1193
+ const obu = readObu(raw, cursor, endPos);
1194
+ if (!obu) break;
1195
+ if (obu.isMetadata) parseCta608DataFromMetadataObu(raw, obu.payloadStart, obu.payloadEnd, fieldData);
1196
+ cursor = Math.max(obu.payloadEnd, cursor + 1);
1021
1197
  }
1022
1198
  return fieldData;
1023
1199
  }
@@ -1035,17 +1211,7 @@ function getSeiData(raw, startPos, endPos) {
1035
1211
  }
1036
1212
  function isCea608Sei(payloadType, payloadSize, sei, pos) {
1037
1213
  if (payloadType !== 4 || payloadSize < 8) return false;
1038
- if (sei.getUint8(pos) !== 181) return false;
1039
- if (sei.getUint16(pos + 1) !== 49) return false;
1040
- if (sei.getUint32(pos + 3) !== 1195456820) return false;
1041
- if (sei.getUint8(pos + 7) !== 3) return false;
1042
- return true;
1043
- }
1044
- function isCCType(type) {
1045
- return type === 0 || type === 1;
1046
- }
1047
- function isNonEmptyCCData(ccData1, ccData2) {
1048
- return (ccData1 & 127) > 0 || (ccData2 & 127) > 0;
1214
+ return isCta608UserData(sei, pos);
1049
1215
  }
1050
1216
  /**
1051
1217
  * H.264 SEI NAL unit type
@@ -1112,21 +1278,7 @@ function parseCta608DataFromSei(sei, fieldData) {
1112
1278
  do
1113
1279
  payloadSize += now = sei.getUint8(cursor++);
1114
1280
  while (now === 255);
1115
- if (isCea608Sei(payloadType, payloadSize, sei, cursor)) {
1116
- const pos = cursor + 10;
1117
- const ccCount = pos + (sei.getUint8(pos - 2) & 31) * 3;
1118
- for (let i = pos; i < ccCount; i += 3) {
1119
- const byte = sei.getUint8(i);
1120
- if (byte & 4) {
1121
- const ccType = byte & 3;
1122
- if (isCCType(ccType)) {
1123
- const ccData1 = sei.getUint8(i + 1);
1124
- const ccData2 = sei.getUint8(i + 2);
1125
- if (isNonEmptyCCData(ccData1, ccData2)) fieldData[ccType].push(ccData1, ccData2);
1126
- }
1127
- }
1128
- }
1129
- }
1281
+ if (isCea608Sei(payloadType, payloadSize, sei, cursor)) parseCcData(sei, cursor + 8, cursor + payloadSize, fieldData);
1130
1282
  cursor += payloadSize;
1131
1283
  }
1132
1284
  }
@@ -1308,5 +1460,5 @@ var SccParser = class {
1308
1460
  };
1309
1461
 
1310
1462
  //#endregion
1311
- export { CaptionScreen, CaptionsLogger, Cta608Channel, Cta608Parser, PenState, Row, SccParser, StyledUnicodeChar, VerboseLevel, extractCta608Data, extractCta608DataFromSample, findCta608Nalus };
1463
+ export { CaptionScreen, CaptionsLogger, Cta608Channel, Cta608Parser, PenState, Row, SccParser, StyledUnicodeChar, VerboseLevel, extractCta608Data, extractCta608DataFromAv1Sample, extractCta608DataFromSample, findCta608Nalus };
1312
1464
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["m: string","specialCea608CharsCodes: Record<number, number>","i: number","chars: string[]","styles: PenStyles","displayText: string[]","styles: Partial<PenStyles>","backgroundColors: string[]","hexArray: string[]","rowsHighCh1: Record<number, number>","rowsHighCh2: Record<number, number>","rowsLowCh1: Record<number, number>","rowsLowCh2: Record<number, number>","cmdFound: boolean","charsFound: number[] | null","chNr: number","row: number","chNr: Channels","pacData: PACData","channelNr: Channels","charCodes: number[]","charCode1: number | null","oneCode: number","index: number","bkgData: Partial<PenStyles>","fieldData: number[][]","ccData1: number","ccData2: number","data: number[]","nalSize: number","fieldData: number[][]","raw","ceaData: number[]"],"sources":["../src/VerboseLevel.ts","../src/CaptionsLogger.ts","../src/PenState.ts","../src/StyledUnicodeChar.ts","../src/utils/NR_COLS.ts","../src/utils/specialCea608CharsCodes.ts","../src/utils/getCharForByte.ts","../src/Row.ts","../src/utils/NR_ROWS.ts","../src/CaptionScreen.ts","../src/Cta608Channel.ts","../src/utils/backgroundColors.ts","../src/utils/createCmdHistory.ts","../src/utils/hasCmdRepeated.ts","../src/utils/numArrayToHexArray.ts","../src/utils/rowsHighCh1.ts","../src/utils/rowsHighCh2.ts","../src/utils/rowsLowCh1.ts","../src/utils/rowsLowCh2.ts","../src/utils/setLastCmd.ts","../src/Cta608Parser.ts","../src/extractCta608Data.ts","../src/utils/seiHelpers.ts","../src/extractCta608DataFromSample.ts","../src/findCta608Nalus.ts","../src/SccParser.ts"],"sourcesContent":["import type { ValueOf } from '@svta/cml-utils'\n\n/**\n * Logging levels for the CTA-608 parser.\n *\n *\n * @enum\n *\n * @public\n */\nexport const VerboseLevel = {\n\tERROR: 0,\n\tTEXT: 1,\n\tWARNING: 2,\n\tINFO: 2,\n\tDEBUG: 3,\n\tDATA: 3,\n} as const\n\n/**\n * @public\n */\nexport type VerboseLevel = ValueOf<typeof VerboseLevel>;\n","/**\n *\n * This code was ported from the dash.js project at:\n * https://github.com/Dash-Industry-Forum/dash.js/blob/development/externals/cea608-parser.js\n * https://github.com/Dash-Industry-Forum/dash.js/commit/8269b26a761e0853bb21d78780ed945144ecdd4d#diff-71bc295a2d6b6b7093a1d3290d53a4b2\n *\n * The original copyright appears below:\n *\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2015-2016, DASH Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * 2. Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport { VerboseLevel } from './VerboseLevel.ts'\n\n/**\n * CaptionsLogger. To be removed in the future.\n *\n * @public\n */\nexport class CaptionsLogger {\n\tpublic time: number | null = null\n\tpublic verboseLevel: VerboseLevel = VerboseLevel.ERROR\n\n\tlog(severity: VerboseLevel, msg: string | (() => string)): void {\n\t\tif (this.verboseLevel >= severity) {\n\t\t\tconst m: string = typeof msg === 'function' ? msg() : msg\n\t\t\tconsole.log(`${this.time} [${severity}] ${m}`)\n\t\t}\n\t}\n}\n","/**\n *\n * This code was ported from the dash.js project at:\n * https://github.com/Dash-Industry-Forum/dash.js/blob/development/externals/cea608-parser.js\n * https://github.com/Dash-Industry-Forum/dash.js/commit/8269b26a761e0853bb21d78780ed945144ecdd4d#diff-71bc295a2d6b6b7093a1d3290d53a4b2\n *\n * The original copyright appears below:\n *\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2015-2016, DASH Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * 2. Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport type { PenStyles } from './PenStyles.ts'\n\n/**\n * Pen state.\n *\n * @public\n */\nexport class PenState {\n\tpublic foreground: string = 'white'\n\tpublic underline: boolean = false\n\tpublic italics: boolean = false\n\tpublic background: string = 'black'\n\tpublic flash: boolean = false\n\n\treset(): void {\n\t\tthis.foreground = 'white'\n\t\tthis.underline = false\n\t\tthis.italics = false\n\t\tthis.background = 'black'\n\t\tthis.flash = false\n\t}\n\n\tsetStyles(styles: Partial<PenStyles>): void {\n\t\tconst attribs = [\n\t\t\t'foreground',\n\t\t\t'underline',\n\t\t\t'italics',\n\t\t\t'background',\n\t\t\t'flash',\n\t\t]\n\t\tfor (const style of attribs) {\n\t\t\tif (Object.prototype.hasOwnProperty.call(styles, style)) {\n\t\t\t\t(this as any)[style] = (styles as any)[style]\n\t\t\t}\n\t\t}\n\t}\n\n\tisDefault(): boolean {\n\t\treturn (\n\t\t\tthis.foreground === 'white' &&\n\t\t\t!this.underline &&\n\t\t\t!this.italics &&\n\t\t\tthis.background === 'black' &&\n\t\t\t!this.flash\n\t\t)\n\t}\n\n\tequals(other: PenState): boolean {\n\t\treturn (\n\t\t\tthis.foreground === other.foreground &&\n\t\t\tthis.underline === other.underline &&\n\t\t\tthis.italics === other.italics &&\n\t\t\tthis.background === other.background &&\n\t\t\tthis.flash === other.flash\n\t\t)\n\t}\n\n\tcopy(newPenState: PenState): void {\n\t\tthis.foreground = newPenState.foreground\n\t\tthis.underline = newPenState.underline\n\t\tthis.italics = newPenState.italics\n\t\tthis.background = newPenState.background\n\t\tthis.flash = newPenState.flash\n\t}\n}\n","/**\n *\n * This code was ported from the dash.js project at:\n * https://github.com/Dash-Industry-Forum/dash.js/blob/development/externals/cea608-parser.js\n * https://github.com/Dash-Industry-Forum/dash.js/commit/8269b26a761e0853bb21d78780ed945144ecdd4d#diff-71bc295a2d6b6b7093a1d3290d53a4b2\n *\n * The original copyright appears below:\n *\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2015-2016, DASH Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * 2. Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport { PenState } from './PenState.ts'\n\n/**\n * Unicode character with styling and background.\n *\n * @public\n */\nexport class StyledUnicodeChar {\n\tuchar: string = ' '\n\tpenState: PenState = new PenState()\n\n\treset(): void {\n\t\tthis.uchar = ' '\n\t\tthis.penState.reset()\n\t}\n\n\tsetChar(uchar: string, newPenState: PenState): void {\n\t\tthis.uchar = uchar\n\t\tthis.penState.copy(newPenState)\n\t}\n\n\tsetPenState(newPenState: PenState): void {\n\t\tthis.penState.copy(newPenState)\n\t}\n\n\tequals(other: StyledUnicodeChar): boolean {\n\t\treturn this.uchar === other.uchar && this.penState.equals(other.penState)\n\t}\n\n\tcopy(newChar: StyledUnicodeChar): void {\n\t\tthis.uchar = newChar.uchar\n\t\tthis.penState.copy(newChar.penState)\n\t}\n\n\tisEmpty(): boolean {\n\t\treturn this.uchar === ' ' && this.penState.isDefault()\n\t}\n}\n","export const NR_COLS = 100\n","/**\n * Exceptions from regular ASCII. CodePoints are mapped to UTF-16 codes\n */\nexport const specialCea608CharsCodes: Record<number, number> = {\n\t42: 225, // lowercase a, acute accent\n\t92: 233, // lowercase e, acute accent\n\t94: 237, // lowercase i, acute accent\n\t95: 243, // lowercase o, acute accent\n\t96: 250, // lowercase u, acute accent\n\t123: 231, // lowercase c with cedilla\n\t124: 247, // division symbol\n\t125: 209, // uppercase N tilde\n\t126: 241, // lowercase n tilde\n\t127: 9608, // Full block\n\n\n\n\t// THIS BLOCK INCLUDES THE 16 EXTENDED (TWO-BYTE) LINE 21 CHARACTERS\n\t// THAT COME FROM HI BYTE=0x11 AND LOW BETWEEN 0x30 AND 0x3F\n\t// THIS MEANS THAT \\x50 MUST BE ADDED TO THE VALUES\n\t128: 174, // Registered symbol (R)\n\t129: 176, // degree sign\n\t130: 189, // 1/2 symbolOutputFilter\n\t131: 191, // Inverted (open) question mark\n\t132: 8482, // Trademark symbol (TM)\n\t133: 162, // Cents symbol\n\t134: 163, // Pounds sterling\n\t135: 9834, // Music 8'th note\n\t136: 224, // lowercase a, grave accent\n\t137: 32, // transparent space (regular)\n\t138: 232, // lowercase e, grave accent\n\t139: 226, // lowercase a, circumflex accent\n\t140: 234, // lowercase e, circumflex accent\n\t141: 238, // lowercase i, circumflex accent\n\t142: 244, // lowercase o, circumflex accent\n\t143: 251, // lowercase u, circumflex accent\n\n\n\t// THIS BLOCK INCLUDES THE 32 EXTENDED (TWO-BYTE) LINE 21 CHARACTERS\n\t// THAT COME FROM HI BYTE=0x12 AND LOW BETWEEN 0x20 AND 0x3F\n\t144: 193, // capital letter A with acute\n\t145: 201, // capital letter E with acute\n\t146: 211, // capital letter O with acute\n\t147: 218, // capital letter U with acute\n\t148: 220, // capital letter U with diaresis\n\t149: 252, // lowercase letter U with diaeresis\n\t150: 8216, // opening single quote\n\t151: 161, // inverted exclamation mark\n\t152: 42, // asterisk\n\t153: 8217, // closing single quote\n\t154: 9473, // box drawings heavy horizontal\n\t155: 169, // copyright sign\n\t156: 8480, // Service mark\n\t157: 8226, // (round) bullet\n\t158: 8220, // Left double quotation mark\n\t159: 8221, // Right double quotation mark\n\t160: 192, // uppercase A, grave accent\n\t161: 194, // uppercase A, circumflex\n\t162: 199, // uppercase C with cedilla\n\t163: 200, // uppercase E, grave accent\n\t164: 202, // uppercase E, circumflex\n\t165: 203, // capital letter E with diaresis\n\t166: 235, // lowercase letter e with diaresis\n\t167: 206, // uppercase I, circumflex\n\t168: 207, // uppercase I, with diaresis\n\t169: 239, // lowercase i, with diaresis\n\t170: 212, // uppercase O, circumflex\n\t171: 217, // uppercase U, grave accent\n\t172: 249, // lowercase u, grave accent\n\t173: 219, // uppercase U, circumflex\n\t174: 171, // left-pointing double angle quotation mark\n\t175: 187, // right-pointing double angle quotation mark\n\n\n\t// THIS BLOCK INCLUDES THE 32 EXTENDED (TWO-BYTE) LINE 21 CHARACTERS\n\t// THAT COME FROM HI BYTE=0x13 AND LOW BETWEEN 0x20 AND 0x3F\n\t176: 195, // Uppercase A, tilde\n\t177: 227, // Lowercase a, tilde\n\t178: 205, // Uppercase I, acute accent\n\t179: 204, // Uppercase I, grave accent\n\t180: 236, // Lowercase i, grave accent\n\t181: 210, // Uppercase O, grave accent\n\t182: 242, // Lowercase o, grave accent\n\t183: 213, // Uppercase O, tilde\n\t184: 245, // Lowercase o, tilde\n\t185: 123, // Open curly brace\n\t186: 125, // Closing curly brace\n\t187: 92, // Backslash\n\t188: 94, // Caret\n\t189: 95, // Underscore\n\t190: 124, // Pipe (vertical line)\n\t191: 8764, // Tilde operator\n\t192: 196, // Uppercase A, umlaut\n\t193: 228, // Lowercase A, umlaut\n\t194: 214, // Uppercase O, umlaut\n\t195: 246, // Lowercase o, umlaut\n\t196: 223, // Esszett (sharp S)\n\t197: 165, // Yen symbolOutputFilter\n\t198: 164, // Generic currency sign\n\t199: 9475, // Box drawings heavy vertical\n\t200: 197, // Uppercase A, ring\n\t201: 229, // Lowercase A, ring\n\t202: 216, // Uppercase O, stroke\n\t203: 248, // Lowercase o, strok\n\t204: 9487, // Box drawings heavy down and right\n\t205: 9491, // Box drawings heavy down and left\n\t206: 9495, // Box drawings heavy up and right\n\t207: 9499, // Box drawings heavy up and left\n}\n","import { specialCea608CharsCodes } from './specialCea608CharsCodes.ts'\n\nexport function getCharForByte(byte: number): string {\n\treturn String.fromCharCode(specialCea608CharsCodes[byte] || byte)\n};\n","/**\n *\n * This code was ported from the dash.js project at:\n * https://github.com/Dash-Industry-Forum/dash.js/blob/development/externals/cea608-parser.js\n * https://github.com/Dash-Industry-Forum/dash.js/commit/8269b26a761e0853bb21d78780ed945144ecdd4d#diff-71bc295a2d6b6b7093a1d3290d53a4b2\n *\n * The original copyright appears below:\n *\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2015-2016, DASH Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * 2. Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport { CaptionsLogger } from './CaptionsLogger.ts'\nimport { PenState } from './PenState.ts'\nimport type { PenStyles } from './PenStyles.ts'\nimport { StyledUnicodeChar } from './StyledUnicodeChar.ts'\nimport { VerboseLevel } from './VerboseLevel.ts'\nimport { NR_COLS } from './utils/NR_COLS.ts'\nimport { getCharForByte } from './utils/getCharForByte.ts'\n\n/**\n * CTA-608 row consisting of NR_COLS instances of StyledUnicodeChar.\n *\n * @public\n */\nexport class Row {\n\tpublic chars: StyledUnicodeChar[] = []\n\tpublic cueStartTime: number | null = null\n\n\tprivate pos: number = 0\n\tprivate currPenState: PenState = new PenState()\n\tprivate logger: CaptionsLogger\n\n\tconstructor(logger: CaptionsLogger = new CaptionsLogger()) {\n\t\tfor (let i = 0; i < NR_COLS; i++) {\n\t\t\tthis.chars.push(new StyledUnicodeChar())\n\t\t}\n\t\tthis.logger = logger\n\t}\n\n\tequals(other: Row): boolean {\n\t\tfor (let i = 0; i < NR_COLS; i++) {\n\t\t\tif (!this.chars[i].equals(other.chars[i])) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\n\tcopy(other: Row): void {\n\t\tfor (let i = 0; i < NR_COLS; i++) {\n\t\t\tthis.chars[i].copy(other.chars[i])\n\t\t}\n\t}\n\n\tisEmpty(): boolean {\n\t\tlet empty = true\n\t\tfor (let i = 0; i < NR_COLS; i++) {\n\t\t\tif (!this.chars[i].isEmpty()) {\n\t\t\t\tempty = false\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\treturn empty\n\t}\n\n\t/**\n\t * Set the cursor to a valid column.\n\t */\n\tsetCursor(absPos: number): void {\n\t\tif (this.pos !== absPos) {\n\t\t\tthis.pos = absPos\n\t\t}\n\n\t\tif (this.pos < 0) {\n\t\t\tthis.logger.log(\n\t\t\t\tVerboseLevel.DEBUG,\n\t\t\t\t'Negative cursor position ' + this.pos,\n\t\t\t)\n\t\t\tthis.pos = 0\n\t\t}\n\t\telse if (this.pos > NR_COLS) {\n\t\t\tthis.logger.log(\n\t\t\t\tVerboseLevel.DEBUG,\n\t\t\t\t'Too large cursor position ' + this.pos,\n\t\t\t)\n\t\t\tthis.pos = NR_COLS\n\t\t}\n\t}\n\n\t/**\n\t * Move the cursor relative to current position.\n\t */\n\tmoveCursor(relPos: number): void {\n\t\tconst newPos = this.pos + relPos\n\t\tif (relPos > 1) {\n\t\t\tfor (let i = this.pos + 1; i < newPos + 1; i++) {\n\t\t\t\tthis.chars[i].setPenState(this.currPenState)\n\t\t\t}\n\t\t}\n\t\tthis.setCursor(newPos)\n\t}\n\n\t/**\n\t * Backspace, move one step back and clear character.\n\t */\n\tbackSpace(): void {\n\t\tthis.moveCursor(-1)\n\t\tthis.chars[this.pos].setChar(' ', this.currPenState)\n\t}\n\n\tinsertChar(byte: number): void {\n\t\tif (byte >= 0x90) {\n\t\t\t// Extended char\n\t\t\tthis.backSpace()\n\t\t}\n\t\tconst char = getCharForByte(byte)\n\t\tif (this.pos >= NR_COLS) {\n\t\t\tthis.logger.log(\n\t\t\t\tVerboseLevel.ERROR,\n\t\t\t\t() =>\n\t\t\t\t\t'Cannot insert ' +\n\t\t\t\t\tbyte.toString(16) +\n\t\t\t\t\t' (' +\n\t\t\t\t\tchar +\n\t\t\t\t\t') at position ' +\n\t\t\t\t\tthis.pos +\n\t\t\t\t\t'. Skipping it!',\n\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tthis.chars[this.pos].setChar(char, this.currPenState)\n\t\tthis.moveCursor(1)\n\t}\n\n\tclearFromPos(startPos: number): void {\n\t\tlet i: number\n\t\tfor (i = startPos; i < NR_COLS; i++) {\n\t\t\tthis.chars[i].reset()\n\t\t}\n\t}\n\n\tclear(): void {\n\t\tthis.clearFromPos(0)\n\t\tthis.pos = 0\n\t\tthis.currPenState.reset()\n\t}\n\n\tclearToEndOfRow(): void {\n\t\tthis.clearFromPos(this.pos)\n\t}\n\n\tgetTextString(): string {\n\t\tconst chars: string[] = []\n\t\tlet empty = true\n\t\tfor (let i = 0; i < NR_COLS; i++) {\n\t\t\tconst char = this.chars[i].uchar\n\t\t\tif (char !== ' ') {\n\t\t\t\tempty = false\n\t\t\t}\n\n\t\t\tchars.push(char)\n\t\t}\n\t\tif (empty) {\n\t\t\treturn ''\n\t\t}\n\t\telse {\n\t\t\treturn chars.join('')\n\t\t}\n\t}\n\n\tsetPenStyles(styles: Partial<PenStyles>): void {\n\t\tthis.currPenState.setStyles(styles)\n\t\tconst currChar = this.chars[this.pos]\n\t\tcurrChar.setPenState(this.currPenState)\n\t}\n}\n","export const NR_ROWS = 15\n","/**\n *\n * This code was ported from the dash.js project at:\n * https://github.com/Dash-Industry-Forum/dash.js/blob/development/externals/cea608-parser.js\n * https://github.com/Dash-Industry-Forum/dash.js/commit/8269b26a761e0853bb21d78780ed945144ecdd4d#diff-71bc295a2d6b6b7093a1d3290d53a4b2\n *\n * The original copyright appears below:\n *\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2015-2016, DASH Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * 2. Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport { CaptionsLogger } from './CaptionsLogger.ts'\nimport type { PACData } from './PACData.ts'\nimport type { PenStyles } from './PenStyles.ts'\nimport { Row } from './Row.ts'\nimport { NR_ROWS } from './utils/NR_ROWS.ts'\nimport { VerboseLevel } from './VerboseLevel.ts'\n\n/**\n * Keep a CTA-608 screen of 32x15 styled characters\n *\n * @public\n */\nexport class CaptionScreen {\n\trows: Row[] = []\n\tprivate currRow: number = NR_ROWS - 1\n\tprivate nrRollUpRows: number | null = null\n\tprivate lastOutputScreen: CaptionScreen | null = null\n\tprivate logger: CaptionsLogger\n\n\tconstructor(logger: CaptionsLogger = new CaptionsLogger()) {\n\t\tfor (let i = 0; i < NR_ROWS; i++) {\n\t\t\tthis.rows.push(new Row(logger))\n\t\t}\n\t\tthis.logger = logger\n\t}\n\n\treset(): void {\n\t\tfor (let i = 0; i < NR_ROWS; i++) {\n\t\t\tthis.rows[i].clear()\n\t\t}\n\t\tthis.currRow = NR_ROWS - 1\n\t}\n\n\tequals(other: CaptionScreen): boolean {\n\t\tlet equal = true\n\t\tfor (let i = 0; i < NR_ROWS; i++) {\n\t\t\tif (!this.rows[i].equals(other.rows[i])) {\n\t\t\t\tequal = false\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\treturn equal\n\t}\n\n\tcopy(other: CaptionScreen): void {\n\t\tfor (let i = 0; i < NR_ROWS; i++) {\n\t\t\tthis.rows[i].copy(other.rows[i])\n\t\t}\n\t}\n\n\tisEmpty(): boolean {\n\t\tlet empty = true\n\t\tfor (let i = 0; i < NR_ROWS; i++) {\n\t\t\tif (!this.rows[i].isEmpty()) {\n\t\t\t\tempty = false\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\treturn empty\n\t}\n\n\tbackSpace(): void {\n\t\tconst row = this.rows[this.currRow]\n\t\trow.backSpace()\n\t}\n\n\tclearToEndOfRow(): void {\n\t\tconst row = this.rows[this.currRow]\n\t\trow.clearToEndOfRow()\n\t}\n\n\t/**\n\t * Insert a character (without styling) in the current row.\n\t */\n\tinsertChar(char: number): void {\n\t\tconst row = this.rows[this.currRow]\n\t\trow.insertChar(char)\n\t}\n\n\tsetPen(styles: Partial<PenStyles>): void {\n\t\tconst row = this.rows[this.currRow]\n\t\trow.setPenStyles(styles)\n\t}\n\n\tmoveCursor(relPos: number): void {\n\t\tconst row = this.rows[this.currRow]\n\t\trow.moveCursor(relPos)\n\t}\n\n\tsetCursor(absPos: number): void {\n\t\tthis.logger.log(VerboseLevel.INFO, 'setCursor: ' + absPos)\n\t\tconst row = this.rows[this.currRow]\n\t\trow.setCursor(absPos)\n\t}\n\n\tsetPAC(pacData: PACData): void {\n\t\tthis.logger.log(\n\t\t\tVerboseLevel.INFO,\n\t\t\t() => 'pacData = ' + JSON.stringify(pacData),\n\t\t)\n\t\tlet newRow = pacData.row - 1\n\t\tif (this.nrRollUpRows && newRow < this.nrRollUpRows - 1) {\n\t\t\tnewRow = this.nrRollUpRows - 1\n\t\t}\n\n\t\t// Make sure this only affects Roll-up Captions by checking this.nrRollUpRows\n\t\tif (this.nrRollUpRows && this.currRow !== newRow) {\n\t\t\t// clear all rows first\n\t\t\tfor (let i = 0; i < NR_ROWS; i++) {\n\t\t\t\tthis.rows[i].clear()\n\t\t\t}\n\n\t\t\t// Copy this.nrRollUpRows rows from lastOutputScreen and place it in the newRow location\n\t\t\t// topRowIndex - the start of rows to copy (inclusive index)\n\t\t\tconst topRowIndex = this.currRow + 1 - this.nrRollUpRows\n\t\t\t// We only copy if the last position was already shown.\n\t\t\t// We use the cueStartTime value to check this.\n\t\t\tconst lastOutputScreen = this.lastOutputScreen\n\t\t\tif (lastOutputScreen) {\n\t\t\t\tconst prevLineTime = lastOutputScreen.rows[topRowIndex].cueStartTime\n\t\t\t\tconst time = this.logger.time\n\t\t\t\tif (prevLineTime !== null && time !== null && prevLineTime < time) {\n\t\t\t\t\tfor (let i = 0; i < this.nrRollUpRows; i++) {\n\t\t\t\t\t\tthis.rows[newRow - this.nrRollUpRows + i + 1].copy(\n\t\t\t\t\t\t\tlastOutputScreen.rows[topRowIndex + i],\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.currRow = newRow\n\t\tconst row = this.rows[this.currRow]\n\t\tif (pacData.indent !== null) {\n\t\t\tconst indent = pacData.indent\n\t\t\tconst prevPos = Math.max(indent - 1, 0)\n\t\t\trow.setCursor(pacData.indent)\n\t\t\tpacData.color = row.chars[prevPos].penState.foreground\n\t\t}\n\t\tconst styles: PenStyles = {\n\t\t\tforeground: pacData.color,\n\t\t\tunderline: pacData.underline,\n\t\t\titalics: pacData.italics,\n\t\t\tbackground: 'black',\n\t\t\tflash: false,\n\t\t}\n\t\tthis.setPen(styles)\n\t}\n\n\t/**\n\t * Set background/extra foreground, but first do back_space, and then insert space (backwards compatibility).\n\t */\n\tsetBkgData(bkgData: Partial<PenStyles>): void {\n\t\tthis.logger.log(\n\t\t\tVerboseLevel.INFO,\n\t\t\t() => 'bkgData = ' + JSON.stringify(bkgData),\n\t\t)\n\t\tthis.backSpace()\n\t\tthis.setPen(bkgData)\n\t\tthis.insertChar(0x20) // Space\n\t}\n\n\tsetRollUpRows(nrRows: number | null): void {\n\t\tthis.nrRollUpRows = nrRows\n\t}\n\n\trollUp(): void {\n\t\tif (this.nrRollUpRows === null) {\n\t\t\tthis.logger.log(\n\t\t\t\tVerboseLevel.DEBUG,\n\t\t\t\t'roll_up but nrRollUpRows not set yet',\n\t\t\t)\n\t\t\treturn // Not properly setup\n\t\t}\n\t\tthis.logger.log(VerboseLevel.TEXT, () => this.getDisplayText())\n\t\tconst topRowIndex = this.currRow + 1 - this.nrRollUpRows\n\t\tconst topRow = this.rows.splice(topRowIndex, 1)[0]\n\t\ttopRow.clear()\n\t\tthis.rows.splice(this.currRow, 0, topRow)\n\t\tthis.logger.log(VerboseLevel.INFO, 'Rolling up')\n\t}\n\n\t/**\n\t * Get all non-empty rows with as unicode text.\n\t */\n\tgetDisplayText(asOneRow?: boolean): string {\n\t\tasOneRow = asOneRow || false\n\t\tconst displayText: string[] = []\n\t\tlet text = ''\n\t\tlet rowNr = -1\n\t\tfor (let i = 0; i < NR_ROWS; i++) {\n\t\t\tconst rowText = this.rows[i].getTextString()\n\t\t\tif (rowText) {\n\t\t\t\trowNr = i + 1\n\t\t\t\tif (asOneRow) {\n\t\t\t\t\tdisplayText.push('Row ' + rowNr + \": '\" + rowText + \"'\")\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdisplayText.push(rowText.trim())\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (displayText.length > 0) {\n\t\t\tif (asOneRow) {\n\t\t\t\ttext = '[' + displayText.join(' | ') + ']'\n\t\t\t}\n\t\t\telse {\n\t\t\t\ttext = displayText.join('\\n')\n\t\t\t}\n\t\t}\n\t\treturn text\n\t}\n\n\tgetTextAndFormat(): Row[] {\n\t\treturn this.rows\n\t}\n}\n","/**\n *\n * This code was ported from the dash.js project at:\n * https://github.com/Dash-Industry-Forum/dash.js/blob/development/externals/cea608-parser.js\n * https://github.com/Dash-Industry-Forum/dash.js/commit/8269b26a761e0853bb21d78780ed945144ecdd4d#diff-71bc295a2d6b6b7093a1d3290d53a4b2\n *\n * The original copyright appears below:\n *\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2015-2016, DASH Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * 2. Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport type { CaptionModes } from './CaptionModes.ts'\nimport { CaptionScreen } from './CaptionScreen.ts'\nimport { CaptionsLogger } from './CaptionsLogger.ts'\nimport type { CueHandler } from './CueHandler.ts'\nimport type { PACData } from './PACData.ts'\nimport type { PenStyles } from './PenStyles.ts'\nimport type { Row } from './Row.ts'\nimport { VerboseLevel } from './VerboseLevel.ts'\nimport { NR_ROWS } from './utils/NR_ROWS.ts'\n\n/**\n * CTA-608 Channel\n *\n * @public\n */\nexport class Cta608Channel {\n\tchNr: number\n\toutputFilter: CueHandler\n\tmode: CaptionModes\n\tdisplayedMemory: CaptionScreen\n\tnonDisplayedMemory: CaptionScreen\n\tlastOutputScreen: CaptionScreen\n\tcurrRollUpRow: Row\n\twriteScreen: CaptionScreen\n\tcueStartTime: number | null\n\n\tprivate logger: CaptionsLogger\n\n\tconstructor(\n\t\tchannelNumber: number,\n\t\toutputFilter: CueHandler,\n\t\tlogger: CaptionsLogger = new CaptionsLogger(),\n\t) {\n\t\tthis.chNr = channelNumber\n\t\tthis.outputFilter = outputFilter\n\t\tthis.mode = null\n\t\tthis.displayedMemory = new CaptionScreen(logger)\n\t\tthis.nonDisplayedMemory = new CaptionScreen(logger)\n\t\tthis.lastOutputScreen = new CaptionScreen(logger)\n\t\tthis.currRollUpRow = this.displayedMemory.rows[NR_ROWS - 1]\n\t\tthis.writeScreen = this.displayedMemory\n\t\tthis.mode = null\n\t\tthis.cueStartTime = null // Keeps track of where a cue started.\n\t\tthis.logger = logger\n\n\t\tthis.logger.log(VerboseLevel.INFO, 'new Cea608Channel(' + this.chNr + ')')\n\t}\n\n\treset(): void {\n\t\tthis.mode = null\n\t\tthis.displayedMemory.reset()\n\t\tthis.nonDisplayedMemory.reset()\n\t\tthis.lastOutputScreen.reset()\n\t\tthis.outputFilter?.reset?.()\n\t\tthis.currRollUpRow = this.displayedMemory.rows[NR_ROWS - 1]\n\t\tthis.writeScreen = this.displayedMemory\n\t\tthis.mode = null\n\t\tthis.cueStartTime = null\n\t}\n\n\tgetHandler(): CueHandler {\n\t\treturn this.outputFilter\n\t}\n\n\tsetHandler(outputFilter: CueHandler): void {\n\t\tthis.outputFilter = outputFilter\n\t}\n\n\tsetPAC(pacData: PACData): void {\n\t\tthis.writeScreen.setPAC(pacData)\n\t}\n\n\tsetBkgData(bkgData: Partial<PenStyles>): void {\n\t\tthis.writeScreen.setBkgData(bkgData)\n\t}\n\n\tsetMode(newMode: CaptionModes): void {\n\t\tif (newMode === this.mode) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.mode = newMode\n\t\tthis.logger.log(VerboseLevel.INFO, () => 'MODE=' + newMode)\n\t\tif (this.mode === 'MODE_POP-ON') {\n\t\t\tthis.writeScreen = this.nonDisplayedMemory\n\t\t}\n\t\telse {\n\t\t\tthis.writeScreen = this.displayedMemory\n\t\t\tthis.writeScreen.reset()\n\t\t}\n\t\tif (this.mode !== 'MODE_ROLL-UP') {\n\t\t\tthis.displayedMemory.setRollUpRows(null)\n\t\t\tthis.nonDisplayedMemory.setRollUpRows(null)\n\t\t}\n\t\tthis.mode = newMode\n\t}\n\n\tinsertChars(chars: number[]): void {\n\t\tfor (const char of chars) {\n\t\t\tthis.writeScreen.insertChar(char)\n\t\t}\n\n\t\tconst screen =\n\t\t\tthis.writeScreen === this.displayedMemory ? 'DISP' : 'NON_DISP'\n\t\tthis.logger.log(\n\t\t\tVerboseLevel.INFO,\n\t\t\t() => screen + ': ' + this.writeScreen.getDisplayText(true),\n\t\t)\n\t\tif (this.mode === 'MODE_PAINT-ON' || this.mode === 'MODE_ROLL-UP') {\n\t\t\tthis.logger.log(\n\t\t\t\tVerboseLevel.TEXT,\n\t\t\t\t() => 'DISPLAYED: ' + this.displayedMemory.getDisplayText(true),\n\t\t\t)\n\t\t\tthis.outputDataUpdate()\n\t\t}\n\t}\n\n\tccRCL(): void {\n\t\t// Resume Caption Loading (switch mode to Pop On)\n\t\tthis.logger.log(VerboseLevel.INFO, 'RCL - Resume Caption Loading')\n\t\tthis.setMode('MODE_POP-ON')\n\t}\n\n\tccBS(): void {\n\t\t// BackSpace\n\t\tthis.logger.log(VerboseLevel.INFO, 'BS - BackSpace')\n\t\tif (this.mode === 'MODE_TEXT') {\n\t\t\treturn\n\t\t}\n\n\t\tthis.writeScreen.backSpace()\n\t\tif (this.writeScreen === this.displayedMemory) {\n\t\t\tthis.outputDataUpdate()\n\t\t}\n\t}\n\n\tccAOF(): void {\n\t\t// Reserved (formerly Alarm Off)\n\t}\n\n\tccAON(): void {\n\t\t// Reserved (formerly Alarm On)\n\t}\n\n\tccDER(): void {\n\t\t// Delete to End of Row\n\t\tthis.logger.log(VerboseLevel.INFO, 'DER- Delete to End of Row')\n\t\tthis.writeScreen.clearToEndOfRow()\n\t\tthis.outputDataUpdate()\n\t}\n\n\tccRU(nrRows: number | null): void {\n\t\t// Roll-Up Captions-2,3,or 4 Rows\n\t\tthis.logger.log(VerboseLevel.INFO, 'RU(' + nrRows + ') - Roll Up')\n\t\tthis.writeScreen = this.displayedMemory\n\t\tthis.setMode('MODE_ROLL-UP')\n\t\tthis.writeScreen.setRollUpRows(nrRows)\n\t}\n\n\tccFON(): void {\n\t\t// Flash On\n\t\tthis.logger.log(VerboseLevel.INFO, 'FON - Flash On')\n\t\tthis.writeScreen.setPen({ flash: true })\n\t}\n\n\tccRDC(): void {\n\t\t// Resume Direct Captioning (switch mode to PaintOn)\n\t\tthis.logger.log(VerboseLevel.INFO, 'RDC - Resume Direct Captioning')\n\t\tthis.setMode('MODE_PAINT-ON')\n\t}\n\n\tccTR(): void {\n\t\t// Text Restart in text mode (not supported, however)\n\t\tthis.logger.log(VerboseLevel.INFO, 'TR')\n\t\tthis.setMode('MODE_TEXT')\n\t}\n\n\tccRTD(): void {\n\t\t// Resume Text Display in Text mode (not supported, however)\n\t\tthis.logger.log(VerboseLevel.INFO, 'RTD')\n\t\tthis.setMode('MODE_TEXT')\n\t}\n\n\tccEDM(): void {\n\t\t// Erase Displayed Memory\n\t\tthis.logger.log(VerboseLevel.INFO, 'EDM - Erase Displayed Memory')\n\t\tthis.displayedMemory.reset()\n\t\tthis.outputDataUpdate(true)\n\t}\n\n\tccCR(): void {\n\t\t// Carriage Return\n\t\tthis.logger.log(VerboseLevel.INFO, 'CR - Carriage Return')\n\t\tthis.writeScreen.rollUp()\n\t\tthis.outputDataUpdate(true)\n\t}\n\n\tccENM(): void {\n\t\t// Erase Non-Displayed Memory\n\t\tthis.logger.log(VerboseLevel.INFO, 'ENM - Erase Non-displayed Memory')\n\t\tthis.nonDisplayedMemory.reset()\n\t}\n\n\tccEOC(): void {\n\t\t// End of Caption (Flip Memories)\n\t\tthis.logger.log(VerboseLevel.INFO, 'EOC - End Of Caption')\n\t\tif (this.mode === 'MODE_POP-ON') {\n\t\t\tconst tmp = this.displayedMemory\n\t\t\tthis.displayedMemory = this.nonDisplayedMemory\n\t\t\tthis.nonDisplayedMemory = tmp\n\t\t\tthis.writeScreen = this.nonDisplayedMemory\n\t\t\tthis.logger.log(\n\t\t\t\tVerboseLevel.TEXT,\n\t\t\t\t() => 'DISP: ' + this.displayedMemory.getDisplayText(),\n\t\t\t)\n\t\t}\n\t\tthis.outputDataUpdate(true)\n\t}\n\n\tccTO(nrCols: number): void {\n\t\t// Tab Offset 1,2, or 3 columns\n\t\tthis.logger.log(VerboseLevel.INFO, 'TO(' + nrCols + ') - Tab Offset')\n\t\tthis.writeScreen.moveCursor(nrCols)\n\t}\n\n\tccMIDROW(secondByte: number): void {\n\t\t// Parse MIDROW command\n\t\tconst styles: Partial<PenStyles> = { flash: false }\n\t\tstyles.underline = secondByte % 2 === 1\n\t\tstyles.italics = secondByte >= 0x2e\n\t\tif (!styles.italics) {\n\t\t\tconst colorIndex = Math.floor(secondByte / 2) - 0x10\n\t\t\tconst colors = [\n\t\t\t\t'white',\n\t\t\t\t'green',\n\t\t\t\t'blue',\n\t\t\t\t'cyan',\n\t\t\t\t'red',\n\t\t\t\t'yellow',\n\t\t\t\t'magenta',\n\t\t\t]\n\t\t\tstyles.foreground = colors[colorIndex]\n\t\t}\n\t\telse {\n\t\t\tstyles.foreground = 'white'\n\t\t}\n\t\tthis.logger.log(VerboseLevel.INFO, 'MIDROW: ' + JSON.stringify(styles))\n\t\tthis.writeScreen.setPen(styles)\n\t}\n\n\toutputDataUpdate(dispatch: boolean = false): void {\n\t\tconst time = this.logger.time\n\t\tif (time === null) {\n\t\t\treturn\n\t\t}\n\n\t\tif (this.outputFilter) {\n\t\t\tif (this.cueStartTime === null && !this.displayedMemory.isEmpty()) {\n\t\t\t\t// Start of a new cue\n\t\t\t\tthis.cueStartTime = time\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (!this.displayedMemory.equals(this.lastOutputScreen)) {\n\t\t\t\t\tthis.outputFilter.newCue(\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\tthis.cueStartTime!,\n\t\t\t\t\t\ttime,\n\t\t\t\t\t\tthis.lastOutputScreen,\n\t\t\t\t\t)\n\t\t\t\t\tif (dispatch && this.outputFilter.dispatchCue) {\n\t\t\t\t\t\tthis.outputFilter.dispatchCue()\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.cueStartTime = this.displayedMemory.isEmpty() ? null : time\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.lastOutputScreen.copy(this.displayedMemory)\n\t\t}\n\t}\n\n\tcueSplitAtTime(t: number): void {\n\t\tif (this.outputFilter) {\n\t\t\tif (!this.displayedMemory.isEmpty()) {\n\t\t\t\tif (this.outputFilter.newCue) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\tthis.outputFilter.newCue(this.cueStartTime!, t, this.displayedMemory)\n\t\t\t\t}\n\n\t\t\t\tthis.cueStartTime = t\n\t\t\t}\n\t\t}\n\t}\n}\n","export const backgroundColors: string[] = [\n\t'white',\n\t'green',\n\t'blue',\n\t'cyan',\n\t'red',\n\t'yellow',\n\t'magenta',\n\t'black',\n\t'transparent',\n]\n","import type { CmdHistory } from '../CmdHistory.ts'\n\nexport function createCmdHistory(): CmdHistory {\n\treturn {\n\t\ta: null,\n\t\tb: null,\n\t}\n}\n","import type { CmdHistory } from '../CmdHistory.ts'\n\nexport function hasCmdRepeated(a: number, b: number, cmdHistory: CmdHistory): boolean {\n\treturn cmdHistory.a === a && cmdHistory.b === b\n}\n","export function numArrayToHexArray(numArray: number[]): string[] {\n\tconst hexArray: string[] = []\n\tfor (const num of numArray) {\n\t\thexArray.push(num.toString(16))\n\t}\n\n\treturn hexArray\n};\n","export const rowsHighCh1: Record<number, number> = {\n\t17: 2,\n\t18: 4,\n\t21: 6,\n\t22: 8,\n\t23: 10,\n\t19: 13,\n\t20: 15,\n}\n","export const rowsHighCh2: Record<number, number> = {\n\t25: 2,\n\t26: 4,\n\t29: 6,\n\t30: 8,\n\t31: 10,\n\t27: 13,\n\t28: 15,\n}\n","// Tables to look up row from PAC data\n\nexport const rowsLowCh1: Record<number, number> = {\n\t17: 1,\n\t18: 3,\n\t21: 5,\n\t22: 7,\n\t23: 9,\n\t16: 11,\n\t19: 12,\n\t20: 14,\n}\n","export const rowsLowCh2: Record<number, number> = {\n\t25: 1,\n\t26: 3,\n\t29: 5,\n\t30: 7,\n\t31: 9,\n\t24: 11,\n\t27: 12,\n\t28: 14,\n}\n","import type { CmdHistory } from '../CmdHistory.ts'\n\nexport function setLastCmd(\n\ta: number | null,\n\tb: number | null,\n\tcmdHistory: CmdHistory,\n): void {\n\tcmdHistory.a = a\n\tcmdHistory.b = b\n}\n","/**\n *\n * This code was ported from the dash.js project at:\n * https://github.com/Dash-Industry-Forum/dash.js/blob/development/externals/cea608-parser.js\n * https://github.com/Dash-Industry-Forum/dash.js/commit/8269b26a761e0853bb21d78780ed945144ecdd4d#diff-71bc295a2d6b6b7093a1d3290d53a4b2\n *\n * The original copyright appears below:\n *\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2015-2016, DASH Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * 2. Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport { CaptionsLogger } from './CaptionsLogger.ts'\nimport type { Channels } from './Channels.ts'\nimport type { CmdHistory } from './CmdHistory.ts'\nimport { Cta608Channel } from './Cta608Channel.ts'\nimport type { PACData } from './PACData.ts'\nimport type { PenStyles } from './PenStyles.ts'\nimport type { SupportedField } from './SupportedField.ts'\nimport { VerboseLevel } from './VerboseLevel.ts'\nimport { backgroundColors } from './utils/backgroundColors.ts'\nimport { createCmdHistory } from './utils/createCmdHistory.ts'\nimport { getCharForByte } from './utils/getCharForByte.ts'\nimport { hasCmdRepeated } from './utils/hasCmdRepeated.ts'\nimport { numArrayToHexArray } from './utils/numArrayToHexArray.ts'\nimport { rowsHighCh1 } from './utils/rowsHighCh1.ts'\nimport { rowsHighCh2 } from './utils/rowsHighCh2.ts'\nimport { rowsLowCh1 } from './utils/rowsLowCh1.ts'\nimport { rowsLowCh2 } from './utils/rowsLowCh2.ts'\nimport { setLastCmd } from './utils/setLastCmd.ts'\n\n/**\n * CEA-608 caption parser.\n *\n * @public\n */\nexport class Cta608Parser {\n\tprivate channels: (Cta608Channel | null)[]\n\tprivate currentChannel: Channels = 0\n\tprivate cmdHistory: CmdHistory = createCmdHistory()\n\tprivate logger: CaptionsLogger\n\tprivate lastTime: number | null = null\n\n\tconstructor(field: SupportedField, out1: any, out2: any) {\n\t\tconst logger = (this.logger = new CaptionsLogger())\n\t\tthis.channels = [\n\t\t\tnull,\n\t\t\tnew Cta608Channel(field, out1, logger),\n\t\t\tnew Cta608Channel(field + 1, out2, logger),\n\t\t]\n\t}\n\n\t/**\n\t * Add data for time t in forms of list of bytes (unsigned ints). The bytes are treated as pairs.\n\t *\n\t * @param time - The time in milliseconds\n\t * @param byteList - The list of bytes\n\t */\n\taddData(time: number | null, byteList: number[]): void {\n\t\tthis.lastTime = time\n\t\tthis.logger.time = time\n\n\t\tfor (let i = 0; i < byteList.length; i += 2) {\n\t\t\tconst a = byteList[i] & 0x7f\n\t\t\tconst b = byteList[i + 1] & 0x7f\n\t\t\tlet cmdFound: boolean = false\n\t\t\tlet charsFound: number[] | null = null\n\n\t\t\tif (this.lastTime !== null) {\n\t\t\t\ttime = this.lastTime + 0.5 * i * 1001 / 30000\n\t\t\t\tthis.logger.time = time\n\t\t\t}\n\n\t\t\tif (a === 0 && b === 0) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis.logger.log(\n\t\t\t\t\tVerboseLevel.DATA,\n\t\t\t\t\t() =>\n\t\t\t\t\t\t'[' +\n\t\t\t\t\t\tnumArrayToHexArray([byteList[i], byteList[i + 1]]) +\n\t\t\t\t\t\t'] -> (' +\n\t\t\t\t\t\tnumArrayToHexArray([a, b]) +\n\t\t\t\t\t\t')',\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tconst cmdHistory = this.cmdHistory\n\t\t\tconst isControlCode = a >= 0x10 && a <= 0x1f\n\t\t\tif (isControlCode) {\n\t\t\t\t// Skip redundant control codes\n\t\t\t\tif (hasCmdRepeated(a, b, cmdHistory)) {\n\t\t\t\t\tsetLastCmd(null, null, cmdHistory)\n\t\t\t\t\tthis.logger.log(\n\t\t\t\t\t\tVerboseLevel.DEBUG,\n\t\t\t\t\t\t() =>\n\t\t\t\t\t\t\t'Repeated command (' +\n\t\t\t\t\t\t\tnumArrayToHexArray([a, b]) +\n\t\t\t\t\t\t\t') is dropped',\n\t\t\t\t\t)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tsetLastCmd(a, b, this.cmdHistory)\n\n\t\t\t\tcmdFound = this.parseCmd(a, b)\n\n\t\t\t\tif (!cmdFound) {\n\t\t\t\t\tcmdFound = this.parseMidrow(a, b)\n\t\t\t\t}\n\n\t\t\t\tif (!cmdFound) {\n\t\t\t\t\tcmdFound = this.parsePAC(a, b)\n\t\t\t\t}\n\n\t\t\t\tif (!cmdFound) {\n\t\t\t\t\tcmdFound = this.parseBackgroundAttributes(a, b)\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tsetLastCmd(null, null, cmdHistory)\n\t\t\t}\n\n\t\t\tif (!cmdFound) {\n\t\t\t\tcharsFound = this.parseChars(a, b)\n\t\t\t\tif (charsFound.length) {\n\t\t\t\t\tconst currChNr = this.currentChannel\n\t\t\t\t\tif (currChNr && currChNr > 0) {\n\t\t\t\t\t\tconst channel = this.channels[currChNr] as Cta608Channel\n\t\t\t\t\t\tchannel.insertChars(charsFound)\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis.logger.log(\n\t\t\t\t\t\t\tVerboseLevel.WARNING,\n\t\t\t\t\t\t\t'No channel found yet. TEXT-MODE?',\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!cmdFound && !charsFound) {\n\t\t\t\tthis.logger.log(\n\t\t\t\t\tVerboseLevel.WARNING,\n\t\t\t\t\t() =>\n\t\t\t\t\t\t\"Couldn't parse cleaned data \" +\n\t\t\t\t\t\tnumArrayToHexArray([a, b]) +\n\t\t\t\t\t\t' orig: ' +\n\t\t\t\t\t\tnumArrayToHexArray([byteList[i], byteList[i + 1]]),\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Parse Command.\n\t *\n\t * @param a - The first byte\n\t * @param b - The second byte\n\t * @returns True if a command was found\n\t */\n\tprivate parseCmd(a: number, b: number): boolean {\n\n\t\tconst cond1 =\n\t\t\t(a === 0x14 || a === 0x1c || a === 0x15 || a === 0x1d) &&\n\t\t\tb >= 0x20 &&\n\t\t\tb <= 0x2f\n\t\tconst cond2 = (a === 0x17 || a === 0x1f) && b >= 0x21 && b <= 0x23\n\t\tif (!(cond1 || cond2)) {\n\t\t\treturn false\n\t\t}\n\n\t\tconst chNr = a === 0x14 || a === 0x15 || a === 0x17 ? 1 : 2\n\t\tconst channel = this.channels[chNr] as Cta608Channel\n\n\t\tif (a === 0x14 || a === 0x15 || a === 0x1c || a === 0x1d) {\n\t\t\tif (b === 0x20) {\n\t\t\t\tchannel.ccRCL()\n\t\t\t}\n\t\t\telse if (b === 0x21) {\n\t\t\t\tchannel.ccBS()\n\t\t\t}\n\t\t\telse if (b === 0x22) {\n\t\t\t\tchannel.ccAOF()\n\t\t\t}\n\t\t\telse if (b === 0x23) {\n\t\t\t\tchannel.ccAON()\n\t\t\t}\n\t\t\telse if (b === 0x24) {\n\t\t\t\tchannel.ccDER()\n\t\t\t}\n\t\t\telse if (b === 0x25) {\n\t\t\t\tchannel.ccRU(2)\n\t\t\t}\n\t\t\telse if (b === 0x26) {\n\t\t\t\tchannel.ccRU(3)\n\t\t\t}\n\t\t\telse if (b === 0x27) {\n\t\t\t\tchannel.ccRU(4)\n\t\t\t}\n\t\t\telse if (b === 0x28) {\n\t\t\t\tchannel.ccFON()\n\t\t\t}\n\t\t\telse if (b === 0x29) {\n\t\t\t\tchannel.ccRDC()\n\t\t\t}\n\t\t\telse if (b === 0x2a) {\n\t\t\t\tchannel.ccTR()\n\t\t\t}\n\t\t\telse if (b === 0x2b) {\n\t\t\t\tchannel.ccRTD()\n\t\t\t}\n\t\t\telse if (b === 0x2c) {\n\t\t\t\tchannel.ccEDM()\n\t\t\t}\n\t\t\telse if (b === 0x2d) {\n\t\t\t\tchannel.ccCR()\n\t\t\t}\n\t\t\telse if (b === 0x2e) {\n\t\t\t\tchannel.ccENM()\n\t\t\t}\n\t\t\telse if (b === 0x2f) {\n\t\t\t\tchannel.ccEOC()\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\t// a == 0x17 || a == 0x1F\n\t\t\tchannel.ccTO(b - 0x20)\n\t\t}\n\n\t\tthis.currentChannel = chNr\n\t\treturn true\n\t}\n\n\t/**\n\t * Parse midrow styling command\n\t *\n\t * @param a - The first byte\n\t * @param b - The second byte\n\t * @returns `true` if midrow styling command was found\n\t */\n\tprivate parseMidrow(a: number, b: number): boolean {\n\t\tlet chNr: number = 0\n\n\t\tif ((a === 0x11 || a === 0x19) && b >= 0x20 && b <= 0x2f) {\n\t\t\tif (a === 0x11) {\n\t\t\t\tchNr = 1\n\t\t\t}\n\t\t\telse {\n\t\t\t\tchNr = 2\n\t\t\t}\n\n\t\t\tif (chNr !== this.currentChannel) {\n\t\t\t\tthis.logger.log(\n\t\t\t\t\tVerboseLevel.ERROR,\n\t\t\t\t\t'Mismatch channel in midrow parsing',\n\t\t\t\t)\n\t\t\t\treturn false\n\t\t\t}\n\t\t\tconst channel = this.channels[chNr]\n\t\t\tif (!channel) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t\tchannel.ccMIDROW(b)\n\t\t\tthis.logger.log(\n\t\t\t\tVerboseLevel.DEBUG,\n\t\t\t\t() => 'MIDROW (' + numArrayToHexArray([a, b]) + ')',\n\t\t\t)\n\t\t\treturn true\n\t\t}\n\t\treturn false\n\t}\n\n\t/**\n\t * Parse Preable Access Codes (Table 53).\n\t *\n\t * @param a - The first byte\n\t * @param b - The second byte\n\t * @returns A Boolean that tells if PAC found\n\t */\n\tprivate parsePAC(a: number, b: number): boolean {\n\t\tlet row: number\n\n\t\tconst case1 =\n\t\t\t((a >= 0x11 && a <= 0x17) || (a >= 0x19 && a <= 0x1f)) &&\n\t\t\tb >= 0x40 &&\n\t\t\tb <= 0x7f\n\t\tconst case2 = (a === 0x10 || a === 0x18) && b >= 0x40 && b <= 0x5f\n\t\tif (!(case1 || case2)) {\n\t\t\treturn false\n\t\t}\n\n\t\tconst chNr: Channels = a <= 0x17 ? 1 : 2\n\n\t\tif (b >= 0x40 && b <= 0x5f) {\n\t\t\trow = chNr === 1 ? rowsLowCh1[a] : rowsLowCh2[a]\n\t\t}\n\t\telse {\n\t\t\t// 0x60 <= b <= 0x7F\n\t\t\trow = chNr === 1 ? rowsHighCh1[a] : rowsHighCh2[a]\n\t\t}\n\t\tconst channel = this.channels[chNr]\n\t\tif (!channel) {\n\t\t\treturn false\n\t\t}\n\t\tchannel.setPAC(this.interpretPAC(row, b))\n\t\tthis.currentChannel = chNr\n\t\treturn true\n\t}\n\n\t/**\n\t * Interpret the second byte of the pac, and return the information.\n\t *\n\t * @param row - The row number\n\t * @param byte - The second byte\n\t * @returns pacData with style parameters\n\t */\n\tprivate interpretPAC(row: number, byte: number): PACData {\n\t\tlet pacIndex\n\t\tconst pacData: PACData = {\n\t\t\tcolor: null,\n\t\t\titalics: false,\n\t\t\tindent: null,\n\t\t\tunderline: false,\n\t\t\trow: row,\n\t\t}\n\n\t\tif (byte > 0x5f) {\n\t\t\tpacIndex = byte - 0x60\n\t\t}\n\t\telse {\n\t\t\tpacIndex = byte - 0x40\n\t\t}\n\n\t\tpacData.underline = (pacIndex & 1) === 1\n\t\tif (pacIndex <= 0xd) {\n\t\t\tpacData.color = [\n\t\t\t\t'white',\n\t\t\t\t'green',\n\t\t\t\t'blue',\n\t\t\t\t'cyan',\n\t\t\t\t'red',\n\t\t\t\t'yellow',\n\t\t\t\t'magenta',\n\t\t\t\t'white',\n\t\t\t][Math.floor(pacIndex / 2)]\n\t\t}\n\t\telse if (pacIndex <= 0xf) {\n\t\t\tpacData.italics = true\n\t\t\tpacData.color = 'white'\n\t\t}\n\t\telse {\n\t\t\tpacData.indent = Math.floor((pacIndex - 0x10) / 2) * 4\n\t\t}\n\t\treturn pacData // Note that row has zero offset. The spec uses 1.\n\t}\n\n\t/**\n\t * Parse characters.\n\t *\n\t * @param a - The first byte\n\t * @param b - The second byte\n\t * @returns An array with 1 to 2 codes corresponding to chars, if found. null otherwise.\n\t */\n\tprivate parseChars(a: number, b: number): number[] {\n\t\tlet channelNr: Channels\n\t\tlet charCodes: number[] = []\n\t\tlet charCode1: number | null = null\n\n\t\tif (a >= 0x19) {\n\t\t\tchannelNr = 2\n\t\t\tcharCode1 = a - 8\n\t\t}\n\t\telse {\n\t\t\tchannelNr = 1\n\t\t\tcharCode1 = a\n\t\t}\n\t\tif (charCode1 >= 0x11 && charCode1 <= 0x13) {\n\t\t\t// Special character\n\t\t\tlet oneCode: number\n\t\t\tif (charCode1 === 0x11) {\n\t\t\t\toneCode = b + 0x50\n\t\t\t}\n\t\t\telse if (charCode1 === 0x12) {\n\t\t\t\toneCode = b + 0x70\n\t\t\t}\n\t\t\telse {\n\t\t\t\toneCode = b + 0x90\n\t\t\t}\n\n\t\t\tthis.logger.log(\n\t\t\t\tVerboseLevel.INFO,\n\t\t\t\t() =>\n\t\t\t\t\t\"Special char '\" +\n\t\t\t\t\tgetCharForByte(oneCode) +\n\t\t\t\t\t\"' in channel \" +\n\t\t\t\t\tchannelNr,\n\t\t\t)\n\t\t\tcharCodes = [oneCode]\n\t\t}\n\t\telse if (a >= 0x20 && a <= 0x7f) {\n\t\t\tcharCodes = b === 0 ? [a] : [a, b]\n\t\t}\n\t\tif (charCodes) {\n\t\t\tthis.logger.log(\n\t\t\t\tVerboseLevel.DEBUG,\n\t\t\t\t() => 'Char codes = ' + numArrayToHexArray(charCodes).join(','),\n\t\t\t)\n\t\t}\n\t\treturn charCodes\n\t}\n\n\t/**\n\t * Parse extended background attributes as well as new foreground color black.\n\t *\n\t * @param a - The first byte\n\t * @param b - The second byte\n\t * @returns True if background attributes are found\n\t */\n\tprivate parseBackgroundAttributes(a: number, b: number): boolean {\n\t\tconst case1 = (a === 0x10 || a === 0x18) && b >= 0x20 && b <= 0x2f\n\t\tconst case2 = (a === 0x17 || a === 0x1f) && b >= 0x2d && b <= 0x2f\n\t\tif (!(case1 || case2)) {\n\t\t\treturn false\n\t\t}\n\t\tlet index: number\n\t\tconst bkgData: Partial<PenStyles> = {}\n\t\tif (a === 0x10 || a === 0x18) {\n\t\t\tindex = Math.floor((b - 0x20) / 2)\n\t\t\tbkgData.background = backgroundColors[index]\n\t\t\tif (b % 2 === 1) {\n\t\t\t\tbkgData.background = bkgData.background + '_semi'\n\t\t\t}\n\t\t}\n\t\telse if (b === 0x2d) {\n\t\t\tbkgData.background = 'transparent'\n\t\t}\n\t\telse {\n\t\t\tbkgData.foreground = 'black'\n\t\t\tif (b === 0x2f) {\n\t\t\t\tbkgData.underline = true\n\t\t\t}\n\t\t}\n\t\tconst chNr: Channels = a <= 0x17 ? 1 : 2\n\t\tconst channel: Cta608Channel = this.channels[chNr] as Cta608Channel\n\t\tchannel.setBkgData(bkgData)\n\t\treturn true\n\t}\n\n\t/**\n\t * Reset state of parser and its channels.\n\t */\n\treset(): void {\n\t\tfor (let i = 0; i < Object.keys(this.channels).length; i++) {\n\t\t\tconst channel = this.channels[i]\n\t\t\tif (channel) {\n\t\t\t\tchannel.reset()\n\t\t\t}\n\t\t}\n\t\tsetLastCmd(null, null, this.cmdHistory)\n\t}\n\n\t/**\n\t * Trigger the generation of a cue, and the start of a new one if displayScreens are not empty.\n\t */\n\tcueSplitAtTime(t: number): void {\n\t\tfor (const channel of this.channels) {\n\t\t\tif (channel) {\n\t\t\t\tchannel.cueSplitAtTime(t)\n\t\t\t}\n\t\t}\n\t}\n}\n","/**\n * Extract CTA-608 data from a DataView\n *\n * @param raw - The DataView to extract the data from\n * @param cta608Range - The range of the CTA-608 data\n * @returns The extracted CTA-608 data\n *\n * @public\n */\nexport function extractCta608Data(raw: DataView, cta608Range: number[]): number[][] {\n\tlet pos = cta608Range[0]\n\tconst fieldData: number[][] = [[], []]\n\n\tpos += 8 // Skip the identifier up to userDataTypeCode\n\tconst ccCount = raw.getUint8(pos) & 31\n\tpos += 2 // Advance 1 and skip reserved byte\n\n\tfor (let i = 0; i < ccCount; i++) {\n\t\tconst byte = raw.getUint8(pos)\n\t\tconst ccValid = byte & 4\n\t\tconst ccType = byte & 3\n\t\tpos++\n\t\tconst ccData1: number = raw.getUint8(pos) // Keep parity bit\n\t\tpos++\n\t\tconst ccData2: number = raw.getUint8(pos) // Keep parity bit\n\t\tpos++\n\t\tif (ccValid && ((ccData1 & 127) + (ccData2 & 127) !== 0)) { //Check validity and non-empty data\n\t\t\tif (ccType === 0) {\n\t\t\t\tfieldData[0].push(ccData1)\n\t\t\t\tfieldData[0].push(ccData2)\n\t\t\t}\n\t\t\telse if (ccType === 1) {\n\t\t\t\tfieldData[1].push(ccData1)\n\t\t\t\tfieldData[1].push(ccData2)\n\t\t\t}\n\t\t}\n\t}\n\treturn fieldData\n}\n","export function getSeiData(raw: DataView, startPos: number, endPos: number): DataView {\n\tconst data: number[] = []\n\n\tfor (let cursor = startPos; cursor < endPos; cursor++) {\n\t\tif (cursor + 2 < endPos && raw.getUint8(cursor) === 0x00 && raw.getUint8(cursor + 1) === 0x00 && raw.getUint8(cursor + 2) === 0x03) {\n\t\t\tdata.push(0x00)\n\t\t\tdata.push(0x00)\n\t\t\tcursor += 2\n\t\t} \n\t\telse {\n\t\t\tdata.push(raw.getUint8(cursor))\n\t\t}\n\t}\n\n\treturn new DataView(new Uint8Array(data).buffer)\n}\n\nexport function isCea608Sei(payloadType: number, payloadSize: number, sei: DataView, pos: number): boolean {\n\tif (payloadType !== 4 || payloadSize < 8) {\n\t\treturn false\n\t}\n\n\tconst countryCode = sei.getUint8(pos)\n\tif (countryCode !== 0xB5) {\n\t\treturn false\n\t}\n\n\tconst providerCode = sei.getUint16(pos + 1)\n\tif (providerCode !== 0x0031) {\n\t\treturn false\n\t}\n\n\tconst userIdentifier = sei.getUint32(pos + 3)\n\tif (userIdentifier !== 0x47413934) {\n\t\treturn false\n\t}\n\n\tconst userDataTypeCode = sei.getUint8(pos + 7)\n\tif (userDataTypeCode !== 0x03) {\n\t\treturn false\n\t}\n\n\treturn true\n}\n\nexport function isCCType(type: number): boolean {\n\treturn type === 0 || type === 1\n}\n\nexport function isNonEmptyCCData(ccData1: number, ccData2: number): boolean {\n\treturn (ccData1 & 0x7F) > 0 || (ccData2 & 0x7F) > 0\n}\n\n/**\n * H.264 SEI NAL unit type\n */\nconst H264_SEI_TYPE = 0x06\n\n/**\n * H.265 prefix SEI NAL unit type\n */\nconst H265_PREFIX_SEI_TYPE = 39\n\n/**\n * H.265 suffix SEI NAL unit type\n */\nconst H265_SUFFIX_SEI_TYPE = 40\n\n/**\n * H.266 prefix SEI NAL unit type\n */\nconst H266_PREFIX_SEI_TYPE = 23\n\n/**\n * H.266 suffix SEI NAL unit type\n */\nconst H266_SUFFIX_SEI_TYPE = 24\n\n/**\n * Check if a NAL unit type is an SEI (Supplemental Enhancement Information) unit\n * for H.264, H.265, or H.266 codecs.\n *\n * @param unitType - The NAL unit type to check\n * @returns true if the unit type is an SEI NAL unit type for any supported codec\n */\nexport function isSeiNalUnitType(unitType: number): boolean {\n\treturn unitType === H264_SEI_TYPE ||\n\t\tunitType === H265_PREFIX_SEI_TYPE ||\n\t\tunitType === H265_SUFFIX_SEI_TYPE ||\n\t\tunitType === H266_PREFIX_SEI_TYPE ||\n\t\tunitType === H266_SUFFIX_SEI_TYPE\n}\n\n/**\n * Detects whether a NAL unit is an SEI (Supplemental Enhancement Information) unit\n * and returns its type and header size.\n *\n * This function supports auto-detection across H.264, H.265, and H.266 codecs:\n * - H.264: 1-byte NAL header, type in bits 0-4\n * - H.265: 2-byte NAL header, type in bits 1-6 of byte 0\n * - H.266: 2-byte NAL header, type in bits 3-7 of byte 1\n *\n * @param raw - The DataView containing the NAL unit data\n * @param pos - The position of the first NAL header byte\n * @returns An object containing the NAL unit type and header size, or null if not an SEI NAL unit\n */\nexport function extractNalUnitType(raw: DataView, pos: number): { nalType: number; headerSize: number } | null {\n\tconst byte0 = raw.getUint8(pos)\n\n\t// H.264: 1-byte header, type in bits 0-4\n\tconst h264Type = byte0 & 0x1F\n\tif (h264Type === H264_SEI_TYPE) {\n\t\treturn { nalType: h264Type, headerSize: 1 }\n\t}\n\n\t// H.265: 2-byte header, type in bits 1-6 of byte 0\n\tconst h265Type = (byte0 >> 1) & 0x3F\n\tif (h265Type === H265_PREFIX_SEI_TYPE || h265Type === H265_SUFFIX_SEI_TYPE) {\n\t\treturn { nalType: h265Type, headerSize: 2 }\n\t}\n\n\t// H.266: 2-byte header, type in bits 3-7 of byte 1\n\tif (pos + 1 >= raw.byteLength) {\n\t\treturn null\n\t}\n\tconst byte1 = raw.getUint8(pos + 1)\n\tconst h266Type = (byte1 >> 3) & 0x1F\n\tif (h266Type === H266_PREFIX_SEI_TYPE || h266Type === H266_SUFFIX_SEI_TYPE) {\n\t\treturn { nalType: h266Type, headerSize: 2 }\n\t}\n\n\treturn null\n}\n\nexport function parseCta608DataFromSei(sei: DataView, fieldData: number[][]): void {\n\tlet cursor = 0\n\t// The last byte is rbsp_trailing_bits, so stop before it\n\twhile (cursor < sei.byteLength - 1) {\n\t\tlet payloadType = 0\n\t\tlet payloadSize = 0\n\t\tlet now\n\n\t\tdo {\n\t\t\tpayloadType += now = sei.getUint8(cursor++)\n\t\t} while (now === 0xFF)\n\t\tdo {\n\t\t\tpayloadSize += now = sei.getUint8(cursor++)\n\t\t} while (now === 0xFF)\n\n\t\tif (isCea608Sei(payloadType, payloadSize, sei, cursor)) {\n\t\t\tconst pos = cursor + 10\n\t\t\tconst ccCount = pos + (sei.getUint8(pos - 2) & 0x1F) * 3\n\t\t\tfor (let i = pos; i < ccCount; i += 3) {\n\t\t\t\tconst byte = sei.getUint8(i)\n\t\t\t\tif (byte & 0x04) {\n\t\t\t\t\tconst ccType = byte & 0x03\n\t\t\t\t\tif (isCCType(ccType)) {\n\t\t\t\t\t\tconst ccData1 = sei.getUint8(i + 1)\n\t\t\t\t\t\tconst ccData2 = sei.getUint8(i + 2)\n\t\t\t\t\t\tif (isNonEmptyCCData(ccData1, ccData2)) {\n\t\t\t\t\t\t\tfieldData[ccType].push(ccData1, ccData2)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcursor += payloadSize\n\t}\n}\n","import {\n\textractNalUnitType,\n\tgetSeiData,\n\tparseCta608DataFromSei,\n} from './utils/seiHelpers.ts'\n\n/**\n * Extracts CEA-608 data from a given sample.\n *\n * @param raw - The DataView with media data\n * @param startPos - The start position within the DataView\n * @param sampleSize - The size of the sample in bytes\n * @returns fieldData array containing field 1 and field 2 data arrays\n *\n * @public\n */\nexport function extractCta608DataFromSample(raw: DataView, startPos: number, sampleSize: number): number[][] {\n\tlet nalSize: number = 0\n\tconst fieldData: number[][] = [[], []]\n\n\t// Loop needs to account for maximum NALU header size (H.265/H.266 = 6 bytes: 4-byte size + 2-byte header)\n\tfor (let cursor = startPos; cursor < startPos + sampleSize - 6; cursor++) {\n\t\tnalSize = raw.getUint32(cursor)\n\n\t\t// The NAL unit data (nalSize bytes) starts after the 4-byte length prefix\n\t\tconst nalEnd = cursor + 4 + nalSize\n\n\t\t// Make sure that we don't go out of bounds\n\t\tif (nalEnd > startPos + sampleSize) {\n\t\t\tbreak\n\t\t}\n\n\t\t// Only process Supplemental Enhancement Information (SEI) NAL units\n\t\tconst seiInfo = extractNalUnitType(raw, cursor + 4)\n\t\tif (seiInfo) {\n\t\t\tconst seiStart = cursor + 4 + seiInfo.headerSize\n\t\t\tif (nalEnd <= raw.byteLength) {\n\t\t\t\tconst seiData = getSeiData(raw, seiStart, nalEnd)\n\t\t\t\tparseCta608DataFromSei(seiData, fieldData)\n\t\t\t}\n\t\t}\n\n\t\t// Jump to the next NAL unit\n\t\tcursor += nalSize + 3\n\t}\n\treturn fieldData\n}\n","import { extractNalUnitType } from './utils/seiHelpers.ts'\n\n/**\n * Find CTA-608 NAL units in a video stream\n *\n * @param raw - The DataView to extract the data from\n * @param startPos - The start position of the data\n * @param size - The size of the data\n * @returns The extracted CTA-608 NAL units\n *\n * @public\n */\nexport function findCta608Nalus(raw: DataView, startPos: number, size: number): number[][] {\n\tlet nalSize = 0, cursor = startPos\n\tconst cta608NaluRanges = []\n\n\t// Check SEI data according to ANSI-SCTE 128\n\tconst isCTA608SEI = (payloadType: number, payloadSize: number, raw: DataView, pos: number) => {\n\t\tif (payloadType !== 4 || payloadSize < 8) {\n\t\t\treturn null\n\t\t}\n\t\tconst countryCode = raw.getUint8(pos)\n\t\tconst providerCode = raw.getUint16(pos + 1)\n\t\tconst userIdentifier = raw.getUint32(pos + 3)\n\t\tconst userDataTypeCode = raw.getUint8(pos + 7)\n\t\treturn countryCode == 181 && providerCode == 49 && userIdentifier == 1195456820 && userDataTypeCode == 3\n\t}\n\n\twhile (cursor < startPos + size) {\n\t\tnalSize = raw.getUint32(cursor)\n\n\t\tconst seiInfo = extractNalUnitType(raw, cursor + 4)\n\t\tif (seiInfo) {\n\t\t\t// SEI NAL Unit. The NAL header is 1 byte (H.264) or 2 bytes (H.265/H.266)\n\t\t\tlet pos = cursor + 4 + seiInfo.headerSize\n\t\t\tlet payloadType = -1\n\t\t\twhile (pos < cursor + 4 + nalSize - 1) { // The last byte should be rbsp_trailing_bits\n\t\t\t\tpayloadType = 0\n\t\t\t\tlet b = 255\n\t\t\t\twhile (b === 255) {\n\t\t\t\t\tb = raw.getUint8(pos)\n\t\t\t\t\tpayloadType += b\n\t\t\t\t\tpos++\n\t\t\t\t}\n\t\t\t\tlet payloadSize = 0\n\t\t\t\tb = 255\n\t\t\t\twhile (b === 255) {\n\t\t\t\t\tb = raw.getUint8(pos)\n\t\t\t\t\tpayloadSize += b\n\t\t\t\t\tpos++\n\t\t\t\t}\n\t\t\t\tif (isCTA608SEI(payloadType, payloadSize, raw, pos)) {\n\t\t\t\t\tcta608NaluRanges.push([pos, payloadSize])\n\t\t\t\t}\n\t\t\t\tpos += payloadSize\n\t\t\t}\n\t\t}\n\t\tcursor += nalSize + 4\n\t}\n\treturn cta608NaluRanges\n}\n","/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2015-2016, DASH Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * 2. Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\n/**\n * SCC Parser\n *\n * @public\n */\nexport class SccParser {\n\thasHeader: boolean = false\n\tnrLinesParsed: number = 0\n\tprocessor: any\n\tfield: number | any\n\n\tconstructor(processor: any, field: number | any = 1) {\n\t\tthis.processor = processor\n\t\tthis.field = field\n\t}\n\n\tparse(text: string): void {\n\t\tconst lines = text.split(/\\r?\\n/)\n\t\tthis.nrLinesParsed = 0\n\n\t\tif (lines[0] === 'Scenarist_SCC V1.0') {\n\t\t\tthis.hasHeader = true\n\t\t\tthis.nrLinesParsed++\n\t\t}\n\n\t\tfor (let l = 1; l < lines.length; l += 2) {\n\t\t\tif (lines[l] !== '') {\n\t\t\t\tbreak // Every second line should be empty\n\t\t\t}\n\t\t\tthis.nrLinesParsed++\n\t\t\tconst lineData = this.parseDataLine(lines[l + 1])\n\t\t\tif (lineData === null) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tthis.nrLinesParsed++\n\t\t\tthis.processor.addData(lineData[0], lineData[1])\n\t\t}\n\t}\n\n\tparseDataLine(line: string): [number, number[]] | null {\n\t\tif (!line) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst lineParts = line.split(/\\s+/)\n\t\tconst timeData = lineParts[0]\n\t\tconst ceaData: number[] = []\n\n\t\tfor (let i = 1; i < lineParts.length; i++) {\n\t\t\tconst fourHexChars = lineParts[i]\n\t\t\tconst a = parseInt(fourHexChars.substring(0, 2), 16)\n\t\t\tconst b = parseInt(fourHexChars.substring(2, 4), 16)\n\t\t\tceaData.push(a, b)\n\t\t}\n\n\t\tconst time = this.timeConverter(timeData)\n\t\treturn [time, ceaData]\n\t}\n\n\ttimeConverter(smpteTs: string): number {\n\t\tconst parts = smpteTs.split(':')\n\t\tif (parts.length === 3) {\n\t\t\tconst lastParts = parts[2].split(';')\n\t\t\tparts[2] = lastParts[0]\n\t\t\tconst frames = parseInt(lastParts[1], 10)\n\t\t\treturn (30 * (60 * (60 * parseInt(parts[0], 10) + parseInt(parts[1], 10)) + parseInt(parts[2], 10)) + frames) * 1001 / 30000\n\t\t}\n\t\treturn 0 // in case if format is incorrect\n\t}\n\n\tgetHeaderStatus(): boolean {\n\t\treturn this.hasHeader\n\t}\n\n\tgetField(): number | any {\n\t\treturn this.field\n\t}\n\n\tgetLinesParsed(): number {\n\t\treturn this.nrLinesParsed\n\t}\n}\n"],"mappings":";;;;;;;;;AAUA,MAAa,eAAe;CAC3B,OAAO;C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M,WAAW,KAAK,cAAc,MAAM,IAAI,GAAG;AACjD,OAAI,aAAa,KAChB;AAED,QAAK;AACL,QAAK,UAAU,QAAQ,SAAS,IAAI,SAAS,GAAG;;;CAIlD,cAAc,MAAyC;AACtD,MAAI,CAAC,KACJ,QAAO;EAGR,MAAM,YAAY,KAAK,MAAM,MAAM;EACnC,MAAM,WAAW,UAAU;EAC3B,MAAMC,UAAoB,EAAE;AAE5B,OAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;GAC1C,MAAM,eAAe,UAAU;GAC/B,MAAM,IAAI,SAAS,aAAa,UAAU,GAAG,EAAE,EAAE,GAAG;GACpD,MAAM,IAAI,SAAS,aAAa,UAAU,GAAG,EAAE,EAAE,GAAG;AACpD,WAAQ,KAAK,GAAG,EAAE;;AAInB,SAAO,CADM,KAAK,cAAc,SAAS,EAC3B,QAAQ;;CAGvB,cAAc,SAAyB;EACtC,MAAM,QAAQ,QAAQ,MAAM,IAAI;AAChC,MAAI,MAAM,WAAW,GAAG;GACvB,MAAM,YAAY,MAAM,GAAG,MAAM,IAAI;AACrC,SAAM,KAAK,UAAU;GACrB,MAAM,SAAS,SAAS,UAAU,IAAI,GAAG;AACzC,WAAQ,MAAM,MAAM,KAAK,SAAS,MAAM,IAAI,GAAG,GAAG,SAAS,MAAM,IAAI,GAAG,IAAI,SAAS,MAAM,IAAI,GAAG,IAAI,UAAU,OAAO;;AAExH,SAAO;;CAGR,kBAA2B;AAC1B,SAAO,KAAK;;CAGb,WAAyB;AACxB,SAAO,KAAK;;CAGb,iBAAyB;AACxB,SAAO,KAAK"}
1
+ {"version":3,"file":"index.js","names":["m: string","specialCea608CharsCodes: Record<number, number>","i: number","chars: string[]","styles: PenStyles","displayText: string[]","styles: Partial<PenStyles>","backgroundColors: string[]","hexArray: string[]","rowsHighCh1: Record<number, number>","rowsHighCh2: Record<number, number>","rowsLowCh1: Record<number, number>","rowsLowCh2: Record<number, number>","cmdFound: boolean","charsFound: number[] | null","chNr: number","row: number","chNr: Channels","pacData: PACData","channelNr: Channels","charCodes: number[]","charCode1: number | null","oneCode: number","index: number","bkgData: Partial<PenStyles>","fieldData: number[][]","fieldData: number[][]","data: number[]","nalSize: number","fieldData: number[][]","raw","ceaData: number[]"],"sources":["../src/VerboseLevel.ts","../src/CaptionsLogger.ts","../src/PenState.ts","../src/StyledUnicodeChar.ts","../src/utils/NR_COLS.ts","../src/utils/specialCea608CharsCodes.ts","../src/utils/getCharForByte.ts","../src/Row.ts","../src/utils/NR_ROWS.ts","../src/CaptionScreen.ts","../src/Cta608Channel.ts","../src/utils/backgroundColors.ts","../src/utils/createCmdHistory.ts","../src/utils/hasCmdRepeated.ts","../src/utils/numArrayToHexArray.ts","../src/utils/rowsHighCh1.ts","../src/utils/rowsHighCh2.ts","../src/utils/rowsLowCh1.ts","../src/utils/rowsLowCh2.ts","../src/utils/setLastCmd.ts","../src/Cta608Parser.ts","../src/utils/parseCcData.ts","../src/extractCta608Data.ts","../src/utils/isCta608UserData.ts","../src/utils/obuHelpers.ts","../src/extractCta608DataFromAv1Sample.ts","../src/utils/seiHelpers.ts","../src/extractCta608DataFromSample.ts","../src/findCta608Nalus.ts","../src/SccParser.ts"],"sourcesContent":["import type { ValueOf } from '@svta/cml-utils'\n\n/**\n * Logging levels for the CTA-608 parser.\n *\n *\n * @enum\n *\n * @public\n */\nexport const VerboseLevel = {\n\tERROR: 0,\n\tTEXT: 1,\n\tWARNING: 2,\n\tINFO: 2,\n\tDEBUG: 3,\n\tDATA: 3,\n} as const\n\n/**\n * @public\n */\nexport type VerboseLevel = ValueOf<typeof VerboseLevel>;\n","/**\n *\n * This code was ported from the dash.js project at:\n * https://github.com/Dash-Industry-Forum/dash.js/blob/development/externals/cea608-parser.js\n * https://github.com/Dash-Industry-Forum/dash.js/commit/8269b26a761e0853bb21d78780ed945144ecdd4d#diff-71bc295a2d6b6b7093a1d3290d53a4b2\n *\n * The original copyright appears below:\n *\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2015-2016, DASH Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * 2. Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport { VerboseLevel } from './VerboseLevel.ts'\n\n/**\n * CaptionsLogger. To be removed in the future.\n *\n * @public\n */\nexport class CaptionsLogger {\n\tpublic time: number | null = null\n\tpublic verboseLevel: VerboseLevel = VerboseLevel.ERROR\n\n\tlog(severity: VerboseLevel, msg: string | (() => string)): void {\n\t\tif (this.verboseLevel >= severity) {\n\t\t\tconst m: string = typeof msg === 'function' ? msg() : msg\n\t\t\tconsole.log(`${this.time} [${severity}] ${m}`)\n\t\t}\n\t}\n}\n","/**\n *\n * This code was ported from the dash.js project at:\n * https://github.com/Dash-Industry-Forum/dash.js/blob/development/externals/cea608-parser.js\n * https://github.com/Dash-Industry-Forum/dash.js/commit/8269b26a761e0853bb21d78780ed945144ecdd4d#diff-71bc295a2d6b6b7093a1d3290d53a4b2\n *\n * The original copyright appears below:\n *\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2015-2016, DASH Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * 2. Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport type { PenStyles } from './PenStyles.ts'\n\n/**\n * Pen state.\n *\n * @public\n */\nexport class PenState {\n\tpublic foreground: string = 'white'\n\tpublic underline: boolean = false\n\tpublic italics: boolean = false\n\tpublic background: string = 'black'\n\tpublic flash: boolean = false\n\n\treset(): void {\n\t\tthis.foreground = 'white'\n\t\tthis.underline = false\n\t\tthis.italics = false\n\t\tthis.background = 'black'\n\t\tthis.flash = false\n\t}\n\n\tsetStyles(styles: Partial<PenStyles>): void {\n\t\tconst attribs = [\n\t\t\t'foreground',\n\t\t\t'underline',\n\t\t\t'italics',\n\t\t\t'background',\n\t\t\t'flash',\n\t\t]\n\t\tfor (const style of attribs) {\n\t\t\tif (Object.prototype.hasOwnProperty.call(styles, style)) {\n\t\t\t\t(this as any)[style] = (styles as any)[style]\n\t\t\t}\n\t\t}\n\t}\n\n\tisDefault(): boolean {\n\t\treturn (\n\t\t\tthis.foreground === 'white' &&\n\t\t\t!this.underline &&\n\t\t\t!this.italics &&\n\t\t\tthis.background === 'black' &&\n\t\t\t!this.flash\n\t\t)\n\t}\n\n\tequals(other: PenState): boolean {\n\t\treturn (\n\t\t\tthis.foreground === other.foreground &&\n\t\t\tthis.underline === other.underline &&\n\t\t\tthis.italics === other.italics &&\n\t\t\tthis.background === other.background &&\n\t\t\tthis.flash === other.flash\n\t\t)\n\t}\n\n\tcopy(newPenState: PenState): void {\n\t\tthis.foreground = newPenState.foreground\n\t\tthis.underline = newPenState.underline\n\t\tthis.italics = newPenState.italics\n\t\tthis.background = newPenState.background\n\t\tthis.flash = newPenState.flash\n\t}\n}\n","/**\n *\n * This code was ported from the dash.js project at:\n * https://github.com/Dash-Industry-Forum/dash.js/blob/development/externals/cea608-parser.js\n * https://github.com/Dash-Industry-Forum/dash.js/commit/8269b26a761e0853bb21d78780ed945144ecdd4d#diff-71bc295a2d6b6b7093a1d3290d53a4b2\n *\n * The original copyright appears below:\n *\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2015-2016, DASH Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * 2. Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport { PenState } from './PenState.ts'\n\n/**\n * Unicode character with styling and background.\n *\n * @public\n */\nexport class StyledUnicodeChar {\n\tuchar: string = ' '\n\tpenState: PenState = new PenState()\n\n\treset(): void {\n\t\tthis.uchar = ' '\n\t\tthis.penState.reset()\n\t}\n\n\tsetChar(uchar: string, newPenState: PenState): void {\n\t\tthis.uchar = uchar\n\t\tthis.penState.copy(newPenState)\n\t}\n\n\tsetPenState(newPenState: PenState): void {\n\t\tthis.penState.copy(newPenState)\n\t}\n\n\tequals(other: StyledUnicodeChar): boolean {\n\t\treturn this.uchar === other.uchar && this.penState.equals(other.penState)\n\t}\n\n\tcopy(newChar: StyledUnicodeChar): void {\n\t\tthis.uchar = newChar.uchar\n\t\tthis.penState.copy(newChar.penState)\n\t}\n\n\tisEmpty(): boolean {\n\t\treturn this.uchar === ' ' && this.penState.isDefault()\n\t}\n}\n","export const NR_COLS = 100\n","/**\n * Exceptions from regular ASCII. CodePoints are mapped to UTF-16 codes\n */\nexport const specialCea608CharsCodes: Record<number, number> = {\n\t42: 225, // lowercase a, acute accent\n\t92: 233, // lowercase e, acute accent\n\t94: 237, // lowercase i, acute accent\n\t95: 243, // lowercase o, acute accent\n\t96: 250, // lowercase u, acute accent\n\t123: 231, // lowercase c with cedilla\n\t124: 247, // division symbol\n\t125: 209, // uppercase N tilde\n\t126: 241, // lowercase n tilde\n\t127: 9608, // Full block\n\n\n\n\t// THIS BLOCK INCLUDES THE 16 EXTENDED (TWO-BYTE) LINE 21 CHARACTERS\n\t// THAT COME FROM HI BYTE=0x11 AND LOW BETWEEN 0x30 AND 0x3F\n\t// THIS MEANS THAT \\x50 MUST BE ADDED TO THE VALUES\n\t128: 174, // Registered symbol (R)\n\t129: 176, // degree sign\n\t130: 189, // 1/2 symbolOutputFilter\n\t131: 191, // Inverted (open) question mark\n\t132: 8482, // Trademark symbol (TM)\n\t133: 162, // Cents symbol\n\t134: 163, // Pounds sterling\n\t135: 9834, // Music 8'th note\n\t136: 224, // lowercase a, grave accent\n\t137: 32, // transparent space (regular)\n\t138: 232, // lowercase e, grave accent\n\t139: 226, // lowercase a, circumflex accent\n\t140: 234, // lowercase e, circumflex accent\n\t141: 238, // lowercase i, circumflex accent\n\t142: 244, // lowercase o, circumflex accent\n\t143: 251, // lowercase u, circumflex accent\n\n\n\t// THIS BLOCK INCLUDES THE 32 EXTENDED (TWO-BYTE) LINE 21 CHARACTERS\n\t// THAT COME FROM HI BYTE=0x12 AND LOW BETWEEN 0x20 AND 0x3F\n\t144: 193, // capital letter A with acute\n\t145: 201, // capital letter E with acute\n\t146: 211, // capital letter O with acute\n\t147: 218, // capital letter U with acute\n\t148: 220, // capital letter U with diaresis\n\t149: 252, // lowercase letter U with diaeresis\n\t150: 8216, // opening single quote\n\t151: 161, // inverted exclamation mark\n\t152: 42, // asterisk\n\t153: 8217, // closing single quote\n\t154: 9473, // box drawings heavy horizontal\n\t155: 169, // copyright sign\n\t156: 8480, // Service mark\n\t157: 8226, // (round) bullet\n\t158: 8220, // Left double quotation mark\n\t159: 8221, // Right double quotation mark\n\t160: 192, // uppercase A, grave accent\n\t161: 194, // uppercase A, circumflex\n\t162: 199, // uppercase C with cedilla\n\t163: 200, // uppercase E, grave accent\n\t164: 202, // uppercase E, circumflex\n\t165: 203, // capital letter E with diaresis\n\t166: 235, // lowercase letter e with diaresis\n\t167: 206, // uppercase I, circumflex\n\t168: 207, // uppercase I, with diaresis\n\t169: 239, // lowercase i, with diaresis\n\t170: 212, // uppercase O, circumflex\n\t171: 217, // uppercase U, grave accent\n\t172: 249, // lowercase u, grave accent\n\t173: 219, // uppercase U, circumflex\n\t174: 171, // left-pointing double angle quotation mark\n\t175: 187, // right-pointing double angle quotation mark\n\n\n\t// THIS BLOCK INCLUDES THE 32 EXTENDED (TWO-BYTE) LINE 21 CHARACTERS\n\t// THAT COME FROM HI BYTE=0x13 AND LOW BETWEEN 0x20 AND 0x3F\n\t176: 195, // Uppercase A, tilde\n\t177: 227, // Lowercase a, tilde\n\t178: 205, // Uppercase I, acute accent\n\t179: 204, // Uppercase I, grave accent\n\t180: 236, // Lowercase i, grave accent\n\t181: 210, // Uppercase O, grave accent\n\t182: 242, // Lowercase o, grave accent\n\t183: 213, // Uppercase O, tilde\n\t184: 245, // Lowercase o, tilde\n\t185: 123, // Open curly brace\n\t186: 125, // Closing curly brace\n\t187: 92, // Backslash\n\t188: 94, // Caret\n\t189: 95, // Underscore\n\t190: 124, // Pipe (vertical line)\n\t191: 8764, // Tilde operator\n\t192: 196, // Uppercase A, umlaut\n\t193: 228, // Lowercase A, umlaut\n\t194: 214, // Uppercase O, umlaut\n\t195: 246, // Lowercase o, umlaut\n\t196: 223, // Esszett (sharp S)\n\t197: 165, // Yen symbolOutputFilter\n\t198: 164, // Generic currency sign\n\t199: 9475, // Box drawings heavy vertical\n\t200: 197, // Uppercase A, ring\n\t201: 229, // Lowercase A, ring\n\t202: 216, // Uppercase O, stroke\n\t203: 248, // Lowercase o, strok\n\t204: 9487, // Box drawings heavy down and right\n\t205: 9491, // Box drawings heavy down and left\n\t206: 9495, // Box drawings heavy up and right\n\t207: 9499, // Box drawings heavy up and left\n}\n","import { specialCea608CharsCodes } from './specialCea608CharsCodes.ts'\n\nexport function getCharForByte(byte: number): string {\n\treturn String.fromCharCode(specialCea608CharsCodes[byte] || byte)\n};\n","/**\n *\n * This code was ported from the dash.js project at:\n * https://github.com/Dash-Industry-Forum/dash.js/blob/development/externals/cea608-parser.js\n * https://github.com/Dash-Industry-Forum/dash.js/commit/8269b26a761e0853bb21d78780ed945144ecdd4d#diff-71bc295a2d6b6b7093a1d3290d53a4b2\n *\n * The original copyright appears below:\n *\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2015-2016, DASH Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * 2. Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport { CaptionsLogger } from './CaptionsLogger.ts'\nimport { PenState } from './PenState.ts'\nimport type { PenStyles } from './PenStyles.ts'\nimport { StyledUnicodeChar } from './StyledUnicodeChar.ts'\nimport { VerboseLevel } from './VerboseLevel.ts'\nimport { NR_COLS } from './utils/NR_COLS.ts'\nimport { getCharForByte } from './utils/getCharForByte.ts'\n\n/**\n * CTA-608 row consisting of NR_COLS instances of StyledUnicodeChar.\n *\n * @public\n */\nexport class Row {\n\tpublic chars: StyledUnicodeChar[] = []\n\tpublic cueStartTime: number | null = null\n\n\tprivate pos: number = 0\n\tprivate currPenState: PenState = new PenState()\n\tprivate logger: CaptionsLogger\n\n\tconstructor(logger: CaptionsLogger = new CaptionsLogger()) {\n\t\tfor (let i = 0; i < NR_COLS; i++) {\n\t\t\tthis.chars.push(new StyledUnicodeChar())\n\t\t}\n\t\tthis.logger = logger\n\t}\n\n\tequals(other: Row): boolean {\n\t\tfor (let i = 0; i < NR_COLS; i++) {\n\t\t\tif (!this.chars[i].equals(other.chars[i])) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\n\tcopy(other: Row): void {\n\t\tfor (let i = 0; i < NR_COLS; i++) {\n\t\t\tthis.chars[i].copy(other.chars[i])\n\t\t}\n\t}\n\n\tisEmpty(): boolean {\n\t\tlet empty = true\n\t\tfor (let i = 0; i < NR_COLS; i++) {\n\t\t\tif (!this.chars[i].isEmpty()) {\n\t\t\t\tempty = false\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\treturn empty\n\t}\n\n\t/**\n\t * Set the cursor to a valid column.\n\t */\n\tsetCursor(absPos: number): void {\n\t\tif (this.pos !== absPos) {\n\t\t\tthis.pos = absPos\n\t\t}\n\n\t\tif (this.pos < 0) {\n\t\t\tthis.logger.log(\n\t\t\t\tVerboseLevel.DEBUG,\n\t\t\t\t'Negative cursor position ' + this.pos,\n\t\t\t)\n\t\t\tthis.pos = 0\n\t\t}\n\t\telse if (this.pos > NR_COLS) {\n\t\t\tthis.logger.log(\n\t\t\t\tVerboseLevel.DEBUG,\n\t\t\t\t'Too large cursor position ' + this.pos,\n\t\t\t)\n\t\t\tthis.pos = NR_COLS\n\t\t}\n\t}\n\n\t/**\n\t * Move the cursor relative to current position.\n\t */\n\tmoveCursor(relPos: number): void {\n\t\tconst newPos = this.pos + relPos\n\t\tif (relPos > 1) {\n\t\t\tfor (let i = this.pos + 1; i < newPos + 1; i++) {\n\t\t\t\tthis.chars[i].setPenState(this.currPenState)\n\t\t\t}\n\t\t}\n\t\tthis.setCursor(newPos)\n\t}\n\n\t/**\n\t * Backspace, move one step back and clear character.\n\t */\n\tbackSpace(): void {\n\t\tthis.moveCursor(-1)\n\t\tthis.chars[this.pos].setChar(' ', this.currPenState)\n\t}\n\n\tinsertChar(byte: number): void {\n\t\tif (byte >= 0x90) {\n\t\t\t// Extended char\n\t\t\tthis.backSpace()\n\t\t}\n\t\tconst char = getCharForByte(byte)\n\t\tif (this.pos >= NR_COLS) {\n\t\t\tthis.logger.log(\n\t\t\t\tVerboseLevel.ERROR,\n\t\t\t\t() =>\n\t\t\t\t\t'Cannot insert ' +\n\t\t\t\t\tbyte.toString(16) +\n\t\t\t\t\t' (' +\n\t\t\t\t\tchar +\n\t\t\t\t\t') at position ' +\n\t\t\t\t\tthis.pos +\n\t\t\t\t\t'. Skipping it!',\n\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tthis.chars[this.pos].setChar(char, this.currPenState)\n\t\tthis.moveCursor(1)\n\t}\n\n\tclearFromPos(startPos: number): void {\n\t\tlet i: number\n\t\tfor (i = startPos; i < NR_COLS; i++) {\n\t\t\tthis.chars[i].reset()\n\t\t}\n\t}\n\n\tclear(): void {\n\t\tthis.clearFromPos(0)\n\t\tthis.pos = 0\n\t\tthis.currPenState.reset()\n\t}\n\n\tclearToEndOfRow(): void {\n\t\tthis.clearFromPos(this.pos)\n\t}\n\n\tgetTextString(): string {\n\t\tconst chars: string[] = []\n\t\tlet empty = true\n\t\tfor (let i = 0; i < NR_COLS; i++) {\n\t\t\tconst char = this.chars[i].uchar\n\t\t\tif (char !== ' ') {\n\t\t\t\tempty = false\n\t\t\t}\n\n\t\t\tchars.push(char)\n\t\t}\n\t\tif (empty) {\n\t\t\treturn ''\n\t\t}\n\t\telse {\n\t\t\treturn chars.join('')\n\t\t}\n\t}\n\n\tsetPenStyles(styles: Partial<PenStyles>): void {\n\t\tthis.currPenState.setStyles(styles)\n\t\tconst currChar = this.chars[this.pos]\n\t\tcurrChar.setPenState(this.currPenState)\n\t}\n}\n","export const NR_ROWS = 15\n","/**\n *\n * This code was ported from the dash.js project at:\n * https://github.com/Dash-Industry-Forum/dash.js/blob/development/externals/cea608-parser.js\n * https://github.com/Dash-Industry-Forum/dash.js/commit/8269b26a761e0853bb21d78780ed945144ecdd4d#diff-71bc295a2d6b6b7093a1d3290d53a4b2\n *\n * The original copyright appears below:\n *\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2015-2016, DASH Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * 2. Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport { CaptionsLogger } from './CaptionsLogger.ts'\nimport type { PACData } from './PACData.ts'\nimport type { PenStyles } from './PenStyles.ts'\nimport { Row } from './Row.ts'\nimport { NR_ROWS } from './utils/NR_ROWS.ts'\nimport { VerboseLevel } from './VerboseLevel.ts'\n\n/**\n * Keep a CTA-608 screen of 32x15 styled characters\n *\n * @public\n */\nexport class CaptionScreen {\n\trows: Row[] = []\n\tprivate currRow: number = NR_ROWS - 1\n\tprivate nrRollUpRows: number | null = null\n\tprivate lastOutputScreen: CaptionScreen | null = null\n\tprivate logger: CaptionsLogger\n\n\tconstructor(logger: CaptionsLogger = new CaptionsLogger()) {\n\t\tfor (let i = 0; i < NR_ROWS; i++) {\n\t\t\tthis.rows.push(new Row(logger))\n\t\t}\n\t\tthis.logger = logger\n\t}\n\n\treset(): void {\n\t\tfor (let i = 0; i < NR_ROWS; i++) {\n\t\t\tthis.rows[i].clear()\n\t\t}\n\t\tthis.currRow = NR_ROWS - 1\n\t}\n\n\tequals(other: CaptionScreen): boolean {\n\t\tlet equal = true\n\t\tfor (let i = 0; i < NR_ROWS; i++) {\n\t\t\tif (!this.rows[i].equals(other.rows[i])) {\n\t\t\t\tequal = false\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\treturn equal\n\t}\n\n\tcopy(other: CaptionScreen): void {\n\t\tfor (let i = 0; i < NR_ROWS; i++) {\n\t\t\tthis.rows[i].copy(other.rows[i])\n\t\t}\n\t}\n\n\tisEmpty(): boolean {\n\t\tlet empty = true\n\t\tfor (let i = 0; i < NR_ROWS; i++) {\n\t\t\tif (!this.rows[i].isEmpty()) {\n\t\t\t\tempty = false\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\treturn empty\n\t}\n\n\tbackSpace(): void {\n\t\tconst row = this.rows[this.currRow]\n\t\trow.backSpace()\n\t}\n\n\tclearToEndOfRow(): void {\n\t\tconst row = this.rows[this.currRow]\n\t\trow.clearToEndOfRow()\n\t}\n\n\t/**\n\t * Insert a character (without styling) in the current row.\n\t */\n\tinsertChar(char: number): void {\n\t\tconst row = this.rows[this.currRow]\n\t\trow.insertChar(char)\n\t}\n\n\tsetPen(styles: Partial<PenStyles>): void {\n\t\tconst row = this.rows[this.currRow]\n\t\trow.setPenStyles(styles)\n\t}\n\n\tmoveCursor(relPos: number): void {\n\t\tconst row = this.rows[this.currRow]\n\t\trow.moveCursor(relPos)\n\t}\n\n\tsetCursor(absPos: number): void {\n\t\tthis.logger.log(VerboseLevel.INFO, 'setCursor: ' + absPos)\n\t\tconst row = this.rows[this.currRow]\n\t\trow.setCursor(absPos)\n\t}\n\n\tsetPAC(pacData: PACData): void {\n\t\tthis.logger.log(\n\t\t\tVerboseLevel.INFO,\n\t\t\t() => 'pacData = ' + JSON.stringify(pacData),\n\t\t)\n\t\tlet newRow = pacData.row - 1\n\t\tif (this.nrRollUpRows && newRow < this.nrRollUpRows - 1) {\n\t\t\tnewRow = this.nrRollUpRows - 1\n\t\t}\n\n\t\t// Make sure this only affects Roll-up Captions by checking this.nrRollUpRows\n\t\tif (this.nrRollUpRows && this.currRow !== newRow) {\n\t\t\t// clear all rows first\n\t\t\tfor (let i = 0; i < NR_ROWS; i++) {\n\t\t\t\tthis.rows[i].clear()\n\t\t\t}\n\n\t\t\t// Copy this.nrRollUpRows rows from lastOutputScreen and place it in the newRow location\n\t\t\t// topRowIndex - the start of rows to copy (inclusive index)\n\t\t\tconst topRowIndex = this.currRow + 1 - this.nrRollUpRows\n\t\t\t// We only copy if the last position was already shown.\n\t\t\t// We use the cueStartTime value to check this.\n\t\t\tconst lastOutputScreen = this.lastOutputScreen\n\t\t\tif (lastOutputScreen) {\n\t\t\t\tconst prevLineTime = lastOutputScreen.rows[topRowIndex].cueStartTime\n\t\t\t\tconst time = this.logger.time\n\t\t\t\tif (prevLineTime !== null && time !== null && prevLineTime < time) {\n\t\t\t\t\tfor (let i = 0; i < this.nrRollUpRows; i++) {\n\t\t\t\t\t\tthis.rows[newRow - this.nrRollUpRows + i + 1].copy(\n\t\t\t\t\t\t\tlastOutputScreen.rows[topRowIndex + i],\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.currRow = newRow\n\t\tconst row = this.rows[this.currRow]\n\t\tif (pacData.indent !== null) {\n\t\t\tconst indent = pacData.indent\n\t\t\tconst prevPos = Math.max(indent - 1, 0)\n\t\t\trow.setCursor(pacData.indent)\n\t\t\tpacData.color = row.chars[prevPos].penState.foreground\n\t\t}\n\t\tconst styles: PenStyles = {\n\t\t\tforeground: pacData.color,\n\t\t\tunderline: pacData.underline,\n\t\t\titalics: pacData.italics,\n\t\t\tbackground: 'black',\n\t\t\tflash: false,\n\t\t}\n\t\tthis.setPen(styles)\n\t}\n\n\t/**\n\t * Set background/extra foreground, but first do back_space, and then insert space (backwards compatibility).\n\t */\n\tsetBkgData(bkgData: Partial<PenStyles>): void {\n\t\tthis.logger.log(\n\t\t\tVerboseLevel.INFO,\n\t\t\t() => 'bkgData = ' + JSON.stringify(bkgData),\n\t\t)\n\t\tthis.backSpace()\n\t\tthis.setPen(bkgData)\n\t\tthis.insertChar(0x20) // Space\n\t}\n\n\tsetRollUpRows(nrRows: number | null): void {\n\t\tthis.nrRollUpRows = nrRows\n\t}\n\n\trollUp(): void {\n\t\tif (this.nrRollUpRows === null) {\n\t\t\tthis.logger.log(\n\t\t\t\tVerboseLevel.DEBUG,\n\t\t\t\t'roll_up but nrRollUpRows not set yet',\n\t\t\t)\n\t\t\treturn // Not properly setup\n\t\t}\n\t\tthis.logger.log(VerboseLevel.TEXT, () => this.getDisplayText())\n\t\tconst topRowIndex = this.currRow + 1 - this.nrRollUpRows\n\t\tconst topRow = this.rows.splice(topRowIndex, 1)[0]\n\t\ttopRow.clear()\n\t\tthis.rows.splice(this.currRow, 0, topRow)\n\t\tthis.logger.log(VerboseLevel.INFO, 'Rolling up')\n\t}\n\n\t/**\n\t * Get all non-empty rows with as unicode text.\n\t */\n\tgetDisplayText(asOneRow?: boolean): string {\n\t\tasOneRow = asOneRow || false\n\t\tconst displayText: string[] = []\n\t\tlet text = ''\n\t\tlet rowNr = -1\n\t\tfor (let i = 0; i < NR_ROWS; i++) {\n\t\t\tconst rowText = this.rows[i].getTextString()\n\t\t\tif (rowText) {\n\t\t\t\trowNr = i + 1\n\t\t\t\tif (asOneRow) {\n\t\t\t\t\tdisplayText.push('Row ' + rowNr + \": '\" + rowText + \"'\")\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdisplayText.push(rowText.trim())\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (displayText.length > 0) {\n\t\t\tif (asOneRow) {\n\t\t\t\ttext = '[' + displayText.join(' | ') + ']'\n\t\t\t}\n\t\t\telse {\n\t\t\t\ttext = displayText.join('\\n')\n\t\t\t}\n\t\t}\n\t\treturn text\n\t}\n\n\tgetTextAndFormat(): Row[] {\n\t\treturn this.rows\n\t}\n}\n","/**\n *\n * This code was ported from the dash.js project at:\n * https://github.com/Dash-Industry-Forum/dash.js/blob/development/externals/cea608-parser.js\n * https://github.com/Dash-Industry-Forum/dash.js/commit/8269b26a761e0853bb21d78780ed945144ecdd4d#diff-71bc295a2d6b6b7093a1d3290d53a4b2\n *\n * The original copyright appears below:\n *\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2015-2016, DASH Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * 2. Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport type { CaptionModes } from './CaptionModes.ts'\nimport { CaptionScreen } from './CaptionScreen.ts'\nimport { CaptionsLogger } from './CaptionsLogger.ts'\nimport type { CueHandler } from './CueHandler.ts'\nimport type { PACData } from './PACData.ts'\nimport type { PenStyles } from './PenStyles.ts'\nimport type { Row } from './Row.ts'\nimport { VerboseLevel } from './VerboseLevel.ts'\nimport { NR_ROWS } from './utils/NR_ROWS.ts'\n\n/**\n * CTA-608 Channel\n *\n * @public\n */\nexport class Cta608Channel {\n\tchNr: number\n\toutputFilter: CueHandler\n\tmode: CaptionModes\n\tdisplayedMemory: CaptionScreen\n\tnonDisplayedMemory: CaptionScreen\n\tlastOutputScreen: CaptionScreen\n\tcurrRollUpRow: Row\n\twriteScreen: CaptionScreen\n\tcueStartTime: number | null\n\n\tprivate logger: CaptionsLogger\n\n\tconstructor(\n\t\tchannelNumber: number,\n\t\toutputFilter: CueHandler,\n\t\tlogger: CaptionsLogger = new CaptionsLogger(),\n\t) {\n\t\tthis.chNr = channelNumber\n\t\tthis.outputFilter = outputFilter\n\t\tthis.mode = null\n\t\tthis.displayedMemory = new CaptionScreen(logger)\n\t\tthis.nonDisplayedMemory = new CaptionScreen(logger)\n\t\tthis.lastOutputScreen = new CaptionScreen(logger)\n\t\tthis.currRollUpRow = this.displayedMemory.rows[NR_ROWS - 1]\n\t\tthis.writeScreen = this.displayedMemory\n\t\tthis.mode = null\n\t\tthis.cueStartTime = null // Keeps track of where a cue started.\n\t\tthis.logger = logger\n\n\t\tthis.logger.log(VerboseLevel.INFO, 'new Cea608Channel(' + this.chNr + ')')\n\t}\n\n\treset(): void {\n\t\tthis.mode = null\n\t\tthis.displayedMemory.reset()\n\t\tthis.nonDisplayedMemory.reset()\n\t\tthis.lastOutputScreen.reset()\n\t\tthis.outputFilter?.reset?.()\n\t\tthis.currRollUpRow = this.displayedMemory.rows[NR_ROWS - 1]\n\t\tthis.writeScreen = this.displayedMemory\n\t\tthis.mode = null\n\t\tthis.cueStartTime = null\n\t}\n\n\tgetHandler(): CueHandler {\n\t\treturn this.outputFilter\n\t}\n\n\tsetHandler(outputFilter: CueHandler): void {\n\t\tthis.outputFilter = outputFilter\n\t}\n\n\tsetPAC(pacData: PACData): void {\n\t\tthis.writeScreen.setPAC(pacData)\n\t}\n\n\tsetBkgData(bkgData: Partial<PenStyles>): void {\n\t\tthis.writeScreen.setBkgData(bkgData)\n\t}\n\n\tsetMode(newMode: CaptionModes): void {\n\t\tif (newMode === this.mode) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.mode = newMode\n\t\tthis.logger.log(VerboseLevel.INFO, () => 'MODE=' + newMode)\n\t\tif (this.mode === 'MODE_POP-ON') {\n\t\t\tthis.writeScreen = this.nonDisplayedMemory\n\t\t}\n\t\telse {\n\t\t\tthis.writeScreen = this.displayedMemory\n\t\t\tthis.writeScreen.reset()\n\t\t}\n\t\tif (this.mode !== 'MODE_ROLL-UP') {\n\t\t\tthis.displayedMemory.setRollUpRows(null)\n\t\t\tthis.nonDisplayedMemory.setRollUpRows(null)\n\t\t}\n\t\tthis.mode = newMode\n\t}\n\n\tinsertChars(chars: number[]): void {\n\t\tfor (const char of chars) {\n\t\t\tthis.writeScreen.insertChar(char)\n\t\t}\n\n\t\tconst screen =\n\t\t\tthis.writeScreen === this.displayedMemory ? 'DISP' : 'NON_DISP'\n\t\tthis.logger.log(\n\t\t\tVerboseLevel.INFO,\n\t\t\t() => screen + ': ' + this.writeScreen.getDisplayText(true),\n\t\t)\n\t\tif (this.mode === 'MODE_PAINT-ON' || this.mode === 'MODE_ROLL-UP') {\n\t\t\tthis.logger.log(\n\t\t\t\tVerboseLevel.TEXT,\n\t\t\t\t() => 'DISPLAYED: ' + this.displayedMemory.getDisplayText(true),\n\t\t\t)\n\t\t\tthis.outputDataUpdate()\n\t\t}\n\t}\n\n\tccRCL(): void {\n\t\t// Resume Caption Loading (switch mode to Pop On)\n\t\tthis.logger.log(VerboseLevel.INFO, 'RCL - Resume Caption Loading')\n\t\tthis.setMode('MODE_POP-ON')\n\t}\n\n\tccBS(): void {\n\t\t// BackSpace\n\t\tthis.logger.log(VerboseLevel.INFO, 'BS - BackSpace')\n\t\tif (this.mode === 'MODE_TEXT') {\n\t\t\treturn\n\t\t}\n\n\t\tthis.writeScreen.backSpace()\n\t\tif (this.writeScreen === this.displayedMemory) {\n\t\t\tthis.outputDataUpdate()\n\t\t}\n\t}\n\n\tccAOF(): void {\n\t\t// Reserved (formerly Alarm Off)\n\t}\n\n\tccAON(): void {\n\t\t// Reserved (formerly Alarm On)\n\t}\n\n\tccDER(): void {\n\t\t// Delete to End of Row\n\t\tthis.logger.log(VerboseLevel.INFO, 'DER- Delete to End of Row')\n\t\tthis.writeScreen.clearToEndOfRow()\n\t\tthis.outputDataUpdate()\n\t}\n\n\tccRU(nrRows: number | null): void {\n\t\t// Roll-Up Captions-2,3,or 4 Rows\n\t\tthis.logger.log(VerboseLevel.INFO, 'RU(' + nrRows + ') - Roll Up')\n\t\tthis.writeScreen = this.displayedMemory\n\t\tthis.setMode('MODE_ROLL-UP')\n\t\tthis.writeScreen.setRollUpRows(nrRows)\n\t}\n\n\tccFON(): void {\n\t\t// Flash On\n\t\tthis.logger.log(VerboseLevel.INFO, 'FON - Flash On')\n\t\tthis.writeScreen.setPen({ flash: true })\n\t}\n\n\tccRDC(): void {\n\t\t// Resume Direct Captioning (switch mode to PaintOn)\n\t\tthis.logger.log(VerboseLevel.INFO, 'RDC - Resume Direct Captioning')\n\t\tthis.setMode('MODE_PAINT-ON')\n\t}\n\n\tccTR(): void {\n\t\t// Text Restart in text mode (not supported, however)\n\t\tthis.logger.log(VerboseLevel.INFO, 'TR')\n\t\tthis.setMode('MODE_TEXT')\n\t}\n\n\tccRTD(): void {\n\t\t// Resume Text Display in Text mode (not supported, however)\n\t\tthis.logger.log(VerboseLevel.INFO, 'RTD')\n\t\tthis.setMode('MODE_TEXT')\n\t}\n\n\tccEDM(): void {\n\t\t// Erase Displayed Memory\n\t\tthis.logger.log(VerboseLevel.INFO, 'EDM - Erase Displayed Memory')\n\t\tthis.displayedMemory.reset()\n\t\tthis.outputDataUpdate(true)\n\t}\n\n\tccCR(): void {\n\t\t// Carriage Return\n\t\tthis.logger.log(VerboseLevel.INFO, 'CR - Carriage Return')\n\t\tthis.writeScreen.rollUp()\n\t\tthis.outputDataUpdate(true)\n\t}\n\n\tccENM(): void {\n\t\t// Erase Non-Displayed Memory\n\t\tthis.logger.log(VerboseLevel.INFO, 'ENM - Erase Non-displayed Memory')\n\t\tthis.nonDisplayedMemory.reset()\n\t}\n\n\tccEOC(): void {\n\t\t// End of Caption (Flip Memories)\n\t\tthis.logger.log(VerboseLevel.INFO, 'EOC - End Of Caption')\n\t\tif (this.mode === 'MODE_POP-ON') {\n\t\t\tconst tmp = this.displayedMemory\n\t\t\tthis.displayedMemory = this.nonDisplayedMemory\n\t\t\tthis.nonDisplayedMemory = tmp\n\t\t\tthis.writeScreen = this.nonDisplayedMemory\n\t\t\tthis.logger.log(\n\t\t\t\tVerboseLevel.TEXT,\n\t\t\t\t() => 'DISP: ' + this.displayedMemory.getDisplayText(),\n\t\t\t)\n\t\t}\n\t\tthis.outputDataUpdate(true)\n\t}\n\n\tccTO(nrCols: number): void {\n\t\t// Tab Offset 1,2, or 3 columns\n\t\tthis.logger.log(VerboseLevel.INFO, 'TO(' + nrCols + ') - Tab Offset')\n\t\tthis.writeScreen.moveCursor(nrCols)\n\t}\n\n\tccMIDROW(secondByte: number): void {\n\t\t// Parse MIDROW command\n\t\tconst styles: Partial<PenStyles> = { flash: false }\n\t\tstyles.underline = secondByte % 2 === 1\n\t\tstyles.italics = secondByte >= 0x2e\n\t\tif (!styles.italics) {\n\t\t\tconst colorIndex = Math.floor(secondByte / 2) - 0x10\n\t\t\tconst colors = [\n\t\t\t\t'white',\n\t\t\t\t'green',\n\t\t\t\t'blue',\n\t\t\t\t'cyan',\n\t\t\t\t'red',\n\t\t\t\t'yellow',\n\t\t\t\t'magenta',\n\t\t\t]\n\t\t\tstyles.foreground = colors[colorIndex]\n\t\t}\n\t\telse {\n\t\t\tstyles.foreground = 'white'\n\t\t}\n\t\tthis.logger.log(VerboseLevel.INFO, 'MIDROW: ' + JSON.stringify(styles))\n\t\tthis.writeScreen.setPen(styles)\n\t\t// A mid-row code is a spacing attribute: it occupies one cell (shown as a\n\t\t// space carrying the new pen) and advances the cursor, so text following\n\t\t// the code starts one column to the right (CTA-608).\n\t\tthis.writeScreen.moveCursor(1)\n\t}\n\n\toutputDataUpdate(dispatch: boolean = false): void {\n\t\tconst time = this.logger.time\n\t\tif (time === null) {\n\t\t\treturn\n\t\t}\n\n\t\tif (this.outputFilter) {\n\t\t\tif (this.cueStartTime === null && !this.displayedMemory.isEmpty()) {\n\t\t\t\t// Start of a new cue\n\t\t\t\tthis.cueStartTime = time\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (!this.displayedMemory.equals(this.lastOutputScreen)) {\n\t\t\t\t\tthis.outputFilter.newCue(\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\tthis.cueStartTime!,\n\t\t\t\t\t\ttime,\n\t\t\t\t\t\tthis.lastOutputScreen,\n\t\t\t\t\t)\n\t\t\t\t\tif (dispatch && this.outputFilter.dispatchCue) {\n\t\t\t\t\t\tthis.outputFilter.dispatchCue()\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.cueStartTime = this.displayedMemory.isEmpty() ? null : time\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.lastOutputScreen.copy(this.displayedMemory)\n\t\t}\n\t}\n\n\tcueSplitAtTime(t: number): void {\n\t\tif (this.outputFilter) {\n\t\t\tif (!this.displayedMemory.isEmpty()) {\n\t\t\t\tif (this.outputFilter.newCue) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\tthis.outputFilter.newCue(this.cueStartTime!, t, this.displayedMemory)\n\t\t\t\t}\n\n\t\t\t\tthis.cueStartTime = t\n\t\t\t}\n\t\t}\n\t}\n}\n","export const backgroundColors: string[] = [\n\t'white',\n\t'green',\n\t'blue',\n\t'cyan',\n\t'red',\n\t'yellow',\n\t'magenta',\n\t'black',\n\t'transparent',\n]\n","import type { CmdHistory } from '../CmdHistory.ts'\n\nexport function createCmdHistory(): CmdHistory {\n\treturn {\n\t\ta: null,\n\t\tb: null,\n\t}\n}\n","import type { CmdHistory } from '../CmdHistory.ts'\n\nexport function hasCmdRepeated(a: number, b: number, cmdHistory: CmdHistory): boolean {\n\treturn cmdHistory.a === a && cmdHistory.b === b\n}\n","export function numArrayToHexArray(numArray: number[]): string[] {\n\tconst hexArray: string[] = []\n\tfor (const num of numArray) {\n\t\thexArray.push(num.toString(16))\n\t}\n\n\treturn hexArray\n};\n","export const rowsHighCh1: Record<number, number> = {\n\t17: 2,\n\t18: 4,\n\t21: 6,\n\t22: 8,\n\t23: 10,\n\t19: 13,\n\t20: 15,\n}\n","export const rowsHighCh2: Record<number, number> = {\n\t25: 2,\n\t26: 4,\n\t29: 6,\n\t30: 8,\n\t31: 10,\n\t27: 13,\n\t28: 15,\n}\n","// Tables to look up row from PAC data\n\nexport const rowsLowCh1: Record<number, number> = {\n\t17: 1,\n\t18: 3,\n\t21: 5,\n\t22: 7,\n\t23: 9,\n\t16: 11,\n\t19: 12,\n\t20: 14,\n}\n","export const rowsLowCh2: Record<number, number> = {\n\t25: 1,\n\t26: 3,\n\t29: 5,\n\t30: 7,\n\t31: 9,\n\t24: 11,\n\t27: 12,\n\t28: 14,\n}\n","import type { CmdHistory } from '../CmdHistory.ts'\n\nexport function setLastCmd(\n\ta: number | null,\n\tb: number | null,\n\tcmdHistory: CmdHistory,\n): void {\n\tcmdHistory.a = a\n\tcmdHistory.b = b\n}\n","/**\n *\n * This code was ported from the dash.js project at:\n * https://github.com/Dash-Industry-Forum/dash.js/blob/development/externals/cea608-parser.js\n * https://github.com/Dash-Industry-Forum/dash.js/commit/8269b26a761e0853bb21d78780ed945144ecdd4d#diff-71bc295a2d6b6b7093a1d3290d53a4b2\n *\n * The original copyright appears below:\n *\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2015-2016, DASH Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * 2. Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\nimport { CaptionsLogger } from './CaptionsLogger.ts'\nimport type { Channels } from './Channels.ts'\nimport type { CmdHistory } from './CmdHistory.ts'\nimport { Cta608Channel } from './Cta608Channel.ts'\nimport type { PACData } from './PACData.ts'\nimport type { PenStyles } from './PenStyles.ts'\nimport type { SupportedField } from './SupportedField.ts'\nimport { VerboseLevel } from './VerboseLevel.ts'\nimport { backgroundColors } from './utils/backgroundColors.ts'\nimport { createCmdHistory } from './utils/createCmdHistory.ts'\nimport { getCharForByte } from './utils/getCharForByte.ts'\nimport { hasCmdRepeated } from './utils/hasCmdRepeated.ts'\nimport { numArrayToHexArray } from './utils/numArrayToHexArray.ts'\nimport { rowsHighCh1 } from './utils/rowsHighCh1.ts'\nimport { rowsHighCh2 } from './utils/rowsHighCh2.ts'\nimport { rowsLowCh1 } from './utils/rowsLowCh1.ts'\nimport { rowsLowCh2 } from './utils/rowsLowCh2.ts'\nimport { setLastCmd } from './utils/setLastCmd.ts'\n\n/**\n * CEA-608 caption parser.\n *\n * @public\n */\nexport class Cta608Parser {\n\tprivate channels: (Cta608Channel | null)[]\n\tprivate currentChannel: Channels = 0\n\tprivate cmdHistory: CmdHistory = createCmdHistory()\n\tprivate logger: CaptionsLogger\n\tprivate lastTime: number | null = null\n\n\tconstructor(field: SupportedField, out1: any, out2: any) {\n\t\tconst logger = (this.logger = new CaptionsLogger())\n\t\tthis.channels = [\n\t\t\tnull,\n\t\t\tnew Cta608Channel(field, out1, logger),\n\t\t\tnew Cta608Channel(field + 1, out2, logger),\n\t\t]\n\t}\n\n\t/**\n\t * Add data for time t in forms of list of bytes (unsigned ints). The bytes are treated as pairs.\n\t *\n\t * @param time - The time in milliseconds\n\t * @param byteList - The list of bytes\n\t */\n\taddData(time: number | null, byteList: number[]): void {\n\t\tthis.lastTime = time\n\t\tthis.logger.time = time\n\n\t\tfor (let i = 0; i < byteList.length; i += 2) {\n\t\t\tconst a = byteList[i] & 0x7f\n\t\t\tconst b = byteList[i + 1] & 0x7f\n\t\t\tlet cmdFound: boolean = false\n\t\t\tlet charsFound: number[] | null = null\n\n\t\t\tif (this.lastTime !== null) {\n\t\t\t\ttime = this.lastTime + 0.5 * i * 1001 / 30000\n\t\t\t\tthis.logger.time = time\n\t\t\t}\n\n\t\t\tif (a === 0 && b === 0) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis.logger.log(\n\t\t\t\t\tVerboseLevel.DATA,\n\t\t\t\t\t() =>\n\t\t\t\t\t\t'[' +\n\t\t\t\t\t\tnumArrayToHexArray([byteList[i], byteList[i + 1]]) +\n\t\t\t\t\t\t'] -> (' +\n\t\t\t\t\t\tnumArrayToHexArray([a, b]) +\n\t\t\t\t\t\t')',\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tconst cmdHistory = this.cmdHistory\n\t\t\tconst isControlCode = a >= 0x10 && a <= 0x1f\n\t\t\tif (isControlCode) {\n\t\t\t\t// Skip redundant control codes\n\t\t\t\tif (hasCmdRepeated(a, b, cmdHistory)) {\n\t\t\t\t\tsetLastCmd(null, null, cmdHistory)\n\t\t\t\t\tthis.logger.log(\n\t\t\t\t\t\tVerboseLevel.DEBUG,\n\t\t\t\t\t\t() =>\n\t\t\t\t\t\t\t'Repeated command (' +\n\t\t\t\t\t\t\tnumArrayToHexArray([a, b]) +\n\t\t\t\t\t\t\t') is dropped',\n\t\t\t\t\t)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tsetLastCmd(a, b, this.cmdHistory)\n\n\t\t\t\tcmdFound = this.parseCmd(a, b)\n\n\t\t\t\tif (!cmdFound) {\n\t\t\t\t\tcmdFound = this.parseMidrow(a, b)\n\t\t\t\t}\n\n\t\t\t\tif (!cmdFound) {\n\t\t\t\t\tcmdFound = this.parsePAC(a, b)\n\t\t\t\t}\n\n\t\t\t\tif (!cmdFound) {\n\t\t\t\t\tcmdFound = this.parseBackgroundAttributes(a, b)\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tsetLastCmd(null, null, cmdHistory)\n\t\t\t}\n\n\t\t\tif (!cmdFound) {\n\t\t\t\tcharsFound = this.parseChars(a, b)\n\t\t\t\tif (charsFound.length) {\n\t\t\t\t\tconst currChNr = this.currentChannel\n\t\t\t\t\tif (currChNr && currChNr > 0) {\n\t\t\t\t\t\tconst channel = this.channels[currChNr] as Cta608Channel\n\t\t\t\t\t\tchannel.insertChars(charsFound)\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis.logger.log(\n\t\t\t\t\t\t\tVerboseLevel.WARNING,\n\t\t\t\t\t\t\t'No channel found yet. TEXT-MODE?',\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!cmdFound && !charsFound) {\n\t\t\t\tthis.logger.log(\n\t\t\t\t\tVerboseLevel.WARNING,\n\t\t\t\t\t() =>\n\t\t\t\t\t\t\"Couldn't parse cleaned data \" +\n\t\t\t\t\t\tnumArrayToHexArray([a, b]) +\n\t\t\t\t\t\t' orig: ' +\n\t\t\t\t\t\tnumArrayToHexArray([byteList[i], byteList[i + 1]]),\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Parse Command.\n\t *\n\t * @param a - The first byte\n\t * @param b - The second byte\n\t * @returns True if a command was found\n\t */\n\tprivate parseCmd(a: number, b: number): boolean {\n\n\t\tconst cond1 =\n\t\t\t(a === 0x14 || a === 0x1c || a === 0x15 || a === 0x1d) &&\n\t\t\tb >= 0x20 &&\n\t\t\tb <= 0x2f\n\t\tconst cond2 = (a === 0x17 || a === 0x1f) && b >= 0x21 && b <= 0x23\n\t\tif (!(cond1 || cond2)) {\n\t\t\treturn false\n\t\t}\n\n\t\tconst chNr = a === 0x14 || a === 0x15 || a === 0x17 ? 1 : 2\n\t\tconst channel = this.channels[chNr] as Cta608Channel\n\n\t\tif (a === 0x14 || a === 0x15 || a === 0x1c || a === 0x1d) {\n\t\t\tif (b === 0x20) {\n\t\t\t\tchannel.ccRCL()\n\t\t\t}\n\t\t\telse if (b === 0x21) {\n\t\t\t\tchannel.ccBS()\n\t\t\t}\n\t\t\telse if (b === 0x22) {\n\t\t\t\tchannel.ccAOF()\n\t\t\t}\n\t\t\telse if (b === 0x23) {\n\t\t\t\tchannel.ccAON()\n\t\t\t}\n\t\t\telse if (b === 0x24) {\n\t\t\t\tchannel.ccDER()\n\t\t\t}\n\t\t\telse if (b === 0x25) {\n\t\t\t\tchannel.ccRU(2)\n\t\t\t}\n\t\t\telse if (b === 0x26) {\n\t\t\t\tchannel.ccRU(3)\n\t\t\t}\n\t\t\telse if (b === 0x27) {\n\t\t\t\tchannel.ccRU(4)\n\t\t\t}\n\t\t\telse if (b === 0x28) {\n\t\t\t\tchannel.ccFON()\n\t\t\t}\n\t\t\telse if (b === 0x29) {\n\t\t\t\tchannel.ccRDC()\n\t\t\t}\n\t\t\telse if (b === 0x2a) {\n\t\t\t\tchannel.ccTR()\n\t\t\t}\n\t\t\telse if (b === 0x2b) {\n\t\t\t\tchannel.ccRTD()\n\t\t\t}\n\t\t\telse if (b === 0x2c) {\n\t\t\t\tchannel.ccEDM()\n\t\t\t}\n\t\t\telse if (b === 0x2d) {\n\t\t\t\tchannel.ccCR()\n\t\t\t}\n\t\t\telse if (b === 0x2e) {\n\t\t\t\tchannel.ccENM()\n\t\t\t}\n\t\t\telse if (b === 0x2f) {\n\t\t\t\tchannel.ccEOC()\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\t// a == 0x17 || a == 0x1F\n\t\t\tchannel.ccTO(b - 0x20)\n\t\t}\n\n\t\tthis.currentChannel = chNr\n\t\treturn true\n\t}\n\n\t/**\n\t * Parse midrow styling command\n\t *\n\t * @param a - The first byte\n\t * @param b - The second byte\n\t * @returns `true` if midrow styling command was found\n\t */\n\tprivate parseMidrow(a: number, b: number): boolean {\n\t\tlet chNr: number = 0\n\n\t\tif ((a === 0x11 || a === 0x19) && b >= 0x20 && b <= 0x2f) {\n\t\t\tif (a === 0x11) {\n\t\t\t\tchNr = 1\n\t\t\t}\n\t\t\telse {\n\t\t\t\tchNr = 2\n\t\t\t}\n\n\t\t\tif (chNr !== this.currentChannel) {\n\t\t\t\tthis.logger.log(\n\t\t\t\t\tVerboseLevel.ERROR,\n\t\t\t\t\t'Mismatch channel in midrow parsing',\n\t\t\t\t)\n\t\t\t\treturn false\n\t\t\t}\n\t\t\tconst channel = this.channels[chNr]\n\t\t\tif (!channel) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t\tchannel.ccMIDROW(b)\n\t\t\tthis.logger.log(\n\t\t\t\tVerboseLevel.DEBUG,\n\t\t\t\t() => 'MIDROW (' + numArrayToHexArray([a, b]) + ')',\n\t\t\t)\n\t\t\treturn true\n\t\t}\n\t\treturn false\n\t}\n\n\t/**\n\t * Parse Preable Access Codes (Table 53).\n\t *\n\t * @param a - The first byte\n\t * @param b - The second byte\n\t * @returns A Boolean that tells if PAC found\n\t */\n\tprivate parsePAC(a: number, b: number): boolean {\n\t\tlet row: number\n\n\t\tconst case1 =\n\t\t\t((a >= 0x11 && a <= 0x17) || (a >= 0x19 && a <= 0x1f)) &&\n\t\t\tb >= 0x40 &&\n\t\t\tb <= 0x7f\n\t\tconst case2 = (a === 0x10 || a === 0x18) && b >= 0x40 && b <= 0x5f\n\t\tif (!(case1 || case2)) {\n\t\t\treturn false\n\t\t}\n\n\t\tconst chNr: Channels = a <= 0x17 ? 1 : 2\n\n\t\tif (b >= 0x40 && b <= 0x5f) {\n\t\t\trow = chNr === 1 ? rowsLowCh1[a] : rowsLowCh2[a]\n\t\t}\n\t\telse {\n\t\t\t// 0x60 <= b <= 0x7F\n\t\t\trow = chNr === 1 ? rowsHighCh1[a] : rowsHighCh2[a]\n\t\t}\n\t\tconst channel = this.channels[chNr]\n\t\tif (!channel) {\n\t\t\treturn false\n\t\t}\n\t\tchannel.setPAC(this.interpretPAC(row, b))\n\t\tthis.currentChannel = chNr\n\t\treturn true\n\t}\n\n\t/**\n\t * Interpret the second byte of the pac, and return the information.\n\t *\n\t * @param row - The row number\n\t * @param byte - The second byte\n\t * @returns pacData with style parameters\n\t */\n\tprivate interpretPAC(row: number, byte: number): PACData {\n\t\tlet pacIndex\n\t\tconst pacData: PACData = {\n\t\t\tcolor: null,\n\t\t\titalics: false,\n\t\t\tindent: null,\n\t\t\tunderline: false,\n\t\t\trow: row,\n\t\t}\n\n\t\tif (byte > 0x5f) {\n\t\t\tpacIndex = byte - 0x60\n\t\t}\n\t\telse {\n\t\t\tpacIndex = byte - 0x40\n\t\t}\n\n\t\tpacData.underline = (pacIndex & 1) === 1\n\t\tif (pacIndex <= 0xd) {\n\t\t\tpacData.color = [\n\t\t\t\t'white',\n\t\t\t\t'green',\n\t\t\t\t'blue',\n\t\t\t\t'cyan',\n\t\t\t\t'red',\n\t\t\t\t'yellow',\n\t\t\t\t'magenta',\n\t\t\t\t'white',\n\t\t\t][Math.floor(pacIndex / 2)]\n\t\t}\n\t\telse if (pacIndex <= 0xf) {\n\t\t\tpacData.italics = true\n\t\t\tpacData.color = 'white'\n\t\t}\n\t\telse {\n\t\t\tpacData.indent = Math.floor((pacIndex - 0x10) / 2) * 4\n\t\t}\n\t\treturn pacData // Note that row has zero offset. The spec uses 1.\n\t}\n\n\t/**\n\t * Parse characters.\n\t *\n\t * @param a - The first byte\n\t * @param b - The second byte\n\t * @returns An array with 1 to 2 codes corresponding to chars, if found. null otherwise.\n\t */\n\tprivate parseChars(a: number, b: number): number[] {\n\t\tlet channelNr: Channels\n\t\tlet charCodes: number[] = []\n\t\tlet charCode1: number | null = null\n\n\t\tif (a >= 0x19) {\n\t\t\tchannelNr = 2\n\t\t\tcharCode1 = a - 8\n\t\t}\n\t\telse {\n\t\t\tchannelNr = 1\n\t\t\tcharCode1 = a\n\t\t}\n\t\tif (charCode1 >= 0x11 && charCode1 <= 0x13) {\n\t\t\t// Special character\n\t\t\tlet oneCode: number\n\t\t\tif (charCode1 === 0x11) {\n\t\t\t\toneCode = b + 0x50\n\t\t\t}\n\t\t\telse if (charCode1 === 0x12) {\n\t\t\t\toneCode = b + 0x70\n\t\t\t}\n\t\t\telse {\n\t\t\t\toneCode = b + 0x90\n\t\t\t}\n\n\t\t\tthis.logger.log(\n\t\t\t\tVerboseLevel.INFO,\n\t\t\t\t() =>\n\t\t\t\t\t\"Special char '\" +\n\t\t\t\t\tgetCharForByte(oneCode) +\n\t\t\t\t\t\"' in channel \" +\n\t\t\t\t\tchannelNr,\n\t\t\t)\n\t\t\tcharCodes = [oneCode]\n\t\t}\n\t\telse if (a >= 0x20 && a <= 0x7f) {\n\t\t\tcharCodes = b === 0 ? [a] : [a, b]\n\t\t}\n\t\tif (charCodes) {\n\t\t\tthis.logger.log(\n\t\t\t\tVerboseLevel.DEBUG,\n\t\t\t\t() => 'Char codes = ' + numArrayToHexArray(charCodes).join(','),\n\t\t\t)\n\t\t}\n\t\treturn charCodes\n\t}\n\n\t/**\n\t * Parse extended background attributes as well as new foreground color black.\n\t *\n\t * @param a - The first byte\n\t * @param b - The second byte\n\t * @returns True if background attributes are found\n\t */\n\tprivate parseBackgroundAttributes(a: number, b: number): boolean {\n\t\tconst case1 = (a === 0x10 || a === 0x18) && b >= 0x20 && b <= 0x2f\n\t\tconst case2 = (a === 0x17 || a === 0x1f) && b >= 0x2d && b <= 0x2f\n\t\tif (!(case1 || case2)) {\n\t\t\treturn false\n\t\t}\n\t\tlet index: number\n\t\tconst bkgData: Partial<PenStyles> = {}\n\t\tif (a === 0x10 || a === 0x18) {\n\t\t\tindex = Math.floor((b - 0x20) / 2)\n\t\t\tbkgData.background = backgroundColors[index]\n\t\t\tif (b % 2 === 1) {\n\t\t\t\tbkgData.background = bkgData.background + '_semi'\n\t\t\t}\n\t\t}\n\t\telse if (b === 0x2d) {\n\t\t\tbkgData.background = 'transparent'\n\t\t}\n\t\telse {\n\t\t\tbkgData.foreground = 'black'\n\t\t\tif (b === 0x2f) {\n\t\t\t\tbkgData.underline = true\n\t\t\t}\n\t\t}\n\t\tconst chNr: Channels = a <= 0x17 ? 1 : 2\n\t\tconst channel: Cta608Channel = this.channels[chNr] as Cta608Channel\n\t\tchannel.setBkgData(bkgData)\n\t\treturn true\n\t}\n\n\t/**\n\t * Reset state of parser and its channels.\n\t */\n\treset(): void {\n\t\tfor (let i = 0; i < Object.keys(this.channels).length; i++) {\n\t\t\tconst channel = this.channels[i]\n\t\t\tif (channel) {\n\t\t\t\tchannel.reset()\n\t\t\t}\n\t\t}\n\t\tsetLastCmd(null, null, this.cmdHistory)\n\t}\n\n\t/**\n\t * Trigger the generation of a cue, and the start of a new one if displayScreens are not empty.\n\t */\n\tcueSplitAtTime(t: number): void {\n\t\tfor (const channel of this.channels) {\n\t\t\tif (channel) {\n\t\t\t\tchannel.cueSplitAtTime(t)\n\t\t\t}\n\t\t}\n\t}\n}\n","export function isCCType(type: number): boolean {\n\treturn type === 0 || type === 1\n}\n\nexport function isNonEmptyCCData(ccData1: number, ccData2: number): boolean {\n\treturn (ccData1 & 0x7F) > 0 || (ccData2 & 0x7F) > 0\n}\n\n/**\n * Parse an ATSC A/53 Part 4 `cc_data()` structure into per-field byte pairs.\n *\n * The payload is identical for every carriage format — an AVC/HEVC/VVC SEI message and\n * an AV1 `metadata_itu_t_t35` OBU carry the same bytes under the same T.35/GA94\n * identifier — so this is the single parser shared by all of them. Only the envelope\n * around it differs.\n *\n * `cc_data()` is self-delimiting: `cc_count` states how many 3-byte constructs follow,\n * so anything after them (SEI `rbsp_trailing_bits`, an AV1 OBU `trailing_bits` byte) is\n * ignored without needing to be recognized.\n *\n * @param raw - The DataView holding the `cc_data()` structure\n * @param pos - The position of the first `cc_data()` byte, holding `cc_count`\n * @param endPos - The exclusive upper bound to read within\n * @param fieldData - Field 1 and field 2 byte arrays, appended to in place\n */\nexport function parseCcData(raw: DataView, pos: number, endPos: number, fieldData: number[][]): void {\n\t// cc_count and em_data must both be within the enclosing structure. A T.35 payload\n\t// carrying nothing but the 8-byte identifier ends here, and reading on would run past\n\t// the end of the DataView.\n\tif (pos + 2 > endPos) {\n\t\treturn\n\t}\n\n\t// process_cc_data_flag is not checked: a caption-bearing payload always sets it, and\n\t// honoring a cleared flag would silently drop pairs some packagers emit regardless.\n\tconst ccCount = raw.getUint8(pos) & 0x1F\n\n\t// Skip cc_count and the em_data byte to reach the first cc construct.\n\tlet cursor = pos + 2\n\tconst ccEnd = Math.min(cursor + ccCount * 3, endPos)\n\n\tfor (; cursor + 2 < ccEnd; cursor += 3) {\n\t\tconst byte = raw.getUint8(cursor)\n\n\t\t// marker_bits (5) | cc_valid (1) | cc_type (2)\n\t\tif (!(byte & 0x04)) {\n\t\t\tcontinue\n\t\t}\n\n\t\tconst ccType = byte & 0x03\n\t\tif (!isCCType(ccType)) {\n\t\t\tcontinue\n\t\t}\n\n\t\t// Keep the parity bit — the 608 parser validates it.\n\t\tconst ccData1 = raw.getUint8(cursor + 1)\n\t\tconst ccData2 = raw.getUint8(cursor + 2)\n\n\t\tif (isNonEmptyCCData(ccData1, ccData2)) {\n\t\t\tfieldData[ccType].push(ccData1, ccData2)\n\t\t}\n\t}\n}\n","import { parseCcData } from './utils/parseCcData.ts'\n\n/**\n * Extract CTA-608 data from a DataView\n *\n * @param raw - The DataView to extract the data from\n * @param cta608Range - The range of the CTA-608 data\n * @returns The extracted CTA-608 data\n *\n * @public\n */\nexport function extractCta608Data(raw: DataView, cta608Range: number[]): number[][] {\n\tconst fieldData: number[][] = [[], []]\n\n\t// Skip the 8-byte A/53 identifier up to userDataTypeCode to reach cc_data(), and bound\n\t// the read by the payload the range describes rather than by the whole DataView.\n\tparseCcData(raw, cta608Range[0] + 8, cta608Range[0] + cta608Range[1], fieldData)\n\n\treturn fieldData\n}\n","/**\n * The 8-byte ATSC A/53 user identifier that prefixes a `cc_data()` payload, per\n * ANSI-SCTE 128: `itu_t_t35_country_code` (0xB5, USA), `terminal_provider_code`\n * (0x0031, ATSC), `terminal_provider_oriented_code` ('GA94'), and\n * `user_data_type_code` (0x03, cc_data).\n *\n * Both carriage formats use it unchanged — an AVC/HEVC/VVC\n * `user_data_registered_itu_t_t35` SEI message and an AV1 `metadata_itu_t_t35` OBU — so\n * this identifies CTA-608 user data for either.\n *\n * @param raw - The DataView holding the T.35 payload\n * @param pos - The position of `itu_t_t35_country_code`\n * @returns true when the 8 bytes at `pos` identify CTA-608 caption data\n */\nexport function isCta608UserData(raw: DataView, pos: number): boolean {\n\treturn raw.getUint8(pos) === 0xB5\n\t\t&& raw.getUint16(pos + 1) === 0x0031\n\t\t&& raw.getUint32(pos + 3) === 0x47413934\n\t\t&& raw.getUint8(pos + 7) === 0x03\n}\n","import { isCta608UserData } from './isCta608UserData.ts'\nimport { parseCcData } from './parseCcData.ts'\n\n/**\n * AV1 `OBU_METADATA` unit type\n */\nconst OBU_METADATA = 5\n\n/**\n * AV1 `METADATA_TYPE_ITUT_T35` metadata type\n */\nconst METADATA_TYPE_ITUT_T35 = 4\n\n/**\n * The maximum number of bytes in an AV1 leb128() value\n */\nconst LEB128_MAX_BYTES = 8\n\n/**\n * A decoded AV1 leb128() value and the number of bytes it occupied.\n */\ntype Leb128 = {\n\treadonly value: number\n\treadonly size: number\n}\n\n/**\n * Read an AV1 `leb128()` variable-length integer (AV1 spec section 4.10.5): up to 8\n * bytes, 7 value bits each, least significant group first, with the high bit marking\n * continuation.\n *\n * Groups are combined by multiplication rather than by `<<`, because a leb128 value may\n * exceed the 32 bits a JavaScript shift operates on.\n *\n * @param raw - The DataView to read from\n * @param pos - The position of the first leb128 byte\n * @param endPos - The exclusive upper bound to read within\n * @returns The value and its byte length, or null when it is truncated or overlong\n */\nexport function readLeb128(raw: DataView, pos: number, endPos: number): Leb128 | null {\n\tlet value = 0\n\n\tfor (let i = 0; i < LEB128_MAX_BYTES; i++) {\n\t\tif (pos + i >= endPos) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst byte = raw.getUint8(pos + i)\n\t\tvalue += (byte & 0x7F) * 2 ** (i * 7)\n\n\t\tif (!(byte & 0x80)) {\n\t\t\treturn { value, size: i + 1 }\n\t\t}\n\t}\n\n\treturn null\n}\n\n/**\n * Detects whether an AV1 OBU header starts an `OBU_METADATA` unit and locates its\n * payload.\n *\n * The header is one byte — `obu_forbidden_bit` (1), `obu_type` (4),\n * `obu_extension_flag` (1), `obu_has_size_field` (1), `obu_reserved_1bit` (1) — followed\n * by an optional extension byte and, when `obu_has_size_field` is set, `obu_size` as a\n * leb128. An OBU without `obu_size` runs to the end of the temporal unit, which mp4\n * permits only for the final OBU in a sample.\n *\n * @param raw - The DataView containing the OBU\n * @param pos - The position of the OBU header byte\n * @param endPos - The exclusive end of the enclosing sample\n * @returns The payload bounds and whether this is a metadata OBU, or null if malformed\n */\nexport function readObu(raw: DataView, pos: number, endPos: number): { isMetadata: boolean; payloadStart: number; payloadEnd: number } | null {\n\tconst header = raw.getUint8(pos)\n\n\t// obu_forbidden_bit must be zero; a set bit means this is not an OBU stream.\n\tif (header & 0x80) {\n\t\treturn null\n\t}\n\n\tlet payloadStart = pos + 1\n\n\t// obu_extension_flag adds a byte of temporal_id / spatial_id.\n\tif (header & 0x04) {\n\t\tpayloadStart++\n\t}\n\n\tlet payloadEnd = endPos\n\n\t// obu_has_size_field\n\tif (header & 0x02) {\n\t\tconst obuSize = readLeb128(raw, payloadStart, endPos)\n\t\tif (!obuSize) {\n\t\t\treturn null\n\t\t}\n\n\t\tpayloadStart += obuSize.size\n\t\tpayloadEnd = payloadStart + obuSize.value\n\n\t\tif (payloadEnd > endPos) {\n\t\t\treturn null\n\t\t}\n\t}\n\n\treturn {\n\t\tisMetadata: ((header >> 3) & 0x0F) === OBU_METADATA,\n\t\tpayloadStart,\n\t\tpayloadEnd,\n\t}\n}\n\n/**\n * Parse CTA-608 field data out of an AV1 metadata OBU payload, ignoring metadata OBUs\n * of any other type.\n *\n * The payload is `metadata_type` as a leb128, then — for ITU-T T.35 — the 8-byte A/53\n * user identifier and the `cc_data()` structure. Unlike an SEI NAL unit an OBU carries\n * no emulation prevention, so the bytes are read verbatim.\n *\n * @param raw - The DataView containing the OBU payload\n * @param pos - The position of `metadata_type`\n * @param endPos - The exclusive end of the OBU payload\n * @param fieldData - Field 1 and field 2 byte arrays, appended to in place\n */\nexport function parseCta608DataFromMetadataObu(raw: DataView, pos: number, endPos: number, fieldData: number[][]): void {\n\tconst metadataType = readLeb128(raw, pos, endPos)\n\tif (!metadataType || metadataType.value !== METADATA_TYPE_ITUT_T35) {\n\t\treturn\n\t}\n\n\tconst userDataStart = pos + metadataType.size\n\n\t// The 8-byte identifier plus at least the cc_count and em_data bytes must be present.\n\tif (userDataStart + 10 > endPos || !isCta608UserData(raw, userDataStart)) {\n\t\treturn\n\t}\n\n\tparseCcData(raw, userDataStart + 8, endPos, fieldData)\n}\n","import { parseCta608DataFromMetadataObu, readObu } from './utils/obuHelpers.ts'\n\n/**\n * Extracts CTA-608 data from an AV1 (`av01`) sample.\n *\n * AV1 has no NAL units, so captions ride in an `metadata_itu_t_t35` OBU rather than in\n * an SEI message. The caption payload is unchanged — the same A/53 `cc_data()` under the\n * same T.35/GA94 identifier that {@link extractCta608DataFromSample} reads — so the\n * returned field data feeds {@link Cta608Parser} identically.\n *\n * This is a separate function rather than a codec branch inside\n * {@link extractCta608DataFromSample} because the two carriages are framed differently and\n * neither sample is self-identifying. A NAL unit sample puts a fixed-width big-endian\n * length in front of each unit, and that width is only known from `lengthSizeMinusOne` in\n * the `avcC`/`hvcC` config. An AV1 sample uses the low-overhead format, where each OBU\n * carries its own `obu_size` after the header — and may omit it on the last OBU. Select on\n * the sample entry type (`av01`) instead.\n *\n * @param raw - The DataView with media data\n * @param startPos - The start position of the sample within the DataView\n * @param sampleSize - The size of the sample in bytes\n * @returns fieldData array containing field 1 and field 2 data arrays\n *\n * @example\n * {@includeCode ../test/extractCta608DataFromAv1Sample.test.ts#example}\n *\n * @public\n */\nexport function extractCta608DataFromAv1Sample(raw: DataView, startPos: number, sampleSize: number): number[][] {\n\tconst fieldData: number[][] = [[], []]\n\n\t// One mp4 sample is one temporal unit: OBUs in the low-overhead format, each sized by\n\t// its own obu_size rather than by an outer length prefix.\n\tconst endPos = Math.min(startPos + sampleSize, raw.byteLength)\n\tlet cursor = startPos\n\n\twhile (cursor < endPos) {\n\t\tconst obu = readObu(raw, cursor, endPos)\n\t\tif (!obu) {\n\t\t\tbreak\n\t\t}\n\n\t\tif (obu.isMetadata) {\n\t\t\tparseCta608DataFromMetadataObu(raw, obu.payloadStart, obu.payloadEnd, fieldData)\n\t\t}\n\n\t\t// A zero-length OBU (a temporal delimiter) must still advance past its header.\n\t\tcursor = Math.max(obu.payloadEnd, cursor + 1)\n\t}\n\n\treturn fieldData\n}\n","import { isCta608UserData } from './isCta608UserData.ts'\nimport { parseCcData } from './parseCcData.ts'\n\nexport function getSeiData(raw: DataView, startPos: number, endPos: number): DataView {\n\tconst data: number[] = []\n\n\tfor (let cursor = startPos; cursor < endPos; cursor++) {\n\t\tif (cursor + 2 < endPos && raw.getUint8(cursor) === 0x00 && raw.getUint8(cursor + 1) === 0x00 && raw.getUint8(cursor + 2) === 0x03) {\n\t\t\tdata.push(0x00)\n\t\t\tdata.push(0x00)\n\t\t\tcursor += 2\n\t\t} \n\t\telse {\n\t\t\tdata.push(raw.getUint8(cursor))\n\t\t}\n\t}\n\n\treturn new DataView(new Uint8Array(data).buffer)\n}\n\nexport function isCea608Sei(payloadType: number, payloadSize: number, sei: DataView, pos: number): boolean {\n\t// user_data_registered_itu_t_t35 is payload type 4, and the A/53 identifier is 8 bytes.\n\tif (payloadType !== 4 || payloadSize < 8) {\n\t\treturn false\n\t}\n\n\treturn isCta608UserData(sei, pos)\n}\n\n/**\n * H.264 SEI NAL unit type\n */\nconst H264_SEI_TYPE = 0x06\n\n/**\n * H.265 prefix SEI NAL unit type\n */\nconst H265_PREFIX_SEI_TYPE = 39\n\n/**\n * H.265 suffix SEI NAL unit type\n */\nconst H265_SUFFIX_SEI_TYPE = 40\n\n/**\n * H.266 prefix SEI NAL unit type\n */\nconst H266_PREFIX_SEI_TYPE = 23\n\n/**\n * H.266 suffix SEI NAL unit type\n */\nconst H266_SUFFIX_SEI_TYPE = 24\n\n/**\n * Check if a NAL unit type is an SEI (Supplemental Enhancement Information) unit\n * for H.264, H.265, or H.266 codecs.\n *\n * @param unitType - The NAL unit type to check\n * @returns true if the unit type is an SEI NAL unit type for any supported codec\n */\nexport function isSeiNalUnitType(unitType: number): boolean {\n\treturn unitType === H264_SEI_TYPE ||\n\t\tunitType === H265_PREFIX_SEI_TYPE ||\n\t\tunitType === H265_SUFFIX_SEI_TYPE ||\n\t\tunitType === H266_PREFIX_SEI_TYPE ||\n\t\tunitType === H266_SUFFIX_SEI_TYPE\n}\n\n/**\n * Detects whether a NAL unit is an SEI (Supplemental Enhancement Information) unit\n * and returns its type and header size.\n *\n * This function supports auto-detection across H.264, H.265, and H.266 codecs:\n * - H.264: 1-byte NAL header, type in bits 0-4\n * - H.265: 2-byte NAL header, type in bits 1-6 of byte 0\n * - H.266: 2-byte NAL header, type in bits 3-7 of byte 1\n *\n * @param raw - The DataView containing the NAL unit data\n * @param pos - The position of the first NAL header byte\n * @returns An object containing the NAL unit type and header size, or null if not an SEI NAL unit\n */\nexport function extractNalUnitType(raw: DataView, pos: number): { nalType: number; headerSize: number } | null {\n\tconst byte0 = raw.getUint8(pos)\n\n\t// H.264: 1-byte header, type in bits 0-4\n\tconst h264Type = byte0 & 0x1F\n\tif (h264Type === H264_SEI_TYPE) {\n\t\treturn { nalType: h264Type, headerSize: 1 }\n\t}\n\n\t// H.265: 2-byte header, type in bits 1-6 of byte 0\n\tconst h265Type = (byte0 >> 1) & 0x3F\n\tif (h265Type === H265_PREFIX_SEI_TYPE || h265Type === H265_SUFFIX_SEI_TYPE) {\n\t\treturn { nalType: h265Type, headerSize: 2 }\n\t}\n\n\t// H.266: 2-byte header, type in bits 3-7 of byte 1\n\tif (pos + 1 >= raw.byteLength) {\n\t\treturn null\n\t}\n\tconst byte1 = raw.getUint8(pos + 1)\n\tconst h266Type = (byte1 >> 3) & 0x1F\n\tif (h266Type === H266_PREFIX_SEI_TYPE || h266Type === H266_SUFFIX_SEI_TYPE) {\n\t\treturn { nalType: h266Type, headerSize: 2 }\n\t}\n\n\treturn null\n}\n\nexport function parseCta608DataFromSei(sei: DataView, fieldData: number[][]): void {\n\tlet cursor = 0\n\t// The last byte is rbsp_trailing_bits, so stop before it\n\twhile (cursor < sei.byteLength - 1) {\n\t\tlet payloadType = 0\n\t\tlet payloadSize = 0\n\t\tlet now\n\n\t\tdo {\n\t\t\tpayloadType += now = sei.getUint8(cursor++)\n\t\t} while (now === 0xFF)\n\t\tdo {\n\t\t\tpayloadSize += now = sei.getUint8(cursor++)\n\t\t} while (now === 0xFF)\n\n\t\tif (isCea608Sei(payloadType, payloadSize, sei, cursor)) {\n\t\t\t// Skip the 8-byte A/53 identifier to reach cc_data(). The read is bounded by this\n\t\t\t// SEI message, so a wrong cc_count cannot consume the message that follows it.\n\t\t\tparseCcData(sei, cursor + 8, cursor + payloadSize, fieldData)\n\t\t}\n\t\tcursor += payloadSize\n\t}\n}\n","import {\n\textractNalUnitType,\n\tgetSeiData,\n\tparseCta608DataFromSei,\n} from './utils/seiHelpers.ts'\n\n/**\n * Extracts CEA-608 data from a given sample.\n *\n * @param raw - The DataView with media data\n * @param startPos - The start position within the DataView\n * @param sampleSize - The size of the sample in bytes\n * @returns fieldData array containing field 1 and field 2 data arrays\n *\n * @public\n */\nexport function extractCta608DataFromSample(raw: DataView, startPos: number, sampleSize: number): number[][] {\n\tlet nalSize: number = 0\n\tconst fieldData: number[][] = [[], []]\n\n\t// Loop needs to account for maximum NALU header size (H.265/H.266 = 6 bytes: 4-byte size + 2-byte header)\n\tfor (let cursor = startPos; cursor < startPos + sampleSize - 6; cursor++) {\n\t\tnalSize = raw.getUint32(cursor)\n\n\t\t// The NAL unit data (nalSize bytes) starts after the 4-byte length prefix\n\t\tconst nalEnd = cursor + 4 + nalSize\n\n\t\t// Make sure that we don't go out of bounds\n\t\tif (nalEnd > startPos + sampleSize) {\n\t\t\tbreak\n\t\t}\n\n\t\t// Only process Supplemental Enhancement Information (SEI) NAL units\n\t\tconst seiInfo = extractNalUnitType(raw, cursor + 4)\n\t\tif (seiInfo) {\n\t\t\tconst seiStart = cursor + 4 + seiInfo.headerSize\n\t\t\tif (nalEnd <= raw.byteLength) {\n\t\t\t\tconst seiData = getSeiData(raw, seiStart, nalEnd)\n\t\t\t\tparseCta608DataFromSei(seiData, fieldData)\n\t\t\t}\n\t\t}\n\n\t\t// Jump to the next NAL unit\n\t\tcursor += nalSize + 3\n\t}\n\treturn fieldData\n}\n","import { extractNalUnitType } from './utils/seiHelpers.ts'\n\n/**\n * Find CTA-608 NAL units in a video stream\n *\n * @param raw - The DataView to extract the data from\n * @param startPos - The start position of the data\n * @param size - The size of the data\n * @returns The extracted CTA-608 NAL units\n *\n * @public\n */\nexport function findCta608Nalus(raw: DataView, startPos: number, size: number): number[][] {\n\tlet nalSize = 0, cursor = startPos\n\tconst cta608NaluRanges = []\n\n\t// Check SEI data according to ANSI-SCTE 128\n\tconst isCTA608SEI = (payloadType: number, payloadSize: number, raw: DataView, pos: number) => {\n\t\tif (payloadType !== 4 || payloadSize < 8) {\n\t\t\treturn null\n\t\t}\n\t\tconst countryCode = raw.getUint8(pos)\n\t\tconst providerCode = raw.getUint16(pos + 1)\n\t\tconst userIdentifier = raw.getUint32(pos + 3)\n\t\tconst userDataTypeCode = raw.getUint8(pos + 7)\n\t\treturn countryCode == 181 && providerCode == 49 && userIdentifier == 1195456820 && userDataTypeCode == 3\n\t}\n\n\twhile (cursor < startPos + size) {\n\t\tnalSize = raw.getUint32(cursor)\n\n\t\tconst seiInfo = extractNalUnitType(raw, cursor + 4)\n\t\tif (seiInfo) {\n\t\t\t// SEI NAL Unit. The NAL header is 1 byte (H.264) or 2 bytes (H.265/H.266)\n\t\t\tlet pos = cursor + 4 + seiInfo.headerSize\n\t\t\tlet payloadType = -1\n\t\t\twhile (pos < cursor + 4 + nalSize - 1) { // The last byte should be rbsp_trailing_bits\n\t\t\t\tpayloadType = 0\n\t\t\t\tlet b = 255\n\t\t\t\twhile (b === 255) {\n\t\t\t\t\tb = raw.getUint8(pos)\n\t\t\t\t\tpayloadType += b\n\t\t\t\t\tpos++\n\t\t\t\t}\n\t\t\t\tlet payloadSize = 0\n\t\t\t\tb = 255\n\t\t\t\twhile (b === 255) {\n\t\t\t\t\tb = raw.getUint8(pos)\n\t\t\t\t\tpayloadSize += b\n\t\t\t\t\tpos++\n\t\t\t\t}\n\t\t\t\tif (isCTA608SEI(payloadType, payloadSize, raw, pos)) {\n\t\t\t\t\tcta608NaluRanges.push([pos, payloadSize])\n\t\t\t\t}\n\t\t\t\tpos += payloadSize\n\t\t\t}\n\t\t}\n\t\tcursor += nalSize + 4\n\t}\n\treturn cta608NaluRanges\n}\n","/**\n * The copyright in this software is being made available under the BSD License,\n * included below. This software may be subject to other third party and contributor\n * rights, including patent rights, and no such rights are granted under this license.\n *\n * Copyright (c) 2015-2016, DASH Industry Forum.\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without modification,\n * are permitted provided that the following conditions are met:\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation and/or\n * other materials provided with the distribution.\n * 2. Neither the name of Dash Industry Forum nor the names of its\n * contributors may be used to endorse or promote products derived from this software\n * without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\n/**\n * SCC Parser\n *\n * @public\n */\nexport class SccParser {\n\thasHeader: boolean = false\n\tnrLinesParsed: number = 0\n\tprocessor: any\n\tfield: number | any\n\n\tconstructor(processor: any, field: number | any = 1) {\n\t\tthis.processor = processor\n\t\tthis.field = field\n\t}\n\n\tparse(text: string): void {\n\t\tconst lines = text.split(/\\r?\\n/)\n\t\tthis.nrLinesParsed = 0\n\n\t\tif (lines[0] === 'Scenarist_SCC V1.0') {\n\t\t\tthis.hasHeader = true\n\t\t\tthis.nrLinesParsed++\n\t\t}\n\n\t\tfor (let l = 1; l < lines.length; l += 2) {\n\t\t\tif (lines[l] !== '') {\n\t\t\t\tbreak // Every second line should be empty\n\t\t\t}\n\t\t\tthis.nrLinesParsed++\n\t\t\tconst lineData = this.parseDataLine(lines[l + 1])\n\t\t\tif (lineData === null) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tthis.nrLinesParsed++\n\t\t\tthis.processor.addData(lineData[0], lineData[1])\n\t\t}\n\t}\n\n\tparseDataLine(line: string): [number, number[]] | null {\n\t\tif (!line) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst lineParts = line.split(/\\s+/)\n\t\tconst timeData = lineParts[0]\n\t\tconst ceaData: number[] = []\n\n\t\tfor (let i = 1; i < lineParts.length; i++) {\n\t\t\tconst fourHexChars = lineParts[i]\n\t\t\tconst a = parseInt(fourHexChars.substring(0, 2), 16)\n\t\t\tconst b = parseInt(fourHexChars.substring(2, 4), 16)\n\t\t\tceaData.push(a, b)\n\t\t}\n\n\t\tconst time = this.timeConverter(timeData)\n\t\treturn [time, ceaData]\n\t}\n\n\ttimeConverter(smpteTs: string): number {\n\t\tconst parts = smpteTs.split(':')\n\t\tif (parts.length === 3) {\n\t\t\tconst lastParts = parts[2].split(';')\n\t\t\tparts[2] = lastParts[0]\n\t\t\tconst frames = parseInt(lastParts[1], 10)\n\t\t\treturn (30 * (60 * (60 * parseInt(parts[0], 10) + parseInt(parts[1], 10)) + parseInt(parts[2], 10)) + frames) * 1001 / 30000\n\t\t}\n\t\treturn 0 // in case if format is incorrect\n\t}\n\n\tgetHeaderStatus(): boolean {\n\t\treturn this.hasHeader\n\t}\n\n\tgetField(): number | any {\n\t\treturn this.field\n\t}\n\n\tgetLinesParsed(): number {\n\t\treturn this.nrLinesParsed\n\t}\n}\n"],"mappings":";;;;;;;;;AAUA,MAAa,eAAe;CAC3B,OAAO;CACP,MAAM;CACN,SAAS;CACT,MAAM;CACN,OAAO;CACP,MAAM;CACN;;;;;;;;;AC4BD,IAAa,iBAAb,MAA4B;;cACE;sBACO,aAAa;;CAEjD,IAAI,UAAwB,KAAoC;AAC/D,MAAI,KAAK,gBAAgB,UAAU;GAClC,MAAMA,IAAY,OAAO,QAAQ,aAAa,KAAK,GAAG;AACtD,WAAQ,IAAI,GAAG,KAAK,KAAK,IAAI,SAAS,IAAI,IAAI;;;;;;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AM,MAAM;EACnC,MAAM,WAAW,UAAU;EAC3B,MAAMC,UAAoB,EAAE;AAE5B,OAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;GAC1C,MAAM,eAAe,UAAU;GAC/B,MAAM,IAAI,SAAS,aAAa,UAAU,GAAG,EAAE,EAAE,GAAG;GACpD,MAAM,IAAI,SAAS,aAAa,UAAU,GAAG,EAAE,EAAE,GAAG;AACpD,WAAQ,KAAK,GAAG,EAAE;;AAInB,SAAO,CADM,KAAK,cAAc,SAAS,EAC3B,QAAQ;;CAGvB,cAAc,SAAyB;EACtC,MAAM,QAAQ,QAAQ,MAAM,IAAI;AAChC,MAAI,MAAM,WAAW,GAAG;GACvB,MAAM,YAAY,MAAM,GAAG,MAAM,IAAI;AACrC,SAAM,KAAK,UAAU;GACrB,MAAM,SAAS,SAAS,UAAU,IAAI,GAAG;AACzC,WAAQ,MAAM,MAAM,KAAK,SAAS,MAAM,IAAI,GAAG,GAAG,SAAS,MAAM,IAAI,GAAG,IAAI,SAAS,MAAM,IAAI,GAAG,IAAI,UAAU,OAAO;;AAExH,SAAO;;CAGR,kBAA2B;AAC1B,SAAO,KAAK;;CAGb,WAAyB;AACxB,SAAO,KAAK;;CAGb,iBAAyB;AACxB,SAAO,KAAK"}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.53.1"
8
+ "packageVersion": "7.58.12"
9
9
  }
10
10
  ]
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svta/cml-608",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "CTA-608/CEA-608 closed captioning functionality",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",