@volcengine/veplayer-plugin 2.4.5-rc.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/esm/index.development.js +2267 -578
  2. package/esm/index.production.js +3 -3
  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 +729 -196
  8. package/esm/veplayer.plugin.flv.production.js +1 -1
  9. package/esm/veplayer.plugin.hls.development.js +1505 -378
  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 +213 -48
  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 +729 -196
  23. package/umd/veplayer.plugin.flv.production.js +1 -1
  24. package/umd/veplayer.plugin.hls.development.js +1472 -345
  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 +213 -48
  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.21-rc.2";
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,16 @@
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",
5780
+ MP3: "mp3"
5640
5781
  };
5641
5782
  var WarningType = {
5642
5783
  LARGE_AV_SHIFT: "LARGE_AV_SHIFT",
@@ -5676,6 +5817,7 @@
5676
5817
  _defineProperty(this, "isVideoEncryption", false);
5677
5818
  _defineProperty(this, "isAudioEncryption", false);
5678
5819
  _defineProperty(this, "isVideo", true);
5820
+ _defineProperty(this, "lastKeyFrameDts", 0);
5679
5821
  _defineProperty(this, "kid", null);
5680
5822
  _defineProperty(this, "pssh", null);
5681
5823
  _defineProperty(this, "ext", void 0);
@@ -5718,6 +5860,9 @@
5718
5860
  }, {
5719
5861
  key: "exist",
5720
5862
  value: function exist() {
5863
+ if (/av01/.test(this.codec)) {
5864
+ return true;
5865
+ }
5721
5866
  return !!(this.pps.length && this.sps.length && this.codec);
5722
5867
  }
5723
5868
  }, {
@@ -5741,6 +5886,7 @@
5741
5886
  _defineProperty(this, "codecType", AudioCodecType.AAC);
5742
5887
  _defineProperty(this, "pid", -1);
5743
5888
  _defineProperty(this, "codec", "");
5889
+ _defineProperty(this, "container", "");
5744
5890
  _defineProperty(this, "sequenceNumber", 0);
5745
5891
  _defineProperty(this, "sampleDuration", 0);
5746
5892
  _defineProperty(this, "timescale", 0);
@@ -5781,7 +5927,7 @@
5781
5927
  }, {
5782
5928
  key: "exist",
5783
5929
  value: function exist() {
5784
- return !!(this.sampleRate && this.channelCount && this.codec && this.codecType === AudioCodecType.AAC);
5930
+ return !!(this.sampleRate && this.channelCount && (this.codec || this.container) && (this.codecType === AudioCodecType.AAC || this.codecType === AudioCodecType.G711PCMA || this.codecType === AudioCodecType.G711PCMU || this.codecType === AudioCodecType.OPUS || this.codecType === AudioCodecType.MP3));
5785
5931
  }
5786
5932
  }, {
5787
5933
  key: "hasSample",
@@ -5986,7 +6132,7 @@
5986
6132
  continue;
5987
6133
  }
5988
6134
  frameLength = (data[i + 3] & 3) << 11 | data[i + 4] << 3 | (data[i + 5] & 224) >> 5;
5989
- if (len - i < frameLength)
6135
+ if (!frameLength || len - i < frameLength)
5990
6136
  break;
5991
6137
  protectionSkipBytes = (~data[i + 1] & 1) * 2;
5992
6138
  frames.push({
@@ -6180,6 +6326,15 @@
6180
6326
  return parseInt(item, 16);
6181
6327
  });
6182
6328
  }
