@volcengine/veplayer-plugin 2.4.2-rc.4 → 2.4.3-rc.1

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 (31) hide show
  1. package/esm/index.development.js +2124 -1344
  2. package/esm/index.production.js +4 -4
  3. package/esm/veplayer.plugin.abr.development.js +71 -3
  4. package/esm/veplayer.plugin.abr.production.js +1 -1
  5. package/esm/veplayer.plugin.drm.development.js +71 -3
  6. package/esm/veplayer.plugin.drm.production.js +1 -1
  7. package/esm/veplayer.plugin.flv.development.js +727 -196
  8. package/esm/veplayer.plugin.flv.production.js +1 -1
  9. package/esm/veplayer.plugin.hls.development.js +1346 -372
  10. package/esm/veplayer.plugin.hls.production.js +1 -1
  11. package/esm/veplayer.plugin.mp4.development.js +73 -5
  12. package/esm/veplayer.plugin.mp4.production.js +1 -1
  13. package/esm/veplayer.plugin.rtm.development.js +189 -778
  14. package/esm/veplayer.plugin.rtm.production.js +1 -1
  15. package/esm/veplayer.plugin.shaka.development.js +72 -4
  16. package/esm/veplayer.plugin.shaka.production.js +1 -1
  17. package/package.json +1 -1
  18. package/umd/veplayer.plugin.abr.development.js +71 -3
  19. package/umd/veplayer.plugin.abr.production.js +1 -1
  20. package/umd/veplayer.plugin.drm.development.js +71 -3
  21. package/umd/veplayer.plugin.drm.production.js +1 -1
  22. package/umd/veplayer.plugin.flv.development.js +727 -196
  23. package/umd/veplayer.plugin.flv.production.js +1 -1
  24. package/umd/veplayer.plugin.hls.development.js +1313 -339
  25. package/umd/veplayer.plugin.hls.production.js +1 -1
  26. package/umd/veplayer.plugin.mp4.development.js +73 -5
  27. package/umd/veplayer.plugin.mp4.production.js +1 -1
  28. package/umd/veplayer.plugin.rtm.development.js +189 -778
  29. package/umd/veplayer.plugin.rtm.production.js +1 -1
  30. package/umd/veplayer.plugin.shaka.development.js +72 -4
  31. package/umd/veplayer.plugin.shaka.production.js +1 -1
@@ -1644,7 +1644,7 @@
1644
1644
  }
1645
1645
  return offsetTime;
1646
1646
  };
1647
- var version = "3.0.19-rc.0";
1647
+ var version = "3.0.20-rc.6";
1648
1648
  var ERROR_MAP = {
1649
1649
  1: 5101,
1650
1650
  2: 5102,
@@ -1753,8 +1753,7 @@
1753
1753
  }
1754
1754
  if (this.__hooks && this.__hooks[hookName]) {
1755
1755
  try {
1756
- var _this$__hooks$hookNam;
1757
- var preRet = (_this$__hooks$hookNam = this.__hooks[hookName]).call.apply(_this$__hooks$hookNam, [this, this].concat(Array.prototype.slice.call(arguments)));
1756
+ var preRet = runHooks(this, hookName, handler);
1758
1757
  if (preRet) {
1759
1758
  if (preRet.then) {
1760
1759
  preRet.then(function(isContinue) {
@@ -1779,6 +1778,19 @@
1779
1778
  }
1780
1779
  }.bind(this);
1781
1780
  }
1781
+ function findHookIndex(hookName, handler) {
1782
+ var __hooks = this.__hooks;
1783
+ if (!__hooks || !Array.isArray(__hooks[hookName])) {
1784
+ return -1;
1785
+ }
1786
+ var hookHandlers = __hooks[hookName];
1787
+ for (var i = 0; i < hookHandlers.length; i++) {
1788
+ if (hookHandlers[i] === handler) {
1789
+ return i;
1790
+ }
1791
+ }
1792
+ return -1;
1793
+ }
1782
1794
  function useHooks(hookName, handler) {
1783
1795
  var __hooks = this.__hooks;
1784
1796
  if (!__hooks) {
@@ -1788,7 +1800,12 @@
1788
1800
  console.warn("has no supported hook which name [".concat(hookName, "]"));
1789
1801
  return false;
1790
1802
  }
1791
- __hooks && (__hooks[hookName] = handler);
1803
+ if (!Array.isArray(__hooks[hookName])) {
1804
+ __hooks[hookName] = [];
1805
+ }
1806
+ if (findHookIndex.call(this, hookName, handler) === -1) {
1807
+ __hooks[hookName].push(handler);
1808
+ }
1792
1809
  return true;
1793
1810
  }
1794
1811
  function removeHooks(hookName, handler) {
@@ -1796,6 +1813,13 @@
1796
1813
  if (!__hooks) {
1797
1814
  return;
1798
1815
  }
1816
+ if (Array.isArray(__hooks[hookName])) {
1817
+ var hooks = __hooks[hookName];
1818
+ var index = findHookIndex.call(this, hookName, handler);
1819
+ if (index !== -1) {
1820
+ hooks.splice(index, 1);
1821
+ }
1822
+ }
1799
1823
  delete __hooks[hookName];
1800
1824
  }
1801
1825
  function hooksDescriptor(instance) {
@@ -1817,6 +1841,38 @@
1817
1841
  function delHooksDescriptor(instance) {
1818
1842
  instance.__hooks = null;
1819
1843
  }
1844
+ function runHooks(obj, hookName, handler) {
1845
+ for (var _len5 = arguments.length, args = new Array(_len5 > 3 ? _len5 - 3 : 0), _key5 = 3; _key5 < _len5; _key5++) {
1846
+ args[_key5 - 3] = arguments[_key5];
1847
+ }
1848
+ if (obj.__hooks && Array.isArray(obj.__hooks[hookName])) {
1849
+ var hooks = obj.__hooks[hookName];
1850
+ var index = -1;
1851
+ var runHooksRecursive = function runHooksRecursive2(obj2, hookName2, handler2) {
1852
+ for (var _len6 = arguments.length, args2 = new Array(_len6 > 3 ? _len6 - 3 : 0), _key6 = 3; _key6 < _len6; _key6++) {
1853
+ args2[_key6 - 3] = arguments[_key6];
1854
+ }
1855
+ index++;
1856
+ if (hooks.length === 0 || index === hooks.length) {
1857
+ return handler2.call.apply(handler2, [obj2, obj2].concat(args2));
1858
+ }
1859
+ var hook2 = hooks[index];
1860
+ var ret = hook2.call.apply(hook2, [obj2, obj2].concat(args2));
1861
+ if (ret && ret.then) {
1862
+ return ret.then(function(data) {
1863
+ return data === false ? null : runHooksRecursive2.apply(void 0, [obj2, hookName2, handler2].concat(args2));
1864
+ }).catch(function(e) {
1865
+ console.warn("[runHooks]".concat(hookName2, " reject"), e.message);
1866
+ });
1867
+ } else if (ret !== false) {
1868
+ return runHooksRecursive2.apply(void 0, [obj2, hookName2, handler2].concat(args2));
1869
+ }
1870
+ };
1871
+ return runHooksRecursive.apply(void 0, [obj, hookName, handler].concat(args));
1872
+ } else {
1873
+ return handler.call.apply(handler, [obj, obj].concat(args));
1874
+ }
1875
+ }
1820
1876
  function showErrorMsg(pluginName, msg) {
1821
1877
  XG_DEBUG.logError("[".concat(pluginName, "] event or callback cant be undefined or null when call ").concat(msg));
1822
1878
  }
@@ -2056,6 +2112,18 @@
2056
2112
  }
2057
2113
  }
2058
2114
  }
2115
+ }, {
2116
+ key: "defineMethod",
2117
+ value: function defineMethod(Obj, map) {
2118
+ for (var key in map) {
2119
+ if (Object.prototype.hasOwnProperty.call(map, key) && typeof map[key] === "function") {
2120
+ Object.defineProperty(Obj, key, {
2121
+ configurable: true,
2122
+ value: map[key]
2123
+ });
2124
+ }
2125
+ }
2126
+ }
2059
2127
  }, {
2060
2128
  key: "defaultConfig",
2061
2129
  get: function get() {
@@ -2678,7 +2746,7 @@
2678
2746
  arr2[i] = arr[i];
2679
2747
  return arr2;
2680
2748
  }
2681
- function _createForOfIteratorHelper(o, allowArrayLike) {
2749
+ function _createForOfIteratorHelper$1(o, allowArrayLike) {
2682
2750
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
2683
2751
  if (!it) {
2684
2752
  if (Array.isArray(o) || (it = _unsupportedIterableToArray$1(o)) || allowArrayLike && o && typeof o.length === "number") {
@@ -2866,6 +2934,21 @@
2866
2934
  length: Buffer2.totalLength && Buffer2.totalLength(buffers)
2867
2935
  };
2868
2936
  }
2937
+ }, {
2938
+ key: "isBuffered",
2939
+ value: function isBuffered(media, pos) {
2940
+ if (media) {
2941
+ var buffered = Buffer2.get(media);
2942
+ if (buffered !== null && buffered !== void 0 && buffered.length) {
2943
+ for (var i = 0; i < buffered.length; i++) {
2944
+ if (pos >= buffered.start(i) && pos <= buffered.end(i)) {
2945
+ return true;
2946
+ }
2947
+ }
2948
+ }
2949
+ }
2950
+ return false;
2951
+ }
2869
2952
  }]);
2870
2953
  return Buffer2;
2871
2954
  }();
@@ -3018,7 +3101,7 @@
3018
3101
  this.logCache.apply(this, [LogCacheLevel.DEBUG].concat(args));
3019
3102
  if (Logger2.disabled)
3020
3103
  return;
3021
- (_console = console).debug.apply(_console, [this._prefix, nowTime$1()].concat(args));
3104
+ (_console = console).debug.apply(_console, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
3022
3105
  }
3023
3106
  }, {
3024
3107
  key: "log",
@@ -3030,7 +3113,7 @@
3030
3113
  this.logCache.apply(this, [LogCacheLevel.LOG].concat(args));
3031
3114
  if (Logger2.disabled)
3032
3115
  return;
3033
- (_console2 = console).log.apply(_console2, [this._prefix, nowTime$1()].concat(args));
3116
+ (_console2 = console).log.apply(_console2, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
3034
3117
  }
3035
3118
  }, {
3036
3119
  key: "warn",
@@ -3042,7 +3125,7 @@
3042
3125
  this.logCache.apply(this, [LogCacheLevel.WARN].concat(args));
3043
3126
  if (Logger2.disabled)
3044
3127
  return;
3045
- (_console3 = console).warn.apply(_console3, [this._prefix, nowTime$1()].concat(args));
3128
+ (_console3 = console).warn.apply(_console3, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
3046
3129
  }
3047
3130
  }, {
3048
3131
  key: "error",
@@ -3054,7 +3137,7 @@
3054
3137
  this.logCache.apply(this, [LogCacheLevel.ERROR].concat(args));
3055
3138
  if (Logger2.disabled)
3056
3139
  return;
3057
- (_console4 = console).error.apply(_console4, [this._prefix, nowTime$1()].concat(args));
3140
+ (_console4 = console).error.apply(_console4, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
3058
3141
  }
3059
3142
  }, {
3060
3143
  key: "logCache",
@@ -3069,7 +3152,7 @@
3069
3152
  var finLogText = logText.map(function(item) {
3070
3153
  return logable(item);
3071
3154
  });
3072
- text = this._prefix + nowTime$1() + JSON.stringify(finLogText);
3155
+ text = "[".concat(nowTime$1(), "]") + this._prefix + JSON.stringify(finLogText);
3073
3156
  } catch (e) {
3074
3157
  return;
3075
3158
  }
@@ -3985,8 +4068,8 @@
3985
4068
  response
3986
4069
  };
3987
4070
  }
