@volcengine/veplayer-plugin 2.4.5-rc.0 → 2.6.0-rc.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 (43) hide show
  1. package/esm/index.d.ts +1 -0
  2. package/esm/index.development.css +11 -0
  3. package/esm/index.development.js +45800 -32626
  4. package/esm/index.production.css +1 -1
  5. package/esm/index.production.js +13 -4
  6. package/esm/veplayer.plugin.abr.development.js +71 -3
  7. package/esm/veplayer.plugin.abr.production.js +1 -1
  8. package/esm/veplayer.plugin.ad.development.css +11 -0
  9. package/esm/veplayer.plugin.ad.development.js +13194 -0
  10. package/esm/veplayer.plugin.ad.production.css +1 -0
  11. package/esm/veplayer.plugin.ad.production.js +4 -0
  12. package/esm/veplayer.plugin.drm.development.js +71 -3
  13. package/esm/veplayer.plugin.drm.production.js +1 -1
  14. package/esm/veplayer.plugin.flv.development.js +729 -196
  15. package/esm/veplayer.plugin.flv.production.js +1 -1
  16. package/esm/veplayer.plugin.hls.development.js +1509 -376
  17. package/esm/veplayer.plugin.hls.production.js +1 -1
  18. package/esm/veplayer.plugin.mp4.development.js +73 -5
  19. package/esm/veplayer.plugin.mp4.production.js +1 -1
  20. package/esm/veplayer.plugin.rtm.development.js +72 -4
  21. package/esm/veplayer.plugin.rtm.production.js +1 -1
  22. package/esm/veplayer.plugin.shaka.development.js +72 -4
  23. package/esm/veplayer.plugin.shaka.production.js +1 -1
  24. package/package.json +1 -1
  25. package/umd/index.d.ts +1 -0
  26. package/umd/veplayer.plugin.abr.development.js +71 -3
  27. package/umd/veplayer.plugin.abr.production.js +1 -1
  28. package/umd/veplayer.plugin.ad.development.css +11 -0
  29. package/umd/veplayer.plugin.ad.development.js +13197 -0
  30. package/umd/veplayer.plugin.ad.production.css +1 -0
  31. package/umd/veplayer.plugin.ad.production.js +1 -0
  32. package/umd/veplayer.plugin.drm.development.js +71 -3
  33. package/umd/veplayer.plugin.drm.production.js +1 -1
  34. package/umd/veplayer.plugin.flv.development.js +729 -196
  35. package/umd/veplayer.plugin.flv.production.js +1 -1
  36. package/umd/veplayer.plugin.hls.development.js +1476 -343
  37. package/umd/veplayer.plugin.hls.production.js +1 -1
  38. package/umd/veplayer.plugin.mp4.development.js +73 -5
  39. package/umd/veplayer.plugin.mp4.production.js +1 -1
  40. package/umd/veplayer.plugin.rtm.development.js +72 -4
  41. package/umd/veplayer.plugin.rtm.production.js +1 -1
  42. package/umd/veplayer.plugin.shaka.development.js +72 -4
  43. 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.3";
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,123 @@
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
+ if (isFirefox) {
7382
+ track.codec = "mp3";
7383
+ } else {
7384
+ track.container = "audio/mpeg";
7385
+ }
7386
+ track.samples.push(sample);
7387
+ return {
7388
+ length: header.frameLength
7389
+ };
7390
+ }
7391
+ }
7392
+ }, {
7393
+ key: "parseHeader",
7394
+ value: function parseHeader(data, offset) {
7395
+ var mpegVersion = data[offset + 1] >> 3 & 3;
7396
+ var mpegLayer = data[offset + 1] >> 1 & 3;
7397
+ var bitRateIndex = data[offset + 2] >> 4 & 15;
7398
+ var sampleRateIndex = data[offset + 2] >> 2 & 3;
7399
+ if (mpegVersion !== 1 && bitRateIndex !== 0 && bitRateIndex !== 15 && sampleRateIndex !== 3) {
7400
+ var paddingBit = data[offset + 2] >> 1 & 1;
7401
+ var channelMode = data[offset + 3] >> 6;
7402
+ var columnInBitrates = mpegVersion === 3 ? 3 - mpegLayer : mpegLayer === 3 ? 3 : 4;
7403
+ var bitRate = BitratesMap[columnInBitrates * 14 + bitRateIndex - 1] * 1e3;
7404
+ var columnInSampleRates = mpegVersion === 3 ? 0 : mpegVersion === 2 ? 1 : 2;
7405
+ var sampleRate = FREQ[columnInSampleRates * 3 + sampleRateIndex];
7406
+ var channelCount = channelMode === 3 ? 1 : 2;
7407
+ var sampleCoefficient = SamplesCoefficients[mpegVersion][mpegLayer];
7408
+ var bytesInSlot = BytesInSlot[mpegLayer];
7409
+ var samplesPerFrame = sampleCoefficient * 8 * bytesInSlot;
7410
+ var frameLength = Math.floor(sampleCoefficient * bitRate / sampleRate + paddingBit) * bytesInSlot;
7411
+ if (chromeVersion === null) {
7412
+ var userAgent = navigator.userAgent || "";
7413
+ var result = userAgent.match(/Chrome\/(\d+)/i);
7414
+ chromeVersion = result ? parseInt(result[1]) : 0;
7415
+ }
7416
+ var needChromeFix = !!chromeVersion && chromeVersion <= 87;
7417
+ if (needChromeFix && mpegLayer === 2 && bitRate >= 224e3 && channelMode === 0) {
7418
+ data[offset + 3] = data[offset + 3] | 128;
7419
+ }
7420
+ return {
7421
+ sampleRate,
7422
+ channelCount,
7423
+ frameLength,
7424
+ samplesPerFrame
7425
+ };
7426
+ }
7427
+ }
7428
+ }]);
7429
+ return MPEG2;
7430
+ }();
7139
7431
  var logger$4 = new Logger$1("TsDemuxer");
7140
7432
  var TsDemuxer = /* @__PURE__ */ function() {
7141
7433
  function TsDemuxer2(videoTrack, audioTrack, metadataTrack) {
7434
+ var fixerConfig = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
7142
7435
  _classCallCheck(this, TsDemuxer2);
7143
7436
  _defineProperty(this, "_pmtId", -1);
7144
7437
  _defineProperty(this, "_remainingPacketData", null);
@@ -7148,7 +7441,7 @@
7148
7441
  this.videoTrack = videoTrack || new VideoTrack();
7149
7442
  this.audioTrack = audioTrack || new AudioTrack();
7150
7443
  this.metadataTrack = metadataTrack || new MetadataTrack();
7151
- this._fixer = new TsFixer(this.videoTrack, this.audioTrack, this.metadataTrack);
7444
+ this._fixer = new TsFixer(this.videoTrack, this.audioTrack, this.metadataTrack, fixerConfig);
7152
7445
  }
7153
7446
  _createClass(TsDemuxer2, [{
7154
7447
  key: "demux",
@@ -7218,6 +7511,13 @@
7218
7511
  case 15:
7219
7512
  audioTrack.pid = audioPid = esPid;
7220
7513
  break;
7514
+ case 3:
7515
+ case 4:
7516
+ if (audioTrack.pid === -1) {
7517
+ audioTrack.pid = audioPid = esPid;
7518
+ audioTrack.codecType = AudioCodecType.MP3;
7519
+ }
7520
+ break;
7221
7521
  case 27:
7222
7522
  if (videoPid !== -1)
7223
7523
  break;
@@ -7417,7 +7717,14 @@
7417
7717
  logger$4.warn("Cannot parse audio pes", this._audioPesData);
7418
7718
  return;
7419
7719
  }
7420
- this._parseAacData(pes);
7720
+ switch (this.audioTrack.codecType) {
7721
+ case AudioCodecType.AAC:
7722
+ this._parseAacData(pes);
7723
+ break;
7724
+ case AudioCodecType.MP3:
7725
+ this._parseMPEG(pes);
7726
+ break;
7727
+ }
7421
7728
  this._audioPesData = [];
7422
7729
  }
7423
7730
  }, {
@@ -7454,6 +7761,32 @@
7454
7761
  logger$4.warn("Cannot parse aac adts", pes);
7455
7762
  }
7456
7763
  }
7764
+ }, {
7765
+ key: "_parseMPEG",
7766
+ value: function _parseMPEG(pes) {
7767
+ var data = pes.data;
7768
+ var length = data.length;
7769
+ var frameIndex = 0;
7770
+ var offset = 0;
7771
+ var pts = pes.pts;
7772
+ if (pts === void 0) {
7773
+ logger$4.warn("[tsdemuxer]: MPEG PES unknown PTS");
7774
+ return;
7775
+ }
7776
+ while (offset < length) {
7777
+ if (MPEG.isHeader(data, offset)) {
7778
+ var frame = MPEG.appendFrame(this.audioTrack, data, offset, pts, frameIndex);
7779
+ if (frame) {
7780
+ offset += frame.length;
7781
+ frameIndex++;
7782
+ } else {
7783
+ break;
7784
+ }
7785
+ } else {
7786
+ offset++;
7787
+ }
7788
+ }
7789
+ }
7457
7790
  }], [{
7458
7791
  key: "probe",
7459
7792
  value: function probe(data) {
@@ -7495,6 +7828,207 @@
7495
7828
  }]);
7496
7829
  return TsDemuxer2;
7497
7830
  }();
