hls.js 1.5.10-0.canary.10320 → 1.5.10-0.canary.10326

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/dist/hls.js CHANGED
@@ -609,7 +609,7 @@
609
609
  // Some browsers don't allow to use bind on console object anyway
610
610
  // fallback to default if needed
611
611
  try {
612
- newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.5.10-0.canary.10320");
612
+ newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.5.10-0.canary.10326");
613
613
  } catch (e) {
614
614
  /* log fn threw an exception. All logger methods are no-ops. */
615
615
  return createLogger();
@@ -6106,13 +6106,16 @@
6106
6106
  * @param maxFragLookUpTolerance - The amount of time that a fragment's start/end can be within in order to be considered contiguous
6107
6107
  * @returns a matching fragment or null
6108
6108
  */
6109
- function findFragmentByPTS(fragPrevious, fragments, bufferEnd, maxFragLookUpTolerance) {
6109
+ function findFragmentByPTS(fragPrevious, fragments, bufferEnd, maxFragLookUpTolerance, nextFragLookupTolerance) {
6110
6110
  if (bufferEnd === void 0) {
6111
6111
  bufferEnd = 0;
6112
6112
  }
6113
6113
  if (maxFragLookUpTolerance === void 0) {
6114
6114
  maxFragLookUpTolerance = 0;
6115
6115
  }
6116
+ if (nextFragLookupTolerance === void 0) {
6117
+ nextFragLookupTolerance = 0.005;
6118
+ }
6116
6119
  var fragNext = null;
6117
6120
  if (fragPrevious) {
6118
6121
  fragNext = fragments[fragPrevious.sn - fragments[0].sn + 1] || null;
@@ -6125,7 +6128,7 @@
6125
6128
  fragNext = fragments[0];
6126
6129
  }
6127
6130
  // Prefer the next fragment if it's within tolerance
6128
- if (fragNext && (!fragPrevious || fragPrevious.level === fragNext.level) && fragmentWithinToleranceTest(bufferEnd, maxFragLookUpTolerance, fragNext) === 0) {
6131
+ if (fragNext && ((!fragPrevious || fragPrevious.level === fragNext.level) && fragmentWithinToleranceTest(bufferEnd, maxFragLookUpTolerance, fragNext) === 0 || fragmentWithinFastStartSwitch(fragNext, fragPrevious, Math.min(nextFragLookupTolerance, maxFragLookUpTolerance)))) {
6129
6132
  return fragNext;
6130
6133
  }
6131
6134
  // We might be seeking past the tolerance so find the best match
@@ -6136,6 +6139,18 @@
6136
6139
  // If no match was found return the next fragment after fragPrevious, or null
6137
6140
  return fragNext;
6138
6141
  }
6142
+ function fragmentWithinFastStartSwitch(fragNext, fragPrevious, nextFragLookupTolerance) {
6143
+ if (fragPrevious && fragPrevious.start === 0 && fragPrevious.level < fragNext.level && (fragPrevious.endPTS || 0) > 0) {
6144
+ var firstDuration = fragPrevious.tagList.reduce(function (duration, tag) {
6145
+ if (tag[0] === 'INF') {
6146
+ duration += parseFloat(tag[1]);
6147
+ }
6148
+ return duration;
6149
+ }, nextFragLookupTolerance);
6150
+ return fragNext.start <= firstDuration;
6151
+ }
6152
+ return false;
6153
+ }
6139
6154
 
6140
6155
  /**
6141
6156
  * The test function used by the findFragmentBySn's BinarySearch to look for the best match to the current buffer conditions.
@@ -10009,7 +10024,7 @@
10009
10024
  if (_this3.state === State.STOPPED || _this3.state === State.ERROR) {
10010
10025
  return;
10011
10026
  }
10012
- _this3.warn(reason);
10027
+ _this3.warn("Frag error: " + ((reason == null ? void 0 : reason.message) || reason));
10013
10028
  _this3.resetFragmentLoading(frag);
10014
10029
  });
10015
10030
  };
@@ -10691,7 +10706,7 @@
10691
10706
  var fragments = levelDetails.fragments,
10692
10707
  endSN = levelDetails.endSN;
10693
10708
  var fragmentHint = levelDetails.fragmentHint;
10694
- var tolerance = config.maxFragLookUpTolerance;
10709
+ var maxFragLookUpTolerance = config.maxFragLookUpTolerance;
10695
10710
  var partList = levelDetails.partList;
10696
10711
  var loadingParts = !!(this.loadingParts && partList != null && partList.length && fragmentHint);
10697
10712
  if (loadingParts && fragmentHint && !this.bitrateTest) {
@@ -10701,7 +10716,7 @@
10701
10716
  }
10702
10717
  var frag;
10703
10718
  if (bufferEnd < end) {
10704
- var lookupTolerance = bufferEnd > end - tolerance ? 0 : tolerance;
10719
+ var lookupTolerance = bufferEnd > end - maxFragLookUpTolerance ? 0 : maxFragLookUpTolerance;
10705
10720
  // Remove the tolerance if it would put the bufferEnd past the actual end of stream
10706
10721
  // Uses buffer and sequence number to calculate switch segment (required if using EXT-X-DISCONTINUITY-SEQUENCE)
10707
10722
  frag = findFragmentByPTS(fragPrevious, fragments, bufferEnd, lookupTolerance);
@@ -13732,7 +13747,7 @@
13732
13747
  if (stt) {
13733
13748
  offset += data[offset] + 1;
13734
13749
  }
13735
- var parsedPIDs = parsePMT(data, offset, this.typeSupported, isSampleAes);
13750
+ var parsedPIDs = parsePMT(data, offset, this.typeSupported, isSampleAes, this.observer);
13736
13751
 
13737
13752
  // only update track id if track PID found while parsing PMT
13738
13753
  // this is to avoid resetting the PID to -1 in case
@@ -13775,14 +13790,7 @@
13775
13790
  }
13776
13791
  }
13777
13792
  if (tsPacketErrors > 0) {
13778
- var error = new Error("Found " + tsPacketErrors + " TS packet/s that do not start with 0x47");
13779
- this.observer.emit(Events.ERROR, Events.ERROR, {
13780
- type: ErrorTypes.MEDIA_ERROR,
13781
- details: ErrorDetails.FRAG_PARSING_ERROR,
13782
- fatal: false,
13783
- error: error,
13784
- reason: error.message
13785
- });
13793
+ emitParsingError(this.observer, new Error("Found " + tsPacketErrors + " TS packet/s that do not start with 0x47"));
13786
13794
  }
13787
13795
  videoTrack.pesData = videoData;
13788
13796
  audioTrack.pesData = audioData;
@@ -13944,16 +13952,7 @@
13944
13952
  } else {
13945
13953
  reason = 'No ADTS header found in AAC PES';
13946
13954
  }
13947
- var error = new Error(reason);
13948
- logger.warn("parsing error: " + reason);
13949
- this.observer.emit(Events.ERROR, Events.ERROR, {
13950
- type: ErrorTypes.MEDIA_ERROR,
13951
- details: ErrorDetails.FRAG_PARSING_ERROR,
13952
- fatal: false,
13953
- levelRetry: recoverable,
13954
- error: error,
13955
- reason: reason
13956
- });
13955
+ emitParsingError(this.observer, new Error(reason), recoverable);
13957
13956
  if (!recoverable) {
13958
13957
  return;
13959
13958
  }
@@ -14055,7 +14054,7 @@
14055
14054
  // skip the PSI header and parse the first PMT entry
14056
14055
  return (data[offset + 10] & 0x1f) << 8 | data[offset + 11];
14057
14056
  }
14058
- function parsePMT(data, offset, typeSupported, isSampleAes) {
14057
+ function parsePMT(data, offset, typeSupported, isSampleAes, observer) {
14059
14058
  var result = {
14060
14059
  audioPid: -1,
14061
14060
  videoPid: -1,
@@ -14173,7 +14172,8 @@
14173
14172
  case 0xc2: // SAMPLE-AES EC3
14174
14173
  /* falls through */
14175
14174
  case 0x87:
14176
- throw new Error('Unsupported EC-3 in M2TS found');
14175
+ emitParsingError(observer, new Error('Unsupported EC-3 in M2TS found'));
14176
+ return result;
14177
14177
  case 0x24:
14178
14178
  // ITU-T Rec. H.265 and ISO/IEC 23008-2 (HEVC)
14179
14179
  {
@@ -14191,6 +14191,17 @@
14191
14191
  }
14192
14192
  return result;
14193
14193
  }
14194
+ function emitParsingError(observer, error, levelRetry) {
14195
+ logger.warn("parsing error: " + error.message);
14196
+ observer.emit(Events.ERROR, Events.ERROR, {
14197
+ type: ErrorTypes.MEDIA_ERROR,
14198
+ details: ErrorDetails.FRAG_PARSING_ERROR,
14199
+ fatal: false,
14200
+ levelRetry: levelRetry,
14201
+ error: error,
14202
+ reason: error.message
14203
+ });
14204
+ }
14194
14205
  function logEncryptedSamplesFoundInUnencryptedStream(type) {
14195
14206
  logger.log(type + " with AES-128-CBC encryption found in unencrypted stream");
14196
14207
  }
@@ -16946,7 +16957,7 @@
16946
16957
  case 'init':
16947
16958
  {
16948
16959
  var config = JSON.parse(data.config);
16949
- self.transmuxer = new Transmuxer(observer, data.typeSupported, config, data.vendor, data.id);
16960
+ self.transmuxer = new Transmuxer(observer, data.typeSupported, config, '', data.id);
16950
16961
  var logger = enableLogs(config.debug, data.id);
16951
16962
  forwardWorkerLogs(logger);
16952
16963
  forwardMessage('init', null);
@@ -17123,10 +17134,6 @@
17123
17134
  this.observer.on(Events.FRAG_DECRYPTED, forwardMessage);
17124
17135
  this.observer.on(Events.ERROR, forwardMessage);
17125
17136
  var m2tsTypeSupported = getM2TSSupportedAudioTypes(config.preferManagedMediaSource);
17126
-
17127
- // navigator.vendor is not always available in Web Worker
17128
- // refer to https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/navigator
17129
- var vendor = navigator.vendor;
17130
17137
  if (this.useWorker && typeof Worker !== 'undefined') {
17131
17138
  var canCreateWorker = config.workerPath || hasUMDWorker();
17132
17139
  if (canCreateWorker) {
@@ -17138,8 +17145,8 @@
17138
17145
  logger.log("injecting Web Worker for \"" + id + "\"");
17139
17146
  this.workerContext = injectWorker();
17140
17147
  }
17141
- this.onwmsg = function (ev) {
17142
- return _this.onWorkerMessage(ev);
17148
+ this.onwmsg = function (event) {
17149
+ return _this.onWorkerMessage(event);
17143
17150
  };
17144
17151
  var worker = this.workerContext.worker;
17145
17152
  worker.addEventListener('message', this.onwmsg);
@@ -17158,7 +17165,7 @@
17158
17165
  worker.postMessage({
17159
17166
  cmd: 'init',
17160
17167
  typeSupported: m2tsTypeSupported,
17161
- vendor: vendor,
17168
+ vendor: '',
17162
17169
  id: id,
17163
17170
  config: JSON.stringify(config)
17164
17171
  });
@@ -17166,12 +17173,12 @@
17166
17173
  logger.warn("Error setting up \"" + id + "\" Web Worker, fallback to inline", err);
17167
17174
  this.resetWorker();
17168
17175
  this.error = null;
17169
- this.transmuxer = new Transmuxer(this.observer, m2tsTypeSupported, config, vendor, id);
17176
+ this.transmuxer = new Transmuxer(this.observer, m2tsTypeSupported, config, '', id);
17170
17177
  }
17171
17178
  return;
17172
17179
  }
17173
17180
  }
17174
- this.transmuxer = new Transmuxer(this.observer, m2tsTypeSupported, config, vendor, id);
17181
+ this.transmuxer = new Transmuxer(this.observer, m2tsTypeSupported, config, '', id);
17175
17182
  }
17176
17183
  var _proto = TransmuxerInterface.prototype;
17177
17184
  _proto.resetWorker = function resetWorker() {
@@ -17317,9 +17324,16 @@
17317
17324
  });
