@volcengine/veplayer-plugin 2.4.2-rc.1 → 2.4.3-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 (31) hide show
  1. package/esm/index.development.js +1968 -659
  2. package/esm/index.production.js +1 -1
  3. package/esm/veplayer.plugin.abr.development.js +71 -3
  4. package/esm/veplayer.plugin.abr.production.js +1 -1
  5. package/esm/veplayer.plugin.drm.development.js +71 -3
  6. package/esm/veplayer.plugin.drm.production.js +1 -1
  7. package/esm/veplayer.plugin.flv.development.js +727 -196
  8. package/esm/veplayer.plugin.flv.production.js +1 -1
  9. package/esm/veplayer.plugin.hls.development.js +1237 -308
  10. package/esm/veplayer.plugin.hls.production.js +1 -1
  11. package/esm/veplayer.plugin.mp4.development.js +73 -5
  12. package/esm/veplayer.plugin.mp4.production.js +1 -1
  13. package/esm/veplayer.plugin.rtm.development.js +124 -139
  14. package/esm/veplayer.plugin.rtm.production.js +1 -1
  15. package/esm/veplayer.plugin.shaka.development.js +72 -4
  16. package/esm/veplayer.plugin.shaka.production.js +1 -1
  17. package/package.json +1 -1
  18. package/umd/veplayer.plugin.abr.development.js +71 -3
  19. package/umd/veplayer.plugin.abr.production.js +1 -1
  20. package/umd/veplayer.plugin.drm.development.js +71 -3
  21. package/umd/veplayer.plugin.drm.production.js +1 -1
  22. package/umd/veplayer.plugin.flv.development.js +727 -196
  23. package/umd/veplayer.plugin.flv.production.js +1 -1
  24. package/umd/veplayer.plugin.hls.development.js +1237 -308
  25. package/umd/veplayer.plugin.hls.production.js +1 -1
  26. package/umd/veplayer.plugin.mp4.development.js +73 -5
  27. package/umd/veplayer.plugin.mp4.production.js +1 -1
  28. package/umd/veplayer.plugin.rtm.development.js +124 -139
  29. package/umd/veplayer.plugin.rtm.production.js +1 -1
  30. package/umd/veplayer.plugin.shaka.development.js +72 -4
  31. package/umd/veplayer.plugin.shaka.production.js +1 -1
@@ -342,13 +342,13 @@ function _regeneratorRuntime$a() {
342
342
  }
343
343
  }, exports;
344
344
  }
345
- function _typeof$b(obj) {
345
+ function _typeof$a(obj) {
346
346
  "@babel/helpers - typeof";
347
- return _typeof$b = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
347
+ return _typeof$a = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
348
348
  return typeof obj2;
349
349
  } : function(obj2) {
350
350
  return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
351
- }, _typeof$b(obj);
351
+ }, _typeof$a(obj);
352
352
  }
353
353
  function asyncGeneratorStep$a(gen, resolve3, reject3, _next, _throw, key2, arg) {
354
354
  try {
@@ -527,13 +527,13 @@ function _objectSpread2$9(target) {
527
527
  }
528
528
  return target;
529
529
  }
530
- function _typeof$a(obj) {
530
+ function _typeof$9(obj) {
531
531
  "@babel/helpers - typeof";
532
- return _typeof$a = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
532
+ return _typeof$9 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
533
533
  return typeof obj2;
534
534
  } : function(obj2) {
535
535
  return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
536
- }, _typeof$a(obj);
536
+ }, _typeof$9(obj);
537
537
  }
538
538
  function _classCallCheck$i(instance, Constructor2) {
539
539
  if (!(instance instanceof Constructor2)) {
@@ -922,7 +922,7 @@ util$2.hasClass = function(el, className) {
922
922
  return item === className;
923
923
  });
924
924
  } catch (e) {
925
- var orgClassName = el.className && _typeof$a(el.className) === "object" ? el.getAttribute("class") : el.className;
925
+ var orgClassName = el.className && _typeof$9(el.className) === "object" ? el.getAttribute("class") : el.className;
926
926
  return orgClassName && !!orgClassName.match(new RegExp("(\\s|^)" + className + "(\\s|$)"));
927
927
  }
928
928
  };
@@ -936,7 +936,7 @@ util$2.addClass = function(el, className) {
936
936
  });