6329
+ function combineToFloat(integer, decimal) {
6330
+ return Number(integer + "." + decimal);
6331
+ }
6332
+ function toDegree(matrix) {
6333
+ if (matrix.length < 5)
6334
+ return 0;
6335
+ var scaled0 = Math.hypot(matrix[0], matrix[3]), scaled1 = Math.hypot(matrix[1], matrix[4]);
6336
+ return 0 === scaled0 || 0 === scaled1 ? 0 : 180 * Math.atan2(matrix[1] / scaled1, matrix[0] / scaled0) / Math.PI;
6337
+ }
6183
6338
  var NALu = /* @__PURE__ */ function() {
6184
6339
  function NALu2() {
6185
6340
  _classCallCheck(this, NALu2);
@@ -6842,13 +6997,16 @@
6842
6997
  var AUDIO_EXCETION_LOG_EMIT_DURATION = 5 * 9e4;
6843
6998
  var MAX_VIDEO_FRAME_DURATION = 9e4;
6844
6999
  var MAX_DTS_DELTA_WITH_NEXT_CHUNK = 9e4 / 2;
7000
+ var LARGE_AV_FIRST_FRAME_FORCE_FIX_THRESHOLD = 9e4 * 5;
6845
7001
  var TsFixer = /* @__PURE__ */ function() {
6846
- function TsFixer2(videoTrack, audioTrack, metadataTrack) {
7002
+ function TsFixer2(videoTrack, audioTrack, metadataTrack, fixerConfig) {
6847
7003
  _classCallCheck(this, TsFixer2);
6848
7004
  this.videoTrack = videoTrack;
6849
7005
  this.audioTrack = audioTrack;
6850
7006
  this.metadataTrack = metadataTrack;
6851
7007
  this._baseDts = -1;
7008
+ this._baseVideoDts = -1;
7009
+ this._baseAudioDts = -1;
6852
7010
  this._baseDtsInited = false;
6853
7011
  this._audioNextPts = void 0;
6854
7012
  this._videoNextDts = void 0;
@@ -6857,6 +7015,8 @@
6857
7015
  this._lastAudioExceptionGapDot = 0;
6858
7016
  this._lastAudioExceptionOverlapDot = 0;
6859
7017
  this._lastAudioExceptionLargeGapDot = 0;
7018
+ this._needForceFixLargeGap = fixerConfig === null || fixerConfig === void 0 ? void 0 : fixerConfig.forceFixLargeGap;
7019
+ this._largeGapThreshold = (fixerConfig === null || fixerConfig === void 0 ? void 0 : fixerConfig.largeGapThreshold) || LARGE_AV_FIRST_FRAME_FORCE_FIX_THRESHOLD;
6860
7020
  }
6861
7021
  _createClass(TsFixer2, [{
6862
7022
  key: "fix",
@@ -6884,10 +7044,16 @@
6884
7044
  if (discontinuity) {
6885
7045
  this._calculateBaseDts(this.audioTrack, this.videoTrack);
6886
7046
  this._baseDts -= startTime;
7047
+ this._baseAudioDts -= startTime;
7048
+ this._baseVideoDts -= startTime;
6887
7049
  }
6888
7050
  if (!contiguous) {
6889
7051
  this._videoNextDts = vaDelta > 0 ? startTime + vaDelta : startTime;
6890
7052
  this._audioNextPts = vaDelta > 0 ? startTime : startTime - vaDelta;
7053
+ if (this._needForceFixLargeGap) {
7054
+ this._videoNextDts = 0;
7055
+ this._audioNextPts = 0;
7056
+ }
6891
7057
  var vDeltaToNextDts = firstVideoSample ? firstVideoSample.dts - this._baseDts - this._videoNextDts : 0;
6892
7058
  var aDeltaToNextDts = firstAudioSample ? firstAudioSample.pts - this._baseDts - this._audioNextPts : 0;
6893
7059
  if (Math.abs(vDeltaToNextDts || aDeltaToNextDts) > MAX_VIDEO_FRAME_DURATION) {
@@ -6920,8 +7086,8 @@
6920
7086
  if (!samples.length)
6921
7087
  return;
6922
7088
  samples.forEach(function(x) {
6923
- x.dts -= _this2._baseDts;
6924
- x.pts -= _this2._baseDts;
7089
+ x.dts -= _this2._needForceFixLargeGap ? _this2._baseVideoDts : _this2._baseDts;
7090
+ x.pts -= _this2._needForceFixLargeGap ? _this2._baseVideoDts : _this2._baseDts;
6925
7091
  });
6926
7092
  if (this._videoNextDts === void 0) {
6927
7093
  var samp0 = samples[0];
@@ -7014,7 +7180,7 @@
7014
7180
  if (!samples.length)
7015
7181
  return;
7016
7182
  samples.forEach(function(x) {
7017
- x.pts -= _this3._baseDts;
7183
+ x.pts -= _this3._needForceFixLargeGap ? _this3._baseAudioDts : _this3._baseDts;
7018
7184
  x.dts = x.pts;
7019
7185
  });
7020
7186
  this._doFixAudioInternal(audioTrack, samples, 9e4);
@@ -7031,12 +7197,15 @@
7031
7197
  var videoBaseDts = Infinity;
7032
7198
  if (audioSamps.length) {
7033
7199
  audioTrack.baseDts = audioBasePts = audioSamps[0].pts;
7200
+ this._baseAudioDts = audioBasePts;
7034
7201
  }
7035
7202
  if (videoSamps.length) {
7036
7203
  videoTrack.baseDts = videoBaseDts = videoSamps[0].dts;
7204
+ this._baseVideoDts = videoBaseDts;
7037
7205
  }
7038
7206
  this._baseDts = Math.min(audioBasePts, videoBaseDts);
7039
7207
  var delta = videoBaseDts - audioBasePts;
7208
+ var largeGap = false;
7040
7209
  if (Number.isFinite(delta) && Math.abs(delta) > LARGE_AV_FIRST_FRAME_GAP) {
7041
7210
  videoTrack.warnings.push({
7042
7211
  type: WarningType.LARGE_AV_SHIFT,
@@ -7046,6 +7215,16 @@
7046
7215
  delta
7047
7216
  });
7048
7217
  }
7218
+ if (Number.isFinite(delta) && Math.abs(delta) > this._largeGapThreshold * MAX_SILENT_FRAME_DURATION) {
7219
+ largeGap = true;
7220
+ }
7221
+ if (!this._baseDtsInited) {
7222
+ if (largeGap && this._needForceFixLargeGap) {
7223
+ this._needForceFixLargeGap = true;
7224
+ } else {
7225
+ this._needForceFixLargeGap = false;
7226
+ }
7227
+ }
7049
7228
  this._baseDtsInited = true;
7050
7229
  return true;
7051
7230
  }
@@ -7136,9 +7315,119 @@
7136
7315
  }]);
7137
7316
  return TsFixer2;
7138
7317
  }();
7318
+ var BitratesMap = [32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160];
7319
+ var FREQ = [44100, 48e3, 32e3, 22050, 24e3, 16e3, 11025, 12e3, 8e3];
7320
+ var SamplesCoefficients = [
7321
+ [
7322
+ 0,
7323
+ 72,
7324
+ 144,
7325
+ 12
7326
+ ],
7327
+ [
7328
+ 0,
7329
+ 0,
7330
+ 0,
7331
+ 0
7332
+ ],
7333
+ [
7334
+ 0,
7335
+ 72,
7336
+ 144,
7337
+ 12
7338
+ ],
7339
+ [
7340
+ 0,
7341
+ 144,
7342
+ 144,
7343
+ 12
7344
+ ]
7345
+ ];
7346
+ var BytesInSlot = [
7347
+ 0,
7348
+ 1,
7349
+ 1,
7350
+ 4
7351
+ ];
7352
+ var chromeVersion = null;
7353
+ var MPEG = /* @__PURE__ */ function() {
7354
+ function MPEG2() {
7355
+ _classCallCheck(this, MPEG2);
7356
+ }
7357
+ _createClass(MPEG2, null, [{
7358
+ key: "isHeader",
7359
+ value: function isHeader(data, offset) {
7360
+ return offset + 1 < data.length && data[offset] === 255 && (data[offset + 1] & 224) === 224 && (data[offset + 1] & 6) !== 0;
7361
+ }
7362
+ }, {
7363
+ key: "appendFrame",
7364
+ value: function appendFrame(track, data, offset, pts, frameIndex) {
7365
+ if (offset + 24 > data.length) {
7366
+ return;
7367
+ }
7368
+ var header = MPEG2.parseHeader(data, offset);
7369
+ if (header && offset + header.frameLength <= data.length) {
7370
+ var frameDuration = header.samplesPerFrame * 9e4 / header.sampleRate;
7371
+ var stamp = pts + frameIndex * frameDuration;
7372
+ var sample = {
7373
+ data: data.subarray(offset, offset + header.frameLength),
7374
+ pts: stamp,
7375
+ dts: stamp
7376
+ };
7377
+ sample.size = sample.data.byteLength;
7378
+ track.config = [];
7379
+ track.channelCount = header.channelCount;
7380
+ track.sampleRate = header.sampleRate;
7381
+ track.container = "audio/mpeg";
7382
+ track.samples.push(sample);
7383
+ return {
7384
+ length: header.frameLength
7385
+ };
7386
+ }
7387
+ }
7388
+ }, {
7389
+ key: "parseHeader",
7390
+ value: function parseHeader(data, offset) {
7391
+ var mpegVersion = data[offset + 1] >> 3 & 3;
7392
+ var mpegLayer = data[offset + 1] >> 1 & 3;
7393
+ var bitRateIndex = data[offset + 2] >> 4 & 15;
7394
+ var sampleRateIndex = data[offset + 2] >> 2 & 3;
7395
+ if (mpegVersion !== 1 && bitRateIndex !== 0 && bitRateIndex !== 15 && sampleRateIndex !== 3) {
7396
+ var paddingBit = data[offset + 2] >> 1 & 1;
7397
+ var channelMode = data[offset + 3] >> 6;
7398
+ var columnInBitrates = mpegVersion === 3 ? 3 - mpegLayer : mpegLayer === 3 ? 3 : 4;
7399
+ var bitRate = BitratesMap[columnInBitrates * 14 + bitRateIndex - 1] * 1e3;
7400
+ var columnInSampleRates = mpegVersion === 3 ? 0 : mpegVersion === 2 ? 1 : 2;
7401
+ var sampleRate = FREQ[columnInSampleRates * 3 + sampleRateIndex];
7402
+ var channelCount = channelMode === 3 ? 1 : 2;
7403
+ var sampleCoefficient = SamplesCoefficients[mpegVersion][mpegLayer];
7404
+ var bytesInSlot = BytesInSlot[mpegLayer];
7405
+ var samplesPerFrame = sampleCoefficient * 8 * bytesInSlot;
7406
+ var frameLength = Math.floor(sampleCoefficient * bitRate / sampleRate + paddingBit) * bytesInSlot;
7407
+ if (chromeVersion === null) {
7408
+ var userAgent = navigator.userAgent || "";
7409
+ var result = userAgent.match(/Chrome\/(\d+)/i);
7410
+ chromeVersion = result ? parseInt(result[1]) : 0;
7411
+ }
7412
+ var needChromeFix = !!chromeVersion && chromeVersion <= 87;
7413
+ if (needChromeFix && mpegLayer === 2 && bitRate >= 224e3 && channelMode === 0) {
7414
+ data[offset + 3] = data[offset + 3] | 128;
7415
+ }
7416
+ return {
7417
+ sampleRate,
7418
+ channelCount,
7419
+ frameLength,
7420
+ samplesPerFrame
7421
+ };
7422
+ }
7423
+ }
7424
+ }]);
7425
+ return MPEG2;
7426
+ }();
7139
7427
  var logger$4 = new Logger$1("TsDemuxer");
7140
7428
  var TsDemuxer = /* @__PURE__ */ function() {
7141
7429
  function TsDemuxer2(videoTrack, audioTrack, metadataTrack) {
7430
+ var fixerConfig = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
7142
7431
  _classCallCheck(this, TsDemuxer2);
7143
7432
  _defineProperty(this, "_pmtId", -1);
7144
7433
  _defineProperty(this, "_remainingPacketData", null);
@@ -7148,7 +7437,7 @@
7148
7437
  this.videoTrack = videoTrack || new VideoTrack();
7149
7438
  this.audioTrack = audioTrack || new AudioTrack();
7150
7439
  this.metadataTrack = metadataTrack || new MetadataTrack();
7151
- this._fixer = new TsFixer(this.videoTrack, this.audioTrack, this.metadataTrack);
7440
+ this._fixer = new TsFixer(this.videoTrack, this.audioTrack, this.metadataTrack, fixerConfig);
7152
7441
  }
7153
7442
  _createClass(TsDemuxer2, [{
7154
7443
  key: "demux",
@@ -7218,6 +7507,11 @@
7218
7507
  case 15:
7219
7508
  audioTrack.pid = audioPid = esPid;
7220
7509
  break;
7510
+ case 3:
7511
+ case 4:
7512
+ audioTrack.pid = audioPid = esPid;
7513
+ audioTrack.codecType = AudioCodecType.MP3;
7514
+ break;
7221
7515
  case 27:
7222
7516
  if (videoPid !== -1)
7223
7517
  break;
@@ -7417,7 +7711,14 @@
7417
7711
  logger$4.warn("Cannot parse audio pes", this._audioPesData);
7418
7712
  return;
7419
7713
  }
7420
- this._parseAacData(pes);
7714
+ switch (this.audioTrack.codecType) {
7715
+ case AudioCodecType.AAC:
7716
+ this._parseAacData(pes);
7717
+ break;
7718
+ case AudioCodecType.MP3:
7719
+ this._parseMPEG(pes);
7720
+ break;
7721
+ }
7421
7722
  this._audioPesData = [];
7422
7723
  }
7423
7724
  }, {
@@ -7454,6 +7755,32 @@
7454
7755
  logger$4.warn("Cannot parse aac adts", pes);
7455
7756
  }
7456
7757
  }
7758
+ }, {
7759
+ key: "_parseMPEG",
7760
+ value: function _parseMPEG(pes) {
7761
+ var data = pes.data;
7762
+ var length = data.length;
7763
+ var frameIndex = 0;
7764
+ var offset = 0;
7765
+ var pts = pes.pts;
7766
+ if (pts === void 0) {
7767
+ logger$4.warn("[tsdemuxer]: MPEG PES unknown PTS");
7768
+ return;
7769
+ }
7770
+ while (offset < length) {
7771
+ if (MPEG.isHeader(data, offset)) {
7772
+ var frame = MPEG.appendFrame(this.audioTrack, data, offset, pts, frameIndex);
7773
+ if (frame) {
7774
+ offset += frame.length;
7775
+ frameIndex++;
7776
+ } else {
7777
+ break;
7778
+ }
7779
+ } else {
7780
+ offset++;
7781
+ }
7782
+ }
7783
+ }
7457
7784
  }], [{
7458
7785
  key: "probe",
7459
7786
  value: function probe(data) {
@@ -7495,6 +7822,207 @@
7495
7822
  }]);
7496
7823
  return TsDemuxer2;
7497
7824
  }();
7825
+ var ByteReader = /* @__PURE__ */ function() {
7826
+ function ByteReader2(buf, offset, len) {
7827
+ _classCallCheck(this, ByteReader2);
7828
+ this.dv = new DataView(buf);
7829
+ this.start = this.offset = offset || this.dv.byteOffset;
7830
+ this.end = len ? this.start + len : this.start + this.dv.byteLength;
7831
+ }
7832
+ _createClass(ByteReader2, [{
7833
+ key: "buffer",
7834
+ get: function get() {
7835
+ return this.dv.buffer;
7836
+ }
7837
+ }, {
7838
+ key: "unreadLength",
7839
+ get: function get() {
7840
+ return Math.max(this.end - this.offset, 0);
7841
+ }
7842
+ }, {
7843
+ key: "size",
7844
+ get: function get() {
7845
+ return this.end - this.start;
7846
+ }
7847
+ }, {
7848
+ key: "readFloat",
7849
+ value: function readFloat(byteNum) {
7850
+ var val = 0;
7851
+ switch (byteNum) {
7852
+ case 4:
7853
+ val = this.dv.getFloat32(this.offset);
7854
+ break;
7855
+ case 8:
7856
+ val = this.dv.getFloat64(this.offset);
7857
+ break;
7858
+ default:
7859
+ throw new Error("read ".concat(byteNum, "-byte float is not supported"));
7860
+ }
7861
+ this.offset += byteNum;
7862
+ return val;
7863
+ }
7864
+ }, {
7865
+ key: "back",
7866
+ value: function back(byteNum) {
7867
+ this.offset -= byteNum;
7868
+ }
7869
+ }, {
7870
+ key: "skip",
7871
+ value: function skip(byteNum) {
7872
+ this.offset += byteNum;
7873
+ }
7874
+ }, {
7875
+ key: "readInt",
7876
+ value: function readInt(byteNum) {
7877
+ var offset = this.offset;
7878
+ this.offset += byteNum;
7879
+ switch (byteNum) {
7880
+ case 1:
7881
+ return this.dv.getInt8(offset);
7882
+ case 2:
7883
+ return this.dv.getInt16(offset);
7884
+ case 4:
7885
+ return this.dv.getInt32(offset);
7886
+ default:
7887
+ throw new Error("read ".concat(byteNum, "-byte integers is not supported"));
7888
+ }
7889
+ }
7890
+ }, {
7891
+ key: "read",
7892
+ value: function read(byteNum) {
7893
+ var offset = this.offset;
7894
+ this.offset += byteNum;
7895
+ switch (byteNum) {
7896
+ case 1:
7897
+ return this.dv.getUint8(offset);
7898
+ case 2:
7899
+ return this.dv.getUint16(offset);
7900
+ case 3:
7901
+ return (this.dv.getUint16(offset) << 8) + this.dv.getUint8(offset + 2);
7902
+ case 4:
7903
+ return this.dv.getUint32(offset);
7904
+ default:
7905
+ this.back(byteNum - 4);
7906
+ return this.read(byteNum - 4) + this.dv.getUint32(offset) * Math.pow(256, byteNum - 4);
7907
+ }
7908
+ }
7909
+ }, {
7910
+ key: "write",
7911
+ value: function write(byteNum, val) {
7912
+ var offset = this.offset;
7913
+ this.offset += byteNum;
7914
+ switch (byteNum) {
7915
+ case 1:
7916
+ return this.dv.setUint8(offset, val);
7917
+ case 2:
7918
+ return this.dv.setUint16(offset, val);
7919
+ case 3:
7920
+ return this.dv.setUint8(offset, val >>> 16), this.dv.setUint16(offset + 1, 65535 & val);
7921
+ case 4:
7922
+ return this.dv.setUint32(offset, val);
7923
+ default:
7924
+ throw new Error("write ".concat(byteNum, "-byte integers is not supported"));
7925
+ }
7926
+ }
7927
+ }, {
7928
+ key: "readToBuffer",
7929
+ value: function readToBuffer(len) {
7930
+ var buffer;
7931
+ if (this.offset || len) {
7932
+ buffer = this.dv.buffer.slice(this.offset, len ? this.offset + len : this.end);
7933
+ } else {
7934
+ buffer = this.dv.buffer;
7935
+ }
7936
+ this.offset += buffer.byteLength;
7937
+ return buffer;
7938
+ }
7939
+ }, {
7940
+ key: "readToUint8",
7941
+ value: function readToUint8(len) {
7942
+ var uint8 = new Uint8Array(this.dv.buffer, this.offset, len || this.unreadLength);
7943
+ this.offset += uint8.byteLength;
7944
+ return uint8;
7945
+ }
7946
+ }, {
7947
+ key: "readString",
7948
+ value: function readString(len) {
7949
+ var i = 0, str = "";
7950
+ for (; i < len; i++) {
7951
+ str += String.fromCharCode(this.dv.getUint8(this.offset));
7952
+ this.offset++;
7953
+ }
7954
+ return str;
7955
+ }
7956
+ }], [{
7957
+ key: "fromUint8",
7958
+ value: function fromUint8(uint8) {
7959
+ return new ByteReader2(uint8.buffer, uint8.byteOffset, uint8.byteLength);
7960
+ }
7961
+ }, {
7962
+ key: "concatUint8s",
7963
+ value: function concatUint8s(args) {
7964
+ var uint8 = new Uint8Array(args.reduce(function(ret, v) {
7965
+ return ret + v.byteLength;
7966
+ }, 0));
7967
+ var offset = 0;
7968
+ args.forEach(function(v) {
7969
+ uint8.set(v, offset);
7970
+ offset += v.byteLength;
7971
+ });
7972
+ return uint8;
7973
+ }
7974
+ }, {
7975
+ key: "concatUint8",
7976
+ value: function concatUint8() {
7977
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
7978
+ args[_key] = arguments[_key];
7979
+ }
7980
+ return this.concatUint8s(args);
7981
+ }
7982
+ }]);
7983
+ return ByteReader2;
7984
+ }();
7985
+ var BitReader = /* @__PURE__ */ function() {
7986
+ function BitReader2(val, size) {
7987
+ _classCallCheck(this, BitReader2);
7988
+ this.offset = 0;
7989
+ this.val = val;
7990
+ this.size = size;
7991
+ }
7992
+ _createClass(BitReader2, [{
7993
+ key: "skip",
7994
+ value: function skip(len) {
7995
+ this.offset += len;
7996
+ }
7997
+ }, {
7998
+ key: "read",
7999
+ value: function read(len) {
8000
+ var unreadLength = this.size - this.offset - len;
8001
+ if (unreadLength >= 0) {
8002
+ var bits = 0, i = 0;
8003
+ this.offset += len;
8004
+ if (this.size > 31) {
8005
+ for (; i < len; i++) {
8006
+ bits += Math.pow(2, i);
8007
+ }
8008
+ return this.val / Math.pow(2, unreadLength) & bits;
8009
+ } else {
8010
+ for (; i < len; i++) {
8011
+ bits += 1 << i;
8012
+ }
8013
+ return this.val >>> unreadLength & bits;
8014
+ }
8015
+ }
8016
+ throw new Error("the number of the read operation exceeds the total length limit of bits");
8017
+ }
8018
+ }], [{
8019
+ key: "fromByte",
8020
+ value: function fromByte(byte, len) {
8021
+ return new BitReader2(byte.read(len), len << 3);
8022
+ }
8023
+ }]);
8024
+ return BitReader2;
8025
+ }();
7498
8026
  var MP4Parser = /* @__PURE__ */ function() {
7499
8027
  function MP4Parser2() {
7500
8028
  _classCallCheck(this, MP4Parser2);
@@ -7652,18 +8180,36 @@
7652
8180
  key: "tkhd",
7653
8181
  value: function tkhd(box) {
7654
8182
  return parseBox(box, true, function(ret, data) {
7655
- var start = 0;
8183
+ var byte = ByteReader.fromUint8(data);
7656
8184
  if (ret.version === 1) {
7657
- ret.trackId = readBig32(data, 16);
7658
- ret.duration = readBig64(data, 24);
7659
- start += 32;
8185
+ byte.read(8);
8186
+ byte.read(8);
8187
+ ret.trackId = byte.read(4);
8188
+ byte.read(4);
8189
+ ret.duration = byte.read(8);
7660
8190
  } else {
7661
- ret.trackId = readBig32(data, 8);
7662
- ret.duration = readBig32(data, 16);
7663
- start += 20;
8191
+ byte.read(4);
8192
+ byte.read(4);
8193
+ ret.trackId = byte.read(4);
8194
+ byte.read(4);
8195
+ ret.duration = byte.read(4);
8196
+ }
8197
+ byte.skip(16);
8198
+ ret.matrix = [];
8199
+ for (var i = 0; i < 36; i++) {
8200
+ ret.matrix.push(byte.read(1));
8201
+ }
8202
+ byte.back(36);
8203
+ var caculatedMatrix = [];
8204
+ for (var _i = 0, int32; _i < 3; _i++) {
8205
+ caculatedMatrix.push(combineToFloat(byte.readInt(2), byte.readInt(2)));
8206
+ caculatedMatrix.push(combineToFloat(byte.readInt(2), byte.readInt(2)));
8207
+ int32 = byte.readInt(4);
8208
+ caculatedMatrix.push(combineToFloat(int32 >> 30, int32 & 1073741823));
7664
8209
  }
7665
- ret.width = readBig32(data, start + 52);
7666
- ret.height = readBig32(data, start + 56);
8210
+ ret.rotation = toDegree(caculatedMatrix);
8211
+ ret.width = byte.read(4);
8212
+ ret.height = byte.read(4);
7667
8213
  });
7668
8214
  }
7669
8215
  }, {
@@ -7793,7 +8339,7 @@
7793
8339
  if (ret.version > 0) {
7794
8340
  var numKeyIds = readBig32(data, start);
7795
8341
  start += 4;
7796
- for (var _i = 0; _i < ("" + numKeyIds).length; _i++) {
8342
+ for (var _i2 = 0; _i2 < ("" + numKeyIds).length; _i2++) {
7797
8343
  for (var j = 0; j < 16; j++) {
7798
8344
  var keyId = data[start];
7799
8345
  start += 1;
@@ -7816,6 +8362,8 @@
7816
8362
  ret.entryCount = readBig32(data);
7817
8363
  ret.entries = MP4Parser2.findBox(data.subarray(4), [], start + 4).map(function(b) {
7818
8364
  switch (b.type) {
8365
+ case "av01":
8366
+ return MP4Parser2.av01(b);
7819
8367
  case "avc1":
7820
8368
  case "avc2":
7821
8369
  case "avc3":
@@ -7895,6 +8443,69 @@
7895
8443
  }
7896
8444
  });
7897
8445
  }
8446
+ }, {
8447
+ key: "colr",
8448
+ value: function colr(box) {
8449
+ return parseBox(box, false, function(ret, data) {
8450
+ var byte = ByteReader.fromUint8(data);
8451
+ ret.data = box.data;
8452
+ ret.colorType = byte.readString(4);
8453
+ if (ret.colorType === "nclx") {
8454
+ ret.colorPrimaries = byte.read(2);
8455
+ ret.transferCharacteristics = byte.read(2);
8456
+ ret.matrixCoefficients = byte.read(2);
8457
+ ret.fullRangeFlag = byte.read(1) >> 7;
8458
+ } else if (ret.colorType === "rICC" || ret.colorType === "prof") {
8459
+ ret.iccProfile = data.readToUint8();
8460
+ }
8461
+ });
8462
+ }
8463
+ }, {
8464
+ key: "av01",
8465
+ value: function av01(box) {
8466
+ return parseBox(box, false, function(ret, data, start) {
8467
+ var bodyStart = parseVisualSampleEntry(ret, data);
8468
+ var bodyData = data.subarray(bodyStart);
8469
+ start += bodyStart;
8470
+ ret.av1C = MP4Parser2.av1C(MP4Parser2.findBox(bodyData, ["av1C"], start)[0]);
8471
+ ret.colr = MP4Parser2.colr(MP4Parser2.findBox(bodyData, ["colr"], start)[0]);
8472
+ });
8473
+ }
8474
+ }, {
8475
+ key: "av1C",
8476
+ value: function av1C(box) {
8477
+ return parseBox(box, false, function(ret, data) {
8478
+ ret.data = box.data;
8479
+ var byte = ByteReader.fromUint8(data);
8480
+ var bit = BitReader.fromByte(byte, 4);
8481
+ ret.marker = bit.read(1);
8482
+ ret.version = bit.read(7);
8483
+ ret.seqProfile = bit.read(3);
8484
+ ret.seqLevelIdx0 = bit.read(5);
8485
+ ret.seqTier0 = bit.read(1);
8486
+ ret.highBitdepth = bit.read(1);
8487
+ ret.twelveBit = bit.read(1);
8488
+ ret.monochrome = bit.read(1);
8489
+ ret.chromaSubsamplingX = bit.read(1);
8490
+ ret.chromaSubsamplingY = bit.read(1);
8491
+ ret.chromaSamplePosition = bit.read(2);
8492
+ ret.reserved = bit.read(3);
8493
+ ret.initialPresentationDelayPresent = bit.read(1);
8494
+ if (ret.initialPresentationDelayPresent) {
8495
+ ret.initialPresentationDelayMinusOne = bit.read(4);
8496
+ } else {
8497
+ ret.initialPresentationDelayMinusOne = 0;
8498
+ }
8499
+ ret.configOBUs = byte.readToUint8();
8500
+ var bitdepth;
8501
+ if (ret.seqLevelIdx0 === 2 && ret.highBitdepth === 1) {
8502
+ bitdepth = ret.twelveBit === 1 ? "12" : "10";
8503
+ } else if (ret.seqProfile <= 2) {
8504
+ bitdepth = ret.highBitdepth === 1 ? "10" : "08";
8505
+ }
8506
+ ret.codec = ["av01", ret.seqProfile, (ret.seqLevelIdx0 < 10 ? "0" + ret.seqLevelIdx0 : ret.seqLevelIdx0) + (ret.seqTier0 ? "H" : "M"), bitdepth].join(".");
8507
+ });
8508
+ }
7898
8509
  }, {
7899
8510
  key: "avc1",
7900
8511
  value: function avc1(box) {
@@ -7929,7 +8540,7 @@
7929
8540
  ret.ppsLength = data[start];
7930
8541
  start += 1;
7931
8542
  ret.pps = [];
7932
- for (var _i2 = 0; _i2 < ret.ppsLength; _i2++) {
8543
+ for (var _i3 = 0; _i3 < ret.ppsLength; _i3++) {
7933
8544
  var _size = readBig16(data, start);
7934
8545
  start += 2;
7935
8546
  ret.pps.push(data.subarray(start, start += _size));
@@ -8098,7 +8709,7 @@
8098
8709
  start += 8;
8099
8710
  }
8100
8711
  } else {
8101
- for (var _i3 = 0; _i3 < entryCount; _i3++) {
8712
+ for (var _i4 = 0; _i4 < entryCount; _i4++) {
8102
8713
  entries.push({
8103
8714
  count: readBig32(data, start),
8104
8715
  offset: -(~readBig32(data, start + 4) + 1)
@@ -8320,13 +8931,20 @@
8320
8931
  v.mvhdTimecale = moov.mvhd.timescale;
8321
8932
  v.timescale = v.formatTimescale = vTrack.mdia.mdhd.timescale;
8322
8933
  v.duration = vTrack.mdia.mdhd.duration || v.mvhdDurtion / v.mvhdTimecale * v.timescale;
8934
+ v.rotation = vTrack.tkhd.rotation;
8935
+ v.matrix = vTrack.tkhd.matrix;
8323
8936
  var e1 = vTrack.mdia.minf.stbl.stsd.entries[0];
8324
8937
  v.width = e1.width;
8325
8938
  v.height = e1.height;
8326
8939
  if (e1.pasp) {
8327
8940
  v.sarRatio = [e1.pasp.hSpacing, e1.pasp.vSpacing];
8328
8941
  }
8329
- if (e1.hvcC) {
8942
+ if (e1.av1C) {
8943
+ v.codecType = VideoCodecType.AV1;
8944
+ v.codec = e1.av1C.codec;
8945
+ v.av1C = e1.av1C.data;
8946
+ v.colr = e1.colr.data;
8947
+ } else if (e1.hvcC) {
8330
8948
  v.codecType = VideoCodecType.HEVC;
8331
8949
  v.codec = e1.hvcC.codec;
8332
8950
  v.vps = e1.hvcC.vps;
@@ -8645,8 +9263,9 @@
8645
9263
  function parseBox(box, isFullBox, parse2) {
8646
9264
  if (!box)
8647
9265
  return;
8648
- if (box.size !== box.data.length)
9266
+ if (box.size !== box.data.length) {
8649
9267
  throw new Error("box ".concat(box.type, " size !== data.length"));
9268
+ }
8650
9269
  var ret = {
8651
9270
  start: box.start,
8652
9271
  size: box.size,
@@ -8685,29 +9304,185 @@
8685
9304
  var FMP4Demuxer = /* @__PURE__ */ function() {
8686
9305
  function FMP4Demuxer2(videoTrack, audioTrack, metadataTrack) {
8687
9306
  _classCallCheck(this, FMP4Demuxer2);
9307
+ _defineProperty(this, "__loadedMoofWraps", []);
9308
+ _defineProperty(this, "__lastRemainData", null);
9309
+ _defineProperty(this, "__lastRemainDataStart", 0);
9310
+ _defineProperty(this, "__nextMoofStart", -1);
8688
9311
  this.videoTrack = videoTrack || new VideoTrack();
8689
9312
  this.audioTrack = audioTrack || new AudioTrack();
8690
9313
  this.metadataTrack = metadataTrack || new MetadataTrack();
8691
9314
  }
8692
9315
  _createClass(FMP4Demuxer2, [{
8693
- key: "demux",
8694
- value: function demux(videoData, audioData) {
9316
+ key: "demuxPart",
9317
+ value: function demuxPart(partData, partDataStart, moov) {
9318
+ var _this = this;
8695
9319
  var videoTrack = this.videoTrack, audioTrack = this.audioTrack;
8696
9320
  var videoExist = videoTrack.exist();
8697
9321
  var audioExist = audioTrack.exist();
9322
+ var isAV01 = /av01/.test(videoTrack.codec);
8698
9323
  videoTrack.samples = [];
8699
9324
  audioTrack.samples = [];
8700
- if (audioData) {
8701
- if (!audioExist) {
8702
- var moovBox = MP4Parser.findBox(audioData, ["moov"])[0];
8703
- if (!moovBox)
8704
- throw new Error("cannot found moov box");
8705
- MP4Parser.moovToTrack(MP4Parser.moov(moovBox), null, audioTrack);
9325
+ var data = partData;
9326
+ var dataStart = partDataStart;
9327
+ if (this.__lastRemainData) {
9328
+ var lastRemainDataEnd = this.__lastRemainDataStart + this.__lastRemainData.byteLength;
9329
+ var continuous = partDataStart <= lastRemainDataEnd && partDataStart > this.__lastRemainDataStart && partDataStart + partData.byteLength > lastRemainDataEnd;
9330
+ if (continuous) {
9331
+ var noDuplicateData = partData.subarray(this.__lastRemainData.byteLength + this.__lastRemainDataStart - partDataStart);
9332
+ data = concatUint8Array(this.__lastRemainData, noDuplicateData);
9333
+ dataStart = this.__lastRemainDataStart;
9334
+ this.__lastRemainData = null;
9335
+ } else {
9336
+ this.__lastRemainData = null;
9337
+ this.__lastRemainDataStart = 0;
9338
+ this.__nextMoofStart = -1;
8706
9339
  }
8707
- var moofBox = MP4Parser.findBox(audioData, ["moof"])[0];
8708
- if (moofBox) {
8709
- var samples = MP4Parser.moofToSamples(MP4Parser.moof(moofBox), null, audioTrack)[audioTrack.id];
8710
- var baseMediaDecodeTime = audioTrack.baseMediaDecodeTime;
9340
+ }
9341
+ if (!moov) {
9342
+ var moovBox = MP4Parser.findBox(data, ["moov"])[0];
9343
+ if (!moovBox)
9344
+ throw new Error("cannot found moov box");
9345
+ moov = MP4Parser.moov(moovBox);
9346
+ }
9347
+ if (data) {
9348
+ var dataEnd = dataStart + data.byteLength;
9349
+ if (!videoExist && !audioExist) {
9350
+ MP4Parser.moovToTrack(moov, videoTrack, audioTrack);
9351
+ }
9352
+ var moofBoxes = [];
9353
+ if (this.__nextMoofStart < 0) {
9354
+ MP4Parser.findBox(data, ["moof"], dataStart).forEach(function(v) {
9355
+ return moofBoxes.push(v);
9356
+ });
9357
+ } else if (this.__nextMoofStart >= dataStart && this.__nextMoofStart <= dataEnd - 8) {
9358
+ MP4Parser.findBox(data.subarray(this.__nextMoofStart - dataStart), ["moof"], this.__nextMoofStart).forEach(function(v) {
9359
+ return moofBoxes.push(v);
9360
+ });
9361
+ }
9362
+ moofBoxes.filter(function(moofBox) {
9363
+ return moofBox.size <= moofBox.data.length;
9364
+ }).forEach(function(moofBox) {
9365
+ var moof = MP4Parser.moof(moofBox);
9366
+ _this.__nextMoofStart = moof.start + Math.max.apply(Math, _toConsumableArray(moof.traf.map(function(v) {
9367
+ return v.trun.samples.reduce(function(ret, w) {
9368
+ return ret + w.size;
9369
+ }, v.trun.dataOffset || 0);
9370
+ })));
9371
+ _this.__loadedMoofWraps.push({
9372
+ start: moof.start,
9373
+ nextMoofStart: _this.__nextMoofStart,
9374
+ moof
9375
+ });
9376
+ _this.__loadedMoofWraps.sort(function(p, n) {
9377
+ return p.start - n.start;
9378
+ });
9379
+ });
9380
+ var _iterator = _createForOfIteratorHelper(this.__loadedMoofWraps), _step;
9381
+ try {
9382
+ var _loop = function _loop2() {
9383
+ var moofWrap = _step.value;
9384
+ if (moofWrap.start > dataEnd || moofWrap.nextMoofStart < dataStart) {
9385
+ return "continue";
9386
+ }
9387
+ var moofStart = moofWrap.start;
9388
+ var tracks = MP4Parser.moofToSamples(moofWrap.moof, videoTrack, audioTrack);
9389
+ var videoBaseMediaDecodeTime = videoTrack.baseMediaDecodeTime;
9390
+ var audioBaseMediaDecodeTime = audioTrack.baseMediaDecodeTime;
9391
+ var nalSize;
9392
+ Object.keys(tracks).forEach(function(k) {
9393
+ if (videoTrack.id == k) {
9394
+ tracks[k].some(function(x) {
9395
+ var xStart = x.offset += moofStart;
9396
+ if (xStart < dataStart) {
9397
+ return;
9398
+ }
9399
+ if (xStart + x.size > dataEnd) {
9400
+ return true;
9401
+ }
9402
+ var sample = new VideoSample((x.pts || x.dts) + videoBaseMediaDecodeTime, x.dts + videoBaseMediaDecodeTime);
9403
+ sample.duration = x.duration;
9404
+ sample.gopId = x.gopId;
9405
+ if (x.keyframe)
9406
+ sample.setToKeyframe();
9407
+ var sampleData = data.subarray(xStart - dataStart, xStart - dataStart + x.size);
9408
+ sample.data = sampleData;
9409
+ if (!isAV01) {
9410
+ var start = 0;
9411
+ var len = sampleData.length - 1;
9412
+ while (start < len) {
9413
+ nalSize = readBig32(sampleData, start);
9414
+ start += 4;
9415
+ sample.units.push(sampleData.subarray(start, start + nalSize));
9416
+ start += nalSize;
9417
+ }
9418
+ }
9419
+ _this.__lastRemainDataStart = xStart + x.size;
9420
+ videoTrack.samples.push(sample);
9421
+ });
9422
+ } else if (audioTrack.id == k) {
9423
+ tracks[k].some(function(x) {
9424
+ var xStart = x.offset + moofStart;
9425
+ if (xStart < dataStart) {
9426
+ return;
9427
+ }
9428
+ if (xStart + x.size > dataEnd) {
9429
+ return true;
9430
+ }
9431
+ var sampleData = data.subarray(xStart - dataStart, xStart - dataStart + x.size);
9432
+ audioTrack.samples.push(new AudioSample(x.dts + audioBaseMediaDecodeTime, sampleData, x.duration));
9433
+ _this.__lastRemainDataStart = xStart + x.size;
9434
+ });
9435
+ }
9436
+ });
9437
+ };
9438
+ for (_iterator.s(); !(_step = _iterator.n()).done; ) {
9439
+ var _ret = _loop();
9440
+ if (_ret === "continue")
9441
+ continue;
9442
+ }
9443
+ } catch (err) {
9444
+ _iterator.e(err);
9445
+ } finally {
9446
+ _iterator.f();
9447
+ }
9448
+ }
9449
+ if (this.__lastRemainDataStart > dataStart && this.__lastRemainDataStart < data.byteLength + dataStart) {
9450
+ this.__lastRemainData = data.subarray(this.__lastRemainDataStart - dataStart);
9451
+ } else {
9452
+ this.__lastRemainData = data;
9453
+ this.__lastRemainDataStart = dataStart;
9454
+ }
9455
+ if (videoTrack.samples.length) {
9456
+ videoTrack.baseMediaDecodeTime = videoTrack.samples[0].pts;
9457
+ }
9458
+ if (audioTrack.samples.length) {
9459
+ audioTrack.baseMediaDecodeTime = audioTrack.samples[0].pts;
9460
+ }
9461
+ return {
9462
+ videoTrack,
9463
+ audioTrack,
9464
+ metadataTrack: this.metadataTrack
9465
+ };
9466
+ }
9467
+ }, {
9468
+ key: "demux",
9469
+ value: function demux(videoData, audioData) {
9470
+ var videoTrack = this.videoTrack, audioTrack = this.audioTrack;
9471
+ var videoExist = videoTrack.exist();
9472
+ var audioExist = audioTrack.exist();
9473
+ videoTrack.samples = [];
9474
+ audioTrack.samples = [];
9475
+ if (audioData) {
9476
+ if (!audioExist) {
9477
+ var moovBox = MP4Parser.findBox(audioData, ["moov"])[0];
9478
+ if (!moovBox)
9479
+ throw new Error("cannot found moov box");
9480
+ MP4Parser.moovToTrack(MP4Parser.moov(moovBox), null, audioTrack);
9481
+ }
9482
+ var moofBox = MP4Parser.findBox(audioData, ["moof"])[0];
9483
+ if (moofBox) {
9484
+ var samples = MP4Parser.moofToSamples(MP4Parser.moof(moofBox), null, audioTrack)[audioTrack.id];
9485
+ var baseMediaDecodeTime = audioTrack.baseMediaDecodeTime;
8711
9486
  if (samples) {
8712
9487
  var baseOffset = moofBox.start;
8713
9488
  samples.map(function(x) {
@@ -9181,10 +9956,16 @@
9181
9956
  if (track.useEME && track.enca) {
9182
9957
  content = MP42.enca(track);
9183
9958
  } else {
9184
- content = MP42.mp4a(track);
9959
+ if (track.codecType === AudioCodecType.OPUS) {
9960
+ content = MP42.opus(track);
9961
+ } else {
9962
+ content = MP42.mp4a(track);
9963
+ }
9185
9964
  }
9186
9965
  } else if (track.useEME && track.encv) {
9187
9966
  content = MP42.encv(track);
9967
+ } else if (track.av1C) {
9968
+ content = MP42.av01(track);
9188
9969
  } else {
9189
9970
  content = MP42.avc1hev1(track);
9190
9971
  }
@@ -9397,6 +10178,90 @@
9397
10178
  var schi = MP42.schi(data);
9398
10179
  return MP42.box(MP42.types.sinf, content, MP42.box(MP42.types.frma, frma), MP42.box(MP42.types.schm, schm), schi);
9399
10180
  }
10181
+ }, {
10182
+ key: "av01",
10183
+ value: function av01(track) {
10184
+ return MP42.box(MP42.types.av01, new Uint8Array([
10185
+ 0,
10186
+ 0,
10187
+ 0,
10188
+ 0,
10189
+ 0,
10190
+ 0,
10191
+ 0,
10192
+ 1,
10193
+ 0,
10194
+ 0,
10195
+ 0,
10196
+ 0,
10197
+ 0,
10198
+ 0,
10199
+ 0,
10200
+ 0,
10201
+ 0,
10202
+ 0,
10203
+ 0,
10204
+ 0,
10205
+ 0,
10206
+ 0,
10207
+ 0,
10208
+ 0,
10209
+ track.width >> 8 & 255,
10210
+ track.width & 255,
10211
+ track.height >> 8 & 255,
10212
+ track.height & 255,
10213
+ 0,
10214
+ 72,
10215
+ 0,
10216
+ 0,
10217
+ 0,
10218
+ 72,
10219
+ 0,
10220
+ 0,
10221
+ 0,
10222
+ 0,
10223
+ 0,
10224
+ 0,
10225
+ 0,
10226
+ 1,
10227
+ 0,
10228
+ 0,
10229
+ 0,
10230
+ 0,
10231
+ 0,
10232
+ 0,
10233
+ 0,
10234
+ 0,
10235
+ 0,
10236
+ 0,
10237
+ 0,
10238
+ 0,
10239
+ 0,
10240
+ 0,
10241
+ 0,
10242
+ 0,
10243
+ 0,
10244
+ 0,
10245
+ 0,
10246
+ 0,
10247
+ 0,
10248
+ 0,
10249
+ 0,
10250
+ 0,
10251
+ 0,
10252
+ 0,
10253
+ 0,
10254
+ 0,
10255
+ 0,
10256
+ 0,
10257
+ 0,
10258
+ 0,
10259
+ 0,
10260
+ 24,
10261
+ 17,
10262
+ 17
10263
+ ]), track.av1C, track.colr);
10264
+ }
9400
10265
  }, {
9401
10266
  key: "avc1hev1",
9402
10267
  value: function avc1hev1(track) {
@@ -9767,6 +10632,53 @@
9767
10632
  )));
9768
10633
  return esds2;
9769
10634
  }
10635
+ }, {
10636
+ key: "opus",
10637
+ value: function opus(track) {
10638
+ var opusAudioDescription = new Uint8Array([
10639
+ 0,
10640
+ 0,
10641
+ 0,
10642
+ 0,
10643
+ 0,
10644
+ 0,
10645
+ 0,
10646
+ 1,
10647
+ 0,
10648
+ 0,
10649
+ 0,
10650
+ 0,
10651
+ 0,
10652
+ 0,
10653
+ 0,
10654
+ 0,
10655
+ 0,
10656
+ track.channelCount,
10657
+ 0,
10658
+ 16,
10659
+ 0,
10660
+ 0,
10661
+ 0,
10662
+ 0,
10663
+ track.sampleRate >> 8 & 255,
10664
+ track.sampleRate & 255,
10665
+ 0,
10666
+ 0
10667
+ ]);
10668
+ var opusSpecificConfig = track.config.length ? MP42.dOps(track) : [];
10669
+ return MP42.box(MP42.types.Opus, opusAudioDescription, opusSpecificConfig);
10670
+ }
10671
+ }, {
10672
+ key: "dOps",
10673
+ value: function dOps(track) {
10674
+ if (track.config) {
10675
+ track.config[4] = track.sampleRate >>> 24 & 255;
10676
+ track.config[5] = track.sampleRate >>> 16 & 255;
10677
+ track.config[6] = track.sampleRate >>> 8 & 255;
10678
+ track.config[7] = track.sampleRate & 255;
10679
+ return MP42.box(MP42.types.dOps, track.config);
10680
+ }
10681
+ }
9770
10682
  }, {
9771
10683
  key: "mvex",
9772
10684
  value: function mvex(tracks) {
@@ -10369,7 +11281,7 @@
10369
11281
  }]);
10370
11282
  return MP42;
10371
11283
  }();
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) {
11284
+ _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
11285
  p[c] = [c.charCodeAt(0), c.charCodeAt(1), c.charCodeAt(2), c.charCodeAt(3)];
10374
11286
  return p;
10375
11287
  }, /* @__PURE__ */ Object.create(null)));
@@ -10704,30 +11616,46 @@
10704
11616
  };
10705
11617
  }
10706
11618
  var samples = track.samples;
11619
+ var isAV01 = /av01/.test(track.codec);
10707
11620
  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;
11621
+ if (isAV01) {
11622
+ samples.forEach(function(s) {
11623
+ mdatSize += s.data.byteLength;
10725
11624
  });
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);
11625
+ } else {
11626
+ samples.forEach(function(s) {
11627
+ mdatSize += s.units.reduce(function(t, c) {
11628
+ return t + c.byteLength;
11629
+ }, 0);
11630
+ mdatSize += s.units.length * 4;
11631
+ });
11632
+ }
11633
+ var mdata = new Uint8Array(mdatSize);
11634
+ if (isAV01) {
11635
+ for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
11636
+ sample = samples[i];
11637
+ mdata.set(sample.data, offset);
11638
+ sample.size = sample.data.byteLength;
11639
+ offset += sample.size;
11640
+ }
11641
+ } else {
11642
+ var mdatView = new DataView(mdata.buffer);
11643
+ var _loop = function _loop2(_offset2, _sample2) {
11644
+ _sample2 = samples[_i];
11645
+ var sampleSize = 0;
11646
+ _sample2.units.forEach(function(u) {
11647
+ mdatView.setUint32(_offset2, u.byteLength);
11648
+ _offset2 += 4;
11649
+ mdata.set(u, _offset2);
11650
+ _offset2 += u.byteLength;
11651
+ sampleSize += 4 + u.byteLength;
11652
+ });
11653
+ _sample2.size = sampleSize;
11654
+ _offset = _offset2, _sample = _sample2;
11655
+ };
11656
+ for (var _i = 0, _l = samples.length, _offset = 0, _sample; _i < _l; _i++) {
11657
+ _loop(_offset, _sample);
11658
+ }
10731
11659
  }
10732
11660
  var mdat = MP4.mdat(mdata);
10733
11661
  var moof = MP4.moof([track]);
@@ -10886,11 +11814,11 @@
10886
11814
  });
10887
11815
  var logger$3 = new Logger$2("Transmuxer");
10888
11816
  var Transmuxer = /* @__PURE__ */ function() {
10889
- function Transmuxer2(hls, isMP4, needRemux) {
11817
+ function Transmuxer2(hls, isMP4, needRemux, fixerConfig) {
10890
11818
  _classCallCheck$3(this, Transmuxer2);
10891
11819
  _defineProperty$3(this, "_initSegmentId", "");
10892
11820
  this.hls = hls;
10893
- this._demuxer = isMP4 ? new FMP4Demuxer() : new TsDemuxer();
11821
+ this._demuxer = isMP4 ? new FMP4Demuxer() : new TsDemuxer(null, null, null, fixerConfig);
10894
11822
  this._isMP4 = isMP4;
10895
11823
  if (needRemux)
10896
11824
  this._remuxer = new FMP4Remuxer(this._demuxer.videoTrack, this._demuxer.audioTrack);
@@ -10921,7 +11849,8 @@
10921
11849
  timescale: audioTrack.timescale,
10922
11850
  firstDts: audioTrack.firstDts / videoTrack.timescale,
10923
11851
  firstPts: audioTrack.firstPts / videoTrack.timescale,
10924
- duration: audioTrack.samplesDuration / videoTrack.timescale
11852
+ duration: audioTrack.samplesDuration / videoTrack.timescale,
11853
+ container: audioTrack.container
10925
11854
  };
10926
11855
  var newId = "".concat(videoTrack.codec, "/").concat(videoTrack.width, "/").concat(videoTrack.height, "/").concat(audioTrack.codec, "/").concat(audioTrack.config);
10927
11856
  if (newId !== this._initSegmentId) {
@@ -11045,7 +11974,7 @@
11045
11974
  }]);
11046
11975
  return Transmuxer2;
11047
11976
  }();
11048
- var _excluded = ["data"], _excluded2 = ["data"];
11977
+ var _excluded$1 = ["data"], _excluded2 = ["data"];
11049
11978
  var logger$2 = new Logger$2("BufferService");
11050
11979
  var BufferService = /* @__PURE__ */ function() {
11051
11980
  function BufferService2(hls) {
@@ -11157,11 +12086,11 @@
11157
12086
  return;
11158
12087
  if (TsDemuxer.probe(chunk)) {
11159
12088
  if (!this._transmuxer)
11160
- this._transmuxer = new Transmuxer(this.hls, false, !this._softVideo);
12089
+ this._transmuxer = new Transmuxer(this.hls, false, !this._softVideo, this.hls.config.fixerConfig);
11161
12090
  } else if (MP4Parser.probe(chunk)) {
11162
12091
  if (this._softVideo) {
11163
12092
  if (!this._transmuxer)
11164
- this._transmuxer = new Transmuxer(this.hls, true);
12093
+ this._transmuxer = new Transmuxer(this.hls, true, null, this.hls.config.fixerConfig);
11165
12094
  } else {
11166
12095
  this._directAppend = true;
11167
12096
  var mix = false;
@@ -11211,7 +12140,8 @@
11211
12140
  key: "appendBuffer",
11212
12141
  value: function() {
11213
12142
  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;
12143
+ var _this2 = this;
12144
+ var afterAppend, p, needInit, _this$_transmuxer$tra, _this$_transmuxer$tra2, video, audio, isFirstAppend, mse, _p, videoData, videoRest, audioData, audioRest;
11215
12145
  return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
11216
12146
  while (1)
11217
12147
  switch (_context2.prev = _context2.next) {
@@ -11222,8 +12152,18 @@
11222
12152
  }
11223
12153
  return _context2.abrupt("return");
11224
12154
  case 2:
12155
+ afterAppend = function afterAppend2() {
12156
+ var _this2$hls;
12157
+ if ((_this2$hls = _this2.hls) !== null && _this2$hls !== void 0 && _this2$hls.emit) {
12158
+ var _this2$hls2;
12159
+ (_this2$hls2 = _this2.hls) === null || _this2$hls2 === void 0 ? void 0 : _this2$hls2.emit(EVENT.APPEND_BUFFER, {
12160
+ start: segment.start,
12161
+ end: segment.end
12162
+ });
12163
+ }
12164
+ };
11225
12165
  if (!this._directAppend) {
11226
- _context2.next = 7;
12166
+ _context2.next = 8;
11227
12167
  break;
11228
12168
  }
11229
12169
  p = [];
@@ -11231,8 +12171,8 @@
11231
12171
  p.push(this._mse.append(MSE.VIDEO, videoChunk));
11232
12172
  if (audioChunk)
11233
12173
  p.push(this._mse.append(MSE.AUDIO, audioChunk));
11234
- return _context2.abrupt("return", Promise.all(p));
11235
- case 7:
12174
+ return _context2.abrupt("return", Promise.all(p).then(afterAppend));
12175
+ case 8:
11236
12176
  needInit = this._needInitSegment || discontinuity;
11237
12177
  _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
12178
  if (audioChunk && audioSegment) {
@@ -11248,21 +12188,22 @@
11248
12188
  this.hls.emit(Event$1.NO_AUDIO_TRACK);
11249
12189
  }
11250
12190
  if (!this._softVideo) {
11251
- _context2.next = 18;
12191
+ _context2.next = 20;
11252
12192
  break;
11253
12193
  }
11254
12194
  this._softVideo.appendBuffer(video, audio);
11255
12195
  this._needInitSegment = false;
11256
- _context2.next = 28;
12196
+ afterAppend();
12197
+ _context2.next = 30;
11257
12198
  break;
11258
- case 18:
12199
+ case 20:
11259
12200
  if (!this._mse) {
11260
- _context2.next = 28;
12201
+ _context2.next = 30;
11261
12202
  break;
11262
12203
  }
11263
12204
  isFirstAppend = !this._sourceCreated;
11264
12205
  if (isFirstAppend) {
11265
- this._createMseSource(video === null || video === void 0 ? void 0 : video.codec, audio === null || audio === void 0 ? void 0 : audio.codec);
12206
+ this._createMseSource(video === null || video === void 0 ? void 0 : video.codec, audio === null || audio === void 0 ? void 0 : audio.codec, audio === null || audio === void 0 ? void 0 : audio.container);
11266
12207
  }
11267
12208
  this._needInitSegment = false;
11268
12209
  mse = this._mse;
@@ -11273,15 +12214,15 @@
11273
12214
  });
11274
12215
  }
11275
12216
  if (video) {
11276
- videoData = video.data, videoRest = _objectWithoutProperties$1(video, _excluded);
12217
+ videoData = video.data, videoRest = _objectWithoutProperties$1(video, _excluded$1);
11277
12218
  _p.push(mse.append(MSE.VIDEO, videoData, videoRest));
11278
12219
  }
11279
12220
  if (audio) {
11280
12221
  audioData = audio.data, audioRest = _objectWithoutProperties$1(audio, _excluded2);
11281
12222
  _p.push(mse.append(MSE.AUDIO, audioData, audioRest));
11282
12223
  }
11283
- return _context2.abrupt("return", Promise.all(_p));
11284
- case 28:
12224
+ return _context2.abrupt("return", Promise.all(_p).then(afterAppend));
12225
+ case 30:
11285
12226
  case "end":
11286
12227
  return _context2.stop();
11287
12228
  }
@@ -11296,7 +12237,7 @@
11296
12237
  key: "removeBuffer",
11297
12238
  value: function() {
11298
12239
  var _removeBuffer = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee3() {
11299
- var _this2 = this;
12240
+ var _this3 = this;
11300
12241
  var start, end, media, _args3 = arguments;
11301
12242
  return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
11302
12243
  while (1)
@@ -11312,7 +12253,7 @@
11312
12253
  return _context3.abrupt("return");
11313
12254
  case 5:
11314
12255
  return _context3.abrupt("return", this._mse.clearBuffer(start, end).then(function() {
11315
- return _this2.hls.emit(EVENT.REMOVE_BUFFER, {
12256
+ return _this3.hls.emit(EVENT.REMOVE_BUFFER, {
11316
12257
  start,
11317
12258
  end,
11318
12259
  removeEnd: end
@@ -11493,30 +12434,51 @@
11493
12434
  return setLiveSeekableRange;
11494
12435
  }()
11495
12436
  }, {
11496
- key: "destroy",
12437
+ key: "detachMedia",
11497
12438
  value: function() {
11498
- var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee9() {
11499
- var _this$_decryptor;
12439
+ var _detachMedia = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee9() {
11500
12440
  return _regeneratorRuntime$1().wrap(function _callee9$(_context9) {
11501
12441
  while (1)
11502
12442
  switch (_context9.prev = _context9.next) {
11503
12443
  case 0:
11504
- (_this$_decryptor = this._decryptor) === null || _this$_decryptor === void 0 ? void 0 : _this$_decryptor.destroy();
11505
12444
  if (!this._mse) {
11506
- _context9.next = 4;
12445
+ _context9.next = 3;
11507
12446
  break;
11508
12447
  }
11509
- _context9.next = 4;
12448
+ _context9.next = 3;
11510
12449
  return this._mse.unbindMedia();
11511
- case 4:
12450
+ case 3:
12451
+ case "end":
12452
+ return _context9.stop();
12453
+ }
12454
+ }, _callee9, this);
12455
+ }));
12456
+ function detachMedia() {
12457
+ return _detachMedia.apply(this, arguments);
12458
+ }
12459
+ return detachMedia;
12460
+ }()
12461
+ }, {
12462
+ key: "destroy",
12463
+ value: function() {
12464
+ var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee10() {
12465
+ var _this$_decryptor;
12466
+ return _regeneratorRuntime$1().wrap(function _callee10$(_context10) {
12467
+ while (1)
12468
+ switch (_context10.prev = _context10.next) {
12469
+ case 0:
12470
+ (_this$_decryptor = this._decryptor) === null || _this$_decryptor === void 0 ? void 0 : _this$_decryptor.destroy();
12471
+ _context10.next = 3;
12472
+ return this.detachMedia();
12473
+ case 3:
11512
12474
  this._decryptor = null;
11513
12475
  this._mse = null;
11514
12476
  this._softVideo = null;
11515
- case 7:
12477
+ case 6:
11516
12478
  case "end":
11517
- return _context9.stop();
12479
+ return _context10.stop();
11518
12480
  }
11519
- }, _callee9, this);
12481
+ }, _callee10, this);
11520
12482
  }));
11521
12483
  function destroy() {
11522
12484
  return _destroy.apply(this, arguments);
@@ -11525,7 +12487,7 @@
11525
12487
  }()
11526
12488
  }, {
11527
12489
  key: "_createMseSource",
11528
- value: function _createMseSource(videoCodec, audioCodec) {
12490
+ value: function _createMseSource(videoCodec, audioCodec, container) {
11529
12491
  logger$2.debug("create mse source, videoCodec=".concat(videoCodec, ", audioCodec=").concat(audioCodec));
11530
12492
  var mse = this._mse;
11531
12493
  if (!mse)
@@ -11537,6 +12499,9 @@
11537
12499
  if (audioCodec) {
11538
12500
  mse.createSource(MSE.AUDIO, "audio/mp4;codecs=".concat(audioCodec));
11539
12501
  this._sourceCreated = true;
12502
+ } else if (container) {
12503
+ mse.createSource(MSE.AUDIO, "".concat(container, ';codecs=""'));
12504
+ this._sourceCreated = true;
11540
12505
  }
11541
12506
  this.hls.emit(EVENT.SOURCEBUFFER_CREATED);
11542
12507
  }
@@ -11604,7 +12569,11 @@
11604
12569
  minSegmentsStartPlay: 3,
11605
12570
  preferMMS: false,
11606
12571
  preferMMSStreaming: false,
11607
- mseLowLatency: true
12572
+ mseLowLatency: true,
12573
+ fixerConfig: {
12574
+ forceFixLargeGap: false,
12575
+ largeGapThreshold: 5
12576
+ }
11608
12577
  }, cfg), {}, {
11609
12578
  media
11610
12579
  });
@@ -11719,6 +12688,8 @@
11719
12688
  _defineProperty$3(this, "lowLatency", false);
11720
12689
  _defineProperty$3(this, "endPartIndex", 0);
11721
12690
  _defineProperty$3(this, "segments", []);
12691
+ _defineProperty$3(this, "dateRanges", {});
12692
+ _defineProperty$3(this, "skippedSegments", 0);
11722
12693
  });
11723
12694
  var MediaSegment = /* @__PURE__ */ function() {
11724
12695
  function MediaSegment2(parentUrl) {
@@ -11840,6 +12811,31 @@
11840
12811
  }]);
11841
12812
  return MediaSegmentKey2;
11842
12813
  }();
12814
+ var HlsUrlParameters = /* @__PURE__ */ function() {
12815
+ function HlsUrlParameters2(msn, part, skip) {
12816
+ _classCallCheck$3(this, HlsUrlParameters2);
12817
+ this.msn = msn;
12818
+ this.part = part;
12819
+ this.skip = skip;
12820
+ }
12821
+ _createClass$3(HlsUrlParameters2, [{
12822
+ key: "addDirectives",
12823
+ value: function addDirectives(uri) {
12824
+ var url = new self.URL(uri);
12825
+ if (this.msn !== void 0) {
12826
+ url.searchParams.set("_HLS_msn", this.msn.toString());
12827
+ }
12828
+ if (this.part) {
12829
+ url.searchParams.set("_HLS_part", this.part.toString());
12830
+ }
12831
+ if (this.skip) {
12832
+ url.searchParams.set("_HLS_skip", this.skip);
12833
+ }
12834
+ return url.href;
12835
+ }
12836
+ }]);
12837
+ return HlsUrlParameters2;
12838
+ }();
11843
12839
  var REGEXP_TAG = /^#(EXT[^:]*)(?::(.*))?$/;
11844
12840
  var REGEXP_ATTR = /([^=]+)=(?:"([^"]*)"|([^",]*))(?:,|$)/g;
11845
12841
  var REGEXP_ABSOLUTE_URL = /^(?:[a-zA-Z0-9+\-.]+:)?\/\//;
@@ -11890,6 +12886,38 @@
11890
12886
  }
11891
12887
  }
11892
12888
  }
12889
+ function isValidDaterange(attr, dateRangeWithSameId) {
12890
+ var _badValueForSameId;
12891
+ if (dateRangeWithSameId) {
12892
+ for (var key in dateRangeWithSameId) {
12893
+ if (Object.prototype.hasOwnProperty.call(dateRangeWithSameId, key) && attr[key] !== dateRangeWithSameId[key]) {
12894
+ _badValueForSameId = key;
12895
+ break;
12896
+ }
12897
+ }
12898
+ }
12899
+ var duration = null;
12900
+ if (attr.DURATION) {
12901
+ duration = parseFloat(attr.DURATION);
12902
+ if (!Number.isFinite(duration)) {
12903
+ duration = null;
12904
+ } else if (attr._endDate) {
12905
+ duration = (attr._endDate.getTime() - attr._startDate.getTime()) / 1e3;
12906
+ }
12907
+ }
12908
+ var cue = enumeratedStringList(attr.CUE || attr["X-CUE"], {
12909
+ pre: false,
12910
+ post: false,
12911
+ once: false
12912
+ });
12913
+ 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);
12914
+ }
12915
+ function enumeratedStringList(attrValue, dict) {
12916
+ return (attrValue ? attrValue.split(/[ ,]+/) : []).reduce(function(result, identifier) {
12917
+ result[identifier.toLowerCase()] = true;
12918
+ return result;
12919
+ }, dict);
12920
+ }
11893
12921
  function parseMasterPlaylist(lines, parentUrl) {
11894
12922
  var master = new MasterPlaylist();
11895
12923
  var index = 0;
@@ -11998,9 +13026,6 @@
11998
13026
  var endOfList = false;
11999
13027
  var partSegmentIndex = 0;
12000
13028
  while (line = lines[index++]) {
12001
- if (endOfList) {
12002
- break;
12003
- }
12004
13029
  if (line[0] !== "#") {
12005
13030
  if (media.lowLatency) {
12006
13031
  curSN++;
@@ -12049,16 +13074,11 @@
12049
13074
  media.canBlockReload = _attr["CAN-BLOCK-RELOAD"] === "YES";
12050
13075
  media.partHoldBack = parseFloat(_attr["PART-HOLD-BACK"] || 0);
12051
13076
  media.canSkipUntil = parseFloat(_attr["CAN-SKIP-UNTIL"] || 0);
12052
- media.canSkipDateRanges = _attr["CAN-SKIP-DATERANGES"] === "YES";
13077
+ media.canSkipDateRanges = media.canSkipUntil > 0 && _attr["CAN-SKIP-DATERANGES"] === "YES";
12053
13078
  }
12054
13079
  break;
12055
13080
  case "ENDLIST":
12056
13081
  {
12057
- var _lastSegment = media.segments[media.segments.length - 1];
12058
- if (_lastSegment) {
12059
- _lastSegment.isLast = true;
12060
- }
12061
- media.live = false;
12062
13082
  endOfList = true;
12063
13083
  }
12064
13084
  break;
@@ -12098,6 +13118,15 @@
12098
13118
  }
12099
13119
  break;
12100
13120
  case "PRELOAD-HINT":
13121
+ {
13122
+ var _attr3 = parseAttr(data);
13123
+ media.preloadHint = _attr3;
13124
+ if (_attr3["TYPE"] === "PART" && _attr3["URI"]) {
13125
+ var tmp = _attr3["URI"].split(".ts")[0].split("-");
13126
+ media.nextSN = tmp[3];
13127
+ media.nextIndex = tmp[tmp.length - 1];
13128
+ }
13129
+ }
12101
13130
  break;
12102
13131
  case "PROGRAM-DATE-TIME":
12103
13132
  curSegment.dataTime = data;
@@ -12117,21 +13146,21 @@
12117
13146
  break;
12118
13147
  case "KEY":
12119
13148
  {
12120
- var _attr3 = parseAttr(data);
12121
- if (_attr3.METHOD === "NONE") {
13149
+ var _attr4 = parseAttr(data);
13150
+ if (_attr4.METHOD === "NONE") {
12122
13151
  curKey = null;
12123
13152
  break;
12124
13153
  }
12125
13154
  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;
13155
+ curKey.method = _attr4.METHOD;
13156
+ curKey.url = /^blob:/.test(_attr4.URI) ? _attr4.URI : getAbsoluteUrl(_attr4.URI, parentUrl);
13157
+ curKey.keyFormat = _attr4.KEYFORMAT || "identity";
13158
+ curKey.keyFormatVersions = _attr4.KEYFORMATVERSIONS;
12130
13159
  if (!curKey.isSupported()) {
12131
- throw new Error("encrypt ".concat(_attr3.METHOD, "/").concat(_attr3.KEYFORMAT, " is not supported"));
13160
+ throw new Error("encrypt ".concat(_attr4.METHOD, "/").concat(_attr4.KEYFORMAT, " is not supported"));
12132
13161
  }
12133
- if (_attr3.IV) {
12134
- var str = _attr3.IV.slice(2);
13162
+ if (_attr4.IV) {
13163
+ var str = _attr4.IV.slice(2);
12135
13164
  str = (str.length & 1 ? "0" : "") + str;
12136
13165
  curKey.iv = new Uint8Array(str.length / 2);
12137
13166
  for (var i = 0, l = str.length / 2; i < l; i++) {
@@ -12142,10 +13171,10 @@
12142
13171
  break;
12143
13172
  case "MAP":
12144
13173
  {
12145
- var _attr4 = parseAttr(data);
12146
- curSegment.url = getAbsoluteUrl(_attr4.URI, parentUrl);
12147
- if (_attr4.BYTERANGE)
12148
- curSegment.setByteRange(_attr4.BYTERANGE);
13174
+ var _attr5 = parseAttr(data);
13175
+ curSegment.url = getAbsoluteUrl(_attr5.URI, parentUrl);
13176
+ if (_attr5.BYTERANGE)
13177
+ curSegment.setByteRange(_attr5.BYTERANGE);
12149
13178
  curSegment.isInitSegment = true;
12150
13179
  curSegment.sn = 0;
12151
13180
  if (curKey) {
@@ -12155,6 +13184,30 @@
12155
13184
  curSegment = new MediaSegment(parentUrl);
12156
13185
  }
12157
13186
  break;
13187
+ case "SKIP":
13188
+ {
13189
+ var _attr6 = parseAttr(data);
13190
+ var skippedSegments = parseInt(_attr6["SKIPPED-SEGMENTS"], 10);
13191
+ if (skippedSegments <= Number.MAX_SAFE_INTEGER) {
13192
+ media.skippedSegments += skippedSegments;
13193
+ curSN += skippedSegments;
13194
+ }
13195
+ }
13196
+ break;
13197
+ case "DATERANGE":
13198
+ {
13199
+ var _attr7 = parseAttr(data);
13200
+ var dateRangeWithSameId = media.dateRanges[_attr7.ID];
13201
+ _attr7._startDate = dateRangeWithSameId ? dateRangeWithSameId._startDate : new Date(_attr7["START-DATE"]);
13202
+ var endDate = (dateRangeWithSameId === null || dateRangeWithSameId === void 0 ? void 0 : dateRangeWithSameId._endDate) || new Date(_attr7.END_DATE);
13203
+ if (Number.isFinite(endDate)) {
13204
+ _attr7._endDate = endDate;
13205
+ }
13206
+ if (isValidDaterange(_attr7, dateRangeWithSameId) || media.skippedSegments) {
13207
+ media.dateRanges[_attr7.ID] = _attr7;
13208
+ }
13209
+ }
13210
+ break;
12158
13211
  }
12159
13212
  }
12160
13213
  media.segments = media.segments.filter(function(x) {
@@ -12162,11 +13215,14 @@
12162
13215
  });
12163
13216
  var lastSegment = media.segments[media.segments.length - 1];
12164
13217
  if (lastSegment) {
12165
- media.endSN = lastSegment.sn;
12166
- media.endPartIndex = lastSegment.partIndex;
12167
- if (endOfList && !lastSegment.isLast) {
13218
+ if (endOfList) {
12168
13219
  lastSegment.isLast = true;
12169
13220
  }
13221
+ media.endSN = lastSegment.sn;
13222
+ media.endPartIndex = lastSegment.partIndex;
13223
+ }
13224
+ if (endOfList) {
13225
+ media.live = false;
12170
13226
  }
12171
13227
  media.totalDuration = totalDuration;
12172
13228
  media.endCC = curCC;
@@ -12345,6 +13401,13 @@
12345
13401
  playlist
12346
13402
  });
12347
13403
  } else {
13404
+ if (this._useLowLatency) {
13405
+ if (playlist.canBlockReload) {
13406
+ this.deliveryDirectives = new HlsUrlParameters(playlist.nextSN, playlist.nextIndex, "");
13407
+ } else {
13408
+ this.deliveryDirectives = null;
13409
+ }
13410
+ }
12348
13411
  this.hls.emit(Event$1.HLS_LEVEL_LOADED, {
12349
13412
  playlist
12350
13413
  });
@@ -12401,41 +13464,45 @@
12401
13464
  var retryCount = this.hls.config.pollRetryCount;
12402
13465
  var fn = /* @__PURE__ */ function() {
12403
13466
  var _ref2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee2() {
12404
- var res;
13467
+ var reqUrl, res;
12405
13468
  return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
12406
13469
  while (1)
12407
13470
  switch (_context2.prev = _context2.next) {
12408
13471
  case 0:
12409
13472
  clearTimeout(_this2._timer);
12410
- _context2.prev = 1;
12411
- _context2.next = 4;
12412
- return _this2.load(url, audioUrl, subtitleUrl);
12413
- case 4:
13473
+ reqUrl = url;
13474
+ _context2.prev = 2;
13475
+ if (_this2.deliveryDirectives) {
13476
+ reqUrl = _this2.deliveryDirectives.addDirectives(url);
13477
+ }
13478
+ _context2.next = 6;
13479
+ return _this2.load(reqUrl, audioUrl, subtitleUrl);
13480
+ case 6:
12414
13481
  res = _context2.sent;
12415
13482
  if (res[0]) {
12416
- _context2.next = 7;
13483
+ _context2.next = 9;
12417
13484
  break;
12418
13485
  }
12419
13486
  return _context2.abrupt("return");
12420
- case 7:
13487
+ case 9:
12421
13488
  retryCount = _this2.hls.config.pollRetryCount;
12422
13489
  cb(res[0], res[1], res[2]);
12423
- _context2.next = 15;
13490
+ _context2.next = 17;
12424
13491
  break;
12425
- case 11:
12426
- _context2.prev = 11;
12427
- _context2.t0 = _context2["catch"](1);
13492
+ case 13:
13493
+ _context2.prev = 13;
13494
+ _context2.t0 = _context2["catch"](2);
12428
13495
  retryCount--;
12429
13496
  if (retryCount <= 0) {
12430
13497
  errorCb(_context2.t0);
12431
13498
  }
12432
- case 15:
13499
+ case 17:
12433
13500
  _this2._timer = setTimeout(fn, time);
12434
- case 16:
13501
+ case 18:
12435
13502
  case "end":
12436
13503
  return _context2.stop();
12437
13504
  }
12438
- }, _callee2, null, [[1, 11]]);
13505
+ }, _callee2, null, [[2, 13]]);
12439
13506
  }));
12440
13507
  return function fn2() {
12441
13508
  return _ref2.apply(this, arguments);
@@ -12965,7 +14032,7 @@
12965
14032
  }, {
12966
14033
  key: "clearOldSegment",
12967
14034
  value: function clearOldSegment() {
12968
- var maxPlaylistSize = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 50;
14035
+ var maxPlaylistSize = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.hls.config.maxPlaylistSize || 50;
12969
14036
  var stream = this.currentStream;
12970
14037
  if (!this.dvrWindow || !stream)
12971
14038
  return;
@@ -13263,7 +14330,7 @@
13263
14330
  _defineProperty$3(_assertThisInitialized$2(_this), "_switchUrlOpts", null);
13264
14331
  _defineProperty$3(_assertThisInitialized$2(_this), "_isProcessQuotaExceeded", false);
13265
14332
  _defineProperty$3(_assertThisInitialized$2(_this), "_loadSegment", /* @__PURE__ */ _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee() {
13266
- var nextSeg, _assertThisInitialize, config, bInfo, bufferThroughout;
14333
+ var _this$_playlist, nextSegment, lastSegment, _assertThisInitialize, config, minFrameDuration, maxBufferThroughout, bInfo, bufferThroughout;
13267
14334
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
13268
14335
  while (1)
13269
14336
  switch (_context.prev = _context.next) {
@@ -13274,42 +14341,44 @@
13274
14341
  }
13275
14342
  return _context.abrupt("return");
13276
14343
  case 2:
13277
- nextSeg = _this._playlist.nextSegment;
14344
+ _this$_playlist = _this._playlist, nextSegment = _this$_playlist.nextSegment, lastSegment = _this$_playlist.lastSegment;
13278
14345
  _assertThisInitialize = _assertThisInitialized$2(_this), config = _assertThisInitialize.config;
13279
- if (nextSeg) {
13280
- _context.next = 6;
14346
+ minFrameDuration = 0.016;
14347
+ maxBufferThroughout = Math.min(Math.max((lastSegment === null || lastSegment === void 0 ? void 0 : lastSegment.duration) - minFrameDuration / 2 || 0, minFrameDuration), 0.1);
14348
+ if (nextSegment) {
14349
+ _context.next = 8;
13281
14350
  break;
13282
14351
  }
13283
14352
  return _context.abrupt("return");
13284
- case 6:
14353
+ case 8:
13285
14354
  if (_this.isLive) {
13286
- _context.next = 16;
14355
+ _context.next = 18;
13287
14356
  break;
13288
14357
  }
13289
14358
  bInfo = _this.bufferInfo();
13290
14359
  if (_this.media.paused && !_this.media.currentTime) {
13291
14360
  bInfo = _this.bufferInfo(bInfo.nextStart || 0.5);
13292
14361
  }
13293
- bufferThroughout = Math.abs(bInfo.end - _this.media.duration) < 0.1;
14362
+ bufferThroughout = Math.abs(bInfo.end - _this.media.duration) < maxBufferThroughout;
13294
14363
  if (!(bInfo.remaining >= config.preloadTime || bufferThroughout)) {
13295
- _context.next = 13;
14364
+ _context.next = 15;
13296
14365
  break;
13297
14366
  }
13298
14367
  _this._tryEos();
13299
14368
  return _context.abrupt("return");
13300
- case 13:
14369
+ case 15:
13301
14370
  if (!(config.preferMMSStreaming && !_this._bufferService.msStreaming)) {
13302
- _context.next = 15;
14371
+ _context.next = 17;
13303
14372
  break;
13304
14373
  }
13305
14374
  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) {
14375
+ case 17:
14376
+ if (!_this._urlSwitching && _this._prevSegSn !== nextSegment.sn - 1 && bInfo.end && Math.abs(nextSegment.start - bInfo.end) > 1) {
13308
14377
  _this._playlist.setNextSegmentByIndex(_this._playlist.findSegmentIndexByTime(bInfo.end + 0.1));
13309
14378
  }
13310
- case 16:
14379
+ case 18:
13311
14380
  return _context.abrupt("return", _this._loadSegmentDirect());
13312
- case 17:
14381
+ case 19:
13313
14382
  case "end":
13314
14383
  return _context.stop();
13315
14384
  }
@@ -13474,7 +14543,6 @@
13474
14543
  return;
13475
14544
  _this._startTick();
13476
14545
  var media = _this.media;
13477
- var buffered = Buffer$1.get(media);
13478
14546
  var segLoaderError = _this._segmentLoader.error;
13479
14547
  _this._onCheckQuotaExceeded();
13480
14548
  if (_this._isProcessQuotaExceeded) {
@@ -13491,7 +14559,7 @@
13491
14559
  }
13492
14560
  return;
13493
14561
  }
13494
- if (Buffer$1.end(buffered) >= 0.1 && media.readyState) {
14562
+ if (media.readyState) {
13495
14563
  if (isMediaPlaying(media)) {
13496
14564
  _this._loadSegment();
13497
14565
  if (_this._gapService) {
@@ -13557,6 +14625,12 @@
13557
14625
  var _this$_bufferService;
13558
14626
  return (_this$_bufferService = this._bufferService) === null || _this$_bufferService === void 0 ? void 0 : _this$_bufferService.baseDts;
13559
14627
  }
14628
+ }, {
14629
+ key: "abrSwitchPoint",
14630
+ get: function get() {
14631
+ var targetSeg = this._urlSwitching ? this._playlist.currentSegment : this._playlist.nextSegment;
14632
+ return targetSeg ? targetSeg.start + targetSeg.duration / 2 : null;
14633
+ }
13560
14634
  }, {
13561
14635
  key: "speedInfo",
13562
14636
  value: function speedInfo() {
@@ -13582,30 +14656,37 @@
13582
14656
  }, {
13583
14657
  key: "load",
13584
14658
  value: function() {
13585
- var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee4(url) {
13586
- var reuseMse, _args4 = arguments;
14659
+ var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee4() {
14660
+ var url, options, reuseMse, _args4 = arguments;
13587
14661
  return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
13588
14662
  while (1)
13589
14663
  switch (_context4.prev = _context4.next) {
13590
14664
  case 0:
13591
- reuseMse = _args4.length > 1 && _args4[1] !== void 0 ? _args4[1] : false;
14665
+ url = _args4.length > 0 && _args4[0] !== void 0 ? _args4[0] : "";
14666
+ options = _args4.length > 1 && _args4[1] !== void 0 ? _args4[1] : {};
14667
+ reuseMse = typeof options === "boolean" ? options : !!(options !== null && options !== void 0 && options.reuseMse);
14668
+ if (_typeof$2(options) === "object" && options !== null && options !== void 0 && options.clearSwitchStatus) {
14669
+ this._urlSwitching = false;
14670
+ this._switchUrlOpts = null;
14671
+ this.config.startTime = void 0;
14672
+ }
13592
14673
  if (url)
13593
14674
  this.config.url = url;
13594
14675
  url = this.config.url;
13595
- _context4.next = 5;
14676
+ _context4.next = 8;
13596
14677
  return this._reset(reuseMse);
13597
- case 5:
13598
- _context4.next = 7;
14678
+ case 8:
14679
+ _context4.next = 10;
13599
14680
  return this._loadData(url);
13600
- case 7:
14681
+ case 10:
13601
14682
  this._startTick();
13602
- case 8:
14683
+ case 11:
13603
14684
  case "end":
13604
14685
  return _context4.stop();
13605
14686
  }
13606
14687
  }, _callee4, this);
13607
14688
  }));
13608
- function load(_x) {
14689
+ function load() {
13609
14690
  return _load.apply(this, arguments);
13610
14691
  }
13611
14692
  return load;
@@ -13614,7 +14695,7 @@
13614
14695
  key: "_loadData",
13615
14696
  value: function() {
13616
14697
  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;
14698
+ var manifest, currentStream, preIndex, _this$_switchUrlOpts, _this$_switchUrlOpts3, _this$_switchUrlOpts4, _this$_switchUrlOpts2, switchTimePoint, segIdx, nextSeg, bufferClearStartPoint, startTime, _this$_switchUrlOpts5;
13618
14699
  return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
13619
14700
  while (1)
13620
14701
  switch (_context5.prev = _context5.next) {
@@ -13635,41 +14716,46 @@
13635
14716
  case 5:
13636
14717
  manifest = _context5.sent;
13637
14718
  currentStream = this._playlist.currentStream;
13638
- if (!(this._urlSwitching && !this.isLive)) {
13639
- _context5.next = 17;
14719
+ if (!this._urlSwitching) {
14720
+ _context5.next = 23;
13640
14721
  break;
13641
14722
  }
14723
+ if (!this.isLive) {
14724
+ _context5.next = 14;
14725
+ break;
14726
+ }
14727
+ preIndex = this._playlist.setNextSegmentBySN(this._prevSegSn);
14728
+ logger.log("segment nb=".concat(this._prevSegSn, " index of ").concat(preIndex, " in the new playlist"));
14729
+ if (preIndex === -1) {
14730
+ this._prevSegCc = null;
14731
+ this._prevSegSn = null;
14732
+ }
14733
+ _context5.next = 23;
14734
+ break;
14735
+ case 14:
13642
14736
  if (currentStream.bitrate === 0 && (_this$_switchUrlOpts = this._switchUrlOpts) !== null && _this$_switchUrlOpts !== void 0 && _this$_switchUrlOpts.bitrate) {
13643
14737
  currentStream.bitrate = (_this$_switchUrlOpts2 = this._switchUrlOpts) === null || _this$_switchUrlOpts2 === void 0 ? void 0 : _this$_switchUrlOpts2.bitrate;
13644
14738
  }
13645
- switchTimePoint = this._getSeamlessSwitchPoint();
14739
+ 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
14740
  this.config.startTime = switchTimePoint;
13647
14741
  segIdx = this._playlist.findSegmentIndexByTime(switchTimePoint);
13648
14742
  nextSeg = this._playlist.getSegmentByIndex(segIdx + 1);
13649
14743
  if (!nextSeg) {
13650
- _context5.next = 17;
14744
+ _context5.next = 23;
13651
14745
  break;
13652
14746
  }
13653
14747
  bufferClearStartPoint = nextSeg.start;
13654
- _context5.next = 17;
14748
+ _context5.next = 23;
13655
14749
  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
- }
14750
+ case 23:
13665
14751
  if (manifest) {
13666
- _context5.next = 20;
14752
+ _context5.next = 25;
13667
14753
  break;
13668
14754
  }
13669
14755
  return _context5.abrupt("return");
13670
- case 20:
14756
+ case 25:
13671
14757
  if (!this.isLive) {
13672
- _context5.next = 31;
14758
+ _context5.next = 36;
13673
14759
  break;
13674
14760
  }
13675
14761
  this._bufferService.setLiveSeekableRange(0, 4294967295);
@@ -13682,35 +14768,35 @@
13682
14768
  if (!manifest.isMaster)
13683
14769
  this._pollM3U8(url);
13684
14770
  if (!(this._playlist.nbSegments < this.config.minSegmentsStartPlay)) {
13685
- _context5.next = 28;
14771
+ _context5.next = 33;
13686
14772
  break;
13687
14773
  }
13688
14774
  return _context5.abrupt("return");
13689
- case 28:
13690
- _context5.next = 30;
14775
+ case 33:
14776
+ _context5.next = 35;
13691
14777
  return this._loadSegment();
13692
- case 30:
14778
+ case 35:
13693
14779
  return _context5.abrupt("return");
13694
- case 31:
13695
- _context5.next = 33;
14780
+ case 36:
14781
+ _context5.next = 38;
13696
14782
  return this._bufferService.updateDuration(currentStream.totalDuration);
13697
- case 33:
14783
+ case 38:
13698
14784
  startTime = this.config.startTime;
13699
14785
  if (startTime) {
13700
- if (!((_this$_switchUrlOpts3 = this._switchUrlOpts) !== null && _this$_switchUrlOpts3 !== void 0 && _this$_switchUrlOpts3.seamless)) {
14786
+ if (!((_this$_switchUrlOpts5 = this._switchUrlOpts) !== null && _this$_switchUrlOpts5 !== void 0 && _this$_switchUrlOpts5.seamless)) {
13701
14787
  this.media.currentTime = startTime;
13702
14788
  }
13703
14789
  this._playlist.setNextSegmentByIndex(this._playlist.findSegmentIndexByTime(startTime) || 0);
13704
14790
  }
13705
- _context5.next = 37;
14791
+ _context5.next = 42;
13706
14792
  return this._loadSegment();
13707
- case 37:
14793
+ case 42:
13708
14794
  case "end":
13709
14795
  return _context5.stop();
13710
14796
  }
13711
14797
  }, _callee5, this);
13712
14798
  }));
13713
- function _loadData(_x2) {
14799
+ function _loadData(_x) {
13714
14800
  return _loadData2.apply(this, arguments);
13715
14801
  }
13716
14802
  return _loadData;
@@ -13724,18 +14810,20 @@
13724
14810
  switch (_context6.prev = _context6.next) {
13725
14811
  case 0:
13726
14812
  this.config.startTime = 0;
13727
- _context6.next = 3;
14813
+ this._urlSwitching = false;
14814
+ this._switchUrlOpts = null;
14815
+ _context6.next = 5;
13728
14816
  return this.load();
13729
- case 3:
14817
+ case 5:
13730
14818
  this._reloadOnPlay = false;
13731
14819
  return _context6.abrupt("return", this.media.play(!isPlayEmit));
13732
- case 5:
14820
+ case 7:
13733
14821
  case "end":
13734
14822
  return _context6.stop();
13735
14823
  }
13736
14824
  }, _callee6, this);
13737
14825
  }));
13738
- function replay(_x3) {
14826
+ function replay(_x2) {
13739
14827
  return _replay.apply(this, arguments);
13740
14828
  }
13741
14829
  return replay;
@@ -13840,7 +14928,7 @@
13840
14928
  }
13841
14929
  }, _callee7, this, [[18, 29]]);