7831
+ var ByteReader = /* @__PURE__ */ function() {
7832
+ function ByteReader2(buf, offset, len) {
7833
+ _classCallCheck(this, ByteReader2);
7834
+ this.dv = new DataView(buf);
7835
+ this.start = this.offset = offset || this.dv.byteOffset;
7836
+ this.end = len ? this.start + len : this.start + this.dv.byteLength;
7837
+ }
7838
+ _createClass(ByteReader2, [{
7839
+ key: "buffer",
7840
+ get: function get() {
7841
+ return this.dv.buffer;
7842
+ }
7843
+ }, {
7844
+ key: "unreadLength",
7845
+ get: function get() {
7846
+ return Math.max(this.end - this.offset, 0);
7847
+ }
7848
+ }, {
7849
+ key: "size",
7850
+ get: function get() {
7851
+ return this.end - this.start;
7852
+ }
7853
+ }, {
7854
+ key: "readFloat",
7855
+ value: function readFloat(byteNum) {
7856
+ var val = 0;
7857
+ switch (byteNum) {
7858
+ case 4:
7859
+ val = this.dv.getFloat32(this.offset);
7860
+ break;
7861
+ case 8:
7862
+ val = this.dv.getFloat64(this.offset);
7863
+ break;
7864
+ default:
7865
+ throw new Error("read ".concat(byteNum, "-byte float is not supported"));
7866
+ }
7867
+ this.offset += byteNum;
7868
+ return val;
7869
+ }
7870
+ }, {
7871
+ key: "back",
7872
+ value: function back(byteNum) {
7873
+ this.offset -= byteNum;
7874
+ }
7875
+ }, {
7876
+ key: "skip",
7877
+ value: function skip(byteNum) {
7878
+ this.offset += byteNum;
7879
+ }
7880
+ }, {
7881
+ key: "readInt",
7882
+ value: function readInt(byteNum) {
7883
+ var offset = this.offset;
7884
+ this.offset += byteNum;
7885
+ switch (byteNum) {
7886
+ case 1:
7887
+ return this.dv.getInt8(offset);
7888
+ case 2:
7889
+ return this.dv.getInt16(offset);
7890
+ case 4:
7891
+ return this.dv.getInt32(offset);
7892
+ default:
7893
+ throw new Error("read ".concat(byteNum, "-byte integers is not supported"));
7894
+ }
7895
+ }
7896
+ }, {
7897
+ key: "read",
7898
+ value: function read(byteNum) {
7899
+ var offset = this.offset;
7900
+ this.offset += byteNum;
7901
+ switch (byteNum) {
7902
+ case 1:
7903
+ return this.dv.getUint8(offset);
7904
+ case 2:
7905
+ return this.dv.getUint16(offset);
7906
+ case 3:
7907
+ return (this.dv.getUint16(offset) << 8) + this.dv.getUint8(offset + 2);
7908
+ case 4:
7909
+ return this.dv.getUint32(offset);
7910
+ default:
7911
+ this.back(byteNum - 4);
7912
+ return this.read(byteNum - 4) + this.dv.getUint32(offset) * Math.pow(256, byteNum - 4);
7913
+ }
7914
+ }
7915
+ }, {
7916
+ key: "write",
7917
+ value: function write(byteNum, val) {
7918
+ var offset = this.offset;
7919
+ this.offset += byteNum;
7920
+ switch (byteNum) {
7921
+ case 1:
7922
+ return this.dv.setUint8(offset, val);
7923
+ case 2:
7924
+ return this.dv.setUint16(offset, val);
7925
+ case 3:
7926
+ return this.dv.setUint8(offset, val >>> 16), this.dv.setUint16(offset + 1, 65535 & val);
7927
+ case 4:
7928
+ return this.dv.setUint32(offset, val);
7929
+ default:
7930
+ throw new Error("write ".concat(byteNum, "-byte integers is not supported"));
7931
+ }
7932
+ }
7933
+ }, {
7934
+ key: "readToBuffer",
7935
+ value: function readToBuffer(len) {
7936
+ var buffer;
7937
+ if (this.offset || len) {
7938
+ buffer = this.dv.buffer.slice(this.offset, len ? this.offset + len : this.end);
7939
+ } else {
7940
+ buffer = this.dv.buffer;
7941
+ }
7942
+ this.offset += buffer.byteLength;
7943
+ return buffer;
7944
+ }
7945
+ }, {
7946
+ key: "readToUint8",
7947
+ value: function readToUint8(len) {
7948
+ var uint8 = new Uint8Array(this.dv.buffer, this.offset, len || this.unreadLength);
7949
+ this.offset += uint8.byteLength;
7950
+ return uint8;
7951
+ }
7952
+ }, {
7953
+ key: "readString",
7954
+ value: function readString(len) {
7955
+ var i = 0, str = "";
7956
+ for (; i < len; i++) {
7957
+ str += String.fromCharCode(this.dv.getUint8(this.offset));
7958
+ this.offset++;
7959
+ }
7960
+ return str;
7961
+ }
7962
+ }], [{
7963
+ key: "fromUint8",
7964
+ value: function fromUint8(uint8) {
7965
+ return new ByteReader2(uint8.buffer, uint8.byteOffset, uint8.byteLength);
7966
+ }
7967
+ }, {
7968
+ key: "concatUint8s",
7969
+ value: function concatUint8s(args) {
7970
+ var uint8 = new Uint8Array(args.reduce(function(ret, v) {
7971
+ return ret + v.byteLength;
7972
+ }, 0));
7973
+ var offset = 0;
7974
+ args.forEach(function(v) {
7975
+ uint8.set(v, offset);
7976
+ offset += v.byteLength;
7977
+ });
7978
+ return uint8;
7979
+ }
7980
+ }, {
7981
+ key: "concatUint8",
7982
+ value: function concatUint8() {
7983
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
7984
+ args[_key] = arguments[_key];
7985
+ }
7986
+ return this.concatUint8s(args);
7987
+ }
7988
+ }]);
7989
+ return ByteReader2;
7990
+ }();
7991
+ var BitReader = /* @__PURE__ */ function() {
7992
+ function BitReader2(val, size) {
7993
+ _classCallCheck(this, BitReader2);
7994
+ this.offset = 0;
7995
+ this.val = val;
7996
+ this.size = size;
7997
+ }
7998
+ _createClass(BitReader2, [{
7999
+ key: "skip",
8000
+ value: function skip(len) {
8001
+ this.offset += len;
8002
+ }
8003
+ }, {
8004
+ key: "read",
8005
+ value: function read(len) {
8006
+ var unreadLength = this.size - this.offset - len;
8007
+ if (unreadLength >= 0) {
8008
+ var bits = 0, i = 0;
8009
+ this.offset += len;
8010
+ if (this.size > 31) {
8011
+ for (; i < len; i++) {
8012
+ bits += Math.pow(2, i);
8013
+ }
8014
+ return this.val / Math.pow(2, unreadLength) & bits;
8015
+ } else {
8016
+ for (; i < len; i++) {
8017
+ bits += 1 << i;
8018
+ }
8019
+ return this.val >>> unreadLength & bits;
8020
+ }
8021
+ }
8022
+ throw new Error("the number of the read operation exceeds the total length limit of bits");
8023
+ }
8024
+ }], [{
8025
+ key: "fromByte",
8026
+ value: function fromByte(byte, len) {
8027
+ return new BitReader2(byte.read(len), len << 3);
8028
+ }
8029
+ }]);
8030
+ return BitReader2;
8031
+ }();
7498
8032
  var MP4Parser = /* @__PURE__ */ function() {
7499
8033
  function MP4Parser2() {
7500
8034
  _classCallCheck(this, MP4Parser2);
@@ -7652,18 +8186,36 @@
7652
8186
  key: "tkhd",
7653
8187
  value: function tkhd(box) {
7654
8188
  return parseBox(box, true, function(ret, data) {
7655
- var start = 0;
8189
+ var byte = ByteReader.fromUint8(data);
7656
8190
  if (ret.version === 1) {
7657
- ret.trackId = readBig32(data, 16);
7658
- ret.duration = readBig64(data, 24);
7659
- start += 32;
8191
+ byte.read(8);
8192
+ byte.read(8);
8193
+ ret.trackId = byte.read(4);
8194
+ byte.read(4);
8195
+ ret.duration = byte.read(8);
7660
8196
  } else {
7661
- ret.trackId = readBig32(data, 8);
7662
- ret.duration = readBig32(data, 16);
7663
- start += 20;
8197
+ byte.read(4);
8198
+ byte.read(4);
8199
+ ret.trackId = byte.read(4);
8200
+ byte.read(4);
8201
+ ret.duration = byte.read(4);
7664
8202
  }
7665
- ret.width = readBig32(data, start + 52);
7666
- ret.height = readBig32(data, start + 56);
8203
+ byte.skip(16);
8204
+ ret.matrix = [];
8205
+ for (var i = 0; i < 36; i++) {
8206
+ ret.matrix.push(byte.read(1));
8207
+ }
8208
+ byte.back(36);
8209
+ var caculatedMatrix = [];
8210
+ for (var _i = 0, int32; _i < 3; _i++) {
8211
+ caculatedMatrix.push(combineToFloat(byte.readInt(2), byte.readInt(2)));
8212
+ caculatedMatrix.push(combineToFloat(byte.readInt(2), byte.readInt(2)));
8213
+ int32 = byte.readInt(4);
8214
+ caculatedMatrix.push(combineToFloat(int32 >> 30, int32 & 1073741823));
8215
+ }
8216
+ ret.rotation = toDegree(caculatedMatrix);
8217
+ ret.width = byte.read(4);
8218
+ ret.height = byte.read(4);
7667
8219
  });
7668
8220
  }
7669
8221
  }, {
@@ -7793,7 +8345,7 @@
7793
8345
  if (ret.version > 0) {
7794
8346
  var numKeyIds = readBig32(data, start);
7795
8347
  start += 4;
7796
- for (var _i = 0; _i < ("" + numKeyIds).length; _i++) {
8348
+ for (var _i2 = 0; _i2 < ("" + numKeyIds).length; _i2++) {
7797
8349
  for (var j = 0; j < 16; j++) {
7798
8350
  var keyId = data[start];
7799
8351
  start += 1;
@@ -7816,6 +8368,8 @@
7816
8368
  ret.entryCount = readBig32(data);
7817
8369
  ret.entries = MP4Parser2.findBox(data.subarray(4), [], start + 4).map(function(b) {
7818
8370
  switch (b.type) {
8371
+ case "av01":
8372
+ return MP4Parser2.av01(b);
7819
8373
  case "avc1":
7820
8374
  case "avc2":
7821
8375
  case "avc3":
@@ -7895,6 +8449,69 @@
7895
8449
  }
7896
8450
  });
7897
8451
  }
8452
+ }, {
8453
+ key: "colr",
8454
+ value: function colr(box) {
8455
+ return parseBox(box, false, function(ret, data) {
8456
+ var byte = ByteReader.fromUint8(data);
8457
+ ret.data = box.data;
8458
+ ret.colorType = byte.readString(4);
8459
+ if (ret.colorType === "nclx") {
8460
+ ret.colorPrimaries = byte.read(2);
8461
+ ret.transferCharacteristics = byte.read(2);
8462
+ ret.matrixCoefficients = byte.read(2);
8463
+ ret.fullRangeFlag = byte.read(1) >> 7;
8464
+ } else if (ret.colorType === "rICC" || ret.colorType === "prof") {
8465
+ ret.iccProfile = data.readToUint8();
8466
+ }
8467
+ });
8468
+ }
8469
+ }, {
8470
+ key: "av01",
8471
+ value: function av01(box) {
8472
+ return parseBox(box, false, function(ret, data, start) {
8473
+ var bodyStart = parseVisualSampleEntry(ret, data);
8474
+ var bodyData = data.subarray(bodyStart);
8475
+ start += bodyStart;
8476
+ ret.av1C = MP4Parser2.av1C(MP4Parser2.findBox(bodyData, ["av1C"], start)[0]);
8477
+ ret.colr = MP4Parser2.colr(MP4Parser2.findBox(bodyData, ["colr"], start)[0]);
8478
+ });
8479
+ }
8480
+ }, {
8481
+ key: "av1C",
8482
+ value: function av1C(box) {
8483
+ return parseBox(box, false, function(ret, data) {
8484
+ ret.data = box.data;
8485
+ var byte = ByteReader.fromUint8(data);
8486
+ var bit = BitReader.fromByte(byte, 4);
8487
+ ret.marker = bit.read(1);
8488
+ ret.version = bit.read(7);
8489
+ ret.seqProfile = bit.read(3);
8490
+ ret.seqLevelIdx0 = bit.read(5);
8491
+ ret.seqTier0 = bit.read(1);
8492
+ ret.highBitdepth = bit.read(1);
8493
+ ret.twelveBit = bit.read(1);
8494
+ ret.monochrome = bit.read(1);
8495
+ ret.chromaSubsamplingX = bit.read(1);
8496
+ ret.chromaSubsamplingY = bit.read(1);
8497
+ ret.chromaSamplePosition = bit.read(2);
8498
+ ret.reserved = bit.read(3);
8499
+ ret.initialPresentationDelayPresent = bit.read(1);
8500
+ if (ret.initialPresentationDelayPresent) {
8501
+ ret.initialPresentationDelayMinusOne = bit.read(4);
8502
+ } else {
8503
+ ret.initialPresentationDelayMinusOne = 0;
8504
+ }
8505
+ ret.configOBUs = byte.readToUint8();
8506
+ var bitdepth;
8507
+ if (ret.seqLevelIdx0 === 2 && ret.highBitdepth === 1) {
8508
+ bitdepth = ret.twelveBit === 1 ? "12" : "10";
8509
+ } else if (ret.seqProfile <= 2) {
8510
+ bitdepth = ret.highBitdepth === 1 ? "10" : "08";
8511
+ }
8512
+ ret.codec = ["av01", ret.seqProfile, (ret.seqLevelIdx0 < 10 ? "0" + ret.seqLevelIdx0 : ret.seqLevelIdx0) + (ret.seqTier0 ? "H" : "M"), bitdepth].join(".");
8513
+ });
8514
+ }
7898
8515
  }, {
7899
8516
  key: "avc1",
7900
8517
  value: function avc1(box) {
@@ -7929,7 +8546,7 @@
7929
8546
  ret.ppsLength = data[start];
7930
8547
  start += 1;
7931
8548
  ret.pps = [];
7932
- for (var _i2 = 0; _i2 < ret.ppsLength; _i2++) {
8549
+ for (var _i3 = 0; _i3 < ret.ppsLength; _i3++) {
7933
8550
  var _size = readBig16(data, start);
7934
8551
  start += 2;
7935
8552
  ret.pps.push(data.subarray(start, start += _size));
@@ -8098,7 +8715,7 @@
8098
8715
  start += 8;
8099
8716
  }
8100
8717
  } else {
8101
- for (var _i3 = 0; _i3 < entryCount; _i3++) {
8718
+ for (var _i4 = 0; _i4 < entryCount; _i4++) {
8102
8719
  entries.push({
8103
8720
  count: readBig32(data, start),
8104
8721
  offset: -(~readBig32(data, start + 4) + 1)
@@ -8320,13 +8937,20 @@
8320
8937
  v.mvhdTimecale = moov.mvhd.timescale;
8321
8938
  v.timescale = v.formatTimescale = vTrack.mdia.mdhd.timescale;
8322
8939
  v.duration = vTrack.mdia.mdhd.duration || v.mvhdDurtion / v.mvhdTimecale * v.timescale;
8940
+ v.rotation = vTrack.tkhd.rotation;
8941
+ v.matrix = vTrack.tkhd.matrix;
8323
8942
  var e1 = vTrack.mdia.minf.stbl.stsd.entries[0];
8324
8943
  v.width = e1.width;
8325
8944
  v.height = e1.height;
8326
8945
  if (e1.pasp) {
8327
8946
  v.sarRatio = [e1.pasp.hSpacing, e1.pasp.vSpacing];
8328
8947
  }
8329
- if (e1.hvcC) {
8948
+ if (e1.av1C) {
8949
+ v.codecType = VideoCodecType.AV1;
8950
+ v.codec = e1.av1C.codec;
8951
+ v.av1C = e1.av1C.data;
8952
+ v.colr = e1.colr.data;
8953
+ } else if (e1.hvcC) {
8330
8954
  v.codecType = VideoCodecType.HEVC;
8331
8955
  v.codec = e1.hvcC.codec;
8332
8956
  v.vps = e1.hvcC.vps;
@@ -8645,8 +9269,9 @@
8645
9269
  function parseBox(box, isFullBox, parse2) {
8646
9270
  if (!box)
8647
9271
  return;
8648
- if (box.size !== box.data.length)
9272
+ if (box.size !== box.data.length) {
8649
9273
  throw new Error("box ".concat(box.type, " size !== data.length"));
9274
+ }
8650
9275
  var ret = {
8651
9276
  start: box.start,
8652
9277
  size: box.size,
@@ -8685,27 +9310,183 @@
8685
9310
  var FMP4Demuxer = /* @__PURE__ */ function() {
8686
9311
  function FMP4Demuxer2(videoTrack, audioTrack, metadataTrack) {
8687
9312
  _classCallCheck(this, FMP4Demuxer2);
9313
+ _defineProperty(this, "__loadedMoofWraps", []);
9314
+ _defineProperty(this, "__lastRemainData", null);
9315
+ _defineProperty(this, "__lastRemainDataStart", 0);
9316
+ _defineProperty(this, "__nextMoofStart", -1);
8688
9317
  this.videoTrack = videoTrack || new VideoTrack();
8689
9318
  this.audioTrack = audioTrack || new AudioTrack();
8690
9319
  this.metadataTrack = metadataTrack || new MetadataTrack();
8691
9320
  }
8692
9321
  _createClass(FMP4Demuxer2, [{
8693
- key: "demux",
8694
- value: function demux(videoData, audioData) {
9322
+ key: "demuxPart",
9323
+ value: function demuxPart(partData, partDataStart, moov) {
9324
+ var _this = this;
8695
9325
  var videoTrack = this.videoTrack, audioTrack = this.audioTrack;
8696
9326
  var videoExist = videoTrack.exist();
8697
9327
  var audioExist = audioTrack.exist();
9328
+ var isAV01 = /av01/.test(videoTrack.codec);
8698
9329
  videoTrack.samples = [];
8699
9330
  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);
9331
+ var data = partData;
9332
+ var dataStart = partDataStart;
9333
+ if (this.__lastRemainData) {
9334
+ var lastRemainDataEnd = this.__lastRemainDataStart + this.__lastRemainData.byteLength;
9335
+ var continuous = partDataStart <= lastRemainDataEnd && partDataStart > this.__lastRemainDataStart && partDataStart + partData.byteLength > lastRemainDataEnd;
9336
+ if (continuous) {
9337
+ var noDuplicateData = partData.subarray(this.__lastRemainData.byteLength + this.__lastRemainDataStart - partDataStart);
9338
+ data = concatUint8Array(this.__lastRemainData, noDuplicateData);
9339
+ dataStart = this.__lastRemainDataStart;
9340
+ this.__lastRemainData = null;
9341
+ } else {
9342
+ this.__lastRemainData = null;
9343
+ this.__lastRemainDataStart = 0;
9344
+ this.__nextMoofStart = -1;
8706
9345
  }
8707
- var moofBox = MP4Parser.findBox(audioData, ["moof"])[0];
8708
- if (moofBox) {
9346
+ }
9347
+ if (!moov) {
9348
+ var moovBox = MP4Parser.findBox(data, ["moov"])[0];
9349
+ if (!moovBox)
9350
+ throw new Error("cannot found moov box");
9351
+ moov = MP4Parser.moov(moovBox);
9352
+ }
9353
+ if (data) {
9354
+ var dataEnd = dataStart + data.byteLength;
9355
+ if (!videoExist && !audioExist) {
9356
+ MP4Parser.moovToTrack(moov, videoTrack, audioTrack);
9357
+ }
9358
+ var moofBoxes = [];
9359
+ if (this.__nextMoofStart < 0) {
9360
+ MP4Parser.findBox(data, ["moof"], dataStart).forEach(function(v) {
9361
+ return moofBoxes.push(v);
9362
+ });
9363
+ } else if (this.__nextMoofStart >= dataStart && this.__nextMoofStart <= dataEnd - 8) {
9364
+ MP4Parser.findBox(data.subarray(this.__nextMoofStart - dataStart), ["moof"], this.__nextMoofStart).forEach(function(v) {
9365
+ return moofBoxes.push(v);
9366
+ });
9367
+ }
9368
+ moofBoxes.filter(function(moofBox) {
9369
+ return moofBox.size <= moofBox.data.length;
9370
+ }).forEach(function(moofBox) {
9371
+ var moof = MP4Parser.moof(moofBox);
9372
+ _this.__nextMoofStart = moof.start + Math.max.apply(Math, _toConsumableArray(moof.traf.map(function(v) {
9373
+ return v.trun.samples.reduce(function(ret, w) {
9374
+ return ret + w.size;
9375
+ }, v.trun.dataOffset || 0);
9376
+ })));
9377
+ _this.__loadedMoofWraps.push({
9378
+ start: moof.start,
9379
+ nextMoofStart: _this.__nextMoofStart,
9380
+ moof
9381
+ });
9382
+ _this.__loadedMoofWraps.sort(function(p, n) {
9383
+ return p.start - n.start;
9384
+ });
9385
+ });
9386
+ var _iterator = _createForOfIteratorHelper(this.__loadedMoofWraps), _step;
9387
+ try {
9388
+ var _loop = function _loop2() {
9389
+ var moofWrap = _step.value;
9390
+ if (moofWrap.start > dataEnd || moofWrap.nextMoofStart < dataStart) {
9391
+ return "continue";
9392
+ }
9393
+ var moofStart = moofWrap.start;
9394
+ var tracks = MP4Parser.moofToSamples(moofWrap.moof, videoTrack, audioTrack);
9395
+ var videoBaseMediaDecodeTime = videoTrack.baseMediaDecodeTime;
9396
+ var audioBaseMediaDecodeTime = audioTrack.baseMediaDecodeTime;
9397
+ var nalSize;
9398
+ Object.keys(tracks).forEach(function(k) {
9399
+ if (videoTrack.id == k) {
9400
+ tracks[k].some(function(x) {
9401
+ var xStart = x.offset += moofStart;
9402
+ if (xStart < dataStart) {
9403
+ return;
9404
+ }
9405
+ if (xStart + x.size > dataEnd) {
9406
+ return true;
9407
+ }
9408
+ var sample = new VideoSample((x.pts || x.dts) + videoBaseMediaDecodeTime, x.dts + videoBaseMediaDecodeTime);
9409
+ sample.duration = x.duration;
9410
+ sample.gopId = x.gopId;
9411
+ if (x.keyframe)
9412
+ sample.setToKeyframe();
9413
+ var sampleData = data.subarray(xStart - dataStart, xStart - dataStart + x.size);
9414
+ sample.data = sampleData;
9415
+ if (!isAV01) {
9416
+ var start = 0;
9417
+ var len = sampleData.length - 1;
9418
+ while (start < len) {
9419
+ nalSize = readBig32(sampleData, start);
9420
+ start += 4;
9421
+ sample.units.push(sampleData.subarray(start, start + nalSize));
9422
+ start += nalSize;
9423
+ }
9424
+ }
9425
+ _this.__lastRemainDataStart = xStart + x.size;
9426
+ videoTrack.samples.push(sample);
9427
+ });
9428
+ } else if (audioTrack.id == k) {
9429
+ tracks[k].some(function(x) {
9430
+ var xStart = x.offset + moofStart;
9431
+ if (xStart < dataStart) {
9432
+ return;
9433
+ }
9434
+ if (xStart + x.size > dataEnd) {
9435
+ return true;
9436
+ }
9437
+ var sampleData = data.subarray(xStart - dataStart, xStart - dataStart + x.size);
9438
+ audioTrack.samples.push(new AudioSample(x.dts + audioBaseMediaDecodeTime, sampleData, x.duration));
9439
+ _this.__lastRemainDataStart = xStart + x.size;
9440
+ });
9441
+ }
9442
+ });
9443
+ };
9444
+ for (_iterator.s(); !(_step = _iterator.n()).done; ) {
9445
+ var _ret = _loop();
9446
+ if (_ret === "continue")
9447
+ continue;
9448
+ }
9449
+ } catch (err) {
9450
+ _iterator.e(err);
9451
+ } finally {
9452
+ _iterator.f();
9453
+ }
9454
+ }
9455
+ if (this.__lastRemainDataStart > dataStart && this.__lastRemainDataStart < data.byteLength + dataStart) {
9456
+ this.__lastRemainData = data.subarray(this.__lastRemainDataStart - dataStart);
9457
+ } else {
9458
+ this.__lastRemainData = data;
9459
+ this.__lastRemainDataStart = dataStart;
9460
+ }
9461
+ if (videoTrack.samples.length) {
9462
+ videoTrack.baseMediaDecodeTime = videoTrack.samples[0].pts;
9463
+ }
9464
+ if (audioTrack.samples.length) {
9465
+ audioTrack.baseMediaDecodeTime = audioTrack.samples[0].pts;
9466
+ }
9467
+ return {
9468
+ videoTrack,
9469
+ audioTrack,
9470
+ metadataTrack: this.metadataTrack
9471
+ };
9472
+ }
9473
+ }, {
9474
+ key: "demux",
9475
+ value: function demux(videoData, audioData) {
9476
+ var videoTrack = this.videoTrack, audioTrack = this.audioTrack;
9477
+ var videoExist = videoTrack.exist();
9478
+ var audioExist = audioTrack.exist();
9479
+ videoTrack.samples = [];
9480
+ audioTrack.samples = [];
9481
+ if (audioData) {
9482
+ if (!audioExist) {
9483
+ var moovBox = MP4Parser.findBox(audioData, ["moov"])[0];
9484
+ if (!moovBox)
9485
+ throw new Error("cannot found moov box");
9486
+ MP4Parser.moovToTrack(MP4Parser.moov(moovBox), null, audioTrack);
9487
+ }
9488
+ var moofBox = MP4Parser.findBox(audioData, ["moof"])[0];
9489
+ if (moofBox) {
8709
9490
  var samples = MP4Parser.moofToSamples(MP4Parser.moof(moofBox), null, audioTrack)[audioTrack.id];
8710
9491
  var baseMediaDecodeTime = audioTrack.baseMediaDecodeTime;
8711
9492
  if (samples) {
@@ -9181,10 +9962,16 @@
9181
9962
  if (track.useEME && track.enca) {
9182
9963
  content = MP42.enca(track);
9183
9964
  } else {
9184
- content = MP42.mp4a(track);
9965
+ if (track.codecType === AudioCodecType.OPUS) {
9966
+ content = MP42.opus(track);
9967
+ } else {
9968
+ content = MP42.mp4a(track);
9969
+ }
9185
9970
  }
9186
9971
  } else if (track.useEME && track.encv) {
9187
9972
  content = MP42.encv(track);
9973
+ } else if (track.av1C) {
9974
+ content = MP42.av01(track);
9188
9975
  } else {
9189
9976
  content = MP42.avc1hev1(track);
9190
9977
  }
@@ -9397,6 +10184,90 @@
9397
10184
  var schi = MP42.schi(data);
9398
10185
  return MP42.box(MP42.types.sinf, content, MP42.box(MP42.types.frma, frma), MP42.box(MP42.types.schm, schm), schi);
9399
10186
  }
10187
+ }, {
10188
+ key: "av01",
10189
+ value: function av01(track) {
10190
+ return MP42.box(MP42.types.av01, new Uint8Array([
10191
+ 0,
10192
+ 0,
10193
+ 0,
10194
+ 0,
10195
+ 0,
10196
+ 0,
10197
+ 0,
10198
+ 1,
10199
+ 0,
10200
+ 0,
10201
+ 0,
10202
+ 0,
10203
+ 0,
10204
+ 0,
10205
+ 0,
10206
+ 0,
10207
+ 0,
10208
+ 0,
10209
+ 0,
10210
+ 0,
10211
+ 0,
10212
+ 0,
10213
+ 0,
10214
+ 0,
10215
+ track.width >> 8 & 255,
10216
+ track.width & 255,
10217
+ track.height >> 8 & 255,
10218
+ track.height & 255,
10219
+ 0,
10220
+ 72,
10221
+ 0,
10222
+ 0,
10223
+ 0,
10224
+ 72,
10225
+ 0,
10226
+ 0,
10227
+ 0,
10228
+ 0,
10229
+ 0,
10230
+ 0,
10231
+ 0,
10232
+ 1,
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
+ 0,
10261
+ 0,
10262
+ 0,
10263
+ 0,
10264
+ 0,
10265
+ 0,
10266
+ 24,
10267
+ 17,
10268
+ 17
10269
+ ]), track.av1C, track.colr);
10270
+ }
9400
10271
  }, {
9401
10272
  key: "avc1hev1",
9402
10273
  value: function avc1hev1(track) {
@@ -9767,6 +10638,53 @@
9767
10638
  )));
9768
10639
  return esds2;
9769
10640
  }
10641
+ }, {
10642
+ key: "opus",
10643
+ value: function opus(track) {
10644
+ var opusAudioDescription = new Uint8Array([
10645
+ 0,
10646
+ 0,
10647
+ 0,
10648
+ 0,
10649
+ 0,
10650
+ 0,
10651
+ 0,
10652
+ 1,
10653
+ 0,
10654
+ 0,
10655
+ 0,
10656
+ 0,
10657
+ 0,
10658
+ 0,
10659
+ 0,
10660
+ 0,
10661
+ 0,
10662
+ track.channelCount,
10663
+ 0,
10664
+ 16,
10665
+ 0,
10666
+ 0,
10667
+ 0,
10668
+ 0,
10669
+ track.sampleRate >> 8 & 255,
10670
+ track.sampleRate & 255,
10671
+ 0,
10672
+ 0
10673
+ ]);
10674
+ var opusSpecificConfig = track.config.length ? MP42.dOps(track) : [];
10675
+ return MP42.box(MP42.types.Opus, opusAudioDescription, opusSpecificConfig);
10676
+ }
10677
+ }, {
10678
+ key: "dOps",
10679
+ value: function dOps(track) {
10680
+ if (track.config) {
10681
+ track.config[4] = track.sampleRate >>> 24 & 255;
10682
+ track.config[5] = track.sampleRate >>> 16 & 255;
10683
+ track.config[6] = track.sampleRate >>> 8 & 255;
10684
+ track.config[7] = track.sampleRate & 255;
10685
+ return MP42.box(MP42.types.dOps, track.config);
10686
+ }
10687
+ }
9770
10688
  }, {
9771
10689
  key: "mvex",
9772
10690
  value: function mvex(tracks) {
@@ -10369,7 +11287,7 @@
10369
11287
  }]);
10370
11288
  return MP42;
10371
11289
  }();
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) {
11290
+ _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
11291
  p[c] = [c.charCodeAt(0), c.charCodeAt(1), c.charCodeAt(2), c.charCodeAt(3)];
10374
11292
  return p;
10375
11293
  }, /* @__PURE__ */ Object.create(null)));
@@ -10704,30 +11622,46 @@
10704
11622
  };
10705
11623
  }
10706
11624
  var samples = track.samples;
11625
+ var isAV01 = /av01/.test(track.codec);
10707
11626
  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;
11627
+ if (isAV01) {
11628
+ samples.forEach(function(s) {
11629
+ mdatSize += s.data.byteLength;
10725
11630
  });
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);
11631
+ } else {
11632
+ samples.forEach(function(s) {
11633
+ mdatSize += s.units.reduce(function(t, c) {
11634
+ return t + c.byteLength;
11635
+ }, 0);
11636
+ mdatSize += s.units.length * 4;
11637
+ });
11638
+ }
11639
+ var mdata = new Uint8Array(mdatSize);
11640
+ if (isAV01) {
11641
+ for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
11642
+ sample = samples[i];
11643
+ mdata.set(sample.data, offset);
11644
+ sample.size = sample.data.byteLength;
11645
+ offset += sample.size;
11646
+ }
11647
+ } else {
11648
+ var mdatView = new DataView(mdata.buffer);
11649
+ var _loop = function _loop2(_offset2, _sample2) {
11650
+ _sample2 = samples[_i];
11651
+ var sampleSize = 0;
11652
+ _sample2.units.forEach(function(u) {
11653
+ mdatView.setUint32(_offset2, u.byteLength);
11654
+ _offset2 += 4;
11655
+ mdata.set(u, _offset2);
11656
+ _offset2 += u.byteLength;
11657
+ sampleSize += 4 + u.byteLength;
11658
+ });
11659
+ _sample2.size = sampleSize;
11660
+ _offset = _offset2, _sample = _sample2;
11661
+ };
11662
+ for (var _i = 0, _l = samples.length, _offset = 0, _sample; _i < _l; _i++) {
11663
+ _loop(_offset, _sample);
11664
+ }
10731
11665
  }
10732
11666
  var mdat = MP4.mdat(mdata);
10733
11667
  var moof = MP4.moof([track]);
@@ -10886,11 +11820,11 @@
10886
11820
  });
10887
11821
  var logger$3 = new Logger$2("Transmuxer");
10888
11822
  var Transmuxer = /* @__PURE__ */ function() {
10889
- function Transmuxer2(hls, isMP4, needRemux) {
11823
+ function Transmuxer2(hls, isMP4, needRemux, fixerConfig) {
10890
11824
  _classCallCheck$3(this, Transmuxer2);
10891
11825
  _defineProperty$3(this, "_initSegmentId", "");
10892
11826
  this.hls = hls;
10893
- this._demuxer = isMP4 ? new FMP4Demuxer() : new TsDemuxer();
11827
+ this._demuxer = isMP4 ? new FMP4Demuxer() : new TsDemuxer(null, null, null, fixerConfig);
10894
11828
  this._isMP4 = isMP4;
10895
11829
  if (needRemux)
10896
11830
  this._remuxer = new FMP4Remuxer(this._demuxer.videoTrack, this._demuxer.audioTrack);
@@ -10921,7 +11855,8 @@
10921
11855
  timescale: audioTrack.timescale,
10922
11856
  firstDts: audioTrack.firstDts / videoTrack.timescale,
10923
11857
  firstPts: audioTrack.firstPts / videoTrack.timescale,
10924
- duration: audioTrack.samplesDuration / videoTrack.timescale
11858
+ duration: audioTrack.samplesDuration / videoTrack.timescale,
11859
+ container: audioTrack.container
10925
11860
  };
10926
11861
  var newId = "".concat(videoTrack.codec, "/").concat(videoTrack.width, "/").concat(videoTrack.height, "/").concat(audioTrack.codec, "/").concat(audioTrack.config);
10927
11862
  if (newId !== this._initSegmentId) {
@@ -11045,7 +11980,7 @@
11045
11980
  }]);
11046
11981
  return Transmuxer2;
11047
11982
  }();
11048
- var _excluded = ["data"], _excluded2 = ["data"];
11983
+ var _excluded$1 = ["data"], _excluded2 = ["data"];
11049
11984
  var logger$2 = new Logger$2("BufferService");
11050
11985
  var BufferService = /* @__PURE__ */ function() {
11051
11986
  function BufferService2(hls) {
@@ -11157,11 +12092,11 @@
11157
12092
  return;
11158
12093
  if (TsDemuxer.probe(chunk)) {
11159
12094
  if (!this._transmuxer)
11160
- this._transmuxer = new Transmuxer(this.hls, false, !this._softVideo);
12095
+ this._transmuxer = new Transmuxer(this.hls, false, !this._softVideo, this.hls.config.fixerConfig);
11161
12096
  } else if (MP4Parser.probe(chunk)) {
11162
12097
  if (this._softVideo) {
11163
12098
  if (!this._transmuxer)
11164
- this._transmuxer = new Transmuxer(this.hls, true);
12099
+ this._transmuxer = new Transmuxer(this.hls, true, null, this.hls.config.fixerConfig);
11165
12100
  } else {
11166
12101
  this._directAppend = true;
11167
12102
  var mix = false;
@@ -11211,7 +12146,8 @@
11211
12146
  key: "appendBuffer",
11212
12147
  value: function() {
11213
12148
  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;
12149
+ var _this2 = this;
12150
+ var afterAppend, p, needInit, _this$_transmuxer$tra, _this$_transmuxer$tra2, video, audio, isFirstAppend, mse, _p, videoData, videoRest, audioData, audioRest;
11215
12151
  return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
11216
12152
  while (1)
11217
12153
  switch (_context2.prev = _context2.next) {
@@ -11222,8 +12158,18 @@
11222
12158
  }
11223
12159
  return _context2.abrupt("return");
11224
12160
  case 2:
12161
+ afterAppend = function afterAppend2() {
12162
+ var _this2$hls;
12163
+ if ((_this2$hls = _this2.hls) !== null && _this2$hls !== void 0 && _this2$hls.emit) {
12164
+ var _this2$hls2;
12165
+ (_this2$hls2 = _this2.hls) === null || _this2$hls2 === void 0 ? void 0 : _this2$hls2.emit(EVENT.APPEND_BUFFER, {
12166
+ start: segment.start,
12167
+ end: segment.end
12168
+ });
12169
+ }
12170
+ };
11225
12171
  if (!this._directAppend) {
11226
- _context2.next = 7;
12172
+ _context2.next = 8;
11227
12173
  break;
11228
12174
  }
11229
12175
  p = [];
@@ -11231,8 +12177,8 @@
11231
12177
  p.push(this._mse.append(MSE.VIDEO, videoChunk));
11232
12178
  if (audioChunk)
11233
12179
  p.push(this._mse.append(MSE.AUDIO, audioChunk));
11234
- return _context2.abrupt("return", Promise.all(p));
11235
- case 7:
12180
+ return _context2.abrupt("return", Promise.all(p).then(afterAppend));
12181
+ case 8:
11236
12182
  needInit = this._needInitSegment || discontinuity;
11237
12183
  _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
12184
  if (audioChunk && audioSegment) {
@@ -11248,21 +12194,22 @@
11248
12194
  this.hls.emit(Event$1.NO_AUDIO_TRACK);
11249
12195
  }
11250
12196
  if (!this._softVideo) {
11251
- _context2.next = 18;
12197
+ _context2.next = 20;
11252
12198
  break;
11253
12199
  }
11254
12200
  this._softVideo.appendBuffer(video, audio);
11255
12201
  this._needInitSegment = false;
11256
- _context2.next = 28;
12202
+ afterAppend();
12203
+ _context2.next = 30;
11257
12204
  break;
11258
- case 18:
12205
+ case 20:
11259
12206
  if (!this._mse) {
11260
- _context2.next = 28;
12207
+ _context2.next = 30;
11261
12208
  break;
11262
12209
  }
11263
12210
  isFirstAppend = !this._sourceCreated;
11264
12211
  if (isFirstAppend) {
11265
- this._createMseSource(video === null || video === void 0 ? void 0 : video.codec, audio === null || audio === void 0 ? void 0 : audio.codec);
12212
+ 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
12213
  }
11267
12214
  this._needInitSegment = false;
11268
12215
  mse = this._mse;
@@ -11273,15 +12220,15 @@
11273
12220
  });
11274
12221
  }
11275
12222
  if (video) {
11276
- videoData = video.data, videoRest = _objectWithoutProperties$1(video, _excluded);
12223
+ videoData = video.data, videoRest = _objectWithoutProperties$1(video, _excluded$1);
11277
12224
  _p.push(mse.append(MSE.VIDEO, videoData, videoRest));
11278
12225
  }
11279
12226
  if (audio) {
11280
12227
  audioData = audio.data, audioRest = _objectWithoutProperties$1(audio, _excluded2);
11281
12228
  _p.push(mse.append(MSE.AUDIO, audioData, audioRest));
11282
12229
  }
11283
- return _context2.abrupt("return", Promise.all(_p));
11284
- case 28:
12230
+ return _context2.abrupt("return", Promise.all(_p).then(afterAppend));
12231
+ case 30:
11285
12232
  case "end":
11286
12233
  return _context2.stop();
11287
12234
  }
@@ -11296,7 +12243,7 @@
11296
12243
  key: "removeBuffer",
11297
12244
  value: function() {
11298
12245
  var _removeBuffer = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee3() {
11299
- var _this2 = this;
12246
+ var _this3 = this;
11300
12247
  var start, end, media, _args3 = arguments;
11301
12248
  return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
11302
12249
  while (1)
@@ -11312,7 +12259,7 @@
11312
12259
  return _context3.abrupt("return");
11313
12260
  case 5:
11314
12261
  return _context3.abrupt("return", this._mse.clearBuffer(start, end).then(function() {
11315
- return _this2.hls.emit(EVENT.REMOVE_BUFFER, {
12262
+ return _this3.hls.emit(EVENT.REMOVE_BUFFER, {
11316
12263
  start,
11317
12264
  end,
11318
12265
  removeEnd: end
@@ -11493,30 +12440,51 @@
11493
12440
  return setLiveSeekableRange;
11494
12441
  }()
11495
12442
  }, {
11496
- key: "destroy",
12443
+ key: "detachMedia",
11497
12444
  value: function() {
11498
- var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee9() {
11499
- var _this$_decryptor;
12445
+ var _detachMedia = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee9() {
11500
12446
  return _regeneratorRuntime$1().wrap(function _callee9$(_context9) {
11501
12447
  while (1)
11502
12448
  switch (_context9.prev = _context9.next) {
11503
12449
  case 0:
11504
- (_this$_decryptor = this._decryptor) === null || _this$_decryptor === void 0 ? void 0 : _this$_decryptor.destroy();
11505
12450
  if (!this._mse) {
11506
- _context9.next = 4;
12451
+ _context9.next = 3;
11507
12452
  break;
11508
12453
  }
11509
- _context9.next = 4;
12454
+ _context9.next = 3;
11510
12455
  return this._mse.unbindMedia();
11511
- case 4:
12456
+ case 3:
12457
+ case "end":
12458
+ return _context9.stop();
12459
+ }
12460
+ }, _callee9, this);
12461
+ }));
12462
+ function detachMedia() {
12463
+ return _detachMedia.apply(this, arguments);
12464
+ }
12465
+ return detachMedia;
12466
+ }()
12467
+ }, {
12468
+ key: "destroy",
12469
+ value: function() {
12470
+ var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee10() {
12471
+ var _this$_decryptor;
12472
+ return _regeneratorRuntime$1().wrap(function _callee10$(_context10) {
12473
+ while (1)
12474
+ switch (_context10.prev = _context10.next) {
12475
+ case 0:
12476
+ (_this$_decryptor = this._decryptor) === null || _this$_decryptor === void 0 ? void 0 : _this$_decryptor.destroy();
12477
+ _context10.next = 3;
12478
+ return this.detachMedia();
12479
+ case 3:
11512
12480
  this._decryptor = null;
11513
12481
  this._mse = null;
11514
12482
  this._softVideo = null;
11515
- case 7:
12483
+ case 6:
11516
12484
  case "end":
11517
- return _context9.stop();
12485
+ return _context10.stop();
11518
12486
  }
11519
- }, _callee9, this);
12487
+ }, _callee10, this);
11520
12488
  }));
11521
12489
  function destroy() {
11522
12490
  return _destroy.apply(this, arguments);
@@ -11525,7 +12493,7 @@
11525
12493
  }()
11526
12494
  }, {
11527
12495
  key: "_createMseSource",
11528
- value: function _createMseSource(videoCodec, audioCodec) {
12496
+ value: function _createMseSource(videoCodec, audioCodec, container) {
11529
12497
  logger$2.debug("create mse source, videoCodec=".concat(videoCodec, ", audioCodec=").concat(audioCodec));
11530
12498
  var mse = this._mse;
11531
12499
  if (!mse)
@@ -11537,6 +12505,9 @@
11537
12505
  if (audioCodec) {
11538
12506
  mse.createSource(MSE.AUDIO, "audio/mp4;codecs=".concat(audioCodec));
11539
12507
  this._sourceCreated = true;
12508
+ } else if (container) {
12509
+ mse.createSource(MSE.AUDIO, "".concat(container, ';codecs=""'));
12510
+ this._sourceCreated = true;
11540
12511
  }
11541
12512
  this.hls.emit(EVENT.SOURCEBUFFER_CREATED);
11542
12513
  }
@@ -11604,7 +12575,11 @@
11604
12575
  minSegmentsStartPlay: 3,
11605
12576
  preferMMS: false,
11606
12577
  preferMMSStreaming: false,
11607
- mseLowLatency: true
12578
+ mseLowLatency: true,
12579
+ fixerConfig: {
12580
+ forceFixLargeGap: false,
12581
+ largeGapThreshold: 5
12582
+ }
11608
12583
  }, cfg), {}, {
11609
12584
  media
11610
12585
  });
@@ -11719,6 +12694,8 @@
11719
12694
  _defineProperty$3(this, "lowLatency", false);
11720
12695
  _defineProperty$3(this, "endPartIndex", 0);
11721
12696
  _defineProperty$3(this, "segments", []);
12697
+ _defineProperty$3(this, "dateRanges", {});
12698
+ _defineProperty$3(this, "skippedSegments", 0);
11722
12699
  });
11723
12700
  var MediaSegment = /* @__PURE__ */ function() {
11724
12701
  function MediaSegment2(parentUrl) {
@@ -11840,6 +12817,31 @@
11840
12817
  }]);
11841
12818
  return MediaSegmentKey2;
11842
12819
  }();
12820
+ var HlsUrlParameters = /* @__PURE__ */ function() {
12821
+ function HlsUrlParameters2(msn, part, skip) {
12822
+ _classCallCheck$3(this, HlsUrlParameters2);
12823
+ this.msn = msn;
12824
+ this.part = part;
12825
+ this.skip = skip;
12826
+ }
12827
+ _createClass$3(HlsUrlParameters2, [{
12828
+ key: "addDirectives",
12829
+ value: function addDirectives(uri) {
12830
+ var url = new self.URL(uri);
12831
+ if (this.msn !== void 0) {
12832
+ url.searchParams.set("_HLS_msn", this.msn.toString());
12833
+ }
12834
+ if (this.part) {
12835
+ url.searchParams.set("_HLS_part", this.part.toString());
12836
+ }
12837
+ if (this.skip) {
12838
+ url.searchParams.set("_HLS_skip", this.skip);
12839
+ }
12840
+ return url.href;
12841
+ }
12842
+ }]);
12843
+ return HlsUrlParameters2;
12844
+ }();
11843
12845
  var REGEXP_TAG = /^#(EXT[^:]*)(?::(.*))?$/;
11844
12846
  var REGEXP_ATTR = /([^=]+)=(?:"([^"]*)"|([^",]*))(?:,|$)/g;
11845
12847
  var REGEXP_ABSOLUTE_URL = /^(?:[a-zA-Z0-9+\-.]+:)?\/\//;
@@ -11890,6 +12892,38 @@
11890
12892
  }
