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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/esm/index.development.js +2267 -578
  2. package/esm/index.production.js +3 -3
  3. package/esm/veplayer.plugin.abr.development.js +71 -3
  4. package/esm/veplayer.plugin.abr.production.js +1 -1
  5. package/esm/veplayer.plugin.drm.development.js +71 -3
  6. package/esm/veplayer.plugin.drm.production.js +1 -1
  7. package/esm/veplayer.plugin.flv.development.js +729 -196
  8. package/esm/veplayer.plugin.flv.production.js +1 -1
  9. package/esm/veplayer.plugin.hls.development.js +1505 -378
  10. package/esm/veplayer.plugin.hls.production.js +1 -1
  11. package/esm/veplayer.plugin.mp4.development.js +73 -5
  12. package/esm/veplayer.plugin.mp4.production.js +1 -1
  13. package/esm/veplayer.plugin.rtm.development.js +213 -48
  14. package/esm/veplayer.plugin.rtm.production.js +1 -1
  15. package/esm/veplayer.plugin.shaka.development.js +72 -4
  16. package/esm/veplayer.plugin.shaka.production.js +1 -1
  17. package/package.json +1 -1
  18. package/umd/veplayer.plugin.abr.development.js +71 -3
  19. package/umd/veplayer.plugin.abr.production.js +1 -1
  20. package/umd/veplayer.plugin.drm.development.js +71 -3
  21. package/umd/veplayer.plugin.drm.production.js +1 -1
  22. package/umd/veplayer.plugin.flv.development.js +729 -196
  23. package/umd/veplayer.plugin.flv.production.js +1 -1
  24. package/umd/veplayer.plugin.hls.development.js +1472 -345
  25. package/umd/veplayer.plugin.hls.production.js +1 -1
  26. package/umd/veplayer.plugin.mp4.development.js +73 -5
  27. package/umd/veplayer.plugin.mp4.production.js +1 -1
  28. package/umd/veplayer.plugin.rtm.development.js +213 -48
  29. package/umd/veplayer.plugin.rtm.production.js +1 -1
  30. package/umd/veplayer.plugin.shaka.development.js +72 -4
  31. package/umd/veplayer.plugin.shaka.production.js +1 -1
@@ -67,10 +67,10 @@ function _regeneratorRuntime$1() {
67
67
  return obj[key] = value;
68
68
  };
69
69
  }
70
- function wrap(innerFn, outerFn, self, tryLocsList) {
70
+ function wrap(innerFn, outerFn, self2, tryLocsList) {
71
71
  var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []);
72
72
  return defineProperty(generator, "_invoke", {
73
- value: makeInvokeMethod(innerFn, self, context)
73
+ value: makeInvokeMethod(innerFn, self2, context)
74
74
  }), generator;
75
75
  }
76
76
  function tryCatch(fn, obj, arg) {
@@ -137,7 +137,7 @@ function _regeneratorRuntime$1() {
137
137
  }
138
138
  });
139
139
  }
140
- function makeInvokeMethod(innerFn, self, context) {
140
+ function makeInvokeMethod(innerFn, self2, context) {
141
141
  var state = "suspendedStart";
142
142
  return function(method, arg) {
143
143
  if ("executing" === state)
@@ -166,7 +166,7 @@ function _regeneratorRuntime$1() {
166
166
  } else
167
167
  "return" === context.method && context.abrupt("return", context.arg);
168
168
  state = "executing";
169
- var record = tryCatch(innerFn, self, context);
169
+ var record = tryCatch(innerFn, self2, context);
170
170
  if ("normal" === record.type) {
171
171
  if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel)
172
172
  continue;
@@ -248,9 +248,9 @@ function _regeneratorRuntime$1() {
248
248
  };
249
249
  }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function() {
250
250
  return this;
251
- }), exports.AsyncIterator = AsyncIterator, exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
251
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function(innerFn, outerFn, self2, tryLocsList, PromiseImpl) {
252
252
  void 0 === PromiseImpl && (PromiseImpl = Promise);
253
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
253
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self2, tryLocsList), PromiseImpl);
254
254
  return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function(result) {
255
255
  return result.done ? result.value : iter.next();
256
256
  });
@@ -385,9 +385,9 @@ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
385
385
  }
