hls.js 1.5.9-0.canary.10268 → 1.5.9-0.canary.10269

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.
@@ -145,14 +145,8 @@ const specialCea608CharsCodes = {
145
145
  /**
146
146
  * Utils
147
147
  */
148
- const getCharForByte = function (byte: number) {
149
- let charCode = byte;
150
- if (specialCea608CharsCodes.hasOwnProperty(byte)) {
151
- charCode = specialCea608CharsCodes[byte];
152
- }
153
-
154
- return String.fromCharCode(charCode);
155
- };
148
+ const getCharForByte = (byte: number) =>
149
+ String.fromCharCode(specialCea608CharsCodes[byte] || byte);
156
150
 
157
151
  const NR_ROWS = 15;
158
152
  const NR_COLS = 100;
@@ -1046,22 +1040,20 @@ class Cea608Parser {
1046
1040
  * Add data for time t in forms of list of bytes (unsigned ints). The bytes are treated as pairs.
1047
1041
  */
1048
1042
  addData(time: number | null, byteList: number[]) {
1049
- let cmdFound: boolean;
1050
- let a: number;
1051
- let b: number;
1052
- let charsFound: number[] | boolean | null = false;
1053
-
1054
1043
  this.logger.time = time;
1055
-
1056
1044
  for (let i = 0; i < byteList.length; i += 2) {
1057
- a = byteList[i] & 0x7f;
1058
- b = byteList[i + 1] & 0x7f;
1045
+ const a = byteList[i] & 0x7f;
1046
+ const b = byteList[i + 1] & 0x7f;
1047
+ let cmdFound: boolean = false;
1048
+ let charsFound: number[] | null = null;
1049
+
1059
1050
  if (a === 0 && b === 0) {
1060
1051
  continue;
1061
1052
  } else {
1062
1053
  this.logger.log(
1063
1054
  VerboseLevel.DATA,
1064
- '[' +
1055
+ () =>
1056
+ '[' +
1065
1057
  numArrayToHexArray([byteList[i], byteList[i + 1]]) +
1066
1058
  '] -> (' +
1067
1059
  numArrayToHexArray([a, b]) +
@@ -1069,20 +1061,39 @@ class Cea608Parser {
1069
1061
  );
1070
1062
  }
1071
1063
 
1072
- cmdFound = this.parseCmd(a, b);
1064
+ const cmdHistory = this.cmdHistory;
1065
+ const isControlCode = a >= 0x10 && a <= 0x1f;
1066
+ if (isControlCode) {
1067
+ // Skip redundant control codes
1068
+ if (hasCmdRepeated(a, b, cmdHistory)) {
1069
+ setLastCmd(null, null, cmdHistory);
1070
+ this.logger.log(
1071
+ VerboseLevel.DEBUG,
1072
+ () =>
1073
+ 'Repeated command (' +
1074
+ numArrayToHexArray([a, b]) +
1075
+ ') is dropped',
1076
+ );
1077
+ continue;
1078
+ }
1079
+ setLastCmd(a, b, this.cmdHistory);
1073
1080
 
1074
- if (!cmdFound) {
1075
- cmdFound = this.parseMidrow(a, b);
1076
- }
1081
+ cmdFound = this.parseCmd(a, b);
1077
1082
 
1078
- if (!cmdFound) {
1079
- cmdFound = this.parsePAC(a, b);
1080
- }
1083
+ if (!cmdFound) {
1084
+ cmdFound = this.parseMidrow(a, b);
1085
+ }
1081
1086
 
1082
- if (!cmdFound) {
1083
- cmdFound = this.parseBackgroundAttributes(a, b);
1084
- }
1087
+ if (!cmdFound) {
1088
+ cmdFound = this.parsePAC(a, b);
1089
+ }
1085
1090
 
1091
+ if (!cmdFound) {
1092
+ cmdFound = this.parseBackgroundAttributes(a, b);
1093
+ }
1094
+ } else {
1095
+ setLastCmd(null, null, cmdHistory);
1096
+ }
1086
1097
  if (!cmdFound) {
1087
1098
  charsFound = this.parseChars(a, b);
1088
1099
  if (charsFound) {
@@ -1101,7 +1112,8 @@ class Cea608Parser {
1101
1112
  if (!cmdFound && !charsFound) {
1102
1113
  this.logger.log(
1103
1114
  VerboseLevel.WARNING,
1104
- "Couldn't parse cleaned data " +
1115
+ () =>
1116
+ "Couldn't parse cleaned data " +
1105
1117
  numArrayToHexArray([a, b]) +
1106
1118
  ' orig: ' +
1107
1119
  numArrayToHexArray([byteList[i], byteList[i + 1]]),
@@ -1115,7 +1127,6 @@ class Cea608Parser {
1115
1127
  * @returns True if a command was found
1116
1128
  */
1117
1129
  parseCmd(a: number, b: number): boolean {
1118
- const { cmdHistory } = this;
1119
1130
  const cond1 =
1120
1131
  (a === 0x14 || a === 0x1c || a === 0x15 || a === 0x1d) &&
1121
1132
  b >= 0x20 &&
@@ -1125,15 +1136,6 @@ class Cea608Parser {
1125
1136
  return false;
1126
1137
  }
1127
1138
 
1128
- if (hasCmdRepeated(a, b, cmdHistory)) {
1129
- setLastCmd(null, null, cmdHistory);
1130
- this.logger.log(
1131
- VerboseLevel.DEBUG,
1132
- 'Repeated command (' + numArrayToHexArray([a, b]) + ') is dropped',
1133
- );
1134
- return true;
1135
- }
1136
-
1137
1139
  const chNr = a === 0x14 || a === 0x15 || a === 0x17 ? 1 : 2;
1138
1140
  const channel = this.channels[chNr] as Cea608Channel;
1139
1141
 
@@ -1175,7 +1177,6 @@ class Cea608Parser {
1175
1177
  // a == 0x17 || a == 0x1F
1176
1178
  channel.ccTO(b - 0x20);
1177
1179
  }
1178
- setLastCmd(a, b, cmdHistory);
1179
1180
  this.currentChannel = chNr;
1180
1181
  return true;
1181
1182
  }
@@ -1207,7 +1208,7 @@ class Cea608Parser {
1207
1208
  channel.ccMIDROW(b);
1208
1209
  this.logger.log(
1209
1210
  VerboseLevel.DEBUG,
1210
- 'MIDROW (' + numArrayToHexArray([a, b]) + ')',
1211
+ () => 'MIDROW (' + numArrayToHexArray([a, b]) + ')',
1211
1212
  );
1212
1213
  return true;
1213
1214
  }
@@ -1220,7 +1221,6 @@ class Cea608Parser {
1220
1221
  */
1221
1222
  parsePAC(a: number, b: number): boolean {
1222
1223
  let row: number;
1223
- const cmdHistory = this.cmdHistory;
1224
1224
 
1225
1225
  const case1 =
1226
1226
  ((a >= 0x11 && a <= 0x17) || (a >= 0x19 && a <= 0x1f)) &&
@@ -1231,11 +1231,6 @@ class Cea608Parser {
1231
1231
  return false;
1232
1232
  }
1233
1233
 
1234
- if (hasCmdRepeated(a, b, cmdHistory)) {
1235
- setLastCmd(null, null, cmdHistory);
1236
- return true; // Repeated commands are dropped (once)
1237
- }
1238
-
1239
1234
  const chNr: Channels = a <= 0x17 ? 1 : 2;
1240
1235
 
1241
1236
  if (b >= 0x40 && b <= 0x5f) {
@@ -1249,7 +1244,6 @@ class Cea608Parser {
1249
1244
  return false;
1250
1245
  }
1251
1246
  channel.setPAC(this.interpretPAC(row, b));
1252
- setLastCmd(a, b, cmdHistory);
1253
1247
  this.currentChannel = chNr;
1254
1248
  return true;
1255
1249
  }
@@ -1324,7 +1318,8 @@ class Cea608Parser {
1324
1318
 
1325
1319
  this.logger.log(
1326
1320
  VerboseLevel.INFO,
1327
- "Special char '" +
1321
+ () =>
1322
+ "Special char '" +
1328
1323
  getCharForByte(oneCode) +
1329
1324
  "' in channel " +
1330
1325
  channelNr,
@@ -1334,12 +1329,10 @@ class Cea608Parser {
1334
1329
  charCodes = b === 0 ? [a] : [a, b];
1335
1330
  }
1336
1331
  if (charCodes) {
1337
- const hexCodes = numArrayToHexArray(charCodes);
1338
1332
  this.logger.log(
1339
1333
  VerboseLevel.DEBUG,
1340
- 'Char codes = ' + hexCodes.join(','),
1334
+ () => 'Char codes = ' + numArrayToHexArray(charCodes).join(','),
1341
1335
  );
1342
- setLastCmd(a, b, this.cmdHistory);
1343
1336
  }
1344
1337
  return charCodes;
1345
1338
  }
@@ -1373,7 +1366,6 @@ class Cea608Parser {
1373
1366
  const chNr: Channels = a <= 0x17 ? 1 : 2;
1374
1367
  const channel: Cea608Channel = this.channels[chNr] as Cea608Channel;
1375
1368
  channel.setBkgData(bkgData);
1376
- setLastCmd(a, b, this.cmdHistory);
1377
1369
  return true;
1378
1370
  }
1379
1371
 
@@ -1387,7 +1379,7 @@ class Cea608Parser {
1387
1379
  channel.reset();
1388
1380
  }
1389
1381
  }
1390
- this.cmdHistory = createCmdHistory();
1382
+ setLastCmd(null, null, this.cmdHistory);
1391
1383
  }
1392
1384
 
1393
1385
  /**