11891
12893
  }
11892
12894
  }
12895
+ function isValidDaterange(attr, dateRangeWithSameId) {
12896
+ var _badValueForSameId;
12897
+ if (dateRangeWithSameId) {
12898
+ for (var key in dateRangeWithSameId) {
12899
+ if (Object.prototype.hasOwnProperty.call(dateRangeWithSameId, key) && attr[key] !== dateRangeWithSameId[key]) {
12900
+ _badValueForSameId = key;
12901
+ break;
12902
+ }
12903
+ }
12904
+ }
12905
+ var duration = null;
12906
+ if (attr.DURATION) {
12907
+ duration = parseFloat(attr.DURATION);
12908
+ if (!Number.isFinite(duration)) {
12909
+ duration = null;
12910
+ } else if (attr._endDate) {
12911
+ duration = (attr._endDate.getTime() - attr._startDate.getTime()) / 1e3;
12912
+ }
12913
+ }
12914
+ var cue = enumeratedStringList(attr.CUE || attr["X-CUE"], {
12915
+ pre: false,
12916
+ post: false,
12917
+ once: false
12918
+ });
12919
+ 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);
12920
+ }
12921
+ function enumeratedStringList(attrValue, dict) {
12922
+ return (attrValue ? attrValue.split(/[ ,]+/) : []).reduce(function(result, identifier) {
12923
+ result[identifier.toLowerCase()] = true;
12924
+ return result;
12925
+ }, dict);
12926
+ }
11893
12927
  function parseMasterPlaylist(lines, parentUrl) {
11894
12928
  var master = new MasterPlaylist();
11895
12929
  var index = 0;
@@ -11998,9 +13032,6 @@
11998
13032
  var endOfList = false;
11999
13033
  var partSegmentIndex = 0;
12000
13034
  while (line = lines[index++]) {
12001
- if (endOfList) {
12002
- break;
12003
- }
12004
13035
  if (line[0] !== "#") {
12005
13036
  if (media.lowLatency) {
12006
13037
  curSN++;
@@ -12049,16 +13080,11 @@
12049
13080
  media.canBlockReload = _attr["CAN-BLOCK-RELOAD"] === "YES";
12050
13081
  media.partHoldBack = parseFloat(_attr["PART-HOLD-BACK"] || 0);
12051
13082
  media.canSkipUntil = parseFloat(_attr["CAN-SKIP-UNTIL"] || 0);
12052
- media.canSkipDateRanges = _attr["CAN-SKIP-DATERANGES"] === "YES";
13083
+ media.canSkipDateRanges = media.canSkipUntil > 0 && _attr["CAN-SKIP-DATERANGES"] === "YES";
12053
13084
  }
12054
13085
  break;
12055
13086
  case "ENDLIST":
12056
13087
  {
12057
- var _lastSegment = media.segments[media.segments.length - 1];
12058
- if (_lastSegment) {
12059
- _lastSegment.isLast = true;
12060
- }
12061
- media.live = false;
12062
13088
  endOfList = true;
12063
13089
  }
12064
13090
  break;
@@ -12098,6 +13124,15 @@
12098
13124
  }
12099
13125
  break;
12100
13126
  case "PRELOAD-HINT":
13127
+ {
13128
+ var _attr3 = parseAttr(data);
13129
+ media.preloadHint = _attr3;
13130
+ if (_attr3["TYPE"] === "PART" && _attr3["URI"]) {
13131
+ var tmp = _attr3["URI"].split(".ts")[0].split("-");
13132
+ media.nextSN = tmp[3];
13133
+ media.nextIndex = tmp[tmp.length - 1];
13134
+ }
13135
+ }
12101
13136
  break;
12102
13137
  case "PROGRAM-DATE-TIME":
12103
13138
  curSegment.dataTime = data;
@@ -12117,21 +13152,21 @@
12117
13152
  break;
12118
13153
  case "KEY":
12119
13154
  {
12120
- var _attr3 = parseAttr(data);
12121
- if (_attr3.METHOD === "NONE") {
13155
+ var _attr4 = parseAttr(data);
13156
+ if (_attr4.METHOD === "NONE") {
12122
13157
  curKey = null;
12123
13158
  break;
12124
13159
  }
12125
13160
  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;
13161
+ curKey.method = _attr4.METHOD;
13162
+ curKey.url = /^blob:/.test(_attr4.URI) ? _attr4.URI : getAbsoluteUrl(_attr4.URI, parentUrl);
13163
+ curKey.keyFormat = _attr4.KEYFORMAT || "identity";
13164
+ curKey.keyFormatVersions = _attr4.KEYFORMATVERSIONS;
12130
13165
  if (!curKey.isSupported()) {
12131
- throw new Error("encrypt ".concat(_attr3.METHOD, "/").concat(_attr3.KEYFORMAT, " is not supported"));
13166
+ throw new Error("encrypt ".concat(_attr4.METHOD, "/").concat(_attr4.KEYFORMAT, " is not supported"));
12132
13167
  }
12133
- if (_attr3.IV) {
12134
- var str = _attr3.IV.slice(2);
13168
+ if (_attr4.IV) {
13169
+ var str = _attr4.IV.slice(2);
12135
13170
  str = (str.length & 1 ? "0" : "") + str;
12136
13171
  curKey.iv = new Uint8Array(str.length / 2);
12137
13172
  for (var i = 0, l = str.length / 2; i < l; i++) {
@@ -12142,10 +13177,10 @@
12142
13177
  break;
12143
13178
  case "MAP":
12144
13179
  {
12145
- var _attr4 = parseAttr(data);
12146
- curSegment.url = getAbsoluteUrl(_attr4.URI, parentUrl);
12147
- if (_attr4.BYTERANGE)
12148
- curSegment.setByteRange(_attr4.BYTERANGE);
13180
+ var _attr5 = parseAttr(data);
13181
+ curSegment.url = getAbsoluteUrl(_attr5.URI, parentUrl);
13182
+ if (_attr5.BYTERANGE)
13183
+ curSegment.setByteRange(_attr5.BYTERANGE);
12149
13184
  curSegment.isInitSegment = true;
12150
13185
  curSegment.sn = 0;
12151
13186
  if (curKey) {
@@ -12155,6 +13190,30 @@
12155
13190
  curSegment = new MediaSegment(parentUrl);
12156
13191
  }
12157
13192
  break;
13193
+ case "SKIP":
13194
+ {
13195
+ var _attr6 = parseAttr(data);
13196
+ var skippedSegments = parseInt(_attr6["SKIPPED-SEGMENTS"], 10);
13197
+ if (skippedSegments <= Number.MAX_SAFE_INTEGER) {
13198
+ media.skippedSegments += skippedSegments;
13199
+ curSN += skippedSegments;
13200
+ }
13201
+ }
13202
+ break;
13203
+ case "DATERANGE":
13204
+ {
13205
+ var _attr7 = parseAttr(data);
13206
+ var dateRangeWithSameId = media.dateRanges[_attr7.ID];
13207
+ _attr7._startDate = dateRangeWithSameId ? dateRangeWithSameId._startDate : new Date(_attr7["START-DATE"]);
13208
+ var endDate = (dateRangeWithSameId === null || dateRangeWithSameId === void 0 ? void 0 : dateRangeWithSameId._endDate) || new Date(_attr7.END_DATE);
13209
+ if (Number.isFinite(endDate)) {
13210
+ _attr7._endDate = endDate;
13211
+ }
13212
+ if (isValidDaterange(_attr7, dateRangeWithSameId) || media.skippedSegments) {
13213
+ media.dateRanges[_attr7.ID] = _attr7;
13214
+ }
13215
+ }
13216
+ break;
12158
13217
  }
12159
13218
  }
12160
13219
  media.segments = media.segments.filter(function(x) {
@@ -12162,11 +13221,14 @@
12162
13221
  });
12163
13222
  var lastSegment = media.segments[media.segments.length - 1];
12164
13223
  if (lastSegment) {
12165
- media.endSN = lastSegment.sn;
12166
- media.endPartIndex = lastSegment.partIndex;
12167
- if (endOfList && !lastSegment.isLast) {
13224
+ if (endOfList) {
12168
13225
  lastSegment.isLast = true;
12169
13226
  }
13227
+ media.endSN = lastSegment.sn;
13228
+ media.endPartIndex = lastSegment.partIndex;
13229
+ }
13230
+ if (endOfList) {
13231
+ media.live = false;
12170
13232
  }
12171
13233
  media.totalDuration = totalDuration;
12172
13234
  media.endCC = curCC;
@@ -12345,6 +13407,13 @@
12345
13407
  playlist
12346
13408
  });
12347
13409
  } else {
13410
+ if (this._useLowLatency) {
13411
+ if (playlist.canBlockReload) {
13412
+ this.deliveryDirectives = new HlsUrlParameters(playlist.nextSN, playlist.nextIndex, "");
13413
+ } else {
13414
+ this.deliveryDirectives = null;
13415
+ }
13416
+ }
12348
13417
  this.hls.emit(Event$1.HLS_LEVEL_LOADED, {
12349
13418
  playlist
12350
13419
  });
@@ -12401,41 +13470,45 @@
12401
13470
  var retryCount = this.hls.config.pollRetryCount;
12402
13471
  var fn = /* @__PURE__ */ function() {
12403
13472
  var _ref2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee2() {
12404
- var res;
13473
+ var reqUrl, res;
12405
13474
  return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
12406
13475
  while (1)
12407
13476
  switch (_context2.prev = _context2.next) {
12408
13477
  case 0:
12409
13478
  clearTimeout(_this2._timer);
12410
- _context2.prev = 1;
12411
- _context2.next = 4;
12412
- return _this2.load(url, audioUrl, subtitleUrl);
12413
- case 4:
13479
+ reqUrl = url;
13480
+ _context2.prev = 2;
13481
+ if (_this2.deliveryDirectives) {
13482
+ reqUrl = _this2.deliveryDirectives.addDirectives(url);
13483
+ }
13484
+ _context2.next = 6;
13485
+ return _this2.load(reqUrl, audioUrl, subtitleUrl);
13486
+ case 6:
12414
13487
  res = _context2.sent;
12415
13488
  if (res[0]) {
12416
- _context2.next = 7;
13489
+ _context2.next = 9;
12417
13490
  break;
12418
13491
  }
12419
13492
  return _context2.abrupt("return");
12420
- case 7:
13493
+ case 9:
12421
13494
  retryCount = _this2.hls.config.pollRetryCount;
12422
13495
  cb(res[0], res[1], res[2]);
12423
- _context2.next = 15;
13496
+ _context2.next = 17;
12424
13497
  break;
12425
- case 11:
12426
- _context2.prev = 11;
12427
- _context2.t0 = _context2["catch"](1);
13498
+ case 13:
13499
+ _context2.prev = 13;
13500
+ _context2.t0 = _context2["catch"](2);
12428
13501
  retryCount--;
12429
13502
  if (retryCount <= 0) {
12430
13503
  errorCb(_context2.t0);
12431
13504
  }
12432
- case 15:
13505
+ case 17:
12433
13506
  _this2._timer = setTimeout(fn, time);
12434
- case 16:
13507
+ case 18:
12435
13508
  case "end":
12436
13509
  return _context2.stop();
12437
13510
  }
12438
- }, _callee2, null, [[1, 11]]);
13511
+ }, _callee2, null, [[2, 13]]);
12439
13512
  }));