13842
14930
  }));
13843
- function switchURL(_x4) {
14931
+ function switchURL(_x3) {
13844
14932
  return _switchURL.apply(this, arguments);
13845
14933
  }
13846
14934
  return switchURL;
@@ -13926,7 +15014,7 @@
13926
15014
  }
13927
15015
  }, _callee8, this, [[8, 16], [21, 31]]);
13928
15016
  }));
13929
- function switchStream(_x5) {
15017
+ function switchStream(_x4) {
13930
15018
  return _switchStream.apply(this, arguments);
13931
15019
  }
13932
15020
  return switchStream;
@@ -14012,7 +15100,7 @@
14012
15100
  }
14013
15101
  }, _callee9, this, [[10, 18], [22, 32]]);
14014
15102
  }));
14015
- function switchAudioStream(_x6) {
15103
+ function switchAudioStream(_x5) {
14016
15104
  return _switchAudioStream.apply(this, arguments);
14017
15105
  }
14018
15106
  return switchAudioStream;
@@ -14037,25 +15125,50 @@
14037
15125
  }
14038
15126
  }, _callee10, this);
14039
15127
  }));
14040
- function switchSubtitleStream(_x7) {
15128
+ function switchSubtitleStream(_x6) {
14041
15129
  return _switchSubtitleStream.apply(this, arguments);
14042
15130
  }
14043
15131
  return switchSubtitleStream;
14044
15132
  }()
