@svta/cml-608 0.19.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.
Files changed (145) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +59 -0
  3. package/dist/CaptionModes.d.ts +7 -0
  4. package/dist/CaptionModes.d.ts.map +1 -0
  5. package/dist/CaptionModes.js +2 -0
  6. package/dist/CaptionModes.js.map +1 -0
  7. package/dist/CaptionScreen.d.ts +80 -0
  8. package/dist/CaptionScreen.d.ts.map +1 -0
  9. package/dist/CaptionScreen.js +220 -0
  10. package/dist/CaptionScreen.js.map +1 -0
  11. package/dist/CaptionsLogger.d.ts +49 -0
  12. package/dist/CaptionsLogger.d.ts.map +1 -0
  13. package/dist/CaptionsLogger.js +56 -0
  14. package/dist/CaptionsLogger.js.map +1 -0
  15. package/dist/Channels.d.ts +7 -0
  16. package/dist/Channels.d.ts.map +1 -0
  17. package/dist/Channels.js +2 -0
  18. package/dist/Channels.js.map +1 -0
  19. package/dist/CmdHistory.d.ts +10 -0
  20. package/dist/CmdHistory.d.ts.map +1 -0
  21. package/dist/CmdHistory.js +2 -0
  22. package/dist/CmdHistory.js.map +1 -0
  23. package/dist/Cta608Channel.d.ts +88 -0
  24. package/dist/Cta608Channel.d.ts.map +1 -0
  25. package/dist/Cta608Channel.js +262 -0
  26. package/dist/Cta608Channel.js.map +1 -0
  27. package/dist/Cta608Parser.d.ts +115 -0
  28. package/dist/Cta608Parser.d.ts.map +1 -0
  29. package/dist/Cta608Parser.js +428 -0
  30. package/dist/Cta608Parser.js.map +1 -0
  31. package/dist/CueHandler.d.ts +12 -0
  32. package/dist/CueHandler.d.ts.map +1 -0
  33. package/dist/CueHandler.js +2 -0
  34. package/dist/CueHandler.js.map +1 -0
  35. package/dist/PACData.d.ts +13 -0
  36. package/dist/PACData.d.ts.map +1 -0
  37. package/dist/PACData.js +2 -0
  38. package/dist/PACData.js.map +1 -0
  39. package/dist/PenState.d.ts +56 -0
  40. package/dist/PenState.d.ts.map +1 -0
  41. package/dist/PenState.js +95 -0
  42. package/dist/PenState.js.map +1 -0
  43. package/dist/PenStyles.d.ts +13 -0
  44. package/dist/PenStyles.d.ts.map +1 -0
  45. package/dist/PenStyles.js +2 -0
  46. package/dist/PenStyles.js.map +1 -0
  47. package/dist/Row.d.ts +75 -0
  48. package/dist/Row.d.ts.map +1 -0
  49. package/dist/Row.js +174 -0
  50. package/dist/Row.js.map +1 -0
  51. package/dist/SccParser.d.ts +49 -0
  52. package/dist/SccParser.d.ts.map +1 -0
  53. package/dist/SccParser.js +99 -0
  54. package/dist/SccParser.js.map +1 -0
  55. package/dist/StyledUnicodeChar.d.ts +54 -0
  56. package/dist/StyledUnicodeChar.d.ts.map +1 -0
  57. package/dist/StyledUnicodeChar.js +71 -0
  58. package/dist/StyledUnicodeChar.js.map +1 -0
  59. package/dist/SupportedField.d.ts +7 -0
  60. package/dist/SupportedField.d.ts.map +1 -0
  61. package/dist/SupportedField.js +2 -0
  62. package/dist/SupportedField.js.map +1 -0
  63. package/dist/VerboseLevel.d.ts +22 -0
  64. package/dist/VerboseLevel.d.ts.map +1 -0
  65. package/dist/VerboseLevel.js +17 -0
  66. package/dist/VerboseLevel.js.map +1 -0
  67. package/dist/extractCta608Data.d.ts +11 -0
  68. package/dist/extractCta608Data.d.ts.map +1 -0
  69. package/dist/extractCta608Data.js +38 -0
  70. package/dist/extractCta608Data.js.map +1 -0
  71. package/dist/extractCta608DataFromSample.d.ts +12 -0
  72. package/dist/extractCta608DataFromSample.d.ts.map +1 -0
  73. package/dist/extractCta608DataFromSample.js +35 -0
  74. package/dist/extractCta608DataFromSample.js.map +1 -0
  75. package/dist/findCta608Nalus.d.ts +12 -0
  76. package/dist/findCta608Nalus.d.ts.map +1 -0
  77. package/dist/findCta608Nalus.js +60 -0
  78. package/dist/findCta608Nalus.js.map +1 -0
  79. package/dist/index.d.ts +22 -0
  80. package/dist/index.d.ts.map +1 -0
  81. package/dist/index.js +16 -0
  82. package/dist/index.js.map +1 -0
  83. package/dist/tsconfig.tsbuildinfo +1 -0
  84. package/dist/tsdoc-metadata.json +11 -0
  85. package/dist/utils/NR_COLS.d.ts +2 -0
  86. package/dist/utils/NR_COLS.d.ts.map +1 -0
  87. package/dist/utils/NR_COLS.js +2 -0
  88. package/dist/utils/NR_COLS.js.map +1 -0
  89. package/dist/utils/NR_ROWS.d.ts +2 -0
  90. package/dist/utils/NR_ROWS.d.ts.map +1 -0
  91. package/dist/utils/NR_ROWS.js +2 -0
  92. package/dist/utils/NR_ROWS.js.map +1 -0
  93. package/dist/utils/backgroundColors.d.ts +2 -0
  94. package/dist/utils/backgroundColors.d.ts.map +1 -0
  95. package/dist/utils/backgroundColors.js +12 -0
  96. package/dist/utils/backgroundColors.js.map +1 -0
  97. package/dist/utils/createCmdHistory.d.ts +3 -0
  98. package/dist/utils/createCmdHistory.d.ts.map +1 -0
  99. package/dist/utils/createCmdHistory.js +7 -0
  100. package/dist/utils/createCmdHistory.js.map +1 -0
  101. package/dist/utils/getCharForByte.d.ts +2 -0
  102. package/dist/utils/getCharForByte.d.ts.map +1 -0
  103. package/dist/utils/getCharForByte.js +6 -0
  104. package/dist/utils/getCharForByte.js.map +1 -0
  105. package/dist/utils/hasCmdRepeated.d.ts +3 -0
  106. package/dist/utils/hasCmdRepeated.d.ts.map +1 -0
  107. package/dist/utils/hasCmdRepeated.js +4 -0
  108. package/dist/utils/hasCmdRepeated.js.map +1 -0
  109. package/dist/utils/index.d.ts +20 -0
  110. package/dist/utils/index.d.ts.map +1 -0
  111. package/dist/utils/index.js +20 -0
  112. package/dist/utils/index.js.map +1 -0
  113. package/dist/utils/numArrayToHexArray.d.ts +2 -0
  114. package/dist/utils/numArrayToHexArray.d.ts.map +1 -0
  115. package/dist/utils/numArrayToHexArray.js +9 -0
  116. package/dist/utils/numArrayToHexArray.js.map +1 -0
  117. package/dist/utils/rowsHighCh1.d.ts +4 -0
  118. package/dist/utils/rowsHighCh1.d.ts.map +1 -0
  119. package/dist/utils/rowsHighCh1.js +10 -0
  120. package/dist/utils/rowsHighCh1.js.map +1 -0
  121. package/dist/utils/rowsHighCh2.d.ts +4 -0
  122. package/dist/utils/rowsHighCh2.d.ts.map +1 -0
  123. package/dist/utils/rowsHighCh2.js +10 -0
  124. package/dist/utils/rowsHighCh2.js.map +1 -0
  125. package/dist/utils/rowsLowCh1.d.ts +4 -0
  126. package/dist/utils/rowsLowCh1.d.ts.map +1 -0
  127. package/dist/utils/rowsLowCh1.js +12 -0
  128. package/dist/utils/rowsLowCh1.js.map +1 -0
  129. package/dist/utils/rowsLowCh2.d.ts +4 -0
  130. package/dist/utils/rowsLowCh2.d.ts.map +1 -0
  131. package/dist/utils/rowsLowCh2.js +11 -0
  132. package/dist/utils/rowsLowCh2.js.map +1 -0
  133. package/dist/utils/seiHelpers.d.ts +7 -0
  134. package/dist/utils/seiHelpers.d.ts.map +1 -0
  135. package/dist/utils/seiHelpers.js +78 -0
  136. package/dist/utils/seiHelpers.js.map +1 -0
  137. package/dist/utils/setLastCmd.d.ts +3 -0
  138. package/dist/utils/setLastCmd.d.ts.map +1 -0
  139. package/dist/utils/setLastCmd.js +5 -0
  140. package/dist/utils/setLastCmd.js.map +1 -0
  141. package/dist/utils/specialCea608CharsCodes.d.ts +7 -0
  142. package/dist/utils/specialCea608CharsCodes.d.ts.map +1 -0
  143. package/dist/utils/specialCea608CharsCodes.js +103 -0
  144. package/dist/utils/specialCea608CharsCodes.js.map +1 -0
  145. package/package.json +80 -0
