@svta/cml-608 0.19.0 → 0.20.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 +15 -0
- package/dist/index.d.ts +405 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1180 -15
- package/dist/index.js.map +1 -1
- package/package.json +4 -28
- package/NOTICE +0 -59
- package/dist/CaptionModes.d.ts +0 -7
- package/dist/CaptionModes.d.ts.map +0 -1
- package/dist/CaptionModes.js +0 -2
- package/dist/CaptionModes.js.map +0 -1
- package/dist/CaptionScreen.d.ts +0 -80
- package/dist/CaptionScreen.d.ts.map +0 -1
- package/dist/CaptionScreen.js +0 -220
- package/dist/CaptionScreen.js.map +0 -1
- package/dist/CaptionsLogger.d.ts +0 -49
- package/dist/CaptionsLogger.d.ts.map +0 -1
- package/dist/CaptionsLogger.js +0 -56
- package/dist/CaptionsLogger.js.map +0 -1
- package/dist/Channels.d.ts +0 -7
- package/dist/Channels.d.ts.map +0 -1
- package/dist/Channels.js +0 -2
- package/dist/Channels.js.map +0 -1
- package/dist/CmdHistory.d.ts +0 -10
- package/dist/CmdHistory.d.ts.map +0 -1
- package/dist/CmdHistory.js +0 -2
- package/dist/CmdHistory.js.map +0 -1
- package/dist/Cta608Channel.d.ts +0 -88
- package/dist/Cta608Channel.d.ts.map +0 -1
- package/dist/Cta608Channel.js +0 -262
- package/dist/Cta608Channel.js.map +0 -1
- package/dist/Cta608Parser.d.ts +0 -115
- package/dist/Cta608Parser.d.ts.map +0 -1
- package/dist/Cta608Parser.js +0 -428
- package/dist/Cta608Parser.js.map +0 -1
- package/dist/CueHandler.d.ts +0 -12
- package/dist/CueHandler.d.ts.map +0 -1
- package/dist/CueHandler.js +0 -2
- package/dist/CueHandler.js.map +0 -1
- package/dist/PACData.d.ts +0 -13
- package/dist/PACData.d.ts.map +0 -1
- package/dist/PACData.js +0 -2
- package/dist/PACData.js.map +0 -1
- package/dist/PenState.d.ts +0 -56
- package/dist/PenState.d.ts.map +0 -1
- package/dist/PenState.js +0 -95
- package/dist/PenState.js.map +0 -1
- package/dist/PenStyles.d.ts +0 -13
- package/dist/PenStyles.d.ts.map +0 -1
- package/dist/PenStyles.js +0 -2
- package/dist/PenStyles.js.map +0 -1
- package/dist/Row.d.ts +0 -75
- package/dist/Row.d.ts.map +0 -1
- package/dist/Row.js +0 -174
- package/dist/Row.js.map +0 -1
- package/dist/SccParser.d.ts +0 -49
- package/dist/SccParser.d.ts.map +0 -1
- package/dist/SccParser.js +0 -99
- package/dist/SccParser.js.map +0 -1
- package/dist/StyledUnicodeChar.d.ts +0 -54
- package/dist/StyledUnicodeChar.d.ts.map +0 -1
- package/dist/StyledUnicodeChar.js +0 -71
- package/dist/StyledUnicodeChar.js.map +0 -1
- package/dist/SupportedField.d.ts +0 -7
- package/dist/SupportedField.d.ts.map +0 -1
- package/dist/SupportedField.js +0 -2
- package/dist/SupportedField.js.map +0 -1
- package/dist/VerboseLevel.d.ts +0 -22
- package/dist/VerboseLevel.d.ts.map +0 -1
- package/dist/VerboseLevel.js +0 -17
- package/dist/VerboseLevel.js.map +0 -1
- package/dist/extractCta608Data.d.ts +0 -11
- package/dist/extractCta608Data.d.ts.map +0 -1
- package/dist/extractCta608Data.js +0 -38
- package/dist/extractCta608Data.js.map +0 -1
- package/dist/extractCta608DataFromSample.d.ts +0 -12
- package/dist/extractCta608DataFromSample.d.ts.map +0 -1
- package/dist/extractCta608DataFromSample.js +0 -35
- package/dist/extractCta608DataFromSample.js.map +0 -1
- package/dist/findCta608Nalus.d.ts +0 -12
- package/dist/findCta608Nalus.d.ts.map +0 -1
- package/dist/findCta608Nalus.js +0 -60
- package/dist/findCta608Nalus.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/utils/NR_COLS.d.ts +0 -2
- package/dist/utils/NR_COLS.d.ts.map +0 -1
- package/dist/utils/NR_COLS.js +0 -2
- package/dist/utils/NR_COLS.js.map +0 -1
- package/dist/utils/NR_ROWS.d.ts +0 -2
- package/dist/utils/NR_ROWS.d.ts.map +0 -1
- package/dist/utils/NR_ROWS.js +0 -2
- package/dist/utils/NR_ROWS.js.map +0 -1
- package/dist/utils/backgroundColors.d.ts +0 -2
- package/dist/utils/backgroundColors.d.ts.map +0 -1
- package/dist/utils/backgroundColors.js +0 -12
- package/dist/utils/backgroundColors.js.map +0 -1
- package/dist/utils/createCmdHistory.d.ts +0 -3
- package/dist/utils/createCmdHistory.d.ts.map +0 -1
- package/dist/utils/createCmdHistory.js +0 -7
- package/dist/utils/createCmdHistory.js.map +0 -1
- package/dist/utils/getCharForByte.d.ts +0 -2
- package/dist/utils/getCharForByte.d.ts.map +0 -1
- package/dist/utils/getCharForByte.js +0 -6
- package/dist/utils/getCharForByte.js.map +0 -1
- package/dist/utils/hasCmdRepeated.d.ts +0 -3
- package/dist/utils/hasCmdRepeated.d.ts.map +0 -1
- package/dist/utils/hasCmdRepeated.js +0 -4
- package/dist/utils/hasCmdRepeated.js.map +0 -1
- package/dist/utils/index.d.ts +0 -20
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -20
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/numArrayToHexArray.d.ts +0 -2
- package/dist/utils/numArrayToHexArray.d.ts.map +0 -1
- package/dist/utils/numArrayToHexArray.js +0 -9
- package/dist/utils/numArrayToHexArray.js.map +0 -1
- package/dist/utils/rowsHighCh1.d.ts +0 -4
- package/dist/utils/rowsHighCh1.d.ts.map +0 -1
- package/dist/utils/rowsHighCh1.js +0 -10
- package/dist/utils/rowsHighCh1.js.map +0 -1
- package/dist/utils/rowsHighCh2.d.ts +0 -4
- package/dist/utils/rowsHighCh2.d.ts.map +0 -1
- package/dist/utils/rowsHighCh2.js +0 -10
- package/dist/utils/rowsHighCh2.js.map +0 -1
- package/dist/utils/rowsLowCh1.d.ts +0 -4
- package/dist/utils/rowsLowCh1.d.ts.map +0 -1
- package/dist/utils/rowsLowCh1.js +0 -12
- package/dist/utils/rowsLowCh1.js.map +0 -1
- package/dist/utils/rowsLowCh2.d.ts +0 -4
- package/dist/utils/rowsLowCh2.d.ts.map +0 -1
- package/dist/utils/rowsLowCh2.js +0 -11
- package/dist/utils/rowsLowCh2.js.map +0 -1
- package/dist/utils/seiHelpers.d.ts +0 -7
- package/dist/utils/seiHelpers.d.ts.map +0 -1
- package/dist/utils/seiHelpers.js +0 -78
- package/dist/utils/seiHelpers.js.map +0 -1
- package/dist/utils/setLastCmd.d.ts +0 -3
- package/dist/utils/setLastCmd.d.ts.map +0 -1
- package/dist/utils/setLastCmd.js +0 -5
- package/dist/utils/setLastCmd.js.map +0 -1
- package/dist/utils/specialCea608CharsCodes.d.ts +0 -7
- package/dist/utils/specialCea608CharsCodes.d.ts.map +0 -1
- package/dist/utils/specialCea608CharsCodes.js +0 -103
- package/dist/utils/specialCea608CharsCodes.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,16 +1,1181 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
//#region src/VerboseLevel.ts
|
|
2
|
+
/**
|
|
3
|
+
* Logging levels for the CTA-608 parser.
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* @enum
|
|
7
|
+
*
|
|
8
|
+
* @beta
|
|
9
|
+
*/
|
|
10
|
+
const VerboseLevel = {
|
|
11
|
+
ERROR: 0,
|
|
12
|
+
TEXT: 1,
|
|
13
|
+
WARNING: 2,
|
|
14
|
+
INFO: 2,
|
|
15
|
+
DEBUG: 3,
|
|
16
|
+
DATA: 3
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/CaptionsLogger.ts
|
|
21
|
+
/**
|
|
22
|
+
* CaptionsLogger. To be removed in the future.
|
|
23
|
+
*
|
|
24
|
+
* @beta
|
|
25
|
+
*/
|
|
26
|
+
var CaptionsLogger = class {
|
|
27
|
+
constructor() {
|
|
28
|
+
this.time = null;
|
|
29
|
+
this.verboseLevel = VerboseLevel.ERROR;
|
|
30
|
+
}
|
|
31
|
+
log(severity, msg) {
|
|
32
|
+
if (this.verboseLevel >= severity) {
|
|
33
|
+
const m = typeof msg === "function" ? msg() : msg;
|
|
34
|
+
console.log(`${this.time} [${severity}] ${m}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/PenState.ts
|
|
41
|
+
/**
|
|
42
|
+
* Pen state.
|
|
43
|
+
*
|
|
44
|
+
* @beta
|
|
45
|
+
*/
|
|
46
|
+
var PenState = class {
|
|
47
|
+
constructor() {
|
|
48
|
+
this.foreground = "white";
|
|
49
|
+
this.underline = false;
|
|
50
|
+
this.italics = false;
|
|
51
|
+
this.background = "black";
|
|
52
|
+
this.flash = false;
|
|
53
|
+
}
|
|
54
|
+
reset() {
|
|
55
|
+
this.foreground = "white";
|
|
56
|
+
this.underline = false;
|
|
57
|
+
this.italics = false;
|
|
58
|
+
this.background = "black";
|
|
59
|
+
this.flash = false;
|
|
60
|
+
}
|
|
61
|
+
setStyles(styles) {
|
|
62
|
+
const attribs = [
|
|
63
|
+
"foreground",
|
|
64
|
+
"underline",
|
|
65
|
+
"italics",
|
|
66
|
+
"background",
|
|
67
|
+
"flash"
|
|
68
|
+
];
|
|
69
|
+
for (let i = 0; i < attribs.length; i++) {
|
|
70
|
+
const style = attribs[i];
|
|
71
|
+
if (Object.prototype.hasOwnProperty.call(styles, style)) this[style] = styles[style];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
isDefault() {
|
|
75
|
+
return this.foreground === "white" && !this.underline && !this.italics && this.background === "black" && !this.flash;
|
|
76
|
+
}
|
|
77
|
+
equals(other) {
|
|
78
|
+
return this.foreground === other.foreground && this.underline === other.underline && this.italics === other.italics && this.background === other.background && this.flash === other.flash;
|
|
79
|
+
}
|
|
80
|
+
copy(newPenState) {
|
|
81
|
+
this.foreground = newPenState.foreground;
|
|
82
|
+
this.underline = newPenState.underline;
|
|
83
|
+
this.italics = newPenState.italics;
|
|
84
|
+
this.background = newPenState.background;
|
|
85
|
+
this.flash = newPenState.flash;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/StyledUnicodeChar.ts
|
|
91
|
+
/**
|
|
92
|
+
* Unicode character with styling and background.
|
|
93
|
+
*
|
|
94
|
+
* @beta
|
|
95
|
+
*/
|
|
96
|
+
var StyledUnicodeChar = class {
|
|
97
|
+
constructor() {
|
|
98
|
+
this.uchar = " ";
|
|
99
|
+
this.penState = new PenState();
|
|
100
|
+
}
|
|
101
|
+
reset() {
|
|
102
|
+
this.uchar = " ";
|
|
103
|
+
this.penState.reset();
|
|
104
|
+
}
|
|
105
|
+
setChar(uchar, newPenState) {
|
|
106
|
+
this.uchar = uchar;
|
|
107
|
+
this.penState.copy(newPenState);
|
|
108
|
+
}
|
|
109
|
+
setPenState(newPenState) {
|
|
110
|
+
this.penState.copy(newPenState);
|
|
111
|
+
}
|
|
112
|
+
equals(other) {
|
|
113
|
+
return this.uchar === other.uchar && this.penState.equals(other.penState);
|
|
114
|
+
}
|
|
115
|
+
copy(newChar) {
|
|
116
|
+
this.uchar = newChar.uchar;
|
|
117
|
+
this.penState.copy(newChar.penState);
|
|
118
|
+
}
|
|
119
|
+
isEmpty() {
|
|
120
|
+
return this.uchar === " " && this.penState.isDefault();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/utils/NR_COLS.ts
|
|
126
|
+
const NR_COLS = 100;
|
|
127
|
+
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/utils/specialCea608CharsCodes.ts
|
|
130
|
+
/**
|
|
131
|
+
* Exceptions from regular ASCII. CodePoints are mapped to UTF-16 codes
|
|
132
|
+
*/
|
|
133
|
+
const specialCea608CharsCodes = {
|
|
134
|
+
42: 225,
|
|
135
|
+
92: 233,
|
|
136
|
+
94: 237,
|
|
137
|
+
95: 243,
|
|
138
|
+
96: 250,
|
|
139
|
+
123: 231,
|
|
140
|
+
124: 247,
|
|
141
|
+
125: 209,
|
|
142
|
+
126: 241,
|
|
143
|
+
127: 9608,
|
|
144
|
+
128: 174,
|
|
145
|
+
129: 176,
|
|
146
|
+
130: 189,
|
|
147
|
+
131: 191,
|
|
148
|
+
132: 8482,
|
|
149
|
+
133: 162,
|
|
150
|
+
134: 163,
|
|
151
|
+
135: 9834,
|
|
152
|
+
136: 224,
|
|
153
|
+
137: 32,
|
|
154
|
+
138: 232,
|
|
155
|
+
139: 226,
|
|
156
|
+
140: 234,
|
|
157
|
+
141: 238,
|
|
158
|
+
142: 244,
|
|
159
|
+
143: 251,
|
|
160
|
+
144: 193,
|
|
161
|
+
145: 201,
|
|
162
|
+
146: 211,
|
|
163
|
+
147: 218,
|
|
164
|
+
148: 220,
|
|
165
|
+
149: 252,
|
|
166
|
+
150: 8216,
|
|
167
|
+
151: 161,
|
|
168
|
+
152: 42,
|
|
169
|
+
153: 8217,
|
|
170
|
+
154: 9473,
|
|
171
|
+
155: 169,
|
|
172
|
+
156: 8480,
|
|
173
|
+
157: 8226,
|
|
174
|
+
158: 8220,
|
|
175
|
+
159: 8221,
|
|
176
|
+
160: 192,
|
|
177
|
+
161: 194,
|
|
178
|
+
162: 199,
|
|
179
|
+
163: 200,
|
|
180
|
+
164: 202,
|
|
181
|
+
165: 203,
|
|
182
|
+
166: 235,
|
|
183
|
+
167: 206,
|
|
184
|
+
168: 207,
|
|
185
|
+
169: 239,
|
|
186
|
+
170: 212,
|
|
187
|
+
171: 217,
|
|
188
|
+
172: 249,
|
|
189
|
+
173: 219,
|
|
190
|
+
174: 171,
|
|
191
|
+
175: 187,
|
|
192
|
+
176: 195,
|
|
193
|
+
177: 227,
|
|
194
|
+
178: 205,
|
|
195
|
+
179: 204,
|
|
196
|
+
180: 236,
|
|
197
|
+
181: 210,
|
|
198
|
+
182: 242,
|
|
199
|
+
183: 213,
|
|
200
|
+
184: 245,
|
|
201
|
+
185: 123,
|
|
202
|
+
186: 125,
|
|
203
|
+
187: 92,
|
|
204
|
+
188: 94,
|
|
205
|
+
189: 95,
|
|
206
|
+
190: 124,
|
|
207
|
+
191: 8764,
|
|
208
|
+
192: 196,
|
|
209
|
+
193: 228,
|
|
210
|
+
194: 214,
|
|
211
|
+
195: 246,
|
|
212
|
+
196: 223,
|
|
213
|
+
197: 165,
|
|
214
|
+
198: 164,
|
|
215
|
+
199: 9475,
|
|
216
|
+
200: 197,
|
|
217
|
+
201: 229,
|
|
218
|
+
202: 216,
|
|
219
|
+
203: 248,
|
|
220
|
+
204: 9487,
|
|
221
|
+
205: 9491,
|
|
222
|
+
206: 9495,
|
|
223
|
+
207: 9499
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region src/utils/getCharForByte.ts
|
|
228
|
+
function getCharForByte(byte) {
|
|
229
|
+
return String.fromCharCode(specialCea608CharsCodes[byte] || byte);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region src/Row.ts
|
|
234
|
+
/**
|
|
235
|
+
* CTA-608 row consisting of NR_COLS instances of StyledUnicodeChar.
|
|
236
|
+
*
|
|
237
|
+
* @beta
|
|
238
|
+
*/
|
|
239
|
+
var Row = class {
|
|
240
|
+
constructor(logger = new CaptionsLogger()) {
|
|
241
|
+
this.chars = [];
|
|
242
|
+
this.cueStartTime = null;
|
|
243
|
+
this.pos = 0;
|
|
244
|
+
this.currPenState = new PenState();
|
|
245
|
+
for (let i = 0; i < NR_COLS; i++) this.chars.push(new StyledUnicodeChar());
|
|
246
|
+
this.logger = logger;
|
|
247
|
+
}
|
|
248
|
+
equals(other) {
|
|
249
|
+
for (let i = 0; i < NR_COLS; i++) if (!this.chars[i].equals(other.chars[i])) return false;
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
copy(other) {
|
|
253
|
+
for (let i = 0; i < NR_COLS; i++) this.chars[i].copy(other.chars[i]);
|
|
254
|
+
}
|
|
255
|
+
isEmpty() {
|
|
256
|
+
let empty = true;
|
|
257
|
+
for (let i = 0; i < NR_COLS; i++) if (!this.chars[i].isEmpty()) {
|
|
258
|
+
empty = false;
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
return empty;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Set the cursor to a valid column.
|
|
265
|
+
*/
|
|
266
|
+
setCursor(absPos) {
|
|
267
|
+
if (this.pos !== absPos) this.pos = absPos;
|
|
268
|
+
if (this.pos < 0) {
|
|
269
|
+
this.logger.log(VerboseLevel.DEBUG, "Negative cursor position " + this.pos);
|
|
270
|
+
this.pos = 0;
|
|
271
|
+
} else if (this.pos > NR_COLS) {
|
|
272
|
+
this.logger.log(VerboseLevel.DEBUG, "Too large cursor position " + this.pos);
|
|
273
|
+
this.pos = NR_COLS;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Move the cursor relative to current position.
|
|
278
|
+
*/
|
|
279
|
+
moveCursor(relPos) {
|
|
280
|
+
const newPos = this.pos + relPos;
|
|
281
|
+
if (relPos > 1) for (let i = this.pos + 1; i < newPos + 1; i++) this.chars[i].setPenState(this.currPenState);
|
|
282
|
+
this.setCursor(newPos);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Backspace, move one step back and clear character.
|
|
286
|
+
*/
|
|
287
|
+
backSpace() {
|
|
288
|
+
this.moveCursor(-1);
|
|
289
|
+
this.chars[this.pos].setChar(" ", this.currPenState);
|
|
290
|
+
}
|
|
291
|
+
insertChar(byte) {
|
|
292
|
+
if (byte >= 144) this.backSpace();
|
|
293
|
+
const char = getCharForByte(byte);
|
|
294
|
+
if (this.pos >= NR_COLS) {
|
|
295
|
+
this.logger.log(VerboseLevel.ERROR, () => "Cannot insert " + byte.toString(16) + " (" + char + ") at position " + this.pos + ". Skipping it!");
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
this.chars[this.pos].setChar(char, this.currPenState);
|
|
299
|
+
this.moveCursor(1);
|
|
300
|
+
}
|
|
301
|
+
clearFromPos(startPos) {
|
|
302
|
+
let i;
|
|
303
|
+
for (i = startPos; i < NR_COLS; i++) this.chars[i].reset();
|
|
304
|
+
}
|
|
305
|
+
clear() {
|
|
306
|
+
this.clearFromPos(0);
|
|
307
|
+
this.pos = 0;
|
|
308
|
+
this.currPenState.reset();
|
|
309
|
+
}
|
|
310
|
+
clearToEndOfRow() {
|
|
311
|
+
this.clearFromPos(this.pos);
|
|
312
|
+
}
|
|
313
|
+
getTextString() {
|
|
314
|
+
const chars = [];
|
|
315
|
+
let empty = true;
|
|
316
|
+
for (let i = 0; i < NR_COLS; i++) {
|
|
317
|
+
const char = this.chars[i].uchar;
|
|
318
|
+
if (char !== " ") empty = false;
|
|
319
|
+
chars.push(char);
|
|
320
|
+
}
|
|
321
|
+
if (empty) return "";
|
|
322
|
+
else return chars.join("");
|
|
323
|
+
}
|
|
324
|
+
setPenStyles(styles) {
|
|
325
|
+
this.currPenState.setStyles(styles);
|
|
326
|
+
this.chars[this.pos].setPenState(this.currPenState);
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region src/utils/NR_ROWS.ts
|
|
332
|
+
const NR_ROWS = 15;
|
|
333
|
+
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/CaptionScreen.ts
|
|
336
|
+
/**
|
|
337
|
+
* Keep a CTA-608 screen of 32x15 styled characters
|
|
338
|
+
*
|
|
339
|
+
* @beta
|
|
340
|
+
*/
|
|
341
|
+
var CaptionScreen = class {
|
|
342
|
+
constructor(logger = new CaptionsLogger()) {
|
|
343
|
+
this.rows = [];
|
|
344
|
+
this.currRow = NR_ROWS - 1;
|
|
345
|
+
this.nrRollUpRows = null;
|
|
346
|
+
this.lastOutputScreen = null;
|
|
347
|
+
for (let i = 0; i < NR_ROWS; i++) this.rows.push(new Row(logger));
|
|
348
|
+
this.logger = logger;
|
|
349
|
+
}
|
|
350
|
+
reset() {
|
|
351
|
+
for (let i = 0; i < NR_ROWS; i++) this.rows[i].clear();
|
|
352
|
+
this.currRow = NR_ROWS - 1;
|
|
353
|
+
}
|
|
354
|
+
equals(other) {
|
|
355
|
+
let equal = true;
|
|
356
|
+
for (let i = 0; i < NR_ROWS; i++) if (!this.rows[i].equals(other.rows[i])) {
|
|
357
|
+
equal = false;
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
return equal;
|
|
361
|
+
}
|
|
362
|
+
copy(other) {
|
|
363
|
+
for (let i = 0; i < NR_ROWS; i++) this.rows[i].copy(other.rows[i]);
|
|
364
|
+
}
|
|
365
|
+
isEmpty() {
|
|
366
|
+
let empty = true;
|
|
367
|
+
for (let i = 0; i < NR_ROWS; i++) if (!this.rows[i].isEmpty()) {
|
|
368
|
+
empty = false;
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
return empty;
|
|
372
|
+
}
|
|
373
|
+
backSpace() {
|
|
374
|
+
this.rows[this.currRow].backSpace();
|
|
375
|
+
}
|
|
376
|
+
clearToEndOfRow() {
|
|
377
|
+
this.rows[this.currRow].clearToEndOfRow();
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Insert a character (without styling) in the current row.
|
|
381
|
+
*/
|
|
382
|
+
insertChar(char) {
|
|
383
|
+
this.rows[this.currRow].insertChar(char);
|
|
384
|
+
}
|
|
385
|
+
setPen(styles) {
|
|
386
|
+
this.rows[this.currRow].setPenStyles(styles);
|
|
387
|
+
}
|
|
388
|
+
moveCursor(relPos) {
|
|
389
|
+
this.rows[this.currRow].moveCursor(relPos);
|
|
390
|
+
}
|
|
391
|
+
setCursor(absPos) {
|
|
392
|
+
this.logger.log(VerboseLevel.INFO, "setCursor: " + absPos);
|
|
393
|
+
this.rows[this.currRow].setCursor(absPos);
|
|
394
|
+
}
|
|
395
|
+
setPAC(pacData) {
|
|
396
|
+
this.logger.log(VerboseLevel.INFO, () => "pacData = " + JSON.stringify(pacData));
|
|
397
|
+
let newRow = pacData.row - 1;
|
|
398
|
+
if (this.nrRollUpRows && newRow < this.nrRollUpRows - 1) newRow = this.nrRollUpRows - 1;
|
|
399
|
+
if (this.nrRollUpRows && this.currRow !== newRow) {
|
|
400
|
+
for (let i = 0; i < NR_ROWS; i++) this.rows[i].clear();
|
|
401
|
+
const topRowIndex = this.currRow + 1 - this.nrRollUpRows;
|
|
402
|
+
const lastOutputScreen = this.lastOutputScreen;
|
|
403
|
+
if (lastOutputScreen) {
|
|
404
|
+
const prevLineTime = lastOutputScreen.rows[topRowIndex].cueStartTime;
|
|
405
|
+
const time = this.logger.time;
|
|
406
|
+
if (prevLineTime !== null && time !== null && prevLineTime < time) for (let i = 0; i < this.nrRollUpRows; i++) this.rows[newRow - this.nrRollUpRows + i + 1].copy(lastOutputScreen.rows[topRowIndex + i]);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
this.currRow = newRow;
|
|
410
|
+
const row = this.rows[this.currRow];
|
|
411
|
+
if (pacData.indent !== null) {
|
|
412
|
+
const indent = pacData.indent;
|
|
413
|
+
const prevPos = Math.max(indent - 1, 0);
|
|
414
|
+
row.setCursor(pacData.indent);
|
|
415
|
+
pacData.color = row.chars[prevPos].penState.foreground;
|
|
416
|
+
}
|
|
417
|
+
const styles = {
|
|
418
|
+
foreground: pacData.color,
|
|
419
|
+
underline: pacData.underline,
|
|
420
|
+
italics: pacData.italics,
|
|
421
|
+
background: "black",
|
|
422
|
+
flash: false
|
|
423
|
+
};
|
|
424
|
+
this.setPen(styles);
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Set background/extra foreground, but first do back_space, and then insert space (backwards compatibility).
|
|
428
|
+
*/
|
|
429
|
+
setBkgData(bkgData) {
|
|
430
|
+
this.logger.log(VerboseLevel.INFO, () => "bkgData = " + JSON.stringify(bkgData));
|
|
431
|
+
this.backSpace();
|
|
432
|
+
this.setPen(bkgData);
|
|
433
|
+
this.insertChar(32);
|
|
434
|
+
}
|
|
435
|
+
setRollUpRows(nrRows) {
|
|
436
|
+
this.nrRollUpRows = nrRows;
|
|
437
|
+
}
|
|
438
|
+
rollUp() {
|
|
439
|
+
if (this.nrRollUpRows === null) {
|
|
440
|
+
this.logger.log(VerboseLevel.DEBUG, "roll_up but nrRollUpRows not set yet");
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
this.logger.log(VerboseLevel.TEXT, () => this.getDisplayText());
|
|
444
|
+
const topRowIndex = this.currRow + 1 - this.nrRollUpRows;
|
|
445
|
+
const topRow = this.rows.splice(topRowIndex, 1)[0];
|
|
446
|
+
topRow.clear();
|
|
447
|
+
this.rows.splice(this.currRow, 0, topRow);
|
|
448
|
+
this.logger.log(VerboseLevel.INFO, "Rolling up");
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Get all non-empty rows with as unicode text.
|
|
452
|
+
*/
|
|
453
|
+
getDisplayText(asOneRow) {
|
|
454
|
+
asOneRow = asOneRow || false;
|
|
455
|
+
const displayText = [];
|
|
456
|
+
let text = "";
|
|
457
|
+
let rowNr = -1;
|
|
458
|
+
for (let i = 0; i < NR_ROWS; i++) {
|
|
459
|
+
const rowText = this.rows[i].getTextString();
|
|
460
|
+
if (rowText) {
|
|
461
|
+
rowNr = i + 1;
|
|
462
|
+
if (asOneRow) displayText.push("Row " + rowNr + ": '" + rowText + "'");
|
|
463
|
+
else displayText.push(rowText.trim());
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
if (displayText.length > 0) if (asOneRow) text = "[" + displayText.join(" | ") + "]";
|
|
467
|
+
else text = displayText.join("\n");
|
|
468
|
+
return text;
|
|
469
|
+
}
|
|
470
|
+
getTextAndFormat() {
|
|
471
|
+
return this.rows;
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region src/Cta608Channel.ts
|
|
477
|
+
/**
|
|
478
|
+
* CTA-608 Channel
|
|
479
|
+
*
|
|
480
|
+
* @beta
|
|
481
|
+
*/
|
|
482
|
+
var Cta608Channel = class {
|
|
483
|
+
constructor(channelNumber, outputFilter, logger = new CaptionsLogger()) {
|
|
484
|
+
this.chNr = channelNumber;
|
|
485
|
+
this.outputFilter = outputFilter;
|
|
486
|
+
this.mode = null;
|
|
487
|
+
this.displayedMemory = new CaptionScreen(logger);
|
|
488
|
+
this.nonDisplayedMemory = new CaptionScreen(logger);
|
|
489
|
+
this.lastOutputScreen = new CaptionScreen(logger);
|
|
490
|
+
this.currRollUpRow = this.displayedMemory.rows[NR_ROWS - 1];
|
|
491
|
+
this.writeScreen = this.displayedMemory;
|
|
492
|
+
this.mode = null;
|
|
493
|
+
this.cueStartTime = null;
|
|
494
|
+
this.logger = logger;
|
|
495
|
+
this.logger.log(VerboseLevel.INFO, "new Cea608Channel(" + this.chNr + ")");
|
|
496
|
+
}
|
|
497
|
+
reset() {
|
|
498
|
+
this.mode = null;
|
|
499
|
+
this.displayedMemory.reset();
|
|
500
|
+
this.nonDisplayedMemory.reset();
|
|
501
|
+
this.lastOutputScreen.reset();
|
|
502
|
+
this.outputFilter?.reset?.();
|
|
503
|
+
this.currRollUpRow = this.displayedMemory.rows[NR_ROWS - 1];
|
|
504
|
+
this.writeScreen = this.displayedMemory;
|
|
505
|
+
this.mode = null;
|
|
506
|
+
this.cueStartTime = null;
|
|
507
|
+
}
|
|
508
|
+
getHandler() {
|
|
509
|
+
return this.outputFilter;
|
|
510
|
+
}
|
|
511
|
+
setHandler(outputFilter) {
|
|
512
|
+
this.outputFilter = outputFilter;
|
|
513
|
+
}
|
|
514
|
+
setPAC(pacData) {
|
|
515
|
+
this.writeScreen.setPAC(pacData);
|
|
516
|
+
}
|
|
517
|
+
setBkgData(bkgData) {
|
|
518
|
+
this.writeScreen.setBkgData(bkgData);
|
|
519
|
+
}
|
|
520
|
+
setMode(newMode) {
|
|
521
|
+
if (newMode === this.mode) return;
|
|
522
|
+
this.mode = newMode;
|
|
523
|
+
this.logger.log(VerboseLevel.INFO, () => "MODE=" + newMode);
|
|
524
|
+
if (this.mode === "MODE_POP-ON") this.writeScreen = this.nonDisplayedMemory;
|
|
525
|
+
else {
|
|
526
|
+
this.writeScreen = this.displayedMemory;
|
|
527
|
+
this.writeScreen.reset();
|
|
528
|
+
}
|
|
529
|
+
if (this.mode !== "MODE_ROLL-UP") {
|
|
530
|
+
this.displayedMemory.setRollUpRows(null);
|
|
531
|
+
this.nonDisplayedMemory.setRollUpRows(null);
|
|
532
|
+
}
|
|
533
|
+
this.mode = newMode;
|
|
534
|
+
}
|
|
535
|
+
insertChars(chars) {
|
|
536
|
+
for (let i = 0; i < chars.length; i++) this.writeScreen.insertChar(chars[i]);
|
|
537
|
+
const screen = this.writeScreen === this.displayedMemory ? "DISP" : "NON_DISP";
|
|
538
|
+
this.logger.log(VerboseLevel.INFO, () => screen + ": " + this.writeScreen.getDisplayText(true));
|
|
539
|
+
if (this.mode === "MODE_PAINT-ON" || this.mode === "MODE_ROLL-UP") {
|
|
540
|
+
this.logger.log(VerboseLevel.TEXT, () => "DISPLAYED: " + this.displayedMemory.getDisplayText(true));
|
|
541
|
+
this.outputDataUpdate();
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
ccRCL() {
|
|
545
|
+
this.logger.log(VerboseLevel.INFO, "RCL - Resume Caption Loading");
|
|
546
|
+
this.setMode("MODE_POP-ON");
|
|
547
|
+
}
|
|
548
|
+
ccBS() {
|
|
549
|
+
this.logger.log(VerboseLevel.INFO, "BS - BackSpace");
|
|
550
|
+
if (this.mode === "MODE_TEXT") return;
|
|
551
|
+
this.writeScreen.backSpace();
|
|
552
|
+
if (this.writeScreen === this.displayedMemory) this.outputDataUpdate();
|
|
553
|
+
}
|
|
554
|
+
ccAOF() {}
|
|
555
|
+
ccAON() {}
|
|
556
|
+
ccDER() {
|
|
557
|
+
this.logger.log(VerboseLevel.INFO, "DER- Delete to End of Row");
|
|
558
|
+
this.writeScreen.clearToEndOfRow();
|
|
559
|
+
this.outputDataUpdate();
|
|
560
|
+
}
|
|
561
|
+
ccRU(nrRows) {
|
|
562
|
+
this.logger.log(VerboseLevel.INFO, "RU(" + nrRows + ") - Roll Up");
|
|
563
|
+
this.writeScreen = this.displayedMemory;
|
|
564
|
+
this.setMode("MODE_ROLL-UP");
|
|
565
|
+
this.writeScreen.setRollUpRows(nrRows);
|
|
566
|
+
}
|
|
567
|
+
ccFON() {
|
|
568
|
+
this.logger.log(VerboseLevel.INFO, "FON - Flash On");
|
|
569
|
+
this.writeScreen.setPen({ flash: true });
|
|
570
|
+
}
|
|
571
|
+
ccRDC() {
|
|
572
|
+
this.logger.log(VerboseLevel.INFO, "RDC - Resume Direct Captioning");
|
|
573
|
+
this.setMode("MODE_PAINT-ON");
|
|
574
|
+
}
|
|
575
|
+
ccTR() {
|
|
576
|
+
this.logger.log(VerboseLevel.INFO, "TR");
|
|
577
|
+
this.setMode("MODE_TEXT");
|
|
578
|
+
}
|
|
579
|
+
ccRTD() {
|
|
580
|
+
this.logger.log(VerboseLevel.INFO, "RTD");
|
|
581
|
+
this.setMode("MODE_TEXT");
|
|
582
|
+
}
|
|
583
|
+
ccEDM() {
|
|
584
|
+
this.logger.log(VerboseLevel.INFO, "EDM - Erase Displayed Memory");
|
|
585
|
+
this.displayedMemory.reset();
|
|
586
|
+
this.outputDataUpdate(true);
|
|
587
|
+
}
|
|
588
|
+
ccCR() {
|
|
589
|
+
this.logger.log(VerboseLevel.INFO, "CR - Carriage Return");
|
|
590
|
+
this.writeScreen.rollUp();
|
|
591
|
+
this.outputDataUpdate(true);
|
|
592
|
+
}
|
|
593
|
+
ccENM() {
|
|
594
|
+
this.logger.log(VerboseLevel.INFO, "ENM - Erase Non-displayed Memory");
|
|
595
|
+
this.nonDisplayedMemory.reset();
|
|
596
|
+
}
|
|
597
|
+
ccEOC() {
|
|
598
|
+
this.logger.log(VerboseLevel.INFO, "EOC - End Of Caption");
|
|
599
|
+
if (this.mode === "MODE_POP-ON") {
|
|
600
|
+
const tmp = this.displayedMemory;
|
|
601
|
+
this.displayedMemory = this.nonDisplayedMemory;
|
|
602
|
+
this.nonDisplayedMemory = tmp;
|
|
603
|
+
this.writeScreen = this.nonDisplayedMemory;
|
|
604
|
+
this.logger.log(VerboseLevel.TEXT, () => "DISP: " + this.displayedMemory.getDisplayText());
|
|
605
|
+
}
|
|
606
|
+
this.outputDataUpdate(true);
|
|
607
|
+
}
|
|
608
|
+
ccTO(nrCols) {
|
|
609
|
+
this.logger.log(VerboseLevel.INFO, "TO(" + nrCols + ") - Tab Offset");
|
|
610
|
+
this.writeScreen.moveCursor(nrCols);
|
|
611
|
+
}
|
|
612
|
+
ccMIDROW(secondByte) {
|
|
613
|
+
const styles = { flash: false };
|
|
614
|
+
styles.underline = secondByte % 2 === 1;
|
|
615
|
+
styles.italics = secondByte >= 46;
|
|
616
|
+
if (!styles.italics) styles.foreground = [
|
|
617
|
+
"white",
|
|
618
|
+
"green",
|
|
619
|
+
"blue",
|
|
620
|
+
"cyan",
|
|
621
|
+
"red",
|
|
622
|
+
"yellow",
|
|
623
|
+
"magenta"
|
|
624
|
+
][Math.floor(secondByte / 2) - 16];
|
|
625
|
+
else styles.foreground = "white";
|
|
626
|
+
this.logger.log(VerboseLevel.INFO, "MIDROW: " + JSON.stringify(styles));
|
|
627
|
+
this.writeScreen.setPen(styles);
|
|
628
|
+
}
|
|
629
|
+
outputDataUpdate(dispatch = false) {
|
|
630
|
+
const time = this.logger.time;
|
|
631
|
+
if (time === null) return;
|
|
632
|
+
if (this.outputFilter) {
|
|
633
|
+
if (this.cueStartTime === null && !this.displayedMemory.isEmpty()) this.cueStartTime = time;
|
|
634
|
+
else if (!this.displayedMemory.equals(this.lastOutputScreen)) {
|
|
635
|
+
this.outputFilter.newCue(this.cueStartTime, time, this.lastOutputScreen);
|
|
636
|
+
if (dispatch && this.outputFilter.dispatchCue) this.outputFilter.dispatchCue();
|
|
637
|
+
this.cueStartTime = this.displayedMemory.isEmpty() ? null : time;
|
|
638
|
+
}
|
|
639
|
+
this.lastOutputScreen.copy(this.displayedMemory);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
cueSplitAtTime(t) {
|
|
643
|
+
if (this.outputFilter) {
|
|
644
|
+
if (!this.displayedMemory.isEmpty()) {
|
|
645
|
+
if (this.outputFilter.newCue) this.outputFilter.newCue(this.cueStartTime, t, this.displayedMemory);
|
|
646
|
+
this.cueStartTime = t;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
//#endregion
|
|
653
|
+
//#region src/utils/backgroundColors.ts
|
|
654
|
+
const backgroundColors = [
|
|
655
|
+
"white",
|
|
656
|
+
"green",
|
|
657
|
+
"blue",
|
|
658
|
+
"cyan",
|
|
659
|
+
"red",
|
|
660
|
+
"yellow",
|
|
661
|
+
"magenta",
|
|
662
|
+
"black",
|
|
663
|
+
"transparent"
|
|
664
|
+
];
|
|
665
|
+
|
|
666
|
+
//#endregion
|
|
667
|
+
//#region src/utils/createCmdHistory.ts
|
|
668
|
+
function createCmdHistory() {
|
|
669
|
+
return {
|
|
670
|
+
a: null,
|
|
671
|
+
b: null
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
//#endregion
|
|
676
|
+
//#region src/utils/hasCmdRepeated.ts
|
|
677
|
+
function hasCmdRepeated(a, b, cmdHistory) {
|
|
678
|
+
return cmdHistory.a === a && cmdHistory.b === b;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
//#endregion
|
|
682
|
+
//#region src/utils/numArrayToHexArray.ts
|
|
683
|
+
function numArrayToHexArray(numArray) {
|
|
684
|
+
const hexArray = [];
|
|
685
|
+
for (let j = 0; j < numArray.length; j++) hexArray.push(numArray[j].toString(16));
|
|
686
|
+
return hexArray;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
//#endregion
|
|
690
|
+
//#region src/utils/rowsHighCh1.ts
|
|
691
|
+
const rowsHighCh1 = {
|
|
692
|
+
17: 2,
|
|
693
|
+
18: 4,
|
|
694
|
+
21: 6,
|
|
695
|
+
22: 8,
|
|
696
|
+
23: 10,
|
|
697
|
+
19: 13,
|
|
698
|
+
20: 15
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
//#endregion
|
|
702
|
+
//#region src/utils/rowsHighCh2.ts
|
|
703
|
+
const rowsHighCh2 = {
|
|
704
|
+
25: 2,
|
|
705
|
+
26: 4,
|
|
706
|
+
29: 6,
|
|
707
|
+
30: 8,
|
|
708
|
+
31: 10,
|
|
709
|
+
27: 13,
|
|
710
|
+
28: 15
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
//#endregion
|
|
714
|
+
//#region src/utils/rowsLowCh1.ts
|
|
715
|
+
const rowsLowCh1 = {
|
|
716
|
+
17: 1,
|
|
717
|
+
18: 3,
|
|
718
|
+
21: 5,
|
|
719
|
+
22: 7,
|
|
720
|
+
23: 9,
|
|
721
|
+
16: 11,
|
|
722
|
+
19: 12,
|
|
723
|
+
20: 14
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
//#endregion
|
|
727
|
+
//#region src/utils/rowsLowCh2.ts
|
|
728
|
+
const rowsLowCh2 = {
|
|
729
|
+
25: 1,
|
|
730
|
+
26: 3,
|
|
731
|
+
29: 5,
|
|
732
|
+
30: 7,
|
|
733
|
+
31: 9,
|
|
734
|
+
24: 11,
|
|
735
|
+
27: 12,
|
|
736
|
+
28: 14
|
|
737
|
+
};
|
|
738
|
+
|
|
739
|
+
//#endregion
|
|
740
|
+
//#region src/utils/setLastCmd.ts
|
|
741
|
+
function setLastCmd(a, b, cmdHistory) {
|
|
742
|
+
cmdHistory.a = a;
|
|
743
|
+
cmdHistory.b = b;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
//#endregion
|
|
747
|
+
//#region src/Cta608Parser.ts
|
|
748
|
+
/**
|
|
749
|
+
* CEA-608 caption parser.
|
|
750
|
+
*
|
|
751
|
+
* @beta
|
|
752
|
+
*/
|
|
753
|
+
var Cta608Parser = class {
|
|
754
|
+
constructor(field, out1, out2) {
|
|
755
|
+
this.currentChannel = 0;
|
|
756
|
+
this.cmdHistory = createCmdHistory();
|
|
757
|
+
this.lastTime = null;
|
|
758
|
+
const logger = this.logger = new CaptionsLogger();
|
|
759
|
+
this.channels = [
|
|
760
|
+
null,
|
|
761
|
+
new Cta608Channel(field, out1, logger),
|
|
762
|
+
new Cta608Channel(field + 1, out2, logger)
|
|
763
|
+
];
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Add data for time t in forms of list of bytes (unsigned ints). The bytes are treated as pairs.
|
|
767
|
+
*
|
|
768
|
+
* @param time - The time in milliseconds
|
|
769
|
+
* @param byteList - The list of bytes
|
|
770
|
+
*/
|
|
771
|
+
addData(time, byteList) {
|
|
772
|
+
this.lastTime = time;
|
|
773
|
+
this.logger.time = time;
|
|
774
|
+
for (let i = 0; i < byteList.length; i += 2) {
|
|
775
|
+
const a = byteList[i] & 127;
|
|
776
|
+
const b = byteList[i + 1] & 127;
|
|
777
|
+
let cmdFound = false;
|
|
778
|
+
let charsFound = null;
|
|
779
|
+
if (this.lastTime !== null) {
|
|
780
|
+
time = this.lastTime + .5 * i * 1001 / 3e4;
|
|
781
|
+
this.logger.time = time;
|
|
782
|
+
}
|
|
783
|
+
if (a === 0 && b === 0) continue;
|
|
784
|
+
else this.logger.log(VerboseLevel.DATA, () => "[" + numArrayToHexArray([byteList[i], byteList[i + 1]]) + "] -> (" + numArrayToHexArray([a, b]) + ")");
|
|
785
|
+
const cmdHistory = this.cmdHistory;
|
|
786
|
+
if (a >= 16 && a <= 31) {
|
|
787
|
+
if (hasCmdRepeated(a, b, cmdHistory)) {
|
|
788
|
+
setLastCmd(null, null, cmdHistory);
|
|
789
|
+
this.logger.log(VerboseLevel.DEBUG, () => "Repeated command (" + numArrayToHexArray([a, b]) + ") is dropped");
|
|
790
|
+
continue;
|
|
791
|
+
}
|
|
792
|
+
setLastCmd(a, b, this.cmdHistory);
|
|
793
|
+
cmdFound = this.parseCmd(a, b);
|
|
794
|
+
if (!cmdFound) cmdFound = this.parseMidrow(a, b);
|
|
795
|
+
if (!cmdFound) cmdFound = this.parsePAC(a, b);
|
|
796
|
+
if (!cmdFound) cmdFound = this.parseBackgroundAttributes(a, b);
|
|
797
|
+
} else setLastCmd(null, null, cmdHistory);
|
|
798
|
+
if (!cmdFound) {
|
|
799
|
+
charsFound = this.parseChars(a, b);
|
|
800
|
+
if (charsFound.length) {
|
|
801
|
+
const currChNr = this.currentChannel;
|
|
802
|
+
if (currChNr && currChNr > 0) this.channels[currChNr].insertChars(charsFound);
|
|
803
|
+
else this.logger.log(VerboseLevel.WARNING, "No channel found yet. TEXT-MODE?");
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
if (!cmdFound && !charsFound) this.logger.log(VerboseLevel.WARNING, () => "Couldn't parse cleaned data " + numArrayToHexArray([a, b]) + " orig: " + numArrayToHexArray([byteList[i], byteList[i + 1]]));
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Parse Command.
|
|
811
|
+
*
|
|
812
|
+
* @param a - The first byte
|
|
813
|
+
* @param b - The second byte
|
|
814
|
+
* @returns True if a command was found
|
|
815
|
+
*/
|
|
816
|
+
parseCmd(a, b) {
|
|
817
|
+
if (!((a === 20 || a === 28 || a === 21 || a === 29) && b >= 32 && b <= 47 || (a === 23 || a === 31) && b >= 33 && b <= 35)) return false;
|
|
818
|
+
const chNr = a === 20 || a === 21 || a === 23 ? 1 : 2;
|
|
819
|
+
const channel = this.channels[chNr];
|
|
820
|
+
if (a === 20 || a === 21 || a === 28 || a === 29) {
|
|
821
|
+
if (b === 32) channel.ccRCL();
|
|
822
|
+
else if (b === 33) channel.ccBS();
|
|
823
|
+
else if (b === 34) channel.ccAOF();
|
|
824
|
+
else if (b === 35) channel.ccAON();
|
|
825
|
+
else if (b === 36) channel.ccDER();
|
|
826
|
+
else if (b === 37) channel.ccRU(2);
|
|
827
|
+
else if (b === 38) channel.ccRU(3);
|
|
828
|
+
else if (b === 39) channel.ccRU(4);
|
|
829
|
+
else if (b === 40) channel.ccFON();
|
|
830
|
+
else if (b === 41) channel.ccRDC();
|
|
831
|
+
else if (b === 42) channel.ccTR();
|
|
832
|
+
else if (b === 43) channel.ccRTD();
|
|
833
|
+
else if (b === 44) channel.ccEDM();
|
|
834
|
+
else if (b === 45) channel.ccCR();
|
|
835
|
+
else if (b === 46) channel.ccENM();
|
|
836
|
+
else if (b === 47) channel.ccEOC();
|
|
837
|
+
} else channel.ccTO(b - 32);
|
|
838
|
+
this.currentChannel = chNr;
|
|
839
|
+
return true;
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Parse midrow styling command
|
|
843
|
+
*
|
|
844
|
+
* @param a - The first byte
|
|
845
|
+
* @param b - The second byte
|
|
846
|
+
* @returns `true` if midrow styling command was found
|
|
847
|
+
*/
|
|
848
|
+
parseMidrow(a, b) {
|
|
849
|
+
let chNr = 0;
|
|
850
|
+
if ((a === 17 || a === 25) && b >= 32 && b <= 47) {
|
|
851
|
+
if (a === 17) chNr = 1;
|
|
852
|
+
else chNr = 2;
|
|
853
|
+
if (chNr !== this.currentChannel) {
|
|
854
|
+
this.logger.log(VerboseLevel.ERROR, "Mismatch channel in midrow parsing");
|
|
855
|
+
return false;
|
|
856
|
+
}
|
|
857
|
+
const channel = this.channels[chNr];
|
|
858
|
+
if (!channel) return false;
|
|
859
|
+
channel.ccMIDROW(b);
|
|
860
|
+
this.logger.log(VerboseLevel.DEBUG, () => "MIDROW (" + numArrayToHexArray([a, b]) + ")");
|
|
861
|
+
return true;
|
|
862
|
+
}
|
|
863
|
+
return false;
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Parse Preable Access Codes (Table 53).
|
|
867
|
+
*
|
|
868
|
+
* @param a - The first byte
|
|
869
|
+
* @param b - The second byte
|
|
870
|
+
* @returns A Boolean that tells if PAC found
|
|
871
|
+
*/
|
|
872
|
+
parsePAC(a, b) {
|
|
873
|
+
let row;
|
|
874
|
+
if (!((a >= 17 && a <= 23 || a >= 25 && a <= 31) && b >= 64 && b <= 127 || (a === 16 || a === 24) && b >= 64 && b <= 95)) return false;
|
|
875
|
+
const chNr = a <= 23 ? 1 : 2;
|
|
876
|
+
if (b >= 64 && b <= 95) row = chNr === 1 ? rowsLowCh1[a] : rowsLowCh2[a];
|
|
877
|
+
else row = chNr === 1 ? rowsHighCh1[a] : rowsHighCh2[a];
|
|
878
|
+
const channel = this.channels[chNr];
|
|
879
|
+
if (!channel) return false;
|
|
880
|
+
channel.setPAC(this.interpretPAC(row, b));
|
|
881
|
+
this.currentChannel = chNr;
|
|
882
|
+
return true;
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* Interpret the second byte of the pac, and return the information.
|
|
886
|
+
*
|
|
887
|
+
* @param row - The row number
|
|
888
|
+
* @param byte - The second byte
|
|
889
|
+
* @returns pacData with style parameters
|
|
890
|
+
*/
|
|
891
|
+
interpretPAC(row, byte) {
|
|
892
|
+
let pacIndex;
|
|
893
|
+
const pacData = {
|
|
894
|
+
color: null,
|
|
895
|
+
italics: false,
|
|
896
|
+
indent: null,
|
|
897
|
+
underline: false,
|
|
898
|
+
row
|
|
899
|
+
};
|
|
900
|
+
if (byte > 95) pacIndex = byte - 96;
|
|
901
|
+
else pacIndex = byte - 64;
|
|
902
|
+
pacData.underline = (pacIndex & 1) === 1;
|
|
903
|
+
if (pacIndex <= 13) pacData.color = [
|
|
904
|
+
"white",
|
|
905
|
+
"green",
|
|
906
|
+
"blue",
|
|
907
|
+
"cyan",
|
|
908
|
+
"red",
|
|
909
|
+
"yellow",
|
|
910
|
+
"magenta",
|
|
911
|
+
"white"
|
|
912
|
+
][Math.floor(pacIndex / 2)];
|
|
913
|
+
else if (pacIndex <= 15) {
|
|
914
|
+
pacData.italics = true;
|
|
915
|
+
pacData.color = "white";
|
|
916
|
+
} else pacData.indent = Math.floor((pacIndex - 16) / 2) * 4;
|
|
917
|
+
return pacData;
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Parse characters.
|
|
921
|
+
*
|
|
922
|
+
* @param a - The first byte
|
|
923
|
+
* @param b - The second byte
|
|
924
|
+
* @returns An array with 1 to 2 codes corresponding to chars, if found. null otherwise.
|
|
925
|
+
*/
|
|
926
|
+
parseChars(a, b) {
|
|
927
|
+
let channelNr;
|
|
928
|
+
let charCodes = [];
|
|
929
|
+
let charCode1 = null;
|
|
930
|
+
if (a >= 25) {
|
|
931
|
+
channelNr = 2;
|
|
932
|
+
charCode1 = a - 8;
|
|
933
|
+
} else {
|
|
934
|
+
channelNr = 1;
|
|
935
|
+
charCode1 = a;
|
|
936
|
+
}
|
|
937
|
+
if (charCode1 >= 17 && charCode1 <= 19) {
|
|
938
|
+
let oneCode;
|
|
939
|
+
if (charCode1 === 17) oneCode = b + 80;
|
|
940
|
+
else if (charCode1 === 18) oneCode = b + 112;
|
|
941
|
+
else oneCode = b + 144;
|
|
942
|
+
this.logger.log(VerboseLevel.INFO, () => "Special char '" + getCharForByte(oneCode) + "' in channel " + channelNr);
|
|
943
|
+
charCodes = [oneCode];
|
|
944
|
+
} else if (a >= 32 && a <= 127) charCodes = b === 0 ? [a] : [a, b];
|
|
945
|
+
if (charCodes) this.logger.log(VerboseLevel.DEBUG, () => "Char codes = " + numArrayToHexArray(charCodes).join(","));
|
|
946
|
+
return charCodes;
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* Parse extended background attributes as well as new foreground color black.
|
|
950
|
+
*
|
|
951
|
+
* @param a - The first byte
|
|
952
|
+
* @param b - The second byte
|
|
953
|
+
* @returns True if background attributes are found
|
|
954
|
+
*/
|
|
955
|
+
parseBackgroundAttributes(a, b) {
|
|
956
|
+
if (!((a === 16 || a === 24) && b >= 32 && b <= 47 || (a === 23 || a === 31) && b >= 45 && b <= 47)) return false;
|
|
957
|
+
let index;
|
|
958
|
+
const bkgData = {};
|
|
959
|
+
if (a === 16 || a === 24) {
|
|
960
|
+
index = Math.floor((b - 32) / 2);
|
|
961
|
+
bkgData.background = backgroundColors[index];
|
|
962
|
+
if (b % 2 === 1) bkgData.background = bkgData.background + "_semi";
|
|
963
|
+
} else if (b === 45) bkgData.background = "transparent";
|
|
964
|
+
else {
|
|
965
|
+
bkgData.foreground = "black";
|
|
966
|
+
if (b === 47) bkgData.underline = true;
|
|
967
|
+
}
|
|
968
|
+
const chNr = a <= 23 ? 1 : 2;
|
|
969
|
+
this.channels[chNr].setBkgData(bkgData);
|
|
970
|
+
return true;
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* Reset state of parser and its channels.
|
|
974
|
+
*/
|
|
975
|
+
reset() {
|
|
976
|
+
for (let i = 0; i < Object.keys(this.channels).length; i++) {
|
|
977
|
+
const channel = this.channels[i];
|
|
978
|
+
if (channel) channel.reset();
|
|
979
|
+
}
|
|
980
|
+
setLastCmd(null, null, this.cmdHistory);
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* Trigger the generation of a cue, and the start of a new one if displayScreens are not empty.
|
|
984
|
+
*/
|
|
985
|
+
cueSplitAtTime(t) {
|
|
986
|
+
for (let i = 0; i < this.channels.length; i++) {
|
|
987
|
+
const channel = this.channels[i];
|
|
988
|
+
if (channel) channel.cueSplitAtTime(t);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
|
|
993
|
+
//#endregion
|
|
994
|
+
//#region src/extractCta608Data.ts
|
|
995
|
+
/**
|
|
996
|
+
* Extract CTA-608 data from a DataView
|
|
997
|
+
*
|
|
998
|
+
* @param raw - The DataView to extract the data from
|
|
999
|
+
* @param cta608Range - The range of the CTA-608 data
|
|
1000
|
+
* @returns The extracted CTA-608 data
|
|
1001
|
+
*
|
|
1002
|
+
* @beta
|
|
1003
|
+
*/
|
|
1004
|
+
function extractCta608Data(raw, cta608Range) {
|
|
1005
|
+
let pos = cta608Range[0];
|
|
1006
|
+
const fieldData = [[], []];
|
|
1007
|
+
pos += 8;
|
|
1008
|
+
const ccCount = raw.getUint8(pos) & 31;
|
|
1009
|
+
pos += 2;
|
|
1010
|
+
for (let i = 0; i < ccCount; i++) {
|
|
1011
|
+
const byte = raw.getUint8(pos);
|
|
1012
|
+
const ccValid = byte & 4;
|
|
1013
|
+
const ccType = byte & 3;
|
|
1014
|
+
pos++;
|
|
1015
|
+
const ccData1 = raw.getUint8(pos);
|
|
1016
|
+
pos++;
|
|
1017
|
+
const ccData2 = raw.getUint8(pos);
|
|
1018
|
+
pos++;
|
|
1019
|
+
if (ccValid && (ccData1 & 127) + (ccData2 & 127) !== 0) {
|
|
1020
|
+
if (ccType === 0) {
|
|
1021
|
+
fieldData[0].push(ccData1);
|
|
1022
|
+
fieldData[0].push(ccData2);
|
|
1023
|
+
} else if (ccType === 1) {
|
|
1024
|
+
fieldData[1].push(ccData1);
|
|
1025
|
+
fieldData[1].push(ccData2);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
return fieldData;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
//#endregion
|
|
1033
|
+
//#region src/findCta608Nalus.ts
|
|
1034
|
+
/**
|
|
1035
|
+
* Find CTA-608 NAL units in a video stream
|
|
1036
|
+
*
|
|
1037
|
+
* @param raw - The DataView to extract the data from
|
|
1038
|
+
* @param startPos - The start position of the data
|
|
1039
|
+
* @param size - The size of the data
|
|
1040
|
+
* @returns The extracted CTA-608 NAL units
|
|
1041
|
+
*
|
|
1042
|
+
* @beta
|
|
1043
|
+
*/
|
|
1044
|
+
function findCta608Nalus(raw, startPos, size) {
|
|
1045
|
+
let nalSize = 0, cursor = startPos, nalType = 0;
|
|
1046
|
+
const cta608NaluRanges = [];
|
|
1047
|
+
const isCTA608SEI = (payloadType, payloadSize, raw$1, pos) => {
|
|
1048
|
+
if (payloadType !== 4 || payloadSize < 8) return null;
|
|
1049
|
+
const countryCode = raw$1.getUint8(pos);
|
|
1050
|
+
const providerCode = raw$1.getUint16(pos + 1);
|
|
1051
|
+
const userIdentifier = raw$1.getUint32(pos + 3);
|
|
1052
|
+
const userDataTypeCode = raw$1.getUint8(pos + 7);
|
|
1053
|
+
return countryCode == 181 && providerCode == 49 && userIdentifier == 1195456820 && userDataTypeCode == 3;
|
|
1054
|
+
};
|
|
1055
|
+
while (cursor < startPos + size) {
|
|
1056
|
+
nalSize = raw.getUint32(cursor);
|
|
1057
|
+
nalType = raw.getUint8(cursor + 4) & 31;
|
|
1058
|
+
if (nalType === 6) {
|
|
1059
|
+
let pos = cursor + 5;
|
|
1060
|
+
let payloadType = -1;
|
|
1061
|
+
while (pos < cursor + 4 + nalSize - 1) {
|
|
1062
|
+
payloadType = 0;
|
|
1063
|
+
let b = 255;
|
|
1064
|
+
while (b === 255) {
|
|
1065
|
+
b = raw.getUint8(pos);
|
|
1066
|
+
payloadType += b;
|
|
1067
|
+
pos++;
|
|
1068
|
+
}
|
|
1069
|
+
let payloadSize = 0;
|
|
1070
|
+
b = 255;
|
|
1071
|
+
while (b === 255) {
|
|
1072
|
+
b = raw.getUint8(pos);
|
|
1073
|
+
payloadSize += b;
|
|
1074
|
+
pos++;
|
|
1075
|
+
}
|
|
1076
|
+
if (isCTA608SEI(payloadType, payloadSize, raw, pos)) cta608NaluRanges.push([pos, payloadSize]);
|
|
1077
|
+
pos += payloadSize;
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
cursor += nalSize + 4;
|
|
1081
|
+
}
|
|
1082
|
+
return cta608NaluRanges;
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
//#endregion
|
|
1086
|
+
//#region src/SccParser.ts
|
|
1087
|
+
/**
|
|
1088
|
+
* The copyright in this software is being made available under the BSD License,
|
|
1089
|
+
* included below. This software may be subject to other third party and contributor
|
|
1090
|
+
* rights, including patent rights, and no such rights are granted under this license.
|
|
1091
|
+
*
|
|
1092
|
+
* Copyright (c) 2015-2016, DASH Industry Forum.
|
|
1093
|
+
* All rights reserved.
|
|
1094
|
+
*
|
|
1095
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
|
1096
|
+
* are permitted provided that the following conditions are met:
|
|
1097
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
1098
|
+
* list of conditions and the following disclaimer.
|
|
1099
|
+
* * Redistributions in binary form must reproduce the above copyright notice,
|
|
1100
|
+
* this list of conditions and the following disclaimer in the documentation and/or
|
|
1101
|
+
* other materials provided with the distribution.
|
|
1102
|
+
* 2. Neither the name of Dash Industry Forum nor the names of its
|
|
1103
|
+
* contributors may be used to endorse or promote products derived from this software
|
|
1104
|
+
* without specific prior written permission.
|
|
1105
|
+
*
|
|
1106
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
|
|
1107
|
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
1108
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
1109
|
+
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
1110
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
1111
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
1112
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
1113
|
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
1114
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
1115
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
|
1116
|
+
*/
|
|
1117
|
+
/**
|
|
1118
|
+
* SCC Parser
|
|
1119
|
+
*
|
|
1120
|
+
* @beta
|
|
1121
|
+
*/
|
|
1122
|
+
var SccParser = class {
|
|
1123
|
+
constructor(processor, field = 1) {
|
|
1124
|
+
this.hasHeader = false;
|
|
1125
|
+
this.nrLinesParsed = 0;
|
|
1126
|
+
this.processor = processor;
|
|
1127
|
+
this.field = field;
|
|
1128
|
+
}
|
|
1129
|
+
parse(text) {
|
|
1130
|
+
const lines = text.split(/\r?\n/);
|
|
1131
|
+
this.nrLinesParsed = 0;
|
|
1132
|
+
if (lines[0] === "Scenarist_SCC V1.0") {
|
|
1133
|
+
this.hasHeader = true;
|
|
1134
|
+
this.nrLinesParsed++;
|
|
1135
|
+
}
|
|
1136
|
+
for (let l = 1; l < lines.length; l += 2) {
|
|
1137
|
+
if (lines[l] !== "") break;
|
|
1138
|
+
this.nrLinesParsed++;
|
|
1139
|
+
const lineData = this.parseDataLine(lines[l + 1]);
|
|
1140
|
+
if (lineData === null) break;
|
|
1141
|
+
this.nrLinesParsed++;
|
|
1142
|
+
this.processor.addData(lineData[0], lineData[1]);
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
parseDataLine(line) {
|
|
1146
|
+
if (!line) return null;
|
|
1147
|
+
const lineParts = line.split(/\s+/);
|
|
1148
|
+
const timeData = lineParts[0];
|
|
1149
|
+
const ceaData = [];
|
|
1150
|
+
for (let i = 1; i < lineParts.length; i++) {
|
|
1151
|
+
const fourHexChars = lineParts[i];
|
|
1152
|
+
const a = parseInt(fourHexChars.substring(0, 2), 16);
|
|
1153
|
+
const b = parseInt(fourHexChars.substring(2, 4), 16);
|
|
1154
|
+
ceaData.push(a, b);
|
|
1155
|
+
}
|
|
1156
|
+
return [this.timeConverter(timeData), ceaData];
|
|
1157
|
+
}
|
|
1158
|
+
timeConverter(smpteTs) {
|
|
1159
|
+
const parts = smpteTs.split(":");
|
|
1160
|
+
if (parts.length === 3) {
|
|
1161
|
+
const lastParts = parts[2].split(";");
|
|
1162
|
+
parts[2] = lastParts[0];
|
|
1163
|
+
const frames = parseInt(lastParts[1], 10);
|
|
1164
|
+
return (30 * (60 * (60 * parseInt(parts[0], 10) + parseInt(parts[1], 10)) + parseInt(parts[2], 10)) + frames) * 1001 / 3e4;
|
|
1165
|
+
}
|
|
1166
|
+
return 0;
|
|
1167
|
+
}
|
|
1168
|
+
getHeaderStatus() {
|
|
1169
|
+
return this.hasHeader;
|
|
1170
|
+
}
|
|
1171
|
+
getField() {
|
|
1172
|
+
return this.field;
|
|
1173
|
+
}
|
|
1174
|
+
getLinesParsed() {
|
|
1175
|
+
return this.nrLinesParsed;
|
|
1176
|
+
}
|
|
1177
|
+
};
|
|
1178
|
+
|
|
1179
|
+
//#endregion
|
|
1180
|
+
export { CaptionScreen, CaptionsLogger, Cta608Channel, Cta608Parser, PenState, Row, SccParser, StyledUnicodeChar, VerboseLevel, extractCta608Data, findCta608Nalus };
|
|
16
1181
|
//# sourceMappingURL=index.js.map
|