12440
13513
  return function fn2() {
12441
13514
  return _ref2.apply(this, arguments);
@@ -12965,7 +14038,7 @@
12965
14038
  }, {
12966
14039
  key: "clearOldSegment",
12967
14040
  value: function clearOldSegment() {
12968
- var maxPlaylistSize = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 50;
14041
+ var maxPlaylistSize = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.hls.config.maxPlaylistSize || 50;
12969
14042
  var stream = this.currentStream;
12970
14043
  if (!this.dvrWindow || !stream)
12971
14044
  return;
@@ -13263,7 +14336,7 @@
13263
14336
  _defineProperty$3(_assertThisInitialized$2(_this), "_switchUrlOpts", null);
13264
14337
  _defineProperty$3(_assertThisInitialized$2(_this), "_isProcessQuotaExceeded", false);
13265
14338
  _defineProperty$3(_assertThisInitialized$2(_this), "_loadSegment", /* @__PURE__ */ _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee() {
13266
- var nextSeg, _assertThisInitialize, config, bInfo, bufferThroughout;
14339
+ var _this$_playlist, nextSegment, lastSegment, _assertThisInitialize, config, minFrameDuration, maxBufferThroughout, bInfo, bufferThroughout;
13267
14340
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
13268
14341
  while (1)
13269
14342
  switch (_context.prev = _context.next) {
@@ -13274,42 +14347,44 @@
13274
14347
  }
13275
14348
  return _context.abrupt("return");
13276
14349
  case 2:
13277
- nextSeg = _this._playlist.nextSegment;
14350
+ _this$_playlist = _this._playlist, nextSegment = _this$_playlist.nextSegment, lastSegment = _this$_playlist.lastSegment;
13278
14351
  _assertThisInitialize = _assertThisInitialized$2(_this), config = _assertThisInitialize.config;
13279
- if (nextSeg) {
13280
- _context.next = 6;
14352
+ minFrameDuration = 0.016;
14353
+ maxBufferThroughout = Math.min(Math.max((lastSegment === null || lastSegment === void 0 ? void 0 : lastSegment.duration) - minFrameDuration / 2 || 0, minFrameDuration), 0.1);
14354
+ if (nextSegment) {
14355
+ _context.next = 8;
13281
14356
  break;
13282
14357
  }
13283
14358
  return _context.abrupt("return");
13284
- case 6:
14359
+ case 8:
13285
14360
  if (_this.isLive) {
13286
- _context.next = 16;
14361
+ _context.next = 18;
13287
14362
  break;
13288
14363
  }
13289
14364
  bInfo = _this.bufferInfo();
13290
14365
  if (_this.media.paused && !_this.media.currentTime) {
13291
14366
  bInfo = _this.bufferInfo(bInfo.nextStart || 0.5);
13292
14367
  }
13293
- bufferThroughout = Math.abs(bInfo.end - _this.media.duration) < 0.1;
14368
+ bufferThroughout = Math.abs(bInfo.end - _this.media.duration) < maxBufferThroughout;
13294
14369
  if (!(bInfo.remaining >= config.preloadTime || bufferThroughout)) {
13295
- _context.next = 13;
14370
+ _context.next = 15;
13296
14371
  break;
13297
14372
  }
13298
14373
  _this._tryEos();
13299
14374
  return _context.abrupt("return");
13300
- case 13:
14375
+ case 15:
13301
14376
  if (!(config.preferMMSStreaming && !_this._bufferService.msStreaming)) {
13302
- _context.next = 15;
14377
+ _context.next = 17;
13303
14378
  break;
13304
14379
  }
13305
14380
  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) {
14381
+ case 17:
14382
+ if (!_this._urlSwitching && _this._prevSegSn !== nextSegment.sn - 1 && bInfo.end && Math.abs(nextSegment.start - bInfo.end) > 1) {
13308
14383
  _this._playlist.setNextSegmentByIndex(_this._playlist.findSegmentIndexByTime(bInfo.end + 0.1));
13309
14384
  }
13310
- case 16:
14385
+ case 18:
13311
14386
  return _context.abrupt("return", _this._loadSegmentDirect());
13312
- case 17:
14387
+ case 19:
13313
14388
  case "end":
13314
14389
  return _context.stop();
13315
14390
  }
@@ -13474,7 +14549,6 @@
13474
14549
  return;
13475
14550
  _this._startTick();
13476
14551
  var media = _this.media;
13477
- var buffered = Buffer$1.get(media);
13478
14552
  var segLoaderError = _this._segmentLoader.error;
13479
14553
  _this._onCheckQuotaExceeded();
13480
14554
  if (_this._isProcessQuotaExceeded) {
@@ -13491,7 +14565,7 @@
13491
14565
  }
13492
14566
  return;
13493
14567
  }
13494
- if (Buffer$1.end(buffered) >= 0.1 && media.readyState) {
14568
+ if (media.readyState) {
13495
14569
  if (isMediaPlaying(media)) {
13496
14570
  _this._loadSegment();
13497
14571
  if (_this._gapService) {
@@ -13557,6 +14631,12 @@
13557
14631
  var _this$_bufferService;
13558
14632
  return (_this$_bufferService = this._bufferService) === null || _this$_bufferService === void 0 ? void 0 : _this$_bufferService.baseDts;
13559
14633
  }
14634
+ }, {
14635
+ key: "abrSwitchPoint",
14636
+ get: function get() {
14637
+ var targetSeg = this._urlSwitching ? this._playlist.currentSegment : this._playlist.nextSegment;
14638
+ return targetSeg ? targetSeg.start + targetSeg.duration / 2 : null;
14639
+ }
13560
14640
  }, {
13561
14641
  key: "speedInfo",
13562
14642
  value: function speedInfo() {
@@ -13582,30 +14662,37 @@
13582
14662
  }, {
13583
14663
  key: "load",
13584
14664
  value: function() {
13585
- var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee4(url) {
13586
- var reuseMse, _args4 = arguments;
14665
+ var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee4() {
14666
+ var url, options, reuseMse, _args4 = arguments;
13587
14667
  return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
13588
14668
  while (1)
13589
14669
  switch (_context4.prev = _context4.next) {
13590
14670
  case 0:
13591
- reuseMse = _args4.length > 1 && _args4[1] !== void 0 ? _args4[1] : false;
14671
+ url = _args4.length > 0 && _args4[0] !== void 0 ? _args4[0] : "";
14672
+ options = _args4.length > 1 && _args4[1] !== void 0 ? _args4[1] : {};
14673
+ reuseMse = typeof options === "boolean" ? options : !!(options !== null && options !== void 0 && options.reuseMse);
14674
+ if (_typeof$2(options) === "object" && options !== null && options !== void 0 && options.clearSwitchStatus) {
14675
+ this._urlSwitching = false;
14676
+ this._switchUrlOpts = null;
14677
+ this.config.startTime = void 0;
14678
+ }
13592
14679
  if (url)
13593
14680
  this.config.url = url;
13594
14681
  url = this.config.url;
13595
- _context4.next = 5;
14682
+ _context4.next = 8;
13596
14683
  return this._reset(reuseMse);
13597
- case 5:
13598
- _context4.next = 7;
14684
+ case 8:
14685
+ _context4.next = 10;
13599
14686
  return this._loadData(url);
13600
- case 7:
14687
+ case 10:
13601
14688
  this._startTick();
13602
- case 8:
14689
+ case 11:
13603
14690
  case "end":
13604
14691
  return _context4.stop();
13605
14692
  }
13606
14693
  }, _callee4, this);
13607
14694
  }));
13608
- function load(_x) {
14695
+ function load() {
13609
14696
  return _load.apply(this, arguments);
13610
14697
  }
13611
14698
  return load;
@@ -13614,7 +14701,7 @@
13614
14701
  key: "_loadData",
13615
14702
  value: function() {
13616
14703
  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;
14704
+ var manifest, currentStream, preIndex, _this$_switchUrlOpts, _this$_switchUrlOpts3, _this$_switchUrlOpts4, _this$_switchUrlOpts2, switchTimePoint, segIdx, nextSeg, bufferClearStartPoint, startTime, _this$_switchUrlOpts5;
13618
14705
  return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
13619
14706
  while (1)
13620
14707
  switch (_context5.prev = _context5.next) {
@@ -13635,41 +14722,46 @@
13635
14722
  case 5:
13636
14723
  manifest = _context5.sent;
13637
14724
  currentStream = this._playlist.currentStream;
13638
- if (!(this._urlSwitching && !this.isLive)) {
13639
- _context5.next = 17;
14725
+ if (!this._urlSwitching) {
14726
+ _context5.next = 23;
13640
14727
  break;
13641
14728
  }
14729
+ if (!this.isLive) {
14730
+ _context5.next = 14;
14731
+ break;
14732
+ }
14733
+ preIndex = this._playlist.setNextSegmentBySN(this._prevSegSn);
14734
+ logger.log("segment nb=".concat(this._prevSegSn, " index of ").concat(preIndex, " in the new playlist"));
14735
+ if (preIndex === -1) {
14736
+ this._prevSegCc = null;
14737
+ this._prevSegSn = null;
14738
+ }
14739
+ _context5.next = 23;
14740
+ break;
14741
+ case 14:
13642
14742
  if (currentStream.bitrate === 0 && (_this$_switchUrlOpts = this._switchUrlOpts) !== null && _this$_switchUrlOpts !== void 0 && _this$_switchUrlOpts.bitrate) {
13643
14743
  currentStream.bitrate = (_this$_switchUrlOpts2 = this._switchUrlOpts) === null || _this$_switchUrlOpts2 === void 0 ? void 0 : _this$_switchUrlOpts2.bitrate;
13644
14744
  }
13645
- switchTimePoint = this._getSeamlessSwitchPoint();
14745
+ 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
14746
  this.config.startTime = switchTimePoint;
13647
14747
  segIdx = this._playlist.findSegmentIndexByTime(switchTimePoint);
13648
14748
  nextSeg = this._playlist.getSegmentByIndex(segIdx + 1);
13649
14749
  if (!nextSeg) {
13650
- _context5.next = 17;
14750
+ _context5.next = 23;
13651
14751
  break;
13652
14752
  }
13653
14753
  bufferClearStartPoint = nextSeg.start;
13654
- _context5.next = 17;
14754
+ _context5.next = 23;
13655
14755
  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
- }
14756
+ case 23:
13665
14757
  if (manifest) {
13666
- _context5.next = 20;
14758
+ _context5.next = 25;
13667
14759
  break;
13668
14760
  }
13669
14761
  return _context5.abrupt("return");
13670
- case 20:
14762
+ case 25:
13671
14763
  if (!this.isLive) {
13672
- _context5.next = 31;
14764
+ _context5.next = 36;
13673
14765
  break;
13674
14766
  }
13675
14767
  this._bufferService.setLiveSeekableRange(0, 4294967295);
@@ -13682,35 +14774,35 @@
13682
14774
  if (!manifest.isMaster)
13683
14775
  this._pollM3U8(url);
13684
14776
  if (!(this._playlist.nbSegments < this.config.minSegmentsStartPlay)) {
13685
- _context5.next = 28;
14777
+ _context5.next = 33;
13686
14778
  break;
13687
14779
  }
13688
14780
  return _context5.abrupt("return");
13689
- case 28:
13690
- _context5.next = 30;
14781
+ case 33:
14782
+ _context5.next = 35;
13691
14783
  return this._loadSegment();
13692
- case 30:
14784
+ case 35:
13693
14785
  return _context5.abrupt("return");
13694
- case 31:
13695
- _context5.next = 33;
14786
+ case 36:
14787
+ _context5.next = 38;
13696
14788
  return this._bufferService.updateDuration(currentStream.totalDuration);
13697
- case 33:
14789
+ case 38:
13698
14790
  startTime = this.config.startTime;
13699
14791
  if (startTime) {
13700
- if (!((_this$_switchUrlOpts3 = this._switchUrlOpts) !== null && _this$_switchUrlOpts3 !== void 0 && _this$_switchUrlOpts3.seamless)) {
14792
+ if (!((_this$_switchUrlOpts5 = this._switchUrlOpts) !== null && _this$_switchUrlOpts5 !== void 0 && _this$_switchUrlOpts5.seamless)) {
13701
14793
  this.media.currentTime = startTime;
13702
14794
  }
13703
14795
  this._playlist.setNextSegmentByIndex(this._playlist.findSegmentIndexByTime(startTime) || 0);
13704
14796
  }
13705
- _context5.next = 37;
14797
+ _context5.next = 42;
13706
14798
  return this._loadSegment();
13707
- case 37:
14799
+ case 42:
13708
14800
  case "end":
13709
14801
  return _context5.stop();
13710
14802
  }
13711
14803
  }, _callee5, this);
13712
14804
  }));
13713
- function _loadData(_x2) {
14805
+ function _loadData(_x) {
13714
14806
  return _loadData2.apply(this, arguments);
13715
14807
  }
13716
14808
  return _loadData;
@@ -13724,18 +14816,20 @@
13724
14816
  switch (_context6.prev = _context6.next) {
13725
14817
  case 0:
13726
14818
  this.config.startTime = 0;
13727
- _context6.next = 3;
14819
+ this._urlSwitching = false;
14820
+ this._switchUrlOpts = null;
14821
+ _context6.next = 5;
13728
14822
  return this.load();
13729
- case 3:
14823
+ case 5:
13730
14824
  this._reloadOnPlay = false;
13731
14825
  return _context6.abrupt("return", this.media.play(!isPlayEmit));
13732
- case 5:
14826
+ case 7:
13733
14827
  case "end":
13734
14828
  return _context6.stop();
13735
14829
  }
13736
14830
  }, _callee6, this);
13737
14831
  }));