3988
- function calculateSpeed(byteLen, millisec) {
3989
- return Math.round(byteLen * 8 * 1e3 / millisec / 1024);
4071
+ function calculateSpeed(byteLen, milliSecond) {
4072
+ return Math.round(byteLen * 8 * 1e3 / milliSecond / 1024);
3990
4073
  }
3991
4074
  var EVENT = {
3992
4075
  ERROR: "error",
@@ -3998,6 +4081,7 @@
3998
4081
  SOURCEBUFFER_CREATED: "core.sourcebuffercreated",
3999
4082
  MEDIASOURCE_OPENED: "core.mediasourceopened",
4000
4083
  ANALYZE_DURATION_EXCEEDED: "core.analyzedurationexceeded",
4084
+ APPEND_BUFFER: "core.appendbuffer",
4001
4085
  REMOVE_BUFFER: "core.removebuffer",
4002
4086
  BUFFEREOS: "core.buffereos",
4003
4087
  KEYFRAME: "core.keyframe",
@@ -4770,7 +4854,7 @@
4770
4854
  value: function _getHeaders(xhr) {
4771
4855
  var headerLines = xhr.getAllResponseHeaders().trim().split("\r\n");
4772
4856
  var headers = {};
4773
- var _iterator = _createForOfIteratorHelper(headerLines), _step;
4857
+ var _iterator = _createForOfIteratorHelper$1(headerLines), _step;
4774
4858
  try {
4775
4859
  for (_iterator.s(); !(_step = _iterator.n()).done; ) {
4776
4860
  var header = _step.value;
@@ -4792,7 +4876,7 @@
4792
4876
  }]);
4793
4877
  return XhrLoader2;
4794
4878
  }(EventEmitter);
4795
- var _excluded$1 = ["retry", "retryDelay", "onRetryError", "transformError"];
4879
+ var _excluded$2 = ["retry", "retryDelay", "onRetryError", "transformError"];
4796
4880
  var Task = /* @__PURE__ */ function() {
4797
4881
  function Task2(type, config) {
4798
4882
  _classCallCheck$1(this, Task2);
@@ -4812,7 +4896,7 @@
4812
4896
  key: "exec",
4813
4897
  value: function exec() {
4814
4898
  var _this = this;
4815
- var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties(_this$_config, _excluded$1);
4899
+ var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties(_this$_config, _excluded$2);
4816
4900
  var request = /* @__PURE__ */ function() {
4817
4901
  var _ref = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee() {
4818
4902
  var response, error, isRetry;
@@ -5608,6 +5692,60 @@
5608
5692
  function _nonIterableRest() {
5609
5693
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
5610
5694
  }
5695
+ function _createForOfIteratorHelper(o, allowArrayLike) {
5696
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
5697
+ if (!it) {
5698
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
5699
+ if (it)
5700
+ o = it;
5701
+ var i = 0;
5702
+ var F = function() {
5703
+ };
5704
+ return {
5705
+ s: F,
5706
+ n: function() {
5707
+ if (i >= o.length)
5708
+ return {
5709
+ done: true
5710
+ };
5711
+ return {
5712
+ done: false,
5713
+ value: o[i++]
5714
+ };
5715
+ },
5716
+ e: function(e) {
5717
+ throw e;
5718
+ },
5719
+ f: F
5720
+ };
5721
+ }
5722
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
5723
+ }
5724
+ var normalCompletion = true, didErr = false, err;
5725
+ return {
5726
+ s: function() {
5727
+ it = it.call(o);
5728
+ },
5729
+ n: function() {
5730
+ var step = it.next();
5731
+ normalCompletion = step.done;
5732
+ return step;
5733
+ },
5734
+ e: function(e) {
5735
+ didErr = true;
5736
+ err = e;
5737
+ },
5738
+ f: function() {
5739
+ try {
5740
+ if (!normalCompletion && it.return != null)
5741
+ it.return();
5742
+ } finally {
5743
+ if (didErr)
5744
+ throw err;
5745
+ }
5746
+ }
5747
+ };
5748
+ }
5611
5749
  function _toPrimitive(input, hint) {
5612
5750
  if (typeof input !== "object" || input === null)
5613
5751
  return input;
@@ -5630,13 +5768,15 @@
5630
5768
  METADATA: "metadata"
5631
5769
  };
5632
5770
  var VideoCodecType = {
5771
+ AV1: "av1",
5633
5772
  AVC: "avc",
5634
5773
  HEVC: "hevc"
5635
5774
  };
5636
5775
  var AudioCodecType = {
5637
5776
  AAC: "aac",
5638
5777
  G711PCMA: "g7110a",
5639
- G711PCMU: "g7110m"
5778
+ G711PCMU: "g7110m",
5779
+ OPUS: "opus"
5640
5780
  };
5641
5781
  var WarningType = {
5642
5782
  LARGE_AV_SHIFT: "LARGE_AV_SHIFT",
@@ -5676,6 +5816,7 @@
5676
5816
  _defineProperty(this, "isVideoEncryption", false);
5677
5817
  _defineProperty(this, "isAudioEncryption", false);
5678
5818
  _defineProperty(this, "isVideo", true);
5819
+ _defineProperty(this, "lastKeyFrameDts", 0);
5679
5820
  _defineProperty(this, "kid", null);
5680
5821
  _defineProperty(this, "pssh", null);
5681
5822
  _defineProperty(this, "ext", void 0);
@@ -5718,6 +5859,9 @@
5718
5859
  }, {
5719
5860
  key: "exist",
5720
5861
  value: function exist() {
5862
+ if (/av01/.test(this.codec)) {
5863
+ return true;
5864
+ }
5721
5865
  return !!(this.pps.length && this.sps.length && this.codec);
5722
5866
  }
5723
5867
  }, {
@@ -5781,7 +5925,7 @@
5781
5925
  }, {
5782
5926
  key: "exist",
5783
5927
  value: function exist() {
5784
- return !!(this.sampleRate && this.channelCount && this.codec && this.codecType === AudioCodecType.AAC);
5928
+ return !!(this.sampleRate && this.channelCount && this.codec && (this.codecType === AudioCodecType.AAC || this.codecType === AudioCodecType.G711PCMA || this.codecType === AudioCodecType.G711PCMU || this.codecType === AudioCodecType.OPUS));
5785
5929
  }
5786
5930
  }, {
5787
5931
  key: "hasSample",
@@ -5986,7 +6130,7 @@
5986
6130
  continue;
5987
6131
  }
5988
6132
  frameLength = (data[i + 3] & 3) << 11 | data[i + 4] << 3 | (data[i + 5] & 224) >> 5;
5989
- if (len - i < frameLength)
6133
+ if (!frameLength || len - i < frameLength)
5990
6134
  break;
5991
6135
  protectionSkipBytes = (~data[i + 1] & 1) * 2;
5992
6136
  frames.push({
@@ -6180,6 +6324,15 @@
6180
6324
  return parseInt(item, 16);
6181
6325
  });
6182
6326
  }
6327
+ function combineToFloat(integer, decimal) {
6328
+ return Number(integer + "." + decimal);
6329
+ }
6330
+ function toDegree(matrix) {
6331
+ if (matrix.length < 5)
6332
+ return 0;
6333
+ var scaled0 = Math.hypot(matrix[0], matrix[3]), scaled1 = Math.hypot(matrix[1], matrix[4]);
6334
+ return 0 === scaled0 || 0 === scaled1 ? 0 : 180 * Math.atan2(matrix[1] / scaled1, matrix[0] / scaled0) / Math.PI;
6335
+ }
6183
6336
  var NALu = /* @__PURE__ */ function() {
6184
6337
  function NALu2() {
6185
6338
  _classCallCheck(this, NALu2);
@@ -6842,13 +6995,16 @@
6842
6995
  var AUDIO_EXCETION_LOG_EMIT_DURATION = 5 * 9e4;
6843
6996
  var MAX_VIDEO_FRAME_DURATION = 9e4;
6844
6997
  var MAX_DTS_DELTA_WITH_NEXT_CHUNK = 9e4 / 2;
6998
+ var LARGE_AV_FIRST_FRAME_FORCE_FIX_THRESHOLD = 9e4 * 5;
6845
6999
  var TsFixer = /* @__PURE__ */ function() {
6846
- function TsFixer2(videoTrack, audioTrack, metadataTrack) {
7000
+ function TsFixer2(videoTrack, audioTrack, metadataTrack, fixerConfig) {
6847
7001
  _classCallCheck(this, TsFixer2);
6848
7002
  this.videoTrack = videoTrack;
6849
7003
  this.audioTrack = audioTrack;
6850
7004
  this.metadataTrack = metadataTrack;
6851
7005
  this._baseDts = -1;
7006
+ this._baseVideoDts = -1;
7007
+ this._baseAudioDts = -1;
6852
7008
  this._baseDtsInited = false;
6853
7009
  this._audioNextPts = void 0;
6854
7010
  this._videoNextDts = void 0;
@@ -6857,6 +7013,8 @@
6857
7013
  this._lastAudioExceptionGapDot = 0;
6858
7014
  this._lastAudioExceptionOverlapDot = 0;
6859
7015
  this._lastAudioExceptionLargeGapDot = 0;
7016
+ this._needForceFixLargeGap = fixerConfig === null || fixerConfig === void 0 ? void 0 : fixerConfig.forceFixLargeGap;
7017
+ this._largeGapThreshold = (fixerConfig === null || fixerConfig === void 0 ? void 0 : fixerConfig.largeGapThreshold) || LARGE_AV_FIRST_FRAME_FORCE_FIX_THRESHOLD;
6860
7018
  }
6861
7019
  _createClass(TsFixer2, [{
6862
7020
  key: "fix",
@@ -6884,10 +7042,16 @@
6884
7042
  if (discontinuity) {
6885
7043
  this._calculateBaseDts(this.audioTrack, this.videoTrack);
6886
7044
  this._baseDts -= startTime;
7045
+ this._baseAudioDts -= startTime;
7046
+ this._baseVideoDts -= startTime;
6887
7047
  }
6888
7048
  if (!contiguous) {
6889
7049
  this._videoNextDts = vaDelta > 0 ? startTime + vaDelta : startTime;
6890
7050
  this._audioNextPts = vaDelta > 0 ? startTime : startTime - vaDelta;
7051
+ if (this._needForceFixLargeGap) {
7052
+ this._videoNextDts = 0;
7053
+ this._audioNextPts = 0;
7054
+ }
6891
7055
  var vDeltaToNextDts = firstVideoSample ? firstVideoSample.dts - this._baseDts - this._videoNextDts : 0;
6892
7056
  var aDeltaToNextDts = firstAudioSample ? firstAudioSample.pts - this._baseDts - this._audioNextPts : 0;
6893
7057
  if (Math.abs(vDeltaToNextDts || aDeltaToNextDts) > MAX_VIDEO_FRAME_DURATION) {
@@ -6920,8 +7084,8 @@
6920
7084
  if (!samples.length)
6921
7085
  return;
6922
7086
  samples.forEach(function(x) {
6923
- x.dts -= _this2._baseDts;
6924
- x.pts -= _this2._baseDts;
7087
+ x.dts -= _this2._needForceFixLargeGap ? _this2._baseVideoDts : _this2._baseDts;
7088
+ x.pts -= _this2._needForceFixLargeGap ? _this2._baseVideoDts : _this2._baseDts;
6925
7089
  });
6926
7090
  if (this._videoNextDts === void 0) {
6927
7091
  var samp0 = samples[0];
@@ -7014,7 +7178,7 @@
7014
7178
  if (!samples.length)
7015
7179
  return;
7016
7180
  samples.forEach(function(x) {
7017
- x.pts -= _this3._baseDts;
7181
+ x.pts -= _this3._needForceFixLargeGap ? _this3._baseAudioDts : _this3._baseDts;
7018
7182
  x.dts = x.pts;
7019
7183
  });
7020
7184
  this._doFixAudioInternal(audioTrack, samples, 9e4);
@@ -7031,12 +7195,15 @@
7031
7195
  var videoBaseDts = Infinity;
7032
7196
  if (audioSamps.length) {
7033
7197
  audioTrack.baseDts = audioBasePts = audioSamps[0].pts;
7198
+ this._baseAudioDts = audioBasePts;
7034
7199
  }
7035
7200
  if (videoSamps.length) {
7036
7201
  videoTrack.baseDts = videoBaseDts = videoSamps[0].dts;
7202
+ this._baseVideoDts = videoBaseDts;
7037
7203
  }
7038
7204
  this._baseDts = Math.min(audioBasePts, videoBaseDts);
7039
7205
  var delta = videoBaseDts - audioBasePts;
7206
+ var largeGap = false;
7040
7207
  if (Number.isFinite(delta) && Math.abs(delta) > LARGE_AV_FIRST_FRAME_GAP) {
7041
7208
  videoTrack.warnings.push({
7042
7209
  type: WarningType.LARGE_AV_SHIFT,
@@ -7046,6 +7213,16 @@
7046
7213
  delta
7047
7214
  });
7048
7215
  }
7216
+ if (Number.isFinite(delta) && Math.abs(delta) > this._largeGapThreshold * MAX_SILENT_FRAME_DURATION) {
7217
+ largeGap = true;
7218
+ }
7219
+ if (!this._baseDtsInited) {
7220
+ if (largeGap && this._needForceFixLargeGap) {
7221
+ this._needForceFixLargeGap = true;
7222
+ } else {
7223
+ this._needForceFixLargeGap = false;
7224
+ }
7225
+ }
7049
7226
  this._baseDtsInited = true;
7050
7227
  return true;
7051
7228
  }
@@ -7139,6 +7316,7 @@
7139
7316
  var logger$4 = new Logger$1("TsDemuxer");
7140
7317
  var TsDemuxer = /* @__PURE__ */ function() {
7141
7318
  function TsDemuxer2(videoTrack, audioTrack, metadataTrack) {
7319
+ var fixerConfig = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
7142
7320
  _classCallCheck(this, TsDemuxer2);
7143
7321
  _defineProperty(this, "_pmtId", -1);
7144
7322
  _defineProperty(this, "_remainingPacketData", null);
@@ -7148,7 +7326,7 @@
7148
7326
  this.videoTrack = videoTrack || new VideoTrack();
7149
7327
  this.audioTrack = audioTrack || new AudioTrack();
7150
7328
  this.metadataTrack = metadataTrack || new MetadataTrack();
7151
- this._fixer = new TsFixer(this.videoTrack, this.audioTrack, this.metadataTrack);
7329
+ this._fixer = new TsFixer(this.videoTrack, this.audioTrack, this.metadataTrack, fixerConfig);
7152
7330
  }
7153
7331
  _createClass(TsDemuxer2, [{
7154
7332
  key: "demux",
@@ -7495,6 +7673,207 @@
7495
7673
  }]);
7496
7674
  return TsDemuxer2;
7497
7675
  }();
7676
+ var ByteReader = /* @__PURE__ */ function() {
7677
+ function ByteReader2(buf, offset, len) {
7678
+ _classCallCheck(this, ByteReader2);
7679
+ this.dv = new DataView(buf);
7680
+ this.start = this.offset = offset || this.dv.byteOffset;
7681
+ this.end = len ? this.start + len : this.start + this.dv.byteLength;
7682
+ }
7683
+ _createClass(ByteReader2, [{
7684
+ key: "buffer",
7685
+ get: function get() {
7686
+ return this.dv.buffer;
7687
+ }
7688
+ }, {
7689
+ key: "unreadLength",
7690
+ get: function get() {
7691
+ return Math.max(this.end - this.offset, 0);
7692
+ }
7693
+ }, {
7694
+ key: "size",
7695
+ get: function get() {
7696
+ return this.end - this.start;
7697
+ }
7698
+ }, {
7699
+ key: "readFloat",
7700
+ value: function readFloat(byteNum) {
7701
+ var val = 0;
7702
+ switch (byteNum) {
7703
+ case 4:
7704
+ val = this.dv.getFloat32(this.offset);
7705
+ break;
7706
+ case 8:
7707
+ val = this.dv.getFloat64(this.offset);
7708
+ break;
7709
+ default:
7710
+ throw new Error("read ".concat(byteNum, "-byte float is not supported"));
7711
+ }
7712
+ this.offset += byteNum;
7713
+ return val;
7714
+ }
7715
+ }, {
7716
+ key: "back",
7717
+ value: function back(byteNum) {
7718
+ this.offset -= byteNum;
7719
+ }
7720
+ }, {
7721
+ key: "skip",
7722
+ value: function skip(byteNum) {
7723
+ this.offset += byteNum;
7724
+ }
7725
+ }, {
7726
+ key: "readInt",
7727
+ value: function readInt(byteNum) {
7728
+ var offset = this.offset;
7729
+ this.offset += byteNum;
7730
+ switch (byteNum) {
7731
+ case 1:
7732
+ return this.dv.getInt8(offset);
7733
+ case 2:
7734
+ return this.dv.getInt16(offset);
7735
+ case 4:
7736
+ return this.dv.getInt32(offset);
7737
+ default:
7738
+ throw new Error("read ".concat(byteNum, "-byte integers is not supported"));
7739
+ }
7740
+ }
7741
+ }, {
7742
+ key: "read",
7743
+ value: function read(byteNum) {
7744
+ var offset = this.offset;
7745
+ this.offset += byteNum;
7746
+ switch (byteNum) {
7747
+ case 1:
7748
+ return this.dv.getUint8(offset);
7749
+ case 2:
7750
+ return this.dv.getUint16(offset);
7751
+ case 3:
7752
+ return (this.dv.getUint16(offset) << 8) + this.dv.getUint8(offset + 2);
7753
+ case 4:
7754
+ return this.dv.getUint32(offset);
7755
+ default:
7756
+ this.back(byteNum - 4);
7757
+ return this.read(byteNum - 4) + this.dv.getUint32(offset) * Math.pow(256, byteNum - 4);
7758
+ }
7759
+ }
7760
+ }, {
7761
+ key: "write",
7762
+ value: function write(byteNum, val) {
7763
+ var offset = this.offset;
7764
+ this.offset += byteNum;
7765
+ switch (byteNum) {
7766
+ case 1:
7767
+ return this.dv.setUint8(offset, val);
7768
+ case 2:
7769
+ return this.dv.setUint16(offset, val);
7770
+ case 3:
7771
+ return this.dv.setUint8(offset, val >>> 16), this.dv.setUint16(offset + 1, 65535 & val);
7772
+ case 4:
7773
+ return this.dv.setUint32(offset, val);
7774
+ default:
7775
+ throw new Error("write ".concat(byteNum, "-byte integers is not supported"));
7776
+ }
7777
+ }
7778
+ }, {
7779
+ key: "readToBuffer",
7780
+ value: function readToBuffer(len) {
7781
+ var buffer;
7782
+ if (this.offset || len) {
7783
+ buffer = this.dv.buffer.slice(this.offset, len ? this.offset + len : this.end);
7784
+ } else {
7785
+ buffer = this.dv.buffer;
7786
+ }
7787
+ this.offset += buffer.byteLength;
7788
+ return buffer;
7789
+ }
7790
+ }, {
7791
+ key: "readToUint8",
7792
+ value: function readToUint8(len) {
7793
+ var uint8 = new Uint8Array(this.dv.buffer, this.offset, len || this.unreadLength);
7794
+ this.offset += uint8.byteLength;
7795
+ return uint8;
7796
+ }
7797
+ }, {
7798
+ key: "readString",
7799
+ value: function readString(len) {
7800
+ var i = 0, str = "";
7801
+ for (; i < len; i++) {
7802
+ str += String.fromCharCode(this.dv.getUint8(this.offset));
7803
+ this.offset++;
7804
+ }
7805
+ return str;
7806
+ }
7807
+ }], [{
7808
+ key: "fromUint8",
7809
+ value: function fromUint8(uint8) {
7810
+ return new ByteReader2(uint8.buffer, uint8.byteOffset, uint8.byteLength);
7811
+ }
7812
+ }, {
7813
+ key: "concatUint8s",
7814
+ value: function concatUint8s(args) {
7815
+ var uint8 = new Uint8Array(args.reduce(function(ret, v) {
7816
+ return ret + v.byteLength;
7817
+ }, 0));
7818
+ var offset = 0;
7819
+ args.forEach(function(v) {
7820
+ uint8.set(v, offset);
7821
+ offset += v.byteLength;
7822
+ });
7823
+ return uint8;
7824
+ }
7825
+ }, {
7826
+ key: "concatUint8",
7827
+ value: function concatUint8() {
7828
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
7829
+ args[_key] = arguments[_key];
7830
+ }
7831
+ return this.concatUint8s(args);
7832
+ }
7833
+ }]);
7834
+ return ByteReader2;
7835
+ }();
7836
+ var BitReader = /* @__PURE__ */ function() {
7837
+ function BitReader2(val, size) {
7838
+ _classCallCheck(this, BitReader2);
7839
+ this.offset = 0;
7840
+ this.val = val;
7841
+ this.size = size;
7842
+ }
7843
+ _createClass(BitReader2, [{
7844
+ key: "skip",
7845
+ value: function skip(len) {
7846
+ this.offset += len;
7847
+ }
7848
+ }, {
7849
+ key: "read",
7850
+ value: function read(len) {
7851
+ var unreadLength = this.size - this.offset - len;
7852
+ if (unreadLength >= 0) {
7853
+ var bits = 0, i = 0;
7854
+ this.offset += len;
7855
+ if (this.size > 31) {
7856
+ for (; i < len; i++) {
7857
+ bits += Math.pow(2, i);
7858
+ }
7859
+ return this.val / Math.pow(2, unreadLength) & bits;
7860
+ } else {
7861
+ for (; i < len; i++) {
7862
+ bits += 1 << i;
7863
+ }
7864
+ return this.val >>> unreadLength & bits;
7865
+ }
7866
+ }
7867
+ throw new Error("the number of the read operation exceeds the total length limit of bits");
7868
+ }
7869
+ }], [{
7870
+ key: "fromByte",
7871
+ value: function fromByte(byte, len) {
7872
+ return new BitReader2(byte.read(len), len << 3);
7873
+ }
7874
+ }]);
7875
+ return BitReader2;
7876
+ }();
7498
7877
  var MP4Parser = /* @__PURE__ */ function() {
7499
7878
  function MP4Parser2() {
7500
7879
  _classCallCheck(this, MP4Parser2);
@@ -7652,18 +8031,36 @@
7652
8031
  key: "tkhd",
7653
8032
  value: function tkhd(box) {
7654
8033
  return parseBox(box, true, function(ret, data) {
7655
- var start = 0;
8034
+ var byte = ByteReader.fromUint8(data);
7656
8035
  if (ret.version === 1) {
7657
- ret.trackId = readBig32(data, 16);
7658
- ret.duration = readBig64(data, 24);
7659
- start += 32;
8036
+ byte.read(8);
8037
+ byte.read(8);
8038
+ ret.trackId = byte.read(4);
8039
+ byte.read(4);
8040
+ ret.duration = byte.read(8);
7660
8041
  } else {
7661
- ret.trackId = readBig32(data, 8);
7662
- ret.duration = readBig32(data, 16);
7663
- start += 20;
8042
+ byte.read(4);
8043
+ byte.read(4);
8044
+ ret.trackId = byte.read(4);
8045
+ byte.read(4);
8046
+ ret.duration = byte.read(4);
7664
8047
  }
7665
- ret.width = readBig32(data, start + 52);
7666
- ret.height = readBig32(data, start + 56);
8048
+ byte.skip(16);
8049
+ ret.matrix = [];
8050
+ for (var i = 0; i < 36; i++) {
8051
+ ret.matrix.push(byte.read(1));
8052
+ }
8053
+ byte.back(36);
8054
+ var caculatedMatrix = [];
8055
+ for (var _i = 0, int32; _i < 3; _i++) {
8056
+ caculatedMatrix.push(combineToFloat(byte.readInt(2), byte.readInt(2)));
8057
+ caculatedMatrix.push(combineToFloat(byte.readInt(2), byte.readInt(2)));
8058
+ int32 = byte.readInt(4);
8059
+ caculatedMatrix.push(combineToFloat(int32 >> 30, int32 & 1073741823));
8060
+ }
8061
+ ret.rotation = toDegree(caculatedMatrix);
8062
+ ret.width = byte.read(4);
8063
+ ret.height = byte.read(4);
7667
8064
  });
7668
8065
  }
7669
8066
  }, {
@@ -7793,7 +8190,7 @@
7793
8190
  if (ret.version > 0) {
7794
8191
  var numKeyIds = readBig32(data, start);
7795
8192
  start += 4;
7796
- for (var _i = 0; _i < ("" + numKeyIds).length; _i++) {
8193
+ for (var _i2 = 0; _i2 < ("" + numKeyIds).length; _i2++) {
7797
8194
  for (var j = 0; j < 16; j++) {
7798
8195
  var keyId = data[start];
7799
8196
  start += 1;
@@ -7816,6 +8213,8 @@
7816
8213
  ret.entryCount = readBig32(data);
7817
8214
  ret.entries = MP4Parser2.findBox(data.subarray(4), [], start + 4).map(function(b) {
7818
8215
  switch (b.type) {
8216
+ case "av01":
8217
+ return MP4Parser2.av01(b);
7819
8218
  case "avc1":
7820
8219
  case "avc2":
7821
8220
  case "avc3":
@@ -7895,6 +8294,69 @@
7895
8294
  }
7896
8295
  });
7897
8296
  }
8297
+ }, {
8298
+ key: "colr",
8299
+ value: function colr(box) {
8300
+ return parseBox(box, false, function(ret, data) {
8301
+ var byte = ByteReader.fromUint8(data);
8302
+ ret.data = box.data;
8303
+ ret.colorType = byte.readString(4);
8304
+ if (ret.colorType === "nclx") {
8305
+ ret.colorPrimaries = byte.read(2);
8306
+ ret.transferCharacteristics = byte.read(2);
8307
+ ret.matrixCoefficients = byte.read(2);
8308
+ ret.fullRangeFlag = byte.read(1) >> 7;
8309
+ } else if (ret.colorType === "rICC" || ret.colorType === "prof") {
8310
+ ret.iccProfile = data.readToUint8();
8311
+ }
8312
+ });
8313
+ }
8314
+ }, {
8315
+ key: "av01",
8316
+ value: function av01(box) {
8317
+ return parseBox(box, false, function(ret, data, start) {
8318
+ var bodyStart = parseVisualSampleEntry(ret, data);
8319
+ var bodyData = data.subarray(bodyStart);
8320
+ start += bodyStart;
8321
+ ret.av1C = MP4Parser2.av1C(MP4Parser2.findBox(bodyData, ["av1C"], start)[0]);
8322
+ ret.colr = MP4Parser2.colr(MP4Parser2.findBox(bodyData, ["colr"], start)[0]);
8323
+ });
8324
+ }
8325
+ }, {
8326
+ key: "av1C",
8327
+ value: function av1C(box) {
8328
+ return parseBox(box, false, function(ret, data) {
8329
+ ret.data = box.data;
8330
+ var byte = ByteReader.fromUint8(data);
8331
+ var bit = BitReader.fromByte(byte, 4);
8332
+ ret.marker = bit.read(1);
8333
+ ret.version = bit.read(7);
8334
+ ret.seqProfile = bit.read(3);
8335
+ ret.seqLevelIdx0 = bit.read(5);
8336
+ ret.seqTier0 = bit.read(1);
8337
+ ret.highBitdepth = bit.read(1);
8338
+ ret.twelveBit = bit.read(1);
8339
+ ret.monochrome = bit.read(1);
8340
+ ret.chromaSubsamplingX = bit.read(1);
8341
+ ret.chromaSubsamplingY = bit.read(1);
8342
+ ret.chromaSamplePosition = bit.read(2);
8343
+ ret.reserved = bit.read(3);
8344
+ ret.initialPresentationDelayPresent = bit.read(1);
8345
+ if (ret.initialPresentationDelayPresent) {
8346
+ ret.initialPresentationDelayMinusOne = bit.read(4);
8347
+ } else {
8348
+ ret.initialPresentationDelayMinusOne = 0;
8349
+ }
8350
+ ret.configOBUs = byte.readToUint8();
8351
+ var bitdepth;
8352
+ if (ret.seqLevelIdx0 === 2 && ret.highBitdepth === 1) {
8353
+ bitdepth = ret.twelveBit === 1 ? "12" : "10";
8354
+ } else if (ret.seqProfile <= 2) {
8355
+ bitdepth = ret.highBitdepth === 1 ? "10" : "08";
8356
+ }
8357
+ ret.codec = ["av01", ret.seqProfile, (ret.seqLevelIdx0 < 10 ? "0" + ret.seqLevelIdx0 : ret.seqLevelIdx0) + (ret.seqTier0 ? "H" : "M"), bitdepth].join(".");
8358
+ });
8359
+ }
7898
8360
  }, {
7899
8361
  key: "avc1",
7900
8362
  value: function avc1(box) {
@@ -7929,7 +8391,7 @@
7929
8391
  ret.ppsLength = data[start];
7930
8392
  start += 1;
7931
8393
  ret.pps = [];
7932
- for (var _i2 = 0; _i2 < ret.ppsLength; _i2++) {
8394
+ for (var _i3 = 0; _i3 < ret.ppsLength; _i3++) {
7933
8395
  var _size = readBig16(data, start);
7934
8396
  start += 2;
7935
8397
  ret.pps.push(data.subarray(start, start += _size));
@@ -8098,7 +8560,7 @@
8098
8560
  start += 8;
8099
8561
  }
8100
8562
  } else {
8101
- for (var _i3 = 0; _i3 < entryCount; _i3++) {
8563
+ for (var _i4 = 0; _i4 < entryCount; _i4++) {
8102
8564
  entries.push({
8103
8565
  count: readBig32(data, start),
8104
8566
  offset: -(~readBig32(data, start + 4) + 1)
@@ -8320,13 +8782,20 @@
8320
8782
  v.mvhdTimecale = moov.mvhd.timescale;
8321
8783
  v.timescale = v.formatTimescale = vTrack.mdia.mdhd.timescale;
8322
8784
  v.duration = vTrack.mdia.mdhd.duration || v.mvhdDurtion / v.mvhdTimecale * v.timescale;
8785
+ v.rotation = vTrack.tkhd.rotation;
8786
+ v.matrix = vTrack.tkhd.matrix;
8323
8787
  var e1 = vTrack.mdia.minf.stbl.stsd.entries[0];
8324
8788
  v.width = e1.width;
8325
8789
  v.height = e1.height;
8326
8790
  if (e1.pasp) {
8327
8791
  v.sarRatio = [e1.pasp.hSpacing, e1.pasp.vSpacing];
8328
8792
  }
8329
- if (e1.hvcC) {
8793
+ if (e1.av1C) {
8794
+ v.codecType = VideoCodecType.AV1;
8795
+ v.codec = e1.av1C.codec;
8796
+ v.av1C = e1.av1C.data;
8797
+ v.colr = e1.colr.data;
8798
+ } else if (e1.hvcC) {
8330
8799
  v.codecType = VideoCodecType.HEVC;
8331
8800
  v.codec = e1.hvcC.codec;
8332
8801
  v.vps = e1.hvcC.vps;
@@ -8645,8 +9114,9 @@
8645
9114
  function parseBox(box, isFullBox, parse2) {
8646
9115
  if (!box)
8647
9116
  return;
8648
- if (box.size !== box.data.length)
9117
+ if (box.size !== box.data.length) {
8649
9118
  throw new Error("box ".concat(box.type, " size !== data.length"));
9119
+ }
8650
9120
  var ret = {
8651
9121
  start: box.start,
8652
9122
  size: box.size,
@@ -8685,11 +9155,167 @@
8685
9155
  var FMP4Demuxer = /* @__PURE__ */ function() {
8686
9156
  function FMP4Demuxer2(videoTrack, audioTrack, metadataTrack) {
8687
9157
  _classCallCheck(this, FMP4Demuxer2);
9158
+ _defineProperty(this, "__loadedMoofWraps", []);
9159
+ _defineProperty(this, "__lastRemainData", null);
9160
+ _defineProperty(this, "__lastRemainDataStart", 0);
9161
+ _defineProperty(this, "__nextMoofStart", -1);
8688
9162
  this.videoTrack = videoTrack || new VideoTrack();
8689
9163
  this.audioTrack = audioTrack || new AudioTrack();
8690
9164
  this.metadataTrack = metadataTrack || new MetadataTrack();
8691
9165
  }
8692
9166
  _createClass(FMP4Demuxer2, [{
9167
+ key: "demuxPart",
9168
+ value: function demuxPart(partData, partDataStart, moov) {
9169
+ var _this = this;
9170
+ var videoTrack = this.videoTrack, audioTrack = this.audioTrack;
9171
+ var videoExist = videoTrack.exist();
9172
+ var audioExist = audioTrack.exist();
9173
+ var isAV01 = /av01/.test(videoTrack.codec);
9174
+ videoTrack.samples = [];
9175
+ audioTrack.samples = [];
9176
+ var data = partData;
9177
+ var dataStart = partDataStart;
9178
+ if (this.__lastRemainData) {
9179
+ var lastRemainDataEnd = this.__lastRemainDataStart + this.__lastRemainData.byteLength;
9180
+ var continuous = partDataStart <= lastRemainDataEnd && partDataStart > this.__lastRemainDataStart && partDataStart + partData.byteLength > lastRemainDataEnd;
9181
+ if (continuous) {
9182
+ var noDuplicateData = partData.subarray(this.__lastRemainData.byteLength + this.__lastRemainDataStart - partDataStart);
9183
+ data = concatUint8Array(this.__lastRemainData, noDuplicateData);
9184
+ dataStart = this.__lastRemainDataStart;
9185
+ this.__lastRemainData = null;
9186
+ } else {
9187
+ this.__lastRemainData = null;
9188
+ this.__lastRemainDataStart = 0;
9189
+ this.__nextMoofStart = -1;
9190
+ }
9191
+ }
9192
+ if (!moov) {
9193
+ var moovBox = MP4Parser.findBox(data, ["moov"])[0];
9194
+ if (!moovBox)
9195
+ throw new Error("cannot found moov box");
9196
+ moov = MP4Parser.moov(moovBox);
9197
+ }
9198
+ if (data) {
9199
+ var dataEnd = dataStart + data.byteLength;
9200
+ if (!videoExist && !audioExist) {
9201
+ MP4Parser.moovToTrack(moov, videoTrack, audioTrack);
9202
+ }
9203
+ var moofBoxes = [];
9204
+ if (this.__nextMoofStart < 0) {
9205
+ MP4Parser.findBox(data, ["moof"], dataStart).forEach(function(v) {
9206
+ return moofBoxes.push(v);
9207
+ });
9208
+ } else if (this.__nextMoofStart >= dataStart && this.__nextMoofStart <= dataEnd - 8) {
9209
+ MP4Parser.findBox(data.subarray(this.__nextMoofStart - dataStart), ["moof"], this.__nextMoofStart).forEach(function(v) {
9210
+ return moofBoxes.push(v);
9211
+ });
9212
+ }
9213
+ moofBoxes.filter(function(moofBox) {
9214
+ return moofBox.size <= moofBox.data.length;
9215
+ }).forEach(function(moofBox) {
9216
+ var moof = MP4Parser.moof(moofBox);
9217
+ _this.__nextMoofStart = moof.start + Math.max.apply(Math, _toConsumableArray(moof.traf.map(function(v) {
9218
+ return v.trun.samples.reduce(function(ret, w) {
9219
+ return ret + w.size;
9220
+ }, v.trun.dataOffset || 0);
9221
+ })));
9222
+ _this.__loadedMoofWraps.push({
9223
+ start: moof.start,
9224
+ nextMoofStart: _this.__nextMoofStart,
9225
+ moof
9226
+ });
9227
+ _this.__loadedMoofWraps.sort(function(p, n) {
9228
+ return p.start - n.start;
9229
+ });
9230
+ });
9231
+ var _iterator = _createForOfIteratorHelper(this.__loadedMoofWraps), _step;
9232
+ try {
9233
+ var _loop = function _loop2() {
9234
+ var moofWrap = _step.value;
9235
+ if (moofWrap.start > dataEnd || moofWrap.nextMoofStart < dataStart) {
9236
+ return "continue";
9237
+ }
9238
+ var moofStart = moofWrap.start;
9239
+ var tracks = MP4Parser.moofToSamples(moofWrap.moof, videoTrack, audioTrack);
9240
+ var videoBaseMediaDecodeTime = videoTrack.baseMediaDecodeTime;
9241
+ var audioBaseMediaDecodeTime = audioTrack.baseMediaDecodeTime;
9242
+ var nalSize;
9243
+ Object.keys(tracks).forEach(function(k) {
9244
+ if (videoTrack.id == k) {
9245
+ tracks[k].some(function(x) {
9246
+ var xStart = x.offset += moofStart;
9247
+ if (xStart < dataStart) {
9248
+ return;
9249
+ }
9250
+ if (xStart + x.size > dataEnd) {
9251
+ return true;
9252
+ }
9253
+ var sample = new VideoSample((x.pts || x.dts) + videoBaseMediaDecodeTime, x.dts + videoBaseMediaDecodeTime);
9254
+ sample.duration = x.duration;
9255
+ sample.gopId = x.gopId;
9256
+ if (x.keyframe)
9257
+ sample.setToKeyframe();
9258
+ var sampleData = data.subarray(xStart - dataStart, xStart - dataStart + x.size);
9259
+ sample.data = sampleData;
9260
+ if (!isAV01) {
9261
+ var start = 0;
9262
+ var len = sampleData.length - 1;
9263
+ while (start < len) {
9264
+ nalSize = readBig32(sampleData, start);
9265
+ start += 4;
9266
+ sample.units.push(sampleData.subarray(start, start + nalSize));
9267
+ start += nalSize;
9268
+ }
9269
+ }
9270
+ _this.__lastRemainDataStart = xStart + x.size;
9271
+ videoTrack.samples.push(sample);
9272
+ });
9273
+ } else if (audioTrack.id == k) {
9274
+ tracks[k].some(function(x) {
9275
+ var xStart = x.offset + moofStart;
9276
+ if (xStart < dataStart) {
9277
+ return;
9278
+ }
9279
+ if (xStart + x.size > dataEnd) {
9280
+ return true;
9281
+ }
9282
+ var sampleData = data.subarray(xStart - dataStart, xStart - dataStart + x.size);
9283
+ audioTrack.samples.push(new AudioSample(x.dts + audioBaseMediaDecodeTime, sampleData, x.duration));
9284
+ _this.__lastRemainDataStart = xStart + x.size;
9285
+ });
9286
+ }
9287
+ });
9288
+ };
9289
+ for (_iterator.s(); !(_step = _iterator.n()).done; ) {
9290
+ var _ret = _loop();
9291
+ if (_ret === "continue")
9292
+ continue;
9293
+ }
9294
+ } catch (err) {
9295
+ _iterator.e(err);
9296
+ } finally {
9297
+ _iterator.f();
9298
+ }
9299
+ }
9300
+ if (this.__lastRemainDataStart > dataStart && this.__lastRemainDataStart < data.byteLength + dataStart) {
9301
+ this.__lastRemainData = data.subarray(this.__lastRemainDataStart - dataStart);
9302
+ } else {
9303
+ this.__lastRemainData = data;
9304
+ this.__lastRemainDataStart = dataStart;
9305
+ }
9306
+ if (videoTrack.samples.length) {
9307
+ videoTrack.baseMediaDecodeTime = videoTrack.samples[0].pts;
9308
+ }
9309
+ if (audioTrack.samples.length) {
9310
+ audioTrack.baseMediaDecodeTime = audioTrack.samples[0].pts;
9311
+ }
9312
+ return {
9313
+ videoTrack,
9314
+ audioTrack,
9315
+ metadataTrack: this.metadataTrack
9316
+ };
9317
+ }
9318
+ }, {
8693
9319
  key: "demux",
8694
9320
  value: function demux(videoData, audioData) {
8695
9321
  var videoTrack = this.videoTrack, audioTrack = this.audioTrack;
@@ -9181,10 +9807,16 @@
9181
9807
  if (track.useEME && track.enca) {
9182
9808
  content = MP42.enca(track);
9183
9809
  } else {
9184
- content = MP42.mp4a(track);
9810
+ if (track.codecType === AudioCodecType.OPUS) {
9811
+ content = MP42.opus(track);
9812
+ } else {
9813
+ content = MP42.mp4a(track);
9814
+ }
9185
9815
  }
9186
9816
  } else if (track.useEME && track.encv) {
9187
9817
  content = MP42.encv(track);
9818
+ } else if (track.av1C) {
9819
+ content = MP42.av01(track);
9188
9820
  } else {
9189
9821
  content = MP42.avc1hev1(track);
9190
9822
  }
@@ -9398,12 +10030,9 @@
9398
10030
  return MP42.box(MP42.types.sinf, content, MP42.box(MP42.types.frma, frma), MP42.box(MP42.types.schm, schm), schi);
9399
10031
  }
9400
10032
  }, {
9401
- key: "avc1hev1",
9402
- value: function avc1hev1(track) {
9403
- var isHevc = track.codecType === VideoCodecType.HEVC;
9404
- var typ = isHevc ? MP42.types.hvc1 : MP42.types.avc1;
9405
- var config = isHevc ? MP42.hvcC(track) : MP42.avcC(track);
9406
- var boxes = [new Uint8Array([
10033
+ key: "av01",
10034
+ value: function av01(track) {
10035
+ return MP42.box(MP42.types.av01, new Uint8Array([
9407
10036
  0,
9408
10037
  0,
9409
10038
  0,
@@ -9482,10 +10111,97 @@
9482
10111
  24,
9483
10112
  17,
9484
10113
  17
9485
- ]), config];
9486
- if (isHevc) {
9487
- boxes.push(MP42.box(MP42.types.fiel, new Uint8Array([1, 0])));
9488
- } else if (track.sarRatio && track.sarRatio.length > 1) {
10114
+ ]), track.av1C, track.colr);
10115
+ }
10116
+ }, {
10117
+ key: "avc1hev1",
10118
+ value: function avc1hev1(track) {
10119
+ var isHevc = track.codecType === VideoCodecType.HEVC;
10120
+ var typ = isHevc ? MP42.types.hvc1 : MP42.types.avc1;
10121
+ var config = isHevc ? MP42.hvcC(track) : MP42.avcC(track);
10122
+ var boxes = [new Uint8Array([
10123
+ 0,
10124
+ 0,
10125
+ 0,
10126
+ 0,
10127
+ 0,
10128
+ 0,
10129
+ 0,
10130
+ 1,
10131
+ 0,
10132
+ 0,
10133
+ 0,
10134
+ 0,
10135
+ 0,
10136
+ 0,
10137
+ 0,
10138
+ 0,
10139
+ 0,
10140
+ 0,
10141
+ 0,
10142
+ 0,
10143
+ 0,
10144
+ 0,
10145
+ 0,
10146
+ 0,
10147
+ track.width >> 8 & 255,
10148
+ track.width & 255,
10149
+ track.height >> 8 & 255,
10150
+ track.height & 255,
10151
+ 0,
10152
+ 72,
10153
+ 0,
10154
+ 0,
10155
+ 0,
10156
+ 72,
10157
+ 0,
10158
+ 0,
10159
+ 0,
10160
+ 0,
10161
+ 0,
10162
+ 0,
10163
+ 0,
10164
+ 1,
10165
+ 0,
10166
+ 0,
10167
+ 0,
10168
+ 0,
10169
+ 0,
10170
+ 0,
10171
+ 0,
10172
+ 0,
10173
+ 0,
10174
+ 0,
10175
+ 0,
10176
+ 0,
10177
+ 0,
10178
+ 0,
10179
+ 0,
10180
+ 0,
10181
+ 0,
10182
+ 0,
10183
+ 0,
10184
+ 0,
10185
+ 0,
10186
+ 0,
10187
+ 0,
10188
+ 0,
10189
+ 0,
10190
+ 0,
10191
+ 0,
10192
+ 0,
10193
+ 0,
10194
+ 0,
10195
+ 0,
10196
+ 0,
10197
+ 0,
10198
+ 24,
10199
+ 17,
10200
+ 17
10201
+ ]), config];
10202
+ if (isHevc) {
10203
+ boxes.push(MP42.box(MP42.types.fiel, new Uint8Array([1, 0])));
10204
+ } else if (track.sarRatio && track.sarRatio.length > 1) {
9489
10205
  boxes.push(MP42.pasp(track.sarRatio));
9490
10206
  }
9491
10207
  return MP42.box.apply(MP42, [typ].concat(boxes));
@@ -9767,6 +10483,53 @@
9767
10483
  )));
9768
10484
  return esds2;
9769
10485
  }
10486
+ }, {
10487
+ key: "opus",
10488
+ value: function opus(track) {
10489
+ var opusAudioDescription = new Uint8Array([
10490
+ 0,
10491
+ 0,
10492
+ 0,
10493
+ 0,
10494
+ 0,
10495
+ 0,
10496
+ 0,
10497
+ 1,
10498
+ 0,
10499
+ 0,
10500
+ 0,
10501
+ 0,
10502
+ 0,
10503
+ 0,
10504
+ 0,
10505
+ 0,
10506
+ 0,
10507
+ track.channelCount,
10508
+ 0,
10509
+ 16,
10510
+ 0,
10511
+ 0,
10512
+ 0,
10513
+ 0,
10514
+ track.sampleRate >> 8 & 255,
10515
+ track.sampleRate & 255,
10516
+ 0,
10517
+ 0
10518
+ ]);
10519
+ var opusSpecificConfig = track.config.length ? MP42.dOps(track) : [];
10520
+ return MP42.box(MP42.types.Opus, opusAudioDescription, opusSpecificConfig);
10521
+ }
10522
+ }, {
10523
+ key: "dOps",
10524
+ value: function dOps(track) {
10525
+ if (track.config) {
10526
+ track.config[4] = track.sampleRate >>> 24 & 255;
10527
+ track.config[5] = track.sampleRate >>> 16 & 255;
10528
+ track.config[6] = track.sampleRate >>> 8 & 255;
10529
+ track.config[7] = track.sampleRate & 255;
10530
+ return MP42.box(MP42.types.dOps, track.config);
10531
+ }
10532
+ }
9770
10533
  }, {
9771
10534
  key: "mvex",
9772
10535
  value: function mvex(tracks) {
@@ -10369,7 +11132,7 @@
10369
11132
  }]);
10370
11133
  return MP42;
10371
11134
  }();
10372
- _defineProperty(MP4, "types", ["avc1", "avcC", "hvc1", "hvcC", "dinf", "dref", "esds", "ftyp", "hdlr", "mdat", "mdhd", "mdia", "mfhd", "minf", "moof", "moov", "mp4a", "mvex", "mvhd", "pasp", "stbl", "stco", "stsc", "stsd", "stsz", "stts", "tfdt", "tfhd", "traf", "trak", "trex", "tkhd", "vmhd", "smhd", "ctts", "stss", "styp", "pssh", "sidx", "sbgp", "saiz", "saio", "senc", "trun", "encv", "enca", "sinf", "btrt", "frma", "tenc", "schm", "schi", "mehd", "fiel", "sdtp"].reduce(function(p, c) {
11135
+ _defineProperty(MP4, "types", ["Opus", "dOps", "av01", "av1C", "avc1", "avcC", "hvc1", "hvcC", "dinf", "dref", "esds", "ftyp", "hdlr", "mdat", "mdhd", "mdia", "mfhd", "minf", "moof", "moov", "mp4a", "mvex", "mvhd", "pasp", "stbl", "stco", "stsc", "stsd", "stsz", "stts", "tfdt", "tfhd", "traf", "trak", "trex", "tkhd", "vmhd", "smhd", "ctts", "stss", "styp", "pssh", "sidx", "sbgp", "saiz", "saio", "senc", "trun", "encv", "enca", "sinf", "btrt", "frma", "tenc", "schm", "schi", "mehd", "fiel", "sdtp"].reduce(function(p, c) {
10373
11136
  p[c] = [c.charCodeAt(0), c.charCodeAt(1), c.charCodeAt(2), c.charCodeAt(3)];
10374
11137
  return p;
10375
11138
  }, /* @__PURE__ */ Object.create(null)));
@@ -10704,30 +11467,46 @@
10704
11467
  };
10705
11468
  }
10706
11469
  var samples = track.samples;
11470
+ var isAV01 = /av01/.test(track.codec);
10707
11471
  var mdatSize = 0;
10708
- samples.forEach(function(s) {
10709
- mdatSize += s.units.reduce(function(t, c) {
10710
- return t + c.byteLength;
10711
- }, 0);
10712
- mdatSize += s.units.length * 4;
10713
- });
10714
- var mdata = new Uint8Array(mdatSize);
10715
- var mdatView = new DataView(mdata.buffer);
10716
- var _loop = function _loop2(_offset, _sample) {
10717
- _sample = samples[i];
10718
- var sampleSize = 0;
10719
- _sample.units.forEach(function(u) {
10720
- mdatView.setUint32(_offset, u.byteLength);
10721
- _offset += 4;
10722
- mdata.set(u, _offset);
10723
- _offset += u.byteLength;
10724
- sampleSize += 4 + u.byteLength;
11472
+ if (isAV01) {
11473
+ samples.forEach(function(s) {
11474
+ mdatSize += s.data.byteLength;
10725
11475
  });
10726
- _sample.size = sampleSize;
10727
- offset = _offset, sample = _sample;
10728
- };
10729
- for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
10730
- _loop(offset, sample);
11476
+ } else {
11477
+ samples.forEach(function(s) {
11478
+ mdatSize += s.units.reduce(function(t, c) {
11479
+ return t + c.byteLength;
11480
+ }, 0);
11481
+ mdatSize += s.units.length * 4;
11482
+ });
11483
+ }
11484
+ var mdata = new Uint8Array(mdatSize);
11485
+ if (isAV01) {
11486
+ for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
11487
+ sample = samples[i];
11488
+ mdata.set(sample.data, offset);
11489
+ sample.size = sample.data.byteLength;
11490
+ offset += sample.size;
11491
+ }
11492
+ } else {
11493
+ var mdatView = new DataView(mdata.buffer);
11494
+ var _loop = function _loop2(_offset2, _sample2) {
11495
+ _sample2 = samples[_i];
11496
+ var sampleSize = 0;
11497
+ _sample2.units.forEach(function(u) {
11498
+ mdatView.setUint32(_offset2, u.byteLength);
11499
+ _offset2 += 4;
11500
+ mdata.set(u, _offset2);
11501
+ _offset2 += u.byteLength;
11502
+ sampleSize += 4 + u.byteLength;
11503
+ });
11504
+ _sample2.size = sampleSize;
11505
+ _offset = _offset2, _sample = _sample2;
11506
+ };
11507
+ for (var _i = 0, _l = samples.length, _offset = 0, _sample; _i < _l; _i++) {
11508
+ _loop(_offset, _sample);
11509
+ }
10731
11510
  }
10732
11511
  var mdat = MP4.mdat(mdata);
10733
11512
  var moof = MP4.moof([track]);
@@ -10886,11 +11665,11 @@
10886
11665
  });
10887
11666
  var logger$3 = new Logger$2("Transmuxer");
10888
11667
  var Transmuxer = /* @__PURE__ */ function() {
10889
- function Transmuxer2(hls, isMP4, needRemux) {
11668
+ function Transmuxer2(hls, isMP4, needRemux, fixerConfig) {
10890
11669
  _classCallCheck$3(this, Transmuxer2);
10891
11670
  _defineProperty$3(this, "_initSegmentId", "");
10892
11671
  this.hls = hls;
10893
- this._demuxer = isMP4 ? new FMP4Demuxer() : new TsDemuxer();
11672
+ this._demuxer = isMP4 ? new FMP4Demuxer() : new TsDemuxer(null, null, null, fixerConfig);
10894
11673
  this._isMP4 = isMP4;
10895
11674
  if (needRemux)
10896
11675
  this._remuxer = new FMP4Remuxer(this._demuxer.videoTrack, this._demuxer.audioTrack);
@@ -11045,7 +11824,7 @@
11045
11824
  }]);
11046
11825
  return Transmuxer2;
11047
11826
  }();
11048
- var _excluded = ["data"], _excluded2 = ["data"];
11827
+ var _excluded$1 = ["data"], _excluded2 = ["data"];
11049
11828
  var logger$2 = new Logger$2("BufferService");
11050
11829
  var BufferService = /* @__PURE__ */ function() {
11051
11830
  function BufferService2(hls) {
@@ -11157,11 +11936,11 @@
11157
11936
  return;
11158
11937
  if (TsDemuxer.probe(chunk)) {
11159
11938
  if (!this._transmuxer)
11160
- this._transmuxer = new Transmuxer(this.hls, false, !this._softVideo);
11939
+ this._transmuxer = new Transmuxer(this.hls, false, !this._softVideo, this.hls.config.fixerConfig);
11161
11940
  } else if (MP4Parser.probe(chunk)) {
11162
11941
  if (this._softVideo) {
11163
11942
  if (!this._transmuxer)
11164
- this._transmuxer = new Transmuxer(this.hls, true);
11943
+ this._transmuxer = new Transmuxer(this.hls, true, null, this.hls.config.fixerConfig);
11165
11944
  } else {
11166
11945
  this._directAppend = true;
11167
11946
  var mix = false;
@@ -11211,7 +11990,8 @@
11211
11990
  key: "appendBuffer",
11212
11991
  value: function() {
11213
11992
  var _appendBuffer = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee2(segment, audioSegment, videoChunk, audioChunk, discontinuity, contiguous, startTime) {
11214
- var p, needInit, _this$_transmuxer$tra, _this$_transmuxer$tra2, video, audio, isFirstAppend, mse, _p, videoData, videoRest, audioData, audioRest;
11993
+ var _this2 = this;
11994
+ var afterAppend, p, needInit, _this$_transmuxer$tra, _this$_transmuxer$tra2, video, audio, isFirstAppend, mse, _p, videoData, videoRest, audioData, audioRest;
11215
11995
  return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
11216
11996
  while (1)
11217
11997
  switch (_context2.prev = _context2.next) {
@@ -11222,8 +12002,18 @@
11222
12002
  }
11223
12003
  return _context2.abrupt("return");
11224
12004
  case 2:
12005
+ afterAppend = function afterAppend2() {
12006
+ var _this2$hls;
12007
+ if ((_this2$hls = _this2.hls) !== null && _this2$hls !== void 0 && _this2$hls.emit) {
12008
+ var _this2$hls2;
12009
+ (_this2$hls2 = _this2.hls) === null || _this2$hls2 === void 0 ? void 0 : _this2$hls2.emit(EVENT.APPEND_BUFFER, {
12010
+ start: segment.start,
12011
+ end: segment.end
12012
+ });
12013
+ }
12014
+ };
11225
12015
  if (!this._directAppend) {
11226
- _context2.next = 7;
12016
+ _context2.next = 8;
11227
12017
  break;
11228
12018
  }
11229
12019
  p = [];
@@ -11231,8 +12021,8 @@
11231
12021
  p.push(this._mse.append(MSE.VIDEO, videoChunk));
11232
12022
  if (audioChunk)
11233
12023
  p.push(this._mse.append(MSE.AUDIO, audioChunk));
11234
- return _context2.abrupt("return", Promise.all(p));
11235
- case 7:
12024
+ return _context2.abrupt("return", Promise.all(p).then(afterAppend));
12025
+ case 8:
11236
12026
  needInit = this._needInitSegment || discontinuity;
11237
12027
  _this$_transmuxer$tra = this._transmuxer.transmux(videoChunk, audioChunk, needInit, contiguous, startTime, this._needInitSegment || discontinuity), _this$_transmuxer$tra2 = _slicedToArray$1(_this$_transmuxer$tra, 2), video = _this$_transmuxer$tra2[0], audio = _this$_transmuxer$tra2[1];
11238
12028
  if (audioChunk && audioSegment) {
@@ -11248,16 +12038,17 @@
11248
12038
  this.hls.emit(Event$1.NO_AUDIO_TRACK);
11249
12039
  }
11250
12040
  if (!this._softVideo) {
11251
- _context2.next = 18;
12041
+ _context2.next = 20;
11252
12042
  break;
11253
12043
  }
11254
12044
  this._softVideo.appendBuffer(video, audio);
11255
12045
  this._needInitSegment = false;
11256
- _context2.next = 28;
12046
+ afterAppend();
12047
+ _context2.next = 30;
11257
12048
  break;
11258
- case 18:
12049
+ case 20:
11259
12050
  if (!this._mse) {
11260
- _context2.next = 28;
12051
+ _context2.next = 30;
11261
12052
  break;
11262
12053
  }
11263
12054
  isFirstAppend = !this._sourceCreated;
@@ -11273,15 +12064,15 @@
11273
12064
  });
11274
12065
  }
11275
12066
  if (video) {
11276
- videoData = video.data, videoRest = _objectWithoutProperties$1(video, _excluded);
12067
+ videoData = video.data, videoRest = _objectWithoutProperties$1(video, _excluded$1);
11277
12068
  _p.push(mse.append(MSE.VIDEO, videoData, videoRest));
11278
12069
  }
11279
12070
  if (audio) {
11280
12071
  audioData = audio.data, audioRest = _objectWithoutProperties$1(audio, _excluded2);
11281
12072
  _p.push(mse.append(MSE.AUDIO, audioData, audioRest));
11282
12073
  }
11283
- return _context2.abrupt("return", Promise.all(_p));
11284
- case 28:
12074
+ return _context2.abrupt("return", Promise.all(_p).then(afterAppend));
12075
+ case 30:
11285
12076
  case "end":
11286
12077
  return _context2.stop();
11287
12078
  }
@@ -11296,7 +12087,7 @@
11296
12087
  key: "removeBuffer",
11297
12088
  value: function() {
11298
12089
  var _removeBuffer = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee3() {
11299
- var _this2 = this;
12090
+ var _this3 = this;
11300
12091
  var start, end, media, _args3 = arguments;
11301
12092
  return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
11302
12093
  while (1)
@@ -11312,7 +12103,7 @@
11312
12103
  return _context3.abrupt("return");
11313
12104
  case 5:
11314
12105
  return _context3.abrupt("return", this._mse.clearBuffer(start, end).then(function() {
11315
- return _this2.hls.emit(EVENT.REMOVE_BUFFER, {
12106
+ return _this3.hls.emit(EVENT.REMOVE_BUFFER, {
11316
12107
  start,
11317
12108
  end,
11318
12109
  removeEnd: end
@@ -11493,30 +12284,51 @@
11493
12284
  return setLiveSeekableRange;
11494
12285
  }()
11495
12286
  }, {
11496
- key: "destroy",
12287
+ key: "detachMedia",
11497
12288
  value: function() {
11498
- var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee9() {
11499
- var _this$_decryptor;
12289
+ var _detachMedia = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee9() {
11500
12290
  return _regeneratorRuntime$1().wrap(function _callee9$(_context9) {
11501
12291
  while (1)
11502
12292
  switch (_context9.prev = _context9.next) {
11503
12293
  case 0:
11504
- (_this$_decryptor = this._decryptor) === null || _this$_decryptor === void 0 ? void 0 : _this$_decryptor.destroy();
11505
12294
  if (!this._mse) {
11506
- _context9.next = 4;
12295
+ _context9.next = 3;
11507
12296
  break;
11508
12297
  }
11509
- _context9.next = 4;
12298
+ _context9.next = 3;
11510
12299
  return this._mse.unbindMedia();
11511
- case 4:
12300
+ case 3:
12301
+ case "end":
12302
+ return _context9.stop();
12303
+ }
12304
+ }, _callee9, this);
12305
+ }));
12306
+ function detachMedia() {
12307
+ return _detachMedia.apply(this, arguments);
12308
+ }
12309
+ return detachMedia;
12310
+ }()
12311
+ }, {
12312
+ key: "destroy",
12313
+ value: function() {
12314
+ var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee10() {
12315
+ var _this$_decryptor;
12316
+ return _regeneratorRuntime$1().wrap(function _callee10$(_context10) {
12317
+ while (1)
12318
+ switch (_context10.prev = _context10.next) {
12319
+ case 0:
12320
+ (_this$_decryptor = this._decryptor) === null || _this$_decryptor === void 0 ? void 0 : _this$_decryptor.destroy();
12321
+ _context10.next = 3;
12322
+ return this.detachMedia();
12323
+ case 3:
11512
12324
  this._decryptor = null;
11513
12325
  this._mse = null;
11514
12326
  this._softVideo = null;
11515
- case 7:
12327
+ case 6:
11516
12328
  case "end":
11517
- return _context9.stop();
12329
+ return _context10.stop();
11518
12330
  }
11519
- }, _callee9, this);
12331
+ }, _callee10, this);
11520
12332
  }));
11521
12333
  function destroy() {
11522
12334
  return _destroy.apply(this, arguments);
@@ -11604,7 +12416,11 @@
11604
12416
  minSegmentsStartPlay: 3,
11605
12417
  preferMMS: false,
11606
12418
  preferMMSStreaming: false,
11607
- mseLowLatency: true
12419
+ mseLowLatency: true,
12420
+ fixerConfig: {
12421
+ forceFixLargeGap: false,
12422
+ largeGapThreshold: 5
12423
+ }
11608
12424
  }, cfg), {}, {
11609
12425
  media
11610
12426
  });
@@ -11719,6 +12535,8 @@
11719
12535
  _defineProperty$3(this, "lowLatency", false);
11720
12536
  _defineProperty$3(this, "endPartIndex", 0);
11721
12537
  _defineProperty$3(this, "segments", []);
12538
+ _defineProperty$3(this, "dateRanges", {});
12539
+ _defineProperty$3(this, "skippedSegments", 0);
11722
12540
  });
11723
12541
  var MediaSegment = /* @__PURE__ */ function() {
11724
12542
  function MediaSegment2(parentUrl) {
@@ -11840,6 +12658,31 @@
11840
12658
  }]);
11841
12659
  return MediaSegmentKey2;
11842
12660
  }();
12661
+ var HlsUrlParameters = /* @__PURE__ */ function() {
12662
+ function HlsUrlParameters2(msn, part, skip) {
12663
+ _classCallCheck$3(this, HlsUrlParameters2);
12664
+ this.msn = msn;
12665
+ this.part = part;
12666
+ this.skip = skip;
12667
+ }
12668
+ _createClass$3(HlsUrlParameters2, [{
12669
+ key: "addDirectives",
12670
+ value: function addDirectives(uri) {
12671
+ var url = new self.URL(uri);
12672
+ if (this.msn !== void 0) {
12673
+ url.searchParams.set("_HLS_msn", this.msn.toString());
12674
+ }
12675
+ if (this.part) {
12676
+ url.searchParams.set("_HLS_part", this.part.toString());
12677
+ }
12678
+ if (this.skip) {
12679
+ url.searchParams.set("_HLS_skip", this.skip);
12680
+ }
12681
+ return url.href;
12682
+ }
12683
+ }]);
12684
+ return HlsUrlParameters2;
12685
+ }();
11843
12686
  var REGEXP_TAG = /^#(EXT[^:]*)(?::(.*))?$/;
11844
12687
  var REGEXP_ATTR = /([^=]+)=(?:"([^"]*)"|([^",]*))(?:,|$)/g;
11845
12688
  var REGEXP_ABSOLUTE_URL = /^(?:[a-zA-Z0-9+\-.]+:)?\/\//;
@@ -11890,6 +12733,38 @@
11890
12733
  }
11891
12734
  }
11892
12735
  }
12736
+ function isValidDaterange(attr, dateRangeWithSameId) {
12737
+ var _badValueForSameId;
12738
+ if (dateRangeWithSameId) {
12739
+ for (var key in dateRangeWithSameId) {
12740
+ if (Object.prototype.hasOwnProperty.call(dateRangeWithSameId, key) && attr[key] !== dateRangeWithSameId[key]) {
12741
+ _badValueForSameId = key;
12742
+ break;
12743
+ }
12744
+ }
12745
+ }
12746
+ var duration = null;
12747
+ if (attr.DURATION) {
12748
+ duration = parseFloat(attr.DURATION);
12749
+ if (!Number.isFinite(duration)) {
12750
+ duration = null;
12751
+ } else if (attr._endDate) {
12752
+ duration = (attr._endDate.getTime() - attr._startDate.getTime()) / 1e3;
12753
+ }
12754
+ }
12755
+ var cue = enumeratedStringList(attr.CUE || attr["X-CUE"], {
12756
+ pre: false,
12757
+ post: false,
12758
+ once: false
12759
+ });
12760
+ return !!attr.ID && !_badValueForSameId && Number.isFinite(attr._startDate.getTime()) && (duration === null || duration >= 0) && (!(attr.END_ON_NEXT === "YES") || !!attr.CLASS) && (!attr.CUE || !cue.pre && !cue.post || cue.pre !== cue.post) && (!(attr.CLASS === "com.apple.hls.interstitial") || "X-ASSET-URI" in attr || "X-ASSET-LIST" in attr);
12761
+ }
12762
+ function enumeratedStringList(attrValue, dict) {
12763
+ return (attrValue ? attrValue.split(/[ ,]+/) : []).reduce(function(result, identifier) {
12764
+ result[identifier.toLowerCase()] = true;
12765
+ return result;
12766
+ }, dict);
12767
+ }
11893
12768
  function parseMasterPlaylist(lines, parentUrl) {
11894
12769
  var master = new MasterPlaylist();
11895
12770
  var index = 0;
@@ -11998,9 +12873,6 @@
11998
12873
  var endOfList = false;
11999
12874
  var partSegmentIndex = 0;
12000
12875
  while (line = lines[index++]) {
12001
- if (endOfList) {
12002
- break;
12003
- }
12004
12876
  if (line[0] !== "#") {
12005
12877
  if (media.lowLatency) {
12006
12878
  curSN++;
@@ -12049,16 +12921,11 @@
12049
12921
  media.canBlockReload = _attr["CAN-BLOCK-RELOAD"] === "YES";
12050
12922
  media.partHoldBack = parseFloat(_attr["PART-HOLD-BACK"] || 0);
12051
12923
  media.canSkipUntil = parseFloat(_attr["CAN-SKIP-UNTIL"] || 0);
12052
- media.canSkipDateRanges = _attr["CAN-SKIP-DATERANGES"] === "YES";
12924
+ media.canSkipDateRanges = media.canSkipUntil > 0 && _attr["CAN-SKIP-DATERANGES"] === "YES";
12053
12925
  }
12054
12926
  break;
12055
12927
  case "ENDLIST":
12056
12928
  {
12057
- var _lastSegment = media.segments[media.segments.length - 1];
12058
- if (_lastSegment) {
12059
- _lastSegment.isLast = true;
12060
- }
12061
- media.live = false;
12062
12929
  endOfList = true;
12063
12930
  }
12064
12931
  break;
@@ -12098,6 +12965,15 @@
12098
12965
  }
12099
12966
  break;
12100
12967
  case "PRELOAD-HINT":
12968
+ {
12969
+ var _attr3 = parseAttr(data);
12970
+ media.preloadHint = _attr3;
12971
+ if (_attr3["TYPE"] === "PART" && _attr3["URI"]) {
12972
+ var tmp = _attr3["URI"].split(".ts")[0].split("-");
12973
+ media.nextSN = tmp[3];
12974
+ media.nextIndex = tmp[tmp.length - 1];
12975
+ }
12976
+ }
12101
12977
  break;
12102
12978
  case "PROGRAM-DATE-TIME":
12103
12979
  curSegment.dataTime = data;
@@ -12117,21 +12993,21 @@
12117
12993
  break;
12118
12994
  case "KEY":
12119
12995
  {
12120
- var _attr3 = parseAttr(data);
12121
- if (_attr3.METHOD === "NONE") {
12996
+ var _attr4 = parseAttr(data);
12997
+ if (_attr4.METHOD === "NONE") {
12122
12998
  curKey = null;
12123
12999
  break;
12124
13000
  }
12125
13001
  curKey = new MediaSegmentKey();
12126
- curKey.method = _attr3.METHOD;
12127
- curKey.url = /^blob:/.test(_attr3.URI) ? _attr3.URI : getAbsoluteUrl(_attr3.URI, parentUrl);
12128
- curKey.keyFormat = _attr3.KEYFORMAT || "identity";
12129
- curKey.keyFormatVersions = _attr3.KEYFORMATVERSIONS;
13002
+ curKey.method = _attr4.METHOD;
13003
+ curKey.url = /^blob:/.test(_attr4.URI) ? _attr4.URI : getAbsoluteUrl(_attr4.URI, parentUrl);
13004
+ curKey.keyFormat = _attr4.KEYFORMAT || "identity";
13005
+ curKey.keyFormatVersions = _attr4.KEYFORMATVERSIONS;
12130
13006
  if (!curKey.isSupported()) {
12131
- throw new Error("encrypt ".concat(_attr3.METHOD, "/").concat(_attr3.KEYFORMAT, " is not supported"));
13007
+ throw new Error("encrypt ".concat(_attr4.METHOD, "/").concat(_attr4.KEYFORMAT, " is not supported"));
12132
13008
  }
12133
- if (_attr3.IV) {
12134
- var str = _attr3.IV.slice(2);
13009
+ if (_attr4.IV) {
13010
+ var str = _attr4.IV.slice(2);
12135
13011
  str = (str.length & 1 ? "0" : "") + str;
12136
13012
  curKey.iv = new Uint8Array(str.length / 2);
12137
13013
  for (var i = 0, l = str.length / 2; i < l; i++) {
@@ -12142,10 +13018,10 @@
12142
13018
  break;
12143
13019
  case "MAP":
12144
13020
  {
12145
- var _attr4 = parseAttr(data);
12146
- curSegment.url = getAbsoluteUrl(_attr4.URI, parentUrl);
12147
- if (_attr4.BYTERANGE)
12148
- curSegment.setByteRange(_attr4.BYTERANGE);
13021
+ var _attr5 = parseAttr(data);
13022
+ curSegment.url = getAbsoluteUrl(_attr5.URI, parentUrl);
13023
+ if (_attr5.BYTERANGE)
13024
+ curSegment.setByteRange(_attr5.BYTERANGE);
12149
13025
  curSegment.isInitSegment = true;
12150
13026
  curSegment.sn = 0;
12151
13027
  if (curKey) {
@@ -12155,6 +13031,30 @@
12155
13031
  curSegment = new MediaSegment(parentUrl);
12156
13032
  }
12157
13033
  break;
13034
+ case "SKIP":
13035
+ {
13036
+ var _attr6 = parseAttr(data);
13037
+ var skippedSegments = parseInt(_attr6["SKIPPED-SEGMENTS"], 10);
13038
+ if (skippedSegments <= Number.MAX_SAFE_INTEGER) {
13039
+ media.skippedSegments += skippedSegments;
13040
+ curSN += skippedSegments;
13041
+ }
13042
+ }
13043
+ break;
13044
+ case "DATERANGE":
13045
+ {
13046
+ var _attr7 = parseAttr(data);
13047
+ var dateRangeWithSameId = media.dateRanges[_attr7.ID];
13048
+ _attr7._startDate = dateRangeWithSameId ? dateRangeWithSameId._startDate : new Date(_attr7["START-DATE"]);
13049
+ var endDate = (dateRangeWithSameId === null || dateRangeWithSameId === void 0 ? void 0 : dateRangeWithSameId._endDate) || new Date(_attr7.END_DATE);
13050
+ if (Number.isFinite(endDate)) {
13051
+ _attr7._endDate = endDate;
13052
+ }
13053
+ if (isValidDaterange(_attr7, dateRangeWithSameId) || media.skippedSegments) {
13054
+ media.dateRanges[_attr7.ID] = _attr7;
13055
+ }
13056
+ }
13057
+ break;
12158
13058
  }
12159
13059
  }
12160
13060
  media.segments = media.segments.filter(function(x) {
@@ -12162,11 +13062,14 @@
12162
13062
  });
12163
13063
  var lastSegment = media.segments[media.segments.length - 1];
12164
13064
  if (lastSegment) {
12165
- media.endSN = lastSegment.sn;
12166
- media.endPartIndex = lastSegment.partIndex;
12167
- if (endOfList && !lastSegment.isLast) {
13065
+ if (endOfList) {
12168
13066
  lastSegment.isLast = true;
12169
13067
  }
13068
+ media.endSN = lastSegment.sn;
13069
+ media.endPartIndex = lastSegment.partIndex;
13070
+ }
13071
+ if (endOfList) {
13072
+ media.live = false;
12170
13073
  }
12171
13074
  media.totalDuration = totalDuration;
12172
13075
  media.endCC = curCC;
@@ -12345,6 +13248,13 @@
12345
13248
  playlist
12346
13249
  });
12347
13250
  } else {
13251
+ if (this._useLowLatency) {
13252
+ if (playlist.canBlockReload) {
13253
+ this.deliveryDirectives = new HlsUrlParameters(playlist.nextSN, playlist.nextIndex, "");
13254
+ } else {
13255
+ this.deliveryDirectives = null;
13256
+ }
13257
+ }
12348
13258
  this.hls.emit(Event$1.HLS_LEVEL_LOADED, {
12349
13259
  playlist
12350
13260
  });
@@ -12401,41 +13311,45 @@
12401
13311
  var retryCount = this.hls.config.pollRetryCount;
12402
13312
  var fn = /* @__PURE__ */ function() {
12403
13313
  var _ref2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee2() {
12404
- var res;
13314
+ var reqUrl, res;
12405
13315
  return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
12406
13316
  while (1)
12407
13317
  switch (_context2.prev = _context2.next) {
12408
13318
  case 0:
12409
13319
  clearTimeout(_this2._timer);
12410
- _context2.prev = 1;
12411
- _context2.next = 4;
12412
- return _this2.load(url, audioUrl, subtitleUrl);
12413
- case 4:
13320
+ reqUrl = url;
13321
+ _context2.prev = 2;
13322
+ if (_this2.deliveryDirectives) {
13323
+ reqUrl = _this2.deliveryDirectives.addDirectives(url);
13324
+ }
13325
+ _context2.next = 6;
13326
+ return _this2.load(reqUrl, audioUrl, subtitleUrl);
13327
+ case 6:
12414
13328
  res = _context2.sent;
12415
13329
  if (res[0]) {
12416
- _context2.next = 7;
13330
+ _context2.next = 9;
12417
13331
  break;
12418
13332
  }
12419
13333
  return _context2.abrupt("return");
12420
- case 7:
13334
+ case 9:
12421
13335
  retryCount = _this2.hls.config.pollRetryCount;
12422
13336
  cb(res[0], res[1], res[2]);
12423
- _context2.next = 15;
13337
+ _context2.next = 17;
12424
13338
  break;
12425
- case 11:
12426
- _context2.prev = 11;
12427
- _context2.t0 = _context2["catch"](1);
13339
+ case 13:
13340
+ _context2.prev = 13;
13341
+ _context2.t0 = _context2["catch"](2);
12428
13342
  retryCount--;
12429
13343
  if (retryCount <= 0) {
12430
13344
  errorCb(_context2.t0);
12431
13345
  }
12432
- case 15:
13346
+ case 17:
12433
13347
  _this2._timer = setTimeout(fn, time);
12434
- case 16:
13348
+ case 18:
12435
13349
  case "end":
12436
13350
  return _context2.stop();
12437
13351
  }
12438
- }, _callee2, null, [[1, 11]]);
13352
+ }, _callee2, null, [[2, 13]]);
12439
13353
  }));
12440
13354
  return function fn2() {
12441
13355
  return _ref2.apply(this, arguments);
@@ -12965,7 +13879,7 @@
12965
13879
  }, {
12966
13880
  key: "clearOldSegment",
12967
13881
  value: function clearOldSegment() {
12968
- var maxPlaylistSize = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 50;
13882
+ var maxPlaylistSize = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.hls.config.maxPlaylistSize || 50;
12969
13883
  var stream = this.currentStream;
12970
13884
  if (!this.dvrWindow || !stream)
12971
13885
  return;
@@ -13263,7 +14177,7 @@
13263
14177
  _defineProperty$3(_assertThisInitialized$2(_this), "_switchUrlOpts", null);
13264
14178
  _defineProperty$3(_assertThisInitialized$2(_this), "_isProcessQuotaExceeded", false);
13265
14179
  _defineProperty$3(_assertThisInitialized$2(_this), "_loadSegment", /* @__PURE__ */ _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee() {
13266
- var nextSeg, _assertThisInitialize, config, bInfo, bufferThroughout;
14180
+ var _this$_playlist, nextSegment, lastSegment, _assertThisInitialize, config, minFrameDuration, maxBufferThroughout, bInfo, bufferThroughout;
13267
14181
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
13268
14182
  while (1)
13269
14183
  switch (_context.prev = _context.next) {
@@ -13274,42 +14188,44 @@
13274
14188
  }
13275
14189
  return _context.abrupt("return");
13276
14190
  case 2:
13277
- nextSeg = _this._playlist.nextSegment;
14191
+ _this$_playlist = _this._playlist, nextSegment = _this$_playlist.nextSegment, lastSegment = _this$_playlist.lastSegment;
13278
14192
  _assertThisInitialize = _assertThisInitialized$2(_this), config = _assertThisInitialize.config;
13279
- if (nextSeg) {
13280
- _context.next = 6;
14193
+ minFrameDuration = 0.016;
14194
+ maxBufferThroughout = Math.min(Math.max((lastSegment === null || lastSegment === void 0 ? void 0 : lastSegment.duration) - minFrameDuration / 2 || 0, minFrameDuration), 0.1);
14195
+ if (nextSegment) {
14196
+ _context.next = 8;
13281
14197
  break;
13282
14198
  }
13283
14199
  return _context.abrupt("return");
13284
- case 6:
14200
+ case 8:
13285
14201
  if (_this.isLive) {
13286
- _context.next = 16;
14202
+ _context.next = 18;
13287
14203
  break;
13288
14204
  }
13289
14205
  bInfo = _this.bufferInfo();
13290
14206
  if (_this.media.paused && !_this.media.currentTime) {
13291
14207
  bInfo = _this.bufferInfo(bInfo.nextStart || 0.5);
13292
14208
  }
13293
- bufferThroughout = Math.abs(bInfo.end - _this.media.duration) < 0.1;
14209
+ bufferThroughout = Math.abs(bInfo.end - _this.media.duration) < maxBufferThroughout;
13294
14210
  if (!(bInfo.remaining >= config.preloadTime || bufferThroughout)) {
13295
- _context.next = 13;
14211
+ _context.next = 15;
13296
14212
  break;
13297
14213
  }
13298
14214
  _this._tryEos();
13299
14215
  return _context.abrupt("return");
13300
- case 13:
14216
+ case 15:
13301
14217
  if (!(config.preferMMSStreaming && !_this._bufferService.msStreaming)) {
13302
- _context.next = 15;
14218
+ _context.next = 17;
13303
14219
  break;
13304
14220
  }
13305
14221
  return _context.abrupt("return");
13306
- case 15:
13307
- if (!_this._urlSwitching && _this._prevSegSn !== nextSeg.sn - 1 && bInfo.end && Math.abs(nextSeg.start - bInfo.end) > 1) {
14222
+ case 17:
14223
+ if (!_this._urlSwitching && _this._prevSegSn !== nextSegment.sn - 1 && bInfo.end && Math.abs(nextSegment.start - bInfo.end) > 1) {
13308
14224
  _this._playlist.setNextSegmentByIndex(_this._playlist.findSegmentIndexByTime(bInfo.end + 0.1));
13309
14225
  }
13310
- case 16:
14226
+ case 18:
13311
14227
  return _context.abrupt("return", _this._loadSegmentDirect());
13312
- case 17:
14228
+ case 19:
13313
14229
  case "end":
13314
14230
  return _context.stop();
13315
14231
  }
@@ -13474,7 +14390,6 @@
13474
14390
  return;
13475
14391
  _this._startTick();
13476
14392
  var media = _this.media;
13477
- var buffered = Buffer$1.get(media);
13478
14393
  var segLoaderError = _this._segmentLoader.error;
13479
14394
  _this._onCheckQuotaExceeded();
13480
14395
  if (_this._isProcessQuotaExceeded) {
@@ -13491,7 +14406,7 @@
13491
14406
  }
13492
14407
  return;
13493
14408
  }
13494
- if (Buffer$1.end(buffered) >= 0.1 && media.readyState) {
14409
+ if (media.readyState) {
13495
14410
  if (isMediaPlaying(media)) {
13496
14411
  _this._loadSegment();
13497
14412
  if (_this._gapService) {
@@ -13557,6 +14472,12 @@
13557
14472
  var _this$_bufferService;
13558
14473
  return (_this$_bufferService = this._bufferService) === null || _this$_bufferService === void 0 ? void 0 : _this$_bufferService.baseDts;
13559
14474
  }
14475
+ }, {
14476
+ key: "abrSwitchPoint",
14477
+ get: function get() {
14478
+ var targetSeg = this._urlSwitching ? this._playlist.currentSegment : this._playlist.nextSegment;
14479
+ return targetSeg ? targetSeg.start + targetSeg.duration / 2 : null;
14480
+ }
13560
14481
  }, {
13561
14482
  key: "speedInfo",
13562
14483
  value: function speedInfo() {
@@ -13582,30 +14503,37 @@
13582
14503
  }, {
13583
14504
  key: "load",
13584
14505
  value: function() {
13585
- var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee4(url) {
13586
- var reuseMse, _args4 = arguments;
14506
+ var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee4() {
14507
+ var url, options, reuseMse, _args4 = arguments;
13587
14508
  return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
13588
14509
  while (1)
13589
14510
  switch (_context4.prev = _context4.next) {
13590
14511
  case 0:
13591
- reuseMse = _args4.length > 1 && _args4[1] !== void 0 ? _args4[1] : false;
14512
+ url = _args4.length > 0 && _args4[0] !== void 0 ? _args4[0] : "";
14513
+ options = _args4.length > 1 && _args4[1] !== void 0 ? _args4[1] : {};
14514
+ reuseMse = typeof options === "boolean" ? options : !!(options !== null && options !== void 0 && options.reuseMse);
14515
+ if (_typeof$2(options) === "object" && options !== null && options !== void 0 && options.clearSwitchStatus) {
14516
+ this._urlSwitching = false;
14517
+ this._switchUrlOpts = null;
14518
+ this.config.startTime = void 0;
14519
+ }
13592
14520
  if (url)
13593
14521
  this.config.url = url;
13594
14522
  url = this.config.url;
13595
- _context4.next = 5;
14523
+ _context4.next = 8;
13596
14524
  return this._reset(reuseMse);
13597
- case 5:
13598
- _context4.next = 7;
14525
+ case 8:
14526
+ _context4.next = 10;
13599
14527
  return this._loadData(url);
13600
- case 7:
14528
+ case 10:
13601
14529
  this._startTick();
13602
- case 8:
14530
+ case 11:
13603
14531
  case "end":
13604
14532
  return _context4.stop();
13605
14533
  }
13606
14534
  }, _callee4, this);
13607
14535
  }));
13608
- function load(_x) {
14536
+ function load() {
13609
14537
  return _load.apply(this, arguments);
13610
14538
  }
13611
14539
  return load;
@@ -13614,7 +14542,7 @@
13614
14542
  key: "_loadData",
13615
14543
  value: function() {
13616
14544
  var _loadData2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee5(url) {
13617
- var manifest, currentStream, _this$_switchUrlOpts, _this$_switchUrlOpts2, switchTimePoint, segIdx, nextSeg, bufferClearStartPoint, preIndex, startTime, _this$_switchUrlOpts3;
14545
+ var manifest, currentStream, preIndex, _this$_switchUrlOpts, _this$_switchUrlOpts3, _this$_switchUrlOpts4, _this$_switchUrlOpts2, switchTimePoint, segIdx, nextSeg, bufferClearStartPoint, startTime, _this$_switchUrlOpts5;
13618
14546
  return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
13619
14547
  while (1)
13620
14548
  switch (_context5.prev = _context5.next) {
@@ -13635,41 +14563,46 @@
13635
14563
  case 5:
13636
14564
  manifest = _context5.sent;
13637
14565
  currentStream = this._playlist.currentStream;
13638
- if (!(this._urlSwitching && !this.isLive)) {
13639
- _context5.next = 17;
14566
+ if (!this._urlSwitching) {
14567
+ _context5.next = 23;
13640
14568
  break;
13641
14569
  }
14570
+ if (!this.isLive) {
14571
+ _context5.next = 14;
14572
+ break;
14573
+ }
14574
+ preIndex = this._playlist.setNextSegmentBySN(this._prevSegSn);
14575
+ logger.log("segment nb=".concat(this._prevSegSn, " index of ").concat(preIndex, " in the new playlist"));
14576
+ if (preIndex === -1) {
14577
+ this._prevSegCc = null;
14578
+ this._prevSegSn = null;
14579
+ }
14580
+ _context5.next = 23;
14581
+ break;
14582
+ case 14:
13642
14583
  if (currentStream.bitrate === 0 && (_this$_switchUrlOpts = this._switchUrlOpts) !== null && _this$_switchUrlOpts !== void 0 && _this$_switchUrlOpts.bitrate) {
13643
14584
  currentStream.bitrate = (_this$_switchUrlOpts2 = this._switchUrlOpts) === null || _this$_switchUrlOpts2 === void 0 ? void 0 : _this$_switchUrlOpts2.bitrate;
13644
14585
  }
13645
- switchTimePoint = this._getSeamlessSwitchPoint();
14586
+ switchTimePoint = typeof ((_this$_switchUrlOpts3 = this._switchUrlOpts) === null || _this$_switchUrlOpts3 === void 0 ? void 0 : _this$_switchUrlOpts3.startTime) === "number" ? (_this$_switchUrlOpts4 = this._switchUrlOpts) === null || _this$_switchUrlOpts4 === void 0 ? void 0 : _this$_switchUrlOpts4.startTime : this._getSeamlessSwitchPoint();
13646
14587
  this.config.startTime = switchTimePoint;
13647
14588
  segIdx = this._playlist.findSegmentIndexByTime(switchTimePoint);
13648
14589
  nextSeg = this._playlist.getSegmentByIndex(segIdx + 1);
13649
14590
  if (!nextSeg) {
13650
- _context5.next = 17;
14591
+ _context5.next = 23;
13651
14592
  break;
13652
14593
  }
13653
14594
  bufferClearStartPoint = nextSeg.start;
13654
- _context5.next = 17;
14595
+ _context5.next = 23;
13655
14596
  return this._bufferService.removeBuffer(bufferClearStartPoint);
13656
- case 17:
13657
- if (this._urlSwitching && this.isLive) {
13658
- preIndex = this._playlist.setNextSegmentBySN(this._prevSegSn);
13659
- logger.log("segment nb=".concat(this._prevSegSn, " index of ").concat(preIndex, " in the new playlist"));
13660
- if (preIndex === -1) {
13661
- this._prevSegCc = null;
13662
- this._prevSegSn = null;
13663
- }
13664
- }
14597
+ case 23:
13665
14598
  if (manifest) {
13666
- _context5.next = 20;
14599
+ _context5.next = 25;
13667
14600
  break;
13668
14601
  }
13669
14602
  return _context5.abrupt("return");
13670
- case 20:
14603
+ case 25:
13671
14604
  if (!this.isLive) {
13672
- _context5.next = 31;
14605
+ _context5.next = 36;
13673
14606
  break;
13674
14607
  }
13675
14608
  this._bufferService.setLiveSeekableRange(0, 4294967295);
@@ -13682,35 +14615,35 @@
13682
14615
  if (!manifest.isMaster)
13683
14616
  this._pollM3U8(url);
13684
14617
  if (!(this._playlist.nbSegments < this.config.minSegmentsStartPlay)) {
13685
- _context5.next = 28;
14618
+ _context5.next = 33;
13686
14619
  break;
13687
14620
  }
13688
14621
  return _context5.abrupt("return");
13689
- case 28:
13690
- _context5.next = 30;
14622
+ case 33:
14623
+ _context5.next = 35;
13691
14624
  return this._loadSegment();
13692
- case 30:
14625
+ case 35:
13693
14626
  return _context5.abrupt("return");
13694
- case 31:
13695
- _context5.next = 33;
14627
+ case 36:
14628
+ _context5.next = 38;
13696
14629
  return this._bufferService.updateDuration(currentStream.totalDuration);
13697
- case 33:
14630
+ case 38:
13698
14631
  startTime = this.config.startTime;
13699
14632
  if (startTime) {
13700
- if (!((_this$_switchUrlOpts3 = this._switchUrlOpts) !== null && _this$_switchUrlOpts3 !== void 0 && _this$_switchUrlOpts3.seamless)) {
14633
+ if (!((_this$_switchUrlOpts5 = this._switchUrlOpts) !== null && _this$_switchUrlOpts5 !== void 0 && _this$_switchUrlOpts5.seamless)) {
13701
14634
  this.media.currentTime = startTime;
13702
14635
  }
13703
14636
  this._playlist.setNextSegmentByIndex(this._playlist.findSegmentIndexByTime(startTime) || 0);
13704
14637
  }
13705
- _context5.next = 37;
14638
+ _context5.next = 42;
13706
14639
  return this._loadSegment();
13707
- case 37:
14640
+ case 42:
13708
14641
  case "end":
13709
14642
  return _context5.stop();
13710
14643
  }
13711
14644
  }, _callee5, this);
13712
14645
  }));
13713
- function _loadData(_x2) {
14646
+ function _loadData(_x) {
13714
14647
  return _loadData2.apply(this, arguments);
13715
14648
  }
13716
14649
  return _loadData;
@@ -13724,18 +14657,20 @@
13724
14657
  switch (_context6.prev = _context6.next) {
13725
14658
  case 0:
13726
14659
  this.config.startTime = 0;
13727
- _context6.next = 3;
14660
+ this._urlSwitching = false;
14661
+ this._switchUrlOpts = null;
14662
+ _context6.next = 5;
13728
14663
  return this.load();
13729
- case 3:
14664
+ case 5:
13730
14665
  this._reloadOnPlay = false;
13731
14666
  return _context6.abrupt("return", this.media.play(!isPlayEmit));
13732
- case 5:
14667
+ case 7:
13733
14668
  case "end":
13734
14669
  return _context6.stop();
13735
14670
  }
13736
14671
  }, _callee6, this);
13737
14672
  }));
13738
- function replay(_x3) {
14673
+ function replay(_x2) {
13739
14674
  return _replay.apply(this, arguments);
13740
14675
  }
13741
14676
  return replay;
@@ -13840,7 +14775,7 @@
13840
14775
  }
13841
14776
  }, _callee7, this, [[18, 29]]);
13842
14777
  }));
13843
- function switchURL(_x4) {
14778
+ function switchURL(_x3) {
13844
14779
  return _switchURL.apply(this, arguments);
13845
14780
  }
13846
14781
  return switchURL;
@@ -13926,7 +14861,7 @@
13926
14861
  }
13927
14862
  }, _callee8, this, [[8, 16], [21, 31]]);
13928
14863
  }));
13929
- function switchStream(_x5) {
14864
+ function switchStream(_x4) {
13930
14865
  return _switchStream.apply(this, arguments);
13931
14866
  }
13932
14867
  return switchStream;
@@ -14012,7 +14947,7 @@
14012
14947
  }
14013
14948
  }, _callee9, this, [[10, 18], [22, 32]]);
14014
14949
  }));
14015
- function switchAudioStream(_x6) {
14950
+ function switchAudioStream(_x5) {
14016
14951
  return _switchAudioStream.apply(this, arguments);
14017
14952
  }
14018
14953
  return switchAudioStream;
@@ -14037,25 +14972,50 @@
14037
14972
  }
14038
14973
  }, _callee10, this);
14039
14974
  }));