937
937
  } catch (e) {
938
938
  if (!util$2.hasClass(el, className)) {
939
- if (el.className && _typeof$a(el.className) === "object") {
939
+ if (el.className && _typeof$9(el.className) === "object") {
940
940
  el.setAttribute("class", el.getAttribute("class") + " " + className);
941
941
  } else {
942
942
  el.className += " " + className;
@@ -956,7 +956,7 @@ util$2.removeClass = function(el, className) {
956
956
  if (util$2.hasClass(el, className)) {
957
957
  className.split(/\s+/g).forEach(function(item) {
958
958
  var reg = new RegExp("(\\s|^)" + item + "(\\s|$)");
959
- if (el.className && _typeof$a(el.className) === "object") {
959
+ if (el.className && _typeof$9(el.className) === "object") {
960
960
  el.setAttribute("class", el.getAttribute("class").replace(reg, " "));
961
961
  } else {
962
962
  el.className = el.className.replace(reg, " ");
@@ -1197,7 +1197,7 @@ util$2.checkIsFunction = function(fun) {
1197
1197
  return fun && typeof fun === "function";
1198
1198
  };
1199
1199
  util$2.checkIsObject = function(obj) {
1200
- return obj !== null && _typeof$a(obj) === "object";
1200
+ return obj !== null && _typeof$9(obj) === "object";
1201
1201
  };
1202
1202
  util$2.hide = function(dom) {
1203
1203
  dom.style.display = "none";
@@ -1550,7 +1550,7 @@ var VERSION_REG = {
1550
1550
  android: /(Android)\s([\d.]+)/,
1551
1551
  ios: /(Version)\/([\d.]+)/
1552
1552
  };
1553
- var H264_MIMETYPES = ["avc1.42E01E, mp4a.40.2", "avc1.58A01E, mp4a.40.2", "avc1.4D401E, mp4a.40.2", "avc1.64001E, mp4a.40.2", "avc1.42E01E", "mp4v.20.8", "avc1.42E01E, mp4a.40.2", "avc1.58A01E, mp4a.40.2", "avc1.4D401E, mp4a.40.2", "avc1.64001E, mp4a.40.2", "mp4v.20.8, mp4a.40.2", "mp4v.20.240, mp4a.40.2"];
1553
+ var H264_MIMETYPES = ["avc1.42E01E, mp4a.40.2", "avc1.58A01E, mp4a.40.2", "avc1.4D401E, mp4a.40.2", "avc1.64001E, mp4a.40.2", "avc1.42E01E", "mp4v.20.8", "mp4v.20.8, mp4a.40.2", "mp4v.20.240, mp4a.40.2"];
1554
1554
  var sniffer = {
1555
1555
  get device() {
1556
1556
  var r = sniffer.os;
@@ -1695,7 +1695,7 @@ var sniffer = {
1695
1695
  }
1696
1696
  }
1697
1697
  };
1698
- var version$3 = "3.0.19-rc.0";
1698
+ var version$3 = "3.0.20-rc.6";
1699
1699
  var ERROR_MAP = {
1700
1700
  1: 5101,
1701
1701
  2: 5102,
@@ -1759,8 +1759,6 @@ var Errors = /* @__PURE__ */ _createClass$i(
1759
1759
  }
1760
1760
  }
1761
1761
  );
1762
- var PLAY = "play";
1763
- var PAUSE = "pause";
1764
1762
  var ERROR = "error";
1765
1763
  var TIME_UPDATE = "timeupdate";
1766
1764
  var WAITING = "waiting";
@@ -1812,8 +1810,7 @@ function hook(hookName, handler) {
1812
1810
  }
1813
1811
  if (this.__hooks && this.__hooks[hookName]) {
1814
1812
  try {
1815
- var _this$__hooks$hookNam;
1816
- var preRet = (_this$__hooks$hookNam = this.__hooks[hookName]).call.apply(_this$__hooks$hookNam, [this, this].concat(Array.prototype.slice.call(arguments)));
1813
+ var preRet = runHooks(this, hookName, handler);
1817
1814
  if (preRet) {
1818
1815
  if (preRet.then) {
1819
1816
  preRet.then(function(isContinue) {
@@ -1838,6 +1835,19 @@ function hook(hookName, handler) {
1838
1835
  }
1839
1836
  }.bind(this);
1840
1837
  }
1838
+ function findHookIndex(hookName, handler) {
1839
+ var __hooks = this.__hooks;
1840
+ if (!__hooks || !Array.isArray(__hooks[hookName])) {
1841
+ return -1;
1842
+ }
1843
+ var hookHandlers = __hooks[hookName];
1844
+ for (var i = 0; i < hookHandlers.length; i++) {
1845
+ if (hookHandlers[i] === handler) {
1846
+ return i;
1847
+ }
1848
+ }
1849
+ return -1;
1850
+ }
1841
1851
  function useHooks(hookName, handler) {
1842
1852
  var __hooks = this.__hooks;
1843
1853
  if (!__hooks) {
@@ -1847,7 +1857,12 @@ function useHooks(hookName, handler) {
1847
1857
  console.warn("has no supported hook which name [".concat(hookName, "]"));
1848
1858
  return false;
1849
1859
  }
1850
- __hooks && (__hooks[hookName] = handler);
1860
+ if (!Array.isArray(__hooks[hookName])) {
1861
+ __hooks[hookName] = [];
1862
+ }
1863
+ if (findHookIndex.call(this, hookName, handler) === -1) {
1864
+ __hooks[hookName].push(handler);
1865
+ }
1851
1866
  return true;
1852
1867
  }
1853
1868
  function removeHooks(hookName, handler) {
@@ -1855,6 +1870,13 @@ function removeHooks(hookName, handler) {
1855
1870
  if (!__hooks) {
1856
1871
  return;
1857
1872
  }
1873
+ if (Array.isArray(__hooks[hookName])) {
1874
+ var hooks = __hooks[hookName];
1875
+ var index2 = findHookIndex.call(this, hookName, handler);
1876
+ if (index2 !== -1) {
1877
+ hooks.splice(index2, 1);
1878
+ }
1879
+ }
1858
1880
  delete __hooks[hookName];
1859
1881
  }
1860
1882
  function hooksDescriptor(instance) {
@@ -1876,6 +1898,38 @@ function hooksDescriptor(instance) {
1876
1898
  function delHooksDescriptor(instance) {
1877
1899
  instance.__hooks = null;
1878
1900
  }
1901
+ function runHooks(obj, hookName, handler) {
1902
+ for (var _len5 = arguments.length, args = new Array(_len5 > 3 ? _len5 - 3 : 0), _key5 = 3; _key5 < _len5; _key5++) {
1903
+ args[_key5 - 3] = arguments[_key5];
1904
+ }
1905
+ if (obj.__hooks && Array.isArray(obj.__hooks[hookName])) {
1906
+ var hooks = obj.__hooks[hookName];
1907
+ var index2 = -1;
1908
+ var runHooksRecursive = function runHooksRecursive2(obj2, hookName2, handler2) {
1909
+ for (var _len6 = arguments.length, args2 = new Array(_len6 > 3 ? _len6 - 3 : 0), _key6 = 3; _key6 < _len6; _key6++) {
1910
+ args2[_key6 - 3] = arguments[_key6];
1911
+ }
1912
+ index2++;
1913
+ if (hooks.length === 0 || index2 === hooks.length) {
1914
+ return handler2.call.apply(handler2, [obj2, obj2].concat(args2));
1915
+ }
1916
+ var hook2 = hooks[index2];
1917
+ var ret = hook2.call.apply(hook2, [obj2, obj2].concat(args2));
1918
+ if (ret && ret.then) {
1919
+ return ret.then(function(data2) {
1920
+ return data2 === false ? null : runHooksRecursive2.apply(void 0, [obj2, hookName2, handler2].concat(args2));
1921
+ }).catch(function(e) {
1922
+ console.warn("[runHooks]".concat(hookName2, " reject"), e.message);
1923
+ });
1924
+ } else if (ret !== false) {
1925
+ return runHooksRecursive2.apply(void 0, [obj2, hookName2, handler2].concat(args2));
1926
+ }
1927
+ };
1928
+ return runHooksRecursive.apply(void 0, [obj, hookName, handler].concat(args));
1929
+ } else {
1930
+ return handler.call.apply(handler, [obj, obj].concat(args));
1931
+ }
1932
+ }
1879
1933
  function showErrorMsg(pluginName, msg) {
1880
1934
  XG_DEBUG.logError("[".concat(pluginName, "] event or callback cant be undefined or null when call ").concat(msg));
1881
1935
  }
@@ -2115,6 +2169,18 @@ var BasePlugin = /* @__PURE__ */ function() {
2115
2169
  }
2116
2170
  }
2117
2171
  }
2172
+ }, {
2173
+ key: "defineMethod",
2174
+ value: function defineMethod(Obj, map6) {
2175
+ for (var key2 in map6) {
2176
+ if (Object.prototype.hasOwnProperty.call(map6, key2) && typeof map6[key2] === "function") {
2177
+ Object.defineProperty(Obj, key2, {
2178
+ configurable: true,
2179
+ value: map6[key2]
2180
+ });
2181
+ }
2182
+ }
2183
+ }
2118
2184
  }, {
2119
2185
  key: "defaultConfig",
2120
2186
  get: function get3() {
@@ -2465,13 +2531,13 @@ function _regeneratorRuntime$9() {
2465
2531
  }
2466
2532
  }, exports;
2467
2533
  }
2468
- function _typeof$9(obj) {
2534
+ function _typeof$8(obj) {
2469
2535
  "@babel/helpers - typeof";
2470
- return _typeof$9 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
2536
+ return _typeof$8 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
2471
2537
  return typeof obj2;
2472
2538
  } : function(obj2) {
2473
2539
  return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
2474
- }, _typeof$9(obj);
2540
+ }, _typeof$8(obj);
2475
2541
  }
2476
2542
  function asyncGeneratorStep$9(gen, resolve3, reject3, _next, _throw, key2, arg) {
2477
2543
  try {
@@ -2737,7 +2803,7 @@ function _arrayLikeToArray$c(arr, len) {
2737
2803
  arr2[i] = arr[i];
2738
2804
  return arr2;
2739
2805
  }
2740
- function _createForOfIteratorHelper$3(o, allowArrayLike) {
2806
+ function _createForOfIteratorHelper$4(o, allowArrayLike) {
2741
2807
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
2742
2808
  if (!it) {
2743
2809
  if (Array.isArray(o) || (it = _unsupportedIterableToArray$c(o)) || allowArrayLike && o && typeof o.length === "number") {
@@ -2925,6 +2991,21 @@ var Buffer$6 = /* @__PURE__ */ function() {
2925
2991
  length: Buffer22.totalLength && Buffer22.totalLength(buffers)
2926
2992
  };
2927
2993
  }
2994
+ }, {
2995
+ key: "isBuffered",
2996
+ value: function isBuffered(media, pos) {
2997
+ if (media) {
2998
+ var buffered = Buffer22.get(media);
2999
+ if (buffered !== null && buffered !== void 0 && buffered.length) {
3000
+ for (var i = 0; i < buffered.length; i++) {
3001
+ if (pos >= buffered.start(i) && pos <= buffered.end(i)) {
3002
+ return true;
3003
+ }
3004
+ }
3005
+ }
3006
+ }
3007
+ return false;
3008
+ }
2928
3009
  }]);
2929
3010
  return Buffer22;
2930
3011
  }();
@@ -3077,7 +3158,7 @@ var Logger$a = /* @__PURE__ */ function() {
3077
3158
  this.logCache.apply(this, [LogCacheLevel$2.DEBUG].concat(args));
3078
3159
  if (Logger2.disabled)
3079
3160
  return;
3080
- (_console = console).debug.apply(_console, [this._prefix, nowTime$7()].concat(args));
3161
+ (_console = console).debug.apply(_console, ["[".concat(nowTime$7(), "]"), this._prefix].concat(args));
3081
3162
  }
3082
3163
  }, {
3083
3164
  key: "log",
@@ -3089,7 +3170,7 @@ var Logger$a = /* @__PURE__ */ function() {
3089
3170
  this.logCache.apply(this, [LogCacheLevel$2.LOG].concat(args));
3090
3171
  if (Logger2.disabled)
3091
3172
  return;
3092
- (_console2 = console).log.apply(_console2, [this._prefix, nowTime$7()].concat(args));
3173
+ (_console2 = console).log.apply(_console2, ["[".concat(nowTime$7(), "]"), this._prefix].concat(args));
3093
3174
  }
3094
3175
  }, {
3095
3176
  key: "warn",
@@ -3101,7 +3182,7 @@ var Logger$a = /* @__PURE__ */ function() {
3101
3182
  this.logCache.apply(this, [LogCacheLevel$2.WARN].concat(args));
3102
3183
  if (Logger2.disabled)
3103
3184
  return;
3104
- (_console3 = console).warn.apply(_console3, [this._prefix, nowTime$7()].concat(args));
3185
+ (_console3 = console).warn.apply(_console3, ["[".concat(nowTime$7(), "]"), this._prefix].concat(args));
3105
3186
  }
3106
3187
  }, {
3107
3188
  key: "error",
@@ -3113,7 +3194,7 @@ var Logger$a = /* @__PURE__ */ function() {
3113
3194
  this.logCache.apply(this, [LogCacheLevel$2.ERROR].concat(args));
3114
3195
  if (Logger2.disabled)
3115
3196
  return;
3116
- (_console4 = console).error.apply(_console4, [this._prefix, nowTime$7()].concat(args));
3197
+ (_console4 = console).error.apply(_console4, ["[".concat(nowTime$7(), "]"), this._prefix].concat(args));
3117
3198
  }
3118
3199
  }, {
3119
3200
  key: "logCache",
@@ -3128,7 +3209,7 @@ var Logger$a = /* @__PURE__ */ function() {
3128
3209
  var finLogText = logText.map(function(item) {
3129
3210
  return logable$2(item);
3130
3211
  });
3131
- text = this._prefix + nowTime$7() + JSON.stringify(finLogText);
3212
+ text = "[".concat(nowTime$7(), "]") + this._prefix + JSON.stringify(finLogText);
3132
3213
  } catch (e) {
3133
3214
  return;
3134
3215
  }
@@ -3187,7 +3268,7 @@ function nowTime$7() {
3187
3268
  return (/* @__PURE__ */ new Date()).toLocaleString();
3188
3269
  }
3189
3270
  function reduceDepth$2(val) {
3190
- if (_typeof$9(val) !== "object") {
3271
+ if (_typeof$8(val) !== "object") {
3191
3272
  return val;
3192
3273
  }
3193
3274
  var objType = Object.prototype.toString.call(val).slice(8, -1);
@@ -3208,7 +3289,7 @@ function logable$2(obj, maxDepth, depth) {
3208
3289
  if (!maxDepth)
3209
3290
  maxDepth = 2;
3210
3291
  var result = {};
3211
- if (!obj || _typeof$9(obj) !== "object") {
3292
+ if (!obj || _typeof$8(obj) !== "object") {
3212
3293
  return obj;
3213
3294
  }
3214
3295
  var objType = Object.prototype.toString.call(obj).slice(8, -1);
@@ -3222,7 +3303,7 @@ function logable$2(obj, maxDepth, depth) {
3222
3303
  if (Object.prototype.hasOwnProperty.call(obj, key2)) {
3223
3304
  if (depth === maxDepth) {
3224
3305
  result[key2] = reduceDepth$2(obj[key2]);
3225
- } else if (_typeof$9(obj[key2]) === "object") {
3306
+ } else if (_typeof$8(obj[key2]) === "object") {
3226
3307
  result[key2] = logable$2(obj[key2], maxDepth, depth + 1);
3227
3308
  } else {
3228
3309
  result[key2] = obj[key2];
@@ -3862,7 +3943,7 @@ var MSE$3 = /* @__PURE__ */ function() {
3862
3943
  } catch (error) {
3863
3944
  if (error && error.message && error.message.indexOf("SourceBuffer is full") >= 0) {
3864
3945
  this._mseFullFlag[type] = true;
3865
- if (op.context && _typeof$9(op.context) === "object") {
3946
+ if (op.context && _typeof$8(op.context) === "object") {
3866
3947
  op.context.isFull = true;
3867
3948
  }
3868
3949
  this._logger.error("[MSE error], context,", op.context, " ,name,", op.opName, ",err,SourceBuffer is full");
@@ -3964,7 +4045,7 @@ var NetError$3 = /* @__PURE__ */ function(_Error) {
3964
4045
  }(/* @__PURE__ */ _wrapNativeSuper$4(Error));
3965
4046
  var toString$z = Object.prototype.toString;
3966
4047
  function isObject$N(a) {
3967
- return a !== null && _typeof$9(a) === "object";
4048
+ return a !== null && _typeof$8(a) === "object";
3968
4049
  }
3969
4050
  function isPlainObject$3(val) {
3970
4051
  if (toString$z.call(val) !== "[object Object]") {
@@ -4044,8 +4125,8 @@ function createResponse$3(data2, done, response, contentLength, age, startTime,
4044
4125
  response
4045
4126
  };
4046
4127
  }
4047
- function calculateSpeed$3(byteLen, millisec) {
4048
- return Math.round(byteLen * 8 * 1e3 / millisec / 1024);
4128
+ function calculateSpeed$3(byteLen, milliSecond) {
4129
+ return Math.round(byteLen * 8 * 1e3 / milliSecond / 1024);
4049
4130
  }
4050
4131
  var EVENT$3 = {
4051
4132
  ERROR: "error",
@@ -4057,6 +4138,7 @@ var EVENT$3 = {
4057
4138
  SOURCEBUFFER_CREATED: "core.sourcebuffercreated",
4058
4139
  MEDIASOURCE_OPENED: "core.mediasourceopened",
4059
4140
  ANALYZE_DURATION_EXCEEDED: "core.analyzedurationexceeded",
4141
+ APPEND_BUFFER: "core.appendbuffer",
4060
4142
  REMOVE_BUFFER: "core.removebuffer",
4061
4143
  BUFFEREOS: "core.buffereos",
4062
4144
  KEYFRAME: "core.keyframe",
@@ -4829,7 +4911,7 @@ var XhrLoader$3 = /* @__PURE__ */ function(_EventEmitter) {
4829
4911
  value: function _getHeaders(xhr) {
4830
4912
  var headerLines = xhr.getAllResponseHeaders().trim().split("\r\n");
4831
4913
  var headers = {};
4832
- var _iterator = _createForOfIteratorHelper$3(headerLines), _step;
4914
+ var _iterator = _createForOfIteratorHelper$4(headerLines), _step;
4833
4915
  try {
4834
4916
  for (_iterator.s(); !(_step = _iterator.n()).done; ) {
4835
4917
  var header = _step.value;
@@ -4851,7 +4933,7 @@ var XhrLoader$3 = /* @__PURE__ */ function(_EventEmitter) {
4851
4933
  }]);
4852
4934
  return XhrLoader2;
4853
4935
  }(EventEmitter$1);
4854
- var _excluded$5 = ["retry", "retryDelay", "onRetryError", "transformError"];
4936
+ var _excluded$6 = ["retry", "retryDelay", "onRetryError", "transformError"];
4855
4937
  var Task$3 = /* @__PURE__ */ function() {
4856
4938
  function Task2(type, config) {
4857
4939
  _classCallCheck$h(this, Task2);
@@ -4871,7 +4953,7 @@ var Task$3 = /* @__PURE__ */ function() {
4871
4953
  key: "exec",
4872
4954
  value: function exec2() {
4873
4955
  var _this = this;
4874
- var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties$5(_this$_config, _excluded$5);
4956
+ var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties$5(_this$_config, _excluded$6);
4875
4957
  var request = /* @__PURE__ */ function() {
4876
4958
  var _ref = _asyncToGenerator$9(/* @__PURE__ */ _regeneratorRuntime$9().mark(function _callee() {
4877
4959
  var response, error, isRetry;
@@ -5689,13 +5771,15 @@ var TrackType$3 = {
5689
5771
  METADATA: "metadata"
5690
5772
  };
5691
5773
  var VideoCodecType$3 = {
5774
+ AV1: "av1",
5692
5775
  AVC: "avc",
5693
5776
  HEVC: "hevc"
5694
5777
  };
5695
5778
  var AudioCodecType$2 = {
5696
5779
  AAC: "aac",
5697
5780
  G711PCMA: "g7110a",
5698
- G711PCMU: "g7110m"
5781
+ G711PCMU: "g7110m",
5782
+ OPUS: "opus"
5699
5783
  };
5700
5784
  var WarningType$1 = {
5701
5785
  LARGE_AV_SHIFT: "LARGE_AV_SHIFT",
@@ -5735,6 +5819,7 @@ var VideoTrack$2 = /* @__PURE__ */ function() {
5735
5819
  _defineProperty$e(this, "isVideoEncryption", false);
5736
5820
  _defineProperty$e(this, "isAudioEncryption", false);
5737
5821
  _defineProperty$e(this, "isVideo", true);
5822
+ _defineProperty$e(this, "lastKeyFrameDts", 0);
5738
5823
  _defineProperty$e(this, "kid", null);
5739
5824
  _defineProperty$e(this, "pssh", null);
5740
5825
  _defineProperty$e(this, "ext", void 0);
@@ -5777,6 +5862,9 @@ var VideoTrack$2 = /* @__PURE__ */ function() {
5777
5862
  }, {
5778
5863
  key: "exist",
5779
5864
  value: function exist() {
5865
+ if (/av01/.test(this.codec)) {
5866
+ return true;
5867
+ }
5780
5868
  return !!(this.pps.length && this.sps.length && this.codec);
5781
5869
  }
5782
5870
  }, {
@@ -5840,7 +5928,7 @@ var AudioTrack$2 = /* @__PURE__ */ function() {
5840
5928
  }, {
5841
5929
  key: "exist",
5842
5930
  value: function exist() {
5843
- return !!(this.sampleRate && this.channelCount && this.codec && this.codecType === AudioCodecType$2.AAC);
5931
+ return !!(this.sampleRate && this.channelCount && this.codec && (this.codecType === AudioCodecType$2.AAC || this.codecType === AudioCodecType$2.G711PCMA || this.codecType === AudioCodecType$2.G711PCMU || this.codecType === AudioCodecType$2.OPUS));
5844
5932
  }
5845
5933
  }, {
5846
5934
  key: "hasSample",
@@ -6054,7 +6142,7 @@ var AAC$2 = /* @__PURE__ */ function() {
6054
6142
  continue;
6055
6143
  }
6056
6144
  frameLength = (data2[i + 3] & 3) << 11 | data2[i + 4] << 3 | (data2[i + 5] & 224) >> 5;
6057
- if (len - i < frameLength)
6145
+ if (!frameLength || len - i < frameLength)
6058
6146
  break;
6059
6147
  protectionSkipBytes = (~data2[i + 1] & 1) * 2;
6060
6148
  frames.push({
@@ -6188,14 +6276,57 @@ var AAC$2 = /* @__PURE__ */ function() {
6188
6276
  return AAC2;
6189
6277
  }();
6190
6278
  _defineProperty$e(AAC$2, "FREQ", [96e3, 88200, 64e3, 48e3, 44100, 32e3, 24e3, 22050, 16e3, 12e3, 11025, 8e3, 7350]);
6279
+ var OPUS = /* @__PURE__ */ function() {
6280
+ function OPUS2() {
6281
+ _classCallCheck$g(this, OPUS2);
6282
+ }
6283
+ _createClass$g(OPUS2, null, [{
6284
+ key: "getFrameDuration",
6285
+ value: function getFrameDuration(samples) {
6286
+ return 20;
6287
+ }
6288
+ }, {
6289
+ key: "parseHeaderPackets",
6290
+ value: function parseHeaderPackets(data2) {
6291
+ if (!data2.length)
6292
+ return;
6293
+ var dv = new DataView(data2.buffer, data2.byteOffset, data2.byteLength);
6294
+ var magicSignature = "";
6295
+ for (var i = 0; i < 8; i++) {
6296
+ magicSignature += String.fromCodePoint(data2[i]);
6297
+ }
6298
+ if (magicSignature !== "OpusHead") {
6299
+ throw new Error("Invalid Opus MagicSignature");
6300
+ }
6301
+ var channelCount = data2[9];
6302
+ console.log("Pre-skip", data2[10], data2[11]);
6303
+ var sampleRate = dv.getUint32(12, true);
6304
+ var outputGain = dv.getInt16(16, true);
6305
+ if (!sampleRate)
6306
+ return;
6307
+ var codec = "opus";
6308
+ var originCodec = "opus";
6309
+ var config = new Uint8Array(data2.buffer, data2.byteOffset + 8, data2.byteLength - 8);
6310
+ return {
6311
+ outputGain,
6312
+ sampleRate,
6313
+ channelCount,
6314
+ config,
6315
+ codec,
6316
+ originCodec
6317
+ };
6318
+ }
6319
+ }]);
6320
+ return OPUS2;
6321
+ }();
6191
6322
  var LARGE_AV_FIRST_FRAME_GAP$1 = 500;
6192
6323
  var AUDIO_GAP_OVERLAP_THRESHOLD_COUNT$1 = 3;
6193
6324
  var MAX_SILENT_FRAME_DURATION$1 = 1e3;
6194
- var AUDIO_EXCETION_LOG_EMIT_DURATION$1 = 5e3;
6325
+ var AUDIO_EXCEPTION_LOG_EMIT_DURATION = 5e3;
6195
6326
  var MAX_VIDEO_FRAME_DURATION$1 = 1e3;
6196
6327
  var MAX_DTS_DELTA_WITH_NEXT_CHUNK$1 = 200;
6197
- var VIDEO_EXCETION_LOG_EMIT_DURATION = 5e3;
6198
- var TRACK_BREACKED_CHECK_TIME = 5;
6328
+ var VIDEO_EXCEPTION_LOG_EMIT_DURATION = 5e3;
6329
+ var TRACK_BROKEN_CHECK_TIME = 5;
6199
6330
  var FlvFixer = /* @__PURE__ */ function() {
6200
6331
  function FlvFixer2(videoTrack, audioTrack, metadataTrack) {
6201
6332
  _classCallCheck$g(this, FlvFixer2);
@@ -6311,7 +6442,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6311
6442
  var firstSample = samples[0];
6312
6443
  var vDelta = this._videoNextDts - firstSample.dts;
6313
6444
  if (Math.abs(vDelta) > MAX_DTS_DELTA_WITH_NEXT_CHUNK$1) {
6314
- if (Math.abs(firstSample.dts - this._lastVideoExceptionChunkFirstDtsDot) > VIDEO_EXCETION_LOG_EMIT_DURATION) {
6445
+ if (Math.abs(firstSample.dts - this._lastVideoExceptionChunkFirstDtsDot) > VIDEO_EXCEPTION_LOG_EMIT_DURATION) {
6315
6446
  var _samples$;
6316
6447
  this._lastVideoExceptionChunkFirstDtsDot = firstSample.dts;
6317
6448
  videoTrack.warnings.push({
@@ -6322,7 +6453,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6322
6453
  sampleDuration: vDelta
6323
6454
  });
6324
6455
  }
6325
- if (this._videoTimestampBreak >= TRACK_BREACKED_CHECK_TIME) {
6456
+ if (this._videoTimestampBreak >= TRACK_BROKEN_CHECK_TIME) {
6326
6457
  this._videoNextDts = firstSample.dts;
6327
6458
  this._videoTimestampBreak = 0;
6328
6459
  } else {
@@ -6345,7 +6476,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6345
6476
  }
6346
6477
  if (sampleDuration > MAX_VIDEO_FRAME_DURATION$1 || sampleDuration < 0) {
6347
6478
  this._videoTimestampBreak++;
6348
- if (Math.abs(dts - this._lastVideoExceptionLargeGapDot) > VIDEO_EXCETION_LOG_EMIT_DURATION) {
6479
+ if (Math.abs(dts - this._lastVideoExceptionLargeGapDot) > VIDEO_EXCEPTION_LOG_EMIT_DURATION) {
6349
6480
  this._lastVideoExceptionLargeGapDot = dts;
6350
6481
  videoTrack.warnings.push({
6351
6482
  type: WarningType$1.LARGE_VIDEO_GAP,
@@ -6426,10 +6557,27 @@ var FlvFixer = /* @__PURE__ */ function() {
6426
6557
  key: "_doFixAudioInternal",
6427
6558
  value: function _doFixAudioInternal(audioTrack, samples, timescale) {
6428
6559
  if (!audioTrack.sampleDuration) {
6429
- audioTrack.sampleDuration = audioTrack.codecType === AudioCodecType$2.AAC ? AAC$2.getFrameDuration(audioTrack.timescale, timescale) : this._getG711Duration(audioTrack);
6560
+ switch (audioTrack.codecType) {
6561
+ case AudioCodecType$2.AAC: {
6562
+ audioTrack.sampleDuration = AAC$2.getFrameDuration(audioTrack.timescale, timescale);
6563
+ break;
6564
+ }
6565
+ case AudioCodecType$2.OPUS: {
6566
+ audioTrack.sampleDuration = OPUS.getFrameDuration(audioTrack.samples, timescale);
6567
+ break;
6568
+ }
6569
+ case AudioCodecType$2.G711PCMA:
6570
+ case AudioCodecType$2.G711PCMU: {
6571
+ audioTrack.sampleDuration = this._getG711Duration(audioTrack);
6572
+ break;
6573
+ }
6574
+ default:
6575
+ console.error("can't fix audio codecType:", audioTrack.codecType);
6576
+ break;
6577
+ }
6430
6578
  }
6431
6579
  var refSampleDuration = audioTrack.sampleDuration;
6432
- var sampleDurationInSampleRate = audioTrack.codecType === AudioCodecType$2.AAC ? 1024 : refSampleDuration * audioTrack.timescale / 1e3;
6580
+ var sampleDurationInSampleRate = audioTrack.codecType === AudioCodecType$2.OPUS ? 20 : audioTrack.codecType === AudioCodecType$2.AAC ? 1024 : refSampleDuration * audioTrack.timescale / 1e3;
6433
6581
  if (this._audioNextPts === void 0) {
6434
6582
  var samp0 = samples[0];
6435
6583
  this._audioNextPts = samp0.pts;
@@ -6438,7 +6586,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6438
6586
  var nextPts = this._audioNextPts;
6439
6587
  var sample = samples[i];
6440
6588
  var delta = sample.pts - nextPts;
6441
- if (i === 0 && this._audioTimestampBreak >= TRACK_BREACKED_CHECK_TIME && this._keyFrameInNextChunk) {
6589
+ if (i === 0 && this._audioTimestampBreak >= TRACK_BROKEN_CHECK_TIME && this._keyFrameInNextChunk) {
6442
6590
  nextPts = this._audioNextPts = sample.dts;
6443
6591
  delta = 0;
6444
6592
  this._audioTimestampBreak = 0;
@@ -6446,7 +6594,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6446
6594
  if (!this._audioTimestampBreak && delta >= AUDIO_GAP_OVERLAP_THRESHOLD_COUNT$1 * refSampleDuration && delta <= MAX_SILENT_FRAME_DURATION$1 && !isSafari$1) {
6447
6595
  var silentFrame = this._getSilentFrame(audioTrack) || samples[0].data.subarray();
6448
6596
  var count = Math.floor(delta / refSampleDuration);
6449
- if (Math.abs(sample.pts - this._lastAudioExceptionGapDot) > AUDIO_EXCETION_LOG_EMIT_DURATION$1) {
6597
+ if (Math.abs(sample.pts - this._lastAudioExceptionGapDot) > AUDIO_EXCEPTION_LOG_EMIT_DURATION) {
6450
6598
  this._lastAudioExceptionGapDot = sample.pts;
6451
6599
  audioTrack.warnings.push({
6452
6600
  type: WarningType$1.AUDIO_FILLED,
@@ -6466,7 +6614,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6466
6614
  }
6467
6615
  i--;
6468
6616
  } else if (delta <= -AUDIO_GAP_OVERLAP_THRESHOLD_COUNT$1 * refSampleDuration && delta >= -1 * MAX_SILENT_FRAME_DURATION$1) {
6469
- if (Math.abs(sample.pts - this._lastAudioExceptionOverlapDot) > AUDIO_EXCETION_LOG_EMIT_DURATION$1) {
6617
+ if (Math.abs(sample.pts - this._lastAudioExceptionOverlapDot) > AUDIO_EXCEPTION_LOG_EMIT_DURATION) {
6470
6618
  this._lastAudioExceptionOverlapDot = sample.pts;
6471
6619
  audioTrack.warnings.push({
6472
6620
  type: WarningType$1.AUDIO_DROPPED,
@@ -6481,7 +6629,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6481
6629
  } else {
6482
6630
  if (Math.abs(delta) > MAX_SILENT_FRAME_DURATION$1) {
6483
6631
  this._audioTimestampBreak++;
6484
- if (Math.abs(sample.pts - this._lastAudioExceptionLargeGapDot) > AUDIO_EXCETION_LOG_EMIT_DURATION$1) {
6632
+ if (Math.abs(sample.pts - this._lastAudioExceptionLargeGapDot) > AUDIO_EXCEPTION_LOG_EMIT_DURATION) {
6485
6633
  this._lastAudioExceptionLargeGapDot = sample.pts;
6486
6634
  audioTrack.warnings.push({
6487
6635
  type: WarningType$1.LARGE_AUDIO_GAP,
@@ -6494,8 +6642,15 @@ var FlvFixer = /* @__PURE__ */ function() {
6494
6642
  });
6495
6643
  }
6496
6644
  }
6497
- sample.dts = sample.pts = nextPts;
6498
- sample.duration = sampleDurationInSampleRate;
6645
+ if (audioTrack.codecType === AudioCodecType$2.OPUS) {
6646
+ var lastSample = samples[samples.length - 1];
6647
+ if (lastSample) {
6648
+ lastSample.duration = sample.pts - lastSample.pts;
6649
+ }
6650
+ } else {
6651
+ sample.dts = sample.pts = nextPts;
6652
+ sample.duration = sampleDurationInSampleRate;
6653
+ }
6499
6654
  this._audioNextPts += refSampleDuration;
6500
6655
  }
6501
6656
  }
@@ -7454,6 +7609,13 @@ var AMF = /* @__PURE__ */ function() {
7454
7609
  }]);
7455
7610
  return AMF2;
7456
7611
  }();
7612
+ var FlvSoundFormat = {
7613
+ MP3: 2,
7614
+ G711A: 7,
7615
+ G711M: 8,
7616
+ AAC: 10,
7617
+ OPUS: 13
7618
+ };
7457
7619
  var logger$9 = new Logger$9("FlvDemuxer");
7458
7620
  var FlvDemuxer = /* @__PURE__ */ function() {
7459
7621
  function FlvDemuxer2(videoTrack, audioTrack, metadataTrack) {
@@ -7470,8 +7632,10 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7470
7632
  _createClass$g(FlvDemuxer2, [{
7471
7633
  key: "demux",
7472
7634
  value: function demux(data2) {
7635
+ var _scriptDataObject$dat;
7473
7636
  var discontinuity = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
7474
7637
  var contiguous = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
7638
+ var seamlessLoadingSwitching = arguments.length > 3 ? arguments[3] : void 0;
7475
7639
  var audioTrack = this.audioTrack, videoTrack = this.videoTrack, metadataTrack = this.metadataTrack;
7476
7640
  if (discontinuity || !contiguous) {
7477
7641
  this._remainingData = null;
@@ -7529,6 +7693,8 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7529
7693
  if (tagType === 8) {
7530
7694
  this._parseAudio(bodyData, timestamp);
7531
7695
  } else if (tagType === 9) {
7696
+ if (seamlessLoadingSwitching)
7697
+ this.seamlessLoadingSwitching = true;
7532
7698
  this._parseVideo(bodyData, timestamp);
7533
7699
  } else if (tagType === 18) {
7534
7700
  this._parseScript(bodyData, timestamp);
@@ -7546,13 +7712,31 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7546
7712
  this._remainingData = data2.subarray(offset);
7547
7713
  }
7548
7714
  audioTrack.formatTimescale = videoTrack.formatTimescale = videoTrack.timescale = metadataTrack.timescale = 1e3;
7549
- audioTrack.timescale = audioTrack.sampleRate || 0;
7715
+ audioTrack.timescale = audioTrack.codecType === AudioCodecType$2.OPUS ? 1e3 : audioTrack.sampleRate || 0;
7550
7716
  if (!audioTrack.exist() && audioTrack.hasSample()) {
7551
7717
  audioTrack.reset();
7552
7718
  }
7553
7719
  if (!videoTrack.exist() && videoTrack.hasSample()) {
7554
7720
  videoTrack.reset();
7555
7721
  }
7722
+ var scriptDataObject = metadataTrack.flvScriptSamples[metadataTrack.flvScriptSamples.length - 1];
7723
+ var metaData = scriptDataObject === null || scriptDataObject === void 0 ? void 0 : (_scriptDataObject$dat = scriptDataObject.data) === null || _scriptDataObject$dat === void 0 ? void 0 : _scriptDataObject$dat.onMetaData;
7724
+ if (metaData) {
7725
+ if (videoTrack !== null && videoTrack !== void 0 && videoTrack.exist()) {
7726
+ if (metaData.hasOwnProperty("duration")) {
7727
+ videoTrack.duration = metaData.duration * 1e3;
7728
+ }
7729
+ if (metaData.hasOwnProperty("width") && metaData.hasOwnProperty("height")) {
7730
+ videoTrack.width = metaData.width;
7731
+ videoTrack.height = metaData.height;
7732
+ }
7733
+ }
7734
+ if (audioTrack !== null && audioTrack !== void 0 && audioTrack.exist()) {
7735
+ if (metaData.hasOwnProperty("duration")) {
7736
+ audioTrack.duration = metaData.duration * 1e3;
7737
+ }
7738
+ }
7739
+ }
7556
7740
  return {
7557
7741
  videoTrack,
7558
7742
  audioTrack,
@@ -7571,8 +7755,8 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7571
7755
  }
7572
7756
  }, {
7573
7757
  key: "demuxAndFix",
7574
- value: function demuxAndFix(data2, discontinuity, contiguous, startTime) {
7575
- this.demux(data2, discontinuity, contiguous);
7758
+ value: function demuxAndFix(data2, discontinuity, contiguous, startTime, seamlessLoadingSwitching) {
7759
+ this.demux(data2, discontinuity, contiguous, seamlessLoadingSwitching);
7576
7760
  return this.fix(startTime, discontinuity, contiguous);
7577
7761
  }
7578
7762
  }, {
@@ -7582,12 +7766,12 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7582
7766
  return;
7583
7767
  var format2 = (data2[0] & 240) >>> 4;
7584
7768
  var track = this.audioTrack;
7585
- if (format2 !== 10 && format2 !== 7 && format2 !== 8) {
7769
+ if (format2 !== FlvSoundFormat.AAC && format2 !== FlvSoundFormat.G711A && format2 !== FlvSoundFormat.G711M && format2 !== FlvSoundFormat.OPUS) {
7586
7770
  logger$9.warn("Unsupported sound format: ".concat(format2));
7587
7771
  track.reset();
7588
7772
  return;
7589
7773
  }
7590
- if (format2 !== 10) {
7774
+ if (format2 !== FlvSoundFormat.AAC && format2 !== FlvSoundFormat.OPUS) {
7591
7775
  var soundRate = (data2[0] & 12) >> 2;
7592
7776
  var soundSize = (data2[0] & 2) >> 1;
7593
7777
  var soundType = data2[0] & 1;
@@ -7595,10 +7779,49 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7595
7779
  track.sampleSize = soundSize ? 16 : 8;
7596
7780
  track.channelCount = soundType + 1;
7597
7781
  }
7598
- if (format2 === 10) {
7599
- this._parseAac(data2, pts);
7600
- } else {
7601
- this._parseG711(data2, pts, format2);
7782
+ switch (format2) {
7783
+ case FlvSoundFormat.G711A:
7784
+ case FlvSoundFormat.G711M:
7785
+ this._parseG711(data2, pts, format2);
7786
+ break;
7787
+ case FlvSoundFormat.AAC:
7788
+ this._parseAac(data2, pts);
7789
+ break;
7790
+ case FlvSoundFormat.OPUS:
7791
+ this._parseOpus(data2, pts);
7792
+ break;
7793
+ }
7794
+ }
7795
+ }, {
7796
+ key: "_parseOpus",
7797
+ value: function _parseOpus(data2, pts) {
7798
+ var track = this.audioTrack;
7799
+ var packetType = data2[1];
7800
+ track.codecType = AudioCodecType$2.OPUS;
7801
+ switch (packetType) {
7802
+ case 0: {
7803
+ var ret = OPUS.parseHeaderPackets(data2.subarray(2));
7804
+ if (ret) {
7805
+ track.codec = ret.codec;
7806
+ track.channelCount = ret.channelCount;
7807
+ track.sampleRate = ret.sampleRate;
7808
+ track.config = ret.config;
7809
+ track.sampleDuration = OPUS.getFrameDuration([], track.timescale);
7810
+ } else {
7811
+ track.reset();
7812
+ logger$9.warn("Cannot parse AudioSpecificConfig", data2);
7813
+ }
7814
+ break;
7815
+ }
7816
+ case 1: {
7817
+ if (pts === void 0 || pts === null)
7818
+ return;
7819
+ var newSample = new AudioSample$2(pts, data2.subarray(2), track.sampleDuration);
7820
+ track.samples.push(newSample);
7821
+ break;
7822
+ }
7823
+ default:
7824
+ logger$9.warn("Unknown OpusPacketType: ".concat(packetType));
7602
7825
  }
7603
7826
  }
7604
7827
  }, {
@@ -7686,8 +7909,13 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7686
7909
  units = this._checkAddMetaNalToUnits(isHevc, units, track);
7687
7910
  if (units && units.length) {
7688
7911
  var sample = new VideoSample$2(dts + cts, dts, units);
7912
+ if (this.seamlessLoadingSwitching && dts < track.lastKeyFrameDts) {
7913
+ return;
7914
+ }
7915
+ this.seamlessLoadingSwitching = false;
7689
7916
  if (frameType === 1) {
7690
7917
  sample.setToKeyframe();
7918
+ track.lastKeyFrameDts = dts;
7691
7919
  }
7692
7920
  track.samples.push(sample);
7693
7921
  units.forEach(function(unit) {
@@ -8161,10 +8389,16 @@ var MP4$4 = /* @__PURE__ */ function() {
8161
8389
  if (track.useEME && track.enca) {
8162
8390
  content = MP42.enca(track);
8163
8391
  } else {
8164
- content = MP42.mp4a(track);
8392
+ if (track.codecType === AudioCodecType$2.OPUS) {
8393
+ content = MP42.opus(track);
8394
+ } else {
8395
+ content = MP42.mp4a(track);
8396
+ }
8165
8397
  }
8166
8398
  } else if (track.useEME && track.encv) {
8167
8399
  content = MP42.encv(track);
8400
+ } else if (track.av1C) {
8401
+ content = MP42.av01(track);
8168
8402
  } else {
8169
8403
  content = MP42.avc1hev1(track);
8170
8404
  }
@@ -8377,6 +8611,90 @@ var MP4$4 = /* @__PURE__ */ function() {
8377
8611
  var schi = MP42.schi(data2);
8378
8612
  return MP42.box(MP42.types.sinf, content, MP42.box(MP42.types.frma, frma), MP42.box(MP42.types.schm, schm), schi);
8379
8613
  }
8614
+ }, {
8615
+ key: "av01",
8616
+ value: function av01(track) {
8617
+ return MP42.box(MP42.types.av01, new Uint8Array([
8618
+ 0,
8619
+ 0,
8620
+ 0,
8621
+ 0,
8622
+ 0,
8623
+ 0,
8624
+ 0,
8625
+ 1,
8626
+ 0,
8627
+ 0,
8628
+ 0,
8629
+ 0,
8630
+ 0,
8631
+ 0,
8632
+ 0,
8633
+ 0,
8634
+ 0,
8635
+ 0,
8636
+ 0,
8637
+ 0,
8638
+ 0,
8639
+ 0,
8640
+ 0,
8641
+ 0,
8642
+ track.width >> 8 & 255,
8643
+ track.width & 255,
8644
+ track.height >> 8 & 255,
8645
+ track.height & 255,
8646
+ 0,
8647
+ 72,
8648
+ 0,
8649
+ 0,
8650
+ 0,
8651
+ 72,
8652
+ 0,
8653
+ 0,
8654
+ 0,
8655
+ 0,
8656
+ 0,
8657
+ 0,
8658
+ 0,
8659
+ 1,
8660
+ 0,
8661
+ 0,
8662
+ 0,
8663
+ 0,
8664
+ 0,
8665
+ 0,
8666
+ 0,
8667
+ 0,
8668
+ 0,
8669
+ 0,
8670
+ 0,
8671
+ 0,
8672
+ 0,
8673
+ 0,
8674
+ 0,
8675
+ 0,
8676
+ 0,
8677
+ 0,
8678
+ 0,
8679
+ 0,
8680
+ 0,
8681
+ 0,
8682
+ 0,
8683
+ 0,
8684
+ 0,
8685
+ 0,
8686
+ 0,
8687
+ 0,
8688
+ 0,
8689
+ 0,
8690
+ 0,
8691
+ 0,
8692
+ 0,
8693
+ 24,
8694
+ 17,
8695
+ 17
8696
+ ]), track.av1C, track.colr);
8697
+ }
8380
8698
  }, {
8381
8699
  key: "avc1hev1",
8382
8700
  value: function avc1hev1(track) {
@@ -8747,6 +9065,53 @@ var MP4$4 = /* @__PURE__ */ function() {
8747
9065
  )));
8748
9066
  return esds2;
8749
9067
  }
9068
+ }, {
9069
+ key: "opus",
9070
+ value: function opus(track) {
9071
+ var opusAudioDescription = new Uint8Array([
9072
+ 0,
9073
+ 0,
9074
+ 0,
9075
+ 0,
9076
+ 0,
9077
+ 0,
9078
+ 0,
9079
+ 1,
9080
+ 0,
9081
+ 0,
9082
+ 0,
9083
+ 0,
9084
+ 0,
9085
+ 0,
9086
+ 0,
9087
+ 0,
9088
+ 0,
9089
+ track.channelCount,
9090
+ 0,
9091
+ 16,
9092
+ 0,
9093
+ 0,
9094
+ 0,
9095
+ 0,
9096
+ track.sampleRate >> 8 & 255,
9097
+ track.sampleRate & 255,
9098
+ 0,
9099
+ 0
9100
+ ]);
9101
+ var opusSpecificConfig = track.config.length ? MP42.dOps(track) : [];
9102
+ return MP42.box(MP42.types.Opus, opusAudioDescription, opusSpecificConfig);
9103
+ }
9104
+ }, {
9105
+ key: "dOps",
9106
+ value: function dOps(track) {
9107
+ if (track.config) {
9108
+ track.config[4] = track.sampleRate >>> 24 & 255;
9109
+ track.config[5] = track.sampleRate >>> 16 & 255;
9110
+ track.config[6] = track.sampleRate >>> 8 & 255;
9111
+ track.config[7] = track.sampleRate & 255;
9112
+ return MP42.box(MP42.types.dOps, track.config);
9113
+ }
9114
+ }
8750
9115
  }, {
8751
9116
  key: "mvex",
8752
9117
  value: function mvex(tracks) {
@@ -9349,7 +9714,7 @@ var MP4$4 = /* @__PURE__ */ function() {
9349
9714
  }]);
9350
9715
  return MP42;
9351
9716
  }();
9352
- _defineProperty$e(MP4$4, "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) {
9717
+ _defineProperty$e(MP4$4, "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) {
9353
9718
  p[c] = [c.charCodeAt(0), c.charCodeAt(1), c.charCodeAt(2), c.charCodeAt(3)];
9354
9719
  return p;
9355
9720
  }, /* @__PURE__ */ Object.create(null)));
@@ -9684,30 +10049,46 @@ var FMP4Remuxer$3 = /* @__PURE__ */ function() {
9684
10049
  };
9685
10050
  }
9686
10051
  var samples = track.samples;
10052
+ var isAV01 = /av01/.test(track.codec);
9687
10053
  var mdatSize = 0;
9688
- samples.forEach(function(s) {
9689
- mdatSize += s.units.reduce(function(t, c) {
9690
- return t + c.byteLength;
9691
- }, 0);
9692
- mdatSize += s.units.length * 4;
9693
- });
9694
- var mdata = new Uint8Array(mdatSize);
9695
- var mdatView = new DataView(mdata.buffer);
9696
- var _loop = function _loop2(_offset, _sample) {
9697
- _sample = samples[i];
9698
- var sampleSize = 0;
9699
- _sample.units.forEach(function(u) {
9700
- mdatView.setUint32(_offset, u.byteLength);
9701
- _offset += 4;
9702
- mdata.set(u, _offset);
9703
- _offset += u.byteLength;
9704
- sampleSize += 4 + u.byteLength;
10054
+ if (isAV01) {
10055
+ samples.forEach(function(s) {
10056
+ mdatSize += s.data.byteLength;
9705
10057
  });
9706
- _sample.size = sampleSize;
9707
- offset = _offset, sample = _sample;
9708
- };
9709
- for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
9710
- _loop(offset, sample);
10058
+ } else {
10059
+ samples.forEach(function(s) {
10060
+ mdatSize += s.units.reduce(function(t, c) {
10061
+ return t + c.byteLength;
10062
+ }, 0);
10063
+ mdatSize += s.units.length * 4;
10064
+ });
10065
+ }
10066
+ var mdata = new Uint8Array(mdatSize);
10067
+ if (isAV01) {
10068
+ for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
10069
+ sample = samples[i];
10070
+ mdata.set(sample.data, offset);
10071
+ sample.size = sample.data.byteLength;
10072
+ offset += sample.size;
10073
+ }
10074
+ } else {
10075
+ var mdatView = new DataView(mdata.buffer);
10076
+ var _loop = function _loop2(_offset2, _sample2) {
10077
+ _sample2 = samples[_i];
10078
+ var sampleSize = 0;
10079
+ _sample2.units.forEach(function(u) {
10080
+ mdatView.setUint32(_offset2, u.byteLength);
10081
+ _offset2 += 4;
10082
+ mdata.set(u, _offset2);
10083
+ _offset2 += u.byteLength;
10084
+ sampleSize += 4 + u.byteLength;
10085
+ });
10086
+ _sample2.size = sampleSize;
10087
+ _offset = _offset2, _sample = _sample2;
10088
+ };
10089
+ for (var _i = 0, _l = samples.length, _offset = 0, _sample; _i < _l; _i++) {
10090
+ _loop(_offset, _sample);
10091
+ }
9711
10092
  }
9712
10093
  var mdat = MP4$4.mdat(mdata);
9713
10094
  var moof = MP4$4.moof([track]);
@@ -11404,6 +11785,55 @@ const NoPadding = {
11404
11785
  unpad() {
11405
11786
  }
11406
11787
  };
11788
+ var TransferCost = /* @__PURE__ */ function() {
11789
+ function TransferCost2() {
11790
+ _classCallCheck$j(this, TransferCost2);
11791
+ _defineProperty$h(this, "_ttfb", 0);
11792
+ _defineProperty$h(this, "_demuxStart", 0);
11793
+ _defineProperty$h(this, "_demuxEnd", 0);
11794
+ _defineProperty$h(this, "_demuxCost", 0);
11795
+ _defineProperty$h(this, "_remuxStart", 0);
11796
+ _defineProperty$h(this, "_remuxEnd", 0);
11797
+ _defineProperty$h(this, "_remuxCost", 0);
11798
+ _defineProperty$h(this, "_appendStart", 0);
11799
+ _defineProperty$h(this, "_appendEnd", 0);
11800
+ _defineProperty$h(this, "_appendCost", 0);
11801
+ }
11802
+ _createClass$j(TransferCost2, [{
11803
+ key: "set",
11804
+ value: function set5(event, value2) {
11805
+ this["_".concat(event)] = value2;
11806
+ }
11807
+ }, {
11808
+ key: "start",
11809
+ value: function start(event) {
11810
+ this["_".concat(event, "Start")] = Date.now();
11811
+ }
11812
+ }, {
11813
+ key: "end",
11814
+ value: function end(event) {
11815
+ this["_".concat(event, "End")] = Date.now();
11816
+ this["_".concat(event, "Cost")] = this["_".concat(event, "Cost")] + (this["_".concat(event, "End")] - this["_".concat(event, "Start")]);
11817
+ }
11818
+ }, {
11819
+ key: "transferCost",
11820
+ get: function get3() {
11821
+ return {
11822
+ ttfbCost: this._ttfb,
11823
+ demuxCost: this._demuxCost,
11824
+ remuxCost: this._remuxCost,
11825
+ appendCost: this._appendCost
11826
+ };
11827
+ }
11828
+ }]);
11829
+ return TransferCost2;
11830
+ }();
11831
+ var TRANSFER_EVENT = {
11832
+ TTFB: "ttfb",
11833
+ DEMUX: "demux",
11834
+ REMUX: "remux",
11835
+ APPEND: "append"
11836
+ };
11407
11837
  var logger$8 = new Logger$a("BufferService");
11408
11838
  var BufferService$1 = /* @__PURE__ */ function() {
11409
11839
  function BufferService2(flv, softVideo) {
@@ -11491,7 +11921,8 @@ var BufferService$1 = /* @__PURE__ */ function() {
11491
11921
  this._contiguous = false;
11492
11922
  this._sourceCreated = false;
11493
11923
  this._initSegmentId = "";
11494
- case 11:
11924
+ this.resetSeamlessSwitchStats();
11925
+ case 12:
11495
11926
  case "end":
11496
11927
  return _context.stop();
11497
11928
  }
@@ -11502,6 +11933,15 @@ var BufferService$1 = /* @__PURE__ */ function() {
11502
11933
  }
11503
11934
  return reset;
11504
11935
  }()
11936
+ }, {
11937
+ key: "resetSeamlessSwitchStats",
11938
+ value: function resetSeamlessSwitchStats() {
11939
+ this.seamlessLoadingSwitch = null;
11940
+ this.seamlessLoadingSwitching = false;
11941
+ if (this._demuxer) {
11942
+ this._demuxer.seamlessLoadingSwitching = false;
11943
+ }
11944
+ }
11505
11945
  }, {
11506
11946
  key: "endOfStream",
11507
11947
  value: function() {
@@ -11607,32 +12047,56 @@ var BufferService$1 = /* @__PURE__ */ function() {
11607
12047
  key: "appendBuffer",
11608
12048
  value: function() {
11609
12049
  var _appendBuffer = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee5(chunk) {
11610
- var demuxer, videoTrack, audioTrack, metadataTrack, videoExist, audioExist, duration, track, videoType, audioType, mse, newId, remuxResult, p;
12050
+ var _this = this;
12051
+ var switchingNoReset, demuxer, videoTrack, audioTrack, metadataTrack, idx, videoExist, audioExist, duration, track, videoType, audioType, mse, afterAppend, newId, remuxResult, p;
11611
12052
  return _regeneratorRuntime$a().wrap(function _callee5$(_context5) {
11612
12053
  while (1)
11613
12054
  switch (_context5.prev = _context5.next) {
11614
12055
  case 0:
12056
+ switchingNoReset = false;
11615
12057
  if (this._cachedBuffer) {
11616
12058
  chunk = concatUint8Array$6(this._cachedBuffer, chunk);
11617
12059
  this._cachedBuffer = null;
11618
12060
  }
11619
12061
  demuxer = this._demuxer;
11620
12062
  if (!(!chunk || !chunk.length || !demuxer)) {
11621
- _context5.next = 4;
12063
+ _context5.next = 5;
11622
12064
  break;
11623
12065
  }
11624
12066
  return _context5.abrupt("return");
11625
- case 4:
11626
- _context5.prev = 4;
11627
- demuxer.demuxAndFix(chunk, this._discontinuity, this._contiguous, this._demuxStartTime);
11628
- _context5.next = 11;
12067
+ case 5:
12068
+ _context5.prev = 5;
12069
+ this.flv._transferCost.start(TRANSFER_EVENT.DEMUX);
12070
+ demuxer.demuxAndFix(chunk, this.seamlessLoadingSwitching || this._discontinuity, this._contiguous, this._demuxStartTime, this.seamlessLoadingSwitching);
12071
+ this.seamlessLoadingSwitching = false;
12072
+ this.flv._transferCost.end(TRANSFER_EVENT.DEMUX);
12073
+ _context5.next = 15;
11629
12074
  break;
11630
- case 8:
11631
- _context5.prev = 8;
11632
- _context5.t0 = _context5["catch"](4);
12075
+ case 12:
12076
+ _context5.prev = 12;
12077
+ _context5.t0 = _context5["catch"](5);
11633
12078
  throw new StreamingError$3(ERR$3.DEMUX, ERR$3.SUB_TYPES.FLV, _context5.t0);
11634
- case 11:
12079
+ case 15:
11635
12080
  videoTrack = demuxer.videoTrack, audioTrack = demuxer.audioTrack, metadataTrack = demuxer.metadataTrack;
12081
+ if (!this.seamlessLoadingSwitch) {
12082
+ _context5.next = 25;
12083
+ break;
12084
+ }
12085
+ idx = videoTrack.samples.findIndex(function(sample) {
12086
+ return sample.originDts === videoTrack.lastKeyFrameDts;
12087
+ });
12088
+ if (!(idx >= 0)) {
12089
+ _context5.next = 25;
12090
+ break;
12091
+ }
12092
+ videoTrack.samples.splice(idx);
12093
+ _context5.next = 22;
12094
+ return this.seamlessLoadingSwitch();
12095
+ case 22:
12096
+ this.seamlessLoadingSwitch = null;
12097
+ chunk = null;
12098
+ switchingNoReset = true;
12099
+ case 25:
11636
12100
  videoExist = videoTrack.exist();
11637
12101
  audioExist = audioTrack.exist();
11638
12102
  if (this._opts.onlyAudio) {
@@ -11644,7 +12108,7 @@ var BufferService$1 = /* @__PURE__ */ function() {
11644
12108
  audioTrack.present = false;
11645
12109
  }
11646
12110
  if (!(!videoExist && videoTrack.present || !audioExist && audioTrack.present)) {
11647
- _context5.next = 29;
12111
+ _context5.next = 42;
11648
12112
  break;
11649
12113
  }
11650
12114
  duration = 0;
@@ -11653,7 +12117,7 @@ var BufferService$1 = /* @__PURE__ */ function() {
11653
12117
  duration = (track.samples[track.samples.length - 1].originPts - track.samples[0].originPts) / track.timescale * 1e3;
11654
12118
  }
11655
12119
  if (!(duration > this._opts.analyzeDuration)) {
11656
- _context5.next = 27;
12120
+ _context5.next = 40;
11657
12121
  break;
11658
12122
  }
11659
12123
  logger$8.warn("analyze duration exceeded, ".concat(duration, "ms"), track);
@@ -11662,19 +12126,28 @@ var BufferService$1 = /* @__PURE__ */ function() {
11662
12126
  this.flv.emit(EVENT$3.ANALYZE_DURATION_EXCEEDED, {
11663
12127
  duration
11664
12128
  });
11665
- _context5.next = 29;
12129
+ _context5.next = 42;
11666
12130
  break;
11667
- case 27:
12131
+ case 40:
11668
12132
  this._cachedBuffer = chunk;
11669
12133
  return _context5.abrupt("return");
11670
- case 29:
12134
+ case 42:
11671
12135
  videoType = videoTrack.type;
11672
12136
  audioType = audioTrack.type;
11673
12137
  this._fireEvents(videoTrack, audioTrack, metadataTrack);
11674
- this._discontinuity = false;
11675
- this._contiguous = true;
11676
- this._demuxStartTime = 0;
12138
+ if (!switchingNoReset) {
12139
+ this._discontinuity = false;
12140
+ this._contiguous = true;
12141
+ this._demuxStartTime = 0;
12142
+ }
11677
12143
  mse = this._mse;
12144
+ afterAppend = function afterAppend2() {
12145
+ var _this$flv;
12146
+ if ((_this$flv = _this.flv) !== null && _this$flv !== void 0 && _this$flv.emit) {
12147
+ var _this$flv2;
12148
+ (_this$flv2 = _this.flv) === null || _this$flv2 === void 0 ? void 0 : _this$flv2.emit(EVENT$3.APPEND_BUFFER, {});
12149
+ }
12150
+ };
11678
12151
  this.flv.emit(EVENT$3.DEMUXED_TRACK, {
11679
12152
  videoTrack
11680
12153
  });
@@ -11685,16 +12158,16 @@ var BufferService$1 = /* @__PURE__ */ function() {
11685
12158
  this._emitMetaParsedEvent(videoTrack, audioTrack);
11686
12159
  }
11687
12160
  if (!mse) {
11688
- _context5.next = 66;
12161
+ _context5.next = 81;
11689
12162
  break;
11690
12163
  }
11691
12164
  if (this._sourceCreated) {
11692
- _context5.next = 47;
12165
+ _context5.next = 59;
11693
12166
  break;
11694
12167
  }
11695
- _context5.next = 43;
12168
+ _context5.next = 55;
11696
12169
  return mse.open();
11697
- case 43:
12170
+ case 55:
11698
12171
  if (videoExist) {
11699
12172
  logger$8.log("codec: video/mp4;codecs=".concat(videoTrack.codec));
11700
12173
  mse.createSource(videoType, "video/mp4;codecs=".concat(videoTrack.codec));
@@ -11705,26 +12178,28 @@ var BufferService$1 = /* @__PURE__ */ function() {
11705
12178
  }
11706
12179
  this._sourceCreated = true;
11707
12180
  this.flv.emit(EVENT$3.SOURCEBUFFER_CREATED);
11708
- case 47:
11709
- _context5.prev = 47;
12181
+ case 59:
12182
+ _context5.prev = 59;
11710
12183
  if (this._needInitSegment && !this._opts.mseLowLatency) {
11711
12184
  videoTrack.duration = this._opts.durationForMSELowLatencyOff * videoTrack.timescale;
11712
12185
  audioTrack.duration = this._opts.durationForMSELowLatencyOff * audioExist.timescale;
11713
12186
  }
12187
+ this.flv._transferCost.start(TRANSFER_EVENT.REMUX);
11714
12188
  remuxResult = this._remuxer.remux(this._needInitSegment);
11715
- _context5.next = 55;
12189
+ this.flv._transferCost.end(TRANSFER_EVENT.REMUX);
12190
+ _context5.next = 69;
11716
12191
  break;
11717
- case 52:
11718
- _context5.prev = 52;
11719
- _context5.t1 = _context5["catch"](47);
12192
+ case 66:
12193
+ _context5.prev = 66;
12194
+ _context5.t1 = _context5["catch"](59);
11720
12195
  throw new StreamingError$3(ERR$3.REMUX, ERR$3.SUB_TYPES.FMP4, _context5.t1);
11721
- case 55:
12196
+ case 69:
11722
12197
  if (!(this._needInitSegment && !remuxResult.videoInitSegment && !remuxResult.audioInitSegment)) {
11723
- _context5.next = 57;
12198
+ _context5.next = 71;
11724
12199
  break;
11725
12200
  }
11726
12201
  return _context5.abrupt("return");
11727
- case 57:
12202
+ case 71:
11728
12203
  this._needInitSegment = false;
11729
12204
  p = [];
11730
12205
  if (remuxResult.videoInitSegment)
@@ -11735,16 +12210,21 @@ var BufferService$1 = /* @__PURE__ */ function() {
11735
12210
  p.push(mse.append(videoType, remuxResult.videoSegment));
11736
12211
  if (remuxResult.audioSegment)
11737
12212
  p.push(mse.append(audioType, remuxResult.audioSegment));
11738
- return _context5.abrupt("return", Promise.all(p));
11739
- case 66:
12213
+ this.flv._transferCost.start(TRANSFER_EVENT.APPEND);
12214
+ return _context5.abrupt("return", Promise.all(p).then(afterAppend).then(function() {
12215
+ _this.flv._transferCost.end(TRANSFER_EVENT.APPEND);
12216
+ afterAppend();
12217
+ }));
12218
+ case 81:
11740
12219
  if (this._softVideo) {
11741
12220
  this._softVideo.appendBuffer(videoTrack, audioTrack);
12221
+ afterAppend();
11742
12222
  }
11743
- case 67:
12223
+ case 82:
11744
12224
  case "end":
11745
12225
  return _context5.stop();
11746
12226
  }
11747
- }, _callee5, this, [[4, 8], [47, 52]]);
12227
+ }, _callee5, this, [[5, 12], [59, 66]]);
11748
12228
  }));
11749
12229
  function appendBuffer(_x2) {
11750
12230
  return _appendBuffer.apply(this, arguments);
@@ -11755,7 +12235,7 @@ var BufferService$1 = /* @__PURE__ */ function() {
11755
12235
  key: "evictBuffer",
11756
12236
  value: function() {
11757
12237
  var _evictBuffer = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee6(bufferBehind) {
11758
- var _this = this;
12238
+ var _this2 = this;
11759
12239
  var media, currentTime, removeEnd, start;
11760
12240
  return _regeneratorRuntime$a().wrap(function _callee6$(_context6) {
11761
12241
  while (1)
@@ -11784,7 +12264,7 @@ var BufferService$1 = /* @__PURE__ */ function() {
11784
12264
  return _context6.abrupt("return");
11785
12265
  case 10:
11786
12266
  return _context6.abrupt("return", this._mse.clearBuffer(0, removeEnd).then(function() {
11787
- return _this.flv.emit(EVENT$3.REMOVE_BUFFER, {
12267
+ return _this2.flv.emit(EVENT$3.REMOVE_BUFFER, {
11788
12268
  removeEnd
11789
12269
  });
11790
12270
  }));
@@ -11834,16 +12314,16 @@ var BufferService$1 = /* @__PURE__ */ function() {
11834
12314
  }, {
11835
12315
  key: "_fireEvents",
11836
12316
  value: function _fireEvents(videoTrack, audioTrack, metadataTrack) {
11837
- var _this2 = this;
11838
- logger$8.debug(videoTrack.samples, audioTrack.samples);
12317
+ var _this3 = this;
12318
+ logger$8.debug("videoTrack samples count: ".concat(videoTrack.samples.length, ", audioTrack samples count: ").concat(audioTrack.samples.length));
11839
12319
  metadataTrack.flvScriptSamples.forEach(function(sample) {
11840
- _this2.flv.emit(EVENT$3.FLV_SCRIPT_DATA, sample);
12320
+ _this3.flv.emit(EVENT$3.FLV_SCRIPT_DATA, sample);
11841
12321
  logger$8.debug("flvScriptData", sample);
11842
12322
  });
11843
12323
  videoTrack.samples.forEach(function(sample) {
11844
12324
  if (sample.keyframe) {
11845
- _this2.flv.emit(EVENT$3.KEYFRAME, {
11846
- pts: sample.pts
12325
+ _this3.flv.emit(EVENT$3.KEYFRAME, {
12326
+ pts: sample.originPts
11847
12327
  });
11848
12328
  }
11849
12329
  });
@@ -11861,7 +12341,7 @@ var BufferService$1 = /* @__PURE__ */ function() {
11861
12341
  break;
11862
12342
  }
11863
12343
  if (type)
11864
- _this2.flv.emit(EVENT$3.STREAM_EXCEPTION, _objectSpread2$a(_objectSpread2$a({}, warn), {}, {
12344
+ _this3.flv.emit(EVENT$3.STREAM_EXCEPTION, _objectSpread2$a(_objectSpread2$a({}, warn), {}, {
11865
12345
  type
11866
12346
  }));
11867
12347
  logger$8.warn("video exception", warn);
@@ -11880,13 +12360,13 @@ var BufferService$1 = /* @__PURE__ */ function() {
11880
12360
  break;
11881
12361
  }
11882
12362
  if (type)
11883
- _this2.flv.emit(EVENT$3.STREAM_EXCEPTION, _objectSpread2$a(_objectSpread2$a({}, warn), {}, {
12363
+ _this3.flv.emit(EVENT$3.STREAM_EXCEPTION, _objectSpread2$a(_objectSpread2$a({}, warn), {}, {
11884
12364
  type
11885
12365
  }));
11886
12366
  logger$8.warn("audio exception", warn);
11887
12367
  });
11888
12368
  metadataTrack.seiSamples.forEach(function(sei) {
11889
- _this2.flv.emit(EVENT$3.SEI, _objectSpread2$a(_objectSpread2$a({}, sei), {}, {
12369
+ _this3.flv.emit(EVENT$3.SEI, _objectSpread2$a(_objectSpread2$a({}, sei), {}, {
11890
12370
  sei: {
11891
12371
  code: sei.data.type,
11892
12372
  content: sei.data.payload,
@@ -11921,7 +12401,8 @@ function getOption$1(opts) {
11921
12401
  durationForMSELowLatencyOff: 6,
11922
12402
  chunkCountForSpeed: 50,
11923
12403
  skipChunkSize: 1e3,
11924
- longtimeNoReceived: 3e3
12404
+ longtimeNoReceived: 3e3,
12405
+ enableStartGapJump: true
11925
12406
  }, opts);
11926
12407
  if (ret.isLive) {
11927
12408
  if (ret.preloadTime) {
@@ -11989,7 +12470,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
11989
12470
  _defineProperty$h(_assertThisInitialized$f(_this), "_acceptRanges", true);
11990
12471
  _defineProperty$h(_assertThisInitialized$f(_this), "_onProgress", /* @__PURE__ */ function() {
11991
12472
  var _ref2 = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee(chunk, done, _ref, response) {
11992
- var startTime, endTime, st, firstByteTime, _this$_mediaLoader, headers, _this$_bufferService, remaining, maxReaderInterval;
12473
+ var startTime, endTime, st, firstByteTime, _this$_mediaLoader, headers, elapsed, _this$_bufferService, remaining, maxReaderInterval;
11993
12474
  return _regeneratorRuntime$a().wrap(function _callee$(_context) {
11994
12475
  while (1)
11995
12476
  switch (_context.prev = _context.next) {
@@ -11997,7 +12478,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
11997
12478
  startTime = _ref.startTime, endTime = _ref.endTime, st = _ref.st, firstByteTime = _ref.firstByteTime;
11998
12479
  _this._loading = !done;
11999
12480
  if (_this._firstProgressEmit) {
12000
- _context.next = 11;
12481
+ _context.next = 13;
12001
12482
  break;
12002
12483
  }
12003
12484
  if (_this.media) {
@@ -12008,49 +12489,51 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
12008
12489
  return _context.abrupt("return");
12009
12490
  case 6:
12010
12491
  headers = response.headers;
12492
+ elapsed = st ? firstByteTime - st : endTime - startTime;
12011
12493
  _this.emit(EVENT$3.TTFB, {
12012
12494
  url: _this._opts.url,
12013
12495
  responseUrl: response.url,
12014
- elapsed: st ? firstByteTime - st : endTime - startTime
12496
+ elapsed
12015
12497
  });
12016
12498
  _this.emit(EVENT$3.LOAD_RESPONSE_HEADERS, {
12017
12499
  headers
12018
12500
  });
12501
+ _this._transferCost.set(TRANSFER_EVENT.TTFB, elapsed);
12019
12502
  _this._acceptRanges = !!(headers !== null && headers !== void 0 && headers.get("Accept-Ranges")) || !!(headers !== null && headers !== void 0 && headers.get("Content-Range"));
12020
12503
  _this._firstProgressEmit = true;
12021
- case 11:
12504
+ case 13:
12022
12505
  if (_this._bufferService) {
12023
- _context.next = 13;
12506
+ _context.next = 15;
12024
12507
  break;
12025
12508
  }
12026
12509
  return _context.abrupt("return");
12027
- case 13:
12510
+ case 15:
12028
12511
  clearTimeout(_this._maxChunkWaitTimer);
12029
12512
  _this._bandwidthService.addChunkRecord(chunk === null || chunk === void 0 ? void 0 : chunk.byteLength, endTime - startTime);
12030
- _context.prev = 15;
12031
- _context.next = 18;
12513
+ _context.prev = 17;
12514
+ _context.next = 20;
12032
12515
  return _this._bufferService.appendBuffer(chunk);
12033
- case 18:
12516
+ case 20:
12034
12517
  (_this$_bufferService = _this._bufferService) === null || _this$_bufferService === void 0 ? void 0 : _this$_bufferService.evictBuffer(_this._opts.bufferBehind);
12035
- _context.next = 31;
12518
+ _context.next = 33;
12036
12519
  break;
12037
- case 21:
12038
- _context.prev = 21;
12039
- _context.t0 = _context["catch"](15);
12520
+ case 23:
12521
+ _context.prev = 23;
12522
+ _context.t0 = _context["catch"](17);
12040
12523
  if (!(!_this.isLive && _this._bufferService.isFull())) {
12041
- _context.next = 30;
12524
+ _context.next = 32;
12042
12525
  break;
12043
12526
  }
12044
- _context.next = 26;
12527
+ _context.next = 28;
12045
12528
  return _this._mediaLoader.cancel();
12046
- case 26:
12529
+ case 28:
12047
12530
  _this._loading = false;
12048
12531
  remaining = _this.bufferInfo().remaining;
12049
12532
  _this._opts.preloadTime = parseInt(remaining) / 2;
12050
12533
  return _context.abrupt("return");
12051
- case 30:
12534
+ case 32:
12052
12535
  return _context.abrupt("return", _this._emitError(StreamingError$3.create(_context.t0)));
12053
- case 31:
12536
+ case 33:
12054
12537
  if (_this._urlSwitching) {
12055
12538
  _this._urlSwitching = false;
12056
12539
  _this.emit(EVENT$3.SWITCH_URL_SUCCESS, {
@@ -12062,7 +12545,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
12062
12545
  _this._tick();
12063
12546
  }
12064
12547
  if (!(done && !_this.media.seeking)) {
12065
- _context.next = 38;
12548
+ _context.next = 40;
12066
12549
  break;
12067
12550
  }
12068
12551
  _this.emit(EVENT$3.LOAD_COMPLETE);
@@ -12071,13 +12554,13 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
12071
12554
  _this._end();
12072
12555
  }
12073
12556
  return _context.abrupt("return");
12074
- case 38:
12557
+ case 40:
12075
12558
  if (_this.isLive) {
12076
- _context.next = 40;
12559
+ _context.next = 42;
12077
12560
  break;
12078
12561
  }
12079
12562
  return _context.abrupt("return");
12080
- case 40:
12563
+ case 42:
12081
12564
  maxReaderInterval = _this._opts.maxReaderInterval;
12082
12565
  if (maxReaderInterval && _this._firstProgressEmit) {
12083
12566
  clearTimeout(_this._maxChunkWaitTimer);
@@ -12091,11 +12574,11 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
12091
12574
  _this._end();
12092
12575
  }, maxReaderInterval);
12093
12576
  }
12094
- case 42:
12577
+ case 44:
12095
12578
  case "end":
12096
12579
  return _context.stop();
12097
12580
  }
12098
- }, _callee, null, [[15, 21]]);
12581
+ }, _callee, null, [[17, 23]]);
12099
12582
  }));
12100
12583
  return function(_x, _x2, _x3, _x4) {
12101
12584
  return _ref2.apply(this, arguments);
@@ -12128,19 +12611,19 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
12128
12611
  if (bufferEnd < MAX_HOLE || !media.readyState)
12129
12612
  return;
12130
12613
  var opts = _this._opts;
12131
- if (isMediaPlaying$1(media)) {
12614
+ if (isMediaPlaying$1(media) && media.currentTime) {
12132
12615
  if (_this._gapService) {
12133
12616
  _this._gapService.do(media, opts.maxJumpDistance, _this.isLive, 3);
12134
12617
  }
12135
12618
  } else {
12136
- if (!media.currentTime && _this._gapService) {
12619
+ if (!media.currentTime && _this._gapService && opts.enableStartGapJump) {
12137
12620
  var gapJump = _this._opts.mseLowLatency || _this._opts.mseLowLatency === false && _this.bufferInfo(MAX_START_GAP).nextStart;
12138
12621
  if (gapJump) {
12139
12622
  _this._gapService.do(media, opts.maxJumpDistance, _this.isLive, 3);
12140
12623
  }
12141
12624
  return;
12142
12625
  }
12143
- if (opts.isLive && media.readyState === 4 && bufferEnd > opts.disconnectTime) {
12626
+ if (opts.isLive && media.readyState === 4 && bufferEnd - media.currentTime > opts.disconnectTime) {
12144
12627
  _this.disconnect();
12145
12628
  }
12146
12629
  }
@@ -12289,6 +12772,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
12289
12772
  responseType: "arraybuffer"
12290
12773
  }));
12291
12774
  _this._disconnectRetryCount = _this._opts.disconnectRetryCount;
12775
+ _this._transferCost = new TransferCost();
12292
12776
  _this._bufferService = new BufferService$1(_assertThisInitialized$f(_this), _this._opts.softDecode ? _this.media : void 0, _this._opts);
12293
12777
  _this._seiService = new SeiService$1(_assertThisInitialized$f(_this));
12294
12778
  _this._bandwidthService = new BandwidthService$1({
@@ -12312,7 +12796,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
12312
12796
  _createClass$j(Flv2, [{
12313
12797
  key: "version",
12314
12798
  get: function get3() {
12315
- return "3.0.19-rc.0";
12799
+ return "3.0.20-rc.6";
12316
12800
  }
12317
12801
  }, {
12318
12802
  key: "isLive",
@@ -12428,9 +12912,9 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
12428
12912
  return this._clear();
12429
12913
  case 8:
12430
12914
  setTimeout(function() {
12915
+ _this2._seamlessSwitching = true;
12431
12916
  _this2._loadData(_this2._opts.url);
12432
12917
  _this2._bufferService.seamlessSwitch();
12433
- _this2._seamlessSwitching = true;
12434
12918
  });
12435
12919
  _context5.next = 13;
12436
12920
  break;
@@ -12454,50 +12938,82 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
12454
12938
  }, {
12455
12939
  key: "disconnect",
12456
12940
  value: function disconnect() {
12941
+ var _this$_bufferService4;
12457
12942
  logger$7.debug("disconnect!");
12943
+ (_this$_bufferService4 = this._bufferService) === null || _this$_bufferService4 === void 0 ? void 0 : _this$_bufferService4.resetSeamlessSwitchStats();
12458
12944
  return this._clear();
12459
12945
  }
12460
12946
  }, {
12461
12947
  key: "switchURL",
12462
12948
  value: function() {
12463
- var _switchURL = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee6(url, seamless) {
12949
+ var _switchURL = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee7(url, seamless) {
12464
12950
  var _this3 = this;
12465
- return _regeneratorRuntime$a().wrap(function _callee6$(_context6) {
12951
+ return _regeneratorRuntime$a().wrap(function _callee7$(_context7) {
12466
12952
  while (1)
12467
- switch (_context6.prev = _context6.next) {
12953
+ switch (_context7.prev = _context7.next) {
12468
12954
  case 0:
12469
12955
  if (this._bufferService) {
12470
- _context6.next = 2;
12956
+ _context7.next = 2;
12471
12957
  break;
12472
12958
  }
12473
- return _context6.abrupt("return");
12959
+ return _context7.abrupt("return");
12474
12960
  case 2:
12475
12961
  this._resetDisconnectCount();
12962
+ if (!(this._loading && seamless)) {
12963
+ _context7.next = 6;
12964
+ break;
12965
+ }
12966
+ this._bufferService.seamlessLoadingSwitch = /* @__PURE__ */ function() {
12967
+ var _ref5 = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee6(pts) {
12968
+ return _regeneratorRuntime$a().wrap(function _callee6$(_context6) {
12969
+ while (1)
12970
+ switch (_context6.prev = _context6.next) {
12971
+ case 0:
12972
+ _context6.next = 2;
12973
+ return _this3._clear();
12974
+ case 2:
12975
+ _this3._bufferService.seamlessLoadingSwitching = true;
12976
+ _this3._urlSwitching = true;
12977
+ _this3._seamlessSwitching = true;
12978
+ _this3._bufferService.seamlessSwitch();
12979
+ _this3._loadData(url);
12980
+ case 7:
12981
+ case "end":
12982
+ return _context6.stop();
12983
+ }
12984
+ }, _callee6);
12985
+ }));
12986
+ return function(_x8) {
12987
+ return _ref5.apply(this, arguments);
12988
+ };
12989
+ }();
12990
+ return _context7.abrupt("return");
12991
+ case 6:
12476
12992
  if (!(!seamless || !this._opts.isLive)) {
12477
- _context6.next = 8;
12993
+ _context7.next = 11;
12478
12994
  break;
12479
12995
  }
12480
- _context6.next = 6;
12996
+ _context7.next = 9;
12481
12997
  return this.load(url);
12482
- case 6:
12998
+ case 9:
12483
12999
  this._urlSwitching = true;
12484
- return _context6.abrupt("return", this.media.play(true).catch(function() {
13000
+ return _context7.abrupt("return", this.media.play(true).catch(function() {
12485
13001
  }));
12486
- case 8:
12487
- _context6.next = 10;
13002
+ case 11:
13003
+ _context7.next = 13;
12488
13004
  return this._clear();
12489
- case 10:
13005
+ case 13:
12490
13006
  setTimeout(function() {
12491
13007
  _this3._urlSwitching = true;
12492
13008
  _this3._seamlessSwitching = true;
12493
13009
  _this3._loadData(url);
12494
13010
  _this3._bufferService.seamlessSwitch();
12495
13011
  });
12496
- case 11:
13012
+ case 14:
12497
13013
  case "end":
12498
- return _context6.stop();
13014
+ return _context7.stop();
12499
13015
  }
12500
- }, _callee6, this);
13016
+ }, _callee7, this);
12501
13017
  }));
12502
13018
  function switchURL(_x6, _x7) {
12503
13019
  return _switchURL.apply(this, arguments);
@@ -12507,16 +13023,16 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
12507
13023
  }, {
12508
13024
  key: "destroy",
12509
13025
  value: function() {
12510
- var _destroy = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee7() {
12511
- return _regeneratorRuntime$a().wrap(function _callee7$(_context7) {
13026
+ var _destroy = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee8() {
13027
+ return _regeneratorRuntime$a().wrap(function _callee8$(_context8) {
12512
13028
  while (1)
12513
- switch (_context7.prev = _context7.next) {
13029
+ switch (_context8.prev = _context8.next) {
12514
13030
  case 0:
12515
13031
  if (this.media) {
12516
- _context7.next = 2;
13032
+ _context8.next = 2;
12517
13033
  break;
12518
13034
  }
12519
- return _context7.abrupt("return");
13035
+ return _context8.abrupt("return");
12520
13036
  case 2:
12521
13037
  this.removeAllListeners();
12522
13038
  this._seiService.reset();
@@ -12526,16 +13042,16 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
12526
13042
  this.media.removeEventListener("timeupdate", this._onTimeupdate);
12527
13043
  this.media.removeEventListener("waiting", this._onWaiting);
12528
13044
  this.media.removeEventListener("progress", this._onBufferUpdate);
12529
- _context7.next = 12;
13045
+ _context8.next = 12;
12530
13046
  return Promise.all([this._clear(), this._bufferService.destroy()]);
12531
13047
  case 12:
12532
13048
  this.media = null;
12533
13049
  this._bufferService = null;
12534
13050
  case 14:
12535
13051
  case "end":
12536
- return _context7.stop();
13052
+ return _context8.stop();
12537
13053
  }
12538
- }, _callee7, this);
13054
+ }, _callee8, this);
12539
13055
  }));
12540
13056
  function destroy() {
12541
13057
  return _destroy.apply(this, arguments);
@@ -12564,26 +13080,26 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
12564
13080
  }, {
12565
13081
  key: "_reset",
12566
13082
  value: function() {
12567
- var _reset2 = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee8() {
12568
- var reuseMse, _args8 = arguments;
12569
- return _regeneratorRuntime$a().wrap(function _callee8$(_context8) {
13083
+ var _reset2 = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee9() {
13084
+ var reuseMse, _args9 = arguments;
13085
+ return _regeneratorRuntime$a().wrap(function _callee9$(_context9) {
12570
13086
  while (1)
12571
- switch (_context8.prev = _context8.next) {
13087
+ switch (_context9.prev = _context9.next) {
12572
13088
  case 0:
12573
- reuseMse = _args8.length > 0 && _args8[0] !== void 0 ? _args8[0] : false;
13089
+ reuseMse = _args9.length > 0 && _args9[0] !== void 0 ? _args9[0] : false;
12574
13090
  this._seiService.reset();
12575
13091
  this._bandwidthService.reset();
12576
13092
  this._stats.reset();
12577
- _context8.next = 6;
13093
+ _context9.next = 6;
12578
13094
  return this._clear();
12579
13095
  case 6:
12580
- _context8.next = 8;
13096
+ _context9.next = 8;
12581
13097
  return this._bufferService.reset(reuseMse);
12582
13098
  case 8:
12583
13099
  case "end":
12584
- return _context8.stop();
13100
+ return _context9.stop();
12585
13101
  }
12586
- }, _callee8, this);
13102
+ }, _callee9, this);
12587
13103
  }));
12588
13104
  function _reset() {
12589
13105
  return _reset2.apply(this, arguments);
@@ -12593,17 +13109,17 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
12593
13109
  }, {
12594
13110
  key: "_loadData",
12595
13111
  value: function() {
12596
- var _loadData2 = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee9(url, range) {
13112
+ var _loadData2 = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee10(url, range) {
12597
13113
  var finnalUrl;
12598
- return _regeneratorRuntime$a().wrap(function _callee9$(_context9) {
13114
+ return _regeneratorRuntime$a().wrap(function _callee10$(_context10) {
12599
13115
  while (1)
12600
- switch (_context9.prev = _context9.next) {
13116
+ switch (_context10.prev = _context10.next) {
12601
13117
  case 0:
12602
13118
  if (url)
12603
13119
  this._opts.url = url;
12604
13120
  finnalUrl = url = this._opts.url;
12605
13121
  if (url) {
12606
- _context9.next = 4;
13122
+ _context10.next = 4;
12607
13123
  break;
12608
13124
  }
12609
13125
  throw new Error("Source url is missing");
@@ -12618,34 +13134,34 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
12618
13134
  });
12619
13135
  logger$7.debug("load data, loading:", this._loading, finnalUrl);
12620
13136
  if (!this._loading) {
12621
- _context9.next = 11;
13137
+ _context10.next = 11;
12622
13138
  break;
12623
13139
  }
12624
- _context9.next = 11;
13140
+ _context10.next = 11;
12625
13141
  return this._mediaLoader.cancel();
12626
13142
  case 11:
12627
13143
  this._loading = true;
12628
- _context9.prev = 12;
12629
- _context9.next = 15;
13144
+ _context10.prev = 12;
13145
+ _context10.next = 15;
12630
13146
  return this._mediaLoader.load({
12631
13147
  url: finnalUrl,
12632
13148
  range
12633
13149
  });
12634
13150
  case 15:
12635
- _context9.next = 21;
13151
+ _context10.next = 21;
12636
13152
  break;
12637
13153
  case 17:
12638
- _context9.prev = 17;
12639
- _context9.t0 = _context9["catch"](12);
13154
+ _context10.prev = 17;
13155
+ _context10.t0 = _context10["catch"](12);
12640
13156
  this._loading = false;
12641
- return _context9.abrupt("return", this._emitError(StreamingError$3.network(_context9.t0), false));
13157
+ return _context10.abrupt("return", this._emitError(StreamingError$3.network(_context10.t0), false));
12642
13158
  case 21:
12643
13159
  case "end":
12644
- return _context9.stop();
13160
+ return _context10.stop();
12645
13161
  }
12646
- }, _callee9, this, [[12, 17]]);
13162
+ }, _callee10, this, [[12, 17]]);
12647
13163
  }));
12648
- function _loadData(_x8, _x9) {
13164
+ function _loadData(_x9, _x10) {
12649
13165
  return _loadData2.apply(this, arguments);
12650
13166
  }
12651
13167
  return _loadData;
@@ -12653,16 +13169,16 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
12653
13169
  }, {
12654
13170
  key: "_clear",
12655
13171
  value: function() {
12656
- var _clear2 = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee10() {
12657
- return _regeneratorRuntime$a().wrap(function _callee10$(_context10) {
13172
+ var _clear2 = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee11() {
13173
+ return _regeneratorRuntime$a().wrap(function _callee11$(_context11) {
12658
13174
  while (1)
12659
- switch (_context10.prev = _context10.next) {
13175
+ switch (_context11.prev = _context11.next) {
12660
13176
  case 0:
12661
13177
  if (!this._mediaLoader) {
12662
- _context10.next = 3;
13178
+ _context11.next = 3;
12663
13179
  break;
12664
13180
  }
12665
- _context10.next = 3;
13181
+ _context11.next = 3;
12666
13182
  return this._mediaLoader.cancel();
12667
13183
  case 3:
12668
13184
  clearTimeout(this._maxChunkWaitTimer);
@@ -12671,9 +13187,9 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
12671
13187
  this._firstProgressEmit = false;
12672
13188
  case 7:
12673
13189
  case "end":
12674
- return _context10.stop();
13190
+ return _context11.stop();
12675
13191
  }
12676
- }, _callee10, this);
13192
+ }, _callee11, this);
12677
13193
  }));
12678
13194
  function _clear() {
12679
13195
  return _clear2.apply(this, arguments);
@@ -12760,9 +13276,13 @@ var PluginExtension$1 = /* @__PURE__ */ function() {
12760
13276
  _createClass$j(PluginExtension2, [{
12761
13277
  key: "_init",
12762
13278
  value: function _init() {
12763
- var _this$_opts2 = this._opts, media = _this$_opts2.media, preloadTime = _this$_opts2.preloadTime, innerDegrade = _this$_opts2.innerDegrade, decodeMode = _this$_opts2.decodeMode;
13279
+ var _this$_opts2 = this._opts, media = _this$_opts2.media, isLive = _this$_opts2.isLive, preloadTime = _this$_opts2.preloadTime, innerDegrade = _this$_opts2.innerDegrade, decodeMode = _this$_opts2.decodeMode;
12764
13280
  if (!media)
12765
13281
  return;
13282
+ if (!isLive && media.setPlayMode) {
13283
+ media.setPlayMode("VOD");
13284
+ return;
13285
+ }
12766
13286
  if (innerDegrade) {
12767
13287
  media.setAttribute("innerdegrade", innerDegrade);
12768
13288
  }
@@ -12800,6 +13320,7 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
12800
13320
  args[_key] = arguments[_key];
12801
13321
  }
12802
13322
  _this = _super.call.apply(_super, [this].concat(args));
13323
+ _defineProperty$h(_assertThisInitialized$f(_this), "logger", logger$7);
12803
13324
  _defineProperty$h(_assertThisInitialized$f(_this), "flv", null);
12804
13325
  _defineProperty$h(_assertThisInitialized$f(_this), "pluginExtension", null);
12805
13326
  _defineProperty$h(_assertThisInitialized$f(_this), "getStats", function() {
@@ -12819,7 +13340,7 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
12819
13340
  if (_this.flv) {
12820
13341
  var _this$player$config, _this$player$config$f;
12821
13342
  _this.player.config.url = url;
12822
- if (_typeof$b(seamless) === "object") {
13343
+ if (_typeof$a(seamless) === "object") {
12823
13344
  seamless = seamless.seamless;
12824
13345
  }
12825
13346
  _this.flv.switchURL(url, seamless);
@@ -12867,11 +13388,17 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
12867
13388
  var _this$flv3;
12868
13389
  return (_this$flv3 = this.flv) === null || _this$flv3 === void 0 ? void 0 : _this$flv3.loader;
12869
13390
  }
13391
+ }, {
13392
+ key: "transferCost",
13393
+ get: function get3() {
13394
+ return this.flv._transferCost.transferCost;
13395
+ }
12870
13396
  }, {
12871
13397
  key: "beforePlayerInit",
12872
13398
  value: function beforePlayerInit() {
12873
13399
  var _this2 = this;
12874
13400
  var config = this.player.config;
13401
+ var mediaElem = this.player.media || this.player.video;
12875
13402
  if (!config.url)
12876
13403
  return;
12877
13404
  if (this.flv)
@@ -12884,10 +13411,10 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
12884
13411
  this.flv = new Flv(_objectSpread2$a({
12885
13412
  softDecode: this.softDecode,
12886
13413
  isLive: config.isLive,
12887
- media: this.player.video,
13414
+ media: mediaElem,
12888
13415
  preProcessUrl: function preProcessUrl(url, ext) {
12889
- var _this2$player$preProc, _this2$player;
12890
- return ((_this2$player$preProc = (_this2$player = _this2.player).preProcessUrl) === null || _this2$player$preProc === void 0 ? void 0 : _this2$player$preProc.call(_this2$player, url, ext)) || {
13416
+ var _this2$player, _this2$player$preProc;
13417
+ return ((_this2$player = _this2.player) === null || _this2$player === void 0 ? void 0 : (_this2$player$preProc = _this2$player.preProcessUrl) === null || _this2$player$preProc === void 0 ? void 0 : _this2$player$preProc.call(_this2$player, url, ext)) || {
12891
13418
  url,
12892
13419
  ext
12893
13420
  };
@@ -12906,7 +13433,8 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
12906
13433
  }
12907
13434
  if (this.softDecode) {
12908
13435
  this.pluginExtension = new PluginExtension$1(_objectSpread2$a({
12909
- media: this.player.video
13436
+ media: this.player.video,
13437
+ isLive: config.isLive
12910
13438
  }, config.flv), this);
12911
13439
  this.player.forceDegradeToVideo = function() {
12912
13440
  var _this2$pluginExtensio;
@@ -12933,6 +13461,7 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
12933
13461
  this._transCoreEvent(EVENT$3.LOAD_RETRY);
12934
13462
  this._transCoreEvent(EVENT$3.SOURCEBUFFER_CREATED);
12935
13463
  this._transCoreEvent(EVENT$3.ANALYZE_DURATION_EXCEEDED);
13464
+ this._transCoreEvent(EVENT$3.APPEND_BUFFER);
12936
13465
  this._transCoreEvent(EVENT$3.REMOVE_BUFFER);
12937
13466
  this._transCoreEvent(EVENT$3.BUFFEREOS);
12938
13467
  this._transCoreEvent(EVENT$3.KEYFRAME);
@@ -13016,13 +13545,13 @@ function _toPropertyKey$5(t) {
13016
13545
  var i = _toPrimitive$5(t, "string");
13017
13546
  return "symbol" == typeof i ? i : String(i);
13018
13547
  }
13019
- function _typeof$8(o) {
13548
+ function _typeof$7(o) {
13020
13549
  "@babel/helpers - typeof";
13021
- return _typeof$8 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
13550
+ return _typeof$7 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
13022
13551
  return typeof o2;
13023
13552
  } : function(o2) {
13024
13553
  return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
13025
- }, _typeof$8(o);
13554
+ }, _typeof$7(o);
13026
13555
  }
13027
13556
  function _classCallCheck$f(instance, Constructor2) {
13028
13557
  if (!(instance instanceof Constructor2)) {
@@ -13389,7 +13918,7 @@ var abrAlgo = function() {
13389
13918
  } else {
13390
13919
  scriptDirectory = "";
13391
13920
  }
13392
- if (!((typeof window === "undefined" ? "undefined" : _typeof$8(window)) === "object" || typeof importScripts === "function"))
13921
+ if (!((typeof window === "undefined" ? "undefined" : _typeof$7(window)) === "object" || typeof importScripts === "function"))
13393
13922
  throw new Error("not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)");
13394
13923
  }
13395
13924
  var out = Module["print"] || console.log.bind(console);
@@ -24120,7 +24649,7 @@ var abrAlgo = function() {
24120
24649
  RuntimeError: Error
24121
24650
  };
24122
24651
  wasmBinary = [];
24123
- if (_typeof$8(WebAssembly2) !== "object") {
24652
+ if (_typeof$7(WebAssembly2) !== "object") {
24124
24653
  abort("no native wasm support detected");
24125
24654
  }
24126
24655
  var wasmMemory;
@@ -25930,7 +26459,7 @@ var Algo = /* @__PURE__ */ function() {
25930
26459
  }, {
25931
26460
  key: "updateDeviceInfo",
25932
26461
  value: function updateDeviceInfo() {
25933
- var devicePixelRatio = (typeof window === "undefined" ? "undefined" : _typeof$8(window)) === "object" ? window.devicePixelRatio || 1 : 1;
26462
+ var devicePixelRatio = (typeof window === "undefined" ? "undefined" : _typeof$7(window)) === "object" ? window.devicePixelRatio || 1 : 1;
25934
26463
  var _this$player$video$ge = this.player.video.getBoundingClientRect(), width = _this$player$video$ge.width, height = _this$player$video$ge.height;
25935
26464
  this.module._updateDeviceInfo(Math.floor(width), Math.floor(height), devicePixelRatio, 30);
25936
26465
  }
@@ -27165,14 +27694,6 @@ function _regeneratorRuntime$8() {
27165
27694
  }
27166
27695
  }, exports;
27167
27696
  }
27168
- function _typeof$7(obj) {
27169
- "@babel/helpers - typeof";
27170
- return _typeof$7 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
27171
- return typeof obj2;
27172
- } : function(obj2) {
27173
- return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
27174
- }, _typeof$7(obj);
27175
- }
27176
27697
  function asyncGeneratorStep$8(gen, resolve3, reject3, _next, _throw, key2, arg) {
27177
27698
  try {
27178
27699
  var info = gen[key2](arg);
@@ -27938,7 +28459,7 @@ function _arrayLikeToArray$a(arr, len) {
27938
28459
  arr2[i] = arr[i];
27939
28460
  return arr2;
27940
28461
  }
27941
- function _createForOfIteratorHelper$2(o, allowArrayLike) {
28462
+ function _createForOfIteratorHelper$3(o, allowArrayLike) {
27942
28463
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
27943
28464
  if (!it) {
27944
28465
  if (Array.isArray(o) || (it = _unsupportedIterableToArray$a(o)) || allowArrayLike && o && typeof o.length === "number") {
@@ -29219,7 +29740,7 @@ var XhrLoader$2 = /* @__PURE__ */ function(_EventEmitter) {
29219
29740
  value: function _getHeaders(xhr) {
29220
29741
  var headerLines = xhr.getAllResponseHeaders().trim().split("\r\n");
29221
29742
  var headers = {};
29222
- var _iterator = _createForOfIteratorHelper$2(headerLines), _step;
29743
+ var _iterator = _createForOfIteratorHelper$3(headerLines), _step;
29223
29744
  try {
29224
29745
  for (_iterator.s(); !(_step = _iterator.n()).done; ) {
29225
29746
  var header = _step.value;
@@ -29241,7 +29762,7 @@ var XhrLoader$2 = /* @__PURE__ */ function(_EventEmitter) {
29241
29762
  }]);
29242
29763
  return XhrLoader2;
29243
29764
  }(EventEmitter$1);
29244
- var _excluded$4 = ["retry", "retryDelay", "onRetryError", "transformError"];
29765
+ var _excluded$5 = ["retry", "retryDelay", "onRetryError", "transformError"];
29245
29766
  var Task$2 = /* @__PURE__ */ function() {
29246
29767
  function Task2(type, config) {
29247
29768
  _classCallCheck$d(this, Task2);
@@ -29261,7 +29782,7 @@ var Task$2 = /* @__PURE__ */ function() {
29261
29782
  key: "exec",
29262
29783
  value: function exec2() {
29263
29784
  var _this = this;
29264
- var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties$4(_this$_config, _excluded$4);
29785
+ var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties$4(_this$_config, _excluded$5);
29265
29786
  var request = /* @__PURE__ */ function() {
29266
29787
  var _ref = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee() {
29267
29788
  var response, error, isRetry;
@@ -30183,8 +30704,7 @@ function getOption(opts) {
30183
30704
  loadTimeout: 5e3,
30184
30705
  stallInterval: 400,
30185
30706
  networkEvaluateInterval: 1e3,
30186
- delayHint: 0,
30187
- seamlesslyReload: false
30707
+ delayHint: 0
30188
30708
  }, opts);
30189
30709
  }
30190
30710
  function _getStats(stats) {
@@ -30447,7 +30967,6 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
30447
30967
  _defineProperty$c(_assertThisInitialized$b(_this), "_audioTransceicer", null);
30448
30968
  _defineProperty$c(_assertThisInitialized$b(_this), "_videoTransceicer", null);
30449
30969
  _defineProperty$c(_assertThisInitialized$b(_this), "_mediaStream", null);
30450
- _defineProperty$c(_assertThisInitialized$b(_this), "_lastMediaStream", null);
30451
30970
  _defineProperty$c(_assertThisInitialized$b(_this), "_media", null);
30452
30971
  _defineProperty$c(_assertThisInitialized$b(_this), "_opts", null);
30453
30972
  _defineProperty$c(_assertThisInitialized$b(_this), "_loader", null);
@@ -30455,10 +30974,19 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
30455
30974
  _defineProperty$c(_assertThisInitialized$b(_this), "_retry", 0);
30456
30975
  _defineProperty$c(_assertThisInitialized$b(_this), "_waitingTimer", 0);
30457
30976
  _defineProperty$c(_assertThisInitialized$b(_this), "_rctConnectStartTs", 0);
30458
- _defineProperty$c(_assertThisInitialized$b(_this), "_isReplacing", false);
30459
30977
  _defineProperty$c(_assertThisInitialized$b(_this), "_onTrack", function(e) {
30460
30978
  logger$6.log("addTrack: ", e.track, e.streams);
30461
30979
  _this["_".concat(e.track.kind)] = e.track;
30980
+ if (!_this._mediaStream) {
30981
+ _this._mediaStream = new MediaStream();
30982
+ _this._media.srcObject = _this._mediaStream;
30983
+ var req = _this._media.play();
30984
+ if (req && req.catch) {
30985
+ req.catch(function(e2) {
30986
+ });
30987
+ }
30988
+ }
30989
+ _this._mediaStream.addTrack(e.track);
30462
30990
  });
30463
30991
  _defineProperty$c(_assertThisInitialized$b(_this), "_mockWaitingByTimeupdate", function() {
30464
30992
  var _this$_pc, _this$_pc2;
@@ -30506,9 +31034,6 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
30506
31034
  }));
30507
31035
  _this._retry = _this._opts.retryCount;
30508
31036
  _this._bindMediaEvent();
30509
- if (_this._opts.mediaStream && _this._opts.seamlesslyReload) {
30510
- _this._lastMediaStream = _this._opts.mediaStream;
30511
- }
30512
31037
  return _this;
30513
31038
  }
30514
31039
  _createClass$e(Rts2, [{
@@ -30552,9 +31077,9 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
30552
31077
  }, {
30553
31078
  key: "load",
30554
31079
  value: function() {
30555
- var _load = _asyncToGenerator$8(/* @__PURE__ */ _regeneratorRuntime$8().mark(function _callee(url, seamless) {
31080
+ var _load = _asyncToGenerator$8(/* @__PURE__ */ _regeneratorRuntime$8().mark(function _callee(url) {
30556
31081
  var _this2 = this;
30557
- var _this$_pc3;
31082
+ var lastPc;
30558
31083
  return _regeneratorRuntime$8().wrap(function _callee$(_context) {
30559
31084
  while (1)
30560
31085
  switch (_context.prev = _context.next) {
@@ -30562,43 +31087,39 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
30562
31087
  this._disconnect();
30563
31088
  this._url = url;
30564
31089
  this._retry = this._opts.retryCount;
30565
- if (seamless) {
30566
- this._lastPc = this._pc;
30567
- } else {
30568
- (_this$_pc3 = this._pc) === null || _this$_pc3 === void 0 ? void 0 : _this$_pc3.close();
31090
+ lastPc = this._pc;
31091
+ if (lastPc) {
31092
+ lastPc.close();
30569
31093
  }
30570
- _context.prev = 4;
31094
+ _context.prev = 5;
30571
31095
  this._pc = new RTCPeerConnection();
30572
31096
  this._bindRTCEvents();
30573
- _context.next = 9;
31097
+ _context.next = 10;
30574
31098
  return this._connect(url);
30575
- case 9:
30576
- _context.next = 14;
31099
+ case 10:
31100
+ _context.next = 15;
30577
31101
  break;
30578
- case 11:
30579
- _context.prev = 11;
30580
- _context.t0 = _context["catch"](4);
31102
+ case 12:
31103
+ _context.prev = 12;
31104
+ _context.t0 = _context["catch"](5);
30581
31105
  setTimeout(function() {
30582
31106
  return _this2._emitError(StreamingError$2.create(ERR$2.OTHER, null, _context.t0));
30583
31107
  });
30584
- case 14:
31108
+ case 15:
30585
31109
  case "end":
30586
31110
  return _context.stop();
30587
31111
  }
30588
- }, _callee, this, [[4, 11]]);
31112
+ }, _callee, this, [[5, 12]]);
30589
31113
  }));
30590
- function load(_x, _x2) {
31114
+ function load(_x) {
30591
31115
  return _load.apply(this, arguments);
30592
31116
  }
30593
31117
  return load;
30594
31118
  }()
30595
31119
  }, {
30596
31120
  key: "switchURL",
30597
- value: function switchURL(url, seamless) {
30598
- if (seamless) {
30599
- this._lastMediaStream = this._mediaStream;
30600
- }
30601
- this.load(url || this._url, seamless);
31121
+ value: function switchURL(url) {
31122
+ this.load(url || this._url);
30602
31123
  }
30603
31124
  }, {
30604
31125
  key: "_bindRTCEvents",
@@ -30624,8 +31145,6 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
30624
31145
  _this3.load(_this3._url);
30625
31146
  }
30626
31147
  if (pc.connectionState === "connected") {
30627
- _this3._closeLastPc();
30628
- _this3._handleMediaStream();
30629
31148
  _this3.emit(EVENT$2.TTFB, {
30630
31149
  url: _this3._url,
30631
31150
  responseUrl: _this3._url,
@@ -30634,40 +31153,6 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
30634
31153
  }
30635
31154
  });
30636
31155
  }
30637
- }, {
30638
- key: "_handleMediaStream",
30639
- value: function _handleMediaStream() {
30640
- var _this4 = this;
30641
- if (this._lastMediaStream) {
30642
- var _this$_media$play;
30643
- var videoTrack = this._lastMediaStream.getVideoTracks()[0];
30644
- var audioTrack = this._lastMediaStream.getAudioTracks()[0];
30645
- if (videoTrack) {
30646
- this._lastMediaStream.removeTrack(videoTrack);
30647
- }
30648
- if (audioTrack) {
30649
- this._lastMediaStream.removeTrack(audioTrack);
30650
- }
30651
- this._mediaStream = this._lastMediaStream;
30652
- this._mediaStream.addTrack(this._audio);
30653
- this._mediaStream.addTrack(this._video);
30654
- this._isReplacing = true;
30655
- this._media.pause();
30656
- (_this$_media$play = this._media.play()) === null || _this$_media$play === void 0 ? void 0 : _this$_media$play.finally(function() {
30657
- _this4._isReplacing = false;
30658
- });
30659
- } else {
30660
- this._mediaStream = new MediaStream();
30661
- this._mediaStream.addTrack(this._audio);
30662
- this._mediaStream.addTrack(this._video);
30663
- this._media.srcObject = this._mediaStream;
30664
- var req = this._media.play();
30665
- if (req && req.catch) {
30666
- req.catch(function(e) {
30667
- });
30668
- }
30669
- }
30670
- }
30671
31156
  }, {
30672
31157
  key: "_bindMediaEvent",
30673
31158
  value: function _bindMediaEvent() {
@@ -30822,14 +31307,6 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
30822
31307
  }
30823
31308
  return _connect;
30824
31309
  }()
30825
- }, {
30826
- key: "_closeLastPc",
30827
- value: function _closeLastPc() {
30828
- if (this._lastPc) {
30829
- this._lastPc.close();
30830
- this._lastPc = null;
30831
- }
30832
- }
30833
31310
  }, {
30834
31311
  key: "_disconnect",
30835
31312
  value: function _disconnect() {
@@ -30844,19 +31321,17 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
30844
31321
  }, {
30845
31322
  key: "_emitError",
30846
31323
  value: function _emitError(error) {
30847
- this._closeLastPc();
30848
31324
  this.emit(EVENT$2.ERROR, error);
30849
31325
  }
30850
31326
  }, {
30851
31327
  key: "destroy",
30852
31328
  value: function destroy() {
30853
- var _this$_media2, _this$_opts;
31329
+ var _this$_media2;
30854
31330
  this._disconnect();
30855
31331
  (_this$_media2 = this._media) === null || _this$_media2 === void 0 ? void 0 : _this$_media2.removeEventListener("timeupdate", this._mockWaitingByTimeupdate);
30856
- if (this._media && !((_this$_opts = this._opts) !== null && _this$_opts !== void 0 && _this$_opts.seamlesslyReload)) {
31332
+ if (this._media) {
30857
31333
  this._media.srcObject = null;
30858
31334
  }
30859
- this._closeLastPc();
30860
31335
  if (this._pc) {
30861
31336
  this._pc.close();
30862
31337
  }
@@ -30954,35 +31429,15 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
30954
31429
  }
30955
31430
  _this = _super.call.apply(_super, [this].concat(args));
30956
31431
  _defineProperty$c(_assertThisInitialized$b(_this), "_rts", null);
30957
- _defineProperty$c(_assertThisInitialized$b(_this), "_mediaStream", null);
30958
31432
  _defineProperty$c(_assertThisInitialized$b(_this), "_rtsOpts", null);
30959
- _defineProperty$c(_assertThisInitialized$b(_this), "_onPause", function() {
30960
- var _this$_rts, _this$_rts2, _this$config, _this$_rts4;
30961
- if (!((_this$_rts = _this._rts) !== null && _this$_rts !== void 0 && _this$_rts._pc) || (_this$_rts2 = _this._rts) !== null && _this$_rts2 !== void 0 && _this$_rts2._isReplacing) {
30962
- return;
30963
- }
30964
- if ((_this$config = _this.config) !== null && _this$config !== void 0 && _this$config.seamlesslyReload) {
30965
- var _this$_rts3;
30966
- _this._mediaStream = (_this$_rts3 = _this._rts) === null || _this$_rts3 === void 0 ? void 0 : _this$_rts3._mediaStream;
30967
- }
30968
- (_this$_rts4 = _this._rts) === null || _this$_rts4 === void 0 ? void 0 : _this$_rts4.destroy();
30969
- });
30970
- _defineProperty$c(_assertThisInitialized$b(_this), "_onPlay", function() {
30971
- var _this$_rts5, _this$_rts6;
30972
- if ((_this$_rts5 = _this._rts) !== null && _this$_rts5 !== void 0 && _this$_rts5._pc || (_this$_rts6 = _this._rts) !== null && _this$_rts6 !== void 0 && _this$_rts6._isReplacing) {
30973
- return;
30974
- }
30975
- _this._init();
30976
- });
30977
31433
  _defineProperty$c(_assertThisInitialized$b(_this), "_init", function() {
30978
- var _this$_rts7;
30979
- (_this$_rts7 = _this._rts) === null || _this$_rts7 === void 0 ? void 0 : _this$_rts7.destroy();
31434
+ var _this$_rts;
31435
+ (_this$_rts = _this._rts) === null || _this$_rts === void 0 ? void 0 : _this$_rts.destroy();
30980
31436
  var config = _this.player.config;
30981
31437
  var rtsOpts = config.rts || {};
30982
31438
  _this._rtsOpts = rtsOpts;
30983
31439
  _this._rts = new Rts(_objectSpread2$7({
30984
31440
  media: _this.player.video,
30985
- mediaStream: _this._mediaStream,
30986
31441
  preProcessUrl: function preProcessUrl(url, ext) {
30987
31442
  var _this$player$preProce, _this$player;
30988
31443
  return ((_this$player$preProce = (_this$player = _this.player).preProcessUrl) === null || _this$player$preProce === void 0 ? void 0 : _this$player$preProce.call(_this$player, url, ext)) || {
@@ -30993,39 +31448,36 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
30993
31448
  }, rtsOpts));
30994
31449
  _this._rts.load(config.url);
30995
31450
  });
30996
- _defineProperty$c(_assertThisInitialized$b(_this), "_onSwitchURL", function(url, seamless) {
31451
+ _defineProperty$c(_assertThisInitialized$b(_this), "_onSwitchURL", function(url) {
30997
31452
  if (_this._rts) {
30998
- if (_typeof$7(seamless) === "object") {
30999
- seamless = seamless.seamless;
31000
- }
31001
31453
  _this.player.config.url = url;
31002
- _this._rts.switchURL(url, seamless);
31454
+ _this._rts.switchURL(url);
31003
31455
  }
31004
31456
  });
31005
31457
  _defineProperty$c(_assertThisInitialized$b(_this), "destroy", function() {
31006
- var _this$_rts8;
31458
+ var _this$_rts2;
31007
31459
  _this.player.switchURL = _this._originSwitchFn;
31008
- (_this$_rts8 = _this._rts) === null || _this$_rts8 === void 0 ? void 0 : _this$_rts8.destroy();
31460
+ (_this$_rts2 = _this._rts) === null || _this$_rts2 === void 0 ? void 0 : _this$_rts2.destroy();
31009
31461
  });
31010
31462
  return _this;
31011
31463
  }
31012
31464
  _createClass$e(RtsPlugin2, [{
31013
31465
  key: "pc",
31014
31466
  get: function get3() {
31015
- var _this$_rts9;
31016
- return (_this$_rts9 = this._rts) === null || _this$_rts9 === void 0 ? void 0 : _this$_rts9.pc;
31467
+ var _this$_rts3;
31468
+ return (_this$_rts3 = this._rts) === null || _this$_rts3 === void 0 ? void 0 : _this$_rts3.pc;
31017
31469
  }
31018
31470
  }, {
31019
31471
  key: "videoTrack",
31020
31472
  get: function get3() {
31021
- var _this$_rts10;
31022
- return (_this$_rts10 = this._rts) === null || _this$_rts10 === void 0 ? void 0 : _this$_rts10.videoTack;
31473
+ var _this$_rts4;
31474
+ return (_this$_rts4 = this._rts) === null || _this$_rts4 === void 0 ? void 0 : _this$_rts4.videoTack;
31023
31475
  }
31024
31476
  }, {
31025
31477
  key: "audioTrack",
31026
31478
  get: function get3() {
31027
- var _this$_rts11;
31028
- return (_this$_rts11 = this._rts) === null || _this$_rts11 === void 0 ? void 0 : _this$_rts11.audioTrack;
31479
+ var _this$_rts5;
31480
+ return (_this$_rts5 = this._rts) === null || _this$_rts5 === void 0 ? void 0 : _this$_rts5.audioTrack;
31029
31481
  }
31030
31482
  }, {
31031
31483
  key: "core",
@@ -31035,18 +31487,18 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
31035
31487
  }, {
31036
31488
  key: "loader",
31037
31489
  get: function get3() {
31038
- var _this$_rts12;
31039
- return (_this$_rts12 = this._rts) === null || _this$_rts12 === void 0 ? void 0 : _this$_rts12.loader;
31490
+ var _this$_rts6;
31491
+ return (_this$_rts6 = this._rts) === null || _this$_rts6 === void 0 ? void 0 : _this$_rts6.loader;
31040
31492
  }
31041
31493
  }, {
31042
31494
  key: "version",
31043
31495
  get: function get3() {
31044
- return "0.2.1-alpha.4";
31496
+ return "0.2.1-alpha.0";
31045
31497
  }
31046
31498
  }, {
31047
31499
  key: "beforePlayerInit",
31048
31500
  value: function beforePlayerInit() {
31049
- var _this$player2, _this2 = this, _this$player$config, _this$player$config$r;
31501
+ var _this$player2, _this2 = this;
31050
31502
  this._init();
31051
31503
  if (!this._originSwitchFn) {
31052
31504
  this._originSwitchFn = this.player.switchURL.bind(this.player);
@@ -31058,10 +31510,6 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
31058
31510
  });
31059
31511
  this.on(URL_CHANGE, this._onSwitchURL);
31060
31512
  this.on(DESTROY, this.destroy);
31061
- if ((_this$player$config = this.player.config) !== null && _this$player$config !== void 0 && (_this$player$config$r = _this$player$config.rts) !== null && _this$player$config$r !== void 0 && _this$player$config$r.seamlesslyReload) {
31062
- this.on(PAUSE, this._onPause);
31063
- this.on(PLAY, this._onPlay);
31064
- }
31065
31513
  this._transErrorEvent();
31066
31514
  this._transCoreEvent(EVENT$2.LOAD_START);
31067
31515
  this._transCoreEvent(EVENT$2.LOAD_COMPLETE);
@@ -31091,20 +31539,20 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
31091
31539
  }, {
31092
31540
  key: "getStats",
31093
31541
  value: function getStats2() {
31094
- var _this$_rts13;
31095
- return (_this$_rts13 = this._rts) === null || _this$_rts13 === void 0 ? void 0 : _this$_rts13.getStats();
31542
+ var _this$_rts7;
31543
+ return (_this$_rts7 = this._rts) === null || _this$_rts7 === void 0 ? void 0 : _this$_rts7.getStats();
31096
31544
  }
31097
31545
  }, {
31098
31546
  key: "getStatsSnapshoot",
31099
31547
  value: function getStatsSnapshoot2() {
31100
- var _this$_rts14;
31101
- return (_this$_rts14 = this._rts) === null || _this$_rts14 === void 0 ? void 0 : _this$_rts14.getStatsSnapshoot();
31548
+ var _this$_rts8;
31549
+ return (_this$_rts8 = this._rts) === null || _this$_rts8 === void 0 ? void 0 : _this$_rts8.getStatsSnapshoot();
31102
31550
  }
31103
31551
  }, {
31104
31552
  key: "getNetWorkInfo",
31105
31553
  value: function getNetWorkInfo() {
31106
- var _this$_rts15;
31107
- return (_this$_rts15 = this._rts) === null || _this$_rts15 === void 0 ? void 0 : _this$_rts15.networkStats;
31554
+ var _this$_rts9;
31555
+ return (_this$_rts9 = this._rts) === null || _this$_rts9 === void 0 ? void 0 : _this$_rts9.networkStats;
31108
31556
  }
31109
31557
  }, {
31110
31558
  key: "_transErrorEvent",
@@ -32448,7 +32896,7 @@ function _arrayLikeToArray$8(arr, len) {
32448
32896
  arr2[i] = arr[i];
32449
32897
  return arr2;
32450
32898
  }
32451
- function _createForOfIteratorHelper$1(o, allowArrayLike) {
32899
+ function _createForOfIteratorHelper$2(o, allowArrayLike) {
32452
32900
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
32453
32901
  if (!it) {
32454
32902
  if (Array.isArray(o) || (it = _unsupportedIterableToArray$8(o)) || allowArrayLike && o && typeof o.length === "number") {
@@ -32636,6 +33084,21 @@ var Buffer$4 = /* @__PURE__ */ function() {
32636
33084
  length: Buffer22.totalLength && Buffer22.totalLength(buffers)
32637
33085
  };
32638
33086
  }
33087
+ }, {
33088
+ key: "isBuffered",
33089
+ value: function isBuffered(media, pos) {
33090
+ if (media) {
33091
+ var buffered = Buffer22.get(media);
33092
+ if (buffered !== null && buffered !== void 0 && buffered.length) {
33093
+ for (var i = 0; i < buffered.length; i++) {
33094
+ if (pos >= buffered.start(i) && pos <= buffered.end(i)) {
33095
+ return true;
33096
+ }
33097
+ }
33098
+ }
33099
+ }
33100
+ return false;
33101
+ }
32639
33102
  }]);
32640
33103
  return Buffer22;
32641
33104
  }();
@@ -32788,7 +33251,7 @@ var Logger$6 = /* @__PURE__ */ function() {
32788
33251
  this.logCache.apply(this, [LogCacheLevel.DEBUG].concat(args));
32789
33252
  if (Logger2.disabled)
32790
33253
  return;
32791
- (_console = console).debug.apply(_console, [this._prefix, nowTime$4()].concat(args));
33254
+ (_console = console).debug.apply(_console, ["[".concat(nowTime$4(), "]"), this._prefix].concat(args));
32792
33255
  }
32793
33256
  }, {
32794
33257
  key: "log",
@@ -32800,7 +33263,7 @@ var Logger$6 = /* @__PURE__ */ function() {
32800
33263
  this.logCache.apply(this, [LogCacheLevel.LOG].concat(args));
32801
33264
  if (Logger2.disabled)
32802
33265
  return;
32803
- (_console2 = console).log.apply(_console2, [this._prefix, nowTime$4()].concat(args));
33266
+ (_console2 = console).log.apply(_console2, ["[".concat(nowTime$4(), "]"), this._prefix].concat(args));
32804
33267
  }
32805
33268
  }, {
32806
33269
  key: "warn",
@@ -32812,7 +33275,7 @@ var Logger$6 = /* @__PURE__ */ function() {
32812
33275
  this.logCache.apply(this, [LogCacheLevel.WARN].concat(args));
32813
33276
  if (Logger2.disabled)
32814
33277
  return;
32815
- (_console3 = console).warn.apply(_console3, [this._prefix, nowTime$4()].concat(args));
33278
+ (_console3 = console).warn.apply(_console3, ["[".concat(nowTime$4(), "]"), this._prefix].concat(args));
32816
33279
  }
32817
33280
  }, {
32818
33281
  key: "error",
@@ -32824,7 +33287,7 @@ var Logger$6 = /* @__PURE__ */ function() {
32824
33287
  this.logCache.apply(this, [LogCacheLevel.ERROR].concat(args));
32825
33288
  if (Logger2.disabled)
32826
33289
  return;
32827
- (_console4 = console).error.apply(_console4, [this._prefix, nowTime$4()].concat(args));
33290
+ (_console4 = console).error.apply(_console4, ["[".concat(nowTime$4(), "]"), this._prefix].concat(args));
32828
33291
  }
32829
33292
  }, {
32830
33293
  key: "logCache",
@@ -32839,7 +33302,7 @@ var Logger$6 = /* @__PURE__ */ function() {
32839
33302
  var finLogText = logText.map(function(item) {
32840
33303
  return logable(item);
32841
33304
  });
32842
- text = this._prefix + nowTime$4() + JSON.stringify(finLogText);
33305
+ text = "[".concat(nowTime$4(), "]") + this._prefix + JSON.stringify(finLogText);
32843
33306
  } catch (e) {
32844
33307
  return;
32845
33308
  }
@@ -33755,8 +34218,8 @@ function createResponse$1(data2, done, response, contentLength, age, startTime,
33755
34218
  response
33756
34219
  };
33757
34220
  }
33758
- function calculateSpeed$1(byteLen, millisec) {
33759
- return Math.round(byteLen * 8 * 1e3 / millisec / 1024);
34221
+ function calculateSpeed$1(byteLen, milliSecond) {
34222
+ return Math.round(byteLen * 8 * 1e3 / milliSecond / 1024);
33760
34223
  }
33761
34224
  var EVENT$1 = {
33762
34225
  ERROR: "error",
@@ -33768,6 +34231,7 @@ var EVENT$1 = {
33768
34231
  SOURCEBUFFER_CREATED: "core.sourcebuffercreated",
33769
34232
  MEDIASOURCE_OPENED: "core.mediasourceopened",
33770
34233
  ANALYZE_DURATION_EXCEEDED: "core.analyzedurationexceeded",
34234
+ APPEND_BUFFER: "core.appendbuffer",
33771
34235
  REMOVE_BUFFER: "core.removebuffer",
33772
34236
  BUFFEREOS: "core.buffereos",
33773
34237
  KEYFRAME: "core.keyframe",
@@ -34540,7 +35004,7 @@ var XhrLoader$1 = /* @__PURE__ */ function(_EventEmitter) {
34540
35004
  value: function _getHeaders(xhr) {
34541
35005
  var headerLines = xhr.getAllResponseHeaders().trim().split("\r\n");
34542
35006
  var headers = {};
34543
- var _iterator = _createForOfIteratorHelper$1(headerLines), _step;
35007
+ var _iterator = _createForOfIteratorHelper$2(headerLines), _step;
34544
35008
  try {
34545
35009
  for (_iterator.s(); !(_step = _iterator.n()).done; ) {
34546
35010
  var header = _step.value;
@@ -34562,7 +35026,7 @@ var XhrLoader$1 = /* @__PURE__ */ function(_EventEmitter) {
34562
35026
  }]);
34563
35027
  return XhrLoader2;
34564
35028
  }(EventEmitter$1);
34565
- var _excluded$3 = ["retry", "retryDelay", "onRetryError", "transformError"];
35029
+ var _excluded$4 = ["retry", "retryDelay", "onRetryError", "transformError"];
34566
35030
  var Task$1 = /* @__PURE__ */ function() {
34567
35031
  function Task2(type, config) {
34568
35032
  _classCallCheck$b(this, Task2);
@@ -34582,7 +35046,7 @@ var Task$1 = /* @__PURE__ */ function() {
34582
35046
  key: "exec",
34583
35047
  value: function exec2() {
34584
35048
  var _this = this;
34585
- var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties$2(_this$_config, _excluded$3);
35049
+ var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties$2(_this$_config, _excluded$4);
34586
35050
  var request = /* @__PURE__ */ function() {
34587
35051
  var _ref = _asyncToGenerator$5(/* @__PURE__ */ _regeneratorRuntime$5().mark(function _callee() {
34588
35052
  var response, error, isRetry;
@@ -35378,6 +35842,60 @@ function _nonIterableSpread$6() {
35378
35842
  function _nonIterableRest$4() {
35379
35843
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
35380
35844
  }
35845
+ function _createForOfIteratorHelper$1(o, allowArrayLike) {
35846
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
35847
+ if (!it) {
35848
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray$7(o)) || allowArrayLike && o && typeof o.length === "number") {
35849
+ if (it)
35850
+ o = it;
35851
+ var i = 0;
35852
+ var F = function() {
35853
+ };
35854
+ return {
35855
+ s: F,
35856
+ n: function() {
35857
+ if (i >= o.length)
35858
+ return {
35859
+ done: true
35860
+ };
35861
+ return {
35862
+ done: false,
35863
+ value: o[i++]
35864
+ };
35865
+ },
35866
+ e: function(e) {
35867
+ throw e;
35868
+ },
35869
+ f: F
35870
+ };
35871
+ }
35872
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
35873
+ }
35874
+ var normalCompletion = true, didErr = false, err;
35875
+ return {
35876
+ s: function() {
35877
+ it = it.call(o);
35878
+ },
35879
+ n: function() {
35880
+ var step = it.next();
35881
+ normalCompletion = step.done;
35882
+ return step;
35883
+ },
35884
+ e: function(e) {
35885
+ didErr = true;
35886
+ err = e;
35887
+ },
35888
+ f: function() {
35889
+ try {
35890
+ if (!normalCompletion && it.return != null)
35891
+ it.return();
35892
+ } finally {
35893
+ if (didErr)
35894
+ throw err;
35895
+ }
35896
+ }
35897
+ };
35898
+ }
35381
35899
  function _toPrimitive(input, hint) {
35382
35900
  if (typeof input !== "object" || input === null)
35383
35901
  return input;
@@ -35400,13 +35918,15 @@ var TrackType$2 = {
35400
35918
  METADATA: "metadata"
35401
35919
  };
35402
35920
  var VideoCodecType$2 = {
35921
+ AV1: "av1",
35403
35922
  AVC: "avc",
35404
35923
  HEVC: "hevc"
35405
35924
  };
35406
35925
  var AudioCodecType$1 = {
35407
35926
  AAC: "aac",
35408
35927
  G711PCMA: "g7110a",
35409
- G711PCMU: "g7110m"
35928
+ G711PCMU: "g7110m",
35929
+ OPUS: "opus"
35410
35930
  };
35411
35931
  var WarningType = {
35412
35932
  LARGE_AV_SHIFT: "LARGE_AV_SHIFT",
@@ -35446,6 +35966,7 @@ var VideoTrack$1 = /* @__PURE__ */ function() {
35446
35966
  _defineProperty$8(this, "isVideoEncryption", false);
35447
35967
  _defineProperty$8(this, "isAudioEncryption", false);
35448
35968
  _defineProperty$8(this, "isVideo", true);
35969
+ _defineProperty$8(this, "lastKeyFrameDts", 0);
35449
35970
  _defineProperty$8(this, "kid", null);
35450
35971
  _defineProperty$8(this, "pssh", null);
35451
35972
  _defineProperty$8(this, "ext", void 0);
@@ -35488,6 +36009,9 @@ var VideoTrack$1 = /* @__PURE__ */ function() {
35488
36009
  }, {
35489
36010
  key: "exist",
35490
36011
  value: function exist() {
36012
+ if (/av01/.test(this.codec)) {
36013
+ return true;
36014
+ }
35491
36015
  return !!(this.pps.length && this.sps.length && this.codec);
35492
36016
  }
35493
36017
  }, {
@@ -35551,7 +36075,7 @@ var AudioTrack$1 = /* @__PURE__ */ function() {
35551
36075
  }, {
35552
36076
  key: "exist",
35553
36077
  value: function exist() {
35554
- return !!(this.sampleRate && this.channelCount && this.codec && this.codecType === AudioCodecType$1.AAC);
36078
+ return !!(this.sampleRate && this.channelCount && this.codec && (this.codecType === AudioCodecType$1.AAC || this.codecType === AudioCodecType$1.G711PCMA || this.codecType === AudioCodecType$1.G711PCMU || this.codecType === AudioCodecType$1.OPUS));
35555
36079
  }
35556
36080
  }, {
35557
36081
  key: "hasSample",
@@ -35756,7 +36280,7 @@ var AAC$1 = /* @__PURE__ */ function() {
35756
36280
  continue;
35757
36281
  }
35758
36282
  frameLength = (data2[i + 3] & 3) << 11 | data2[i + 4] << 3 | (data2[i + 5] & 224) >> 5;
35759
- if (len - i < frameLength)
36283
+ if (!frameLength || len - i < frameLength)
35760
36284
  break;
35761
36285
  protectionSkipBytes = (~data2[i + 1] & 1) * 2;
35762
36286
  frames.push({
@@ -35950,6 +36474,15 @@ function parse$2(a) {
35950
36474
  return parseInt(item, 16);
35951
36475
  });
35952
36476
  }
36477
+ function combineToFloat(integer, decimal) {
36478
+ return Number(integer + "." + decimal);
36479
+ }
36480
+ function toDegree(matrix) {
36481
+ if (matrix.length < 5)
36482
+ return 0;
36483
+ var scaled0 = Math.hypot(matrix[0], matrix[3]), scaled1 = Math.hypot(matrix[1], matrix[4]);
36484
+ return 0 === scaled0 || 0 === scaled1 ? 0 : 180 * Math.atan2(matrix[1] / scaled1, matrix[0] / scaled0) / Math.PI;
36485
+ }
35953
36486
  var NALu = /* @__PURE__ */ function() {
35954
36487
  function NALu2() {
35955
36488
  _classCallCheck$a(this, NALu2);
@@ -36612,13 +37145,16 @@ var MAX_SILENT_FRAME_DURATION = 9e4;
36612
37145
  var AUDIO_EXCETION_LOG_EMIT_DURATION = 5 * 9e4;
36613
37146
  var MAX_VIDEO_FRAME_DURATION = 9e4;
36614
37147
  var MAX_DTS_DELTA_WITH_NEXT_CHUNK = 9e4 / 2;
37148
+ var LARGE_AV_FIRST_FRAME_FORCE_FIX_THRESHOLD = 9e4 * 5;
36615
37149
  var TsFixer = /* @__PURE__ */ function() {
36616
- function TsFixer2(videoTrack, audioTrack, metadataTrack) {
37150
+ function TsFixer2(videoTrack, audioTrack, metadataTrack, fixerConfig) {
36617
37151
  _classCallCheck$a(this, TsFixer2);
36618
37152
  this.videoTrack = videoTrack;
36619
37153
  this.audioTrack = audioTrack;
36620
37154
  this.metadataTrack = metadataTrack;
36621
37155
  this._baseDts = -1;
37156
+ this._baseVideoDts = -1;
37157
+ this._baseAudioDts = -1;
36622
37158
  this._baseDtsInited = false;
36623
37159
  this._audioNextPts = void 0;
36624
37160
  this._videoNextDts = void 0;
@@ -36627,6 +37163,8 @@ var TsFixer = /* @__PURE__ */ function() {
36627
37163
  this._lastAudioExceptionGapDot = 0;
36628
37164
  this._lastAudioExceptionOverlapDot = 0;
36629
37165
  this._lastAudioExceptionLargeGapDot = 0;
37166
+ this._needForceFixLargeGap = fixerConfig === null || fixerConfig === void 0 ? void 0 : fixerConfig.forceFixLargeGap;
37167
+ this._largeGapThreshold = (fixerConfig === null || fixerConfig === void 0 ? void 0 : fixerConfig.largeGapThreshold) || LARGE_AV_FIRST_FRAME_FORCE_FIX_THRESHOLD;
36630
37168
  }
36631
37169
  _createClass$a(TsFixer2, [{
36632
37170
  key: "fix",
@@ -36654,10 +37192,16 @@ var TsFixer = /* @__PURE__ */ function() {
36654
37192
  if (discontinuity) {
36655
37193
  this._calculateBaseDts(this.audioTrack, this.videoTrack);
36656
37194
  this._baseDts -= startTime;
37195
+ this._baseAudioDts -= startTime;
37196
+ this._baseVideoDts -= startTime;
36657
37197
  }
36658
37198
  if (!contiguous) {
36659
37199
  this._videoNextDts = vaDelta > 0 ? startTime + vaDelta : startTime;
36660
37200
  this._audioNextPts = vaDelta > 0 ? startTime : startTime - vaDelta;
37201
+ if (this._needForceFixLargeGap) {
37202
+ this._videoNextDts = 0;
37203
+ this._audioNextPts = 0;
37204
+ }
36661
37205
  var vDeltaToNextDts = firstVideoSample ? firstVideoSample.dts - this._baseDts - this._videoNextDts : 0;
36662
37206
  var aDeltaToNextDts = firstAudioSample ? firstAudioSample.pts - this._baseDts - this._audioNextPts : 0;
36663
37207
  if (Math.abs(vDeltaToNextDts || aDeltaToNextDts) > MAX_VIDEO_FRAME_DURATION) {
@@ -36690,8 +37234,8 @@ var TsFixer = /* @__PURE__ */ function() {
36690
37234
  if (!samples.length)
36691
37235
  return;
36692
37236
  samples.forEach(function(x2) {
36693
- x2.dts -= _this2._baseDts;
36694
- x2.pts -= _this2._baseDts;
37237
+ x2.dts -= _this2._needForceFixLargeGap ? _this2._baseVideoDts : _this2._baseDts;
37238
+ x2.pts -= _this2._needForceFixLargeGap ? _this2._baseVideoDts : _this2._baseDts;
36695
37239
  });
36696
37240
  if (this._videoNextDts === void 0) {
36697
37241
  var samp0 = samples[0];
@@ -36784,7 +37328,7 @@ var TsFixer = /* @__PURE__ */ function() {
36784
37328
  if (!samples.length)
36785
37329
  return;
36786
37330
  samples.forEach(function(x2) {
36787
- x2.pts -= _this3._baseDts;
37331
+ x2.pts -= _this3._needForceFixLargeGap ? _this3._baseAudioDts : _this3._baseDts;
36788
37332
  x2.dts = x2.pts;
36789
37333
  });
36790
37334
  this._doFixAudioInternal(audioTrack, samples, 9e4);
@@ -36801,12 +37345,15 @@ var TsFixer = /* @__PURE__ */ function() {
36801
37345
  var videoBaseDts = Infinity;
36802
37346
  if (audioSamps.length) {
36803
37347
  audioTrack.baseDts = audioBasePts = audioSamps[0].pts;
37348
+ this._baseAudioDts = audioBasePts;
36804
37349
  }
36805
37350
  if (videoSamps.length) {
36806
37351
  videoTrack.baseDts = videoBaseDts = videoSamps[0].dts;
37352
+ this._baseVideoDts = videoBaseDts;
36807
37353
  }
36808
37354
  this._baseDts = Math.min(audioBasePts, videoBaseDts);
36809
37355
  var delta = videoBaseDts - audioBasePts;
37356
+ var largeGap = false;
36810
37357
  if (Number.isFinite(delta) && Math.abs(delta) > LARGE_AV_FIRST_FRAME_GAP) {
36811
37358
  videoTrack.warnings.push({
36812
37359
  type: WarningType.LARGE_AV_SHIFT,
@@ -36816,6 +37363,16 @@ var TsFixer = /* @__PURE__ */ function() {
36816
37363
  delta
36817
37364
  });
36818
37365
  }
37366
+ if (Number.isFinite(delta) && Math.abs(delta) > this._largeGapThreshold * MAX_SILENT_FRAME_DURATION) {
37367
+ largeGap = true;
37368
+ }
37369
+ if (!this._baseDtsInited) {
37370
+ if (largeGap && this._needForceFixLargeGap) {
37371
+ this._needForceFixLargeGap = true;
37372
+ } else {
37373
+ this._needForceFixLargeGap = false;
37374
+ }
37375
+ }
36819
37376
  this._baseDtsInited = true;
36820
37377
  return true;
36821
37378
  }
@@ -36909,6 +37466,7 @@ var TsFixer = /* @__PURE__ */ function() {
36909
37466
  var logger$5 = new Logger$5("TsDemuxer");
36910
37467
  var TsDemuxer = /* @__PURE__ */ function() {
36911
37468
  function TsDemuxer2(videoTrack, audioTrack, metadataTrack) {
37469
+ var fixerConfig = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
36912
37470
  _classCallCheck$a(this, TsDemuxer2);
36913
37471
  _defineProperty$8(this, "_pmtId", -1);
36914
37472
  _defineProperty$8(this, "_remainingPacketData", null);
@@ -36918,7 +37476,7 @@ var TsDemuxer = /* @__PURE__ */ function() {
36918
37476
  this.videoTrack = videoTrack || new VideoTrack$1();
36919
37477
  this.audioTrack = audioTrack || new AudioTrack$1();
36920
37478
  this.metadataTrack = metadataTrack || new MetadataTrack$1();
36921
- this._fixer = new TsFixer(this.videoTrack, this.audioTrack, this.metadataTrack);
37479
+ this._fixer = new TsFixer(this.videoTrack, this.audioTrack, this.metadataTrack, fixerConfig);
36922
37480
  }
36923
37481
  _createClass$a(TsDemuxer2, [{
36924
37482
  key: "demux",
@@ -37265,6 +37823,207 @@ var TsDemuxer = /* @__PURE__ */ function() {
37265
37823
  }]);
37266
37824
  return TsDemuxer2;
37267
37825
  }();
37826
+ var ByteReader = /* @__PURE__ */ function() {
37827
+ function ByteReader2(buf, offset, len) {
37828
+ _classCallCheck$a(this, ByteReader2);
37829
+ this.dv = new DataView(buf);
37830
+ this.start = this.offset = offset || this.dv.byteOffset;
37831
+ this.end = len ? this.start + len : this.start + this.dv.byteLength;
37832
+ }
37833
+ _createClass$a(ByteReader2, [{
37834
+ key: "buffer",
37835
+ get: function get3() {
37836
+ return this.dv.buffer;
37837
+ }
37838
+ }, {
37839
+ key: "unreadLength",
37840
+ get: function get3() {
37841
+ return Math.max(this.end - this.offset, 0);
37842
+ }
37843
+ }, {
37844
+ key: "size",
37845
+ get: function get3() {
37846
+ return this.end - this.start;
37847
+ }
37848
+ }, {
37849
+ key: "readFloat",
37850
+ value: function readFloat(byteNum) {
37851
+ var val = 0;
37852
+ switch (byteNum) {
37853
+ case 4:
37854
+ val = this.dv.getFloat32(this.offset);
37855
+ break;
37856
+ case 8:
37857
+ val = this.dv.getFloat64(this.offset);
37858
+ break;
37859
+ default:
37860
+ throw new Error("read ".concat(byteNum, "-byte float is not supported"));
37861
+ }
37862
+ this.offset += byteNum;
37863
+ return val;
37864
+ }
37865
+ }, {
37866
+ key: "back",
37867
+ value: function back(byteNum) {
37868
+ this.offset -= byteNum;
37869
+ }
37870
+ }, {
37871
+ key: "skip",
37872
+ value: function skip(byteNum) {
37873
+ this.offset += byteNum;
37874
+ }
37875
+ }, {
37876
+ key: "readInt",
37877
+ value: function readInt(byteNum) {
37878
+ var offset = this.offset;
37879
+ this.offset += byteNum;
37880
+ switch (byteNum) {
37881
+ case 1:
37882
+ return this.dv.getInt8(offset);
37883
+ case 2:
37884
+ return this.dv.getInt16(offset);
37885
+ case 4:
37886
+ return this.dv.getInt32(offset);
37887
+ default:
37888
+ throw new Error("read ".concat(byteNum, "-byte integers is not supported"));
37889
+ }
37890
+ }
37891
+ }, {
37892
+ key: "read",
37893
+ value: function read(byteNum) {
37894
+ var offset = this.offset;
37895
+ this.offset += byteNum;
37896
+ switch (byteNum) {
37897
+ case 1:
37898
+ return this.dv.getUint8(offset);
37899
+ case 2:
37900
+ return this.dv.getUint16(offset);
37901
+ case 3:
37902
+ return (this.dv.getUint16(offset) << 8) + this.dv.getUint8(offset + 2);
37903
+ case 4:
37904
+ return this.dv.getUint32(offset);
37905
+ default:
37906
+ this.back(byteNum - 4);
37907
+ return this.read(byteNum - 4) + this.dv.getUint32(offset) * Math.pow(256, byteNum - 4);
37908
+ }
37909
+ }
37910
+ }, {
37911
+ key: "write",
37912
+ value: function write(byteNum, val) {
37913
+ var offset = this.offset;
37914
+ this.offset += byteNum;
37915
+ switch (byteNum) {
37916
+ case 1:
37917
+ return this.dv.setUint8(offset, val);
37918
+ case 2:
37919
+ return this.dv.setUint16(offset, val);
37920
+ case 3:
37921
+ return this.dv.setUint8(offset, val >>> 16), this.dv.setUint16(offset + 1, 65535 & val);
37922
+ case 4:
37923
+ return this.dv.setUint32(offset, val);
37924
+ default:
37925
+ throw new Error("write ".concat(byteNum, "-byte integers is not supported"));
37926
+ }
37927
+ }
37928
+ }, {
37929
+ key: "readToBuffer",
37930
+ value: function readToBuffer(len) {
37931
+ var buffer;
37932
+ if (this.offset || len) {
37933
+ buffer = this.dv.buffer.slice(this.offset, len ? this.offset + len : this.end);
37934
+ } else {
37935
+ buffer = this.dv.buffer;
37936
+ }
37937
+ this.offset += buffer.byteLength;
37938
+ return buffer;
37939
+ }
37940
+ }, {
37941
+ key: "readToUint8",
37942
+ value: function readToUint8(len) {
37943
+ var uint8 = new Uint8Array(this.dv.buffer, this.offset, len || this.unreadLength);
37944
+ this.offset += uint8.byteLength;
37945
+ return uint8;
37946
+ }
37947
+ }, {
37948
+ key: "readString",
37949
+ value: function readString(len) {
37950
+ var i = 0, str2 = "";
37951
+ for (; i < len; i++) {
37952
+ str2 += String.fromCharCode(this.dv.getUint8(this.offset));
37953
+ this.offset++;
37954
+ }
37955
+ return str2;
37956
+ }
37957
+ }], [{
37958
+ key: "fromUint8",
37959
+ value: function fromUint8(uint8) {
37960
+ return new ByteReader2(uint8.buffer, uint8.byteOffset, uint8.byteLength);
37961
+ }
37962
+ }, {
37963
+ key: "concatUint8s",
37964
+ value: function concatUint8s(args) {
37965
+ var uint8 = new Uint8Array(args.reduce(function(ret, v) {
37966
+ return ret + v.byteLength;
37967
+ }, 0));
37968
+ var offset = 0;
37969
+ args.forEach(function(v) {
37970
+ uint8.set(v, offset);
37971
+ offset += v.byteLength;
37972
+ });
37973
+ return uint8;
37974
+ }
37975
+ }, {
37976
+ key: "concatUint8",
37977
+ value: function concatUint8() {
37978
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
37979
+ args[_key] = arguments[_key];
37980
+ }
37981
+ return this.concatUint8s(args);
37982
+ }
37983
+ }]);
37984
+ return ByteReader2;
37985
+ }();
37986
+ var BitReader = /* @__PURE__ */ function() {
37987
+ function BitReader2(val, size) {
37988
+ _classCallCheck$a(this, BitReader2);
37989
+ this.offset = 0;
37990
+ this.val = val;
37991
+ this.size = size;
37992
+ }
37993
+ _createClass$a(BitReader2, [{
37994
+ key: "skip",
37995
+ value: function skip(len) {
37996
+ this.offset += len;
37997
+ }
37998
+ }, {
37999
+ key: "read",
38000
+ value: function read(len) {
38001
+ var unreadLength = this.size - this.offset - len;
38002
+ if (unreadLength >= 0) {
38003
+ var bits = 0, i = 0;
38004
+ this.offset += len;
38005
+ if (this.size > 31) {
38006
+ for (; i < len; i++) {
38007
+ bits += Math.pow(2, i);
38008
+ }
38009
+ return this.val / Math.pow(2, unreadLength) & bits;
38010
+ } else {
38011
+ for (; i < len; i++) {
38012
+ bits += 1 << i;
38013
+ }
38014
+ return this.val >>> unreadLength & bits;
38015
+ }
38016
+ }
38017
+ throw new Error("the number of the read operation exceeds the total length limit of bits");
38018
+ }
38019
+ }], [{
38020
+ key: "fromByte",
38021
+ value: function fromByte(byte, len) {
38022
+ return new BitReader2(byte.read(len), len << 3);
38023
+ }
38024
+ }]);
38025
+ return BitReader2;
38026
+ }();
37268
38027
  var MP4Parser$1 = /* @__PURE__ */ function() {
37269
38028
  function MP4Parser2() {
37270
38029
  _classCallCheck$a(this, MP4Parser2);
@@ -37422,18 +38181,36 @@ var MP4Parser$1 = /* @__PURE__ */ function() {
37422
38181
  key: "tkhd",
37423
38182
  value: function tkhd(box) {
37424
38183
  return parseBox$1(box, true, function(ret, data2) {
37425
- var start = 0;
38184
+ var byte = ByteReader.fromUint8(data2);
37426
38185
  if (ret.version === 1) {
37427
- ret.trackId = readBig32$1(data2, 16);
37428
- ret.duration = readBig64$1(data2, 24);
37429
- start += 32;
38186
+ byte.read(8);
38187
+ byte.read(8);
38188
+ ret.trackId = byte.read(4);
38189
+ byte.read(4);
38190
+ ret.duration = byte.read(8);
37430
38191
  } else {
37431
- ret.trackId = readBig32$1(data2, 8);
37432
- ret.duration = readBig32$1(data2, 16);
37433
- start += 20;
38192
+ byte.read(4);
38193
+ byte.read(4);
38194
+ ret.trackId = byte.read(4);
38195
+ byte.read(4);
38196
+ ret.duration = byte.read(4);
38197
+ }
38198
+ byte.skip(16);
38199
+ ret.matrix = [];
38200
+ for (var i = 0; i < 36; i++) {
38201
+ ret.matrix.push(byte.read(1));
38202
+ }
38203
+ byte.back(36);
38204
+ var caculatedMatrix = [];
38205
+ for (var _i = 0, int32; _i < 3; _i++) {
38206
+ caculatedMatrix.push(combineToFloat(byte.readInt(2), byte.readInt(2)));
38207
+ caculatedMatrix.push(combineToFloat(byte.readInt(2), byte.readInt(2)));
38208
+ int32 = byte.readInt(4);
38209
+ caculatedMatrix.push(combineToFloat(int32 >> 30, int32 & 1073741823));
37434
38210
  }
37435
- ret.width = readBig32$1(data2, start + 52);
37436
- ret.height = readBig32$1(data2, start + 56);
38211
+ ret.rotation = toDegree(caculatedMatrix);
38212
+ ret.width = byte.read(4);
38213
+ ret.height = byte.read(4);
37437
38214
  });
37438
38215
  }
37439
38216
  }, {
@@ -37563,7 +38340,7 @@ var MP4Parser$1 = /* @__PURE__ */ function() {
37563
38340
  if (ret.version > 0) {
37564
38341
  var numKeyIds = readBig32$1(data2, start);
37565
38342
  start += 4;
37566
- for (var _i = 0; _i < ("" + numKeyIds).length; _i++) {
38343
+ for (var _i2 = 0; _i2 < ("" + numKeyIds).length; _i2++) {
37567
38344
  for (var j = 0; j < 16; j++) {
37568
38345
  var keyId = data2[start];
37569
38346
  start += 1;
@@ -37586,6 +38363,8 @@ var MP4Parser$1 = /* @__PURE__ */ function() {
37586
38363
  ret.entryCount = readBig32$1(data2);
37587
38364
  ret.entries = MP4Parser2.findBox(data2.subarray(4), [], start + 4).map(function(b) {
37588
38365
  switch (b.type) {
38366
+ case "av01":
38367
+ return MP4Parser2.av01(b);
37589
38368
  case "avc1":
37590
38369
  case "avc2":
37591
38370
  case "avc3":
@@ -37665,6 +38444,69 @@ var MP4Parser$1 = /* @__PURE__ */ function() {
37665
38444
  }
37666
38445
  });
37667
38446
  }
38447
+ }, {
38448
+ key: "colr",
38449
+ value: function colr(box) {
38450
+ return parseBox$1(box, false, function(ret, data2) {
38451
+ var byte = ByteReader.fromUint8(data2);
38452
+ ret.data = box.data;
38453
+ ret.colorType = byte.readString(4);
38454
+ if (ret.colorType === "nclx") {
38455
+ ret.colorPrimaries = byte.read(2);
38456
+ ret.transferCharacteristics = byte.read(2);
38457
+ ret.matrixCoefficients = byte.read(2);
38458
+ ret.fullRangeFlag = byte.read(1) >> 7;
38459
+ } else if (ret.colorType === "rICC" || ret.colorType === "prof") {
38460
+ ret.iccProfile = data2.readToUint8();
38461
+ }
38462
+ });
38463
+ }
38464
+ }, {
38465
+ key: "av01",
38466
+ value: function av01(box) {
38467
+ return parseBox$1(box, false, function(ret, data2, start) {
38468
+ var bodyStart = parseVisualSampleEntry$1(ret, data2);
38469
+ var bodyData = data2.subarray(bodyStart);
38470
+ start += bodyStart;
38471
+ ret.av1C = MP4Parser2.av1C(MP4Parser2.findBox(bodyData, ["av1C"], start)[0]);
38472
+ ret.colr = MP4Parser2.colr(MP4Parser2.findBox(bodyData, ["colr"], start)[0]);
38473
+ });
38474
+ }
38475
+ }, {
38476
+ key: "av1C",
38477
+ value: function av1C(box) {
38478
+ return parseBox$1(box, false, function(ret, data2) {
38479
+ ret.data = box.data;
38480
+ var byte = ByteReader.fromUint8(data2);
38481
+ var bit = BitReader.fromByte(byte, 4);
38482
+ ret.marker = bit.read(1);
38483
+ ret.version = bit.read(7);
38484
+ ret.seqProfile = bit.read(3);
38485
+ ret.seqLevelIdx0 = bit.read(5);
38486
+ ret.seqTier0 = bit.read(1);
38487
+ ret.highBitdepth = bit.read(1);
38488
+ ret.twelveBit = bit.read(1);
38489
+ ret.monochrome = bit.read(1);
38490
+ ret.chromaSubsamplingX = bit.read(1);
38491
+ ret.chromaSubsamplingY = bit.read(1);
38492
+ ret.chromaSamplePosition = bit.read(2);
38493
+ ret.reserved = bit.read(3);
38494
+ ret.initialPresentationDelayPresent = bit.read(1);
38495
+ if (ret.initialPresentationDelayPresent) {
38496
+ ret.initialPresentationDelayMinusOne = bit.read(4);
38497
+ } else {
38498
+ ret.initialPresentationDelayMinusOne = 0;
38499
+ }
38500
+ ret.configOBUs = byte.readToUint8();
38501
+ var bitdepth;
38502
+ if (ret.seqLevelIdx0 === 2 && ret.highBitdepth === 1) {
38503
+ bitdepth = ret.twelveBit === 1 ? "12" : "10";
38504
+ } else if (ret.seqProfile <= 2) {
38505
+ bitdepth = ret.highBitdepth === 1 ? "10" : "08";
38506
+ }
38507
+ ret.codec = ["av01", ret.seqProfile, (ret.seqLevelIdx0 < 10 ? "0" + ret.seqLevelIdx0 : ret.seqLevelIdx0) + (ret.seqTier0 ? "H" : "M"), bitdepth].join(".");
38508
+ });
38509
+ }
37668
38510
  }, {
37669
38511
  key: "avc1",
37670
38512
  value: function avc1(box) {
@@ -37699,7 +38541,7 @@ var MP4Parser$1 = /* @__PURE__ */ function() {
37699
38541
  ret.ppsLength = data2[start];
37700
38542
  start += 1;
37701
38543
  ret.pps = [];
37702
- for (var _i2 = 0; _i2 < ret.ppsLength; _i2++) {
38544
+ for (var _i3 = 0; _i3 < ret.ppsLength; _i3++) {
37703
38545
  var _size = readBig16$1(data2, start);
37704
38546
  start += 2;
37705
38547
  ret.pps.push(data2.subarray(start, start += _size));
@@ -37868,7 +38710,7 @@ var MP4Parser$1 = /* @__PURE__ */ function() {
37868
38710
  start += 8;
37869
38711
  }
37870
38712
  } else {
37871
- for (var _i3 = 0; _i3 < entryCount; _i3++) {
38713
+ for (var _i4 = 0; _i4 < entryCount; _i4++) {
37872
38714
  entries5.push({
37873
38715
  count: readBig32$1(data2, start),
37874
38716
  offset: -(~readBig32$1(data2, start + 4) + 1)
@@ -38090,13 +38932,20 @@ var MP4Parser$1 = /* @__PURE__ */ function() {
38090
38932
  v.mvhdTimecale = moov.mvhd.timescale;
38091
38933
  v.timescale = v.formatTimescale = vTrack.mdia.mdhd.timescale;
38092
38934
  v.duration = vTrack.mdia.mdhd.duration || v.mvhdDurtion / v.mvhdTimecale * v.timescale;
38935
+ v.rotation = vTrack.tkhd.rotation;
38936
+ v.matrix = vTrack.tkhd.matrix;
38093
38937
  var e1 = vTrack.mdia.minf.stbl.stsd.entries[0];
38094
38938
  v.width = e1.width;
38095
38939
  v.height = e1.height;
38096
38940
  if (e1.pasp) {
38097
38941
  v.sarRatio = [e1.pasp.hSpacing, e1.pasp.vSpacing];
38098
38942
  }
38099
- if (e1.hvcC) {
38943
+ if (e1.av1C) {
38944
+ v.codecType = VideoCodecType$2.AV1;
38945
+ v.codec = e1.av1C.codec;
38946
+ v.av1C = e1.av1C.data;
38947
+ v.colr = e1.colr.data;
38948
+ } else if (e1.hvcC) {
38100
38949
  v.codecType = VideoCodecType$2.HEVC;
38101
38950
  v.codec = e1.hvcC.codec;
38102
38951
  v.vps = e1.hvcC.vps;
@@ -38415,8 +39264,9 @@ function parseAudioSampleEntry$1(ret, data2) {
38415
39264
  function parseBox$1(box, isFullBox, parse4) {
38416
39265
  if (!box)
38417
39266
  return;
38418
- if (box.size !== box.data.length)
39267
+ if (box.size !== box.data.length) {
38419
39268
  throw new Error("box ".concat(box.type, " size !== data.length"));
39269
+ }
38420
39270
  var ret = {
38421
39271
  start: box.start,
38422
39272
  size: box.size,
@@ -38455,11 +39305,167 @@ var toHex$1 = function toHex2() {
38455
39305
  var FMP4Demuxer = /* @__PURE__ */ function() {
38456
39306
  function FMP4Demuxer2(videoTrack, audioTrack, metadataTrack) {
38457
39307
  _classCallCheck$a(this, FMP4Demuxer2);
39308
+ _defineProperty$8(this, "__loadedMoofWraps", []);
39309
+ _defineProperty$8(this, "__lastRemainData", null);
39310
+ _defineProperty$8(this, "__lastRemainDataStart", 0);
39311
+ _defineProperty$8(this, "__nextMoofStart", -1);
38458
39312
  this.videoTrack = videoTrack || new VideoTrack$1();
38459
39313
  this.audioTrack = audioTrack || new AudioTrack$1();
38460
39314
  this.metadataTrack = metadataTrack || new MetadataTrack$1();
38461
39315
  }
38462
39316
  _createClass$a(FMP4Demuxer2, [{
39317
+ key: "demuxPart",
39318
+ value: function demuxPart(partData, partDataStart, moov) {
39319
+ var _this = this;
39320
+ var videoTrack = this.videoTrack, audioTrack = this.audioTrack;
39321
+ var videoExist = videoTrack.exist();
39322
+ var audioExist = audioTrack.exist();
39323
+ var isAV01 = /av01/.test(videoTrack.codec);
39324
+ videoTrack.samples = [];
39325
+ audioTrack.samples = [];
39326
+ var data2 = partData;
39327
+ var dataStart = partDataStart;
39328
+ if (this.__lastRemainData) {
39329
+ var lastRemainDataEnd = this.__lastRemainDataStart + this.__lastRemainData.byteLength;
39330
+ var continuous = partDataStart <= lastRemainDataEnd && partDataStart > this.__lastRemainDataStart && partDataStart + partData.byteLength > lastRemainDataEnd;
39331
+ if (continuous) {
39332
+ var noDuplicateData = partData.subarray(this.__lastRemainData.byteLength + this.__lastRemainDataStart - partDataStart);
39333
+ data2 = concatUint8Array$3(this.__lastRemainData, noDuplicateData);
39334
+ dataStart = this.__lastRemainDataStart;
39335
+ this.__lastRemainData = null;
39336
+ } else {
39337
+ this.__lastRemainData = null;
39338
+ this.__lastRemainDataStart = 0;
39339
+ this.__nextMoofStart = -1;
39340
+ }
39341
+ }
39342
+ if (!moov) {
39343
+ var moovBox = MP4Parser$1.findBox(data2, ["moov"])[0];
39344
+ if (!moovBox)
39345
+ throw new Error("cannot found moov box");
39346
+ moov = MP4Parser$1.moov(moovBox);
39347
+ }
39348
+ if (data2) {
39349
+ var dataEnd = dataStart + data2.byteLength;
39350
+ if (!videoExist && !audioExist) {
39351
+ MP4Parser$1.moovToTrack(moov, videoTrack, audioTrack);
39352
+ }
39353
+ var moofBoxes = [];
39354
+ if (this.__nextMoofStart < 0) {
39355
+ MP4Parser$1.findBox(data2, ["moof"], dataStart).forEach(function(v) {
39356
+ return moofBoxes.push(v);
39357
+ });
39358
+ } else if (this.__nextMoofStart >= dataStart && this.__nextMoofStart <= dataEnd - 8) {
39359
+ MP4Parser$1.findBox(data2.subarray(this.__nextMoofStart - dataStart), ["moof"], this.__nextMoofStart).forEach(function(v) {
39360
+ return moofBoxes.push(v);
39361
+ });
39362
+ }
39363
+ moofBoxes.filter(function(moofBox) {
39364
+ return moofBox.size <= moofBox.data.length;
39365
+ }).forEach(function(moofBox) {
39366
+ var moof = MP4Parser$1.moof(moofBox);
39367
+ _this.__nextMoofStart = moof.start + Math.max.apply(Math, _toConsumableArray$6(moof.traf.map(function(v) {
39368
+ return v.trun.samples.reduce(function(ret, w) {
39369
+ return ret + w.size;
39370
+ }, v.trun.dataOffset || 0);
39371
+ })));
39372
+ _this.__loadedMoofWraps.push({
39373
+ start: moof.start,
39374
+ nextMoofStart: _this.__nextMoofStart,
39375
+ moof
39376
+ });
39377
+ _this.__loadedMoofWraps.sort(function(p, n) {
39378
+ return p.start - n.start;
39379
+ });
39380
+ });
39381
+ var _iterator = _createForOfIteratorHelper$1(this.__loadedMoofWraps), _step;
39382
+ try {
39383
+ var _loop = function _loop2() {
39384
+ var moofWrap = _step.value;
39385
+ if (moofWrap.start > dataEnd || moofWrap.nextMoofStart < dataStart) {
39386
+ return "continue";
39387
+ }
39388
+ var moofStart = moofWrap.start;
39389
+ var tracks = MP4Parser$1.moofToSamples(moofWrap.moof, videoTrack, audioTrack);
39390
+ var videoBaseMediaDecodeTime = videoTrack.baseMediaDecodeTime;
39391
+ var audioBaseMediaDecodeTime = audioTrack.baseMediaDecodeTime;
39392
+ var nalSize;
39393
+ Object.keys(tracks).forEach(function(k) {
39394
+ if (videoTrack.id == k) {
39395
+ tracks[k].some(function(x2) {
39396
+ var xStart = x2.offset += moofStart;
39397
+ if (xStart < dataStart) {
39398
+ return;
39399
+ }
39400
+ if (xStart + x2.size > dataEnd) {
39401
+ return true;
39402
+ }
39403
+ var sample = new VideoSample$1((x2.pts || x2.dts) + videoBaseMediaDecodeTime, x2.dts + videoBaseMediaDecodeTime);
39404
+ sample.duration = x2.duration;
39405
+ sample.gopId = x2.gopId;
39406
+ if (x2.keyframe)
39407
+ sample.setToKeyframe();
39408
+ var sampleData = data2.subarray(xStart - dataStart, xStart - dataStart + x2.size);
39409
+ sample.data = sampleData;
39410
+ if (!isAV01) {
39411
+ var start = 0;
39412
+ var len = sampleData.length - 1;
39413
+ while (start < len) {
39414
+ nalSize = readBig32$1(sampleData, start);
39415
+ start += 4;
39416
+ sample.units.push(sampleData.subarray(start, start + nalSize));
39417
+ start += nalSize;
39418
+ }
39419
+ }
39420
+ _this.__lastRemainDataStart = xStart + x2.size;
39421
+ videoTrack.samples.push(sample);
39422
+ });
39423
+ } else if (audioTrack.id == k) {
39424
+ tracks[k].some(function(x2) {
39425
+ var xStart = x2.offset + moofStart;
39426
+ if (xStart < dataStart) {
39427
+ return;
39428
+ }
39429
+ if (xStart + x2.size > dataEnd) {
39430
+ return true;
39431
+ }
39432
+ var sampleData = data2.subarray(xStart - dataStart, xStart - dataStart + x2.size);
39433
+ audioTrack.samples.push(new AudioSample$1(x2.dts + audioBaseMediaDecodeTime, sampleData, x2.duration));
39434
+ _this.__lastRemainDataStart = xStart + x2.size;
39435
+ });
39436
+ }
39437
+ });
39438
+ };
39439
+ for (_iterator.s(); !(_step = _iterator.n()).done; ) {
39440
+ var _ret = _loop();
39441
+ if (_ret === "continue")
39442
+ continue;
39443
+ }
39444
+ } catch (err) {
39445
+ _iterator.e(err);
39446
+ } finally {
39447
+ _iterator.f();
39448
+ }
39449
+ }
39450
+ if (this.__lastRemainDataStart > dataStart && this.__lastRemainDataStart < data2.byteLength + dataStart) {
39451
+ this.__lastRemainData = data2.subarray(this.__lastRemainDataStart - dataStart);
39452
+ } else {
39453
+ this.__lastRemainData = data2;
39454
+ this.__lastRemainDataStart = dataStart;
39455
+ }
39456
+ if (videoTrack.samples.length) {
39457
+ videoTrack.baseMediaDecodeTime = videoTrack.samples[0].pts;
39458
+ }
39459
+ if (audioTrack.samples.length) {
39460
+ audioTrack.baseMediaDecodeTime = audioTrack.samples[0].pts;
39461
+ }
39462
+ return {
39463
+ videoTrack,
39464
+ audioTrack,
39465
+ metadataTrack: this.metadataTrack
39466
+ };
39467
+ }
39468
+ }, {
38463
39469
  key: "demux",
38464
39470
  value: function demux(videoData, audioData) {
38465
39471
  var videoTrack = this.videoTrack, audioTrack = this.audioTrack;
@@ -38951,10 +39957,16 @@ var MP4$3 = /* @__PURE__ */ function() {
38951
39957
  if (track.useEME && track.enca) {
38952
39958
  content = MP42.enca(track);
38953
39959
  } else {
38954
- content = MP42.mp4a(track);
39960
+ if (track.codecType === AudioCodecType$1.OPUS) {
39961
+ content = MP42.opus(track);
39962
+ } else {
39963
+ content = MP42.mp4a(track);
39964
+ }
38955
39965
  }
38956
39966
  } else if (track.useEME && track.encv) {
38957
39967
  content = MP42.encv(track);
39968
+ } else if (track.av1C) {
39969
+ content = MP42.av01(track);
38958
39970
  } else {
38959
39971
  content = MP42.avc1hev1(track);
38960
39972
  }
@@ -39167,6 +40179,90 @@ var MP4$3 = /* @__PURE__ */ function() {
39167
40179
  var schi = MP42.schi(data2);
39168
40180
  return MP42.box(MP42.types.sinf, content, MP42.box(MP42.types.frma, frma), MP42.box(MP42.types.schm, schm), schi);
39169
40181
  }
40182
+ }, {
40183
+ key: "av01",
40184
+ value: function av01(track) {
40185
+ return MP42.box(MP42.types.av01, new Uint8Array([
40186
+ 0,
40187
+ 0,
40188
+ 0,
40189
+ 0,
40190
+ 0,
40191
+ 0,
40192
+ 0,
40193
+ 1,
40194
+ 0,
40195
+ 0,
40196
+ 0,
40197
+ 0,
40198
+ 0,
40199
+ 0,
40200
+ 0,
40201
+ 0,
40202
+ 0,
40203
+ 0,
40204
+ 0,
40205
+ 0,
40206
+ 0,
40207
+ 0,
40208
+ 0,
40209
+ 0,
40210
+ track.width >> 8 & 255,
40211
+ track.width & 255,
40212
+ track.height >> 8 & 255,
40213
+ track.height & 255,
40214
+ 0,
40215
+ 72,
40216
+ 0,
40217
+ 0,
40218
+ 0,
40219
+ 72,
40220
+ 0,
40221
+ 0,
40222
+ 0,
40223
+ 0,
40224
+ 0,
40225
+ 0,
40226
+ 0,
40227
+ 1,
40228
+ 0,
40229
+ 0,
40230
+ 0,
40231
+ 0,
40232
+ 0,
40233
+ 0,
40234
+ 0,
40235
+ 0,
40236
+ 0,
40237
+ 0,
40238
+ 0,
40239
+ 0,
40240
+ 0,
40241
+ 0,
40242
+ 0,
40243
+ 0,
40244
+ 0,
40245
+ 0,
40246
+ 0,
40247
+ 0,
40248
+ 0,
40249
+ 0,
40250
+ 0,
40251
+ 0,
40252
+ 0,
40253
+ 0,
40254
+ 0,
40255
+ 0,
40256
+ 0,
40257
+ 0,
40258
+ 0,
40259
+ 0,
40260
+ 0,
40261
+ 24,
40262
+ 17,
40263
+ 17
40264
+ ]), track.av1C, track.colr);
40265
+ }
39170
40266
  }, {
39171
40267
  key: "avc1hev1",
39172
40268
  value: function avc1hev1(track) {
@@ -39537,6 +40633,53 @@ var MP4$3 = /* @__PURE__ */ function() {
39537
40633
  )));
39538
40634
  return esds2;
39539
40635
  }
40636
+ }, {
40637
+ key: "opus",
40638
+ value: function opus(track) {
40639
+ var opusAudioDescription = new Uint8Array([
40640
+ 0,
40641
+ 0,
40642
+ 0,
40643
+ 0,
40644
+ 0,
40645
+ 0,
40646
+ 0,
40647
+ 1,
40648
+ 0,
40649
+ 0,
40650
+ 0,
40651
+ 0,
40652
+ 0,
40653
+ 0,
40654
+ 0,
40655
+ 0,
40656
+ 0,
40657
+ track.channelCount,
40658
+ 0,
40659
+ 16,
40660
+ 0,
40661
+ 0,
40662
+ 0,
40663
+ 0,
40664
+ track.sampleRate >> 8 & 255,
40665
+ track.sampleRate & 255,
40666
+ 0,
40667
+ 0
40668
+ ]);
40669
+ var opusSpecificConfig = track.config.length ? MP42.dOps(track) : [];
40670
+ return MP42.box(MP42.types.Opus, opusAudioDescription, opusSpecificConfig);
40671
+ }
40672
+ }, {
40673
+ key: "dOps",
40674
+ value: function dOps(track) {
40675
+ if (track.config) {
40676
+ track.config[4] = track.sampleRate >>> 24 & 255;
40677
+ track.config[5] = track.sampleRate >>> 16 & 255;
40678
+ track.config[6] = track.sampleRate >>> 8 & 255;
40679
+ track.config[7] = track.sampleRate & 255;
40680
+ return MP42.box(MP42.types.dOps, track.config);
40681
+ }
40682
+ }
39540
40683
  }, {
39541
40684
  key: "mvex",
39542
40685
  value: function mvex(tracks) {
@@ -40139,7 +41282,7 @@ var MP4$3 = /* @__PURE__ */ function() {
40139
41282
  }]);
40140
41283
  return MP42;
40141
41284
  }();
40142
- _defineProperty$8(MP4$3, "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) {
41285
+ _defineProperty$8(MP4$3, "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) {
40143
41286
  p[c] = [c.charCodeAt(0), c.charCodeAt(1), c.charCodeAt(2), c.charCodeAt(3)];
40144
41287
  return p;
40145
41288
  }, /* @__PURE__ */ Object.create(null)));
@@ -40474,30 +41617,46 @@ var FMP4Remuxer$2 = /* @__PURE__ */ function() {
40474
41617
  };
40475
41618
  }
40476
41619
  var samples = track.samples;
41620
+ var isAV01 = /av01/.test(track.codec);
40477
41621
  var mdatSize = 0;
40478
- samples.forEach(function(s) {
40479
- mdatSize += s.units.reduce(function(t, c) {
40480
- return t + c.byteLength;
40481
- }, 0);
40482
- mdatSize += s.units.length * 4;
40483
- });
40484
- var mdata = new Uint8Array(mdatSize);
40485
- var mdatView = new DataView(mdata.buffer);
40486
- var _loop = function _loop2(_offset, _sample) {
40487
- _sample = samples[i];
40488
- var sampleSize = 0;
40489
- _sample.units.forEach(function(u) {
40490
- mdatView.setUint32(_offset, u.byteLength);
40491
- _offset += 4;
40492
- mdata.set(u, _offset);
40493
- _offset += u.byteLength;
40494
- sampleSize += 4 + u.byteLength;
41622
+ if (isAV01) {
41623
+ samples.forEach(function(s) {
41624
+ mdatSize += s.data.byteLength;
40495
41625
  });
40496
- _sample.size = sampleSize;
40497
- offset = _offset, sample = _sample;
40498
- };
40499
- for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
40500
- _loop(offset, sample);
41626
+ } else {
41627
+ samples.forEach(function(s) {
41628
+ mdatSize += s.units.reduce(function(t, c) {
41629
+ return t + c.byteLength;
41630
+ }, 0);
41631
+ mdatSize += s.units.length * 4;
41632
+ });
41633
+ }
41634
+ var mdata = new Uint8Array(mdatSize);
41635
+ if (isAV01) {
41636
+ for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
41637
+ sample = samples[i];
41638
+ mdata.set(sample.data, offset);
41639
+ sample.size = sample.data.byteLength;
41640
+ offset += sample.size;
41641
+ }
41642
+ } else {
41643
+ var mdatView = new DataView(mdata.buffer);
41644
+ var _loop = function _loop2(_offset2, _sample2) {
41645
+ _sample2 = samples[_i];
41646
+ var sampleSize = 0;
41647
+ _sample2.units.forEach(function(u) {
41648
+ mdatView.setUint32(_offset2, u.byteLength);
41649
+ _offset2 += 4;
41650
+ mdata.set(u, _offset2);
41651
+ _offset2 += u.byteLength;
41652
+ sampleSize += 4 + u.byteLength;
41653
+ });
41654
+ _sample2.size = sampleSize;
41655
+ _offset = _offset2, _sample = _sample2;
41656
+ };
41657
+ for (var _i = 0, _l = samples.length, _offset = 0, _sample; _i < _l; _i++) {
41658
+ _loop(_offset, _sample);
41659
+ }
40501
41660
  }
40502
41661
  var mdat = MP4$3.mdat(mdata);
40503
41662
  var moof = MP4$3.moof([track]);
@@ -40656,11 +41815,11 @@ var Event$1 = _objectSpread2$5(_objectSpread2$5({}, EVENT$1), {}, {
40656
41815
  });
40657
41816
  var logger$4 = new Logger$6("Transmuxer");
40658
41817
  var Transmuxer = /* @__PURE__ */ function() {
40659
- function Transmuxer2(hls, isMP4, needRemux) {
41818
+ function Transmuxer2(hls, isMP4, needRemux, fixerConfig) {
40660
41819
  _classCallCheck$c(this, Transmuxer2);
40661
41820
  _defineProperty$a(this, "_initSegmentId", "");
40662
41821
  this.hls = hls;
40663
- this._demuxer = isMP4 ? new FMP4Demuxer() : new TsDemuxer();
41822
+ this._demuxer = isMP4 ? new FMP4Demuxer() : new TsDemuxer(null, null, null, fixerConfig);
40664
41823
  this._isMP4 = isMP4;
40665
41824
  if (needRemux)
40666
41825
  this._remuxer = new FMP4Remuxer$2(this._demuxer.videoTrack, this._demuxer.audioTrack);
@@ -40815,7 +41974,7 @@ var Transmuxer = /* @__PURE__ */ function() {
40815
41974
  }]);
40816
41975
  return Transmuxer2;
40817
41976
  }();
40818
- var _excluded$2 = ["data"], _excluded2 = ["data"];
41977
+ var _excluded$3 = ["data"], _excluded2 = ["data"];
40819
41978
  var logger$3 = new Logger$6("BufferService");
40820
41979
  var BufferService = /* @__PURE__ */ function() {
40821
41980
  function BufferService2(hls) {
@@ -40927,11 +42086,11 @@ var BufferService = /* @__PURE__ */ function() {
40927
42086
  return;
40928
42087
  if (TsDemuxer.probe(chunk)) {
40929
42088
  if (!this._transmuxer)
40930
- this._transmuxer = new Transmuxer(this.hls, false, !this._softVideo);
42089
+ this._transmuxer = new Transmuxer(this.hls, false, !this._softVideo, this.hls.config.fixerConfig);
40931
42090
  } else if (MP4Parser$1.probe(chunk)) {
40932
42091
  if (this._softVideo) {
40933
42092
  if (!this._transmuxer)
40934
- this._transmuxer = new Transmuxer(this.hls, true);
42093
+ this._transmuxer = new Transmuxer(this.hls, true, null, this.hls.config.fixerConfig);
40935
42094
  } else {
40936
42095
  this._directAppend = true;
40937
42096
  var mix = false;
@@ -40981,7 +42140,8 @@ var BufferService = /* @__PURE__ */ function() {
40981
42140
  key: "appendBuffer",
40982
42141
  value: function() {
40983
42142
  var _appendBuffer = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee2(segment, audioSegment, videoChunk, audioChunk, discontinuity, contiguous, startTime) {
40984
- var p, needInit, _this$_transmuxer$tra, _this$_transmuxer$tra2, video, audio, isFirstAppend, mse, _p, videoData, videoRest, audioData, audioRest;
42143
+ var _this2 = this;
42144
+ var afterAppend, p, needInit, _this$_transmuxer$tra, _this$_transmuxer$tra2, video, audio, isFirstAppend, mse, _p, videoData, videoRest, audioData, audioRest;
40985
42145
  return _regeneratorRuntime$6().wrap(function _callee2$(_context2) {
40986
42146
  while (1)
40987
42147
  switch (_context2.prev = _context2.next) {
@@ -40992,8 +42152,18 @@ var BufferService = /* @__PURE__ */ function() {
40992
42152
  }
40993
42153
  return _context2.abrupt("return");
40994
42154
  case 2:
42155
+ afterAppend = function afterAppend2() {
42156
+ var _this2$hls;
42157
+ if ((_this2$hls = _this2.hls) !== null && _this2$hls !== void 0 && _this2$hls.emit) {
42158
+ var _this2$hls2;
42159
+ (_this2$hls2 = _this2.hls) === null || _this2$hls2 === void 0 ? void 0 : _this2$hls2.emit(EVENT$1.APPEND_BUFFER, {
42160
+ start: segment.start,
42161
+ end: segment.end
42162
+ });
42163
+ }
42164
+ };
40995
42165
  if (!this._directAppend) {
40996
- _context2.next = 7;
42166
+ _context2.next = 8;
40997
42167
  break;
40998
42168
  }
40999
42169
  p = [];
@@ -41001,8 +42171,8 @@ var BufferService = /* @__PURE__ */ function() {
41001
42171
  p.push(this._mse.append(MSE$2.VIDEO, videoChunk));
41002
42172
  if (audioChunk)
41003
42173
  p.push(this._mse.append(MSE$2.AUDIO, audioChunk));
41004
- return _context2.abrupt("return", Promise.all(p));
41005
- case 7:
42174
+ return _context2.abrupt("return", Promise.all(p).then(afterAppend));
42175
+ case 8:
41006
42176
  needInit = this._needInitSegment || discontinuity;
41007
42177
  _this$_transmuxer$tra = this._transmuxer.transmux(videoChunk, audioChunk, needInit, contiguous, startTime, this._needInitSegment || discontinuity), _this$_transmuxer$tra2 = _slicedToArray$5(_this$_transmuxer$tra, 2), video = _this$_transmuxer$tra2[0], audio = _this$_transmuxer$tra2[1];
41008
42178
  if (audioChunk && audioSegment) {
@@ -41018,16 +42188,17 @@ var BufferService = /* @__PURE__ */ function() {
41018
42188
  this.hls.emit(Event$1.NO_AUDIO_TRACK);
41019
42189
  }
41020
42190
  if (!this._softVideo) {
41021
- _context2.next = 18;
42191
+ _context2.next = 20;
41022
42192
  break;
41023
42193
  }
41024
42194
  this._softVideo.appendBuffer(video, audio);
41025
42195
  this._needInitSegment = false;
41026
- _context2.next = 28;
42196
+ afterAppend();
42197
+ _context2.next = 30;
41027
42198
  break;
41028
- case 18:
42199
+ case 20:
41029
42200
  if (!this._mse) {
41030
- _context2.next = 28;
42201
+ _context2.next = 30;
41031
42202
  break;
41032
42203
  }
41033
42204
  isFirstAppend = !this._sourceCreated;
@@ -41043,15 +42214,15 @@ var BufferService = /* @__PURE__ */ function() {
41043
42214
  });
41044
42215
  }
41045
42216
  if (video) {
41046
- videoData = video.data, videoRest = _objectWithoutProperties$3(video, _excluded$2);
42217
+ videoData = video.data, videoRest = _objectWithoutProperties$3(video, _excluded$3);
41047
42218
  _p.push(mse.append(MSE$2.VIDEO, videoData, videoRest));
41048
42219
  }
41049
42220
  if (audio) {
41050
42221
  audioData = audio.data, audioRest = _objectWithoutProperties$3(audio, _excluded2);
41051
42222
  _p.push(mse.append(MSE$2.AUDIO, audioData, audioRest));
41052
42223
  }
41053
- return _context2.abrupt("return", Promise.all(_p));
41054
- case 28:
42224
+ return _context2.abrupt("return", Promise.all(_p).then(afterAppend));
42225
+ case 30:
41055
42226
  case "end":
41056
42227
  return _context2.stop();
41057
42228
  }
@@ -41066,7 +42237,7 @@ var BufferService = /* @__PURE__ */ function() {
41066
42237
  key: "removeBuffer",
41067
42238
  value: function() {
41068
42239
  var _removeBuffer = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee3() {
41069
- var _this2 = this;
42240
+ var _this3 = this;
41070
42241
  var start, end, media, _args3 = arguments;
41071
42242
  return _regeneratorRuntime$6().wrap(function _callee3$(_context3) {
41072
42243
  while (1)
@@ -41082,7 +42253,7 @@ var BufferService = /* @__PURE__ */ function() {
41082
42253
  return _context3.abrupt("return");
41083
42254
  case 5:
41084
42255
  return _context3.abrupt("return", this._mse.clearBuffer(start, end).then(function() {
41085
- return _this2.hls.emit(EVENT$1.REMOVE_BUFFER, {
42256
+ return _this3.hls.emit(EVENT$1.REMOVE_BUFFER, {
41086
42257
  start,
41087
42258
  end,
41088
42259
  removeEnd: end
@@ -41263,30 +42434,51 @@ var BufferService = /* @__PURE__ */ function() {
41263
42434
  return setLiveSeekableRange;
41264
42435
  }()
41265
42436
  }, {
41266
- key: "destroy",
42437
+ key: "detachMedia",
41267
42438
  value: function() {
41268
- var _destroy = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee9() {
41269
- var _this$_decryptor;
42439
+ var _detachMedia = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee9() {
41270
42440
  return _regeneratorRuntime$6().wrap(function _callee9$(_context9) {
41271
42441
  while (1)
41272
42442
  switch (_context9.prev = _context9.next) {
41273
42443
  case 0:
41274
- (_this$_decryptor = this._decryptor) === null || _this$_decryptor === void 0 ? void 0 : _this$_decryptor.destroy();
41275
42444
  if (!this._mse) {
41276
- _context9.next = 4;
42445
+ _context9.next = 3;
41277
42446
  break;
41278
42447
  }
41279
- _context9.next = 4;
42448
+ _context9.next = 3;
41280
42449
  return this._mse.unbindMedia();
41281
- case 4:
42450
+ case 3:
42451
+ case "end":
42452
+ return _context9.stop();
42453
+ }
42454
+ }, _callee9, this);
42455
+ }));
42456
+ function detachMedia() {
42457
+ return _detachMedia.apply(this, arguments);
42458
+ }
42459
+ return detachMedia;
42460
+ }()
42461
+ }, {
42462
+ key: "destroy",
42463
+ value: function() {
42464
+ var _destroy = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee10() {
42465
+ var _this$_decryptor;
42466
+ return _regeneratorRuntime$6().wrap(function _callee10$(_context10) {
42467
+ while (1)
42468
+ switch (_context10.prev = _context10.next) {
42469
+ case 0:
42470
+ (_this$_decryptor = this._decryptor) === null || _this$_decryptor === void 0 ? void 0 : _this$_decryptor.destroy();
42471
+ _context10.next = 3;
42472
+ return this.detachMedia();
42473
+ case 3:
41282
42474
  this._decryptor = null;
41283
42475
  this._mse = null;
41284
42476
  this._softVideo = null;
41285
- case 7:
42477
+ case 6:
41286
42478
  case "end":
41287
- return _context9.stop();
42479
+ return _context10.stop();
41288
42480
  }
41289
- }, _callee9, this);
42481
+ }, _callee10, this);
41290
42482
  }));
41291
42483
  function destroy() {
41292
42484
  return _destroy.apply(this, arguments);
@@ -41374,7 +42566,11 @@ function getConfig$2(cfg) {
41374
42566
  minSegmentsStartPlay: 3,
41375
42567
  preferMMS: false,
41376
42568
  preferMMSStreaming: false,
41377
- mseLowLatency: true
42569
+ mseLowLatency: true,
42570
+ fixerConfig: {
42571
+ forceFixLargeGap: false,
42572
+ largeGapThreshold: 5
42573
+ }
41378
42574
  }, cfg), {}, {
41379
42575
  media
41380
42576
  });
@@ -41489,6 +42685,8 @@ var MediaPlaylist = /* @__PURE__ */ _createClass$c(function MediaPlaylist2() {
41489
42685
  _defineProperty$a(this, "lowLatency", false);
41490
42686
  _defineProperty$a(this, "endPartIndex", 0);
41491
42687
  _defineProperty$a(this, "segments", []);
42688
+ _defineProperty$a(this, "dateRanges", {});
42689
+ _defineProperty$a(this, "skippedSegments", 0);
41492
42690
  });
41493
42691
  var MediaSegment = /* @__PURE__ */ function() {
41494
42692
  function MediaSegment2(parentUrl) {
@@ -41660,6 +42858,38 @@ function getCodecs(type, codecs) {
41660
42858
  }
41661
42859
  }
41662
42860
  }
42861
+ function isValidDaterange(attr, dateRangeWithSameId) {
42862
+ var _badValueForSameId;
42863
+ if (dateRangeWithSameId) {
42864
+ for (var key2 in dateRangeWithSameId) {
42865
+ if (Object.prototype.hasOwnProperty.call(dateRangeWithSameId, key2) && attr[key2] !== dateRangeWithSameId[key2]) {
42866
+ _badValueForSameId = key2;
42867
+ break;
42868
+ }
42869
+ }
42870
+ }
42871
+ var duration = null;
42872
+ if (attr.DURATION) {
42873
+ duration = parseFloat(attr.DURATION);
42874
+ if (!Number.isFinite(duration)) {
42875
+ duration = null;
42876
+ } else if (attr._endDate) {
42877
+ duration = (attr._endDate.getTime() - attr._startDate.getTime()) / 1e3;
42878
+ }
42879
+ }
42880
+ var cue = enumeratedStringList(attr.CUE || attr["X-CUE"], {
42881
+ pre: false,
42882
+ post: false,
42883
+ once: false
42884
+ });
42885
+ 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);
42886
+ }
42887
+ function enumeratedStringList(attrValue, dict) {
42888
+ return (attrValue ? attrValue.split(/[ ,]+/) : []).reduce(function(result, identifier) {
42889
+ result[identifier.toLowerCase()] = true;
42890
+ return result;
42891
+ }, dict);
42892
+ }
41663
42893
  function parseMasterPlaylist(lines, parentUrl) {
41664
42894
  var master = new MasterPlaylist();
41665
42895
  var index2 = 0;
@@ -41768,9 +42998,6 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
41768
42998
  var endOfList = false;
41769
42999
  var partSegmentIndex = 0;
41770
43000
  while (line = lines[index2++]) {
41771
- if (endOfList) {
41772
- break;
41773
- }
41774
43001
  if (line[0] !== "#") {
41775
43002
  if (media.lowLatency) {
41776
43003
  curSN++;
@@ -41824,11 +43051,6 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
41824
43051
  break;
41825
43052
  case "ENDLIST":
41826
43053
  {
41827
- var _lastSegment = media.segments[media.segments.length - 1];
41828
- if (_lastSegment) {
41829
- _lastSegment.isLast = true;
41830
- }
41831
- media.live = false;
41832
43054
  endOfList = true;
41833
43055
  }
41834
43056
  break;
@@ -41925,6 +43147,29 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
41925
43147
  curSegment = new MediaSegment(parentUrl);
41926
43148
  }
41927
43149
  break;
43150
+ case "SKIP":
43151
+ {
43152
+ var _attr5 = parseAttr(data2);
43153
+ var skippedSegments = parseInt(_attr5["SKIPPED-SEGMENTS"], 10);
43154
+ if (skippedSegments <= Number.MAX_SAFE_INTEGER) {
43155
+ media.skippedSegments += skippedSegments;
43156
+ }
43157
+ }
43158
+ break;
43159
+ case "DATERANGE":
43160
+ {
43161
+ var _attr6 = parseAttr(data2);
43162
+ var dateRangeWithSameId = media.dateRanges[_attr6.ID];
43163
+ _attr6._startDate = dateRangeWithSameId ? dateRangeWithSameId._startDate : new Date(_attr6["START-DATE"]);
43164
+ var endDate = (dateRangeWithSameId === null || dateRangeWithSameId === void 0 ? void 0 : dateRangeWithSameId._endDate) || new Date(_attr6.END_DATE);
43165
+ if (Number.isFinite(endDate)) {
43166
+ _attr6._endDate = endDate;
43167
+ }
43168
+ if (isValidDaterange(_attr6, dateRangeWithSameId) || media.skippedSegments) {
43169
+ media.dateRanges[_attr6.ID] = _attr6;
43170
+ }
43171
+ }
43172
+ break;
41928
43173
  }
41929
43174
  }
41930
43175
  media.segments = media.segments.filter(function(x2) {
@@ -41932,11 +43177,14 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
41932
43177
  });
41933
43178
  var lastSegment = media.segments[media.segments.length - 1];
41934
43179
  if (lastSegment) {
41935
- media.endSN = lastSegment.sn;
41936
- media.endPartIndex = lastSegment.partIndex;
41937
- if (endOfList && !lastSegment.isLast) {
43180
+ if (endOfList) {
41938
43181
  lastSegment.isLast = true;
41939
43182
  }
43183
+ media.endSN = lastSegment.sn;
43184
+ media.endPartIndex = lastSegment.partIndex;
43185
+ }
43186
+ if (endOfList) {
43187
+ media.live = false;
41940
43188
  }
41941
43189
  media.totalDuration = totalDuration;
41942
43190
  media.endCC = curCC;
@@ -43033,7 +44281,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
43033
44281
  _defineProperty$a(_assertThisInitialized$9(_this), "_switchUrlOpts", null);
43034
44282
  _defineProperty$a(_assertThisInitialized$9(_this), "_isProcessQuotaExceeded", false);
43035
44283
  _defineProperty$a(_assertThisInitialized$9(_this), "_loadSegment", /* @__PURE__ */ _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee() {
43036
- var nextSeg, _assertThisInitialize, config, bInfo, bufferThroughout;
44284
+ var _this$_playlist, nextSegment, lastSegment, _assertThisInitialize, config, minFrameDuration, maxBufferThroughout, bInfo, bufferThroughout;
43037
44285
  return _regeneratorRuntime$6().wrap(function _callee$(_context) {
43038
44286
  while (1)
43039
44287
  switch (_context.prev = _context.next) {
@@ -43044,42 +44292,44 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
43044
44292
  }
43045
44293
  return _context.abrupt("return");
43046
44294
  case 2:
43047
- nextSeg = _this._playlist.nextSegment;
44295
+ _this$_playlist = _this._playlist, nextSegment = _this$_playlist.nextSegment, lastSegment = _this$_playlist.lastSegment;
43048
44296
  _assertThisInitialize = _assertThisInitialized$9(_this), config = _assertThisInitialize.config;
43049
- if (nextSeg) {
43050
- _context.next = 6;
44297
+ minFrameDuration = 0.016;
44298
+ maxBufferThroughout = Math.min(Math.max((lastSegment === null || lastSegment === void 0 ? void 0 : lastSegment.duration) - minFrameDuration / 2 || 0, minFrameDuration), 0.1);
44299
+ if (nextSegment) {
44300
+ _context.next = 8;
43051
44301
  break;
43052
44302
  }
43053
44303
  return _context.abrupt("return");
43054
- case 6:
44304
+ case 8:
43055
44305
  if (_this.isLive) {
43056
- _context.next = 16;
44306
+ _context.next = 18;
43057
44307
  break;
43058
44308
  }
43059
44309
  bInfo = _this.bufferInfo();
43060
44310
  if (_this.media.paused && !_this.media.currentTime) {
43061
44311
  bInfo = _this.bufferInfo(bInfo.nextStart || 0.5);
43062
44312
  }
43063
- bufferThroughout = Math.abs(bInfo.end - _this.media.duration) < 0.1;
44313
+ bufferThroughout = Math.abs(bInfo.end - _this.media.duration) < maxBufferThroughout;
43064
44314
  if (!(bInfo.remaining >= config.preloadTime || bufferThroughout)) {
43065
- _context.next = 13;
44315
+ _context.next = 15;
43066
44316
  break;
43067
44317
  }
43068
44318
  _this._tryEos();
43069
44319
  return _context.abrupt("return");
43070
- case 13:
44320
+ case 15:
43071
44321
  if (!(config.preferMMSStreaming && !_this._bufferService.msStreaming)) {
43072
- _context.next = 15;
44322
+ _context.next = 17;
43073
44323
  break;
43074
44324
  }
43075
44325
  return _context.abrupt("return");
43076
- case 15:
43077
- if (!_this._urlSwitching && _this._prevSegSn !== nextSeg.sn - 1 && bInfo.end && Math.abs(nextSeg.start - bInfo.end) > 1) {
44326
+ case 17:
44327
+ if (!_this._urlSwitching && _this._prevSegSn !== nextSegment.sn - 1 && bInfo.end && Math.abs(nextSegment.start - bInfo.end) > 1) {
43078
44328
  _this._playlist.setNextSegmentByIndex(_this._playlist.findSegmentIndexByTime(bInfo.end + 0.1));
43079
44329
  }
43080
- case 16:
44330
+ case 18:
43081
44331
  return _context.abrupt("return", _this._loadSegmentDirect());
43082
- case 17:
44332
+ case 19:
43083
44333
  case "end":
43084
44334
  return _context.stop();
43085
44335
  }
@@ -43327,6 +44577,12 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
43327
44577
  var _this$_bufferService;
43328
44578
  return (_this$_bufferService = this._bufferService) === null || _this$_bufferService === void 0 ? void 0 : _this$_bufferService.baseDts;
43329
44579
  }
44580
+ }, {
44581
+ key: "abrSwitchPoint",
44582
+ get: function get3() {
44583
+ var targetSeg = this._urlSwitching ? this._playlist.currentSegment : this._playlist.nextSegment;
44584
+ return targetSeg ? targetSeg.start + targetSeg.duration / 2 : null;
44585
+ }
43330
44586
  }, {
43331
44587
  key: "speedInfo",
43332
44588
  value: function speedInfo() {
@@ -43352,30 +44608,37 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
43352
44608
  }, {
43353
44609
  key: "load",
43354
44610
  value: function() {
43355
- var _load = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee4(url) {
43356
- var reuseMse, _args4 = arguments;
44611
+ var _load = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee4() {
44612
+ var url, options, reuseMse, _args4 = arguments;
43357
44613
  return _regeneratorRuntime$6().wrap(function _callee4$(_context4) {
43358
44614
  while (1)
43359
44615
  switch (_context4.prev = _context4.next) {
43360
44616
  case 0:
43361
- reuseMse = _args4.length > 1 && _args4[1] !== void 0 ? _args4[1] : false;
44617
+ url = _args4.length > 0 && _args4[0] !== void 0 ? _args4[0] : "";
44618
+ options = _args4.length > 1 && _args4[1] !== void 0 ? _args4[1] : {};
44619
+ reuseMse = typeof options === "boolean" ? options : !!(options !== null && options !== void 0 && options.reuseMse);
44620
+ if (_typeof$5(options) === "object" && options !== null && options !== void 0 && options.clearSwitchStatus) {
44621
+ this._urlSwitching = false;
44622
+ this._switchUrlOpts = null;
44623
+ this.config.startTime = void 0;
44624
+ }
43362
44625
  if (url)
43363
44626
  this.config.url = url;
43364
44627
  url = this.config.url;
43365
- _context4.next = 5;
44628
+ _context4.next = 8;
43366
44629
  return this._reset(reuseMse);
43367
- case 5:
43368
- _context4.next = 7;
44630
+ case 8:
44631
+ _context4.next = 10;
43369
44632
  return this._loadData(url);
43370
- case 7:
44633
+ case 10:
43371
44634
  this._startTick();
43372
- case 8:
44635
+ case 11:
43373
44636
  case "end":
43374
44637
  return _context4.stop();
43375
44638
  }
43376
44639
  }, _callee4, this);
43377
44640
  }));
43378
- function load(_x) {
44641
+ function load() {
43379
44642
  return _load.apply(this, arguments);
43380
44643
  }
43381
44644
  return load;
@@ -43384,7 +44647,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
43384
44647
  key: "_loadData",
43385
44648
  value: function() {
43386
44649
  var _loadData2 = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee5(url) {
43387
- var manifest, currentStream, _this$_switchUrlOpts, _this$_switchUrlOpts2, switchTimePoint, segIdx, nextSeg, bufferClearStartPoint, preIndex, startTime, _this$_switchUrlOpts3;
44650
+ var manifest, currentStream, preIndex, _this$_switchUrlOpts, _this$_switchUrlOpts3, _this$_switchUrlOpts4, _this$_switchUrlOpts2, switchTimePoint, segIdx, nextSeg, bufferClearStartPoint, startTime, _this$_switchUrlOpts5;
43388
44651
  return _regeneratorRuntime$6().wrap(function _callee5$(_context5) {
43389
44652
  while (1)
43390
44653
  switch (_context5.prev = _context5.next) {
@@ -43405,41 +44668,46 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
43405
44668
  case 5:
43406
44669
  manifest = _context5.sent;
43407
44670
  currentStream = this._playlist.currentStream;
43408
- if (!(this._urlSwitching && !this.isLive)) {
43409
- _context5.next = 17;
44671
+ if (!this._urlSwitching) {
44672
+ _context5.next = 23;
43410
44673
  break;
43411
44674
  }
44675
+ if (!this.isLive) {
44676
+ _context5.next = 14;
44677
+ break;
44678
+ }
44679
+ preIndex = this._playlist.setNextSegmentBySN(this._prevSegSn);
44680
+ logger$1.log("segment nb=".concat(this._prevSegSn, " index of ").concat(preIndex, " in the new playlist"));
44681
+ if (preIndex === -1) {
44682
+ this._prevSegCc = null;
44683
+ this._prevSegSn = null;
44684
+ }
44685
+ _context5.next = 23;
44686
+ break;
44687
+ case 14:
43412
44688
  if (currentStream.bitrate === 0 && (_this$_switchUrlOpts = this._switchUrlOpts) !== null && _this$_switchUrlOpts !== void 0 && _this$_switchUrlOpts.bitrate) {
43413
44689
  currentStream.bitrate = (_this$_switchUrlOpts2 = this._switchUrlOpts) === null || _this$_switchUrlOpts2 === void 0 ? void 0 : _this$_switchUrlOpts2.bitrate;
43414
44690
  }
43415
- switchTimePoint = this._getSeamlessSwitchPoint();
44691
+ 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();
43416
44692
  this.config.startTime = switchTimePoint;
43417
44693
  segIdx = this._playlist.findSegmentIndexByTime(switchTimePoint);
43418
44694
  nextSeg = this._playlist.getSegmentByIndex(segIdx + 1);
43419
44695
  if (!nextSeg) {
43420
- _context5.next = 17;
44696
+ _context5.next = 23;
43421
44697
  break;
43422
44698
  }
43423
44699
  bufferClearStartPoint = nextSeg.start;
43424
- _context5.next = 17;
44700
+ _context5.next = 23;
43425
44701
  return this._bufferService.removeBuffer(bufferClearStartPoint);
43426
- case 17:
43427
- if (this._urlSwitching && this.isLive) {
43428
- preIndex = this._playlist.setNextSegmentBySN(this._prevSegSn);
43429
- logger$1.log("segment nb=".concat(this._prevSegSn, " index of ").concat(preIndex, " in the new playlist"));
43430
- if (preIndex === -1) {
43431
- this._prevSegCc = null;
43432
- this._prevSegSn = null;
43433
- }
43434
- }
44702
+ case 23:
43435
44703
  if (manifest) {
43436
- _context5.next = 20;
44704
+ _context5.next = 25;
43437
44705
  break;
43438
44706
  }
43439
44707
  return _context5.abrupt("return");
43440
- case 20:
44708
+ case 25:
43441
44709
  if (!this.isLive) {
43442
- _context5.next = 31;
44710
+ _context5.next = 36;
43443
44711
  break;
43444
44712
  }
43445
44713
  this._bufferService.setLiveSeekableRange(0, 4294967295);
@@ -43452,35 +44720,35 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
43452
44720
  if (!manifest.isMaster)
43453
44721
  this._pollM3U8(url);
43454
44722
  if (!(this._playlist.nbSegments < this.config.minSegmentsStartPlay)) {
43455
- _context5.next = 28;
44723
+ _context5.next = 33;
43456
44724
  break;
43457
44725
  }
43458
44726
  return _context5.abrupt("return");
43459
- case 28:
43460
- _context5.next = 30;
44727
+ case 33:
44728
+ _context5.next = 35;
43461
44729
  return this._loadSegment();
43462
- case 30:
44730
+ case 35:
43463
44731
  return _context5.abrupt("return");
43464
- case 31:
43465
- _context5.next = 33;
44732
+ case 36:
44733
+ _context5.next = 38;
43466
44734
  return this._bufferService.updateDuration(currentStream.totalDuration);
43467
- case 33:
44735
+ case 38:
43468
44736
  startTime = this.config.startTime;
43469
44737
  if (startTime) {
43470
- if (!((_this$_switchUrlOpts3 = this._switchUrlOpts) !== null && _this$_switchUrlOpts3 !== void 0 && _this$_switchUrlOpts3.seamless)) {
44738
+ if (!((_this$_switchUrlOpts5 = this._switchUrlOpts) !== null && _this$_switchUrlOpts5 !== void 0 && _this$_switchUrlOpts5.seamless)) {
43471
44739
  this.media.currentTime = startTime;
43472
44740
  }
43473
44741
  this._playlist.setNextSegmentByIndex(this._playlist.findSegmentIndexByTime(startTime) || 0);
43474
44742
  }
43475
- _context5.next = 37;
44743
+ _context5.next = 42;
43476
44744
  return this._loadSegment();
43477
- case 37:
44745
+ case 42:
43478
44746
  case "end":
43479
44747
  return _context5.stop();
43480
44748
  }
43481
44749
  }, _callee5, this);
43482
44750
  }));
43483
- function _loadData(_x2) {
44751
+ function _loadData(_x) {
43484
44752
  return _loadData2.apply(this, arguments);
43485
44753
  }
43486
44754
  return _loadData;
@@ -43494,18 +44762,20 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
43494
44762
  switch (_context6.prev = _context6.next) {
43495
44763
  case 0:
43496
44764
  this.config.startTime = 0;
43497
- _context6.next = 3;
44765
+ this._urlSwitching = false;
44766
+ this._switchUrlOpts = null;
44767
+ _context6.next = 5;
43498
44768
  return this.load();
43499
- case 3:
44769
+ case 5:
43500
44770
  this._reloadOnPlay = false;
43501
44771
  return _context6.abrupt("return", this.media.play(!isPlayEmit));
43502
- case 5:
44772
+ case 7:
43503
44773
  case "end":
43504
44774
  return _context6.stop();
43505
44775
  }
43506
44776
  }, _callee6, this);
43507
44777
  }));
43508
- function replay(_x3) {
44778
+ function replay(_x2) {
43509
44779
  return _replay.apply(this, arguments);
43510
44780
  }
43511
44781
  return replay;
@@ -43610,7 +44880,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
43610
44880
  }
43611
44881
  }, _callee7, this, [[18, 29]]);
43612
44882
  }));
43613
- function switchURL(_x4) {
44883
+ function switchURL(_x3) {
43614
44884
  return _switchURL.apply(this, arguments);
43615
44885
  }
43616
44886
  return switchURL;
@@ -43696,7 +44966,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
43696
44966
  }
43697
44967
  }, _callee8, this, [[8, 16], [21, 31]]);
43698
44968
  }));
43699
- function switchStream(_x5) {
44969
+ function switchStream(_x4) {
43700
44970
  return _switchStream.apply(this, arguments);
43701
44971
  }
43702
44972
  return switchStream;
@@ -43782,7 +45052,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
43782
45052
  }
43783
45053
  }, _callee9, this, [[10, 18], [22, 32]]);
43784
45054
  }));
43785
- function switchAudioStream(_x6) {
45055
+ function switchAudioStream(_x5) {
43786
45056
  return _switchAudioStream.apply(this, arguments);
43787
45057
  }
43788
45058
  return switchAudioStream;
@@ -43807,25 +45077,50 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
43807
45077
  }
43808
45078
  }, _callee10, this);
43809
45079
  }));
43810
- function switchSubtitleStream(_x7) {
45080
+ function switchSubtitleStream(_x6) {
43811
45081
  return _switchSubtitleStream.apply(this, arguments);
43812
45082
  }
43813
45083
  return switchSubtitleStream;
43814
45084
  }()
43815
45085
  }, {
43816
- key: "destroy",
45086
+ key: "detachMedia",
43817
45087
  value: function() {
43818
- var _destroy = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee11() {
43819
- var _this$_seiService2;
45088
+ var _detachMedia = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee11() {
43820
45089
  return _regeneratorRuntime$6().wrap(function _callee11$(_context11) {
43821
45090
  while (1)
43822
45091
  switch (_context11.prev = _context11.next) {
45092
+ case 0:
45093
+ if (!this._bufferService) {
45094
+ _context11.next = 3;
45095
+ break;
45096
+ }
45097
+ _context11.next = 3;
45098
+ return this._bufferService.detachMedia();
45099
+ case 3:
45100
+ case "end":
45101
+ return _context11.stop();
45102
+ }
45103
+ }, _callee11, this);
45104
+ }));
45105
+ function detachMedia() {
45106
+ return _detachMedia.apply(this, arguments);
45107
+ }
45108
+ return detachMedia;
45109
+ }()
45110
+ }, {
45111
+ key: "destroy",
45112
+ value: function() {
45113
+ var _destroy = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee12() {
45114
+ var _this$_seiService2;
45115
+ return _regeneratorRuntime$6().wrap(function _callee12$(_context12) {
45116
+ while (1)
45117
+ switch (_context12.prev = _context12.next) {
43823
45118
  case 0:
43824
45119
  if (this.media) {
43825
- _context11.next = 2;
45120
+ _context12.next = 2;
43826
45121
  break;
43827
45122
  }
43828
- return _context11.abrupt("return");
45123
+ return _context12.abrupt("return");
43829
45124
  case 2:
43830
45125
  this.removeAllListeners();
43831
45126
  this._playlist.reset();
@@ -43836,15 +45131,15 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
43836
45131
  this.media.removeEventListener("pause", this._onPause);
43837
45132
  this.media.removeEventListener("seeking", this._onSeeking);
43838
45133
  this.media.removeEventListener("timeupdate", this._onTimeupdate);
43839
- _context11.next = 13;
45134
+ _context12.next = 13;
43840
45135
  return Promise.all([this._clear(), this._bufferService.destroy()]);
43841
45136
  case 13:
43842
45137
  this.media = null;
43843
45138
  case 14:
43844
45139
  case "end":
43845
- return _context11.stop();
45140
+ return _context12.stop();
43846
45141
  }
43847
- }, _callee11, this);
45142
+ }, _callee12, this);
43848
45143
  }));
43849
45144
  function destroy() {
43850
45145
  return _destroy.apply(this, arguments);
@@ -43854,48 +45149,48 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
43854
45149
  }, {
43855
45150
  key: "_loadM3U8",
43856
45151
  value: function() {
43857
- var _loadM3U = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee12(url) {
45152
+ var _loadM3U = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee13(url) {
43858
45153
  var playlist, _this$config$manifest, _this$config$manifest2, manifest, _ref4, _ref5, _this$_playlist$curre;
43859
- return _regeneratorRuntime$6().wrap(function _callee12$(_context12) {
45154
+ return _regeneratorRuntime$6().wrap(function _callee13$(_context13) {
43860
45155
  while (1)
43861
- switch (_context12.prev = _context12.next) {
45156
+ switch (_context13.prev = _context13.next) {
43862
45157
  case 0:
43863
- _context12.prev = 0;
45158
+ _context13.prev = 0;
43864
45159
  manifest = (_this$config$manifest = this.config.manifestList) === null || _this$config$manifest === void 0 ? void 0 : (_this$config$manifest2 = _this$config$manifest.filter(function(x2) {
43865
45160
  return x2.url === url;
43866
45161
  })[0]) === null || _this$config$manifest2 === void 0 ? void 0 : _this$config$manifest2.manifest;
43867
45162
  if (!manifest) {
43868
- _context12.next = 6;
45163
+ _context13.next = 6;
43869
45164
  break;
43870
45165
  }
43871
- _context12.t0 = this._manifestLoader.parseText(manifest, url);
43872
- _context12.next = 9;
45166
+ _context13.t0 = this._manifestLoader.parseText(manifest, url);
45167
+ _context13.next = 9;
43873
45168
  break;
43874
45169
  case 6:
43875
- _context12.next = 8;
45170
+ _context13.next = 8;
43876
45171
  return this._manifestLoader.load(url);
43877
45172
  case 8:
43878
- _context12.t0 = _context12.sent;
45173
+ _context13.t0 = _context13.sent;
43879
45174
  case 9:
43880
- _ref4 = _context12.t0;
45175
+ _ref4 = _context13.t0;
43881
45176
  _ref5 = _slicedToArray$5(_ref4, 1);
43882
45177
  playlist = _ref5[0];
43883
- _context12.next = 17;
45178
+ _context13.next = 17;
43884
45179
  break;
43885
45180
  case 14:
43886
- _context12.prev = 14;
43887
- _context12.t1 = _context12["catch"](0);
43888
- throw this._emitError(StreamingError$1.create(_context12.t1));
45181
+ _context13.prev = 14;
45182
+ _context13.t1 = _context13["catch"](0);
45183
+ throw this._emitError(StreamingError$1.create(_context13.t1));
43889
45184
  case 17:
43890
45185
  if (playlist) {
43891
- _context12.next = 19;
45186
+ _context13.next = 19;
43892
45187
  break;
43893
45188
  }
43894
- return _context12.abrupt("return");
45189
+ return _context13.abrupt("return");
43895
45190
  case 19:
43896
45191
  this._playlist.upsertPlaylist(playlist);
43897
45192
  if (!playlist.isMaster) {
43898
- _context12.next = 24;
45193
+ _context13.next = 24;
43899
45194
  break;
43900
45195
  }
43901
45196
  if ((_this$_playlist$curre = this._playlist.currentStream.subtitleStreams) !== null && _this$_playlist$curre !== void 0 && _this$_playlist$curre.length) {
@@ -43903,18 +45198,18 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
43903
45198
  list: this._playlist.currentStream.subtitleStreams
43904
45199
  });
43905
45200
  }
43906
- _context12.next = 24;
45201
+ _context13.next = 24;
43907
45202
  return this._refreshM3U8();
43908
45203
  case 24:
43909
45204
  this.emit(Event$1.STREAM_PARSED);
43910
- return _context12.abrupt("return", playlist);
45205
+ return _context13.abrupt("return", playlist);
43911
45206
  case 26:
43912
45207
  case "end":
43913
- return _context12.stop();
45208
+ return _context13.stop();
43914
45209
  }
43915
- }, _callee12, this, [[0, 14]]);
45210
+ }, _callee13, this, [[0, 14]]);
43916
45211
  }));
43917
- function _loadM3U8(_x8) {
45212
+ function _loadM3U8(_x7) {
43918
45213
  return _loadM3U.apply(this, arguments);
43919
45214
  }
43920
45215
  return _loadM3U8;
@@ -43948,7 +45243,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
43948
45243
  var isEmpty = this._playlist.isEmpty;
43949
45244
  var pollInterval;
43950
45245
  if (this._playlist.lowLatency) {
43951
- pollInterval = (this._playlist.currentStream.partTargetDuration * 2 || 0) * 1e3;
45246
+ pollInterval = (this._playlist.currentStream.partTargetDuration || 0) * 1e3;
43952
45247
  } else {
43953
45248
  var _this$_playlist$lastS;
43954
45249
  pollInterval = (((_this$_playlist$lastS = this._playlist.lastSegment) === null || _this$_playlist$lastS === void 0 ? void 0 : _this$_playlist$lastS.duration) || 0) * 1e3;
@@ -43976,53 +45271,53 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
43976
45271
  }, {
43977
45272
  key: "_loadSegmentDirect",
43978
45273
  value: function() {
43979
- var _loadSegmentDirect2 = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee13(loadOnce) {
45274
+ var _loadSegmentDirect2 = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee14(loadOnce) {
43980
45275
  var seg, appended, cachedError, _this$_playlist$curre2, bufferEnd, sameStream;
43981
- return _regeneratorRuntime$6().wrap(function _callee13$(_context13) {
45276
+ return _regeneratorRuntime$6().wrap(function _callee14$(_context14) {
43982
45277
  while (1)
43983
- switch (_context13.prev = _context13.next) {
45278
+ switch (_context14.prev = _context14.next) {
43984
45279
  case 0:
43985
45280
  seg = this._playlist.nextSegment;
43986
45281
  if (seg) {
43987
- _context13.next = 3;
45282
+ _context14.next = 3;
43988
45283
  break;
43989
45284
  }
43990
- return _context13.abrupt("return");
45285
+ return _context14.abrupt("return");
43991
45286
  case 3:
43992
45287
  appended = false;
43993
45288
  cachedError = null;
43994
- _context13.prev = 5;
45289
+ _context14.prev = 5;
43995
45290
  this._segmentProcessing = true;
43996
45291
  logger$1.log("load segment, sn:".concat(seg.sn, ", [").concat(seg.start, ", ").concat(seg.end, "], partIndex:").concat(seg.partIndex));
43997
- _context13.next = 10;
45292
+ _context14.next = 10;
43998
45293
  return this._reqAndBufferSegment(seg, this._playlist.getAudioSegment(seg));
43999
45294
  case 10:
44000
- appended = _context13.sent;
44001
- _context13.next = 16;
45295
+ appended = _context14.sent;
45296
+ _context14.next = 16;
44002
45297
  break;
44003
45298
  case 13:
44004
- _context13.prev = 13;
44005
- _context13.t0 = _context13["catch"](5);
44006
- cachedError = _context13.t0;
45299
+ _context14.prev = 13;
45300
+ _context14.t0 = _context14["catch"](5);
45301
+ cachedError = _context14.t0;
44007
45302
  case 16:
44008
- _context13.prev = 16;
45303
+ _context14.prev = 16;
44009
45304
  this._segmentProcessing = false;
44010
- return _context13.finish(16);
45305
+ return _context14.finish(16);
44011
45306
  case 19:
44012
45307
  if (!cachedError) {
44013
- _context13.next = 26;
45308
+ _context14.next = 26;
44014
45309
  break;
44015
45310
  }
44016
45311
  if (!this._bufferService.isFull()) {
44017
- _context13.next = 25;
45312
+ _context14.next = 25;
44018
45313
  break;
44019
45314
  }
44020
45315
  logger$1.log("load segment, sn:".concat(seg.sn, ", partIndex:").concat(seg.partIndex));
44021
45316
  this._segmentProcessing = true;
44022
45317
  this._isProcessQuotaExceeded = true;
44023
- return _context13.abrupt("return", false);
45318
+ return _context14.abrupt("return", false);
44024
45319
  case 25:
44025
- return _context13.abrupt("return", this._emitError(StreamingError$1.create(cachedError)));
45320
+ return _context14.abrupt("return", this._emitError(StreamingError$1.create(cachedError)));
44026
45321
  case 26:
44027
45322
  if (appended) {
44028
45323
  bufferEnd = this.bufferInfo().end;
@@ -44048,14 +45343,14 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
44048
45343
  this._loadSegment();
44049
45344
  }
44050
45345
  }
44051
- return _context13.abrupt("return", appended);
45346
+ return _context14.abrupt("return", appended);
44052
45347
  case 28:
44053
45348
  case "end":
44054
- return _context13.stop();
45349
+ return _context14.stop();
44055
45350
  }
44056
- }, _callee13, this, [[5, 13, 16, 19]]);
45351
+ }, _callee14, this, [[5, 13, 16, 19]]);
44057
45352
  }));
44058
- function _loadSegmentDirect(_x9) {
45353
+ function _loadSegmentDirect(_x8) {
44059
45354
  return _loadSegmentDirect2.apply(this, arguments);
44060
45355
  }
44061
45356
  return _loadSegmentDirect;
@@ -44063,45 +45358,45 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
44063
45358
  }, {
44064
45359
  key: "_reqAndBufferSegment",
44065
45360
  value: function() {
44066
- var _reqAndBufferSegment2 = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee14(seg, audioSeg) {
45361
+ var _reqAndBufferSegment2 = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee15(seg, audioSeg) {
44067
45362
  var _this$_bufferService2;
44068
45363
  var cc, discontinuity, responses, data2, sn, start, stream, before, contiguous, segStart;
44069
- return _regeneratorRuntime$6().wrap(function _callee14$(_context14) {
45364
+ return _regeneratorRuntime$6().wrap(function _callee15$(_context15) {
44070
45365
  while (1)
44071
- switch (_context14.prev = _context14.next) {
45366
+ switch (_context15.prev = _context15.next) {
44072
45367
  case 0:
44073
45368
  cc = seg ? seg.cc : audioSeg.cc;
44074
45369
  discontinuity = this._prevSegCc !== cc;
44075
45370
  responses = [];
44076
- _context14.prev = 3;
44077
- _context14.next = 6;
45371
+ _context15.prev = 3;
45372
+ _context15.next = 6;
44078
45373
  return this._segmentLoader.load(seg, audioSeg, discontinuity);
44079
45374
  case 6:
44080
- responses = _context14.sent;
44081
- _context14.next = 14;
45375
+ responses = _context15.sent;
45376
+ _context15.next = 14;
44082
45377
  break;
44083
45378
  case 9:
44084
- _context14.prev = 9;
44085
- _context14.t0 = _context14["catch"](3);
44086
- _context14.t0.fatal = false;
44087
- this._segmentLoader.error = _context14.t0;
44088
- throw _context14.t0;
45379
+ _context15.prev = 9;
45380
+ _context15.t0 = _context15["catch"](3);
45381
+ _context15.t0.fatal = false;
45382
+ this._segmentLoader.error = _context15.t0;
45383
+ throw _context15.t0;
44089
45384
  case 14:
44090
45385
  if (responses[0]) {
44091
- _context14.next = 16;
45386
+ _context15.next = 16;
44092
45387
  break;
44093
45388
  }
44094
- return _context14.abrupt("return");
45389
+ return _context15.abrupt("return");
44095
45390
  case 16:
44096
- _context14.next = 18;
45391
+ _context15.next = 18;
44097
45392
  return (_this$_bufferService2 = this._bufferService).decryptBuffer.apply(_this$_bufferService2, _toConsumableArray$7(responses));
44098
45393
  case 18:
44099
- data2 = _context14.sent;
45394
+ data2 = _context15.sent;
44100
45395
  if (data2) {
44101
- _context14.next = 21;
45396
+ _context15.next = 21;
44102
45397
  break;
44103
45398
  }
44104
- return _context14.abrupt("return");
45399
+ return _context15.abrupt("return");
44105
45400
  case 21:
44106
45401
  sn = seg ? seg.sn : audioSeg.sn;
44107
45402
  start = seg ? seg.start : audioSeg.start;
@@ -44115,26 +45410,26 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
44115
45410
  logger$1.warn("update the new playlist liveEdge, segment id=".concat(sn, ", buffer start=").concat(segStart, ", liveEdge=").concat(this._playlist.liveEdge));
44116
45411
  start = segStart;
44117
45412
  }
44118
- _context14.next = 30;
45413
+ _context15.next = 30;
44119
45414
  return this._bufferService.appendBuffer(seg, audioSeg, data2[0], data2[1], discontinuity, contiguous, start);
44120
45415
  case 30:
44121
45416
  this.emit(Event$1.APPEND_COST, {
44122
45417
  elapsed: Date.now() - before,
44123
45418
  url: seg.url
44124
45419
  });
44125
- _context14.next = 33;
45420
+ _context15.next = 33;
44126
45421
  return this._bufferService.evictBuffer(this.config.bufferBehind);
44127
45422
  case 33:
44128
45423
  this._prevSegCc = cc;
44129
45424
  this._prevSegSn = sn;
44130
- return _context14.abrupt("return", true);
45425
+ return _context15.abrupt("return", true);
44131
45426
  case 36:
44132
45427
  case "end":
44133
- return _context14.stop();
45428
+ return _context15.stop();
44134
45429
  }
44135
- }, _callee14, this, [[3, 9]]);
45430
+ }, _callee15, this, [[3, 9]]);
44136
45431
  }));
44137
- function _reqAndBufferSegment(_x10, _x11) {
45432
+ function _reqAndBufferSegment(_x9, _x10) {
44138
45433
  return _reqAndBufferSegment2.apply(this, arguments);
44139
45434
  }
44140
45435
  return _reqAndBufferSegment;
@@ -44142,11 +45437,11 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
44142
45437
  }, {
44143
45438
  key: "_onCheckQuotaExceeded",
44144
45439
  value: function() {
44145
- var _onCheckQuotaExceeded2 = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee15() {
45440
+ var _onCheckQuotaExceeded2 = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee16() {
44146
45441
  var seekTime, buffered, inBuffered, i, bufferBehind, mediaTime;
44147
- return _regeneratorRuntime$6().wrap(function _callee15$(_context15) {
45442
+ return _regeneratorRuntime$6().wrap(function _callee16$(_context16) {
44148
45443
  while (1)
44149
- switch (_context15.prev = _context15.next) {
45444
+ switch (_context16.prev = _context16.next) {
44150
45445
  case 0:
44151
45446
  seekTime = this.media.currentTime;
44152
45447
  buffered = this.media.buffered;
@@ -44154,37 +45449,37 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
44154
45449
  i = 0;
44155
45450
  case 4:
44156
45451
  if (!(i < buffered.length)) {
44157
- _context15.next = 11;
45452
+ _context16.next = 11;
44158
45453
  break;
44159
45454
  }
44160
45455
  if (!(buffered.start(0) >= seekTime && seekTime < buffered.end(i))) {
44161
- _context15.next = 8;
45456
+ _context16.next = 8;
44162
45457
  break;
44163
45458
  }
44164
45459
  inBuffered = true;
44165
- return _context15.abrupt("break", 11);
45460
+ return _context16.abrupt("break", 11);
44166
45461
  case 8:
44167
45462
  i++;
44168
- _context15.next = 4;
45463
+ _context16.next = 4;
44169
45464
  break;
44170
45465
  case 11:
44171
45466
  if (!this._bufferService.isFull()) {
44172
- _context15.next = 17;
45467
+ _context16.next = 17;
44173
45468
  break;
44174
45469
  }
44175
45470
  bufferBehind = inBuffered ? this.config.bufferBehind : 5;
44176
45471
  mediaTime = this.media.currentTime;
44177
45472
  if (!(mediaTime - bufferBehind > 0)) {
44178
- _context15.next = 17;
45473
+ _context16.next = 17;
44179
45474
  break;
44180
45475
  }
44181
- _context15.next = 17;
45476
+ _context16.next = 17;
44182
45477
  return this._bufferService.removeBuffer(0, mediaTime - bufferBehind);
44183
45478
  case 17:
44184
45479
  case "end":
44185
- return _context15.stop();
45480
+ return _context16.stop();
44186
45481
  }
44187
- }, _callee15, this);
45482
+ }, _callee16, this);
44188
45483
  }));
44189
45484
  function _onCheckQuotaExceeded() {
44190
45485
  return _onCheckQuotaExceeded2.apply(this, arguments);
@@ -44202,22 +45497,22 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
44202
45497
  }, {
44203
45498
  key: "_clear",
44204
45499
  value: function() {
44205
- var _clear2 = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee16() {
44206
- return _regeneratorRuntime$6().wrap(function _callee16$(_context16) {
45500
+ var _clear2 = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee17() {
45501
+ return _regeneratorRuntime$6().wrap(function _callee17$(_context17) {
44207
45502
  while (1)
44208
- switch (_context16.prev = _context16.next) {
45503
+ switch (_context17.prev = _context17.next) {
44209
45504
  case 0:
44210
45505
  clearTimeout(this._disconnectTimer);
44211
45506
  this._stopTick();
44212
- _context16.next = 4;
45507
+ _context17.next = 4;
44213
45508
  return Promise.all([this._segmentLoader.cancel(), this._manifestLoader.stopPoll()]);
44214
45509
  case 4:
44215
45510
  this._segmentProcessing = false;
44216
45511
  case 5:
44217
45512
  case "end":
44218
- return _context16.stop();
45513
+ return _context17.stop();
44219
45514
  }
44220
- }, _callee16, this);
45515
+ }, _callee17, this);
44221
45516
  }));
44222
45517
  function _clear() {
44223
45518
  return _clear2.apply(this, arguments);
@@ -44227,14 +45522,14 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
44227
45522
  }, {
44228
45523
  key: "_reset",
44229
45524
  value: function() {
44230
- var _reset2 = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee17() {
45525
+ var _reset2 = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee18() {
44231
45526
  var _this$_seiService3;
44232
- var reuseMse, _args17 = arguments;
44233
- return _regeneratorRuntime$6().wrap(function _callee17$(_context17) {
45527
+ var reuseMse, _args18 = arguments;
45528
+ return _regeneratorRuntime$6().wrap(function _callee18$(_context18) {
44234
45529
  while (1)
44235
- switch (_context17.prev = _context17.next) {
45530
+ switch (_context18.prev = _context18.next) {
44236
45531
  case 0:
44237
- reuseMse = _args17.length > 0 && _args17[0] !== void 0 ? _args17[0] : false;
45532
+ reuseMse = _args18.length > 0 && _args18[0] !== void 0 ? _args18[0] : false;
44238
45533
  this._reloadOnPlay = false;
44239
45534
  this._prevSegSn = null;
44240
45535
  this._prevSegCc = null;
@@ -44243,15 +45538,15 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
44243
45538
  this._segmentLoader.reset();
44244
45539
  (_this$_seiService3 = this._seiService) === null || _this$_seiService3 === void 0 ? void 0 : _this$_seiService3.reset();
44245
45540
  this._stats.reset();
44246
- _context17.next = 11;
45541
+ _context18.next = 11;
44247
45542
  return this._clear();
44248
45543
  case 11:
44249
- return _context17.abrupt("return", this._bufferService.reset(reuseMse));
45544
+ return _context18.abrupt("return", this._bufferService.reset(reuseMse));
44250
45545
  case 12:
44251
45546
  case "end":
44252
- return _context17.stop();
45547
+ return _context18.stop();
44253
45548
  }
44254
- }, _callee17, this);
45549
+ }, _callee18, this);
44255
45550
  }));
44256
45551
  function _reset() {
44257
45552
  return _reset2.apply(this, arguments);
@@ -44332,8 +45627,8 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
44332
45627
  value: function _tryEos() {
44333
45628
  var _this$_bufferService3, _this$_bufferService4;
44334
45629
  var media = this.media;
44335
- var _this$_playlist = this._playlist, nextSegment = _this$_playlist.nextSegment, lastSegment = _this$_playlist.lastSegment;
44336
- 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);
45630
+ var _this$_playlist2 = this._playlist, nextSegment = _this$_playlist2.nextSegment, lastSegment = _this$_playlist2.lastSegment;
45631
+ var eosAllowed = (!nextSegment || lastSegment && Buffer$4.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);
44337
45632
  if (!eosAllowed) {
44338
45633
  return;
44339
45634
  }
@@ -44369,7 +45664,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
44369
45664
  }]);
44370
45665
  return Hls2;
44371
45666
  }(EventEmitter$1);
44372
- _defineProperty$a(Hls, "version", "3.0.19-rc.0");
45667
+ _defineProperty$a(Hls, "version", "3.0.20-rc.6");
44373
45668
  try {
44374
45669
  if (localStorage.getItem("xgd")) {
44375
45670
  Hls.enableLogger();
@@ -44460,6 +45755,7 @@ var PluginExtension = /* @__PURE__ */ function() {
44460
45755
  }]);
44461
45756
  return PluginExtension2;
44462
45757
  }();
45758
+ var _excluded$2 = ["currentTime"];
44463
45759
  function parseSwitchUrlArgs(args, plugin) {
44464
45760
  var player = plugin.player;
44465
45761
  var curTime = player.currentTime;
@@ -44470,9 +45766,14 @@ function parseSwitchUrlArgs(args, plugin) {
44470
45766
  case "boolean":
44471
45767
  options.seamless = args;
44472
45768
  break;
44473
- case "object":
44474
- Object.assign(options, args);
45769
+ case "object": {
45770
+ var currentTime = args.currentTime, rest = _objectWithoutProperties$3(args, _excluded$2);
45771
+ Object.assign(options, rest);
45772
+ if (typeof currentTime === "number") {
45773
+ options.startTime = currentTime;
45774
+ }
44475
45775
  break;
45776
+ }
44476
45777
  }
44477
45778
  return options;
44478
45779
  }
@@ -44482,10 +45783,11 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
44482
45783
  function HlsPlugin2() {
44483
45784
  var _this;
44484
45785
  _classCallCheck$c(this, HlsPlugin2);
44485
- for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
44486
- _args[_key] = arguments[_key];
45786
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
45787
+ args[_key] = arguments[_key];
44487
45788
  }
44488
- _this = _super.call.apply(_super, [this].concat(_args));
45789
+ _this = _super.call.apply(_super, [this].concat(args));
45790
+ _defineProperty$a(_assertThisInitialized$9(_this), "logger", logger$1);
44489
45791
  _defineProperty$a(_assertThisInitialized$9(_this), "hls", null);
44490
45792
  _defineProperty$a(_assertThisInitialized$9(_this), "pluginExtension", null);
44491
45793
  _defineProperty$a(_assertThisInitialized$9(_this), "getStats", function() {
@@ -44497,24 +45799,6 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
44497
45799
  var lang = _ref.lang;
44498
45800
  (_this$hls2 = _this.hls) === null || _this$hls2 === void 0 ? void 0 : _this$hls2.switchSubtitleStream(lang);
44499
45801
  });
44500
- _defineProperty$a(_assertThisInitialized$9(_this), "_onSwitchURL", function(url, args) {
44501
- return new Promise(function(resolve3, reject3) {
44502
- var _assertThisInitialize = _assertThisInitialized$9(_this), player = _assertThisInitialize.player, hls = _assertThisInitialize.hls;
44503
- if (hls) {
44504
- var _this$player$config, _this$player$config$h;
44505
- var options = parseSwitchUrlArgs(args, _assertThisInitialized$9(_this));
44506
- player.config.url = url;
44507
- hls.switchURL(url, options).then(function() {
44508
- return resolve3(true);
44509
- }).catch(reject3);
44510
- 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) {
44511
- _this._keepPauseStatus();
44512
- }
44513
- } else {
44514
- reject3();
44515
- }
44516
- });
44517
- });
44518
45802
  _defineProperty$a(_assertThisInitialized$9(_this), "_keepPauseStatus", function() {
44519
45803
  var paused = _this.player.paused;
44520
45804
  if (!paused)
@@ -44539,8 +45823,8 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
44539
45823
  }, {
44540
45824
  key: "softDecode",
44541
45825
  get: function get3() {
44542
- var _this$player, _this$player$config2;
44543
- 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;
45826
+ var _this$player, _this$player$config;
45827
+ 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;
44544
45828
  return !!mediaType && mediaType !== "video" && mediaType !== "audio";
44545
45829
  }
44546
45830
  }, {
@@ -44548,13 +45832,35 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
44548
45832
  value: function beforePlayerInit() {
44549
45833
  var _this2 = this;
44550
45834
  var config = this.player.config;
45835
+ var mediaElem = this.player.media || this.player.video;
44551
45836
  var hlsOpts = config.hls || {};
44552
45837
  if (!config.url && !config.__allowHlsEmptyUrl__ || !hlsOpts.preferMMS && MSE$2.isMMSOnly()) {
44553
45838
  return;
44554
45839
  }
44555
45840
  if (this.hls)
44556
45841
  this.hls.destroy();
44557
- this.player.switchURL = this._onSwitchURL;
45842
+ var descriptor = Object.getOwnPropertyDescriptor(this.player, "switchURL");
45843
+ if (!descriptor || descriptor.writable) {
45844
+ this.player.switchURL = function(url, args) {
45845
+ return new Promise(function(resolve3, reject3) {
45846
+ var player = _this2.player, hls = _this2.hls;
45847
+ if (hls) {
45848
+ var _this2$player$config, _this2$player$config$;
45849
+ var options = parseSwitchUrlArgs(args, _this2);
45850
+ player.config.url = url;
45851
+ hls.switchURL(url, options).then(function() {
45852
+ return resolve3(true);
45853
+ }).catch(reject3);
45854
+ 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) {
45855
+ _this2._keepPauseStatus();
45856
+ }
45857
+ } else {
45858
+ reject3();
45859
+ }
45860
+ });
45861
+ };
45862
+ }
45863
+ var onSwitchUrl = this.player.switchURL;
44558
45864
  this.player.handleSource = false;
44559
45865
  hlsOpts.innerDegrade = hlsOpts.innerDegrade || config.innerDegrade;
44560
45866
  if (hlsOpts.disconnectTime === null || hlsOpts.disconnectTime === void 0)
@@ -44562,7 +45868,7 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
44562
45868
  this.hls = new Hls(_objectSpread2$5({
44563
45869
  softDecode: this.softDecode,
44564
45870
  isLive: config.isLive,
44565
- media: this.player.media || this.player.video,
45871
+ media: mediaElem,
44566
45872
  startTime: config.startTime,
44567
45873
  url: config.url
44568
45874
  }, hlsOpts));
@@ -44580,7 +45886,7 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
44580
45886
  if (this.softDecode) {
44581
45887
  this.pluginExtension = new PluginExtension(_objectSpread2$5({
44582
45888
  isLive: config.isLive,
44583
- media: this.player.video
45889
+ media: mediaElem
44584
45890
  }, hlsOpts), this);
44585
45891
  this.player.forceDegradeToVideo = function() {
44586
45892
  var _this2$pluginExtensio;
@@ -44597,8 +45903,8 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
44597
45903
  return (_this2$hls2 = _this2.hls) === null || _this2$hls2 === void 0 ? void 0 : _this2$hls2.replay();
44598
45904
  });
44599
45905
  }
45906
+ this.on(URL_CHANGE, onSwitchUrl);
44600
45907
  this.on(SWITCH_SUBTITLE, this._onSwitchSubtitle);
44601
- this.on(URL_CHANGE, this._onSwitchURL);
44602
45908
  this.on(DESTROY, this.destroy.bind(this));
44603
45909
  this._transError();
44604
45910
  this._transCoreEvent(EVENT$1.TTFB);
@@ -44608,6 +45914,7 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
44608
45914
  this._transCoreEvent(EVENT$1.LOAD_RETRY);
44609
45915
  this._transCoreEvent(EVENT$1.SOURCEBUFFER_CREATED);
44610
45916
  this._transCoreEvent(EVENT$1.MEDIASOURCE_OPENED);
45917
+ this._transCoreEvent(EVENT$1.APPEND_BUFFER);
44611
45918
  this._transCoreEvent(EVENT$1.REMOVE_BUFFER);
44612
45919
  this._transCoreEvent(EVENT$1.BUFFEREOS);
44613
45920
  this._transCoreEvent(EVENT$1.KEYFRAME);
@@ -44627,7 +45934,9 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
44627
45934
  this._transCoreEvent(Event$1.SUBTITLE_PLAYLIST);
44628
45935
  this._transCoreEvent(Event$1.APPEND_COST);
44629
45936
  if (config.url) {
44630
- this.hls.load(config.url, true).catch(function(e) {
45937
+ this.hls.load(config.url, {
45938
+ reuseMse: true
45939
+ }).catch(function(e) {
44631
45940
  });
44632
45941
  }
44633
45942
  }