14045
15133
  }, {
14046
- key: "destroy",
15134
+ key: "detachMedia",
14047
15135
  value: function() {
14048
- var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee11() {
14049
- var _this$_seiService2;
15136
+ var _detachMedia = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee11() {
14050
15137
  return _regeneratorRuntime$1().wrap(function _callee11$(_context11) {
14051
15138
  while (1)
14052
15139
  switch (_context11.prev = _context11.next) {
15140
+ case 0:
15141
+ if (!this._bufferService) {
15142
+ _context11.next = 3;
15143
+ break;
15144
+ }
15145
+ _context11.next = 3;
15146
+ return this._bufferService.detachMedia();
15147
+ case 3:
15148
+ case "end":
15149
+ return _context11.stop();
15150
+ }
15151
+ }, _callee11, this);
15152
+ }));
15153
+ function detachMedia() {
15154
+ return _detachMedia.apply(this, arguments);
15155
+ }
15156
+ return detachMedia;
15157
+ }()
15158
+ }, {
15159
+ key: "destroy",
15160
+ value: function() {
15161
+ var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee12() {
15162
+ var _this$_seiService2;
15163
+ return _regeneratorRuntime$1().wrap(function _callee12$(_context12) {
15164
+ while (1)
15165
+ switch (_context12.prev = _context12.next) {
14053
15166
  case 0:
14054
15167
  if (this.media) {
14055
- _context11.next = 2;
15168
+ _context12.next = 2;
14056
15169
  break;
14057
15170
  }
14058
- return _context11.abrupt("return");
15171
+ return _context12.abrupt("return");
14059
15172
  case 2:
14060
15173
  this.removeAllListeners();
14061
15174
  this._playlist.reset();
@@ -14066,15 +15179,15 @@
14066
15179
  this.media.removeEventListener("pause", this._onPause);
14067
15180
  this.media.removeEventListener("seeking", this._onSeeking);
14068
15181
  this.media.removeEventListener("timeupdate", this._onTimeupdate);
14069
- _context11.next = 13;
15182
+ _context12.next = 13;
14070
15183
  return Promise.all([this._clear(), this._bufferService.destroy()]);
14071
15184
  case 13:
14072
15185
  this.media = null;
14073
15186
  case 14:
14074
15187
  case "end":
14075
- return _context11.stop();
15188
+ return _context12.stop();
14076
15189
  }
14077
- }, _callee11, this);
15190
+ }, _callee12, this);
14078
15191
  }));