13738
- function replay(_x3) {
14832
+ function replay(_x2) {
13739
14833
  return _replay.apply(this, arguments);
13740
14834
  }
13741
14835
  return replay;
@@ -13840,7 +14934,7 @@
13840
14934
  }
13841
14935
  }, _callee7, this, [[18, 29]]);
13842
14936
  }));
13843
- function switchURL(_x4) {
14937
+ function switchURL(_x3) {
13844
14938
  return _switchURL.apply(this, arguments);
13845
14939
  }
13846
14940
  return switchURL;
@@ -13926,7 +15020,7 @@
13926
15020
  }
13927
15021
  }, _callee8, this, [[8, 16], [21, 31]]);
13928
15022
  }));
13929
- function switchStream(_x5) {
15023
+ function switchStream(_x4) {
13930
15024
  return _switchStream.apply(this, arguments);
13931
15025
  }
13932
15026
  return switchStream;
@@ -14012,7 +15106,7 @@
14012
15106
  }
14013
15107
  }, _callee9, this, [[10, 18], [22, 32]]);
14014
15108
  }));
14015
- function switchAudioStream(_x6) {
15109
+ function switchAudioStream(_x5) {
14016
15110
  return _switchAudioStream.apply(this, arguments);
14017
15111
  }
14018
15112
  return switchAudioStream;
@@ -14037,25 +15131,50 @@
14037
15131
  }
