hls.js 1.5.10-0.canary.10321 → 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.light.js CHANGED
@@ -580,7 +580,7 @@
580
580
  // Some browsers don't allow to use bind on console object anyway
581
581
  // fallback to default if needed
582
582
  try {
583
- newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.5.10-0.canary.10321");
583
+ newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.5.10-0.canary.10326");
584
584
  } catch (e) {
585
585
  /* log fn threw an exception. All logger methods are no-ops. */
586
586
  return createLogger();
@@ -5475,13 +5475,16 @@
5475
5475
  * @param maxFragLookUpTolerance - The amount of time that a fragment's start/end can be within in order to be considered contiguous
5476
5476
  * @returns a matching fragment or null
5477
5477
  */
5478
- function findFragmentByPTS(fragPrevious, fragments, bufferEnd, maxFragLookUpTolerance) {
5478
+ function findFragmentByPTS(fragPrevious, fragments, bufferEnd, maxFragLookUpTolerance, nextFragLookupTolerance) {
5479
5479
  if (bufferEnd === void 0) {
5480
5480
  bufferEnd = 0;
5481
5481
  }
5482
5482
  if (maxFragLookUpTolerance === void 0) {
5483
5483
  maxFragLookUpTolerance = 0;
5484
5484
  }
5485
+ if (nextFragLookupTolerance === void 0) {
5486
+ nextFragLookupTolerance = 0.005;
5487
+ }
5485
5488
  var fragNext = null;
5486
5489
  if (fragPrevious) {
5487
5490
  fragNext = fragments[fragPrevious.sn - fragments[0].sn + 1] || null;
@@ -5494,7 +5497,7 @@
5494
5497
  fragNext = fragments[0];
5495
5498
  }
5496
5499
  // Prefer the next fragment if it's within tolerance
5497
- if (fragNext && (!fragPrevious || fragPrevious.level === fragNext.level) && fragmentWithinToleranceTest(bufferEnd, maxFragLookUpTolerance, fragNext) === 0) {
5500
+ if (fragNext && ((!fragPrevious || fragPrevious.level === fragNext.level) && fragmentWithinToleranceTest(bufferEnd, maxFragLookUpTolerance, fragNext) === 0 || fragmentWithinFastStartSwitch(fragNext, fragPrevious, Math.min(nextFragLookupTolerance, maxFragLookUpTolerance)))) {
5498
5501
  return fragNext;
5499
5502
  }
5500
5503
  // We might be seeking past the tolerance so find the best match
@@ -5505,6 +5508,18 @@
5505
5508
  // If no match was found return the next fragment after fragPrevious, or null
5506
5509
  return fragNext;
5507
5510
  }
5511
+ function fragmentWithinFastStartSwitch(fragNext, fragPrevious, nextFragLookupTolerance) {
5512
+ if (fragPrevious && fragPrevious.start === 0 && fragPrevious.level < fragNext.level && (fragPrevious.endPTS || 0) > 0) {
5513
+ var firstDuration = fragPrevious.tagList.reduce(function (duration, tag) {
5514
+ if (tag[0] === 'INF') {
5515
+ duration += parseFloat(tag[1]);
5516
+ }
5517
+ return duration;
5518
+ }, nextFragLookupTolerance);
5519
+ return fragNext.start <= firstDuration;
5520
+ }
5521
+ return false;
5522
+ }
5508
5523
 
5509
5524
  /**
5510
5525
  * The test function used by the findFragmentBySn's BinarySearch to look for the best match to the current buffer conditions.
@@ -12790,7 +12805,7 @@
12790
12805
  if (_this3.state === State.STOPPED || _this3.state === State.ERROR) {
12791
12806
  return;
12792
12807
  }
12793
- _this3.warn(reason);
12808
+ _this3.warn("Frag error: " + ((reason == null ? void 0 : reason.message) || reason));
12794
12809
  _this3.resetFragmentLoading(frag);
12795
12810
  });
12796
12811
  };
@@ -13472,7 +13487,7 @@
13472
13487
  var fragments = levelDetails.fragments,
13473
13488
  endSN = levelDetails.endSN;
13474
13489
  var fragmentHint = levelDetails.fragmentHint;
13475
- var tolerance = config.maxFragLookUpTolerance;
13490
+ var maxFragLookUpTolerance = config.maxFragLookUpTolerance;
13476
13491
  var partList = levelDetails.partList;
13477
13492
  var loadingParts = !!(this.loadingParts && partList != null && partList.length && fragmentHint);
13478
13493
  if (loadingParts && fragmentHint && !this.bitrateTest) {
@@ -13482,7 +13497,7 @@
13482
13497
  }
13483
13498
  var frag;
13484
13499
  if (bufferEnd < end) {
13485
- var lookupTolerance = bufferEnd > end - tolerance ? 0 : tolerance;
13500
+ var lookupTolerance = bufferEnd > end - maxFragLookUpTolerance ? 0 : maxFragLookUpTolerance;
13486
13501
  // Remove the tolerance if it would put the bufferEnd past the actual end of stream
13487
13502
  // Uses buffer and sequence number to calculate switch segment (required if using EXT-X-DISCONTINUITY-SEQUENCE)
13488
13503
  frag = findFragmentByPTS(fragPrevious, fragments, bufferEnd, lookupTolerance);
@@ -15773,7 +15788,7 @@
15773
15788
  if (stt) {
15774
15789
  offset += data[offset] + 1;
15775
15790
  }
15776
- var parsedPIDs = parsePMT(data, offset, this.typeSupported, isSampleAes);
15791
+ var parsedPIDs = parsePMT(data, offset, this.typeSupported, isSampleAes, this.observer);
15777
15792
 
15778
15793
  // only update track id if track PID found while parsing PMT
15779
15794
  // this is to avoid resetting the PID to -1 in case
@@ -15816,14 +15831,7 @@
15816
15831
  }
15817
15832
  }
15818
15833
  if (tsPacketErrors > 0) {
15819
- var error = new Error("Found " + tsPacketErrors + " TS packet/s that do not start with 0x47");
15820
- this.observer.emit(Events.ERROR, Events.ERROR, {
15821
- type: ErrorTypes.MEDIA_ERROR,
15822
- details: ErrorDetails.FRAG_PARSING_ERROR,
15823
- fatal: false,
15824
- error: error,
15825
- reason: error.message
15826
- });
15834
+ emitParsingError(this.observer, new Error("Found " + tsPacketErrors + " TS packet/s that do not start with 0x47"));
15827
15835
  }
15828
15836
  videoTrack.pesData = videoData;
15829
15837
  audioTrack.pesData = audioData;
@@ -15975,16 +15983,7 @@
15975
15983
  } else {
15976
15984
  reason = 'No ADTS header found in AAC PES';
15977
15985
  }
15978
- var error = new Error(reason);
15979
- logger.warn("parsing error: " + reason);
15980
- this.observer.emit(Events.ERROR, Events.ERROR, {
15981
- type: ErrorTypes.MEDIA_ERROR,
15982
- details: ErrorDetails.FRAG_PARSING_ERROR,
15983
- fatal: false,
15984
- levelRetry: recoverable,
15985
- error: error,
15986
- reason: reason
15987
- });
15986
+ emitParsingError(this.observer, new Error(reason), recoverable);
15988
15987
  if (!recoverable) {
15989
15988
  return;
15990
15989
  }
@@ -16071,7 +16070,7 @@
16071
16070
  // skip the PSI header and parse the first PMT entry
16072
16071
  return (data[offset + 10] & 0x1f) << 8 | data[offset + 11];
16073
16072
  }
16074
- function parsePMT(data, offset, typeSupported, isSampleAes) {
16073
+ function parsePMT(data, offset, typeSupported, isSampleAes, observer) {
16075
16074
  var result = {
16076
16075
  audioPid: -1,
16077
16076
  videoPid: -1,
@@ -16179,11 +16178,13 @@
16179
16178
  case 0xc2: // SAMPLE-AES EC3
16180
16179
  /* falls through */
16181
16180
  case 0x87:
16182
- throw new Error('Unsupported EC-3 in M2TS found');
16181
+ emitParsingError(observer, new Error('Unsupported EC-3 in M2TS found'));
16182
+ return result;
16183
16183
  case 0x24:
16184
16184
  // ITU-T Rec. H.265 and ISO/IEC 23008-2 (HEVC)
16185
16185
  {
16186
- throw new Error('Unsupported HEVC in M2TS found');
16186
+ emitParsingError(observer, new Error('Unsupported HEVC in M2TS found'));
16187
+ return result;
16187
16188
  }
16188
16189
  }
16189
16190
  // move to the next table entry
@@ -16192,6 +16193,17 @@
16192
16193
  }
16193
16194
  return result;
16194
16195
  }