14079
15192
  function destroy() {
14080
15193
  return _destroy.apply(this, arguments);
@@ -14084,48 +15197,48 @@
14084
15197
  }, {
14085
15198
  key: "_loadM3U8",
14086
15199
  value: function() {
14087
- var _loadM3U = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee12(url) {
15200
+ var _loadM3U = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee13(url) {
14088
15201
  var playlist, _this$config$manifest, _this$config$manifest2, manifest, _ref4, _ref5, _this$_playlist$curre;
14089
- return _regeneratorRuntime$1().wrap(function _callee12$(_context12) {
15202
+ return _regeneratorRuntime$1().wrap(function _callee13$(_context13) {
14090
15203
  while (1)
14091
- switch (_context12.prev = _context12.next) {
15204
+ switch (_context13.prev = _context13.next) {
14092
15205
  case 0:
14093
- _context12.prev = 0;
15206
+ _context13.prev = 0;
14094
15207
  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
15208
  return x.url === url;
14096
15209
  })[0]) === null || _this$config$manifest2 === void 0 ? void 0 : _this$config$manifest2.manifest;
14097
15210
  if (!manifest) {
14098
- _context12.next = 6;
15211
+ _context13.next = 6;
14099
15212
  break;
14100
15213
  }
14101
- _context12.t0 = this._manifestLoader.parseText(manifest, url);
14102
- _context12.next = 9;
15214
+ _context13.t0 = this._manifestLoader.parseText(manifest, url);
15215
+ _context13.next = 9;
14103
15216
  break;
14104
15217
  case 6:
14105
- _context12.next = 8;
15218
+ _context13.next = 8;
14106
15219
  return this._manifestLoader.load(url);
14107
15220
  case 8:
14108
- _context12.t0 = _context12.sent;
15221
+ _context13.t0 = _context13.sent;
14109
15222
  case 9:
14110
- _ref4 = _context12.t0;
15223
+ _ref4 = _context13.t0;
14111
15224
  _ref5 = _slicedToArray$1(_ref4, 1);
14112
15225
  playlist = _ref5[0];
14113
- _context12.next = 17;
15226
+ _context13.next = 17;
14114
15227
  break;
14115
15228
  case 14:
14116
- _context12.prev = 14;
14117
- _context12.t1 = _context12["catch"](0);
14118
- throw this._emitError(StreamingError.create(_context12.t1));
15229
+ _context13.prev = 14;
15230
+ _context13.t1 = _context13["catch"](0);
15231
+ throw this._emitError(StreamingError.create(_context13.t1));
14119
15232
  case 17:
14120
15233
  if (playlist) {
14121
- _context12.next = 19;
15234
+ _context13.next = 19;
14122
15235
  break;
14123
15236
  }
14124
- return _context12.abrupt("return");
15237
+ return _context13.abrupt("return");
14125
15238
  case 19:
14126
15239
  this._playlist.upsertPlaylist(playlist);
14127
15240
  if (!playlist.isMaster) {
14128
- _context12.next = 24;
15241
+ _context13.next = 24;
14129
15242
  break;
14130
15243
  }
14131
15244
  if ((_this$_playlist$curre = this._playlist.currentStream.subtitleStreams) !== null && _this$_playlist$curre !== void 0 && _this$_playlist$curre.length) {
@@ -14133,18 +15246,18 @@
14133
15246
  list: this._playlist.currentStream.subtitleStreams
14134
15247
  });
14135
15248
  }
14136
- _context12.next = 24;
15249
+ _context13.next = 24;
14137
15250
  return this._refreshM3U8();
14138
15251
  case 24:
14139
15252
  this.emit(Event$1.STREAM_PARSED);
14140
- return _context12.abrupt("return", playlist);
15253
+ return _context13.abrupt("return", playlist);
14141
15254
  case 26:
14142
15255
  case "end":
14143
- return _context12.stop();
15256
+ return _context13.stop();
14144
15257
  }
14145
- }, _callee12, this, [[0, 14]]);
15258
+ }, _callee13, this, [[0, 14]]);
14146
15259
  }));