386
386
  function _asyncToGenerator$1(fn) {
387
387
  return function() {
388
- var self = this, args = arguments;
388
+ var self2 = this, args = arguments;
389
389
  return new Promise(function(resolve, reject) {
390
- var gen = fn.apply(self, args);
390
+ var gen = fn.apply(self2, args);
391
391
  function _next(value) {
392
392
  asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
393
393
  }
@@ -514,19 +514,19 @@ function _objectWithoutProperties$1(source, excluded) {
514
514
  }
515
515
  return target;
516
516
  }
517
- function _assertThisInitialized$2(self) {
518
- if (self === void 0) {
517
+ function _assertThisInitialized$2(self2) {
518
+ if (self2 === void 0) {
519
519
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
520
520
  }
521
- return self;
521
+ return self2;
522
522
  }
523
- function _possibleConstructorReturn$2(self, call) {
523
+ function _possibleConstructorReturn$2(self2, call) {
524
524
  if (call && (typeof call === "object" || typeof call === "function")) {
525
525
  return call;
526
526
  } else if (call !== void 0) {
527
527
  throw new TypeError("Derived constructors may only return object or undefined");
528
528
  }
529
- return _assertThisInitialized$2(self);
529
+ return _assertThisInitialized$2(self2);
530
530
  }
531
531
  function _createSuper$2(Derived) {
532
532
  var hasNativeReflectConstruct = _isNativeReflectConstruct$2();
@@ -1640,7 +1640,7 @@ util.getCurrentTimeByOffset = function(offsetTime, segments) {
1640
1640
  }
1641
1641
  return offsetTime;
1642
1642
  };
1643
- var version = "3.0.19-rc.0";
1643
+ var version = "3.0.21-rc.2";
1644
1644
  var ERROR_MAP = {
1645
1645
  1: 5101,
1646
1646
  2: 5102,
@@ -1749,8 +1749,7 @@ function hook(hookName, handler) {
1749
1749
  }
1750
1750
  if (this.__hooks && this.__hooks[hookName]) {
1751
1751
  try {
1752
- var _this$__hooks$hookNam;
1753
- var preRet = (_this$__hooks$hookNam = this.__hooks[hookName]).call.apply(_this$__hooks$hookNam, [this, this].concat(Array.prototype.slice.call(arguments)));
1752
+ var preRet = runHooks(this, hookName, handler);
1754
1753
  if (preRet) {
1755
1754
  if (preRet.then) {
1756
1755
  preRet.then(function(isContinue) {
@@ -1775,6 +1774,19 @@ function hook(hookName, handler) {
1775
1774
  }
1776
1775
  }.bind(this);
1777
1776
  }
1777
+ function findHookIndex(hookName, handler) {
1778
+ var __hooks = this.__hooks;
1779
+ if (!__hooks || !Array.isArray(__hooks[hookName])) {
1780
+ return -1;
1781
+ }
1782
+ var hookHandlers = __hooks[hookName];
1783
+ for (var i = 0; i < hookHandlers.length; i++) {
1784
+ if (hookHandlers[i] === handler) {
1785
+ return i;
1786
+ }
1787
+ }
1788
+ return -1;
1789
+ }
1778
1790
  function useHooks(hookName, handler) {
1779
1791
  var __hooks = this.__hooks;
1780
1792
  if (!__hooks) {
@@ -1784,7 +1796,12 @@ function useHooks(hookName, handler) {
1784
1796
  console.warn("has no supported hook which name [".concat(hookName, "]"));
1785
1797
  return false;
1786
1798
  }
1787
- __hooks && (__hooks[hookName] = handler);
1799
+ if (!Array.isArray(__hooks[hookName])) {
1800
+ __hooks[hookName] = [];
1801
+ }
1802
+ if (findHookIndex.call(this, hookName, handler) === -1) {
1803
+ __hooks[hookName].push(handler);
1804
+ }
1788
1805
  return true;
1789
1806
  }
1790
1807
  function removeHooks(hookName, handler) {
@@ -1792,6 +1809,13 @@ function removeHooks(hookName, handler) {
1792
1809
  if (!__hooks) {
1793
1810
  return;
1794
1811
  }
1812
+ if (Array.isArray(__hooks[hookName])) {
1813
+ var hooks = __hooks[hookName];
1814
+ var index = findHookIndex.call(this, hookName, handler);
1815
+ if (index !== -1) {
1816
+ hooks.splice(index, 1);
1817
+ }
1818
+ }
1795
1819
  delete __hooks[hookName];
1796
1820
  }
1797
1821
  function hooksDescriptor(instance) {
@@ -1813,6 +1837,38 @@ function hooksDescriptor(instance) {
1813
1837
  function delHooksDescriptor(instance) {
1814
1838
  instance.__hooks = null;
1815
1839
  }
1840
+ function runHooks(obj, hookName, handler) {
1841
+ for (var _len5 = arguments.length, args = new Array(_len5 > 3 ? _len5 - 3 : 0), _key5 = 3; _key5 < _len5; _key5++) {
1842
+ args[_key5 - 3] = arguments[_key5];
1843
+ }
1844
+ if (obj.__hooks && Array.isArray(obj.__hooks[hookName])) {
1845
+ var hooks = obj.__hooks[hookName];
1846
+ var index = -1;
1847
+ var runHooksRecursive = function runHooksRecursive2(obj2, hookName2, handler2) {
1848
+ for (var _len6 = arguments.length, args2 = new Array(_len6 > 3 ? _len6 - 3 : 0), _key6 = 3; _key6 < _len6; _key6++) {
1849
+ args2[_key6 - 3] = arguments[_key6];
1850
+ }
1851
+ index++;
1852
+ if (hooks.length === 0 || index === hooks.length) {
1853
+ return handler2.call.apply(handler2, [obj2, obj2].concat(args2));
1854
+ }
1855
+ var hook2 = hooks[index];
1856
+ var ret = hook2.call.apply(hook2, [obj2, obj2].concat(args2));
1857
+ if (ret && ret.then) {
1858
+ return ret.then(function(data) {
1859
+ return data === false ? null : runHooksRecursive2.apply(void 0, [obj2, hookName2, handler2].concat(args2));
1860
+ }).catch(function(e) {
1861
+ console.warn("[runHooks]".concat(hookName2, " reject"), e.message);
1862
+ });
1863
+ } else if (ret !== false) {
1864
+ return runHooksRecursive2.apply(void 0, [obj2, hookName2, handler2].concat(args2));
1865
+ }
1866
+ };
1867
+ return runHooksRecursive.apply(void 0, [obj, hookName, handler].concat(args));
1868
+ } else {
1869
+ return handler.call.apply(handler, [obj, obj].concat(args));
1870
+ }
1871
+ }
1816
1872
  function showErrorMsg(pluginName, msg) {
1817
1873
  XG_DEBUG.logError("[".concat(pluginName, "] event or callback cant be undefined or null when call ").concat(msg));
1818
1874
  }
@@ -2052,6 +2108,18 @@ var BasePlugin = /* @__PURE__ */ function() {
2052
2108
  }
2053
2109
  }
2054
2110
  }
2111
+ }, {
2112
+ key: "defineMethod",
2113
+ value: function defineMethod(Obj, map) {
2114
+ for (var key in map) {
2115
+ if (Object.prototype.hasOwnProperty.call(map, key) && typeof map[key] === "function") {
2116
+ Object.defineProperty(Obj, key, {
2117
+ configurable: true,
2118
+ value: map[key]
2119
+ });
2120
+ }
2121
+ }
2122
+ }
2055
2123
  }, {
2056
2124
  key: "defaultConfig",
2057
2125
  get: function get() {
@@ -2108,10 +2176,10 @@ function _regeneratorRuntime() {
2108
2176
  return obj[key] = value;
2109
2177
  };
2110
2178
  }
2111
- function wrap(innerFn, outerFn, self, tryLocsList) {
2179
+ function wrap(innerFn, outerFn, self2, tryLocsList) {
2112
2180
  var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []);
2113
2181
  return defineProperty(generator, "_invoke", {
2114
- value: makeInvokeMethod(innerFn, self, context)
2182
+ value: makeInvokeMethod(innerFn, self2, context)
2115
2183
  }), generator;
2116
2184
  }
2117
2185
  function tryCatch(fn, obj, arg) {
@@ -2178,7 +2246,7 @@ function _regeneratorRuntime() {
2178
2246
  }
2179
2247
  });
2180
2248
  }
2181
- function makeInvokeMethod(innerFn, self, context) {
2249
+ function makeInvokeMethod(innerFn, self2, context) {
2182
2250
  var state = "suspendedStart";
2183
2251
  return function(method, arg) {
2184
2252
  if ("executing" === state)
@@ -2207,7 +2275,7 @@ function _regeneratorRuntime() {
2207
2275
  } else
2208
2276
  "return" === context.method && context.abrupt("return", context.arg);
2209
2277
  state = "executing";
2210
- var record = tryCatch(innerFn, self, context);
2278
+ var record = tryCatch(innerFn, self2, context);
2211
2279
  if ("normal" === record.type) {
2212
2280
  if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel)
2213
2281
  continue;
@@ -2289,9 +2357,9 @@ function _regeneratorRuntime() {
2289
2357
  };
2290
2358
  }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function() {
2291
2359
  return this;
2292
- }), exports.AsyncIterator = AsyncIterator, exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
2360
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function(innerFn, outerFn, self2, tryLocsList, PromiseImpl) {
2293
2361
  void 0 === PromiseImpl && (PromiseImpl = Promise);
2294
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
2362
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self2, tryLocsList), PromiseImpl);
2295
2363
  return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function(result) {
2296
2364
  return result.done ? result.value : iter.next();
2297
2365
  });
@@ -2426,9 +2494,9 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2426
2494
  }
2427
2495
  function _asyncToGenerator(fn) {
2428
2496
  return function() {
2429
- var self = this, args = arguments;
2497
+ var self2 = this, args = arguments;
2430
2498
  return new Promise(function(resolve, reject) {
2431
- var gen = fn.apply(self, args);
2499
+ var gen = fn.apply(self2, args);
2432
2500
  function _next(value) {
2433
2501
  asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
2434
2502
  }
@@ -2602,19 +2670,19 @@ function _objectWithoutProperties(source, excluded) {
2602
2670
  }
2603
2671
  return target;
2604
2672
  }
2605
- function _assertThisInitialized$1(self) {
2606
- if (self === void 0) {
2673
+ function _assertThisInitialized$1(self2) {
2674
+ if (self2 === void 0) {
2607
2675
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
2608
2676
  }
2609
- return self;
2677
+ return self2;
2610
2678
  }
2611
- function _possibleConstructorReturn$1(self, call) {
2679
+ function _possibleConstructorReturn$1(self2, call) {
2612
2680
  if (call && (typeof call === "object" || typeof call === "function")) {
2613
2681
  return call;
2614
2682
  } else if (call !== void 0) {
2615
2683
  throw new TypeError("Derived constructors may only return object or undefined");
2616
2684
  }
2617
- return _assertThisInitialized$1(self);
2685
+ return _assertThisInitialized$1(self2);
2618
2686
  }
2619
2687
  function _createSuper$1(Derived) {
2620
2688
  var hasNativeReflectConstruct = _isNativeReflectConstruct$1();
@@ -2674,7 +2742,7 @@ function _arrayLikeToArray$1(arr, len) {
2674
2742
  arr2[i] = arr[i];
2675
2743
  return arr2;
2676
2744
  }
2677
- function _createForOfIteratorHelper(o, allowArrayLike) {
2745
+ function _createForOfIteratorHelper$1(o, allowArrayLike) {
2678
2746
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
2679
2747
  if (!it) {
2680
2748
  if (Array.isArray(o) || (it = _unsupportedIterableToArray$1(o)) || allowArrayLike && o && typeof o.length === "number") {
@@ -2862,6 +2930,21 @@ var Buffer$1 = /* @__PURE__ */ function() {
2862
2930
  length: Buffer2.totalLength && Buffer2.totalLength(buffers)
2863
2931
  };
2864
2932
  }
2933
+ }, {
2934
+ key: "isBuffered",
2935
+ value: function isBuffered(media, pos) {
2936
+ if (media) {
2937
+ var buffered = Buffer2.get(media);
2938
+ if (buffered !== null && buffered !== void 0 && buffered.length) {
2939
+ for (var i = 0; i < buffered.length; i++) {
2940
+ if (pos >= buffered.start(i) && pos <= buffered.end(i)) {
2941
+ return true;
2942
+ }
2943
+ }
2944
+ }
2945
+ }
2946
+ return false;
2947
+ }
2865
2948
  }]);
2866
2949
  return Buffer2;
2867
2950
  }();
@@ -3014,7 +3097,7 @@ var Logger$2 = /* @__PURE__ */ function() {
3014
3097
  this.logCache.apply(this, [LogCacheLevel.DEBUG].concat(args));
3015
3098
  if (Logger2.disabled)
3016
3099
  return;
3017
- (_console = console).debug.apply(_console, [this._prefix, nowTime$1()].concat(args));
3100
+ (_console = console).debug.apply(_console, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
3018
3101
  }
3019
3102
  }, {
3020
3103
  key: "log",
@@ -3026,7 +3109,7 @@ var Logger$2 = /* @__PURE__ */ function() {
3026
3109
  this.logCache.apply(this, [LogCacheLevel.LOG].concat(args));
3027
3110
  if (Logger2.disabled)
3028
3111
  return;
3029
- (_console2 = console).log.apply(_console2, [this._prefix, nowTime$1()].concat(args));
3112
+ (_console2 = console).log.apply(_console2, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
3030
3113
  }
3031
3114
  }, {
3032
3115
  key: "warn",
@@ -3038,7 +3121,7 @@ var Logger$2 = /* @__PURE__ */ function() {
3038
3121
  this.logCache.apply(this, [LogCacheLevel.WARN].concat(args));
3039
3122
  if (Logger2.disabled)
3040
3123
  return;
3041
- (_console3 = console).warn.apply(_console3, [this._prefix, nowTime$1()].concat(args));
3124
+ (_console3 = console).warn.apply(_console3, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
3042
3125
  }
3043
3126
  }, {
3044
3127
  key: "error",
@@ -3050,7 +3133,7 @@ var Logger$2 = /* @__PURE__ */ function() {
3050
3133
  this.logCache.apply(this, [LogCacheLevel.ERROR].concat(args));
3051
3134
  if (Logger2.disabled)
3052
3135
  return;
3053
- (_console4 = console).error.apply(_console4, [this._prefix, nowTime$1()].concat(args));
3136
+ (_console4 = console).error.apply(_console4, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
3054
3137
  }
3055
3138
  }, {
3056
3139
  key: "logCache",
@@ -3065,7 +3148,7 @@ var Logger$2 = /* @__PURE__ */ function() {
3065
3148
  var finLogText = logText.map(function(item) {
3066
3149
  return logable(item);
3067
3150
  });
3068
- text = this._prefix + nowTime$1() + JSON.stringify(finLogText);
3151
+ text = "[".concat(nowTime$1(), "]") + this._prefix + JSON.stringify(finLogText);
3069
3152
  } catch (e) {
3070
3153
  return;
3071
3154
  }
@@ -3981,8 +4064,8 @@ function createResponse(data, done, response, contentLength, age, startTime, fir
3981
4064
  response
3982
4065
  };
3983
4066
  }
3984
- function calculateSpeed(byteLen, millisec) {
3985
- return Math.round(byteLen * 8 * 1e3 / millisec / 1024);
4067
+ function calculateSpeed(byteLen, milliSecond) {
4068
+ return Math.round(byteLen * 8 * 1e3 / milliSecond / 1024);
3986
4069
  }
3987
4070
  var EVENT = {
3988
4071
  ERROR: "error",
@@ -3994,6 +4077,7 @@ var EVENT = {
3994
4077
  SOURCEBUFFER_CREATED: "core.sourcebuffercreated",
3995
4078
  MEDIASOURCE_OPENED: "core.mediasourceopened",
3996
4079
  ANALYZE_DURATION_EXCEEDED: "core.analyzedurationexceeded",
4080
+ APPEND_BUFFER: "core.appendbuffer",
3997
4081
  REMOVE_BUFFER: "core.removebuffer",
3998
4082
  BUFFEREOS: "core.buffereos",
3999
4083
  KEYFRAME: "core.keyframe",
@@ -4766,7 +4850,7 @@ var XhrLoader = /* @__PURE__ */ function(_EventEmitter) {
4766
4850
  value: function _getHeaders(xhr) {
4767
4851
  var headerLines = xhr.getAllResponseHeaders().trim().split("\r\n");
4768
4852
  var headers = {};
4769
- var _iterator = _createForOfIteratorHelper(headerLines), _step;
4853
+ var _iterator = _createForOfIteratorHelper$1(headerLines), _step;
4770
4854
  try {
4771
4855
  for (_iterator.s(); !(_step = _iterator.n()).done; ) {
4772
4856
  var header = _step.value;
@@ -4788,7 +4872,7 @@ var XhrLoader = /* @__PURE__ */ function(_EventEmitter) {
4788
4872
  }]);
4789
4873
  return XhrLoader2;
4790
4874
  }(EventEmitter);
4791
- var _excluded$1 = ["retry", "retryDelay", "onRetryError", "transformError"];
4875
+ var _excluded$2 = ["retry", "retryDelay", "onRetryError", "transformError"];
4792
4876
  var Task = /* @__PURE__ */ function() {
4793
4877
  function Task2(type, config) {
4794
4878
  _classCallCheck$1(this, Task2);
@@ -4808,7 +4892,7 @@ var Task = /* @__PURE__ */ function() {
4808
4892
  key: "exec",
4809
4893
  value: function exec() {
4810
4894
  var _this = this;
4811
- var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties(_this$_config, _excluded$1);
4895
+ var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties(_this$_config, _excluded$2);
4812
4896
  var request = /* @__PURE__ */ function() {
4813
4897
  var _ref = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee() {
4814
4898
  var response, error, isRetry;
@@ -5533,19 +5617,19 @@ function _isNativeReflectConstruct() {
5533
5617
  return false;
5534
5618
  }
5535
5619
  }
5536
- function _assertThisInitialized(self) {
5537
- if (self === void 0) {
5620
+ function _assertThisInitialized(self2) {
5621
+ if (self2 === void 0) {
5538
5622
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
5539
5623
  }
5540
- return self;
5624
+ return self2;
5541
5625
  }
5542
- function _possibleConstructorReturn(self, call) {
5626
+ function _possibleConstructorReturn(self2, call) {
5543
5627
  if (call && (typeof call === "object" || typeof call === "function")) {
5544
5628
  return call;
5545
5629
  } else if (call !== void 0) {
5546
5630
  throw new TypeError("Derived constructors may only return object or undefined");
5547
5631
  }
5548
- return _assertThisInitialized(self);
5632
+ return _assertThisInitialized(self2);
5549
5633
  }
5550
5634
  function _createSuper(Derived) {
5551
5635
  var hasNativeReflectConstruct = _isNativeReflectConstruct();
@@ -5604,6 +5688,60 @@ function _nonIterableSpread() {
5604
5688
  function _nonIterableRest() {
5605
5689
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
5606
5690
  }
5691
+ function _createForOfIteratorHelper(o, allowArrayLike) {
5692
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
5693
+ if (!it) {
5694
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
5695
+ if (it)
5696
+ o = it;
5697
+ var i = 0;
5698
+ var F = function() {
5699
+ };
5700
+ return {
5701
+ s: F,
5702
+ n: function() {
5703
+ if (i >= o.length)
5704
+ return {
5705
+ done: true
5706
+ };
5707
+ return {
5708
+ done: false,
5709
+ value: o[i++]
5710
+ };
5711
+ },
5712
+ e: function(e) {
5713
+ throw e;
5714
+ },
5715
+ f: F
5716
+ };
5717
+ }
5718
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
5719
+ }
5720
+ var normalCompletion = true, didErr = false, err;
5721
+ return {
5722
+ s: function() {
5723
+ it = it.call(o);
5724
+ },
5725
+ n: function() {
5726
+ var step = it.next();
5727
+ normalCompletion = step.done;
5728
+ return step;
5729
+ },
5730
+ e: function(e) {
5731
+ didErr = true;
5732
+ err = e;
5733
+ },
5734
+ f: function() {
5735
+ try {
5736
+ if (!normalCompletion && it.return != null)
5737
+ it.return();
5738
+ } finally {
5739
+ if (didErr)
5740
+ throw err;
5741
+ }
5742
+ }
5743
+ };
5744
+ }
5607
5745
  function _toPrimitive(input, hint) {
5608
5746
  if (typeof input !== "object" || input === null)
5609
5747
  return input;
@@ -5626,13 +5764,16 @@ var TrackType = {
5626
5764
  METADATA: "metadata"
5627
5765
  };
5628
5766
  var VideoCodecType = {
5767
+ AV1: "av1",
5629
5768
  AVC: "avc",
5630
5769
  HEVC: "hevc"
5631
5770
  };
5632
5771
  var AudioCodecType = {
5633
5772
  AAC: "aac",
5634
5773
  G711PCMA: "g7110a",
5635
- G711PCMU: "g7110m"
5774
+ G711PCMU: "g7110m",
5775
+ OPUS: "opus",
5776
+ MP3: "mp3"
5636
5777
  };
5637
5778
  var WarningType = {
5638
5779
  LARGE_AV_SHIFT: "LARGE_AV_SHIFT",
@@ -5672,6 +5813,7 @@ var VideoTrack = /* @__PURE__ */ function() {
5672
5813
  _defineProperty(this, "isVideoEncryption", false);
5673
5814
  _defineProperty(this, "isAudioEncryption", false);
5674
5815
  _defineProperty(this, "isVideo", true);
5816
+ _defineProperty(this, "lastKeyFrameDts", 0);
5675
5817
  _defineProperty(this, "kid", null);
5676
5818
  _defineProperty(this, "pssh", null);
5677
5819
  _defineProperty(this, "ext", void 0);
@@ -5714,6 +5856,9 @@ var VideoTrack = /* @__PURE__ */ function() {
5714
5856
  }, {
5715
5857
  key: "exist",
5716
5858
  value: function exist() {
5859
+ if (/av01/.test(this.codec)) {
5860
+ return true;
5861
+ }
5717
5862
  return !!(this.pps.length && this.sps.length && this.codec);
5718
5863
  }
5719
5864
  }, {
@@ -5737,6 +5882,7 @@ var AudioTrack = /* @__PURE__ */ function() {
5737
5882
  _defineProperty(this, "codecType", AudioCodecType.AAC);
5738
5883
  _defineProperty(this, "pid", -1);
5739
5884
  _defineProperty(this, "codec", "");
5885
+ _defineProperty(this, "container", "");
5740
5886
  _defineProperty(this, "sequenceNumber", 0);
5741
5887
  _defineProperty(this, "sampleDuration", 0);
5742
5888
  _defineProperty(this, "timescale", 0);
@@ -5777,7 +5923,7 @@ var AudioTrack = /* @__PURE__ */ function() {
5777
5923
  }, {
5778
5924
  key: "exist",
5779
5925
  value: function exist() {
5780
- return !!(this.sampleRate && this.channelCount && this.codec && this.codecType === AudioCodecType.AAC);
5926
+ return !!(this.sampleRate && this.channelCount && (this.codec || this.container) && (this.codecType === AudioCodecType.AAC || this.codecType === AudioCodecType.G711PCMA || this.codecType === AudioCodecType.G711PCMU || this.codecType === AudioCodecType.OPUS || this.codecType === AudioCodecType.MP3));
5781
5927
  }
5782
5928
  }, {
5783
5929
  key: "hasSample",
@@ -5982,7 +6128,7 @@ var AAC = /* @__PURE__ */ function() {
5982
6128
  continue;
5983
6129
  }
5984
6130
  frameLength = (data[i + 3] & 3) << 11 | data[i + 4] << 3 | (data[i + 5] & 224) >> 5;
5985
- if (len - i < frameLength)
6131
+ if (!frameLength || len - i < frameLength)
5986
6132
  break;
5987
6133
  protectionSkipBytes = (~data[i + 1] & 1) * 2;
5988
6134
  frames.push({
@@ -6176,6 +6322,15 @@ function parse2(a) {
6176
6322
  return parseInt(item, 16);
6177
6323
  });
6178
6324
  }
6325
+ function combineToFloat(integer, decimal) {
6326
+ return Number(integer + "." + decimal);
6327
+ }
6328
+ function toDegree(matrix) {
6329
+ if (matrix.length < 5)
6330
+ return 0;
6331
+ var scaled0 = Math.hypot(matrix[0], matrix[3]), scaled1 = Math.hypot(matrix[1], matrix[4]);
6332
+ return 0 === scaled0 || 0 === scaled1 ? 0 : 180 * Math.atan2(matrix[1] / scaled1, matrix[0] / scaled0) / Math.PI;
6333
+ }
6179
6334
  var NALu = /* @__PURE__ */ function() {
6180
6335
  function NALu2() {
6181
6336
  _classCallCheck(this, NALu2);
@@ -6838,13 +6993,16 @@ var MAX_SILENT_FRAME_DURATION = 9e4;
6838
6993
  var AUDIO_EXCETION_LOG_EMIT_DURATION = 5 * 9e4;
6839
6994
  var MAX_VIDEO_FRAME_DURATION = 9e4;
6840
6995
  var MAX_DTS_DELTA_WITH_NEXT_CHUNK = 9e4 / 2;
6996
+ var LARGE_AV_FIRST_FRAME_FORCE_FIX_THRESHOLD = 9e4 * 5;
6841
6997
  var TsFixer = /* @__PURE__ */ function() {
6842
- function TsFixer2(videoTrack, audioTrack, metadataTrack) {
6998
+ function TsFixer2(videoTrack, audioTrack, metadataTrack, fixerConfig) {
6843
6999
  _classCallCheck(this, TsFixer2);
6844
7000
  this.videoTrack = videoTrack;
6845
7001
  this.audioTrack = audioTrack;
6846
7002
  this.metadataTrack = metadataTrack;
6847
7003
  this._baseDts = -1;
7004
+ this._baseVideoDts = -1;
7005
+ this._baseAudioDts = -1;
6848
7006
  this._baseDtsInited = false;
6849
7007
  this._audioNextPts = void 0;
6850
7008
  this._videoNextDts = void 0;
@@ -6853,6 +7011,8 @@ var TsFixer = /* @__PURE__ */ function() {
6853
7011
  this._lastAudioExceptionGapDot = 0;
6854
7012
  this._lastAudioExceptionOverlapDot = 0;
6855
7013
  this._lastAudioExceptionLargeGapDot = 0;
7014
+ this._needForceFixLargeGap = fixerConfig === null || fixerConfig === void 0 ? void 0 : fixerConfig.forceFixLargeGap;
7015
+ this._largeGapThreshold = (fixerConfig === null || fixerConfig === void 0 ? void 0 : fixerConfig.largeGapThreshold) || LARGE_AV_FIRST_FRAME_FORCE_FIX_THRESHOLD;
6856
7016
  }
6857
7017
  _createClass(TsFixer2, [{
6858
7018
  key: "fix",
@@ -6880,10 +7040,16 @@ var TsFixer = /* @__PURE__ */ function() {
6880
7040
  if (discontinuity) {
6881
7041
  this._calculateBaseDts(this.audioTrack, this.videoTrack);
6882
7042
  this._baseDts -= startTime;
7043
+ this._baseAudioDts -= startTime;
7044
+ this._baseVideoDts -= startTime;
6883
7045
  }
6884
7046
  if (!contiguous) {
6885
7047
  this._videoNextDts = vaDelta > 0 ? startTime + vaDelta : startTime;
6886
7048
  this._audioNextPts = vaDelta > 0 ? startTime : startTime - vaDelta;
7049
+ if (this._needForceFixLargeGap) {
7050
+ this._videoNextDts = 0;
7051
+ this._audioNextPts = 0;
7052
+ }
6887
7053
  var vDeltaToNextDts = firstVideoSample ? firstVideoSample.dts - this._baseDts - this._videoNextDts : 0;
6888
7054
  var aDeltaToNextDts = firstAudioSample ? firstAudioSample.pts - this._baseDts - this._audioNextPts : 0;
6889
7055
  if (Math.abs(vDeltaToNextDts || aDeltaToNextDts) > MAX_VIDEO_FRAME_DURATION) {
@@ -6916,8 +7082,8 @@ var TsFixer = /* @__PURE__ */ function() {
6916
7082
  if (!samples.length)
6917
7083
  return;
6918
7084
  samples.forEach(function(x) {
6919
- x.dts -= _this2._baseDts;
6920
- x.pts -= _this2._baseDts;
7085
+ x.dts -= _this2._needForceFixLargeGap ? _this2._baseVideoDts : _this2._baseDts;
7086
+ x.pts -= _this2._needForceFixLargeGap ? _this2._baseVideoDts : _this2._baseDts;
6921
7087
  });
6922
7088
  if (this._videoNextDts === void 0) {
6923
7089
  var samp0 = samples[0];
@@ -7010,7 +7176,7 @@ var TsFixer = /* @__PURE__ */ function() {
7010
7176
  if (!samples.length)
7011
7177
  return;
7012
7178
  samples.forEach(function(x) {
7013
- x.pts -= _this3._baseDts;
7179
+ x.pts -= _this3._needForceFixLargeGap ? _this3._baseAudioDts : _this3._baseDts;
7014
7180
  x.dts = x.pts;
7015
7181
  });
7016
7182
  this._doFixAudioInternal(audioTrack, samples, 9e4);
@@ -7027,12 +7193,15 @@ var TsFixer = /* @__PURE__ */ function() {
7027
7193
  var videoBaseDts = Infinity;
7028
7194
  if (audioSamps.length) {
7029
7195
  audioTrack.baseDts = audioBasePts = audioSamps[0].pts;
7196
+ this._baseAudioDts = audioBasePts;
7030
7197
  }
7031
7198
  if (videoSamps.length) {
7032
7199
  videoTrack.baseDts = videoBaseDts = videoSamps[0].dts;
7200
+ this._baseVideoDts = videoBaseDts;
7033
7201
  }
7034
7202
  this._baseDts = Math.min(audioBasePts, videoBaseDts);
7035
7203
  var delta = videoBaseDts - audioBasePts;
7204
+ var largeGap = false;
7036
7205
  if (Number.isFinite(delta) && Math.abs(delta) > LARGE_AV_FIRST_FRAME_GAP) {
7037
7206
  videoTrack.warnings.push({
7038
7207
  type: WarningType.LARGE_AV_SHIFT,
@@ -7042,6 +7211,16 @@ var TsFixer = /* @__PURE__ */ function() {
7042
7211
  delta
7043
7212
  });
7044
7213
  }
7214
+ if (Number.isFinite(delta) && Math.abs(delta) > this._largeGapThreshold * MAX_SILENT_FRAME_DURATION) {
7215
+ largeGap = true;
7216
+ }
7217
+ if (!this._baseDtsInited) {
7218
+ if (largeGap && this._needForceFixLargeGap) {
7219
+ this._needForceFixLargeGap = true;
7220
+ } else {
7221
+ this._needForceFixLargeGap = false;
7222
+ }
7223
+ }
7045
7224
  this._baseDtsInited = true;
7046
7225
  return true;
7047
7226
  }
@@ -7132,9 +7311,119 @@ var TsFixer = /* @__PURE__ */ function() {
7132
7311
  }]);
7133
7312
  return TsFixer2;
7134
7313
  }();
7314
+ var BitratesMap = [32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160];
7315
+ var FREQ = [44100, 48e3, 32e3, 22050, 24e3, 16e3, 11025, 12e3, 8e3];
7316
+ var SamplesCoefficients = [
7317
+ [
7318
+ 0,
7319
+ 72,
7320
+ 144,
7321
+ 12
7322
+ ],
7323
+ [
7324
+ 0,
7325
+ 0,
7326
+ 0,
7327
+ 0
7328
+ ],
7329
+ [
7330
+ 0,
7331
+ 72,
7332
+ 144,
7333
+ 12
7334
+ ],
7335
+ [
7336
+ 0,
7337
+ 144,
7338
+ 144,
7339
+ 12
7340
+ ]
7341
+ ];
7342
+ var BytesInSlot = [
7343
+ 0,
7344
+ 1,
7345
+ 1,
7346
+ 4
7347
+ ];
7348
+ var chromeVersion = null;
7349
+ var MPEG = /* @__PURE__ */ function() {
7350
+ function MPEG2() {
7351
+ _classCallCheck(this, MPEG2);
7352
+ }
7353
+ _createClass(MPEG2, null, [{
7354
+ key: "isHeader",
7355
+ value: function isHeader(data, offset) {
7356
+ return offset + 1 < data.length && data[offset] === 255 && (data[offset + 1] & 224) === 224 && (data[offset + 1] & 6) !== 0;
7357
+ }
7358
+ }, {
7359
+ key: "appendFrame",
7360
+ value: function appendFrame(track, data, offset, pts, frameIndex) {
7361
+ if (offset + 24 > data.length) {
7362
+ return;
7363
+ }
7364
+ var header = MPEG2.parseHeader(data, offset);
7365
+ if (header && offset + header.frameLength <= data.length) {
7366
+ var frameDuration = header.samplesPerFrame * 9e4 / header.sampleRate;
7367
+ var stamp = pts + frameIndex * frameDuration;
7368
+ var sample = {
7369
+ data: data.subarray(offset, offset + header.frameLength),
7370
+ pts: stamp,
7371
+ dts: stamp
7372
+ };
7373
+ sample.size = sample.data.byteLength;
7374
+ track.config = [];
7375
+ track.channelCount = header.channelCount;
7376
+ track.sampleRate = header.sampleRate;
7377
+ track.container = "audio/mpeg";
7378
+ track.samples.push(sample);
7379
+ return {
7380
+ length: header.frameLength
7381
+ };
7382
+ }
7383
+ }
7384
+ }, {
7385
+ key: "parseHeader",
7386
+ value: function parseHeader(data, offset) {
7387
+ var mpegVersion = data[offset + 1] >> 3 & 3;
7388
+ var mpegLayer = data[offset + 1] >> 1 & 3;
7389
+ var bitRateIndex = data[offset + 2] >> 4 & 15;
7390
+ var sampleRateIndex = data[offset + 2] >> 2 & 3;
7391
+ if (mpegVersion !== 1 && bitRateIndex !== 0 && bitRateIndex !== 15 && sampleRateIndex !== 3) {
7392
+ var paddingBit = data[offset + 2] >> 1 & 1;
7393
+ var channelMode = data[offset + 3] >> 6;
7394
+ var columnInBitrates = mpegVersion === 3 ? 3 - mpegLayer : mpegLayer === 3 ? 3 : 4;
7395
+ var bitRate = BitratesMap[columnInBitrates * 14 + bitRateIndex - 1] * 1e3;
7396
+ var columnInSampleRates = mpegVersion === 3 ? 0 : mpegVersion === 2 ? 1 : 2;
7397
+ var sampleRate = FREQ[columnInSampleRates * 3 + sampleRateIndex];
7398
+ var channelCount = channelMode === 3 ? 1 : 2;
7399
+ var sampleCoefficient = SamplesCoefficients[mpegVersion][mpegLayer];
7400
+ var bytesInSlot = BytesInSlot[mpegLayer];
7401
+ var samplesPerFrame = sampleCoefficient * 8 * bytesInSlot;
7402
+ var frameLength = Math.floor(sampleCoefficient * bitRate / sampleRate + paddingBit) * bytesInSlot;
7403
+ if (chromeVersion === null) {
7404
+ var userAgent = navigator.userAgent || "";
7405
+ var result = userAgent.match(/Chrome\/(\d+)/i);
7406
+ chromeVersion = result ? parseInt(result[1]) : 0;
7407
+ }
7408
+ var needChromeFix = !!chromeVersion && chromeVersion <= 87;
7409
+ if (needChromeFix && mpegLayer === 2 && bitRate >= 224e3 && channelMode === 0) {
7410
+ data[offset + 3] = data[offset + 3] | 128;
7411
+ }
7412
+ return {
7413
+ sampleRate,
7414
+ channelCount,
7415
+ frameLength,
7416
+ samplesPerFrame
7417
+ };
7418
+ }
7419
+ }
7420
+ }]);
7421
+ return MPEG2;
7422
+ }();
7135
7423
  var logger$4 = new Logger$1("TsDemuxer");
7136
7424
  var TsDemuxer = /* @__PURE__ */ function() {
7137
7425
  function TsDemuxer2(videoTrack, audioTrack, metadataTrack) {
7426
+ var fixerConfig = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
7138
7427
  _classCallCheck(this, TsDemuxer2);
7139
7428
  _defineProperty(this, "_pmtId", -1);
7140
7429
  _defineProperty(this, "_remainingPacketData", null);
@@ -7144,7 +7433,7 @@ var TsDemuxer = /* @__PURE__ */ function() {
7144
7433
  this.videoTrack = videoTrack || new VideoTrack();
7145
7434
  this.audioTrack = audioTrack || new AudioTrack();
7146
7435
  this.metadataTrack = metadataTrack || new MetadataTrack();
7147
- this._fixer = new TsFixer(this.videoTrack, this.audioTrack, this.metadataTrack);
7436
+ this._fixer = new TsFixer(this.videoTrack, this.audioTrack, this.metadataTrack, fixerConfig);
7148
7437
  }
7149
7438
  _createClass(TsDemuxer2, [{
7150
7439
  key: "demux",
@@ -7214,6 +7503,11 @@ var TsDemuxer = /* @__PURE__ */ function() {
7214
7503
  case 15:
7215
7504
  audioTrack.pid = audioPid = esPid;
7216
7505
  break;
7506
+ case 3:
7507
+ case 4:
7508
+ audioTrack.pid = audioPid = esPid;
7509
+ audioTrack.codecType = AudioCodecType.MP3;
7510
+ break;
7217
7511
  case 27:
7218
7512
  if (videoPid !== -1)
7219
7513
  break;
@@ -7413,7 +7707,14 @@ var TsDemuxer = /* @__PURE__ */ function() {
7413
7707
  logger$4.warn("Cannot parse audio pes", this._audioPesData);
7414
7708
  return;
7415
7709
  }
7416
- this._parseAacData(pes);
7710
+ switch (this.audioTrack.codecType) {
7711
+ case AudioCodecType.AAC:
7712
+ this._parseAacData(pes);
7713
+ break;
7714
+ case AudioCodecType.MP3:
7715
+ this._parseMPEG(pes);
7716
+ break;
7717
+ }
7417
7718
  this._audioPesData = [];
7418
7719
  }
7419
7720
  }, {
@@ -7450,6 +7751,32 @@ var TsDemuxer = /* @__PURE__ */ function() {
7450
7751
  logger$4.warn("Cannot parse aac adts", pes);
7451
7752
  }
7452
7753
  }
7754
+ }, {
7755
+ key: "_parseMPEG",
7756
+ value: function _parseMPEG(pes) {
7757
+ var data = pes.data;
7758
+ var length = data.length;
7759
+ var frameIndex = 0;
7760
+ var offset = 0;
7761
+ var pts = pes.pts;
7762
+ if (pts === void 0) {
7763
+ logger$4.warn("[tsdemuxer]: MPEG PES unknown PTS");
7764
+ return;
7765
+ }
7766
+ while (offset < length) {
7767
+ if (MPEG.isHeader(data, offset)) {
7768
+ var frame = MPEG.appendFrame(this.audioTrack, data, offset, pts, frameIndex);
7769
+ if (frame) {
7770
+ offset += frame.length;
7771
+ frameIndex++;
7772
+ } else {
7773
+ break;
7774
+ }
7775
+ } else {
7776
+ offset++;
7777
+ }
7778
+ }
7779
+ }
7453
7780
  }], [{
7454
7781
  key: "probe",
7455
7782
  value: function probe(data) {
@@ -7491,6 +7818,207 @@ var TsDemuxer = /* @__PURE__ */ function() {
7491
7818
  }]);
7492
7819
  return TsDemuxer2;
7493
7820
  }();
7821
+ var ByteReader = /* @__PURE__ */ function() {
7822
+ function ByteReader2(buf, offset, len) {
7823
+ _classCallCheck(this, ByteReader2);
7824
+ this.dv = new DataView(buf);
7825
+ this.start = this.offset = offset || this.dv.byteOffset;
7826
+ this.end = len ? this.start + len : this.start + this.dv.byteLength;
7827
+ }
7828
+ _createClass(ByteReader2, [{
7829
+ key: "buffer",
7830
+ get: function get() {
7831
+ return this.dv.buffer;
7832
+ }
7833
+ }, {
7834
+ key: "unreadLength",
7835
+ get: function get() {
7836
+ return Math.max(this.end - this.offset, 0);
7837
+ }
7838
+ }, {
7839
+ key: "size",
7840
+ get: function get() {
7841
+ return this.end - this.start;
7842
+ }
7843
+ }, {
7844
+ key: "readFloat",
7845
+ value: function readFloat(byteNum) {
7846
+ var val = 0;
7847
+ switch (byteNum) {
7848
+ case 4:
7849
+ val = this.dv.getFloat32(this.offset);
7850
+ break;
7851
+ case 8:
7852
+ val = this.dv.getFloat64(this.offset);
7853
+ break;
7854
+ default:
7855
+ throw new Error("read ".concat(byteNum, "-byte float is not supported"));
7856
+ }
7857
+ this.offset += byteNum;
7858
+ return val;
7859
+ }
7860
+ }, {
7861
+ key: "back",
7862
+ value: function back(byteNum) {
7863
+ this.offset -= byteNum;
7864
+ }
7865
+ }, {
7866
+ key: "skip",
7867
+ value: function skip(byteNum) {
7868
+ this.offset += byteNum;
7869
+ }
7870
+ }, {
7871
+ key: "readInt",
7872
+ value: function readInt(byteNum) {
7873
+ var offset = this.offset;
7874
+ this.offset += byteNum;
7875
+ switch (byteNum) {
7876
+ case 1:
7877
+ return this.dv.getInt8(offset);
7878
+ case 2:
7879
+ return this.dv.getInt16(offset);
7880
+ case 4:
7881
+ return this.dv.getInt32(offset);
7882
+ default:
7883
+ throw new Error("read ".concat(byteNum, "-byte integers is not supported"));
7884
+ }
7885
+ }
7886
+ }, {
7887
+ key: "read",
7888
+ value: function read(byteNum) {
7889
+ var offset = this.offset;
7890
+ this.offset += byteNum;
7891
+ switch (byteNum) {
7892
+ case 1:
7893
+ return this.dv.getUint8(offset);
7894
+ case 2:
7895
+ return this.dv.getUint16(offset);
7896
+ case 3:
7897
+ return (this.dv.getUint16(offset) << 8) + this.dv.getUint8(offset + 2);
7898
+ case 4:
7899
+ return this.dv.getUint32(offset);
7900
+ default:
7901
+ this.back(byteNum - 4);
7902
+ return this.read(byteNum - 4) + this.dv.getUint32(offset) * Math.pow(256, byteNum - 4);
7903
+ }
7904
+ }
7905
+ }, {
7906
+ key: "write",
7907
+ value: function write(byteNum, val) {
7908
+ var offset = this.offset;
7909
+ this.offset += byteNum;
7910
+ switch (byteNum) {
7911
+ case 1:
7912
+ return this.dv.setUint8(offset, val);
7913
+ case 2:
7914
+ return this.dv.setUint16(offset, val);
7915
+ case 3:
7916
+ return this.dv.setUint8(offset, val >>> 16), this.dv.setUint16(offset + 1, 65535 & val);
7917
+ case 4:
7918
+ return this.dv.setUint32(offset, val);
7919
+ default:
7920
+ throw new Error("write ".concat(byteNum, "-byte integers is not supported"));
7921
+ }
7922
+ }
7923
+ }, {
7924
+ key: "readToBuffer",
7925
+ value: function readToBuffer(len) {
7926
+ var buffer;
7927
+ if (this.offset || len) {
7928
+ buffer = this.dv.buffer.slice(this.offset, len ? this.offset + len : this.end);
7929
+ } else {
7930
+ buffer = this.dv.buffer;
7931
+ }
7932
+ this.offset += buffer.byteLength;
7933
+ return buffer;
7934
+ }
7935
+ }, {
7936
+ key: "readToUint8",
7937
+ value: function readToUint8(len) {
7938
+ var uint8 = new Uint8Array(this.dv.buffer, this.offset, len || this.unreadLength);
7939
+ this.offset += uint8.byteLength;
7940
+ return uint8;
7941
+ }
7942
+ }, {
7943
+ key: "readString",
7944
+ value: function readString(len) {
7945
+ var i = 0, str = "";
7946
+ for (; i < len; i++) {
7947
+ str += String.fromCharCode(this.dv.getUint8(this.offset));
7948
+ this.offset++;
7949
+ }
7950
+ return str;
7951
+ }
7952
+ }], [{
7953
+ key: "fromUint8",
7954
+ value: function fromUint8(uint8) {
7955
+ return new ByteReader2(uint8.buffer, uint8.byteOffset, uint8.byteLength);
7956
+ }
7957
+ }, {
7958
+ key: "concatUint8s",
7959
+ value: function concatUint8s(args) {
7960
+ var uint8 = new Uint8Array(args.reduce(function(ret, v) {
7961
+ return ret + v.byteLength;
7962
+ }, 0));
7963
+ var offset = 0;
7964
+ args.forEach(function(v) {
7965
+ uint8.set(v, offset);
7966
+ offset += v.byteLength;
7967
+ });
7968
+ return uint8;
7969
+ }
7970
+ }, {
7971
+ key: "concatUint8",
7972
+ value: function concatUint8() {
7973
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
7974
+ args[_key] = arguments[_key];
7975
+ }
7976
+ return this.concatUint8s(args);
7977
+ }
7978
+ }]);
7979
+ return ByteReader2;
7980
+ }();
7981
+ var BitReader = /* @__PURE__ */ function() {
7982
+ function BitReader2(val, size) {
7983
+ _classCallCheck(this, BitReader2);
7984
+ this.offset = 0;
7985
+ this.val = val;
7986
+ this.size = size;
7987
+ }
7988
+ _createClass(BitReader2, [{
7989
+ key: "skip",
7990
+ value: function skip(len) {
7991
+ this.offset += len;
7992
+ }
7993
+ }, {
7994
+ key: "read",
7995
+ value: function read(len) {
7996
+ var unreadLength = this.size - this.offset - len;
7997
+ if (unreadLength >= 0) {
7998
+ var bits = 0, i = 0;
7999
+ this.offset += len;
8000
+ if (this.size > 31) {
8001
+ for (; i < len; i++) {
8002
+ bits += Math.pow(2, i);
8003
+ }
8004
+ return this.val / Math.pow(2, unreadLength) & bits;
8005
+ } else {
8006
+ for (; i < len; i++) {
8007
+ bits += 1 << i;
8008
+ }
8009
+ return this.val >>> unreadLength & bits;
8010
+ }
8011
+ }
8012
+ throw new Error("the number of the read operation exceeds the total length limit of bits");
8013
+ }
8014
+ }], [{
8015
+ key: "fromByte",
8016
+ value: function fromByte(byte, len) {
8017
+ return new BitReader2(byte.read(len), len << 3);
8018
+ }
8019
+ }]);
8020
+ return BitReader2;
8021
+ }();
7494
8022
  var MP4Parser = /* @__PURE__ */ function() {
7495
8023
  function MP4Parser2() {
7496
8024
  _classCallCheck(this, MP4Parser2);
@@ -7648,18 +8176,36 @@ var MP4Parser = /* @__PURE__ */ function() {
7648
8176
  key: "tkhd",
7649
8177
  value: function tkhd(box) {
7650
8178
  return parseBox(box, true, function(ret, data) {
7651
- var start = 0;
8179
+ var byte = ByteReader.fromUint8(data);
7652
8180
  if (ret.version === 1) {
7653
- ret.trackId = readBig32(data, 16);
7654
- ret.duration = readBig64(data, 24);
7655
- start += 32;
8181
+ byte.read(8);
8182
+ byte.read(8);
8183
+ ret.trackId = byte.read(4);
8184
+ byte.read(4);
8185
+ ret.duration = byte.read(8);
7656
8186
  } else {
7657
- ret.trackId = readBig32(data, 8);
7658
- ret.duration = readBig32(data, 16);
7659
- start += 20;
8187
+ byte.read(4);
8188
+ byte.read(4);
8189
+ ret.trackId = byte.read(4);
8190
+ byte.read(4);
8191
+ ret.duration = byte.read(4);
8192
+ }
8193
+ byte.skip(16);
8194
+ ret.matrix = [];
8195
+ for (var i = 0; i < 36; i++) {
8196
+ ret.matrix.push(byte.read(1));
8197
+ }
8198
+ byte.back(36);
8199
+ var caculatedMatrix = [];
8200
+ for (var _i = 0, int32; _i < 3; _i++) {
8201
+ caculatedMatrix.push(combineToFloat(byte.readInt(2), byte.readInt(2)));
8202
+ caculatedMatrix.push(combineToFloat(byte.readInt(2), byte.readInt(2)));
8203
+ int32 = byte.readInt(4);
8204
+ caculatedMatrix.push(combineToFloat(int32 >> 30, int32 & 1073741823));
7660
8205
  }
7661
- ret.width = readBig32(data, start + 52);
7662
- ret.height = readBig32(data, start + 56);
8206
+ ret.rotation = toDegree(caculatedMatrix);
8207
+ ret.width = byte.read(4);
8208
+ ret.height = byte.read(4);
7663
8209
  });
7664
8210
  }
7665
8211
  }, {
@@ -7789,7 +8335,7 @@ var MP4Parser = /* @__PURE__ */ function() {
7789
8335
  if (ret.version > 0) {
7790
8336
  var numKeyIds = readBig32(data, start);
7791
8337
  start += 4;
7792
- for (var _i = 0; _i < ("" + numKeyIds).length; _i++) {
8338
+ for (var _i2 = 0; _i2 < ("" + numKeyIds).length; _i2++) {
7793
8339
  for (var j = 0; j < 16; j++) {
7794
8340
  var keyId = data[start];
7795
8341
  start += 1;
@@ -7812,6 +8358,8 @@ var MP4Parser = /* @__PURE__ */ function() {
7812
8358
  ret.entryCount = readBig32(data);
7813
8359
  ret.entries = MP4Parser2.findBox(data.subarray(4), [], start + 4).map(function(b) {
7814
8360
  switch (b.type) {
8361
+ case "av01":
8362
+ return MP4Parser2.av01(b);
7815
8363
  case "avc1":
7816
8364
  case "avc2":
7817
8365
  case "avc3":
@@ -7891,6 +8439,69 @@ var MP4Parser = /* @__PURE__ */ function() {
7891
8439
  }
7892
8440
  });
7893
8441
  }
8442
+ }, {
8443
+ key: "colr",
8444
+ value: function colr(box) {
8445
+ return parseBox(box, false, function(ret, data) {
8446
+ var byte = ByteReader.fromUint8(data);
8447
+ ret.data = box.data;
8448
+ ret.colorType = byte.readString(4);
8449
+ if (ret.colorType === "nclx") {
8450
+ ret.colorPrimaries = byte.read(2);
8451
+ ret.transferCharacteristics = byte.read(2);
8452
+ ret.matrixCoefficients = byte.read(2);
8453
+ ret.fullRangeFlag = byte.read(1) >> 7;
8454
+ } else if (ret.colorType === "rICC" || ret.colorType === "prof") {
8455
+ ret.iccProfile = data.readToUint8();
8456
+ }
8457
+ });
8458
+ }
8459
+ }, {
8460
+ key: "av01",
8461
+ value: function av01(box) {
8462
+ return parseBox(box, false, function(ret, data, start) {
8463
+ var bodyStart = parseVisualSampleEntry(ret, data);
8464
+ var bodyData = data.subarray(bodyStart);
8465
+ start += bodyStart;
8466
+ ret.av1C = MP4Parser2.av1C(MP4Parser2.findBox(bodyData, ["av1C"], start)[0]);
8467
+ ret.colr = MP4Parser2.colr(MP4Parser2.findBox(bodyData, ["colr"], start)[0]);
8468
+ });
8469
+ }
8470
+ }, {
8471
+ key: "av1C",
8472
+ value: function av1C(box) {
8473
+ return parseBox(box, false, function(ret, data) {
8474
+ ret.data = box.data;
8475
+ var byte = ByteReader.fromUint8(data);
8476
+ var bit = BitReader.fromByte(byte, 4);
8477
+ ret.marker = bit.read(1);
8478
+ ret.version = bit.read(7);
8479
+ ret.seqProfile = bit.read(3);
8480
+ ret.seqLevelIdx0 = bit.read(5);
8481
+ ret.seqTier0 = bit.read(1);
8482
+ ret.highBitdepth = bit.read(1);
8483
+ ret.twelveBit = bit.read(1);
8484
+ ret.monochrome = bit.read(1);
8485
+ ret.chromaSubsamplingX = bit.read(1);
8486
+ ret.chromaSubsamplingY = bit.read(1);
8487
+ ret.chromaSamplePosition = bit.read(2);
8488
+ ret.reserved = bit.read(3);
8489
+ ret.initialPresentationDelayPresent = bit.read(1);
8490
+ if (ret.initialPresentationDelayPresent) {
8491
+ ret.initialPresentationDelayMinusOne = bit.read(4);
8492
+ } else {
8493
+ ret.initialPresentationDelayMinusOne = 0;
8494
+ }
8495
+ ret.configOBUs = byte.readToUint8();
8496
+ var bitdepth;
8497
+ if (ret.seqLevelIdx0 === 2 && ret.highBitdepth === 1) {
8498
+ bitdepth = ret.twelveBit === 1 ? "12" : "10";
8499
+ } else if (ret.seqProfile <= 2) {
8500
+ bitdepth = ret.highBitdepth === 1 ? "10" : "08";
8501
+ }
8502
+ ret.codec = ["av01", ret.seqProfile, (ret.seqLevelIdx0 < 10 ? "0" + ret.seqLevelIdx0 : ret.seqLevelIdx0) + (ret.seqTier0 ? "H" : "M"), bitdepth].join(".");
8503
+ });
8504
+ }
7894
8505
  }, {
7895
8506
  key: "avc1",
7896
8507
  value: function avc1(box) {
@@ -7925,7 +8536,7 @@ var MP4Parser = /* @__PURE__ */ function() {
7925
8536
  ret.ppsLength = data[start];
7926
8537
  start += 1;
7927
8538
  ret.pps = [];
7928
- for (var _i2 = 0; _i2 < ret.ppsLength; _i2++) {
8539
+ for (var _i3 = 0; _i3 < ret.ppsLength; _i3++) {
7929
8540
  var _size = readBig16(data, start);
7930
8541
  start += 2;
7931
8542
  ret.pps.push(data.subarray(start, start += _size));
@@ -8094,7 +8705,7 @@ var MP4Parser = /* @__PURE__ */ function() {
8094
8705
  start += 8;
8095
8706
  }
8096
8707
  } else {
8097
- for (var _i3 = 0; _i3 < entryCount; _i3++) {
8708
+ for (var _i4 = 0; _i4 < entryCount; _i4++) {
8098
8709
  entries.push({
8099
8710
  count: readBig32(data, start),
8100
8711
  offset: -(~readBig32(data, start + 4) + 1)
@@ -8316,13 +8927,20 @@ var MP4Parser = /* @__PURE__ */ function() {
8316
8927
  v.mvhdTimecale = moov.mvhd.timescale;
8317
8928
  v.timescale = v.formatTimescale = vTrack.mdia.mdhd.timescale;
8318
8929
  v.duration = vTrack.mdia.mdhd.duration || v.mvhdDurtion / v.mvhdTimecale * v.timescale;
8930
+ v.rotation = vTrack.tkhd.rotation;
8931
+ v.matrix = vTrack.tkhd.matrix;
8319
8932
  var e1 = vTrack.mdia.minf.stbl.stsd.entries[0];
8320
8933
  v.width = e1.width;
8321
8934
  v.height = e1.height;
8322
8935
  if (e1.pasp) {
8323
8936
  v.sarRatio = [e1.pasp.hSpacing, e1.pasp.vSpacing];
8324
8937
  }
8325
- if (e1.hvcC) {
8938
+ if (e1.av1C) {
8939
+ v.codecType = VideoCodecType.AV1;
8940
+ v.codec = e1.av1C.codec;
8941
+ v.av1C = e1.av1C.data;
8942
+ v.colr = e1.colr.data;
8943
+ } else if (e1.hvcC) {
8326
8944
  v.codecType = VideoCodecType.HEVC;
8327
8945
  v.codec = e1.hvcC.codec;
8328
8946
  v.vps = e1.hvcC.vps;
@@ -8641,8 +9259,9 @@ function parseAudioSampleEntry(ret, data) {
8641
9259
  function parseBox(box, isFullBox, parse3) {
8642
9260
  if (!box)
8643
9261
  return;
8644
- if (box.size !== box.data.length)
9262
+ if (box.size !== box.data.length) {
8645
9263
  throw new Error("box ".concat(box.type, " size !== data.length"));
9264
+ }
8646
9265
  var ret = {
8647
9266
  start: box.start,
8648
9267
  size: box.size,
@@ -8681,29 +9300,185 @@ var toHex = function toHex2() {
8681
9300
  var FMP4Demuxer = /* @__PURE__ */ function() {
8682
9301
  function FMP4Demuxer2(videoTrack, audioTrack, metadataTrack) {
8683
9302
  _classCallCheck(this, FMP4Demuxer2);
9303
+ _defineProperty(this, "__loadedMoofWraps", []);
9304
+ _defineProperty(this, "__lastRemainData", null);
9305
+ _defineProperty(this, "__lastRemainDataStart", 0);
9306
+ _defineProperty(this, "__nextMoofStart", -1);
8684
9307
  this.videoTrack = videoTrack || new VideoTrack();
8685
9308
  this.audioTrack = audioTrack || new AudioTrack();
8686
9309
  this.metadataTrack = metadataTrack || new MetadataTrack();
8687
9310
  }
8688
9311
  _createClass(FMP4Demuxer2, [{
8689
- key: "demux",
8690
- value: function demux(videoData, audioData) {
9312
+ key: "demuxPart",
9313
+ value: function demuxPart(partData, partDataStart, moov) {
9314
+ var _this = this;
8691
9315
  var videoTrack = this.videoTrack, audioTrack = this.audioTrack;
8692
9316
  var videoExist = videoTrack.exist();
8693
9317
  var audioExist = audioTrack.exist();
9318
+ var isAV01 = /av01/.test(videoTrack.codec);
8694
9319
  videoTrack.samples = [];
8695
9320
  audioTrack.samples = [];
8696
- if (audioData) {
8697
- if (!audioExist) {
8698
- var moovBox = MP4Parser.findBox(audioData, ["moov"])[0];
8699
- if (!moovBox)
8700
- throw new Error("cannot found moov box");
8701
- MP4Parser.moovToTrack(MP4Parser.moov(moovBox), null, audioTrack);
9321
+ var data = partData;
9322
+ var dataStart = partDataStart;
9323
+ if (this.__lastRemainData) {
9324
+ var lastRemainDataEnd = this.__lastRemainDataStart + this.__lastRemainData.byteLength;
9325
+ var continuous = partDataStart <= lastRemainDataEnd && partDataStart > this.__lastRemainDataStart && partDataStart + partData.byteLength > lastRemainDataEnd;
9326
+ if (continuous) {
9327
+ var noDuplicateData = partData.subarray(this.__lastRemainData.byteLength + this.__lastRemainDataStart - partDataStart);
9328
+ data = concatUint8Array(this.__lastRemainData, noDuplicateData);
9329
+ dataStart = this.__lastRemainDataStart;
9330
+ this.__lastRemainData = null;
9331
+ } else {
9332
+ this.__lastRemainData = null;
9333
+ this.__lastRemainDataStart = 0;
9334
+ this.__nextMoofStart = -1;
8702
9335
  }
8703
- var moofBox = MP4Parser.findBox(audioData, ["moof"])[0];
8704
- if (moofBox) {
8705
- var samples = MP4Parser.moofToSamples(MP4Parser.moof(moofBox), null, audioTrack)[audioTrack.id];
8706
- var baseMediaDecodeTime = audioTrack.baseMediaDecodeTime;
9336
+ }
9337
+ if (!moov) {
9338
+ var moovBox = MP4Parser.findBox(data, ["moov"])[0];
9339
+ if (!moovBox)
9340
+ throw new Error("cannot found moov box");
9341
+ moov = MP4Parser.moov(moovBox);
9342
+ }
9343
+ if (data) {
9344
+ var dataEnd = dataStart + data.byteLength;
9345
+ if (!videoExist && !audioExist) {
9346
+ MP4Parser.moovToTrack(moov, videoTrack, audioTrack);
9347
+ }
9348
+ var moofBoxes = [];
9349
+ if (this.__nextMoofStart < 0) {
9350
+ MP4Parser.findBox(data, ["moof"], dataStart).forEach(function(v) {
9351
+ return moofBoxes.push(v);
9352
+ });
9353
+ } else if (this.__nextMoofStart >= dataStart && this.__nextMoofStart <= dataEnd - 8) {
9354
+ MP4Parser.findBox(data.subarray(this.__nextMoofStart - dataStart), ["moof"], this.__nextMoofStart).forEach(function(v) {
9355
+ return moofBoxes.push(v);
9356
+ });
9357
+ }
9358
+ moofBoxes.filter(function(moofBox) {
9359
+ return moofBox.size <= moofBox.data.length;
9360
+ }).forEach(function(moofBox) {
9361
+ var moof = MP4Parser.moof(moofBox);
9362
+ _this.__nextMoofStart = moof.start + Math.max.apply(Math, _toConsumableArray(moof.traf.map(function(v) {
9363
+ return v.trun.samples.reduce(function(ret, w) {
9364
+ return ret + w.size;
9365
+ }, v.trun.dataOffset || 0);
9366
+ })));
9367
+ _this.__loadedMoofWraps.push({
9368
+ start: moof.start,
9369
+ nextMoofStart: _this.__nextMoofStart,
9370
+ moof
9371
+ });
9372
+ _this.__loadedMoofWraps.sort(function(p, n) {
9373
+ return p.start - n.start;
9374
+ });
9375
+ });
9376
+ var _iterator = _createForOfIteratorHelper(this.__loadedMoofWraps), _step;
9377
+ try {
9378
+ var _loop = function _loop2() {
9379
+ var moofWrap = _step.value;
9380
+ if (moofWrap.start > dataEnd || moofWrap.nextMoofStart < dataStart) {
9381
+ return "continue";
9382
+ }
9383
+ var moofStart = moofWrap.start;
9384
+ var tracks = MP4Parser.moofToSamples(moofWrap.moof, videoTrack, audioTrack);
9385
+ var videoBaseMediaDecodeTime = videoTrack.baseMediaDecodeTime;
9386
+ var audioBaseMediaDecodeTime = audioTrack.baseMediaDecodeTime;
9387
+ var nalSize;
9388
+ Object.keys(tracks).forEach(function(k) {
9389
+ if (videoTrack.id == k) {
9390
+ tracks[k].some(function(x) {
9391
+ var xStart = x.offset += moofStart;
9392
+ if (xStart < dataStart) {
9393
+ return;
9394
+ }
9395
+ if (xStart + x.size > dataEnd) {
9396
+ return true;
9397
+ }
9398
+ var sample = new VideoSample((x.pts || x.dts) + videoBaseMediaDecodeTime, x.dts + videoBaseMediaDecodeTime);
9399
+ sample.duration = x.duration;
9400
+ sample.gopId = x.gopId;
9401
+ if (x.keyframe)
9402
+ sample.setToKeyframe();
9403
+ var sampleData = data.subarray(xStart - dataStart, xStart - dataStart + x.size);
9404
+ sample.data = sampleData;
9405
+ if (!isAV01) {
9406
+ var start = 0;
9407
+ var len = sampleData.length - 1;
9408
+ while (start < len) {
9409
+ nalSize = readBig32(sampleData, start);
9410
+ start += 4;
9411
+ sample.units.push(sampleData.subarray(start, start + nalSize));
9412
+ start += nalSize;
9413
+ }
9414
+ }
9415
+ _this.__lastRemainDataStart = xStart + x.size;
9416
+ videoTrack.samples.push(sample);
9417
+ });
9418
+ } else if (audioTrack.id == k) {
9419
+ tracks[k].some(function(x) {
9420
+ var xStart = x.offset + moofStart;
9421
+ if (xStart < dataStart) {
9422
+ return;
9423
+ }
9424
+ if (xStart + x.size > dataEnd) {
9425
+ return true;
9426
+ }
9427
+ var sampleData = data.subarray(xStart - dataStart, xStart - dataStart + x.size);
9428
+ audioTrack.samples.push(new AudioSample(x.dts + audioBaseMediaDecodeTime, sampleData, x.duration));
9429
+ _this.__lastRemainDataStart = xStart + x.size;
9430
+ });
9431
+ }
9432
+ });
9433
+ };
9434
+ for (_iterator.s(); !(_step = _iterator.n()).done; ) {
9435
+ var _ret = _loop();
9436
+ if (_ret === "continue")
9437
+ continue;
9438
+ }
9439
+ } catch (err) {
9440
+ _iterator.e(err);
9441
+ } finally {
9442
+ _iterator.f();
9443
+ }
9444
+ }
9445
+ if (this.__lastRemainDataStart > dataStart && this.__lastRemainDataStart < data.byteLength + dataStart) {
9446
+ this.__lastRemainData = data.subarray(this.__lastRemainDataStart - dataStart);
9447
+ } else {
9448
+ this.__lastRemainData = data;
9449
+ this.__lastRemainDataStart = dataStart;
9450
+ }
9451
+ if (videoTrack.samples.length) {
9452
+ videoTrack.baseMediaDecodeTime = videoTrack.samples[0].pts;
9453
+ }
9454
+ if (audioTrack.samples.length) {
9455
+ audioTrack.baseMediaDecodeTime = audioTrack.samples[0].pts;
9456
+ }
9457
+ return {
9458
+ videoTrack,
9459
+ audioTrack,
9460
+ metadataTrack: this.metadataTrack
9461
+ };
9462
+ }
9463
+ }, {
9464
+ key: "demux",
9465
+ value: function demux(videoData, audioData) {
9466
+ var videoTrack = this.videoTrack, audioTrack = this.audioTrack;
9467
+ var videoExist = videoTrack.exist();
9468
+ var audioExist = audioTrack.exist();
9469
+ videoTrack.samples = [];
9470
+ audioTrack.samples = [];
9471
+ if (audioData) {
9472
+ if (!audioExist) {
9473
+ var moovBox = MP4Parser.findBox(audioData, ["moov"])[0];
9474
+ if (!moovBox)
9475
+ throw new Error("cannot found moov box");
9476
+ MP4Parser.moovToTrack(MP4Parser.moov(moovBox), null, audioTrack);
9477
+ }
9478
+ var moofBox = MP4Parser.findBox(audioData, ["moof"])[0];
9479
+ if (moofBox) {
9480
+ var samples = MP4Parser.moofToSamples(MP4Parser.moof(moofBox), null, audioTrack)[audioTrack.id];
9481
+ var baseMediaDecodeTime = audioTrack.baseMediaDecodeTime;
8707
9482
  if (samples) {
8708
9483
  var baseOffset = moofBox.start;
8709
9484
  samples.map(function(x) {
@@ -8804,13 +9579,13 @@ var Buffer = /* @__PURE__ */ function() {
8804
9579
  _createClass(Buffer2, [{
8805
9580
  key: "write",
8806
9581
  value: function write() {
8807
- var self = this;
9582
+ var self2 = this;
8808
9583
  for (var _len2 = arguments.length, buffer = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
8809
9584
  buffer[_key2] = arguments[_key2];
8810
9585
  }
8811
9586
  buffer.forEach(function(item) {
8812
9587
  if (item) {
8813
- self.buffer = Concat(Uint8Array, self.buffer, item);
9588
+ self2.buffer = Concat(Uint8Array, self2.buffer, item);
8814
9589
  } else {
8815
9590
  window.console.warn(item);
8816
9591
  }
@@ -9177,10 +9952,16 @@ var MP4 = /* @__PURE__ */ function() {
9177
9952
  if (track.useEME && track.enca) {
9178
9953
  content = MP42.enca(track);
9179
9954
  } else {
9180
- content = MP42.mp4a(track);
9955
+ if (track.codecType === AudioCodecType.OPUS) {
9956
+ content = MP42.opus(track);
9957
+ } else {
9958
+ content = MP42.mp4a(track);
9959
+ }
9181
9960
  }
9182
9961
  } else if (track.useEME && track.encv) {
9183
9962
  content = MP42.encv(track);
9963
+ } else if (track.av1C) {
9964
+ content = MP42.av01(track);
9184
9965
  } else {
9185
9966
  content = MP42.avc1hev1(track);
9186
9967
  }
@@ -9393,6 +10174,90 @@ var MP4 = /* @__PURE__ */ function() {
9393
10174
  var schi = MP42.schi(data);
9394
10175
  return MP42.box(MP42.types.sinf, content, MP42.box(MP42.types.frma, frma), MP42.box(MP42.types.schm, schm), schi);
9395
10176
  }
10177
+ }, {
10178
+ key: "av01",
10179
+ value: function av01(track) {
10180
+ return MP42.box(MP42.types.av01, new Uint8Array([
10181
+ 0,
10182
+ 0,
10183
+ 0,
10184
+ 0,
10185
+ 0,
10186
+ 0,
10187
+ 0,
10188
+ 1,
10189
+ 0,
10190
+ 0,
10191
+ 0,
10192
+ 0,
10193
+ 0,
10194
+ 0,
10195
+ 0,
10196
+ 0,
10197
+ 0,
10198
+ 0,
10199
+ 0,
10200
+ 0,
10201
+ 0,
10202
+ 0,
10203
+ 0,
10204
+ 0,
10205
+ track.width >> 8 & 255,
10206
+ track.width & 255,
10207
+ track.height >> 8 & 255,
10208
+ track.height & 255,
10209
+ 0,
10210
+ 72,
10211
+ 0,
10212
+ 0,
10213
+ 0,
10214
+ 72,
10215
+ 0,
10216
+ 0,
10217
+ 0,
10218
+ 0,
10219
+ 0,
10220
+ 0,
10221
+ 0,
10222
+ 1,
10223
+ 0,
10224
+ 0,
10225
+ 0,
10226
+ 0,
10227
+ 0,
10228
+ 0,
10229
+ 0,
10230
+ 0,
10231
+ 0,
10232
+ 0,
10233
+ 0,
10234
+ 0,
10235
+ 0,
10236
+ 0,
10237
+ 0,
10238
+ 0,
10239
+ 0,
10240
+ 0,
10241
+ 0,
10242
+ 0,
10243
+ 0,
10244
+ 0,
10245
+ 0,
10246
+ 0,
10247
+ 0,
10248
+ 0,
10249
+ 0,
10250
+ 0,
10251
+ 0,
10252
+ 0,
10253
+ 0,
10254
+ 0,
10255
+ 0,
10256
+ 24,
10257
+ 17,
10258
+ 17
10259
+ ]), track.av1C, track.colr);
10260
+ }
9396
10261
  }, {
9397
10262
  key: "avc1hev1",
9398
10263
  value: function avc1hev1(track) {
@@ -9763,6 +10628,53 @@ var MP4 = /* @__PURE__ */ function() {
9763
10628
  )));
9764
10629
  return esds2;
9765
10630
  }
10631
+ }, {
10632
+ key: "opus",
10633
+ value: function opus(track) {
10634
+ var opusAudioDescription = new Uint8Array([
10635
+ 0,
10636
+ 0,
10637
+ 0,
10638
+ 0,
10639
+ 0,
10640
+ 0,
10641
+ 0,
10642
+ 1,
10643
+ 0,
10644
+ 0,
10645
+ 0,
10646
+ 0,
10647
+ 0,
10648
+ 0,
10649
+ 0,
10650
+ 0,
10651
+ 0,
10652
+ track.channelCount,
10653
+ 0,
10654
+ 16,
10655
+ 0,
10656
+ 0,
10657
+ 0,
10658
+ 0,
10659
+ track.sampleRate >> 8 & 255,
10660
+ track.sampleRate & 255,
10661
+ 0,
10662
+ 0
10663
+ ]);
10664
+ var opusSpecificConfig = track.config.length ? MP42.dOps(track) : [];
10665
+ return MP42.box(MP42.types.Opus, opusAudioDescription, opusSpecificConfig);
10666
+ }
10667
+ }, {
10668
+ key: "dOps",
10669
+ value: function dOps(track) {
10670
+ if (track.config) {
10671
+ track.config[4] = track.sampleRate >>> 24 & 255;
10672
+ track.config[5] = track.sampleRate >>> 16 & 255;
10673
+ track.config[6] = track.sampleRate >>> 8 & 255;
10674
+ track.config[7] = track.sampleRate & 255;
10675
+ return MP42.box(MP42.types.dOps, track.config);
10676
+ }
10677
+ }
9766
10678
  }, {
9767
10679
  key: "mvex",
9768
10680
  value: function mvex(tracks) {
@@ -10365,7 +11277,7 @@ var MP4 = /* @__PURE__ */ function() {
10365
11277
  }]);
10366
11278
  return MP42;
10367
11279
  }();
10368
- _defineProperty(MP4, "types", ["avc1", "avcC", "hvc1", "hvcC", "dinf", "dref", "esds", "ftyp", "hdlr", "mdat", "mdhd", "mdia", "mfhd", "minf", "moof", "moov", "mp4a", "mvex", "mvhd", "pasp", "stbl", "stco", "stsc", "stsd", "stsz", "stts", "tfdt", "tfhd", "traf", "trak", "trex", "tkhd", "vmhd", "smhd", "ctts", "stss", "styp", "pssh", "sidx", "sbgp", "saiz", "saio", "senc", "trun", "encv", "enca", "sinf", "btrt", "frma", "tenc", "schm", "schi", "mehd", "fiel", "sdtp"].reduce(function(p, c) {
11280
+ _defineProperty(MP4, "types", ["Opus", "dOps", "av01", "av1C", "avc1", "avcC", "hvc1", "hvcC", "dinf", "dref", "esds", "ftyp", "hdlr", "mdat", "mdhd", "mdia", "mfhd", "minf", "moof", "moov", "mp4a", "mvex", "mvhd", "pasp", "stbl", "stco", "stsc", "stsd", "stsz", "stts", "tfdt", "tfhd", "traf", "trak", "trex", "tkhd", "vmhd", "smhd", "ctts", "stss", "styp", "pssh", "sidx", "sbgp", "saiz", "saio", "senc", "trun", "encv", "enca", "sinf", "btrt", "frma", "tenc", "schm", "schi", "mehd", "fiel", "sdtp"].reduce(function(p, c) {
10369
11281
  p[c] = [c.charCodeAt(0), c.charCodeAt(1), c.charCodeAt(2), c.charCodeAt(3)];
10370
11282
  return p;
10371
11283
  }, /* @__PURE__ */ Object.create(null)));
@@ -10700,30 +11612,46 @@ var FMP4Remuxer = /* @__PURE__ */ function() {
10700
11612
  };
10701
11613
  }
10702
11614
  var samples = track.samples;
11615
+ var isAV01 = /av01/.test(track.codec);
10703
11616
  var mdatSize = 0;
10704
- samples.forEach(function(s) {
10705
- mdatSize += s.units.reduce(function(t, c) {
10706
- return t + c.byteLength;
10707
- }, 0);
10708
- mdatSize += s.units.length * 4;
10709
- });
10710
- var mdata = new Uint8Array(mdatSize);
10711
- var mdatView = new DataView(mdata.buffer);
10712
- var _loop = function _loop2(_offset, _sample) {
10713
- _sample = samples[i];
10714
- var sampleSize = 0;
10715
- _sample.units.forEach(function(u) {
10716
- mdatView.setUint32(_offset, u.byteLength);
10717
- _offset += 4;
10718
- mdata.set(u, _offset);
10719
- _offset += u.byteLength;
10720
- sampleSize += 4 + u.byteLength;
11617
+ if (isAV01) {
11618
+ samples.forEach(function(s) {
11619
+ mdatSize += s.data.byteLength;
10721
11620
  });
10722
- _sample.size = sampleSize;
10723
- offset = _offset, sample = _sample;
10724
- };
10725
- for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
10726
- _loop(offset, sample);
11621
+ } else {
11622
+ samples.forEach(function(s) {
11623
+ mdatSize += s.units.reduce(function(t, c) {
11624
+ return t + c.byteLength;
11625
+ }, 0);
11626
+ mdatSize += s.units.length * 4;
11627
+ });
11628
+ }
11629
+ var mdata = new Uint8Array(mdatSize);
11630
+ if (isAV01) {
11631
+ for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
11632
+ sample = samples[i];
11633
+ mdata.set(sample.data, offset);
11634
+ sample.size = sample.data.byteLength;
11635
+ offset += sample.size;
11636
+ }
11637
+ } else {
11638
+ var mdatView = new DataView(mdata.buffer);
11639
+ var _loop = function _loop2(_offset2, _sample2) {
11640
+ _sample2 = samples[_i];
11641
+ var sampleSize = 0;
11642
+ _sample2.units.forEach(function(u) {
11643
+ mdatView.setUint32(_offset2, u.byteLength);
11644
+ _offset2 += 4;
11645
+ mdata.set(u, _offset2);
11646
+ _offset2 += u.byteLength;
11647
+ sampleSize += 4 + u.byteLength;
11648
+ });
11649
+ _sample2.size = sampleSize;
11650
+ _offset = _offset2, _sample = _sample2;
11651
+ };
11652
+ for (var _i = 0, _l = samples.length, _offset = 0, _sample; _i < _l; _i++) {
11653
+ _loop(_offset, _sample);
11654
+ }
10727
11655
  }
10728
11656
  var mdat = MP4.mdat(mdata);
10729
11657
  var moof = MP4.moof([track]);
@@ -10882,11 +11810,11 @@ var Event$1 = _objectSpread2$2(_objectSpread2$2({}, EVENT), {}, {
10882
11810
  });
10883
11811
  var logger$3 = new Logger$2("Transmuxer");
10884
11812
  var Transmuxer = /* @__PURE__ */ function() {
10885
- function Transmuxer2(hls, isMP4, needRemux) {
11813
+ function Transmuxer2(hls, isMP4, needRemux, fixerConfig) {
10886
11814
  _classCallCheck$3(this, Transmuxer2);
10887
11815
  _defineProperty$3(this, "_initSegmentId", "");
10888
11816
  this.hls = hls;
10889
- this._demuxer = isMP4 ? new FMP4Demuxer() : new TsDemuxer();
11817
+ this._demuxer = isMP4 ? new FMP4Demuxer() : new TsDemuxer(null, null, null, fixerConfig);
10890
11818
  this._isMP4 = isMP4;
10891
11819
  if (needRemux)
10892
11820
  this._remuxer = new FMP4Remuxer(this._demuxer.videoTrack, this._demuxer.audioTrack);
@@ -10917,7 +11845,8 @@ var Transmuxer = /* @__PURE__ */ function() {
10917
11845
  timescale: audioTrack.timescale,
10918
11846
  firstDts: audioTrack.firstDts / videoTrack.timescale,
10919
11847
  firstPts: audioTrack.firstPts / videoTrack.timescale,
10920
- duration: audioTrack.samplesDuration / videoTrack.timescale
11848
+ duration: audioTrack.samplesDuration / videoTrack.timescale,
11849
+ container: audioTrack.container
10921
11850
  };
10922
11851
  var newId = "".concat(videoTrack.codec, "/").concat(videoTrack.width, "/").concat(videoTrack.height, "/").concat(audioTrack.codec, "/").concat(audioTrack.config);
10923
11852
  if (newId !== this._initSegmentId) {
@@ -11041,7 +11970,7 @@ var Transmuxer = /* @__PURE__ */ function() {
11041
11970
  }]);
11042
11971
  return Transmuxer2;
11043
11972
  }();
11044
- var _excluded = ["data"], _excluded2 = ["data"];
11973
+ var _excluded$1 = ["data"], _excluded2 = ["data"];
11045
11974
  var logger$2 = new Logger$2("BufferService");
11046
11975
  var BufferService = /* @__PURE__ */ function() {
11047
11976
  function BufferService2(hls) {
@@ -11153,11 +12082,11 @@ var BufferService = /* @__PURE__ */ function() {
11153
12082
  return;
11154
12083
  if (TsDemuxer.probe(chunk)) {
11155
12084
  if (!this._transmuxer)
11156
- this._transmuxer = new Transmuxer(this.hls, false, !this._softVideo);
12085
+ this._transmuxer = new Transmuxer(this.hls, false, !this._softVideo, this.hls.config.fixerConfig);
11157
12086
  } else if (MP4Parser.probe(chunk)) {
11158
12087
  if (this._softVideo) {
11159
12088
  if (!this._transmuxer)
11160
- this._transmuxer = new Transmuxer(this.hls, true);
12089
+ this._transmuxer = new Transmuxer(this.hls, true, null, this.hls.config.fixerConfig);
11161
12090
  } else {
11162
12091
  this._directAppend = true;
11163
12092
  var mix = false;
@@ -11207,7 +12136,8 @@ var BufferService = /* @__PURE__ */ function() {
11207
12136
  key: "appendBuffer",
11208
12137
  value: function() {
11209
12138
  var _appendBuffer = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee2(segment, audioSegment, videoChunk, audioChunk, discontinuity, contiguous, startTime) {
11210
- var p, needInit, _this$_transmuxer$tra, _this$_transmuxer$tra2, video, audio, isFirstAppend, mse, _p, videoData, videoRest, audioData, audioRest;
12139
+ var _this2 = this;
12140
+ var afterAppend, p, needInit, _this$_transmuxer$tra, _this$_transmuxer$tra2, video, audio, isFirstAppend, mse, _p, videoData, videoRest, audioData, audioRest;
11211
12141
  return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
11212
12142
  while (1)
11213
12143
  switch (_context2.prev = _context2.next) {
@@ -11218,8 +12148,18 @@ var BufferService = /* @__PURE__ */ function() {
11218
12148
  }
11219
12149
  return _context2.abrupt("return");
11220
12150
  case 2:
12151
+ afterAppend = function afterAppend2() {
12152
+ var _this2$hls;
12153
+ if ((_this2$hls = _this2.hls) !== null && _this2$hls !== void 0 && _this2$hls.emit) {
12154
+ var _this2$hls2;
12155
+ (_this2$hls2 = _this2.hls) === null || _this2$hls2 === void 0 ? void 0 : _this2$hls2.emit(EVENT.APPEND_BUFFER, {
12156
+ start: segment.start,
12157
+ end: segment.end
12158
+ });
12159
+ }
12160
+ };
11221
12161
  if (!this._directAppend) {
11222
- _context2.next = 7;
12162
+ _context2.next = 8;
11223
12163
  break;
11224
12164
  }
11225
12165
  p = [];
@@ -11227,8 +12167,8 @@ var BufferService = /* @__PURE__ */ function() {
11227
12167
  p.push(this._mse.append(MSE.VIDEO, videoChunk));
11228
12168
  if (audioChunk)
11229
12169
  p.push(this._mse.append(MSE.AUDIO, audioChunk));
11230
- return _context2.abrupt("return", Promise.all(p));
11231
- case 7:
12170
+ return _context2.abrupt("return", Promise.all(p).then(afterAppend));
12171
+ case 8:
11232
12172
  needInit = this._needInitSegment || discontinuity;
11233
12173
  _this$_transmuxer$tra = this._transmuxer.transmux(videoChunk, audioChunk, needInit, contiguous, startTime, this._needInitSegment || discontinuity), _this$_transmuxer$tra2 = _slicedToArray$1(_this$_transmuxer$tra, 2), video = _this$_transmuxer$tra2[0], audio = _this$_transmuxer$tra2[1];
11234
12174
  if (audioChunk && audioSegment) {
@@ -11244,21 +12184,22 @@ var BufferService = /* @__PURE__ */ function() {
11244
12184
  this.hls.emit(Event$1.NO_AUDIO_TRACK);
11245
12185
  }
11246
12186
  if (!this._softVideo) {
11247
- _context2.next = 18;
12187
+ _context2.next = 20;
11248
12188
  break;
11249
12189
  }
11250
12190
  this._softVideo.appendBuffer(video, audio);
11251
12191
  this._needInitSegment = false;
11252
- _context2.next = 28;
12192
+ afterAppend();
12193
+ _context2.next = 30;
11253
12194
  break;
11254
- case 18:
12195
+ case 20:
11255
12196
  if (!this._mse) {
11256
- _context2.next = 28;
12197
+ _context2.next = 30;
11257
12198
  break;
11258
12199
  }
11259
12200
  isFirstAppend = !this._sourceCreated;
11260
12201
  if (isFirstAppend) {
11261
- this._createMseSource(video === null || video === void 0 ? void 0 : video.codec, audio === null || audio === void 0 ? void 0 : audio.codec);
12202
+ this._createMseSource(video === null || video === void 0 ? void 0 : video.codec, audio === null || audio === void 0 ? void 0 : audio.codec, audio === null || audio === void 0 ? void 0 : audio.container);
11262
12203
  }
11263
12204
  this._needInitSegment = false;
11264
12205
  mse = this._mse;
@@ -11269,15 +12210,15 @@ var BufferService = /* @__PURE__ */ function() {
11269
12210
  });
11270
12211
  }
11271
12212
  if (video) {
11272
- videoData = video.data, videoRest = _objectWithoutProperties$1(video, _excluded);
12213
+ videoData = video.data, videoRest = _objectWithoutProperties$1(video, _excluded$1);
11273
12214
  _p.push(mse.append(MSE.VIDEO, videoData, videoRest));
11274
12215
  }
11275
12216
  if (audio) {
11276
12217
  audioData = audio.data, audioRest = _objectWithoutProperties$1(audio, _excluded2);
11277
12218
  _p.push(mse.append(MSE.AUDIO, audioData, audioRest));
11278
12219
  }
11279
- return _context2.abrupt("return", Promise.all(_p));
11280
- case 28:
12220
+ return _context2.abrupt("return", Promise.all(_p).then(afterAppend));
12221
+ case 30:
11281
12222
  case "end":
11282
12223
  return _context2.stop();
11283
12224
  }
@@ -11292,7 +12233,7 @@ var BufferService = /* @__PURE__ */ function() {
11292
12233
  key: "removeBuffer",
11293
12234
  value: function() {
11294
12235
  var _removeBuffer = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee3() {
11295
- var _this2 = this;
12236
+ var _this3 = this;
11296
12237
  var start, end, media, _args3 = arguments;
11297
12238
  return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
11298
12239
  while (1)
@@ -11308,7 +12249,7 @@ var BufferService = /* @__PURE__ */ function() {
11308
12249
  return _context3.abrupt("return");
11309
12250
  case 5:
11310
12251
  return _context3.abrupt("return", this._mse.clearBuffer(start, end).then(function() {
11311
- return _this2.hls.emit(EVENT.REMOVE_BUFFER, {
12252
+ return _this3.hls.emit(EVENT.REMOVE_BUFFER, {
11312
12253
  start,
11313
12254
  end,
11314
12255
  removeEnd: end
@@ -11489,30 +12430,51 @@ var BufferService = /* @__PURE__ */ function() {
11489
12430
  return setLiveSeekableRange;
11490
12431
  }()
11491
12432
  }, {
11492
- key: "destroy",
12433
+ key: "detachMedia",
11493
12434
  value: function() {
11494
- var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee9() {
11495
- var _this$_decryptor;
12435
+ var _detachMedia = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee9() {
11496
12436
  return _regeneratorRuntime$1().wrap(function _callee9$(_context9) {
11497
12437
  while (1)
11498
12438
  switch (_context9.prev = _context9.next) {
11499
12439
  case 0:
11500
- (_this$_decryptor = this._decryptor) === null || _this$_decryptor === void 0 ? void 0 : _this$_decryptor.destroy();
11501
12440
  if (!this._mse) {
11502
- _context9.next = 4;
12441
+ _context9.next = 3;
11503
12442
  break;
11504
12443
  }
11505
- _context9.next = 4;
12444
+ _context9.next = 3;
11506
12445
  return this._mse.unbindMedia();
11507
- case 4:
12446
+ case 3:
12447
+ case "end":
12448
+ return _context9.stop();
12449
+ }
12450
+ }, _callee9, this);
12451
+ }));
12452
+ function detachMedia() {
12453
+ return _detachMedia.apply(this, arguments);
12454
+ }
12455
+ return detachMedia;
12456
+ }()
12457
+ }, {
12458
+ key: "destroy",
12459
+ value: function() {
12460
+ var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee10() {
12461
+ var _this$_decryptor;
12462
+ return _regeneratorRuntime$1().wrap(function _callee10$(_context10) {
12463
+ while (1)
12464
+ switch (_context10.prev = _context10.next) {
12465
+ case 0:
12466
+ (_this$_decryptor = this._decryptor) === null || _this$_decryptor === void 0 ? void 0 : _this$_decryptor.destroy();
12467
+ _context10.next = 3;
12468
+ return this.detachMedia();
12469
+ case 3:
11508
12470
  this._decryptor = null;
11509
12471
  this._mse = null;
11510
12472
  this._softVideo = null;
11511
- case 7:
12473
+ case 6:
11512
12474
  case "end":
11513
- return _context9.stop();
12475
+ return _context10.stop();
11514
12476
  }
11515
- }, _callee9, this);
12477
+ }, _callee10, this);
11516
12478
  }));
11517
12479
  function destroy() {
11518
12480
  return _destroy.apply(this, arguments);
@@ -11521,7 +12483,7 @@ var BufferService = /* @__PURE__ */ function() {
11521
12483
  }()
11522
12484
  }, {
11523
12485
  key: "_createMseSource",
11524
- value: function _createMseSource(videoCodec, audioCodec) {
12486
+ value: function _createMseSource(videoCodec, audioCodec, container) {
11525
12487
  logger$2.debug("create mse source, videoCodec=".concat(videoCodec, ", audioCodec=").concat(audioCodec));
11526
12488
  var mse = this._mse;
11527
12489
  if (!mse)
@@ -11533,6 +12495,9 @@ var BufferService = /* @__PURE__ */ function() {
11533
12495
  if (audioCodec) {
11534
12496
  mse.createSource(MSE.AUDIO, "audio/mp4;codecs=".concat(audioCodec));
11535
12497
  this._sourceCreated = true;
12498
+ } else if (container) {
12499
+ mse.createSource(MSE.AUDIO, "".concat(container, ';codecs=""'));
12500
+ this._sourceCreated = true;
11536
12501
  }
11537
12502
  this.hls.emit(EVENT.SOURCEBUFFER_CREATED);
11538
12503
  }
@@ -11600,7 +12565,11 @@ function getConfig(cfg) {
11600
12565
  minSegmentsStartPlay: 3,
11601
12566
  preferMMS: false,
11602
12567
  preferMMSStreaming: false,
11603
- mseLowLatency: true
12568
+ mseLowLatency: true,
12569
+ fixerConfig: {
12570
+ forceFixLargeGap: false,
12571
+ largeGapThreshold: 5
12572
+ }
11604
12573
  }, cfg), {}, {
11605
12574
  media
11606
12575
  });
@@ -11715,6 +12684,8 @@ var MediaPlaylist = /* @__PURE__ */ _createClass$3(function MediaPlaylist2() {
11715
12684
  _defineProperty$3(this, "lowLatency", false);
11716
12685
  _defineProperty$3(this, "endPartIndex", 0);
11717
12686
  _defineProperty$3(this, "segments", []);
12687
+ _defineProperty$3(this, "dateRanges", {});
12688
+ _defineProperty$3(this, "skippedSegments", 0);
11718
12689
  });
11719
12690
  var MediaSegment = /* @__PURE__ */ function() {
11720
12691
  function MediaSegment2(parentUrl) {
@@ -11836,6 +12807,31 @@ var MediaSegmentKey = /* @__PURE__ */ function() {
11836
12807
  }]);
11837
12808
  return MediaSegmentKey2;
11838
12809
  }();
12810
+ var HlsUrlParameters = /* @__PURE__ */ function() {
12811
+ function HlsUrlParameters2(msn, part, skip) {
12812
+ _classCallCheck$3(this, HlsUrlParameters2);
12813
+ this.msn = msn;
12814
+ this.part = part;
12815
+ this.skip = skip;
12816
+ }
12817
+ _createClass$3(HlsUrlParameters2, [{
12818
+ key: "addDirectives",
12819
+ value: function addDirectives(uri) {
12820
+ var url = new self.URL(uri);
12821
+ if (this.msn !== void 0) {
12822
+ url.searchParams.set("_HLS_msn", this.msn.toString());
12823
+ }
12824
+ if (this.part) {
12825
+ url.searchParams.set("_HLS_part", this.part.toString());
12826
+ }
12827
+ if (this.skip) {
12828
+ url.searchParams.set("_HLS_skip", this.skip);
12829
+ }
12830
+ return url.href;
12831
+ }
12832
+ }]);
12833
+ return HlsUrlParameters2;
12834
+ }();
11839
12835
  var REGEXP_TAG = /^#(EXT[^:]*)(?::(.*))?$/;
11840
12836
  var REGEXP_ATTR = /([^=]+)=(?:"([^"]*)"|([^",]*))(?:,|$)/g;
11841
12837
  var REGEXP_ABSOLUTE_URL = /^(?:[a-zA-Z0-9+\-.]+:)?\/\//;
@@ -11886,6 +12882,38 @@ function getCodecs(type, codecs) {
11886
12882
  }
11887
12883
  }
11888
12884
  }
12885
+ function isValidDaterange(attr, dateRangeWithSameId) {
12886
+ var _badValueForSameId;
12887
+ if (dateRangeWithSameId) {
12888
+ for (var key in dateRangeWithSameId) {
12889
+ if (Object.prototype.hasOwnProperty.call(dateRangeWithSameId, key) && attr[key] !== dateRangeWithSameId[key]) {
12890
+ _badValueForSameId = key;
12891
+ break;
12892
+ }
12893
+ }
12894
+ }
12895
+ var duration = null;
12896
+ if (attr.DURATION) {
12897
+ duration = parseFloat(attr.DURATION);
12898
+ if (!Number.isFinite(duration)) {
12899
+ duration = null;
12900
+ } else if (attr._endDate) {
12901
+ duration = (attr._endDate.getTime() - attr._startDate.getTime()) / 1e3;
12902
+ }
12903
+ }
12904
+ var cue = enumeratedStringList(attr.CUE || attr["X-CUE"], {
12905
+ pre: false,
12906
+ post: false,
12907
+ once: false
12908
+ });
12909
+ 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);
12910
+ }
12911
+ function enumeratedStringList(attrValue, dict) {
12912
+ return (attrValue ? attrValue.split(/[ ,]+/) : []).reduce(function(result, identifier) {
12913
+ result[identifier.toLowerCase()] = true;
12914
+ return result;
12915
+ }, dict);
12916
+ }
11889
12917
  function parseMasterPlaylist(lines, parentUrl) {
11890
12918
  var master = new MasterPlaylist();
11891
12919
  var index = 0;
@@ -11994,9 +13022,6 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
11994
13022
  var endOfList = false;
11995
13023
  var partSegmentIndex = 0;
11996
13024
  while (line = lines[index++]) {
11997
- if (endOfList) {
11998
- break;
11999
- }
12000
13025
  if (line[0] !== "#") {
12001
13026
  if (media.lowLatency) {
12002
13027
  curSN++;
@@ -12045,16 +13070,11 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
12045
13070
  media.canBlockReload = _attr["CAN-BLOCK-RELOAD"] === "YES";
12046
13071
  media.partHoldBack = parseFloat(_attr["PART-HOLD-BACK"] || 0);
12047
13072
  media.canSkipUntil = parseFloat(_attr["CAN-SKIP-UNTIL"] || 0);
12048
- media.canSkipDateRanges = _attr["CAN-SKIP-DATERANGES"] === "YES";
13073
+ media.canSkipDateRanges = media.canSkipUntil > 0 && _attr["CAN-SKIP-DATERANGES"] === "YES";
12049
13074
  }
12050
13075
  break;
12051
13076
  case "ENDLIST":
12052
13077
  {
12053
- var _lastSegment = media.segments[media.segments.length - 1];
12054
- if (_lastSegment) {
12055
- _lastSegment.isLast = true;
12056
- }
12057
- media.live = false;
12058
13078
  endOfList = true;
12059
13079
  }
12060
13080
  break;
@@ -12094,6 +13114,15 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
12094
13114
  }
12095
13115
  break;
12096
13116
  case "PRELOAD-HINT":
13117
+ {
13118
+ var _attr3 = parseAttr(data);
13119
+ media.preloadHint = _attr3;
13120
+ if (_attr3["TYPE"] === "PART" && _attr3["URI"]) {
13121
+ var tmp = _attr3["URI"].split(".ts")[0].split("-");
13122
+ media.nextSN = tmp[3];
13123
+ media.nextIndex = tmp[tmp.length - 1];
13124
+ }
13125
+ }
12097
13126
  break;
12098
13127
  case "PROGRAM-DATE-TIME":
12099
13128
  curSegment.dataTime = data;
@@ -12113,21 +13142,21 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
12113
13142
  break;
12114
13143
  case "KEY":
12115
13144
  {
12116
- var _attr3 = parseAttr(data);
12117
- if (_attr3.METHOD === "NONE") {
13145
+ var _attr4 = parseAttr(data);
13146
+ if (_attr4.METHOD === "NONE") {
12118
13147
  curKey = null;
12119
13148
  break;
12120
13149
  }
12121
13150
  curKey = new MediaSegmentKey();
12122
- curKey.method = _attr3.METHOD;
12123
- curKey.url = /^blob:/.test(_attr3.URI) ? _attr3.URI : getAbsoluteUrl(_attr3.URI, parentUrl);
12124
- curKey.keyFormat = _attr3.KEYFORMAT || "identity";
12125
- curKey.keyFormatVersions = _attr3.KEYFORMATVERSIONS;
13151
+ curKey.method = _attr4.METHOD;
13152
+ curKey.url = /^blob:/.test(_attr4.URI) ? _attr4.URI : getAbsoluteUrl(_attr4.URI, parentUrl);
13153
+ curKey.keyFormat = _attr4.KEYFORMAT || "identity";
13154
+ curKey.keyFormatVersions = _attr4.KEYFORMATVERSIONS;
12126
13155
  if (!curKey.isSupported()) {
12127
- throw new Error("encrypt ".concat(_attr3.METHOD, "/").concat(_attr3.KEYFORMAT, " is not supported"));
13156
+ throw new Error("encrypt ".concat(_attr4.METHOD, "/").concat(_attr4.KEYFORMAT, " is not supported"));
12128
13157
  }
12129
- if (_attr3.IV) {
12130
- var str = _attr3.IV.slice(2);
13158
+ if (_attr4.IV) {
13159
+ var str = _attr4.IV.slice(2);
12131
13160
  str = (str.length & 1 ? "0" : "") + str;
12132
13161
  curKey.iv = new Uint8Array(str.length / 2);
12133
13162
  for (var i = 0, l = str.length / 2; i < l; i++) {
@@ -12138,10 +13167,10 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
12138
13167
  break;
12139
13168
  case "MAP":
12140
13169
  {
12141
- var _attr4 = parseAttr(data);
12142
- curSegment.url = getAbsoluteUrl(_attr4.URI, parentUrl);
12143
- if (_attr4.BYTERANGE)
12144
- curSegment.setByteRange(_attr4.BYTERANGE);
13170
+ var _attr5 = parseAttr(data);
13171
+ curSegment.url = getAbsoluteUrl(_attr5.URI, parentUrl);
13172
+ if (_attr5.BYTERANGE)
13173
+ curSegment.setByteRange(_attr5.BYTERANGE);
12145
13174
  curSegment.isInitSegment = true;
12146
13175
  curSegment.sn = 0;
12147
13176
  if (curKey) {
@@ -12151,6 +13180,30 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
12151
13180
  curSegment = new MediaSegment(parentUrl);
12152
13181
  }
12153
13182
  break;
13183
+ case "SKIP":
13184
+ {
13185
+ var _attr6 = parseAttr(data);
13186
+ var skippedSegments = parseInt(_attr6["SKIPPED-SEGMENTS"], 10);
13187
+ if (skippedSegments <= Number.MAX_SAFE_INTEGER) {
13188
+ media.skippedSegments += skippedSegments;
13189
+ curSN += skippedSegments;
13190
+ }
13191
+ }
13192
+ break;
13193
+ case "DATERANGE":
13194
+ {
13195
+ var _attr7 = parseAttr(data);
13196
+ var dateRangeWithSameId = media.dateRanges[_attr7.ID];
13197
+ _attr7._startDate = dateRangeWithSameId ? dateRangeWithSameId._startDate : new Date(_attr7["START-DATE"]);
13198
+ var endDate = (dateRangeWithSameId === null || dateRangeWithSameId === void 0 ? void 0 : dateRangeWithSameId._endDate) || new Date(_attr7.END_DATE);
13199
+ if (Number.isFinite(endDate)) {
13200
+ _attr7._endDate = endDate;
13201
+ }
13202
+ if (isValidDaterange(_attr7, dateRangeWithSameId) || media.skippedSegments) {
13203
+ media.dateRanges[_attr7.ID] = _attr7;
13204
+ }
13205
+ }
13206
+ break;
12154
13207
  }
12155
13208
  }
12156
13209
  media.segments = media.segments.filter(function(x) {
@@ -12158,11 +13211,14 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
12158
13211
  });
12159
13212
  var lastSegment = media.segments[media.segments.length - 1];
12160
13213
  if (lastSegment) {
12161
- media.endSN = lastSegment.sn;
12162
- media.endPartIndex = lastSegment.partIndex;
12163
- if (endOfList && !lastSegment.isLast) {
13214
+ if (endOfList) {
12164
13215
  lastSegment.isLast = true;
12165
13216
  }
13217
+ media.endSN = lastSegment.sn;
13218
+ media.endPartIndex = lastSegment.partIndex;
13219
+ }
13220
+ if (endOfList) {
13221
+ media.live = false;
12166
13222
  }
12167
13223
  media.totalDuration = totalDuration;
12168
13224
  media.endCC = curCC;
@@ -12341,6 +13397,13 @@ var ManifestLoader = /* @__PURE__ */ function() {
12341
13397
  playlist
12342
13398
  });
12343
13399
  } else {
13400
+ if (this._useLowLatency) {
13401
+ if (playlist.canBlockReload) {
13402
+ this.deliveryDirectives = new HlsUrlParameters(playlist.nextSN, playlist.nextIndex, "");
13403
+ } else {
13404
+ this.deliveryDirectives = null;
13405
+ }
13406
+ }
12344
13407
  this.hls.emit(Event$1.HLS_LEVEL_LOADED, {
12345
13408
  playlist
12346
13409
  });
@@ -12397,41 +13460,45 @@ var ManifestLoader = /* @__PURE__ */ function() {
12397
13460
  var retryCount = this.hls.config.pollRetryCount;
12398
13461
  var fn = /* @__PURE__ */ function() {
12399
13462
  var _ref2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee2() {
12400
- var res;
13463
+ var reqUrl, res;
12401
13464
  return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
12402
13465
  while (1)
12403
13466
  switch (_context2.prev = _context2.next) {
12404
13467
  case 0:
12405
13468
  clearTimeout(_this2._timer);
12406
- _context2.prev = 1;
12407
- _context2.next = 4;
12408
- return _this2.load(url, audioUrl, subtitleUrl);
12409
- case 4:
13469
+ reqUrl = url;
13470
+ _context2.prev = 2;
13471
+ if (_this2.deliveryDirectives) {
13472
+ reqUrl = _this2.deliveryDirectives.addDirectives(url);
13473
+ }
13474
+ _context2.next = 6;
13475
+ return _this2.load(reqUrl, audioUrl, subtitleUrl);
13476
+ case 6:
12410
13477
  res = _context2.sent;
12411
13478
  if (res[0]) {
12412
- _context2.next = 7;
13479
+ _context2.next = 9;
12413
13480
  break;
12414
13481
  }
12415
13482
  return _context2.abrupt("return");
12416
- case 7:
13483
+ case 9:
12417
13484
  retryCount = _this2.hls.config.pollRetryCount;
12418
13485
  cb(res[0], res[1], res[2]);
12419
- _context2.next = 15;
13486
+ _context2.next = 17;
12420
13487
  break;
12421
- case 11:
12422
- _context2.prev = 11;
12423
- _context2.t0 = _context2["catch"](1);
13488
+ case 13:
13489
+ _context2.prev = 13;
13490
+ _context2.t0 = _context2["catch"](2);
12424
13491
  retryCount--;
12425
13492
  if (retryCount <= 0) {
12426
13493
  errorCb(_context2.t0);
12427
13494
  }
12428
- case 15:
13495
+ case 17:
12429
13496
  _this2._timer = setTimeout(fn, time);
12430
- case 16:
13497
+ case 18:
12431
13498
  case "end":
12432
13499
  return _context2.stop();
12433
13500
  }
12434
- }, _callee2, null, [[1, 11]]);
13501
+ }, _callee2, null, [[2, 13]]);
12435
13502
  }));
12436
13503
  return function fn2() {
12437
13504
  return _ref2.apply(this, arguments);
@@ -12961,7 +14028,7 @@ var Playlist = /* @__PURE__ */ function() {
12961
14028
  }, {
12962
14029
  key: "clearOldSegment",
12963
14030
  value: function clearOldSegment() {
12964
- var maxPlaylistSize = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 50;
14031
+ var maxPlaylistSize = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.hls.config.maxPlaylistSize || 50;
12965
14032
  var stream = this.currentStream;
12966
14033
  if (!this.dvrWindow || !stream)
12967
14034
  return;
@@ -13259,7 +14326,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
13259
14326
  _defineProperty$3(_assertThisInitialized$2(_this), "_switchUrlOpts", null);
13260
14327
  _defineProperty$3(_assertThisInitialized$2(_this), "_isProcessQuotaExceeded", false);
13261
14328
  _defineProperty$3(_assertThisInitialized$2(_this), "_loadSegment", /* @__PURE__ */ _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee() {
13262
- var nextSeg, _assertThisInitialize, config, bInfo, bufferThroughout;
14329
+ var _this$_playlist, nextSegment, lastSegment, _assertThisInitialize, config, minFrameDuration, maxBufferThroughout, bInfo, bufferThroughout;
13263
14330
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
13264
14331
  while (1)
13265
14332
  switch (_context.prev = _context.next) {
@@ -13270,42 +14337,44 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
13270
14337
  }
13271
14338
  return _context.abrupt("return");
13272
14339
  case 2:
13273
- nextSeg = _this._playlist.nextSegment;
14340
+ _this$_playlist = _this._playlist, nextSegment = _this$_playlist.nextSegment, lastSegment = _this$_playlist.lastSegment;
13274
14341
  _assertThisInitialize = _assertThisInitialized$2(_this), config = _assertThisInitialize.config;
13275
- if (nextSeg) {
13276
- _context.next = 6;
14342
+ minFrameDuration = 0.016;
14343
+ maxBufferThroughout = Math.min(Math.max((lastSegment === null || lastSegment === void 0 ? void 0 : lastSegment.duration) - minFrameDuration / 2 || 0, minFrameDuration), 0.1);
14344
+ if (nextSegment) {
14345
+ _context.next = 8;
13277
14346
  break;
13278
14347
  }
13279
14348
  return _context.abrupt("return");
13280
- case 6:
14349
+ case 8:
13281
14350
  if (_this.isLive) {
13282
- _context.next = 16;
14351
+ _context.next = 18;
13283
14352
  break;
13284
14353
  }
13285
14354
  bInfo = _this.bufferInfo();
13286
14355
  if (_this.media.paused && !_this.media.currentTime) {
13287
14356
  bInfo = _this.bufferInfo(bInfo.nextStart || 0.5);
13288
14357
  }
13289
- bufferThroughout = Math.abs(bInfo.end - _this.media.duration) < 0.1;
14358
+ bufferThroughout = Math.abs(bInfo.end - _this.media.duration) < maxBufferThroughout;
13290
14359
  if (!(bInfo.remaining >= config.preloadTime || bufferThroughout)) {
13291
- _context.next = 13;
14360
+ _context.next = 15;
13292
14361
  break;
13293
14362
  }
13294
14363
  _this._tryEos();
13295
14364
  return _context.abrupt("return");
13296
- case 13:
14365
+ case 15:
13297
14366
  if (!(config.preferMMSStreaming && !_this._bufferService.msStreaming)) {
13298
- _context.next = 15;
14367
+ _context.next = 17;
13299
14368
  break;
13300
14369
  }
13301
14370
  return _context.abrupt("return");
13302
- case 15:
13303
- if (!_this._urlSwitching && _this._prevSegSn !== nextSeg.sn - 1 && bInfo.end && Math.abs(nextSeg.start - bInfo.end) > 1) {
14371
+ case 17:
14372
+ if (!_this._urlSwitching && _this._prevSegSn !== nextSegment.sn - 1 && bInfo.end && Math.abs(nextSegment.start - bInfo.end) > 1) {
13304
14373
  _this._playlist.setNextSegmentByIndex(_this._playlist.findSegmentIndexByTime(bInfo.end + 0.1));
13305
14374
  }
13306
- case 16:
14375
+ case 18:
13307
14376
  return _context.abrupt("return", _this._loadSegmentDirect());
13308
- case 17:
14377
+ case 19:
13309
14378
  case "end":
13310
14379
  return _context.stop();
13311
14380
  }
@@ -13470,7 +14539,6 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
13470
14539
  return;
13471
14540
  _this._startTick();
13472
14541
  var media = _this.media;
13473
- var buffered = Buffer$1.get(media);
13474
14542
  var segLoaderError = _this._segmentLoader.error;
13475
14543
  _this._onCheckQuotaExceeded();
13476
14544
  if (_this._isProcessQuotaExceeded) {
@@ -13487,7 +14555,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
13487
14555
  }
13488
14556
  return;
13489
14557
  }
13490
- if (Buffer$1.end(buffered) >= 0.1 && media.readyState) {
14558
+ if (media.readyState) {
13491
14559
  if (isMediaPlaying(media)) {
13492
14560
  _this._loadSegment();
13493
14561
  if (_this._gapService) {
@@ -13553,6 +14621,12 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
13553
14621
  var _this$_bufferService;
13554
14622
  return (_this$_bufferService = this._bufferService) === null || _this$_bufferService === void 0 ? void 0 : _this$_bufferService.baseDts;
13555
14623
  }
14624
+ }, {
14625
+ key: "abrSwitchPoint",
14626
+ get: function get() {
14627
+ var targetSeg = this._urlSwitching ? this._playlist.currentSegment : this._playlist.nextSegment;
14628
+ return targetSeg ? targetSeg.start + targetSeg.duration / 2 : null;
14629
+ }
13556
14630
  }, {
13557
14631
  key: "speedInfo",
13558
14632
  value: function speedInfo() {
@@ -13578,30 +14652,37 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
13578
14652
  }, {
13579
14653
  key: "load",
13580
14654
  value: function() {
13581
- var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee4(url) {
13582
- var reuseMse, _args4 = arguments;
14655
+ var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee4() {
14656
+ var url, options, reuseMse, _args4 = arguments;
13583
14657
  return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
13584
14658
  while (1)
13585
14659
  switch (_context4.prev = _context4.next) {
13586
14660
  case 0:
13587
- reuseMse = _args4.length > 1 && _args4[1] !== void 0 ? _args4[1] : false;
14661
+ url = _args4.length > 0 && _args4[0] !== void 0 ? _args4[0] : "";
14662
+ options = _args4.length > 1 && _args4[1] !== void 0 ? _args4[1] : {};
14663
+ reuseMse = typeof options === "boolean" ? options : !!(options !== null && options !== void 0 && options.reuseMse);
14664
+ if (_typeof$2(options) === "object" && options !== null && options !== void 0 && options.clearSwitchStatus) {
14665
+ this._urlSwitching = false;
14666
+ this._switchUrlOpts = null;
14667
+ this.config.startTime = void 0;
14668
+ }
13588
14669
  if (url)
13589
14670
  this.config.url = url;
13590
14671
  url = this.config.url;
13591
- _context4.next = 5;
14672
+ _context4.next = 8;
13592
14673
  return this._reset(reuseMse);
13593
- case 5:
13594
- _context4.next = 7;
14674
+ case 8:
14675
+ _context4.next = 10;
13595
14676
  return this._loadData(url);
13596
- case 7:
14677
+ case 10:
13597
14678
  this._startTick();
13598
- case 8:
14679
+ case 11:
13599
14680
  case "end":
13600
14681
  return _context4.stop();
13601
14682
  }
13602
14683
  }, _callee4, this);
13603
14684
  }));
13604
- function load(_x) {
14685
+ function load() {
13605
14686
  return _load.apply(this, arguments);
13606
14687
  }
13607
14688
  return load;
@@ -13610,7 +14691,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
13610
14691
  key: "_loadData",
13611
14692
  value: function() {
13612
14693
  var _loadData2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee5(url) {
13613
- var manifest, currentStream, _this$_switchUrlOpts, _this$_switchUrlOpts2, switchTimePoint, segIdx, nextSeg, bufferClearStartPoint, preIndex, startTime, _this$_switchUrlOpts3;
14694
+ var manifest, currentStream, preIndex, _this$_switchUrlOpts, _this$_switchUrlOpts3, _this$_switchUrlOpts4, _this$_switchUrlOpts2, switchTimePoint, segIdx, nextSeg, bufferClearStartPoint, startTime, _this$_switchUrlOpts5;
13614
14695
  return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
13615
14696
  while (1)
13616
14697
  switch (_context5.prev = _context5.next) {
@@ -13631,41 +14712,46 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
13631
14712
  case 5:
13632
14713
  manifest = _context5.sent;
13633
14714
  currentStream = this._playlist.currentStream;
13634
- if (!(this._urlSwitching && !this.isLive)) {
13635
- _context5.next = 17;
14715
+ if (!this._urlSwitching) {
14716
+ _context5.next = 23;
13636
14717
  break;
13637
14718
  }
14719
+ if (!this.isLive) {
14720
+ _context5.next = 14;
14721
+ break;
14722
+ }
14723
+ preIndex = this._playlist.setNextSegmentBySN(this._prevSegSn);
14724
+ logger.log("segment nb=".concat(this._prevSegSn, " index of ").concat(preIndex, " in the new playlist"));
14725
+ if (preIndex === -1) {
14726
+ this._prevSegCc = null;
14727
+ this._prevSegSn = null;
14728
+ }
14729
+ _context5.next = 23;
14730
+ break;
14731
+ case 14:
13638
14732
  if (currentStream.bitrate === 0 && (_this$_switchUrlOpts = this._switchUrlOpts) !== null && _this$_switchUrlOpts !== void 0 && _this$_switchUrlOpts.bitrate) {
13639
14733
  currentStream.bitrate = (_this$_switchUrlOpts2 = this._switchUrlOpts) === null || _this$_switchUrlOpts2 === void 0 ? void 0 : _this$_switchUrlOpts2.bitrate;
13640
14734
  }
13641
- switchTimePoint = this._getSeamlessSwitchPoint();
14735
+ 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();
13642
14736
  this.config.startTime = switchTimePoint;
13643
14737
  segIdx = this._playlist.findSegmentIndexByTime(switchTimePoint);
13644
14738
  nextSeg = this._playlist.getSegmentByIndex(segIdx + 1);
13645
14739
  if (!nextSeg) {
13646
- _context5.next = 17;
14740
+ _context5.next = 23;
13647
14741
  break;
13648
14742
  }
13649
14743
  bufferClearStartPoint = nextSeg.start;
13650
- _context5.next = 17;
14744
+ _context5.next = 23;
13651
14745
  return this._bufferService.removeBuffer(bufferClearStartPoint);
13652
- case 17:
13653
- if (this._urlSwitching && this.isLive) {
13654
- preIndex = this._playlist.setNextSegmentBySN(this._prevSegSn);
13655
- logger.log("segment nb=".concat(this._prevSegSn, " index of ").concat(preIndex, " in the new playlist"));
13656
- if (preIndex === -1) {
13657
- this._prevSegCc = null;
13658
- this._prevSegSn = null;
13659
- }
13660
- }
14746
+ case 23:
13661
14747
  if (manifest) {
13662
- _context5.next = 20;
14748
+ _context5.next = 25;
13663
14749
  break;
13664
14750
  }
13665
14751
  return _context5.abrupt("return");
13666
- case 20:
14752
+ case 25:
13667
14753
  if (!this.isLive) {
13668
- _context5.next = 31;
14754
+ _context5.next = 36;
13669
14755
  break;
13670
14756
  }
13671
14757
  this._bufferService.setLiveSeekableRange(0, 4294967295);
@@ -13678,35 +14764,35 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
13678
14764
  if (!manifest.isMaster)
13679
14765
  this._pollM3U8(url);
13680
14766
  if (!(this._playlist.nbSegments < this.config.minSegmentsStartPlay)) {
13681
- _context5.next = 28;
14767
+ _context5.next = 33;
13682
14768
  break;
13683
14769
  }
13684
14770
  return _context5.abrupt("return");
13685
- case 28:
13686
- _context5.next = 30;
14771
+ case 33:
14772
+ _context5.next = 35;
13687
14773
  return this._loadSegment();
13688
- case 30:
14774
+ case 35:
13689
14775
  return _context5.abrupt("return");
13690
- case 31:
13691
- _context5.next = 33;
14776
+ case 36:
14777
+ _context5.next = 38;
13692
14778
  return this._bufferService.updateDuration(currentStream.totalDuration);
13693
- case 33:
14779
+ case 38:
13694
14780
  startTime = this.config.startTime;
13695
14781
  if (startTime) {
13696
- if (!((_this$_switchUrlOpts3 = this._switchUrlOpts) !== null && _this$_switchUrlOpts3 !== void 0 && _this$_switchUrlOpts3.seamless)) {
14782
+ if (!((_this$_switchUrlOpts5 = this._switchUrlOpts) !== null && _this$_switchUrlOpts5 !== void 0 && _this$_switchUrlOpts5.seamless)) {
13697
14783
  this.media.currentTime = startTime;
13698
14784
  }
13699
14785
  this._playlist.setNextSegmentByIndex(this._playlist.findSegmentIndexByTime(startTime) || 0);
13700
14786
  }
13701
- _context5.next = 37;
14787
+ _context5.next = 42;
13702
14788
  return this._loadSegment();
13703
- case 37:
14789
+ case 42:
13704
14790
  case "end":
13705
14791
  return _context5.stop();
13706
14792
  }
13707
14793
  }, _callee5, this);
13708
14794
  }));
13709
- function _loadData(_x2) {
14795
+ function _loadData(_x) {
13710
14796
  return _loadData2.apply(this, arguments);
13711
14797
  }
13712
14798
  return _loadData;
@@ -13720,18 +14806,20 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
13720
14806
  switch (_context6.prev = _context6.next) {
13721
14807
  case 0:
13722
14808
  this.config.startTime = 0;
13723
- _context6.next = 3;
14809
+ this._urlSwitching = false;
14810
+ this._switchUrlOpts = null;
14811
+ _context6.next = 5;
13724
14812
  return this.load();
13725
- case 3:
14813
+ case 5:
13726
14814
  this._reloadOnPlay = false;
13727
14815
  return _context6.abrupt("return", this.media.play(!isPlayEmit));
13728
- case 5:
14816
+ case 7:
13729
14817
  case "end":
13730
14818
  return _context6.stop();
13731
14819
  }
13732
14820
  }, _callee6, this);
13733
14821
  }));
13734
- function replay(_x3) {
14822
+ function replay(_x2) {
13735
14823
  return _replay.apply(this, arguments);
13736
14824
  }
13737
14825
  return replay;
@@ -13836,7 +14924,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
13836
14924
  }
13837
14925
  }, _callee7, this, [[18, 29]]);
13838
14926
  }));
13839
- function switchURL(_x4) {
14927
+ function switchURL(_x3) {
13840
14928
  return _switchURL.apply(this, arguments);
13841
14929
  }
13842
14930
  return switchURL;
@@ -13922,7 +15010,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
13922
15010
  }
13923
15011
  }, _callee8, this, [[8, 16], [21, 31]]);
13924
15012
  }));
13925
- function switchStream(_x5) {
15013
+ function switchStream(_x4) {
13926
15014
  return _switchStream.apply(this, arguments);
13927
15015
  }
13928
15016
  return switchStream;
@@ -14008,7 +15096,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14008
15096
  }
14009
15097
  }, _callee9, this, [[10, 18], [22, 32]]);
14010
15098
  }));
14011
- function switchAudioStream(_x6) {
15099
+ function switchAudioStream(_x5) {
14012
15100
  return _switchAudioStream.apply(this, arguments);
14013
15101
  }
14014
15102
  return switchAudioStream;
@@ -14033,25 +15121,50 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14033
15121
  }
14034
15122
  }, _callee10, this);
14035
15123
  }));
14036
- function switchSubtitleStream(_x7) {
15124
+ function switchSubtitleStream(_x6) {
14037
15125
  return _switchSubtitleStream.apply(this, arguments);
14038
15126
  }
14039
15127
  return switchSubtitleStream;
14040
15128
  }()
14041
15129
  }, {
14042
- key: "destroy",
15130
+ key: "detachMedia",
14043
15131
  value: function() {
14044
- var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee11() {
14045
- var _this$_seiService2;
15132
+ var _detachMedia = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee11() {
14046
15133
  return _regeneratorRuntime$1().wrap(function _callee11$(_context11) {
14047
15134
  while (1)
14048
15135
  switch (_context11.prev = _context11.next) {
15136
+ case 0:
15137
+ if (!this._bufferService) {
15138
+ _context11.next = 3;
15139
+ break;
15140
+ }
15141
+ _context11.next = 3;
15142
+ return this._bufferService.detachMedia();
15143
+ case 3:
15144
+ case "end":
15145
+ return _context11.stop();
15146
+ }
15147
+ }, _callee11, this);
15148
+ }));
15149
+ function detachMedia() {
15150
+ return _detachMedia.apply(this, arguments);
15151
+ }
15152
+ return detachMedia;
15153
+ }()
15154
+ }, {
15155
+ key: "destroy",
15156
+ value: function() {
15157
+ var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee12() {
15158
+ var _this$_seiService2;
15159
+ return _regeneratorRuntime$1().wrap(function _callee12$(_context12) {
15160
+ while (1)
15161
+ switch (_context12.prev = _context12.next) {
14049
15162
  case 0:
14050
15163
  if (this.media) {
14051
- _context11.next = 2;
15164
+ _context12.next = 2;
14052
15165
  break;
14053
15166
  }
14054
- return _context11.abrupt("return");
15167
+ return _context12.abrupt("return");
14055
15168
  case 2:
14056
15169
  this.removeAllListeners();
14057
15170
  this._playlist.reset();
@@ -14062,15 +15175,15 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14062
15175
  this.media.removeEventListener("pause", this._onPause);
14063
15176
  this.media.removeEventListener("seeking", this._onSeeking);
14064
15177
  this.media.removeEventListener("timeupdate", this._onTimeupdate);
14065
- _context11.next = 13;
15178
+ _context12.next = 13;
14066
15179
  return Promise.all([this._clear(), this._bufferService.destroy()]);
14067
15180
  case 13:
14068
15181
  this.media = null;
14069
15182
  case 14:
14070
15183
  case "end":
14071
- return _context11.stop();
15184
+ return _context12.stop();
14072
15185
  }
14073
- }, _callee11, this);
15186
+ }, _callee12, this);
14074
15187
  }));
14075
15188
  function destroy() {
14076
15189
  return _destroy.apply(this, arguments);
@@ -14080,48 +15193,48 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14080
15193
  }, {
14081
15194
  key: "_loadM3U8",
14082
15195
  value: function() {
14083
- var _loadM3U = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee12(url) {
15196
+ var _loadM3U = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee13(url) {
14084
15197
  var playlist, _this$config$manifest, _this$config$manifest2, manifest, _ref4, _ref5, _this$_playlist$curre;
14085
- return _regeneratorRuntime$1().wrap(function _callee12$(_context12) {
15198
+ return _regeneratorRuntime$1().wrap(function _callee13$(_context13) {
14086
15199
  while (1)
14087
- switch (_context12.prev = _context12.next) {
15200
+ switch (_context13.prev = _context13.next) {
14088
15201
  case 0:
14089
- _context12.prev = 0;
15202
+ _context13.prev = 0;
14090
15203
  manifest = (_this$config$manifest = this.config.manifestList) === null || _this$config$manifest === void 0 ? void 0 : (_this$config$manifest2 = _this$config$manifest.filter(function(x) {
14091
15204
  return x.url === url;
14092
15205
  })[0]) === null || _this$config$manifest2 === void 0 ? void 0 : _this$config$manifest2.manifest;
14093
15206
  if (!manifest) {
14094
- _context12.next = 6;
15207
+ _context13.next = 6;
14095
15208
  break;
14096
15209
  }
14097
- _context12.t0 = this._manifestLoader.parseText(manifest, url);
14098
- _context12.next = 9;
15210
+ _context13.t0 = this._manifestLoader.parseText(manifest, url);
15211
+ _context13.next = 9;
14099
15212
  break;
14100
15213
  case 6:
14101
- _context12.next = 8;
15214
+ _context13.next = 8;
14102
15215
  return this._manifestLoader.load(url);
14103
15216
  case 8:
14104
- _context12.t0 = _context12.sent;
15217
+ _context13.t0 = _context13.sent;
14105
15218
  case 9:
14106
- _ref4 = _context12.t0;
15219
+ _ref4 = _context13.t0;
14107
15220
  _ref5 = _slicedToArray$1(_ref4, 1);
14108
15221
  playlist = _ref5[0];
14109
- _context12.next = 17;
15222
+ _context13.next = 17;
14110
15223
  break;
14111
15224
  case 14:
14112
- _context12.prev = 14;
14113
- _context12.t1 = _context12["catch"](0);
14114
- throw this._emitError(StreamingError.create(_context12.t1));
15225
+ _context13.prev = 14;
15226
+ _context13.t1 = _context13["catch"](0);
15227
+ throw this._emitError(StreamingError.create(_context13.t1));
14115
15228
  case 17:
14116
15229
  if (playlist) {
14117
- _context12.next = 19;
15230
+ _context13.next = 19;
14118
15231
  break;
14119
15232
  }
14120
- return _context12.abrupt("return");
15233
+ return _context13.abrupt("return");
14121
15234
  case 19:
14122
15235
  this._playlist.upsertPlaylist(playlist);
14123
15236
  if (!playlist.isMaster) {
14124
- _context12.next = 24;
15237
+ _context13.next = 24;
14125
15238
  break;
14126
15239
  }
14127
15240
  if ((_this$_playlist$curre = this._playlist.currentStream.subtitleStreams) !== null && _this$_playlist$curre !== void 0 && _this$_playlist$curre.length) {
@@ -14129,18 +15242,18 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14129
15242
  list: this._playlist.currentStream.subtitleStreams
14130
15243
  });
14131
15244
  }
14132
- _context12.next = 24;
15245
+ _context13.next = 24;
14133
15246
  return this._refreshM3U8();
14134
15247
  case 24:
14135
15248
  this.emit(Event$1.STREAM_PARSED);
14136
- return _context12.abrupt("return", playlist);
15249
+ return _context13.abrupt("return", playlist);
14137
15250
  case 26:
14138
15251
  case "end":
14139
- return _context12.stop();
15252
+ return _context13.stop();
14140
15253
  }
14141
- }, _callee12, this, [[0, 14]]);
15254
+ }, _callee13, this, [[0, 14]]);
14142
15255
  }));
14143
- function _loadM3U8(_x8) {
15256
+ function _loadM3U8(_x7) {
14144
15257
  return _loadM3U.apply(this, arguments);
14145
15258
  }
14146
15259
  return _loadM3U8;
@@ -14174,7 +15287,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14174
15287
  var isEmpty = this._playlist.isEmpty;
14175
15288
  var pollInterval;
14176
15289
  if (this._playlist.lowLatency) {
14177
- pollInterval = (this._playlist.currentStream.partTargetDuration * 2 || 0) * 1e3;
15290
+ pollInterval = (this._playlist.currentStream.partTargetDuration || 0) * 1e3;
14178
15291
  } else {
14179
15292
  var _this$_playlist$lastS;
14180
15293
  pollInterval = (((_this$_playlist$lastS = this._playlist.lastSegment) === null || _this$_playlist$lastS === void 0 ? void 0 : _this$_playlist$lastS.duration) || 0) * 1e3;
@@ -14202,53 +15315,53 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14202
15315
  }, {
14203
15316
  key: "_loadSegmentDirect",
14204
15317
  value: function() {
14205
- var _loadSegmentDirect2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee13(loadOnce) {
15318
+ var _loadSegmentDirect2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee14(loadOnce) {
14206
15319
  var seg, appended, cachedError, _this$_playlist$curre2, bufferEnd, sameStream;
14207
- return _regeneratorRuntime$1().wrap(function _callee13$(_context13) {
15320
+ return _regeneratorRuntime$1().wrap(function _callee14$(_context14) {
14208
15321
  while (1)
14209
- switch (_context13.prev = _context13.next) {
15322
+ switch (_context14.prev = _context14.next) {
14210
15323
  case 0:
14211
15324
  seg = this._playlist.nextSegment;
14212
15325
  if (seg) {
14213
- _context13.next = 3;
15326
+ _context14.next = 3;
14214
15327
  break;
14215
15328
  }
14216
- return _context13.abrupt("return");
15329
+ return _context14.abrupt("return");
14217
15330
  case 3:
14218
15331
  appended = false;
14219
15332
  cachedError = null;
14220
- _context13.prev = 5;
15333
+ _context14.prev = 5;
14221
15334
  this._segmentProcessing = true;
14222
15335
  logger.log("load segment, sn:".concat(seg.sn, ", [").concat(seg.start, ", ").concat(seg.end, "], partIndex:").concat(seg.partIndex));
14223
- _context13.next = 10;
15336
+ _context14.next = 10;
14224
15337
  return this._reqAndBufferSegment(seg, this._playlist.getAudioSegment(seg));
14225
15338
  case 10:
14226
- appended = _context13.sent;
14227
- _context13.next = 16;
15339
+ appended = _context14.sent;
15340
+ _context14.next = 16;
14228
15341
  break;
14229
15342
  case 13:
14230
- _context13.prev = 13;
14231
- _context13.t0 = _context13["catch"](5);
14232
- cachedError = _context13.t0;
15343
+ _context14.prev = 13;
15344
+ _context14.t0 = _context14["catch"](5);
15345
+ cachedError = _context14.t0;
14233
15346
  case 16:
14234
- _context13.prev = 16;
15347
+ _context14.prev = 16;
14235
15348
  this._segmentProcessing = false;
14236
- return _context13.finish(16);
15349
+ return _context14.finish(16);
14237
15350
  case 19:
14238
15351
  if (!cachedError) {
14239
- _context13.next = 26;
15352
+ _context14.next = 26;
14240
15353
  break;
14241
15354
  }
14242
15355
  if (!this._bufferService.isFull()) {
14243
- _context13.next = 25;
15356
+ _context14.next = 25;
14244
15357
  break;
14245
15358
  }
14246
15359
  logger.log("load segment, sn:".concat(seg.sn, ", partIndex:").concat(seg.partIndex));
14247
15360
  this._segmentProcessing = true;
14248
15361
  this._isProcessQuotaExceeded = true;
14249
- return _context13.abrupt("return", false);
15362
+ return _context14.abrupt("return", false);
14250
15363
  case 25:
14251
- return _context13.abrupt("return", this._emitError(StreamingError.create(cachedError)));
15364
+ return _context14.abrupt("return", this._emitError(StreamingError.create(cachedError)));
14252
15365
  case 26:
14253
15366
  if (appended) {
14254
15367
  bufferEnd = this.bufferInfo().end;
@@ -14274,14 +15387,14 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14274
15387
  this._loadSegment();
14275
15388
  }
14276
15389
  }
14277
- return _context13.abrupt("return", appended);
15390
+ return _context14.abrupt("return", appended);
14278
15391
  case 28:
14279
15392
  case "end":
14280
- return _context13.stop();
15393
+ return _context14.stop();
14281
15394
  }
14282
- }, _callee13, this, [[5, 13, 16, 19]]);
15395
+ }, _callee14, this, [[5, 13, 16, 19]]);
14283
15396
  }));
14284
- function _loadSegmentDirect(_x9) {
15397
+ function _loadSegmentDirect(_x8) {
14285
15398
  return _loadSegmentDirect2.apply(this, arguments);
14286
15399
  }
14287
15400
  return _loadSegmentDirect;
@@ -14289,45 +15402,45 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14289
15402
  }, {
14290
15403
  key: "_reqAndBufferSegment",
14291
15404
  value: function() {
14292
- var _reqAndBufferSegment2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee14(seg, audioSeg) {
15405
+ var _reqAndBufferSegment2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee15(seg, audioSeg) {
14293
15406
  var _this$_bufferService2;
14294
15407
  var cc, discontinuity, responses, data, sn, start, stream, before, contiguous, segStart;
14295
- return _regeneratorRuntime$1().wrap(function _callee14$(_context14) {
15408
+ return _regeneratorRuntime$1().wrap(function _callee15$(_context15) {
14296
15409
  while (1)
14297
- switch (_context14.prev = _context14.next) {
15410
+ switch (_context15.prev = _context15.next) {
14298
15411
  case 0:
14299
15412
  cc = seg ? seg.cc : audioSeg.cc;
14300
15413
  discontinuity = this._prevSegCc !== cc;
14301
15414
  responses = [];
14302
- _context14.prev = 3;
14303
- _context14.next = 6;
15415
+ _context15.prev = 3;
15416
+ _context15.next = 6;
14304
15417
  return this._segmentLoader.load(seg, audioSeg, discontinuity);
14305
15418
  case 6:
14306
- responses = _context14.sent;
14307
- _context14.next = 14;
15419
+ responses = _context15.sent;
15420
+ _context15.next = 14;
14308
15421
  break;
14309
15422
  case 9:
14310
- _context14.prev = 9;
14311
- _context14.t0 = _context14["catch"](3);
14312
- _context14.t0.fatal = false;
14313
- this._segmentLoader.error = _context14.t0;
14314
- throw _context14.t0;
15423
+ _context15.prev = 9;
15424
+ _context15.t0 = _context15["catch"](3);
15425
+ _context15.t0.fatal = false;
15426
+ this._segmentLoader.error = _context15.t0;
15427
+ throw _context15.t0;
14315
15428
  case 14:
14316
15429
  if (responses[0]) {
14317
- _context14.next = 16;
15430
+ _context15.next = 16;
14318
15431
  break;
14319
15432
  }
14320
- return _context14.abrupt("return");
15433
+ return _context15.abrupt("return");
14321
15434
  case 16:
14322
- _context14.next = 18;
15435
+ _context15.next = 18;
14323
15436
  return (_this$_bufferService2 = this._bufferService).decryptBuffer.apply(_this$_bufferService2, _toConsumableArray$2(responses));
14324
15437
  case 18:
14325
- data = _context14.sent;
15438
+ data = _context15.sent;
14326
15439
  if (data) {
14327
- _context14.next = 21;
15440
+ _context15.next = 21;
14328
15441
  break;
14329
15442
  }
14330
- return _context14.abrupt("return");
15443
+ return _context15.abrupt("return");
14331
15444
  case 21:
14332
15445
  sn = seg ? seg.sn : audioSeg.sn;
14333
15446
  start = seg ? seg.start : audioSeg.start;
@@ -14341,26 +15454,26 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14341
15454
  logger.warn("update the new playlist liveEdge, segment id=".concat(sn, ", buffer start=").concat(segStart, ", liveEdge=").concat(this._playlist.liveEdge));
14342
15455
  start = segStart;
14343
15456
  }
14344
- _context14.next = 30;
15457
+ _context15.next = 30;
14345
15458
  return this._bufferService.appendBuffer(seg, audioSeg, data[0], data[1], discontinuity, contiguous, start);
14346
15459
  case 30:
14347
15460
  this.emit(Event$1.APPEND_COST, {
14348
15461
  elapsed: Date.now() - before,
14349
15462
  url: seg.url
14350
15463
  });
14351
- _context14.next = 33;
15464
+ _context15.next = 33;
14352
15465
  return this._bufferService.evictBuffer(this.config.bufferBehind);
14353
15466
  case 33:
14354
15467
  this._prevSegCc = cc;
14355
15468
  this._prevSegSn = sn;
14356
- return _context14.abrupt("return", true);
15469
+ return _context15.abrupt("return", true);
14357
15470
  case 36:
14358
15471
  case "end":
14359
- return _context14.stop();
15472
+ return _context15.stop();
14360
15473
  }
14361
- }, _callee14, this, [[3, 9]]);
15474
+ }, _callee15, this, [[3, 9]]);
14362
15475
  }));
14363
- function _reqAndBufferSegment(_x10, _x11) {
15476
+ function _reqAndBufferSegment(_x9, _x10) {
14364
15477
  return _reqAndBufferSegment2.apply(this, arguments);
14365
15478
  }
14366
15479
  return _reqAndBufferSegment;
@@ -14368,11 +15481,11 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14368
15481
  }, {
14369
15482
  key: "_onCheckQuotaExceeded",
14370
15483
  value: function() {
14371
- var _onCheckQuotaExceeded2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee15() {
15484
+ var _onCheckQuotaExceeded2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee16() {
14372
15485
  var seekTime, buffered, inBuffered, i, bufferBehind, mediaTime;
14373
- return _regeneratorRuntime$1().wrap(function _callee15$(_context15) {
15486
+ return _regeneratorRuntime$1().wrap(function _callee16$(_context16) {
14374
15487
  while (1)
14375
- switch (_context15.prev = _context15.next) {
15488
+ switch (_context16.prev = _context16.next) {
14376
15489
  case 0:
14377
15490
  seekTime = this.media.currentTime;
14378
15491
  buffered = this.media.buffered;
@@ -14380,37 +15493,37 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14380
15493
  i = 0;
14381
15494
  case 4:
14382
15495
  if (!(i < buffered.length)) {
14383
- _context15.next = 11;
15496
+ _context16.next = 11;
14384
15497
  break;
14385
15498
  }
14386
15499
  if (!(buffered.start(0) >= seekTime && seekTime < buffered.end(i))) {
14387
- _context15.next = 8;
15500
+ _context16.next = 8;
14388
15501
  break;
14389
15502
  }
14390
15503
  inBuffered = true;
14391
- return _context15.abrupt("break", 11);
15504
+ return _context16.abrupt("break", 11);
14392
15505
  case 8:
14393
15506
  i++;
14394
- _context15.next = 4;
15507
+ _context16.next = 4;
14395
15508
  break;
14396
15509
  case 11:
14397
15510
  if (!this._bufferService.isFull()) {
14398
- _context15.next = 17;
15511
+ _context16.next = 17;
14399
15512
  break;
14400
15513
  }
14401
15514
  bufferBehind = inBuffered ? this.config.bufferBehind : 5;
14402
15515
  mediaTime = this.media.currentTime;
14403
15516
  if (!(mediaTime - bufferBehind > 0)) {
14404
- _context15.next = 17;
15517
+ _context16.next = 17;
14405
15518
  break;
14406
15519
  }
14407
- _context15.next = 17;
15520
+ _context16.next = 17;
14408
15521
  return this._bufferService.removeBuffer(0, mediaTime - bufferBehind);
14409
15522
  case 17:
14410
15523
  case "end":
14411
- return _context15.stop();
15524
+ return _context16.stop();
14412
15525
  }
14413
- }, _callee15, this);
15526
+ }, _callee16, this);
14414
15527
  }));
14415
15528
  function _onCheckQuotaExceeded() {
14416
15529
  return _onCheckQuotaExceeded2.apply(this, arguments);
@@ -14428,22 +15541,22 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14428
15541
  }, {
14429
15542
  key: "_clear",
14430
15543
  value: function() {
14431
- var _clear2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee16() {
14432
- return _regeneratorRuntime$1().wrap(function _callee16$(_context16) {
15544
+ var _clear2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee17() {
15545
+ return _regeneratorRuntime$1().wrap(function _callee17$(_context17) {
14433
15546
  while (1)
14434
- switch (_context16.prev = _context16.next) {
15547
+ switch (_context17.prev = _context17.next) {
14435
15548
  case 0:
14436
15549
  clearTimeout(this._disconnectTimer);
14437
15550
  this._stopTick();
14438
- _context16.next = 4;
15551
+ _context17.next = 4;
14439
15552
  return Promise.all([this._segmentLoader.cancel(), this._manifestLoader.stopPoll()]);
14440
15553
  case 4:
14441
15554
  this._segmentProcessing = false;
14442
15555
  case 5:
14443
15556
  case "end":
14444
- return _context16.stop();
15557
+ return _context17.stop();
14445
15558
  }
14446
- }, _callee16, this);
15559
+ }, _callee17, this);
14447
15560
  }));
14448
15561
  function _clear() {
14449
15562
  return _clear2.apply(this, arguments);
@@ -14453,14 +15566,14 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14453
15566
  }, {
14454
15567
  key: "_reset",
14455
15568
  value: function() {
14456
- var _reset2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee17() {
15569
+ var _reset2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee18() {
14457
15570
  var _this$_seiService3;
14458
- var reuseMse, _args17 = arguments;
14459
- return _regeneratorRuntime$1().wrap(function _callee17$(_context17) {
15571
+ var reuseMse, _args18 = arguments;
15572
+ return _regeneratorRuntime$1().wrap(function _callee18$(_context18) {
14460
15573
  while (1)
14461
- switch (_context17.prev = _context17.next) {
15574
+ switch (_context18.prev = _context18.next) {
14462
15575
  case 0:
14463
- reuseMse = _args17.length > 0 && _args17[0] !== void 0 ? _args17[0] : false;
15576
+ reuseMse = _args18.length > 0 && _args18[0] !== void 0 ? _args18[0] : false;
14464
15577
  this._reloadOnPlay = false;
14465
15578
  this._prevSegSn = null;
14466
15579
  this._prevSegCc = null;
@@ -14469,15 +15582,15 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14469
15582
  this._segmentLoader.reset();
14470
15583
  (_this$_seiService3 = this._seiService) === null || _this$_seiService3 === void 0 ? void 0 : _this$_seiService3.reset();
14471
15584
  this._stats.reset();
14472
- _context17.next = 11;
15585
+ _context18.next = 11;
14473
15586
  return this._clear();
14474
15587
  case 11:
14475
- return _context17.abrupt("return", this._bufferService.reset(reuseMse));
15588
+ return _context18.abrupt("return", this._bufferService.reset(reuseMse));
14476
15589
  case 12:
14477
15590
  case "end":
14478
- return _context17.stop();
15591
+ return _context18.stop();
14479
15592
  }
14480
- }, _callee17, this);
15593
+ }, _callee18, this);
14481
15594
  }));
14482
15595
  function _reset() {
14483
15596
  return _reset2.apply(this, arguments);
@@ -14558,8 +15671,8 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14558
15671
  value: function _tryEos() {
14559
15672
  var _this$_bufferService3, _this$_bufferService4;
14560
15673
  var media = this.media;
14561
- var _this$_playlist = this._playlist, nextSegment = _this$_playlist.nextSegment, lastSegment = _this$_playlist.lastSegment;
14562
- 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);
15674
+ var _this$_playlist2 = this._playlist, nextSegment = _this$_playlist2.nextSegment, lastSegment = _this$_playlist2.lastSegment;
15675
+ var eosAllowed = (!nextSegment || lastSegment && Buffer$1.isBuffered(media, lastSegment.start + lastSegment.duration / 2)) && media.readyState && media.duration > 0 && ((_this$_bufferService3 = this._bufferService) === null || _this$_bufferService3 === void 0 ? void 0 : _this$_bufferService3.msIsOpened) && !((_this$_bufferService4 = this._bufferService) !== null && _this$_bufferService4 !== void 0 && _this$_bufferService4.msHasOpTasks);
14563
15676
  if (!eosAllowed) {
14564
15677
  return;
14565
15678
  }
@@ -14595,7 +15708,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14595
15708
  }]);
14596
15709
  return Hls2;
14597
15710
  }(EventEmitter);
14598
- _defineProperty$3(Hls, "version", "3.0.19-rc.0");
15711
+ _defineProperty$3(Hls, "version", "3.0.21-rc.2");
14599
15712
  try {
14600
15713
  if (localStorage.getItem("xgd")) {
14601
15714
  Hls.enableLogger();
@@ -14686,6 +15799,7 @@ var PluginExtension = /* @__PURE__ */ function() {
14686
15799
  }]);
14687
15800
  return PluginExtension2;
14688
15801
  }();
15802
+ var _excluded = ["currentTime"];
14689
15803
  function parseSwitchUrlArgs(args, plugin) {
14690
15804
  var player = plugin.player;
14691
15805
  var curTime = player.currentTime;
@@ -14696,9 +15810,14 @@ function parseSwitchUrlArgs(args, plugin) {
14696
15810
  case "boolean":
14697
15811
  options.seamless = args;
14698
15812
  break;
14699
- case "object":
14700
- Object.assign(options, args);
15813
+ case "object": {
15814
+ var currentTime = args.currentTime, rest = _objectWithoutProperties$1(args, _excluded);
15815
+ Object.assign(options, rest);
15816
+ if (typeof currentTime === "number") {
15817
+ options.startTime = currentTime;
15818
+ }
14701
15819
  break;
15820
+ }
14702
15821
  }
14703
15822
  return options;
14704
15823
  }
@@ -14708,10 +15827,11 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
14708
15827
  function HlsPlugin2() {
14709
15828
  var _this;
14710
15829
  _classCallCheck$3(this, HlsPlugin2);
14711
- for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
14712
- _args[_key] = arguments[_key];
15830
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
15831
+ args[_key] = arguments[_key];
14713
15832
  }
14714
- _this = _super.call.apply(_super, [this].concat(_args));
15833
+ _this = _super.call.apply(_super, [this].concat(args));
15834
+ _defineProperty$3(_assertThisInitialized$2(_this), "logger", logger);
14715
15835
  _defineProperty$3(_assertThisInitialized$2(_this), "hls", null);
14716
15836
  _defineProperty$3(_assertThisInitialized$2(_this), "pluginExtension", null);
14717
15837
  _defineProperty$3(_assertThisInitialized$2(_this), "getStats", function() {
@@ -14723,24 +15843,6 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
14723
15843
  var lang = _ref.lang;
14724
15844
  (_this$hls2 = _this.hls) === null || _this$hls2 === void 0 ? void 0 : _this$hls2.switchSubtitleStream(lang);
14725
15845
  });
14726
- _defineProperty$3(_assertThisInitialized$2(_this), "_onSwitchURL", function(url, args) {
14727
- return new Promise(function(resolve, reject) {
14728
- var _assertThisInitialize = _assertThisInitialized$2(_this), player = _assertThisInitialize.player, hls = _assertThisInitialize.hls;
14729
- if (hls) {
14730
- var _this$player$config, _this$player$config$h;
14731
- var options = parseSwitchUrlArgs(args, _assertThisInitialized$2(_this));
14732
- player.config.url = url;
14733
- hls.switchURL(url, options).then(function() {
14734
- return resolve(true);
14735
- }).catch(reject);
14736
- 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) {
14737
- _this._keepPauseStatus();
14738
- }
14739
- } else {
14740
- reject();
14741
- }
14742
- });
14743
- });
14744
15846
  _defineProperty$3(_assertThisInitialized$2(_this), "_keepPauseStatus", function() {
14745
15847
  var paused = _this.player.paused;
14746
15848
  if (!paused)
@@ -14765,8 +15867,8 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
14765
15867
  }, {
14766
15868
  key: "softDecode",
14767
15869
  get: function get() {
14768
- var _this$player, _this$player$config2;
14769
- 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;
15870
+ var _this$player, _this$player$config;
15871
+ 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;
14770
15872
  return !!mediaType && mediaType !== "video" && mediaType !== "audio";
14771
15873
  }
14772
15874
  }, {
@@ -14774,13 +15876,35 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
14774
15876
  value: function beforePlayerInit() {
14775
15877
  var _this2 = this;
14776
15878
  var config = this.player.config;
15879
+ var mediaElem = this.player.media || this.player.video;
14777
15880
  var hlsOpts = config.hls || {};
14778
15881
  if (!config.url && !config.__allowHlsEmptyUrl__ || !hlsOpts.preferMMS && MSE.isMMSOnly()) {
14779
15882
  return;
14780
15883
  }
14781
15884
  if (this.hls)
14782
15885
  this.hls.destroy();
14783
- this.player.switchURL = this._onSwitchURL;
15886
+ var descriptor = Object.getOwnPropertyDescriptor(this.player, "switchURL");
15887
+ if (!descriptor || descriptor.writable) {
15888
+ this.player.switchURL = function(url, args) {
15889
+ return new Promise(function(resolve, reject) {
15890
+ var player = _this2.player, hls = _this2.hls;
15891
+ if (hls) {
15892
+ var _this2$player$config, _this2$player$config$;
15893
+ var options = parseSwitchUrlArgs(args, _this2);
15894
+ player.config.url = url;
15895
+ hls.switchURL(url, options).then(function() {
15896
+ return resolve(true);
15897
+ }).catch(reject);
15898
+ 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) {
15899
+ _this2._keepPauseStatus();
15900
+ }
15901
+ } else {
15902
+ reject();
15903
+ }
15904
+ });
15905
+ };
15906
+ }
15907
+ var onSwitchUrl = this.player.switchURL;
14784
15908
  this.player.handleSource = false;
14785
15909
  hlsOpts.innerDegrade = hlsOpts.innerDegrade || config.innerDegrade;
14786
15910
  if (hlsOpts.disconnectTime === null || hlsOpts.disconnectTime === void 0)
@@ -14788,7 +15912,7 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
14788
15912
  this.hls = new Hls(_objectSpread2$2({
14789
15913
  softDecode: this.softDecode,
14790
15914
  isLive: config.isLive,
14791
- media: this.player.media || this.player.video,
15915
+ media: mediaElem,
14792
15916
  startTime: config.startTime,
14793
15917
  url: config.url
14794
15918
  }, hlsOpts));
@@ -14806,7 +15930,7 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
14806
15930
  if (this.softDecode) {
14807
15931
  this.pluginExtension = new PluginExtension(_objectSpread2$2({
14808
15932
  isLive: config.isLive,
14809
- media: this.player.video
15933
+ media: mediaElem
14810
15934
  }, hlsOpts), this);
14811
15935
  this.player.forceDegradeToVideo = function() {
14812
15936
  var _this2$pluginExtensio;
@@ -14823,8 +15947,8 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
14823
15947
  return (_this2$hls2 = _this2.hls) === null || _this2$hls2 === void 0 ? void 0 : _this2$hls2.replay();
14824
15948
  });
14825
15949
  }
15950
+ this.on(URL_CHANGE, onSwitchUrl);
14826
15951
  this.on(SWITCH_SUBTITLE, this._onSwitchSubtitle);
14827
- this.on(URL_CHANGE, this._onSwitchURL);
14828
15952
  this.on(DESTROY, this.destroy.bind(this));
14829
15953
  this._transError();
14830
15954
  this._transCoreEvent(EVENT.TTFB);
@@ -14834,6 +15958,7 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
14834
15958
  this._transCoreEvent(EVENT.LOAD_RETRY);
14835
15959
  this._transCoreEvent(EVENT.SOURCEBUFFER_CREATED);
14836
15960
  this._transCoreEvent(EVENT.MEDIASOURCE_OPENED);
15961
+ this._transCoreEvent(EVENT.APPEND_BUFFER);
14837
15962
  this._transCoreEvent(EVENT.REMOVE_BUFFER);
14838
15963
  this._transCoreEvent(EVENT.BUFFEREOS);
14839
15964
  this._transCoreEvent(EVENT.KEYFRAME);
@@ -14853,7 +15978,9 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
14853
15978
  this._transCoreEvent(Event$1.SUBTITLE_PLAYLIST);
14854
15979
  this._transCoreEvent(Event$1.APPEND_COST);
14855
15980
  if (config.url) {
14856
- this.hls.load(config.url, true).catch(function(e) {
15981
+ this.hls.load(config.url, {
15982
+ reuseMse: true
15983
+ }).catch(function(e) {
14857
15984
  });
14858
15985
  }
14859
15986
  }