14040
- function switchSubtitleStream(_x7) {
14975
+ function switchSubtitleStream(_x6) {
14041
14976
  return _switchSubtitleStream.apply(this, arguments);
14042
14977
  }
14043
14978
  return switchSubtitleStream;
14044
14979
  }()
14045
14980
  }, {
14046
- key: "destroy",
14981
+ key: "detachMedia",
14047
14982
  value: function() {
14048
- var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee11() {
14049
- var _this$_seiService2;
14983
+ var _detachMedia = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee11() {
14050
14984
  return _regeneratorRuntime$1().wrap(function _callee11$(_context11) {
14051
14985
  while (1)
14052
14986
  switch (_context11.prev = _context11.next) {
14987
+ case 0:
14988
+ if (!this._bufferService) {
14989
+ _context11.next = 3;
14990
+ break;
14991
+ }
14992
+ _context11.next = 3;
14993
+ return this._bufferService.detachMedia();
14994
+ case 3:
14995
+ case "end":
14996
+ return _context11.stop();
14997
+ }
14998
+ }, _callee11, this);
14999
+ }));
15000
+ function detachMedia() {
15001
+ return _detachMedia.apply(this, arguments);
15002
+ }
15003
+ return detachMedia;
15004
+ }()
15005
+ }, {
15006
+ key: "destroy",
15007
+ value: function() {
15008
+ var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee12() {
15009
+ var _this$_seiService2;
15010
+ return _regeneratorRuntime$1().wrap(function _callee12$(_context12) {
15011
+ while (1)
15012
+ switch (_context12.prev = _context12.next) {
14053
15013
  case 0:
14054
15014
  if (this.media) {
14055
- _context11.next = 2;
15015
+ _context12.next = 2;
14056
15016
  break;
14057
15017
  }
14058
- return _context11.abrupt("return");
15018
+ return _context12.abrupt("return");
14059
15019
  case 2:
14060
15020
  this.removeAllListeners();
14061
15021
  this._playlist.reset();
@@ -14066,15 +15026,15 @@
14066
15026
  this.media.removeEventListener("pause", this._onPause);
14067
15027
  this.media.removeEventListener("seeking", this._onSeeking);
14068
15028
  this.media.removeEventListener("timeupdate", this._onTimeupdate);
14069
- _context11.next = 13;
15029
+ _context12.next = 13;
14070
15030
  return Promise.all([this._clear(), this._bufferService.destroy()]);
14071
15031
  case 13:
14072
15032
  this.media = null;
14073
15033
  case 14:
14074
15034
  case "end":
14075
- return _context11.stop();
15035
+ return _context12.stop();
14076
15036
  }
14077
- }, _callee11, this);
15037
+ }, _callee12, this);
14078
15038
  }));