@@ -0,0 +1,115 @@
1
+ /**
2
+ *
3
+ * This code was ported from the dash.js project at:
4
+ * https://github.com/Dash-Industry-Forum/dash.js/blob/development/externals/cea608-parser.js
5
+ * https://github.com/Dash-Industry-Forum/dash.js/commit/8269b26a761e0853bb21d78780ed945144ecdd4d#diff-71bc295a2d6b6b7093a1d3290d53a4b2
6
+ *
7
+ * The original copyright appears below:
8
+ *
9
+ * The copyright in this software is being made available under the BSD License,
10
+ * included below. This software may be subject to other third party and contributor
11
+ * rights, including patent rights, and no such rights are granted under this license.
12
+ *
13
+ * Copyright (c) 2015-2016, DASH Industry Forum.
14
+ * All rights reserved.
15
+ *
16
+ * Redistribution and use in source and binary forms, with or without modification,
17
+ * are permitted provided that the following conditions are met:
18
+ * 1. Redistributions of source code must retain the above copyright notice, this
19
+ * list of conditions and the following disclaimer.
20
+ * * Redistributions in binary form must reproduce the above copyright notice,
21
+ * this list of conditions and the following disclaimer in the documentation and/or
22
+ * other materials provided with the distribution.
23
+ * 2. Neither the name of Dash Industry Forum nor the names of its
24
+ * contributors may be used to endorse or promote products derived from this software
25
+ * without specific prior written permission.
26
+ *
27
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
28
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
31
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
34
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
+ * POSSIBILITY OF SUCH DAMAGE.
37
+ */
38
+ import type { SupportedField } from './SupportedField.js';
39
+ /**
40
+ * CEA-608 caption parser.
41
+ *
42
+ * @beta
43
+ */
44
+ export declare class Cta608Parser {
45
+ private channels;
46
+ private currentChannel;
47
+ private cmdHistory;
48
+ private logger;
49
+ private lastTime;
50
+ constructor(field: SupportedField, out1: any, out2: any);
51
+ /**
52
+ * Add data for time t in forms of list of bytes (unsigned ints). The bytes are treated as pairs.
53
+ *
54
+ * @param time - The time in milliseconds
55
+ * @param byteList - The list of bytes
56
+ */
57
+ addData(time: number | null, byteList: number[]): void;
58
+ /**
59
+ * Parse Command.
60
+ *
61
+ * @param a - The first byte
62
+ * @param b - The second byte
63
+ * @returns True if a command was found
64
+ */
65
+ private parseCmd;
66
+ /**
67
+ * Parse midrow styling command
68
+ *
69
+ * @param a - The first byte
70
+ * @param b - The second byte
71
+ * @returns `true` if midrow styling command was found
72
+ */
73
+ private parseMidrow;
74
+ /**
75
+ * Parse Preable Access Codes (Table 53).
76
+ *
77
+ * @param a - The first byte
78
+ * @param b - The second byte
79
+ * @returns A Boolean that tells if PAC found
80
+ */
81
+ private parsePAC;
82
+ /**
83
+ * Interpret the second byte of the pac, and return the information.
84
+ *
85
+ * @param row - The row number
86
+ * @param byte - The second byte
87
+ * @returns pacData with style parameters
88
+ */
89
+ private interpretPAC;
90
+ /**
91
+ * Parse characters.
92
+ *
93
+ * @param a - The first byte
94
+ * @param b - The second byte
95
+ * @returns An array with 1 to 2 codes corresponding to chars, if found. null otherwise.
96
+ */
97
+ private parseChars;
98
+ /**
99
+ * Parse extended background attributes as well as new foreground color black.
100
+ *
101
+ * @param a - The first byte
102
+ * @param b - The second byte
103
+ * @returns True if background attributes are found
104
+ */
105
+ private parseBackgroundAttributes;
106
+ /**
107
+ * Reset state of parser and its channels.
108
+ */
109
+ reset(): void;
110
+ /**
111
+ * Trigger the generation of a cue, and the start of a new one if displayScreens are not empty.
112
+ */
113
+ cueSplitAtTime(t: number): void;
114
+ }
115
+ //# sourceMappingURL=Cta608Parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Cta608Parser.d.ts","sourceRoot":"","sources":["../src/Cta608Parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAQH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAa1D;;;;GAIG;AACH,qBAAa,YAAY;IACxB,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,cAAc,CAAe;IACrC,OAAO,CAAC,UAAU,CAAkC;IACpD,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,QAAQ,CAAuB;gBAE3B,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG;IASvD;;;;;OAKG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI;IA8FtD;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IAyEhB;;;;;;OAMG;IACH,OAAO,CAAC,WAAW;IAgCnB;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IA8BhB;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;IAwCpB;;;;;;OAMG;IACH,OAAO,CAAC,UAAU;IAgDlB;;;;;;OAMG;IACH,OAAO,CAAC,yBAAyB;IA8BjC;;OAEG;IACH,KAAK,IAAI,IAAI;IAUb;;OAEG;IACH,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;CAQ/B"}
@@ -0,0 +1,428 @@
1
+ /**
2
+ *
3
+ * This code was ported from the dash.js project at:
4
+ * https://github.com/Dash-Industry-Forum/dash.js/blob/development/externals/cea608-parser.js
5
+ * https://github.com/Dash-Industry-Forum/dash.js/commit/8269b26a761e0853bb21d78780ed945144ecdd4d#diff-71bc295a2d6b6b7093a1d3290d53a4b2
6
+ *
7
+ * The original copyright appears below:
8
+ *
9
+ * The copyright in this software is being made available under the BSD License,
10
+ * included below. This software may be subject to other third party and contributor
11
+ * rights, including patent rights, and no such rights are granted under this license.
12
+ *
13
+ * Copyright (c) 2015-2016, DASH Industry Forum.
14
+ * All rights reserved.
15
+ *
16
+ * Redistribution and use in source and binary forms, with or without modification,
17
+ * are permitted provided that the following conditions are met:
18
+ * 1. Redistributions of source code must retain the above copyright notice, this
19
+ * list of conditions and the following disclaimer.
20
+ * * Redistributions in binary form must reproduce the above copyright notice,
21
+ * this list of conditions and the following disclaimer in the documentation and/or
22
+ * other materials provided with the distribution.
23
+ * 2. Neither the name of Dash Industry Forum nor the names of its
24
+ * contributors may be used to endorse or promote products derived from this software
25
+ * without specific prior written permission.
26
+ *
27
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
28
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
31
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
34
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
+ * POSSIBILITY OF SUCH DAMAGE.
37
+ */
38
+ import { CaptionsLogger } from './CaptionsLogger.js';
39
+ import { Cta608Channel } from './Cta608Channel.js';
40
+ import { VerboseLevel } from './VerboseLevel.js';
41
+ import { backgroundColors } from './utils/backgroundColors.js';
42
+ import { createCmdHistory } from './utils/createCmdHistory.js';
43
+ import { getCharForByte } from './utils/getCharForByte.js';
44
+ import { hasCmdRepeated } from './utils/hasCmdRepeated.js';
45
+ import { numArrayToHexArray } from './utils/numArrayToHexArray.js';
46
+ import { rowsHighCh1 } from './utils/rowsHighCh1.js';
47
+ import { rowsHighCh2 } from './utils/rowsHighCh2.js';
48
+ import { rowsLowCh1 } from './utils/rowsLowCh1.js';
49
+ import { rowsLowCh2 } from './utils/rowsLowCh2.js';
50
+ import { setLastCmd } from './utils/setLastCmd.js';
51
+ /**
52
+ * CEA-608 caption parser.
53
+ *
54
+ * @beta
55
+ */
56
+ export class Cta608Parser {
57
+ constructor(field, out1, out2) {
58
+ this.currentChannel = 0;
59
+ this.cmdHistory = createCmdHistory();
60
+ this.lastTime = null;
61
+ const logger = (this.logger = new CaptionsLogger());
62
+ this.channels = [
63
+ null,
64
+ new Cta608Channel(field, out1, logger),
65
+ new Cta608Channel(field + 1, out2, logger),
66
+ ];
67
+ }
68
+ /**
69
+ * Add data for time t in forms of list of bytes (unsigned ints). The bytes are treated as pairs.
70
+ *
71
+ * @param time - The time in milliseconds
72
+ * @param byteList - The list of bytes
73
+ */
74
+ addData(time, byteList) {
75
+ this.lastTime = time;
76
+ this.logger.time = time;
77
+ for (let i = 0; i < byteList.length; i += 2) {
78
+ const a = byteList[i] & 0x7f;
79
+ const b = byteList[i + 1] & 0x7f;
80
+ let cmdFound = false;
81
+ let charsFound = null;
82
+ if (this.lastTime !== null) {
83
+ time = this.lastTime + 0.5 * i * 1001 / 30000;
84
+ this.logger.time = time;
85
+ }
86
+ if (a === 0 && b === 0) {
87
+ continue;
88
+ }
89
+ else {
90
+ this.logger.log(VerboseLevel.DATA, () => '[' +
91
+ numArrayToHexArray([byteList[i], byteList[i + 1]]) +
92
+ '] -> (' +
93
+ numArrayToHexArray([a, b]) +
94
+ ')');
95
+ }
96
+ const cmdHistory = this.cmdHistory;
97
+ const isControlCode = a >= 0x10 && a <= 0x1f;
98
+ if (isControlCode) {
99
+ // Skip redundant control codes
100
+ if (hasCmdRepeated(a, b, cmdHistory)) {
101
+ setLastCmd(null, null, cmdHistory);
102
+ this.logger.log(VerboseLevel.DEBUG, () => 'Repeated command (' +
103
+ numArrayToHexArray([a, b]) +
104
+ ') is dropped');
105
+ continue;
106
+ }
107
+ setLastCmd(a, b, this.cmdHistory);
108
+ cmdFound = this.parseCmd(a, b);
109
+ if (!cmdFound) {
110
+ cmdFound = this.parseMidrow(a, b);
111
+ }
112
+ if (!cmdFound) {
113
+ cmdFound = this.parsePAC(a, b);
114
+ }
115
+ if (!cmdFound) {
116
+ cmdFound = this.parseBackgroundAttributes(a, b);
117
+ }
118
+ }
119
+ else {
120
+ setLastCmd(null, null, cmdHistory);
121
+ }
122
+ if (!cmdFound) {
123
+ charsFound = this.parseChars(a, b);
124
+ if (charsFound.length) {
125
+ const currChNr = this.currentChannel;
126
+ if (currChNr && currChNr > 0) {
127
+ const channel = this.channels[currChNr];
128
+ channel.insertChars(charsFound);
129
+ }
130
+ else {
131
+ this.logger.log(VerboseLevel.WARNING, 'No channel found yet. TEXT-MODE?');
132
+ }
133
+ }
134
+ }
135
+ if (!cmdFound && !charsFound) {
136
+ this.logger.log(VerboseLevel.WARNING, () => "Couldn't parse cleaned data " +
137
+ numArrayToHexArray([a, b]) +
138
+ ' orig: ' +
139
+ numArrayToHexArray([byteList[i], byteList[i + 1]]));
140
+ }
141
+ }
142
+ }
143
+ /**
144
+ * Parse Command.
145
+ *
146
+ * @param a - The first byte
147
+ * @param b - The second byte
148
+ * @returns True if a command was found
149
+ */
150
+ parseCmd(a, b) {
151
+ const cond1 = (a === 0x14 || a === 0x1c || a === 0x15 || a === 0x1d) &&
152
+ b >= 0x20 &&
153
+ b <= 0x2f;
154
+ const cond2 = (a === 0x17 || a === 0x1f) && b >= 0x21 && b <= 0x23;
155
+ if (!(cond1 || cond2)) {
156
+ return false;
157
+ }
158
+ const chNr = a === 0x14 || a === 0x15 || a === 0x17 ? 1 : 2;
159
+ const channel = this.channels[chNr];
160
+ if (a === 0x14 || a === 0x15 || a === 0x1c || a === 0x1d) {
161
+ if (b === 0x20) {
162
+ channel.ccRCL();
163
+ }
164
+ else if (b === 0x21) {
165
+ channel.ccBS();
166
+ }
167
+ else if (b === 0x22) {
168
+ channel.ccAOF();
169
+ }
170
+ else if (b === 0x23) {
171
+ channel.ccAON();
172
+ }
173
+ else if (b === 0x24) {
174
+ channel.ccDER();
175
+ }
176
+ else if (b === 0x25) {
177
+ channel.ccRU(2);
178
+ }
179
+ else if (b === 0x26) {
180
+ channel.ccRU(3);
181
+ }
182
+ else if (b === 0x27) {
183
+ channel.ccRU(4);
184
+ }
185
+ else if (b === 0x28) {
186
+ channel.ccFON();
187
+ }
188
+ else if (b === 0x29) {
189
+ channel.ccRDC();
190
+ }
191
+ else if (b === 0x2a) {
192
+ channel.ccTR();
193
+ }
194
+ else if (b === 0x2b) {
195
+ channel.ccRTD();
196
+ }
197
+ else if (b === 0x2c) {
198
+ channel.ccEDM();
199
+ }
200
+ else if (b === 0x2d) {
201
+ channel.ccCR();
202
+ }
203
+ else if (b === 0x2e) {
204
+ channel.ccENM();
205
+ }
206
+ else if (b === 0x2f) {
207
+ channel.ccEOC();
208
+ }
209
+ }
210
+ else {
211
+ // a == 0x17 || a == 0x1F
212
+ channel.ccTO(b - 0x20);
213
+ }
214
+ this.currentChannel = chNr;
215
+ return true;
216
+ }
217
+ /**
218
+ * Parse midrow styling command
219
+ *
220
+ * @param a - The first byte
221
+ * @param b - The second byte
222
+ * @returns `true` if midrow styling command was found
223
+ */
224
+ parseMidrow(a, b) {
225
+ let chNr = 0;
226
+ if ((a === 0x11 || a === 0x19) && b >= 0x20 && b <= 0x2f) {
227
+ if (a === 0x11) {
228
+ chNr = 1;
229
+ }
230
+ else {
231
+ chNr = 2;
232
+ }
233
+ if (chNr !== this.currentChannel) {
234
+ this.logger.log(VerboseLevel.ERROR, 'Mismatch channel in midrow parsing');
235
+ return false;
236
+ }
237
+ const channel = this.channels[chNr];
238
+ if (!channel) {
239
+ return false;
240
+ }
241
+ channel.ccMIDROW(b);
242
+ this.logger.log(VerboseLevel.DEBUG, () => 'MIDROW (' + numArrayToHexArray([a, b]) + ')');
243
+ return true;
244
+ }
245
+ return false;
246
+ }
247
+ /**
248
+ * Parse Preable Access Codes (Table 53).
249
+ *
250
+ * @param a - The first byte
251
+ * @param b - The second byte
252
+ * @returns A Boolean that tells if PAC found
253
+ */
254
+ parsePAC(a, b) {
255
+ let row;
256
+ const case1 = ((a >= 0x11 && a <= 0x17) || (a >= 0x19 && a <= 0x1f)) &&
257
+ b >= 0x40 &&
258
+ b <= 0x7f;
259
+ const case2 = (a === 0x10 || a === 0x18) && b >= 0x40 && b <= 0x5f;
260
+ if (!(case1 || case2)) {
261
+ return false;
262
+ }
263
+ const chNr = a <= 0x17 ? 1 : 2;
264
+ if (b >= 0x40 && b <= 0x5f) {
265
+ row = chNr === 1 ? rowsLowCh1[a] : rowsLowCh2[a];
266
+ }
267
+ else {
268
+ // 0x60 <= b <= 0x7F
269
+ row = chNr === 1 ? rowsHighCh1[a] : rowsHighCh2[a];
270
+ }
271
+ const channel = this.channels[chNr];
272
+ if (!channel) {
273
+ return false;
274
+ }
275
+ channel.setPAC(this.interpretPAC(row, b));
276
+ this.currentChannel = chNr;
277
+ return true;
278
+ }
279
+ /**
280
+ * Interpret the second byte of the pac, and return the information.
281
+ *
282
+ * @param row - The row number
283
+ * @param byte - The second byte
284
+ * @returns pacData with style parameters
285
+ */
286
+ interpretPAC(row, byte) {
287
+ let pacIndex;
288
+ const pacData = {
289
+ color: null,
290
+ italics: false,
291
+ indent: null,
292
+ underline: false,
293
+ row: row,
294
+ };
295
+ if (byte > 0x5f) {
296
+ pacIndex = byte - 0x60;
297
+ }
298
+ else {
299
+ pacIndex = byte - 0x40;
300
+ }
301
+ pacData.underline = (pacIndex & 1) === 1;
302
+ if (pacIndex <= 0xd) {
303
+ pacData.color = [
304
+ 'white',
305
+ 'green',
306
+ 'blue',
307
+ 'cyan',
308
+ 'red',
309
+ 'yellow',
310
+ 'magenta',
311
+ 'white',
312
+ ][Math.floor(pacIndex / 2)];
313
+ }
314
+ else if (pacIndex <= 0xf) {
315
+ pacData.italics = true;
316
+ pacData.color = 'white';
317
+ }
318
+ else {
319
+ pacData.indent = Math.floor((pacIndex - 0x10) / 2) * 4;
320
+ }
321
+ return pacData; // Note that row has zero offset. The spec uses 1.
322
+ }
323
+ /**
324
+ * Parse characters.
325
+ *
326
+ * @param a - The first byte
327
+ * @param b - The second byte
328
+ * @returns An array with 1 to 2 codes corresponding to chars, if found. null otherwise.
329
+ */
330
+ parseChars(a, b) {
331
+ let channelNr;
332
+ let charCodes = [];
333
+ let charCode1 = null;
334
+ if (a >= 0x19) {
335
+ channelNr = 2;
336
+ charCode1 = a - 8;
337
+ }
338
+ else {
339
+ channelNr = 1;
340
+ charCode1 = a;
341
+ }
342
+ if (charCode1 >= 0x11 && charCode1 <= 0x13) {
343
+ // Special character
344
+ let oneCode;
345
+ if (charCode1 === 0x11) {
346
+ oneCode = b + 0x50;
347
+ }
348
+ else if (charCode1 === 0x12) {
349
+ oneCode = b + 0x70;
350
+ }
351
+ else {
352
+ oneCode = b + 0x90;
353
+ }
354
+ this.logger.log(VerboseLevel.INFO, () => "Special char '" +
355
+ getCharForByte(oneCode) +
356
+ "' in channel " +
357
+ channelNr);
358
+ charCodes = [oneCode];
359
+ }
360
+ else if (a >= 0x20 && a <= 0x7f) {
361
+ charCodes = b === 0 ? [a] : [a, b];
362
+ }
363
+ if (charCodes) {
364
+ this.logger.log(VerboseLevel.DEBUG, () => 'Char codes = ' + numArrayToHexArray(charCodes).join(','));
365
+ }
366
+ return charCodes;
367
+ }
368
+ /**
369
+ * Parse extended background attributes as well as new foreground color black.
370
+ *
371
+ * @param a - The first byte
372
+ * @param b - The second byte
373
+ * @returns True if background attributes are found
374
+ */
375
+ parseBackgroundAttributes(a, b) {
376
+ const case1 = (a === 0x10 || a === 0x18) && b >= 0x20 && b <= 0x2f;
377
+ const case2 = (a === 0x17 || a === 0x1f) && b >= 0x2d && b <= 0x2f;
378
+ if (!(case1 || case2)) {
379
+ return false;
380
+ }
381
+ let index;
382
+ const bkgData = {};
383
+ if (a === 0x10 || a === 0x18) {
384
+ index = Math.floor((b - 0x20) / 2);
385
+ bkgData.background = backgroundColors[index];
386
+ if (b % 2 === 1) {
387
+ bkgData.background = bkgData.background + '_semi';
388
+ }
389
+ }
390
+ else if (b === 0x2d) {
391
+ bkgData.background = 'transparent';
392
+ }
393
+ else {
394
+ bkgData.foreground = 'black';
395
+ if (b === 0x2f) {
396
+ bkgData.underline = true;
397
+ }
398
+ }
399
+ const chNr = a <= 0x17 ? 1 : 2;
400
+ const channel = this.channels[chNr];
401
+ channel.setBkgData(bkgData);
402
+ return true;
403
+ }
404
+ /**
405
+ * Reset state of parser and its channels.
406
+ */
407
+ reset() {
408
+ for (let i = 0; i < Object.keys(this.channels).length; i++) {
409
+ const channel = this.channels[i];
410
+ if (channel) {
411
+ channel.reset();
412
+ }
413
+ }
414
+ setLastCmd(null, null, this.cmdHistory);
415
+ }
416
+ /**
417
+ * Trigger the generation of a cue, and the start of a new one if displayScreens are not empty.
418
+ */
419
+ cueSplitAtTime(t) {
420
+ for (let i = 0; i < this.channels.length; i++) {
421
+ const channel = this.channels[i];
422
+ if (channel) {
423
+ channel.cueSplitAtTime(t);
424
+ }
425
+ }
426
+ }
427
+ }
428
+ //# sourceMappingURL=Cta608Parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Cta608Parser.js","sourceRoot":"","sources":["../src/Cta608Parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAInD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,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IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACzC,MAAM,OAAO,GAAkB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAkB,CAAC;QACpE,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;OAEG;IACH,KAAK;QACJ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC5D,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;YACjC,IAAI,OAAO,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,EAAE,CAAC;YACjB,CAAC;QACF,CAAC;QACD,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,cAAc,CAAC,CAAS;QACvB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;YACjC,IAAI,OAAO,EAAE,CAAC;gBACb,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;YAC3B,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["/**\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.js';\nimport type { Channels } from './Channels.js';\nimport type { CmdHistory } from './CmdHistory.js';\nimport { Cta608Channel } from './Cta608Channel.js';\nimport type { PACData } from './PACData.js';\nimport type { PenStyles } from './PenStyles.js';\nimport type { SupportedField } from './SupportedField.js';\nimport { VerboseLevel } from './VerboseLevel.js';\nimport { backgroundColors } from './utils/backgroundColors.js';\nimport { createCmdHistory } from './utils/createCmdHistory.js';\nimport { getCharForByte } from './utils/getCharForByte.js';\nimport { hasCmdRepeated } from './utils/hasCmdRepeated.js';\nimport { numArrayToHexArray } from './utils/numArrayToHexArray.js';\nimport { rowsHighCh1 } from './utils/rowsHighCh1.js';\nimport { rowsHighCh2 } from './utils/rowsHighCh2.js';\nimport { rowsLowCh1 } from './utils/rowsLowCh1.js';\nimport { rowsLowCh2 } from './utils/rowsLowCh2.js';\nimport { setLastCmd } from './utils/setLastCmd.js';\n\n/**\n * CEA-608 caption parser.\n *\n * @beta\n */\nexport class Cta608Parser {\n\tprivate channels: Array<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 (let i = 0; i < this.channels.length; i++) {\n\t\t\tconst channel = this.channels[i];\n\t\t\tif (channel) {\n\t\t\t\tchannel.cueSplitAtTime(t);\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import type { CaptionScreen } from './CaptionScreen.js';
2
+ /**
3
+ * A handler for CTA-608 cues.
4
+ *
5
+ * @beta
6
+ */
7
+ export type CueHandler = {
8
+ newCue(startTime: number, endTime: number, screen: CaptionScreen): void;
9
+ reset?(): void;
10
+ dispatchCue?(): void;
11
+ };
12
+ //# sourceMappingURL=CueHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CueHandler.d.ts","sourceRoot":"","sources":["../src/CueHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG;IACxB,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,CAAC;IACxE,KAAK,CAAC,IAAI,IAAI,CAAC;IACf,WAAW,CAAC,IAAI,IAAI,CAAC;CACrB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=CueHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CueHandler.js","sourceRoot":"","sources":["../src/CueHandler.ts"],"names":[],"mappings":"","sourcesContent":["import type { CaptionScreen } from './CaptionScreen.js';\n\n/**\n * A handler for CTA-608 cues.\n *\n * @beta\n */\nexport type CueHandler = {\n\tnewCue(startTime: number, endTime: number, screen: CaptionScreen): void;\n\treset?(): void;\n\tdispatchCue?(): void;\n};\n"]}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Represents a single PAC (Preamble Address Code) data.
3
+ *
4
+ * @beta
5
+ */
6
+ export type PACData = {
7
+ row: number;
8
+ indent: number | null;
9
+ color: string | null;
10
+ underline: boolean;
11
+ italics: boolean;
12
+ };
13
+ //# sourceMappingURL=PACData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PACData.d.ts","sourceRoot":"","sources":["../src/PACData.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,OAAO,GAAG;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;CACjB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=PACData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PACData.js","sourceRoot":"","sources":["../src/PACData.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Represents a single PAC (Preamble Address Code) data.\n *\n * @beta\n */\nexport type PACData = {\n\trow: number;\n\tindent: number | null;\n\tcolor: string | null;\n\tunderline: boolean;\n\titalics: boolean;\n};\n"]}