14038
15132
  }, _callee10, this);
14039
15133
  }));
14040
- function switchSubtitleStream(_x7) {
15134
+ function switchSubtitleStream(_x6) {
14041
15135
  return _switchSubtitleStream.apply(this, arguments);
14042
15136
  }
14043
15137
  return switchSubtitleStream;
14044
15138
  }()
14045
15139
  }, {
14046
- key: "destroy",
15140
+ key: "detachMedia",
14047
15141
  value: function() {
14048
- var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee11() {
14049
- var _this$_seiService2;
15142
+ var _detachMedia = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee11() {
14050
15143
  return _regeneratorRuntime$1().wrap(function _callee11$(_context11) {
14051
15144
  while (1)
14052
15145
  switch (_context11.prev = _context11.next) {
15146
+ case 0:
15147
+ if (!this._bufferService) {
15148
+ _context11.next = 3;
15149
+ break;
15150
+ }
15151
+ _context11.next = 3;
15152
+ return this._bufferService.detachMedia();
15153
+ case 3:
15154
+ case "end":
15155
+ return _context11.stop();
15156
+ }
15157
+ }, _callee11, this);
15158
+ }));
15159
+ function detachMedia() {
15160
+ return _detachMedia.apply(this, arguments);
15161
+ }
15162
+ return detachMedia;
15163
+ }()
15164
+ }, {
15165
+ key: "destroy",
15166
+ value: function() {
15167
+ var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee12() {
15168
+ var _this$_seiService2;
15169
+ return _regeneratorRuntime$1().wrap(function _callee12$(_context12) {
15170
+ while (1)
15171
+ switch (_context12.prev = _context12.next) {
14053
15172
  case 0:
14054
15173
  if (this.media) {
14055
- _context11.next = 2;
15174
+ _context12.next = 2;
14056
15175
  break;
14057
15176
  }
14058
- return _context11.abrupt("return");
15177
+ return _context12.abrupt("return");
14059
15178
  case 2:
14060
15179
  this.removeAllListeners();
14061
15180
  this._playlist.reset();
@@ -14066,15 +15185,15 @@
14066
15185
  this.media.removeEventListener("pause", this._onPause);
14067
15186
  this.media.removeEventListener("seeking", this._onSeeking);
14068
15187
  this.media.removeEventListener("timeupdate", this._onTimeupdate);
14069
- _context11.next = 13;
15188
+ _context12.next = 13;
14070
15189
  return Promise.all([this._clear(), this._bufferService.destroy()]);
14071
15190
  case 13:
14072
15191
  this.media = null;
14073
15192
  case 14:
14074
15193
  case "end":
14075
- return _context11.stop();
15194
+ return _context12.stop();
14076
15195
  }
14077
- }, _callee11, this);
15196
+ }, _callee12, this);
14078
15197
  }));