14147
- function _loadM3U8(_x8) {
15260
+ function _loadM3U8(_x7) {
14148
15261
  return _loadM3U.apply(this, arguments);
14149
15262
  }
14150
15263
  return _loadM3U8;
@@ -14178,7 +15291,7 @@
14178
15291
  var isEmpty = this._playlist.isEmpty;
14179
15292
  var pollInterval;
14180
15293
  if (this._playlist.lowLatency) {
14181
- pollInterval = (this._playlist.currentStream.partTargetDuration * 2 || 0) * 1e3;
15294
+ pollInterval = (this._playlist.currentStream.partTargetDuration || 0) * 1e3;
14182
15295
  } else {
14183
15296
  var _this$_playlist$lastS;
14184
15297
  pollInterval = (((_this$_playlist$lastS = this._playlist.lastSegment) === null || _this$_playlist$lastS === void 0 ? void 0 : _this$_playlist$lastS.duration) || 0) * 1e3;
@@ -14206,53 +15319,53 @@
14206
15319
  }, {
14207
15320
  key: "_loadSegmentDirect",
14208
15321
  value: function() {
14209
- var _loadSegmentDirect2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee13(loadOnce) {
15322
+ var _loadSegmentDirect2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee14(loadOnce) {
14210
15323
  var seg, appended, cachedError, _this$_playlist$curre2, bufferEnd, sameStream;
14211
- return _regeneratorRuntime$1().wrap(function _callee13$(_context13) {
15324
+ return _regeneratorRuntime$1().wrap(function _callee14$(_context14) {
14212
15325
  while (1)
14213
- switch (_context13.prev = _context13.next) {
15326
+ switch (_context14.prev = _context14.next) {
14214
15327
  case 0:
14215
15328
  seg = this._playlist.nextSegment;
14216
15329
  if (seg) {
14217
- _context13.next = 3;
15330
+ _context14.next = 3;
14218
15331
  break;
14219
15332
  }
14220
- return _context13.abrupt("return");
15333
+ return _context14.abrupt("return");
14221
15334
  case 3:
14222
15335
  appended = false;
14223
15336
  cachedError = null;
14224
- _context13.prev = 5;
15337
+ _context14.prev = 5;
14225
15338
  this._segmentProcessing = true;
14226
15339
  logger.log("load segment, sn:".concat(seg.sn, ", [").concat(seg.start, ", ").concat(seg.end, "], partIndex:").concat(seg.partIndex));
14227
- _context13.next = 10;
15340
+ _context14.next = 10;
14228
15341
  return this._reqAndBufferSegment(seg, this._playlist.getAudioSegment(seg));
14229
15342
  case 10:
14230
- appended = _context13.sent;
14231
- _context13.next = 16;
15343
+ appended = _context14.sent;
15344
+ _context14.next = 16;
14232
15345
  break;
14233
15346
  case 13:
14234
- _context13.prev = 13;
14235
- _context13.t0 = _context13["catch"](5);
14236
- cachedError = _context13.t0;
15347
+ _context14.prev = 13;
15348
+ _context14.t0 = _context14["catch"](5);
15349
+ cachedError = _context14.t0;
14237
15350
  case 16:
14238
- _context13.prev = 16;
15351
+ _context14.prev = 16;
14239
15352
  this._segmentProcessing = false;
14240
- return _context13.finish(16);
15353
+ return _context14.finish(16);
14241
15354
  case 19:
14242
15355
  if (!cachedError) {
14243
- _context13.next = 26;
15356
+ _context14.next = 26;
14244
15357
  break;
14245
15358
  }
14246
15359
  if (!this._bufferService.isFull()) {
14247
- _context13.next = 25;
15360
+ _context14.next = 25;
14248
15361
  break;
14249
15362
  }
14250
15363
  logger.log("load segment, sn:".concat(seg.sn, ", partIndex:").concat(seg.partIndex));
14251
15364
  this._segmentProcessing = true;
14252
15365
  this._isProcessQuotaExceeded = true;
14253
- return _context13.abrupt("return", false);
15366
+ return _context14.abrupt("return", false);
14254
15367
  case 25:
14255
- return _context13.abrupt("return", this._emitError(StreamingError.create(cachedError)));
15368
+ return _context14.abrupt("return", this._emitError(StreamingError.create(cachedError)));
14256
15369
  case 26:
14257
15370
  if (appended) {
14258
15371
  bufferEnd = this.bufferInfo().end;
@@ -14278,14 +15391,14 @@
14278
15391
  this._loadSegment();
14279
15392
  }
14280
15393
  }
14281
- return _context13.abrupt("return", appended);
15394
+ return _context14.abrupt("return", appended);
14282
15395
  case 28:
14283
15396
  case "end":
14284
- return _context13.stop();
15397
+ return _context14.stop();
14285
15398
  }
14286
- }, _callee13, this, [[5, 13, 16, 19]]);
15399
+ }, _callee14, this, [[5, 13, 16, 19]]);
14287
15400
  }));
14288
- function _loadSegmentDirect(_x9) {
15401
+ function _loadSegmentDirect(_x8) {
14289
15402
  return _loadSegmentDirect2.apply(this, arguments);
14290
15403
  }
14291
15404
  return _loadSegmentDirect;
@@ -14293,45 +15406,45 @@
14293
15406
  }, {
14294
15407
  key: "_reqAndBufferSegment",
14295
15408
  value: function() {
14296
- var _reqAndBufferSegment2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee14(seg, audioSeg) {
15409
+ var _reqAndBufferSegment2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee15(seg, audioSeg) {
14297
15410
  var _this$_bufferService2;
14298
15411
  var cc, discontinuity, responses, data, sn, start, stream, before, contiguous, segStart;
14299
- return _regeneratorRuntime$1().wrap(function _callee14$(_context14) {
15412
+ return _regeneratorRuntime$1().wrap(function _callee15$(_context15) {
14300
15413
  while (1)
14301
- switch (_context14.prev = _context14.next) {
15414
+ switch (_context15.prev = _context15.next) {
14302
15415
  case 0:
14303
15416
  cc = seg ? seg.cc : audioSeg.cc;
14304
15417
  discontinuity = this._prevSegCc !== cc;
14305
15418
  responses = [];
14306
- _context14.prev = 3;
14307
- _context14.next = 6;
15419
+ _context15.prev = 3;
15420
+ _context15.next = 6;
14308
15421
  return this._segmentLoader.load(seg, audioSeg, discontinuity);
14309
15422
  case 6:
14310
- responses = _context14.sent;
14311
- _context14.next = 14;
15423
+ responses = _context15.sent;
15424
+ _context15.next = 14;
14312
15425
  break;
14313
15426
  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;
15427
+ _context15.prev = 9;
15428
+ _context15.t0 = _context15["catch"](3);
15429
+ _context15.t0.fatal = false;
15430
+ this._segmentLoader.error = _context15.t0;
15431
+ throw _context15.t0;
14319
15432
  case 14:
14320
15433
  if (responses[0]) {
14321
- _context14.next = 16;
15434
+ _context15.next = 16;
14322
15435
  break;
14323
15436
  }
14324
- return _context14.abrupt("return");
15437
+ return _context15.abrupt("return");
14325
15438
  case 16:
14326
- _context14.next = 18;
15439
+ _context15.next = 18;
14327
15440
  return (_this$_bufferService2 = this._bufferService).decryptBuffer.apply(_this$_bufferService2, _toConsumableArray$2(responses));
14328
15441
  case 18:
14329
- data = _context14.sent;
15442
+ data = _context15.sent;
14330
15443
  if (data) {
14331
- _context14.next = 21;
15444
+ _context15.next = 21;
14332
15445
  break;
14333
15446
  }
14334
- return _context14.abrupt("return");
15447
+ return _context15.abrupt("return");
14335
15448
  case 21:
14336
15449
  sn = seg ? seg.sn : audioSeg.sn;
14337
15450
  start = seg ? seg.start : audioSeg.start;
@@ -14345,26 +15458,26 @@
14345
15458
  logger.warn("update the new playlist liveEdge, segment id=".concat(sn, ", buffer start=").concat(segStart, ", liveEdge=").concat(this._playlist.liveEdge));
14346
15459
  start = segStart;
14347
15460
  }
14348
- _context14.next = 30;
15461
+ _context15.next = 30;
14349
15462
  return this._bufferService.appendBuffer(seg, audioSeg, data[0], data[1], discontinuity, contiguous, start);
14350
15463
  case 30:
14351
15464
  this.emit(Event$1.APPEND_COST, {
14352
15465
  elapsed: Date.now() - before,
14353
15466
  url: seg.url
14354
15467
  });
14355
- _context14.next = 33;
15468
+ _context15.next = 33;
14356
15469
  return this._bufferService.evictBuffer(this.config.bufferBehind);
14357
15470
  case 33:
14358
15471
  this._prevSegCc = cc;
14359
15472
  this._prevSegSn = sn;
14360
- return _context14.abrupt("return", true);
15473
+ return _context15.abrupt("return", true);
14361
15474
  case 36:
14362
15475
  case "end":
14363
- return _context14.stop();
15476
+ return _context15.stop();
14364
15477
  }
14365
- }, _callee14, this, [[3, 9]]);
15478
+ }, _callee15, this, [[3, 9]]);
14366
15479
  }));
14367
- function _reqAndBufferSegment(_x10, _x11) {
15480
+ function _reqAndBufferSegment(_x9, _x10) {
14368
15481
  return _reqAndBufferSegment2.apply(this, arguments);
14369
15482
  }
14370
15483
  return _reqAndBufferSegment;
@@ -14372,11 +15485,11 @@
14372
15485
  }, {
14373
15486
  key: "_onCheckQuotaExceeded",
14374
15487
  value: function() {
14375
- var _onCheckQuotaExceeded2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee15() {
15488
+ var _onCheckQuotaExceeded2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee16() {
14376
15489
  var seekTime, buffered, inBuffered, i, bufferBehind, mediaTime;
14377
- return _regeneratorRuntime$1().wrap(function _callee15$(_context15) {
15490
+ return _regeneratorRuntime$1().wrap(function _callee16$(_context16) {
14378
15491
  while (1)
14379
- switch (_context15.prev = _context15.next) {
15492
+ switch (_context16.prev = _context16.next) {
14380
15493
  case 0:
14381
15494
  seekTime = this.media.currentTime;
14382
15495
  buffered = this.media.buffered;
@@ -14384,37 +15497,37 @@
14384
15497
  i = 0;
14385
15498
  case 4:
14386
15499
  if (!(i < buffered.length)) {
14387
- _context15.next = 11;
15500
+ _context16.next = 11;
14388
15501
  break;
14389
15502
  }
14390
15503
  if (!(buffered.start(0) >= seekTime && seekTime < buffered.end(i))) {
14391
- _context15.next = 8;
15504
+ _context16.next = 8;
14392
15505
  break;
14393
15506
  }
14394
15507
  inBuffered = true;
14395
- return _context15.abrupt("break", 11);
15508
+ return _context16.abrupt("break", 11);
14396
15509
  case 8:
14397
15510
  i++;
14398
- _context15.next = 4;
15511
+ _context16.next = 4;
14399
15512
  break;
14400
15513
  case 11:
14401
15514
  if (!this._bufferService.isFull()) {
14402
- _context15.next = 17;
15515
+ _context16.next = 17;
14403
15516
  break;
14404
15517
  }
14405
15518
  bufferBehind = inBuffered ? this.config.bufferBehind : 5;
14406
15519
  mediaTime = this.media.currentTime;
14407
15520
  if (!(mediaTime - bufferBehind > 0)) {
14408
- _context15.next = 17;
15521
+ _context16.next = 17;
14409
15522
  break;
14410
15523
  }
14411
- _context15.next = 17;
15524
+ _context16.next = 17;
14412
15525
  return this._bufferService.removeBuffer(0, mediaTime - bufferBehind);
14413
15526
  case 17:
14414
15527
  case "end":
14415
- return _context15.stop();
15528
+ return _context16.stop();
14416
15529
  }
14417
- }, _callee15, this);
15530
+ }, _callee16, this);
14418
15531
  }));
14419
15532
  function _onCheckQuotaExceeded() {
14420
15533
  return _onCheckQuotaExceeded2.apply(this, arguments);
@@ -14432,22 +15545,22 @@
14432
15545
  }, {
14433
15546
  key: "_clear",
14434
15547
  value: function() {
14435
- var _clear2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee16() {
14436
- return _regeneratorRuntime$1().wrap(function _callee16$(_context16) {
15548
+ var _clear2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee17() {
15549
+ return _regeneratorRuntime$1().wrap(function _callee17$(_context17) {
14437
15550
  while (1)
14438
- switch (_context16.prev = _context16.next) {
15551
+ switch (_context17.prev = _context17.next) {
14439
15552
  case 0:
14440
15553
  clearTimeout(this._disconnectTimer);
14441
15554
  this._stopTick();
14442
- _context16.next = 4;
15555
+ _context17.next = 4;
14443
15556
  return Promise.all([this._segmentLoader.cancel(), this._manifestLoader.stopPoll()]);
14444
15557
  case 4:
14445
15558
  this._segmentProcessing = false;
14446
15559
  case 5:
14447
15560
  case "end":
14448
- return _context16.stop();
15561
+ return _context17.stop();
14449
15562
  }
14450
- }, _callee16, this);
15563
+ }, _callee17, this);
14451
15564
  }));
14452
15565
  function _clear() {
14453
15566
  return _clear2.apply(this, arguments);
@@ -14457,14 +15570,14 @@
14457
15570
  }, {
14458
15571
  key: "_reset",
14459
15572
  value: function() {
14460
- var _reset2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee17() {
15573
+ var _reset2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee18() {
14461
15574
  var _this$_seiService3;
14462
- var reuseMse, _args17 = arguments;
14463
- return _regeneratorRuntime$1().wrap(function _callee17$(_context17) {
15575
+ var reuseMse, _args18 = arguments;
15576
+ return _regeneratorRuntime$1().wrap(function _callee18$(_context18) {
14464
15577
  while (1)
14465
- switch (_context17.prev = _context17.next) {
15578
+ switch (_context18.prev = _context18.next) {
14466
15579
  case 0:
14467
- reuseMse = _args17.length > 0 && _args17[0] !== void 0 ? _args17[0] : false;
15580
+ reuseMse = _args18.length > 0 && _args18[0] !== void 0 ? _args18[0] : false;
14468
15581
  this._reloadOnPlay = false;
14469
15582
  this._prevSegSn = null;
14470
15583
  this._prevSegCc = null;
@@ -14473,15 +15586,15 @@
14473
15586
  this._segmentLoader.reset();
14474
15587
  (_this$_seiService3 = this._seiService) === null || _this$_seiService3 === void 0 ? void 0 : _this$_seiService3.reset();
14475
15588
  this._stats.reset();
14476
- _context17.next = 11;
15589
+ _context18.next = 11;
14477
15590
  return this._clear();
14478
15591
  case 11:
14479
- return _context17.abrupt("return", this._bufferService.reset(reuseMse));
15592
+ return _context18.abrupt("return", this._bufferService.reset(reuseMse));
14480
15593
  case 12:
14481
15594
  case "end":
14482
- return _context17.stop();
15595
+ return _context18.stop();
14483
15596
  }
14484
- }, _callee17, this);
15597
+ }, _callee18, this);
14485
15598
  }));
14486
15599
  function _reset() {
14487
15600
  return _reset2.apply(this, arguments);
@@ -14562,8 +15675,8 @@
14562
15675
  value: function _tryEos() {
14563
15676
  var _this$_bufferService3, _this$_bufferService4;
14564
15677
  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);
15678
+ var _this$_playlist2 = this._playlist, nextSegment = _this$_playlist2.nextSegment, lastSegment = _this$_playlist2.lastSegment;
15679
+ 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
15680
  if (!eosAllowed) {
14568
15681
  return;
14569
15682
  }
@@ -14599,7 +15712,7 @@
14599
15712
  }]);
14600
15713
  return Hls2;
14601
15714
  }(EventEmitter);
14602
- _defineProperty$3(Hls, "version", "3.0.19-rc.0");
15715
+ _defineProperty$3(Hls, "version", "3.0.21-rc.2");
14603
15716
  try {
14604
15717
  if (localStorage.getItem("xgd")) {
14605
15718
  Hls.enableLogger();
@@ -14690,6 +15803,7 @@
14690
15803
  }]);
14691
15804
  return PluginExtension2;
14692
15805
  }();
15806
+ var _excluded = ["currentTime"];
14693
15807
  function parseSwitchUrlArgs(args, plugin) {
14694
15808
  var player = plugin.player;
14695
15809
  var curTime = player.currentTime;
@@ -14700,9 +15814,14 @@
14700
15814
  case "boolean":
14701
15815
  options.seamless = args;
14702
15816
  break;
14703
- case "object":
14704
- Object.assign(options, args);
15817
+ case "object": {
15818
+ var currentTime = args.currentTime, rest = _objectWithoutProperties$1(args, _excluded);
15819
+ Object.assign(options, rest);
15820
+ if (typeof currentTime === "number") {
15821
+ options.startTime = currentTime;
15822
+ }
14705
15823
  break;
15824
+ }
14706
15825
  }
14707
15826
  return options;
14708
15827
  }
@@ -14712,10 +15831,11 @@
14712
15831
  function HlsPlugin2() {
14713
15832
  var _this;
14714
15833
  _classCallCheck$3(this, HlsPlugin2);
14715
- for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
14716
- _args[_key] = arguments[_key];
15834
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
15835
+ args[_key] = arguments[_key];
14717
15836
  }
14718
- _this = _super.call.apply(_super, [this].concat(_args));
15837
+ _this = _super.call.apply(_super, [this].concat(args));
15838
+ _defineProperty$3(_assertThisInitialized$2(_this), "logger", logger);
14719
15839
  _defineProperty$3(_assertThisInitialized$2(_this), "hls", null);
14720
15840
  _defineProperty$3(_assertThisInitialized$2(_this), "pluginExtension", null);
14721
15841
  _defineProperty$3(_assertThisInitialized$2(_this), "getStats", function() {
@@ -14727,24 +15847,6 @@
14727
15847
  var lang = _ref.lang;
14728
15848
  (_this$hls2 = _this.hls) === null || _this$hls2 === void 0 ? void 0 : _this$hls2.switchSubtitleStream(lang);
14729
15849
  });
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
15850
  _defineProperty$3(_assertThisInitialized$2(_this), "_keepPauseStatus", function() {
14749
15851
  var paused = _this.player.paused;
14750
15852
  if (!paused)
@@ -14769,8 +15871,8 @@
14769
15871
  }, {
14770
15872
  key: "softDecode",
14771
15873
  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;
15874
+ var _this$player, _this$player$config;
15875
+ 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
15876
  return !!mediaType && mediaType !== "video" && mediaType !== "audio";
14775
15877
  }
14776
15878
  }, {
@@ -14778,13 +15880,35 @@
14778
15880
  value: function beforePlayerInit() {
14779
15881
  var _this2 = this;
14780
15882
  var config = this.player.config;
15883
+ var mediaElem = this.player.media || this.player.video;
14781
15884
  var hlsOpts = config.hls || {};
14782
15885
  if (!config.url && !config.__allowHlsEmptyUrl__ || !hlsOpts.preferMMS && MSE.isMMSOnly()) {
14783
15886
  return;
14784
15887
  }
14785
15888
  if (this.hls)
14786
15889
  this.hls.destroy();
14787
- this.player.switchURL = this._onSwitchURL;
15890
+ var descriptor = Object.getOwnPropertyDescriptor(this.player, "switchURL");
15891
+ if (!descriptor || descriptor.writable) {
15892
+ this.player.switchURL = function(url, args) {
15893
+ return new Promise(function(resolve, reject) {
15894
+ var player = _this2.player, hls = _this2.hls;
15895
+ if (hls) {
15896
+ var _this2$player$config, _this2$player$config$;
15897
+ var options = parseSwitchUrlArgs(args, _this2);
15898
+ player.config.url = url;
15899
+ hls.switchURL(url, options).then(function() {
15900
+ return resolve(true);
15901
+ }).catch(reject);
15902
+ 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) {
15903
+ _this2._keepPauseStatus();
15904
+ }
15905
+ } else {
15906
+ reject();
15907
+ }
15908
+ });
15909
+ };
15910
+ }
15911
+ var onSwitchUrl = this.player.switchURL;
14788
15912
  this.player.handleSource = false;
14789
15913
  hlsOpts.innerDegrade = hlsOpts.innerDegrade || config.innerDegrade;
14790
15914
  if (hlsOpts.disconnectTime === null || hlsOpts.disconnectTime === void 0)
@@ -14792,7 +15916,7 @@
14792
15916
  this.hls = new Hls(_objectSpread2$2({
14793
15917
  softDecode: this.softDecode,
14794
15918
  isLive: config.isLive,
14795
- media: this.player.media || this.player.video,
15919
+ media: mediaElem,
14796
15920
  startTime: config.startTime,
14797
15921
  url: config.url
14798
15922
  }, hlsOpts));
@@ -14810,7 +15934,7 @@
14810
15934
  if (this.softDecode) {
14811
15935
  this.pluginExtension = new PluginExtension(_objectSpread2$2({
14812
15936
  isLive: config.isLive,
14813
- media: this.player.video
15937
+ media: mediaElem
14814
15938
  }, hlsOpts), this);
14815
15939
  this.player.forceDegradeToVideo = function() {
14816
15940
  var _this2$pluginExtensio;
@@ -14827,8 +15951,8 @@
14827
15951
  return (_this2$hls2 = _this2.hls) === null || _this2$hls2 === void 0 ? void 0 : _this2$hls2.replay();
14828
15952
  });
14829
15953
  }
15954
+ this.on(URL_CHANGE, onSwitchUrl);
14830
15955
  this.on(SWITCH_SUBTITLE, this._onSwitchSubtitle);
14831
- this.on(URL_CHANGE, this._onSwitchURL);
14832
15956
  this.on(DESTROY, this.destroy.bind(this));
14833
15957
  this._transError();
14834
15958
  this._transCoreEvent(EVENT.TTFB);
@@ -14838,6 +15962,7 @@
14838
15962
  this._transCoreEvent(EVENT.LOAD_RETRY);
14839
15963
  this._transCoreEvent(EVENT.SOURCEBUFFER_CREATED);
14840
15964
  this._transCoreEvent(EVENT.MEDIASOURCE_OPENED);
15965
+ this._transCoreEvent(EVENT.APPEND_BUFFER);
14841
15966
  this._transCoreEvent(EVENT.REMOVE_BUFFER);
14842
15967
  this._transCoreEvent(EVENT.BUFFEREOS);
14843
15968
  this._transCoreEvent(EVENT.KEYFRAME);
@@ -14857,7 +15982,9 @@
14857
15982
  this._transCoreEvent(Event$1.SUBTITLE_PLAYLIST);
14858
15983
  this._transCoreEvent(Event$1.APPEND_COST);
14859
15984
  if (config.url) {
14860
- this.hls.load(config.url, true).catch(function(e) {
15985
+ this.hls.load(config.url, {
15986
+ reuseMse: true
15987
+ }).catch(function(e) {
14861
15988
  });
14862
15989
  }
14863
15990
  }