14079
15039
  function destroy() {
14080
15040
  return _destroy.apply(this, arguments);
@@ -14084,48 +15044,48 @@
14084
15044
  }, {
14085
15045
  key: "_loadM3U8",
14086
15046
  value: function() {
14087
- var _loadM3U = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee12(url) {
15047
+ var _loadM3U = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee13(url) {
14088
15048
  var playlist, _this$config$manifest, _this$config$manifest2, manifest, _ref4, _ref5, _this$_playlist$curre;
14089
- return _regeneratorRuntime$1().wrap(function _callee12$(_context12) {
15049
+ return _regeneratorRuntime$1().wrap(function _callee13$(_context13) {
14090
15050
  while (1)
14091
- switch (_context12.prev = _context12.next) {
15051
+ switch (_context13.prev = _context13.next) {
14092
15052
  case 0:
14093
- _context12.prev = 0;
15053
+ _context13.prev = 0;
14094
15054
  manifest = (_this$config$manifest = this.config.manifestList) === null || _this$config$manifest === void 0 ? void 0 : (_this$config$manifest2 = _this$config$manifest.filter(function(x) {
14095
15055
  return x.url === url;
14096
15056
  })[0]) === null || _this$config$manifest2 === void 0 ? void 0 : _this$config$manifest2.manifest;
14097
15057
  if (!manifest) {
14098
- _context12.next = 6;
15058
+ _context13.next = 6;
14099
15059
  break;
14100
15060
  }
14101
- _context12.t0 = this._manifestLoader.parseText(manifest, url);
14102
- _context12.next = 9;
15061
+ _context13.t0 = this._manifestLoader.parseText(manifest, url);
15062
+ _context13.next = 9;
14103
15063
  break;
14104
15064
  case 6:
14105
- _context12.next = 8;
15065
+ _context13.next = 8;
14106
15066
  return this._manifestLoader.load(url);
14107
15067
  case 8:
14108
- _context12.t0 = _context12.sent;
15068
+ _context13.t0 = _context13.sent;
14109
15069
  case 9:
14110
- _ref4 = _context12.t0;
15070
+ _ref4 = _context13.t0;
14111
15071
  _ref5 = _slicedToArray$1(_ref4, 1);
14112
15072
  playlist = _ref5[0];
14113
- _context12.next = 17;
15073
+ _context13.next = 17;
14114
15074
  break;
14115
15075
  case 14:
14116
- _context12.prev = 14;
14117
- _context12.t1 = _context12["catch"](0);
14118
- throw this._emitError(StreamingError.create(_context12.t1));
15076
+ _context13.prev = 14;
15077
+ _context13.t1 = _context13["catch"](0);
15078
+ throw this._emitError(StreamingError.create(_context13.t1));
14119
15079
  case 17:
14120
15080
  if (playlist) {
14121
- _context12.next = 19;
15081
+ _context13.next = 19;
14122
15082
  break;
14123
15083
  }
14124
- return _context12.abrupt("return");
15084
+ return _context13.abrupt("return");
14125
15085
  case 19:
14126
15086
  this._playlist.upsertPlaylist(playlist);
14127
15087
  if (!playlist.isMaster) {
14128
- _context12.next = 24;
15088
+ _context13.next = 24;
14129
15089
  break;
14130
15090
  }
14131
15091
  if ((_this$_playlist$curre = this._playlist.currentStream.subtitleStreams) !== null && _this$_playlist$curre !== void 0 && _this$_playlist$curre.length) {
@@ -14133,18 +15093,18 @@
14133
15093
  list: this._playlist.currentStream.subtitleStreams
14134
15094
  });
14135
15095
  }
14136
- _context12.next = 24;
15096
+ _context13.next = 24;
14137
15097
  return this._refreshM3U8();
14138
15098
  case 24:
14139
15099
  this.emit(Event$1.STREAM_PARSED);
14140
- return _context12.abrupt("return", playlist);
15100
+ return _context13.abrupt("return", playlist);
14141
15101
  case 26:
14142
15102
  case "end":
14143
- return _context12.stop();
15103
+ return _context13.stop();
14144
15104
  }
14145
- }, _callee12, this, [[0, 14]]);
15105
+ }, _callee13, this, [[0, 14]]);
14146
15106
  }));