16196
+ function emitParsingError(observer, error, levelRetry) {
16197
+ logger.warn("parsing error: " + error.message);
16198
+ observer.emit(Events.ERROR, Events.ERROR, {
16199
+ type: ErrorTypes.MEDIA_ERROR,
16200
+ details: ErrorDetails.FRAG_PARSING_ERROR,
16201
+ fatal: false,
16202
+ levelRetry: levelRetry,
16203
+ error: error,
16204
+ reason: error.message
16205
+ });
16206
+ }
16195
16207
  function logEncryptedSamplesFoundInUnencryptedStream(type) {
16196
16208
  logger.log(type + " with AES-128-CBC encryption found in unencrypted stream");
16197
16209
  }
@@ -18926,7 +18938,7 @@
18926
18938
  case 'init':
18927
18939
  {
18928
18940
  var config = JSON.parse(data.config);
18929
- self.transmuxer = new Transmuxer(observer, data.typeSupported, config, data.vendor, data.id);
18941
+ self.transmuxer = new Transmuxer(observer, data.typeSupported, config, '', data.id);
18930
18942
  var logger = enableLogs(config.debug, data.id);
18931
18943
  forwardWorkerLogs(logger);
18932
18944
  forwardMessage('init', null);
@@ -19103,10 +19115,6 @@
19103
19115
  this.observer.on(Events.FRAG_DECRYPTED, forwardMessage);
19104
19116
  this.observer.on(Events.ERROR, forwardMessage);
19105
19117
  var m2tsTypeSupported = getM2TSSupportedAudioTypes(config.preferManagedMediaSource);
19106
-
19107
- // navigator.vendor is not always available in Web Worker
19108
- // refer to https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/navigator
19109
- var vendor = navigator.vendor;
19110
19118
  if (this.useWorker && typeof Worker !== 'undefined') {
19111
19119
  var canCreateWorker = config.workerPath || hasUMDWorker();
19112
19120
  if (canCreateWorker) {
@@ -19118,8 +19126,8 @@
19118
19126
  logger.log("injecting Web Worker for \"" + id + "\"");
19119
19127
  this.workerContext = injectWorker();
19120
19128
  }
19121
- this.onwmsg = function (ev) {
19122
- return _this.onWorkerMessage(ev);
19129
+ this.onwmsg = function (event) {
19130
+ return _this.onWorkerMessage(event);
19123
19131
  };
19124
19132
  var worker = this.workerContext.worker;
19125
19133
  worker.addEventListener('message', this.onwmsg);
@@ -19138,7 +19146,7 @@
19138
19146
  worker.postMessage({
19139
19147
  cmd: 'init',
19140
19148
  typeSupported: m2tsTypeSupported,
19141
- vendor: vendor,
19149
+ vendor: '',
19142
19150
  id: id,
19143
19151
  config: JSON.stringify(config)
19144
19152
  });
@@ -19146,12 +19154,12 @@
19146
19154
  logger.warn("Error setting up \"" + id + "\" Web Worker, fallback to inline", err);
19147
19155
  this.resetWorker();
19148
19156
  this.error = null;
19149
- this.transmuxer = new Transmuxer(this.observer, m2tsTypeSupported, config, vendor, id);
19157
+ this.transmuxer = new Transmuxer(this.observer, m2tsTypeSupported, config, '', id);
19150
19158
  }
19151
19159
  return;
19152
19160
  }
19153
19161
  }