14079
15198
  function destroy() {
14080
15199
  return _destroy.apply(this, arguments);
@@ -14084,48 +15203,48 @@
14084
15203
  }, {
14085
15204
  key: "_loadM3U8",
14086
15205
  value: function() {
14087
- var _loadM3U = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee12(url) {
15206
+ var _loadM3U = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee13(url) {
14088
15207
  var playlist, _this$config$manifest, _this$config$manifest2, manifest, _ref4, _ref5, _this$_playlist$curre;
14089
- return _regeneratorRuntime$1().wrap(function _callee12$(_context12) {
15208
+ return _regeneratorRuntime$1().wrap(function _callee13$(_context13) {
14090
15209
  while (1)
14091
- switch (_context12.prev = _context12.next) {
15210
+ switch (_context13.prev = _context13.next) {
14092
15211
  case 0:
14093
- _context12.prev = 0;
15212
+ _context13.prev = 0;
14094
15213
  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
15214
  return x.url === url;
14096
15215
  })[0]) === null || _this$config$manifest2 === void 0 ? void 0 : _this$config$manifest2.manifest;
14097
15216
  if (!manifest) {
14098
- _context12.next = 6;
15217
+ _context13.next = 6;
14099
15218
  break;
14100
15219
  }
14101
- _context12.t0 = this._manifestLoader.parseText(manifest, url);
14102
- _context12.next = 9;
15220
+ _context13.t0 = this._manifestLoader.parseText(manifest, url);
15221
+ _context13.next = 9;
14103
15222
  break;
14104
15223
  case 6:
14105
- _context12.next = 8;
15224
+ _context13.next = 8;
14106
15225
  return this._manifestLoader.load(url);
14107
15226
  case 8:
14108
- _context12.t0 = _context12.sent;
15227
+ _context13.t0 = _context13.sent;
14109
15228
  case 9:
14110
- _ref4 = _context12.t0;
15229
+ _ref4 = _context13.t0;
14111
15230
  _ref5 = _slicedToArray$1(_ref4, 1);
14112
15231
  playlist = _ref5[0];
14113
- _context12.next = 17;
15232
+ _context13.next = 17;
14114
15233
  break;
14115
15234
  case 14:
14116
- _context12.prev = 14;
14117
- _context12.t1 = _context12["catch"](0);
14118
- throw this._emitError(StreamingError.create(_context12.t1));
15235
+ _context13.prev = 14;
15236
+ _context13.t1 = _context13["catch"](0);
15237
+ throw this._emitError(StreamingError.create(_context13.t1));
14119
15238
  case 17:
14120
15239
  if (playlist) {
14121
- _context12.next = 19;
15240
+ _context13.next = 19;
14122
15241
  break;
14123
15242
  }
14124
- return _context12.abrupt("return");
15243
+ return _context13.abrupt("return");
14125
15244
  case 19:
14126
15245
  this._playlist.upsertPlaylist(playlist);
14127
15246
  if (!playlist.isMaster) {
14128
- _context12.next = 24;
15247
+ _context13.next = 24;
14129
15248
  break;
14130
15249
  }
14131
15250
  if ((_this$_playlist$curre = this._playlist.currentStream.subtitleStreams) !== null && _this$_playlist$curre !== void 0 && _this$_playlist$curre.length) {
@@ -14133,18 +15252,18 @@
14133
15252
  list: this._playlist.currentStream.subtitleStreams
14134
15253
  });
14135
15254
  }
14136
- _context12.next = 24;
15255
+ _context13.next = 24;
14137
15256
  return this._refreshM3U8();
14138
15257
  case 24:
14139
15258
  this.emit(Event$1.STREAM_PARSED);
14140
- return _context12.abrupt("return", playlist);
15259
+ return _context13.abrupt("return", playlist);
14141
15260
  case 26:
14142
15261
  case "end":
14143
- return _context12.stop();
15262
+ return _context13.stop();
14144
15263
  }
14145
- }, _callee12, this, [[0, 14]]);
15264
+ }, _callee13, this, [[0, 14]]);
14146
15265
  }));