14147
- function _loadM3U8(_x8) {
15107
+ function _loadM3U8(_x7) {
14148
15108
  return _loadM3U.apply(this, arguments);
14149
15109
  }
14150
15110
  return _loadM3U8;
@@ -14178,7 +15138,7 @@
14178
15138
  var isEmpty = this._playlist.isEmpty;
14179
15139
  var pollInterval;
14180
15140
  if (this._playlist.lowLatency) {
14181
- pollInterval = (this._playlist.currentStream.partTargetDuration * 2 || 0) * 1e3;
15141
+ pollInterval = (this._playlist.currentStream.partTargetDuration || 0) * 1e3;
14182
15142
  } else {
14183
15143
  var _this$_playlist$lastS;
14184
15144
  pollInterval = (((_this$_playlist$lastS = this._playlist.lastSegment) === null || _this$_playlist$lastS === void 0 ? void 0 : _this$_playlist$lastS.duration) || 0) * 1e3;
@@ -14206,53 +15166,53 @@
14206
15166
  }, {
14207
15167
  key: "_loadSegmentDirect",
14208
15168
  value: function() {
14209
- var _loadSegmentDirect2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee13(loadOnce) {
15169
+ var _loadSegmentDirect2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee14(loadOnce) {
14210
15170
  var seg, appended, cachedError, _this$_playlist$curre2, bufferEnd, sameStream;
14211
- return _regeneratorRuntime$1().wrap(function _callee13$(_context13) {
15171
+ return _regeneratorRuntime$1().wrap(function _callee14$(_context14) {
14212
15172
  while (1)
14213
- switch (_context13.prev = _context13.next) {
15173
+ switch (_context14.prev = _context14.next) {
14214
15174
  case 0:
14215
15175
  seg = this._playlist.nextSegment;
14216
15176
  if (seg) {
14217
- _context13.next = 3;
15177
+ _context14.next = 3;
14218
15178
  break;
14219
15179
  }
14220
- return _context13.abrupt("return");
15180
+ return _context14.abrupt("return");
14221
15181
  case 3:
14222
15182
  appended = false;
14223
15183
  cachedError = null;
14224
- _context13.prev = 5;
15184
+ _context14.prev = 5;
14225
15185
  this._segmentProcessing = true;
14226
15186
  logger.log("load segment, sn:".concat(seg.sn, ", [").concat(seg.start, ", ").concat(seg.end, "], partIndex:").concat(seg.partIndex));
14227
- _context13.next = 10;
15187
+ _context14.next = 10;
14228
15188
  return this._reqAndBufferSegment(seg, this._playlist.getAudioSegment(seg));
14229
15189
  case 10:
14230
- appended = _context13.sent;
14231
- _context13.next = 16;
15190
+ appended = _context14.sent;
15191
+ _context14.next = 16;
14232
15192
  break;
14233
15193
  case 13:
14234
- _context13.prev = 13;
14235
- _context13.t0 = _context13["catch"](5);
14236
- cachedError = _context13.t0;
15194
+ _context14.prev = 13;
15195
+ _context14.t0 = _context14["catch"](5);
15196
+ cachedError = _context14.t0;
14237
15197
  case 16:
14238
- _context13.prev = 16;
15198
+ _context14.prev = 16;
14239
15199
  this._segmentProcessing = false;
14240
- return _context13.finish(16);
15200
+ return _context14.finish(16);
14241
15201
  case 19:
14242
15202
  if (!cachedError) {
14243
- _context13.next = 26;
15203
+ _context14.next = 26;
14244
15204
  break;
14245
15205
  }
14246
15206
  if (!this._bufferService.isFull()) {
14247
- _context13.next = 25;
15207
+ _context14.next = 25;
14248
15208
  break;
14249
15209
  }
14250
15210
  logger.log("load segment, sn:".concat(seg.sn, ", partIndex:").concat(seg.partIndex));
14251
15211
  this._segmentProcessing = true;
14252
15212
  this._isProcessQuotaExceeded = true;
14253
- return _context13.abrupt("return", false);
15213
+ return _context14.abrupt("return", false);
14254
15214
  case 25:
14255
- return _context13.abrupt("return", this._emitError(StreamingError.create(cachedError)));
15215
+ return _context14.abrupt("return", this._emitError(StreamingError.create(cachedError)));
14256
15216
  case 26:
14257
15217
  if (appended) {
14258
15218
  bufferEnd = this.bufferInfo().end;
@@ -14278,14 +15238,14 @@
14278
15238
  this._loadSegment();
14279
15239
  }
14280
15240
  }
14281
- return _context13.abrupt("return", appended);
15241
+ return _context14.abrupt("return", appended);
14282
15242
  case 28:
14283
15243
  case "end":
14284
- return _context13.stop();
15244
+ return _context14.stop();
14285
15245
  }
14286
- }, _callee13, this, [[5, 13, 16, 19]]);
15246
+ }, _callee14, this, [[5, 13, 16, 19]]);
14287
15247
  }));
14288
- function _loadSegmentDirect(_x9) {
15248
+ function _loadSegmentDirect(_x8) {
14289
15249
  return _loadSegmentDirect2.apply(this, arguments);
14290
15250
  }
14291
15251
  return _loadSegmentDirect;
@@ -14293,45 +15253,45 @@
14293
15253
  }, {
14294
15254
  key: "_reqAndBufferSegment",
14295
15255
  value: function() {
14296
- var _reqAndBufferSegment2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee14(seg, audioSeg) {
15256
+ var _reqAndBufferSegment2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee15(seg, audioSeg) {
14297
15257
  var _this$_bufferService2;
14298
15258
  var cc, discontinuity, responses, data, sn, start, stream, before, contiguous, segStart;
14299
- return _regeneratorRuntime$1().wrap(function _callee14$(_context14) {
15259
+ return _regeneratorRuntime$1().wrap(function _callee15$(_context15) {
14300
15260
  while (1)
14301
- switch (_context14.prev = _context14.next) {
15261
+ switch (_context15.prev = _context15.next) {
14302
15262
  case 0:
14303
15263
  cc = seg ? seg.cc : audioSeg.cc;
14304
15264
  discontinuity = this._prevSegCc !== cc;
14305
15265
  responses = [];
14306
- _context14.prev = 3;
14307
- _context14.next = 6;
15266
+ _context15.prev = 3;
15267
+ _context15.next = 6;
14308
15268
  return this._segmentLoader.load(seg, audioSeg, discontinuity);
14309
15269
  case 6:
14310
- responses = _context14.sent;
14311
- _context14.next = 14;
15270
+ responses = _context15.sent;
15271
+ _context15.next = 14;
14312
15272
  break;
14313
15273
  case 9:
14314
- _context14.prev = 9;
14315
- _context14.t0 = _context14["catch"](3);
14316
- _context14.t0.fatal = false;
14317
- this._segmentLoader.error = _context14.t0;
14318
- throw _context14.t0;
15274
+ _context15.prev = 9;
15275
+ _context15.t0 = _context15["catch"](3);
15276
+ _context15.t0.fatal = false;
15277
+ this._segmentLoader.error = _context15.t0;
15278
+ throw _context15.t0;
14319
15279
  case 14:
14320
15280
  if (responses[0]) {
14321
- _context14.next = 16;
15281
+ _context15.next = 16;
14322
15282
  break;
14323
15283
  }
14324
- return _context14.abrupt("return");
15284
+ return _context15.abrupt("return");
14325
15285
  case 16:
14326
- _context14.next = 18;
15286
+ _context15.next = 18;
14327
15287
  return (_this$_bufferService2 = this._bufferService).decryptBuffer.apply(_this$_bufferService2, _toConsumableArray$2(responses));
14328
15288
  case 18:
14329
- data = _context14.sent;
15289
+ data = _context15.sent;
14330
15290
  if (data) {
14331
- _context14.next = 21;
15291
+ _context15.next = 21;
14332
15292
  break;
14333
15293
  }
14334
- return _context14.abrupt("return");
15294
+ return _context15.abrupt("return");
14335
15295
  case 21:
14336
15296
  sn = seg ? seg.sn : audioSeg.sn;
14337
15297
  start = seg ? seg.start : audioSeg.start;
@@ -14345,26 +15305,26 @@
14345
15305
  logger.warn("update the new playlist liveEdge, segment id=".concat(sn, ", buffer start=").concat(segStart, ", liveEdge=").concat(this._playlist.liveEdge));
14346
15306
  start = segStart;
14347
15307
  }
14348
- _context14.next = 30;
15308
+ _context15.next = 30;
14349
15309
  return this._bufferService.appendBuffer(seg, audioSeg, data[0], data[1], discontinuity, contiguous, start);
14350
15310
  case 30:
14351
15311
  this.emit(Event$1.APPEND_COST, {
14352
15312
  elapsed: Date.now() - before,
14353
15313
  url: seg.url
14354
15314
  });
14355
- _context14.next = 33;
15315
+ _context15.next = 33;
14356
15316
  return this._bufferService.evictBuffer(this.config.bufferBehind);
14357
15317
  case 33:
14358
15318
  this._prevSegCc = cc;
14359
15319
  this._prevSegSn = sn;
14360
- return _context14.abrupt("return", true);
15320
+ return _context15.abrupt("return", true);
14361
15321
  case 36:
14362
15322
  case "end":
14363
- return _context14.stop();
15323
+ return _context15.stop();
14364
15324
  }
14365
- }, _callee14, this, [[3, 9]]);
15325
+ }, _callee15, this, [[3, 9]]);
14366
15326
  }));
14367
- function _reqAndBufferSegment(_x10, _x11) {
15327
+ function _reqAndBufferSegment(_x9, _x10) {
14368
15328
  return _reqAndBufferSegment2.apply(this, arguments);
14369
15329
  }
14370
15330
  return _reqAndBufferSegment;
@@ -14372,11 +15332,11 @@
14372
15332
  }, {
14373
15333
  key: "_onCheckQuotaExceeded",
14374
15334
  value: function() {
14375
- var _onCheckQuotaExceeded2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee15() {
15335
+ var _onCheckQuotaExceeded2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee16() {
14376
15336
  var seekTime, buffered, inBuffered, i, bufferBehind, mediaTime;
14377
- return _regeneratorRuntime$1().wrap(function _callee15$(_context15) {
15337
+ return _regeneratorRuntime$1().wrap(function _callee16$(_context16) {
14378
15338
  while (1)
14379
- switch (_context15.prev = _context15.next) {
15339
+ switch (_context16.prev = _context16.next) {
14380
15340
  case 0:
14381
15341
  seekTime = this.media.currentTime;
14382
15342
  buffered = this.media.buffered;
@@ -14384,37 +15344,37 @@
14384
15344
  i = 0;
14385
15345
  case 4:
14386
15346
  if (!(i < buffered.length)) {
14387
- _context15.next = 11;
15347
+ _context16.next = 11;
14388
15348
  break;
14389
15349
  }
14390
15350
  if (!(buffered.start(0) >= seekTime && seekTime < buffered.end(i))) {
14391
- _context15.next = 8;
15351
+ _context16.next = 8;
14392
15352
  break;
14393
15353
  }
14394
15354
  inBuffered = true;
14395
- return _context15.abrupt("break", 11);
15355
+ return _context16.abrupt("break", 11);
14396
15356
  case 8:
14397
15357
  i++;
14398
- _context15.next = 4;
15358
+ _context16.next = 4;
14399
15359
  break;
14400
15360
  case 11:
14401
15361
  if (!this._bufferService.isFull()) {
14402
- _context15.next = 17;
15362
+ _context16.next = 17;
14403
15363
  break;
14404
15364
  }
14405
15365
  bufferBehind = inBuffered ? this.config.bufferBehind : 5;
14406
15366
  mediaTime = this.media.currentTime;
14407
15367
  if (!(mediaTime - bufferBehind > 0)) {
14408
- _context15.next = 17;
15368
+ _context16.next = 17;
14409
15369
  break;
14410
15370
  }
14411
- _context15.next = 17;
15371
+ _context16.next = 17;
14412
15372
  return this._bufferService.removeBuffer(0, mediaTime - bufferBehind);
14413
15373
  case 17:
14414
15374
  case "end":
14415
- return _context15.stop();
15375
+ return _context16.stop();
14416
15376
  }
14417
- }, _callee15, this);
15377
+ }, _callee16, this);
14418
15378
  }));
14419
15379
  function _onCheckQuotaExceeded() {
14420
15380
  return _onCheckQuotaExceeded2.apply(this, arguments);
@@ -14432,22 +15392,22 @@
14432
15392
  }, {
14433
15393
  key: "_clear",
14434
15394
  value: function() {
14435
- var _clear2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee16() {
14436
- return _regeneratorRuntime$1().wrap(function _callee16$(_context16) {
15395
+ var _clear2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee17() {
15396
+ return _regeneratorRuntime$1().wrap(function _callee17$(_context17) {
14437
15397
  while (1)
14438
- switch (_context16.prev = _context16.next) {
15398
+ switch (_context17.prev = _context17.next) {
14439
15399
  case 0:
14440
15400
  clearTimeout(this._disconnectTimer);
14441
15401
  this._stopTick();
14442
- _context16.next = 4;
15402
+ _context17.next = 4;
14443
15403
  return Promise.all([this._segmentLoader.cancel(), this._manifestLoader.stopPoll()]);
14444
15404
  case 4:
14445
15405
  this._segmentProcessing = false;
14446
15406
  case 5:
14447
15407
  case "end":
14448
- return _context16.stop();
15408
+ return _context17.stop();
14449
15409
  }
14450
- }, _callee16, this);
15410
+ }, _callee17, this);
14451
15411
  }));
14452
15412
  function _clear() {
14453
15413
  return _clear2.apply(this, arguments);
@@ -14457,14 +15417,14 @@
14457
15417
  }, {
14458
15418
  key: "_reset",
14459
15419
  value: function() {
14460
- var _reset2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee17() {
15420
+ var _reset2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee18() {
14461
15421
  var _this$_seiService3;
14462
- var reuseMse, _args17 = arguments;
14463
- return _regeneratorRuntime$1().wrap(function _callee17$(_context17) {
15422
+ var reuseMse, _args18 = arguments;
15423
+ return _regeneratorRuntime$1().wrap(function _callee18$(_context18) {
14464
15424
  while (1)
14465
- switch (_context17.prev = _context17.next) {
15425
+ switch (_context18.prev = _context18.next) {
14466
15426
  case 0:
14467
- reuseMse = _args17.length > 0 && _args17[0] !== void 0 ? _args17[0] : false;
15427
+ reuseMse = _args18.length > 0 && _args18[0] !== void 0 ? _args18[0] : false;
14468
15428
  this._reloadOnPlay = false;
14469
15429
  this._prevSegSn = null;
14470
15430
  this._prevSegCc = null;
@@ -14473,15 +15433,15 @@
14473
15433
  this._segmentLoader.reset();
14474
15434
  (_this$_seiService3 = this._seiService) === null || _this$_seiService3 === void 0 ? void 0 : _this$_seiService3.reset();
14475
15435
  this._stats.reset();
14476
- _context17.next = 11;
15436
+ _context18.next = 11;
14477
15437
  return this._clear();
14478
15438
  case 11:
14479
- return _context17.abrupt("return", this._bufferService.reset(reuseMse));
15439
+ return _context18.abrupt("return", this._bufferService.reset(reuseMse));
14480
15440
  case 12:
14481
15441
  case "end":
14482
- return _context17.stop();
15442
+ return _context18.stop();
14483
15443
  }
14484
- }, _callee17, this);
15444
+ }, _callee18, this);
14485
15445
  }));
14486
15446
  function _reset() {
14487
15447
  return _reset2.apply(this, arguments);
@@ -14562,8 +15522,8 @@
14562
15522
  value: function _tryEos() {
14563
15523
  var _this$_bufferService3, _this$_bufferService4;
14564
15524
  var media = this.media;
14565
- var _this$_playlist = this._playlist, nextSegment = _this$_playlist.nextSegment, lastSegment = _this$_playlist.lastSegment;
14566
- var eosAllowed = !nextSegment && media.readyState && media.duration > 0 && ((_this$_bufferService3 = this._bufferService) === null || _this$_bufferService3 === void 0 ? void 0 : _this$_bufferService3.msIsOpened) && !((_this$_bufferService4 = this._bufferService) !== null && _this$_bufferService4 !== void 0 && _this$_bufferService4.msHasOpTasks);
15525
+ var _this$_playlist2 = this._playlist, nextSegment = _this$_playlist2.nextSegment, lastSegment = _this$_playlist2.lastSegment;
15526
+ var eosAllowed = (!nextSegment || lastSegment && Buffer$1.isBuffered(media, lastSegment.start + lastSegment.duration / 2)) && media.readyState && media.duration > 0 && ((_this$_bufferService3 = this._bufferService) === null || _this$_bufferService3 === void 0 ? void 0 : _this$_bufferService3.msIsOpened) && !((_this$_bufferService4 = this._bufferService) !== null && _this$_bufferService4 !== void 0 && _this$_bufferService4.msHasOpTasks);
14567
15527
  if (!eosAllowed) {
14568
15528
  return;
14569
15529
  }
@@ -14599,7 +15559,7 @@
14599
15559
  }]);
14600
15560
  return Hls2;
14601
15561
  }(EventEmitter);
14602
- _defineProperty$3(Hls, "version", "3.0.19-rc.0");
15562
+ _defineProperty$3(Hls, "version", "3.0.20-alpha.3");
14603
15563
  try {
14604
15564
  if (localStorage.getItem("xgd")) {
14605
15565
  Hls.enableLogger();
@@ -14690,6 +15650,7 @@
14690
15650
  }]);
14691
15651
  return PluginExtension2;
14692
15652
  }();
15653
+ var _excluded = ["currentTime"];
14693
15654
  function parseSwitchUrlArgs(args, plugin) {
14694
15655
  var player = plugin.player;
14695
15656
  var curTime = player.currentTime;
@@ -14700,9 +15661,14 @@
14700
15661
  case "boolean":
14701
15662
  options.seamless = args;
14702
15663
  break;
14703
- case "object":
14704
- Object.assign(options, args);
15664
+ case "object": {
15665
+ var currentTime = args.currentTime, rest = _objectWithoutProperties$1(args, _excluded);
15666
+ Object.assign(options, rest);
15667
+ if (typeof currentTime === "number") {
15668
+ options.startTime = currentTime;
15669
+ }
14705
15670
  break;
15671
+ }
14706
15672
  }
14707
15673
  return options;
14708
15674
  }
@@ -14712,10 +15678,11 @@
14712
15678
  function HlsPlugin2() {
14713
15679
  var _this;
14714
15680
  _classCallCheck$3(this, HlsPlugin2);
14715
- for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
14716
- _args[_key] = arguments[_key];
15681
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
15682
+ args[_key] = arguments[_key];
14717
15683
  }
14718
- _this = _super.call.apply(_super, [this].concat(_args));
15684
+ _this = _super.call.apply(_super, [this].concat(args));
15685
+ _defineProperty$3(_assertThisInitialized$2(_this), "logger", logger);
14719
15686
  _defineProperty$3(_assertThisInitialized$2(_this), "hls", null);
14720
15687
  _defineProperty$3(_assertThisInitialized$2(_this), "pluginExtension", null);
14721
15688
  _defineProperty$3(_assertThisInitialized$2(_this), "getStats", function() {
@@ -14727,24 +15694,6 @@
14727
15694
  var lang = _ref.lang;
14728
15695
  (_this$hls2 = _this.hls) === null || _this$hls2 === void 0 ? void 0 : _this$hls2.switchSubtitleStream(lang);
14729
15696
  });
14730
- _defineProperty$3(_assertThisInitialized$2(_this), "_onSwitchURL", function(url, args) {
14731
- return new Promise(function(resolve, reject) {
14732
- var _assertThisInitialize = _assertThisInitialized$2(_this), player = _assertThisInitialize.player, hls = _assertThisInitialize.hls;
14733
- if (hls) {
14734
- var _this$player$config, _this$player$config$h;
14735
- var options = parseSwitchUrlArgs(args, _assertThisInitialized$2(_this));
14736
- player.config.url = url;
14737
- hls.switchURL(url, options).then(function() {
14738
- return resolve(true);
14739
- }).catch(reject);
14740
- if (!options.seamless && (_this$player$config = _this.player.config) !== null && _this$player$config !== void 0 && (_this$player$config$h = _this$player$config.hls) !== null && _this$player$config$h !== void 0 && _this$player$config$h.keepStatusAfterSwitch) {
14741
- _this._keepPauseStatus();
14742
- }
14743
- } else {
14744
- reject();
14745
- }
14746
- });
14747
- });
14748
15697
  _defineProperty$3(_assertThisInitialized$2(_this), "_keepPauseStatus", function() {
14749
15698
  var paused = _this.player.paused;
14750
15699
  if (!paused)
@@ -14769,8 +15718,8 @@
14769
15718
  }, {
14770
15719
  key: "softDecode",
14771
15720
  get: function get() {
14772
- var _this$player, _this$player$config2;
14773
- var mediaType = (_this$player = this.player) === null || _this$player === void 0 ? void 0 : (_this$player$config2 = _this$player.config) === null || _this$player$config2 === void 0 ? void 0 : _this$player$config2.mediaType;
15721
+ var _this$player, _this$player$config;
15722
+ var mediaType = (_this$player = this.player) === null || _this$player === void 0 ? void 0 : (_this$player$config = _this$player.config) === null || _this$player$config === void 0 ? void 0 : _this$player$config.mediaType;
14774
15723
  return !!mediaType && mediaType !== "video" && mediaType !== "audio";
14775
15724
  }
14776
15725
  }, {
@@ -14778,13 +15727,35 @@
14778
15727
  value: function beforePlayerInit() {
14779
15728
  var _this2 = this;
14780
15729
  var config = this.player.config;
15730
+ var mediaElem = this.player.media || this.player.video;
14781
15731
  var hlsOpts = config.hls || {};
14782
15732
  if (!config.url && !config.__allowHlsEmptyUrl__ || !hlsOpts.preferMMS && MSE.isMMSOnly()) {
14783
15733
  return;
14784
15734
  }
14785
15735
  if (this.hls)
14786
15736
  this.hls.destroy();
14787
- this.player.switchURL = this._onSwitchURL;
15737
+ var descriptor = Object.getOwnPropertyDescriptor(this.player, "switchURL");
15738
+ if (!descriptor || descriptor.writable) {
15739
+ this.player.switchURL = function(url, args) {
15740
+ return new Promise(function(resolve, reject) {
15741
+ var player = _this2.player, hls = _this2.hls;
15742
+ if (hls) {
15743
+ var _this2$player$config, _this2$player$config$;
15744
+ var options = parseSwitchUrlArgs(args, _this2);
15745
+ player.config.url = url;
15746
+ hls.switchURL(url, options).then(function() {
15747
+ return resolve(true);
15748
+ }).catch(reject);
15749
+ if (!options.seamless && (_this2$player$config = _this2.player.config) !== null && _this2$player$config !== void 0 && (_this2$player$config$ = _this2$player$config.hls) !== null && _this2$player$config$ !== void 0 && _this2$player$config$.keepStatusAfterSwitch) {
15750
+ _this2._keepPauseStatus();
15751
+ }
15752
+ } else {
15753
+ reject();
15754
+ }
15755
+ });
15756
+ };
15757
+ }
15758
+ var onSwitchUrl = this.player.switchURL;
14788
15759
  this.player.handleSource = false;
14789
15760
  hlsOpts.innerDegrade = hlsOpts.innerDegrade || config.innerDegrade;
14790
15761
  if (hlsOpts.disconnectTime === null || hlsOpts.disconnectTime === void 0)
@@ -14792,7 +15763,7 @@
14792
15763
  this.hls = new Hls(_objectSpread2$2({
14793
15764
  softDecode: this.softDecode,
14794
15765
  isLive: config.isLive,
14795
- media: this.player.media || this.player.video,
15766
+ media: mediaElem,
14796
15767
  startTime: config.startTime,
14797
15768
  url: config.url
14798
15769
  }, hlsOpts));
@@ -14810,7 +15781,7 @@
14810
15781
  if (this.softDecode) {
14811
15782
  this.pluginExtension = new PluginExtension(_objectSpread2$2({
14812
15783
  isLive: config.isLive,
14813
- media: this.player.video
15784
+ media: mediaElem
14814
15785
  }, hlsOpts), this);
14815
15786
  this.player.forceDegradeToVideo = function() {
14816
15787
  var _this2$pluginExtensio;
@@ -14827,8 +15798,8 @@
14827
15798
  return (_this2$hls2 = _this2.hls) === null || _this2$hls2 === void 0 ? void 0 : _this2$hls2.replay();
14828
15799
  });
14829
15800
  }
15801
+ this.on(URL_CHANGE, onSwitchUrl);
14830
15802
  this.on(SWITCH_SUBTITLE, this._onSwitchSubtitle);
14831
- this.on(URL_CHANGE, this._onSwitchURL);
14832
15803
  this.on(DESTROY, this.destroy.bind(this));
14833
15804
  this._transError();
14834
15805
  this._transCoreEvent(EVENT.TTFB);
@@ -14838,6 +15809,7 @@
14838
15809
  this._transCoreEvent(EVENT.LOAD_RETRY);
14839
15810
  this._transCoreEvent(EVENT.SOURCEBUFFER_CREATED);
14840
15811
  this._transCoreEvent(EVENT.MEDIASOURCE_OPENED);
15812
+ this._transCoreEvent(EVENT.APPEND_BUFFER);
14841
15813
  this._transCoreEvent(EVENT.REMOVE_BUFFER);
14842
15814
  this._transCoreEvent(EVENT.BUFFEREOS);
14843
15815
  this._transCoreEvent(EVENT.KEYFRAME);
@@ -14857,7 +15829,9 @@
14857
15829
  this._transCoreEvent(Event$1.SUBTITLE_PLAYLIST);
14858
15830
  this._transCoreEvent(Event$1.APPEND_COST);
14859
15831
  if (config.url) {
14860
- this.hls.load(config.url, true).catch(function(e) {
15832
+ this.hls.load(config.url, {
15833
+ reuseMse: true
15834
+ }).catch(function(e) {
14861
15835
  });
14862
15836
  }
14863
15837
  }