19154
- this.transmuxer = new Transmuxer(this.observer, m2tsTypeSupported, config, vendor, id);
19162
+ this.transmuxer = new Transmuxer(this.observer, m2tsTypeSupported, config, '', id);
19155
19163
  }
19156
19164
  var _proto = TransmuxerInterface.prototype;
19157
19165
  _proto.resetWorker = function resetWorker() {
@@ -19297,9 +19305,16 @@
19297
19305
  });
19298
19306
  this.onFlush(chunkMeta);
19299
19307
  };
19300
- _proto.onWorkerMessage = function onWorkerMessage(ev) {
19301
- var data = ev.data;
19308
+ _proto.onWorkerMessage = function onWorkerMessage(event) {
19309
+ var data = event.data;
19310
+ if (!(data != null && data.event)) {
19311
+ logger.warn("worker message received with no " + (data ? 'event name' : 'data'));
19312
+ return;
19313
+ }
19302
19314
  var hls = this.hls;
19315
+ if (!this.hls) {
19316
+ return;
19317
+ }
19303
19318
  switch (data.event) {
19304
19319
  case 'init':
19305
19320
  {
@@ -20642,7 +20657,8 @@
20642
20657
  // In the case that AAC and HE-AAC audio codecs are signalled in manifest,
20643
20658
  // force HE-AAC, as it seems that most browsers prefers it.
20644
20659
  // don't force HE-AAC if mono stream, or in Firefox
20645
- if (audio.metadata.channelCount !== 1 && ua.indexOf('firefox') === -1) {
20660
+ var audioMetadata = audio.metadata;
20661
+ if (audioMetadata && 'channelCount' in audioMetadata && (audioMetadata.channelCount || 1) !== 1 && ua.indexOf('firefox') === -1) {
20646
20662
  audioCodec = 'mp4a.40.5';
20647
20663
  }
20648
20664
  }
@@ -21693,7 +21709,7 @@
21693
21709
  * Get the video-dev/hls.js package version.
21694
21710
  */
21695
21711
  function get() {
21696
- return "1.5.10-0.canary.10321";
21712
+ return "1.5.10-0.canary.10326";
21697
21713
  }
21698
21714
  }, {
21699
21715
  key: "Events",