14147
- function _loadM3U8(_x8) {
15266
+ function _loadM3U8(_x7) {
14148
15267
  return _loadM3U.apply(this, arguments);
14149
15268
  }
14150
15269
  return _loadM3U8;
@@ -14178,7 +15297,7 @@
14178
15297
  var isEmpty = this._playlist.isEmpty;
14179
15298
  var pollInterval;
14180
15299
  if (this._playlist.lowLatency) {
14181
- pollInterval = (this._playlist.currentStream.partTargetDuration * 2 || 0) * 1e3;
15300
+ pollInterval = (this._playlist.currentStream.partTargetDuration || 0) * 1e3;
14182
15301
  } else {
14183
15302
  var _this$_playlist$lastS;
14184
15303
  pollInterval = (((_this$_playlist$lastS = this._playlist.lastSegment) === null || _this$_playlist$lastS === void 0 ? void 0 : _this$_playlist$lastS.duration) || 0) * 1e3;
@@ -14206,53 +15325,53 @@
14206
15325
  }, {
14207
15326
  key: "_loadSegmentDirect",
14208
15327
  value: function() {
14209
- var _loadSegmentDirect2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee13(loadOnce) {
15328
+ var _loadSegmentDirect2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee14(loadOnce) {
14210
15329
  var seg, appended, cachedError, _this$_playlist$curre2, bufferEnd, sameStream;
14211
- return _regeneratorRuntime$1().wrap(function _callee13$(_context13) {
15330
+ return _regeneratorRuntime$1().wrap(function _callee14$(_context14) {
14212
15331
  while (1)
14213
- switch (_context13.prev = _context13.next) {
15332
+ switch (_context14.prev = _context14.next) {
14214
15333
  case 0:
14215
15334
  seg = this._playlist.nextSegment;
14216
15335
  if (seg) {
14217
- _context13.next = 3;
15336
+ _context14.next = 3;
14218
15337
  break;
14219
15338
  }
14220
- return _context13.abrupt("return");
15339
+ return _context14.abrupt("return");
14221
15340
  case 3:
14222
15341
  appended = false;
14223
15342
  cachedError = null;
14224
- _context13.prev = 5;
15343
+ _context14.prev = 5;
14225
15344
  this._segmentProcessing = true;
14226
15345
  logger.log("load segment, sn:".concat(seg.sn, ", [").concat(seg.start, ", ").concat(seg.end, "], partIndex:").concat(seg.partIndex));
14227
- _context13.next = 10;
15346
+ _context14.next = 10;
14228
15347
  return this._reqAndBufferSegment(seg, this._playlist.getAudioSegment(seg));
14229
15348
  case 10:
14230
- appended = _context13.sent;
14231
- _context13.next = 16;
15349
+ appended = _context14.sent;
15350
+ _context14.next = 16;
14232
15351
  break;
14233
15352
  case 13:
14234
- _context13.prev = 13;
14235
- _context13.t0 = _context13["catch"](5);
14236
- cachedError = _context13.t0;
15353
+ _context14.prev = 13;
15354
+ _context14.t0 = _context14["catch"](5);
15355
+ cachedError = _context14.t0;
14237
15356
  case 16:
14238
- _context13.prev = 16;
15357
+ _context14.prev = 16;
14239
15358
  this._segmentProcessing = false;
14240
- return _context13.finish(16);
15359
+ return _context14.finish(16);
14241
15360
  case 19:
14242
15361
  if (!cachedError) {
14243
- _context13.next = 26;
15362
+ _context14.next = 26;
14244
15363
  break;
14245
15364
  }
14246
15365
  if (!this._bufferService.isFull()) {
14247
- _context13.next = 25;
15366
+ _context14.next = 25;
14248
15367
  break;
14249
15368
  }
14250
15369
  logger.log("load segment, sn:".concat(seg.sn, ", partIndex:").concat(seg.partIndex));
14251
15370
  this._segmentProcessing = true;
14252
15371
  this._isProcessQuotaExceeded = true;
14253
- return _context13.abrupt("return", false);
15372
+ return _context14.abrupt("return", false);
14254
15373
  case 25:
14255
- return _context13.abrupt("return", this._emitError(StreamingError.create(cachedError)));
15374
+ return _context14.abrupt("return", this._emitError(StreamingError.create(cachedError)));
14256
15375
  case 26:
14257
15376
  if (appended) {
14258
15377
  bufferEnd = this.bufferInfo().end;
@@ -14278,14 +15397,14 @@
14278
15397
  this._loadSegment();
14279
15398
  }
14280
15399
  }
14281
- return _context13.abrupt("return", appended);
15400
+ return _context14.abrupt("return", appended);
14282
15401
  case 28:
14283
15402
  case "end":
14284
- return _context13.stop();
15403
+ return _context14.stop();
14285
15404
  }
14286
- }, _callee13, this, [[5, 13, 16, 19]]);
15405
+ }, _callee14, this, [[5, 13, 16, 19]]);
14287
15406
  }));
14288
- function _loadSegmentDirect(_x9) {
15407
+ function _loadSegmentDirect(_x8) {
14289
15408
  return _loadSegmentDirect2.apply(this, arguments);
14290
15409
  }
14291
15410
  return _loadSegmentDirect;
@@ -14293,45 +15412,45 @@
14293
15412
  }, {
14294
15413
  key: "_reqAndBufferSegment",
14295
15414
  value: function() {
14296
- var _reqAndBufferSegment2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee14(seg, audioSeg) {
15415
+ var _reqAndBufferSegment2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee15(seg, audioSeg) {
14297
15416
  var _this$_bufferService2;
14298
15417
  var cc, discontinuity, responses, data, sn, start, stream, before, contiguous, segStart;
14299
- return _regeneratorRuntime$1().wrap(function _callee14$(_context14) {
15418
+ return _regeneratorRuntime$1().wrap(function _callee15$(_context15) {
14300
15419
  while (1)
14301
- switch (_context14.prev = _context14.next) {
15420
+ switch (_context15.prev = _context15.next) {
14302
15421
  case 0:
14303
15422
  cc = seg ? seg.cc : audioSeg.cc;
14304
15423
  discontinuity = this._prevSegCc !== cc;
14305
15424
  responses = [];
14306
- _context14.prev = 3;
14307
- _context14.next = 6;
15425
+ _context15.prev = 3;
15426
+ _context15.next = 6;
14308
15427
  return this._segmentLoader.load(seg, audioSeg, discontinuity);
14309
15428
  case 6:
14310
- responses = _context14.sent;
14311
- _context14.next = 14;
15429
+ responses = _context15.sent;
15430
+ _context15.next = 14;
14312
15431
  break;
14313
15432
  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;
15433
+ _context15.prev = 9;
15434
+ _context15.t0 = _context15["catch"](3);
15435
+ _context15.t0.fatal = false;
15436
+ this._segmentLoader.error = _context15.t0;
15437
+ throw _context15.t0;
14319
15438
  case 14:
14320
15439
  if (responses[0]) {
14321
- _context14.next = 16;
15440
+ _context15.next = 16;
14322
15441
  break;
14323
15442
  }
14324
- return _context14.abrupt("return");
15443
+ return _context15.abrupt("return");
14325
15444
  case 16:
14326
- _context14.next = 18;
15445
+ _context15.next = 18;
14327
15446
  return (_this$_bufferService2 = this._bufferService).decryptBuffer.apply(_this$_bufferService2, _toConsumableArray$2(responses));
14328
15447
  case 18:
14329
- data = _context14.sent;
15448
+ data = _context15.sent;
14330
15449
  if (data) {
14331
- _context14.next = 21;
15450
+ _context15.next = 21;
14332
15451
  break;
14333
15452
  }
14334
- return _context14.abrupt("return");
15453
+ return _context15.abrupt("return");
14335
15454
  case 21:
14336
15455
  sn = seg ? seg.sn : audioSeg.sn;
14337
15456
  start = seg ? seg.start : audioSeg.start;
@@ -14345,26 +15464,26 @@
14345
15464
  logger.warn("update the new playlist liveEdge, segment id=".concat(sn, ", buffer start=").concat(segStart, ", liveEdge=").concat(this._playlist.liveEdge));
14346
15465
  start = segStart;
14347
15466
  }
14348
- _context14.next = 30;
15467
+ _context15.next = 30;
14349
15468
  return this._bufferService.appendBuffer(seg, audioSeg, data[0], data[1], discontinuity, contiguous, start);
14350
15469
  case 30:
14351
15470
  this.emit(Event$1.APPEND_COST, {
14352
15471
  elapsed: Date.now() - before,
14353
15472
  url: seg.url
14354
15473
  });
14355
- _context14.next = 33;
15474
+ _context15.next = 33;
14356
15475
  return this._bufferService.evictBuffer(this.config.bufferBehind);
14357
15476
  case 33:
14358
15477
  this._prevSegCc = cc;
14359
15478
  this._prevSegSn = sn;
14360
- return _context14.abrupt("return", true);
15479
+ return _context15.abrupt("return", true);
14361
15480
  case 36:
14362
15481
  case "end":
14363
- return _context14.stop();
15482
+ return _context15.stop();
14364
15483
  }
14365
- }, _callee14, this, [[3, 9]]);
15484
+ }, _callee15, this, [[3, 9]]);
14366
15485
  }));
14367
- function _reqAndBufferSegment(_x10, _x11) {
15486
+ function _reqAndBufferSegment(_x9, _x10) {
14368
15487
  return _reqAndBufferSegment2.apply(this, arguments);
14369
15488
  }
14370
15489
  return _reqAndBufferSegment;
@@ -14372,11 +15491,11 @@
14372
15491
  }, {
14373
15492
  key: "_onCheckQuotaExceeded",
14374
15493
  value: function() {
14375
- var _onCheckQuotaExceeded2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee15() {
15494
+ var _onCheckQuotaExceeded2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee16() {
14376
15495
  var seekTime, buffered, inBuffered, i, bufferBehind, mediaTime;
14377
- return _regeneratorRuntime$1().wrap(function _callee15$(_context15) {
15496
+ return _regeneratorRuntime$1().wrap(function _callee16$(_context16) {
14378
15497
  while (1)
14379
- switch (_context15.prev = _context15.next) {
15498
+ switch (_context16.prev = _context16.next) {
14380
15499
  case 0:
14381
15500
  seekTime = this.media.currentTime;
14382
15501
  buffered = this.media.buffered;
@@ -14384,37 +15503,37 @@
14384
15503
  i = 0;
14385
15504
  case 4:
14386
15505
  if (!(i < buffered.length)) {
14387
- _context15.next = 11;
15506
+ _context16.next = 11;
14388
15507
  break;
14389
15508
  }
14390
15509
  if (!(buffered.start(0) >= seekTime && seekTime < buffered.end(i))) {
14391
- _context15.next = 8;
15510
+ _context16.next = 8;
14392
15511
  break;
14393
15512
  }
14394
15513
  inBuffered = true;
14395
- return _context15.abrupt("break", 11);
15514
+ return _context16.abrupt("break", 11);
14396
15515
  case 8:
14397
15516
  i++;
14398
- _context15.next = 4;
15517
+ _context16.next = 4;
14399
15518
  break;
14400
15519
  case 11:
14401
15520
  if (!this._bufferService.isFull()) {
14402
- _context15.next = 17;
15521
+ _context16.next = 17;
14403
15522
  break;
14404
15523
  }
14405
15524
  bufferBehind = inBuffered ? this.config.bufferBehind : 5;
14406
15525
  mediaTime = this.media.currentTime;
14407
15526
  if (!(mediaTime - bufferBehind > 0)) {
14408
- _context15.next = 17;
15527
+ _context16.next = 17;
14409
15528
  break;
14410
15529
  }
14411
- _context15.next = 17;
15530
+ _context16.next = 17;
14412
15531
  return this._bufferService.removeBuffer(0, mediaTime - bufferBehind);
14413
15532
  case 17:
14414
15533
  case "end":
14415
- return _context15.stop();
15534
+ return _context16.stop();
14416
15535
  }
14417
- }, _callee15, this);
15536
+ }, _callee16, this);
14418
15537
  }));
14419
15538
  function _onCheckQuotaExceeded() {
14420
15539
  return _onCheckQuotaExceeded2.apply(this, arguments);
@@ -14432,22 +15551,22 @@
14432
15551
  }, {
14433
15552
  key: "_clear",
14434
15553
  value: function() {
14435
- var _clear2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee16() {
14436
- return _regeneratorRuntime$1().wrap(function _callee16$(_context16) {
15554
+ var _clear2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee17() {
15555
+ return _regeneratorRuntime$1().wrap(function _callee17$(_context17) {
14437
15556
  while (1)
14438
- switch (_context16.prev = _context16.next) {
15557
+ switch (_context17.prev = _context17.next) {
14439
15558
  case 0:
14440
15559
  clearTimeout(this._disconnectTimer);
14441
15560
  this._stopTick();
14442
- _context16.next = 4;
15561
+ _context17.next = 4;
14443
15562
  return Promise.all([this._segmentLoader.cancel(), this._manifestLoader.stopPoll()]);
14444
15563
  case 4:
14445
15564
  this._segmentProcessing = false;
14446
15565
  case 5:
14447
15566
  case "end":
14448
- return _context16.stop();
15567
+ return _context17.stop();
14449
15568
  }
14450
- }, _callee16, this);
15569
+ }, _callee17, this);
14451
15570
  }));
14452
15571
  function _clear() {
14453
15572
  return _clear2.apply(this, arguments);
@@ -14457,14 +15576,14 @@
14457
15576
  }, {
14458
15577
  key: "_reset",
14459
15578
  value: function() {
14460
- var _reset2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee17() {
15579
+ var _reset2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee18() {
14461
15580
  var _this$_seiService3;
14462
- var reuseMse, _args17 = arguments;
14463
- return _regeneratorRuntime$1().wrap(function _callee17$(_context17) {
15581
+ var reuseMse, _args18 = arguments;
15582
+ return _regeneratorRuntime$1().wrap(function _callee18$(_context18) {
14464
15583
  while (1)
14465
- switch (_context17.prev = _context17.next) {
15584
+ switch (_context18.prev = _context18.next) {
14466
15585
  case 0:
14467
- reuseMse = _args17.length > 0 && _args17[0] !== void 0 ? _args17[0] : false;
15586
+ reuseMse = _args18.length > 0 && _args18[0] !== void 0 ? _args18[0] : false;
14468
15587
  this._reloadOnPlay = false;
14469
15588
  this._prevSegSn = null;
14470
15589
  this._prevSegCc = null;
@@ -14473,15 +15592,15 @@
14473
15592
  this._segmentLoader.reset();
14474
15593
  (_this$_seiService3 = this._seiService) === null || _this$_seiService3 === void 0 ? void 0 : _this$_seiService3.reset();
14475
15594
  this._stats.reset();
14476
- _context17.next = 11;
15595
+ _context18.next = 11;
14477
15596
  return this._clear();
14478
15597
  case 11:
14479
- return _context17.abrupt("return", this._bufferService.reset(reuseMse));
15598
+ return _context18.abrupt("return", this._bufferService.reset(reuseMse));
14480
15599
  case 12:
14481
15600
  case "end":
14482
- return _context17.stop();
15601
+ return _context18.stop();
14483
15602
  }
14484
- }, _callee17, this);
15603
+ }, _callee18, this);
14485
15604
  }));
14486
15605
  function _reset() {
14487
15606
  return _reset2.apply(this, arguments);
@@ -14562,8 +15681,8 @@
14562
15681
  value: function _tryEos() {
14563
15682
  var _this$_bufferService3, _this$_bufferService4;
14564
15683
  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);
15684
+ var _this$_playlist2 = this._playlist, nextSegment = _this$_playlist2.nextSegment, lastSegment = _this$_playlist2.lastSegment;
15685
+ 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
15686
  if (!eosAllowed) {
14568
15687
  return;
14569
15688
  }
@@ -14599,7 +15718,7 @@
14599
15718
  }]);
14600
15719
  return Hls2;
14601
15720
  }(EventEmitter);
14602
- _defineProperty$3(Hls, "version", "3.0.19-rc.0");
15721
+ _defineProperty$3(Hls, "version", "3.0.21-rc.3");
14603
15722
  try {
14604
15723
  if (localStorage.getItem("xgd")) {
14605
15724
  Hls.enableLogger();
@@ -14690,6 +15809,7 @@
14690
15809
  }]);
14691
15810
  return PluginExtension2;
14692
15811
  }();
15812
+ var _excluded = ["currentTime"];
14693
15813
  function parseSwitchUrlArgs(args, plugin) {
14694
15814
  var player = plugin.player;
14695
15815
  var curTime = player.currentTime;
@@ -14700,9 +15820,14 @@
14700
15820
  case "boolean":
14701
15821
  options.seamless = args;
14702
15822
  break;
14703
- case "object":
14704
- Object.assign(options, args);
15823
+ case "object": {
15824
+ var currentTime = args.currentTime, rest = _objectWithoutProperties$1(args, _excluded);
15825
+ Object.assign(options, rest);
15826
+ if (typeof currentTime === "number") {
15827
+ options.startTime = currentTime;
15828
+ }
14705
15829
  break;
15830
+ }
14706
15831
  }
14707
15832
  return options;
14708
15833
  }
@@ -14712,10 +15837,11 @@
14712
15837
  function HlsPlugin2() {
14713
15838
  var _this;
14714
15839
  _classCallCheck$3(this, HlsPlugin2);
14715
- for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
14716
- _args[_key] = arguments[_key];
15840
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
15841
+ args[_key] = arguments[_key];
14717
15842
  }
14718
- _this = _super.call.apply(_super, [this].concat(_args));
15843
+ _this = _super.call.apply(_super, [this].concat(args));
15844
+ _defineProperty$3(_assertThisInitialized$2(_this), "logger", logger);
14719
15845
  _defineProperty$3(_assertThisInitialized$2(_this), "hls", null);
14720
15846
  _defineProperty$3(_assertThisInitialized$2(_this), "pluginExtension", null);
14721
15847
  _defineProperty$3(_assertThisInitialized$2(_this), "getStats", function() {
@@ -14727,24 +15853,6 @@
14727
15853
  var lang = _ref.lang;
14728
15854
  (_this$hls2 = _this.hls) === null || _this$hls2 === void 0 ? void 0 : _this$hls2.switchSubtitleStream(lang);
14729
15855
  });
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
15856
  _defineProperty$3(_assertThisInitialized$2(_this), "_keepPauseStatus", function() {
14749
15857
  var paused = _this.player.paused;
14750
15858
  if (!paused)
@@ -14769,8 +15877,8 @@
14769
15877
  }, {
14770
15878
  key: "softDecode",
14771
15879
  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;
15880
+ var _this$player, _this$player$config;
15881
+ 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
15882
  return !!mediaType && mediaType !== "video" && mediaType !== "audio";
14775
15883
  }
14776
15884
  }, {
@@ -14778,13 +15886,35 @@
14778
15886
  value: function beforePlayerInit() {
14779
15887
  var _this2 = this;
14780
15888
  var config = this.player.config;
15889
+ var mediaElem = this.player.media || this.player.video;
14781
15890
  var hlsOpts = config.hls || {};
14782
15891
  if (!config.url && !config.__allowHlsEmptyUrl__ || !hlsOpts.preferMMS && MSE.isMMSOnly()) {
14783
15892
  return;
14784
15893
  }
14785
15894
  if (this.hls)
14786
15895
  this.hls.destroy();
14787
- this.player.switchURL = this._onSwitchURL;
15896
+ var descriptor = Object.getOwnPropertyDescriptor(this.player, "switchURL");
15897
+ if (!descriptor || descriptor.writable) {
15898
+ this.player.switchURL = function(url, args) {
15899
+ return new Promise(function(resolve, reject) {
15900
+ var player = _this2.player, hls = _this2.hls;
15901
+ if (hls) {
15902
+ var _this2$player$config, _this2$player$config$;
15903
+ var options = parseSwitchUrlArgs(args, _this2);
15904
+ player.config.url = url;
15905
+ hls.switchURL(url, options).then(function() {
15906
+ return resolve(true);
15907
+ }).catch(reject);
15908
+ 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) {
15909
+ _this2._keepPauseStatus();
15910
+ }
15911
+ } else {
15912
+ reject();
15913
+ }
15914
+ });
15915
+ };
15916
+ }
15917
+ var onSwitchUrl = this.player.switchURL;
14788
15918
  this.player.handleSource = false;
14789
15919
  hlsOpts.innerDegrade = hlsOpts.innerDegrade || config.innerDegrade;
14790
15920
  if (hlsOpts.disconnectTime === null || hlsOpts.disconnectTime === void 0)
@@ -14792,7 +15922,7 @@
14792
15922
  this.hls = new Hls(_objectSpread2$2({
14793
15923
  softDecode: this.softDecode,
14794
15924
  isLive: config.isLive,
14795
- media: this.player.media || this.player.video,
15925
+ media: mediaElem,
14796
15926
  startTime: config.startTime,
14797
15927
  url: config.url
14798
15928
  }, hlsOpts));
@@ -14810,7 +15940,7 @@
14810
15940
  if (this.softDecode) {
14811
15941
  this.pluginExtension = new PluginExtension(_objectSpread2$2({
14812
15942
  isLive: config.isLive,
14813
- media: this.player.video
15943
+ media: mediaElem
14814
15944
  }, hlsOpts), this);
14815
15945
  this.player.forceDegradeToVideo = function() {
14816
15946
  var _this2$pluginExtensio;
@@ -14827,8 +15957,8 @@
14827
15957
  return (_this2$hls2 = _this2.hls) === null || _this2$hls2 === void 0 ? void 0 : _this2$hls2.replay();
14828
15958
  });
14829
15959
  }
15960
+ this.on(URL_CHANGE, onSwitchUrl);
14830
15961
  this.on(SWITCH_SUBTITLE, this._onSwitchSubtitle);
14831
- this.on(URL_CHANGE, this._onSwitchURL);
14832
15962
  this.on(DESTROY, this.destroy.bind(this));
14833
15963
  this._transError();
14834
15964
  this._transCoreEvent(EVENT.TTFB);
@@ -14838,6 +15968,7 @@
14838
15968
  this._transCoreEvent(EVENT.LOAD_RETRY);
14839
15969
  this._transCoreEvent(EVENT.SOURCEBUFFER_CREATED);
14840
15970
  this._transCoreEvent(EVENT.MEDIASOURCE_OPENED);
15971
+ this._transCoreEvent(EVENT.APPEND_BUFFER);
14841
15972
  this._transCoreEvent(EVENT.REMOVE_BUFFER);
14842
15973
  this._transCoreEvent(EVENT.BUFFEREOS);
14843
15974
  this._transCoreEvent(EVENT.KEYFRAME);
@@ -14857,7 +15988,9 @@
14857
15988
  this._transCoreEvent(Event$1.SUBTITLE_PLAYLIST);
14858
15989
  this._transCoreEvent(Event$1.APPEND_COST);
14859
15990
  if (config.url) {
14860
- this.hls.load(config.url, true).catch(function(e) {
15991
+ this.hls.load(config.url, {
15992
+ reuseMse: true
15993
+ }).catch(function(e) {
14861
15994
  });
14862
15995
  }
14863
15996
  }