17318
17325
  this.onFlush(chunkMeta);
17319
17326
  };
17320
- _proto.onWorkerMessage = function onWorkerMessage(ev) {
17321
- var data = ev.data;
17327
+ _proto.onWorkerMessage = function onWorkerMessage(event) {
17328
+ var data = event.data;
17329
+ if (!(data != null && data.event)) {
17330
+ logger.warn("worker message received with no " + (data ? 'event name' : 'data'));
17331
+ return;
17332
+ }
17322
17333
  var hls = this.hls;
17334
+ if (!this.hls) {
17335
+ return;
17336
+ }
17323
17337
  switch (data.event) {
17324
17338
  case 'init':
17325
17339
  {
@@ -26399,8 +26413,6 @@
26399
26413
  this.config = null;
26400
26414
  this.context = null;
26401
26415
  this.xhrSetup = null;
26402
- // @ts-ignore
26403
- this.stats = null;
26404
26416
  };
26405
26417
  _proto.abortInternal = function abortInternal() {
26406
26418
  var loader = this.loader;
@@ -26447,13 +26459,14 @@
26447
26459
  var xhrSetup = this.xhrSetup;
26448
26460
  if (xhrSetup) {
26449
26461
  Promise.resolve().then(function () {
26450
- if (_this.stats.aborted) return;
26462
+ if (_this.loader !== xhr || _this.stats.aborted) return;
26451
26463
  return xhrSetup(xhr, context.url);
26452
26464
  }).catch(function (error) {
26465
+ if (_this.loader !== xhr || _this.stats.aborted) return;
26453
26466
  xhr.open('GET', context.url, true);
26454
26467
  return xhrSetup(xhr, context.url);
26455
26468
  }).then(function () {
26456
- if (_this.stats.aborted) return;
26469
+ if (_this.loader !== xhr || _this.stats.aborted) return;
26457
26470
  _this.openAndSendXhr(xhr, context, config);
26458
26471
  }).catch(function (error) {
26459
26472
  // IE11 throws an exception on xhr.open if attempting to access an HTTP resource over HTTPS
@@ -26570,8 +26583,8 @@
26570
26583
  }
26571
26584
  };
26572
26585
  _proto.loadtimeout = function loadtimeout() {
26573
- var _this$config;
26574
- var retryConfig = (_this$config = this.config) == null ? void 0 : _this$config.loadPolicy.timeoutRetry;
26586
+ if (!this.config) return;
26587
+ var retryConfig = this.config.loadPolicy.timeoutRetry;
26575
26588
  var retryCount = this.stats.retry;
26576
26589
  if (shouldRetry(retryConfig, retryCount, true)) {
26577
26590
  this.retry(retryConfig);
@@ -29452,7 +29465,8 @@
29452
29465
  // In the case that AAC and HE-AAC audio codecs are signalled in manifest,
29453
29466
  // force HE-AAC, as it seems that most browsers prefers it.
29454
29467
  // don't force HE-AAC if mono stream, or in Firefox
29455
- if (audio.metadata.channelCount !== 1 && ua.indexOf('firefox') === -1) {
29468
+ var audioMetadata = audio.metadata;
29469
+ if (audioMetadata && 'channelCount' in audioMetadata && (audioMetadata.channelCount || 1) !== 1 && ua.indexOf('firefox') === -1) {
29456
29470
  audioCodec = 'mp4a.40.5';
29457
29471
  }
29458
29472
  }
@@ -30503,7 +30517,7 @@
30503
30517
  * Get the video-dev/hls.js package version.
30504
30518
  */
30505
30519
  function get() {
30506
- return "1.5.10-0.canary.10320";
30520
+ return "1.5.10-0.canary.10326";
30507
30521
  }
30508
30522
  }, {
30509
30523
  key: "Events",