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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/esm/index.d.ts +0 -1
  2. package/esm/index.development.css +0 -7
  3. package/esm/index.development.js +47274 -53342
  4. package/esm/index.production.css +1 -1
  5. package/esm/index.production.js +4 -13
  6. package/esm/veplayer.plugin.abr.development.js +12 -0
  7. package/esm/veplayer.plugin.abr.production.js +1 -1
  8. package/esm/veplayer.plugin.drm.development.js +12 -0
  9. package/esm/veplayer.plugin.drm.production.js +1 -1
  10. package/esm/veplayer.plugin.flv.development.js +675 -194
  11. package/esm/veplayer.plugin.flv.production.js +1 -1
  12. package/esm/veplayer.plugin.hls.development.js +1159 -369
  13. package/esm/veplayer.plugin.hls.production.js +1 -1
  14. package/esm/veplayer.plugin.mp4.development.js +13 -1
  15. package/esm/veplayer.plugin.mp4.production.js +1 -1
  16. package/esm/veplayer.plugin.rtm.development.js +167 -51
  17. package/esm/veplayer.plugin.rtm.production.js +1 -1
  18. package/esm/veplayer.plugin.shaka.development.js +12 -0
  19. package/esm/veplayer.plugin.shaka.production.js +1 -1
  20. package/package.json +1 -1
  21. package/umd/index.d.ts +0 -1
  22. package/umd/veplayer.plugin.abr.development.js +12 -0
  23. package/umd/veplayer.plugin.abr.production.js +1 -1
  24. package/umd/veplayer.plugin.drm.development.js +12 -0
  25. package/umd/veplayer.plugin.drm.production.js +1 -1
  26. package/umd/veplayer.plugin.flv.development.js +675 -194
  27. package/umd/veplayer.plugin.flv.production.js +1 -1
  28. package/umd/veplayer.plugin.hls.development.js +1126 -336
  29. package/umd/veplayer.plugin.hls.production.js +1 -1
  30. package/umd/veplayer.plugin.mp4.development.js +13 -1
  31. package/umd/veplayer.plugin.mp4.production.js +1 -1
  32. package/umd/veplayer.plugin.rtm.development.js +167 -51
  33. package/umd/veplayer.plugin.rtm.production.js +1 -1
  34. package/umd/veplayer.plugin.shaka.development.js +12 -0
  35. package/umd/veplayer.plugin.shaka.production.js +1 -1
  36. package/esm/veplayer.plugin.ad.development.css +0 -7
  37. package/esm/veplayer.plugin.ad.development.js +0 -9042
  38. package/esm/veplayer.plugin.ad.production.css +0 -1
  39. package/esm/veplayer.plugin.ad.production.js +0 -4
  40. package/umd/veplayer.plugin.ad.development.css +0 -7
  41. package/umd/veplayer.plugin.ad.development.js +0 -9045
  42. package/umd/veplayer.plugin.ad.production.css +0 -1
  43. package/umd/veplayer.plugin.ad.production.js +0 -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.20-alpha.4";
1643
+ var version = "3.0.21-rc.5";
1644
1644
  var ERROR_MAP = {
1645
1645
  1: 5101,
1646
1646
  2: 5102,
@@ -2108,6 +2108,18 @@ var BasePlugin = /* @__PURE__ */ function() {
2108
2108
  }
2109
2109
  }
2110
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
+ }
2111
2123
  }, {
2112
2124
  key: "defaultConfig",
2113
2125
  get: function get() {
@@ -2164,10 +2176,10 @@ function _regeneratorRuntime() {
2164
2176
  return obj[key] = value;
2165
2177
  };
2166
2178
  }
2167
- function wrap(innerFn, outerFn, self, tryLocsList) {
2179
+ function wrap(innerFn, outerFn, self2, tryLocsList) {
2168
2180
  var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []);
2169
2181
  return defineProperty(generator, "_invoke", {
2170
- value: makeInvokeMethod(innerFn, self, context)
2182
+ value: makeInvokeMethod(innerFn, self2, context)
2171
2183
  }), generator;
2172
2184
  }
2173
2185
  function tryCatch(fn, obj, arg) {
@@ -2234,7 +2246,7 @@ function _regeneratorRuntime() {
2234
2246
  }
2235
2247
  });
2236
2248
  }
2237
- function makeInvokeMethod(innerFn, self, context) {
2249
+ function makeInvokeMethod(innerFn, self2, context) {
2238
2250
  var state = "suspendedStart";
2239
2251
  return function(method, arg) {
2240
2252
  if ("executing" === state)
@@ -2263,7 +2275,7 @@ function _regeneratorRuntime() {
2263
2275
  } else
2264
2276
  "return" === context.method && context.abrupt("return", context.arg);
2265
2277
  state = "executing";
2266
- var record = tryCatch(innerFn, self, context);
2278
+ var record = tryCatch(innerFn, self2, context);
2267
2279
  if ("normal" === record.type) {
2268
2280
  if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel)
2269
2281
  continue;
@@ -2345,9 +2357,9 @@ function _regeneratorRuntime() {
2345
2357
  };
2346
2358
  }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function() {
2347
2359
  return this;
2348
- }), exports.AsyncIterator = AsyncIterator, exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
2360
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function(innerFn, outerFn, self2, tryLocsList, PromiseImpl) {
2349
2361
  void 0 === PromiseImpl && (PromiseImpl = Promise);
2350
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
2362
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self2, tryLocsList), PromiseImpl);
2351
2363
  return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function(result) {
2352
2364
  return result.done ? result.value : iter.next();
2353
2365
  });
@@ -2482,9 +2494,9 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2482
2494
  }
2483
2495
  function _asyncToGenerator(fn) {
2484
2496
  return function() {
2485
- var self = this, args = arguments;
2497
+ var self2 = this, args = arguments;
2486
2498
  return new Promise(function(resolve, reject) {
2487
- var gen = fn.apply(self, args);
2499
+ var gen = fn.apply(self2, args);
2488
2500
  function _next(value) {
2489
2501
  asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
2490
2502
  }
@@ -2658,19 +2670,19 @@ function _objectWithoutProperties(source, excluded) {
2658
2670
  }
2659
2671
  return target;
2660
2672
  }
2661
- function _assertThisInitialized$1(self) {
2662
- if (self === void 0) {
2673
+ function _assertThisInitialized$1(self2) {
2674
+ if (self2 === void 0) {
2663
2675
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
2664
2676
  }
2665
- return self;
2677
+ return self2;
2666
2678
  }
2667
- function _possibleConstructorReturn$1(self, call) {
2679
+ function _possibleConstructorReturn$1(self2, call) {
2668
2680
  if (call && (typeof call === "object" || typeof call === "function")) {
2669
2681
  return call;
2670
2682
  } else if (call !== void 0) {
2671
2683
  throw new TypeError("Derived constructors may only return object or undefined");
2672
2684
  }
2673
- return _assertThisInitialized$1(self);
2685
+ return _assertThisInitialized$1(self2);
2674
2686
  }
2675
2687
  function _createSuper$1(Derived) {
2676
2688
  var hasNativeReflectConstruct = _isNativeReflectConstruct$1();
@@ -2730,7 +2742,7 @@ function _arrayLikeToArray$1(arr, len) {
2730
2742
  arr2[i] = arr[i];
2731
2743
  return arr2;
2732
2744
  }
2733
- function _createForOfIteratorHelper(o, allowArrayLike) {
2745
+ function _createForOfIteratorHelper$1(o, allowArrayLike) {
2734
2746
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
2735
2747
  if (!it) {
2736
2748
  if (Array.isArray(o) || (it = _unsupportedIterableToArray$1(o)) || allowArrayLike && o && typeof o.length === "number") {
@@ -3085,7 +3097,7 @@ var Logger$2 = /* @__PURE__ */ function() {
3085
3097
  this.logCache.apply(this, [LogCacheLevel.DEBUG].concat(args));
3086
3098
  if (Logger2.disabled)
3087
3099
  return;
3088
- (_console = console).debug.apply(_console, [this._prefix, nowTime$1()].concat(args));
3100
+ (_console = console).debug.apply(_console, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
3089
3101
  }
3090
3102
  }, {
3091
3103
  key: "log",
@@ -3097,7 +3109,7 @@ var Logger$2 = /* @__PURE__ */ function() {
3097
3109
  this.logCache.apply(this, [LogCacheLevel.LOG].concat(args));
3098
3110
  if (Logger2.disabled)
3099
3111
  return;
3100
- (_console2 = console).log.apply(_console2, [this._prefix, nowTime$1()].concat(args));
3112
+ (_console2 = console).log.apply(_console2, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
3101
3113
  }
3102
3114
  }, {
3103
3115
  key: "warn",
@@ -3109,7 +3121,7 @@ var Logger$2 = /* @__PURE__ */ function() {
3109
3121
  this.logCache.apply(this, [LogCacheLevel.WARN].concat(args));
3110
3122
  if (Logger2.disabled)
3111
3123
  return;
3112
- (_console3 = console).warn.apply(_console3, [this._prefix, nowTime$1()].concat(args));
3124
+ (_console3 = console).warn.apply(_console3, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
3113
3125
  }
3114
3126
  }, {
3115
3127
  key: "error",
@@ -3121,7 +3133,7 @@ var Logger$2 = /* @__PURE__ */ function() {
3121
3133
  this.logCache.apply(this, [LogCacheLevel.ERROR].concat(args));
3122
3134
  if (Logger2.disabled)
3123
3135
  return;
3124
- (_console4 = console).error.apply(_console4, [this._prefix, nowTime$1()].concat(args));
3136
+ (_console4 = console).error.apply(_console4, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
3125
3137
  }
3126
3138
  }, {
3127
3139
  key: "logCache",
@@ -3136,7 +3148,7 @@ var Logger$2 = /* @__PURE__ */ function() {
3136
3148
  var finLogText = logText.map(function(item) {
3137
3149
  return logable(item);
3138
3150
  });
3139
- text = this._prefix + nowTime$1() + JSON.stringify(finLogText);
3151
+ text = "[".concat(nowTime$1(), "]") + this._prefix + JSON.stringify(finLogText);
3140
3152
  } catch (e) {
3141
3153
  return;
3142
3154
  }
@@ -4052,8 +4064,8 @@ function createResponse(data, done, response, contentLength, age, startTime, fir
4052
4064
  response
4053
4065
  };
4054
4066
  }
4055
- function calculateSpeed(byteLen, millisec) {
4056
- return Math.round(byteLen * 8 * 1e3 / millisec / 1024);
4067
+ function calculateSpeed(byteLen, milliSecond) {
4068
+ return Math.round(byteLen * 8 * 1e3 / milliSecond / 1024);
4057
4069
  }
4058
4070
  var EVENT = {
4059
4071
  ERROR: "error",
@@ -4065,6 +4077,7 @@ var EVENT = {
4065
4077
  SOURCEBUFFER_CREATED: "core.sourcebuffercreated",
4066
4078
  MEDIASOURCE_OPENED: "core.mediasourceopened",
4067
4079
  ANALYZE_DURATION_EXCEEDED: "core.analyzedurationexceeded",
4080
+ APPEND_BUFFER: "core.appendbuffer",
4068
4081
  REMOVE_BUFFER: "core.removebuffer",
4069
4082
  BUFFEREOS: "core.buffereos",
4070
4083
  KEYFRAME: "core.keyframe",
@@ -4837,7 +4850,7 @@ var XhrLoader = /* @__PURE__ */ function(_EventEmitter) {
4837
4850
  value: function _getHeaders(xhr) {
4838
4851
  var headerLines = xhr.getAllResponseHeaders().trim().split("\r\n");
4839
4852
  var headers = {};
4840
- var _iterator = _createForOfIteratorHelper(headerLines), _step;
4853
+ var _iterator = _createForOfIteratorHelper$1(headerLines), _step;
4841
4854
  try {
4842
4855
  for (_iterator.s(); !(_step = _iterator.n()).done; ) {
4843
4856
  var header = _step.value;
@@ -4859,7 +4872,7 @@ var XhrLoader = /* @__PURE__ */ function(_EventEmitter) {
4859
4872
  }]);
4860
4873
  return XhrLoader2;
4861
4874
  }(EventEmitter);
4862
- var _excluded$1 = ["retry", "retryDelay", "onRetryError", "transformError"];
4875
+ var _excluded$2 = ["retry", "retryDelay", "onRetryError", "transformError"];
4863
4876
  var Task = /* @__PURE__ */ function() {
4864
4877
  function Task2(type, config) {
4865
4878
  _classCallCheck$1(this, Task2);
@@ -4879,7 +4892,7 @@ var Task = /* @__PURE__ */ function() {
4879
4892
  key: "exec",
4880
4893
  value: function exec() {
4881
4894
  var _this = this;
4882
- 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);
4883
4896
  var request = /* @__PURE__ */ function() {
4884
4897
  var _ref = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee() {
4885
4898
  var response, error, isRetry;
@@ -5604,19 +5617,19 @@ function _isNativeReflectConstruct() {
5604
5617
  return false;
5605
5618
  }
5606
5619
  }
5607
- function _assertThisInitialized(self) {
5608
- if (self === void 0) {
5620
+ function _assertThisInitialized(self2) {
5621
+ if (self2 === void 0) {
5609
5622
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
5610
5623
  }
5611
- return self;
5624
+ return self2;
5612
5625
  }
5613
- function _possibleConstructorReturn(self, call) {
5626
+ function _possibleConstructorReturn(self2, call) {
5614
5627
  if (call && (typeof call === "object" || typeof call === "function")) {
5615
5628
  return call;
5616
5629
  } else if (call !== void 0) {
5617
5630
  throw new TypeError("Derived constructors may only return object or undefined");
5618
5631
  }
5619
- return _assertThisInitialized(self);
5632
+ return _assertThisInitialized(self2);
5620
5633
  }
5621
5634
  function _createSuper(Derived) {
5622
5635
  var hasNativeReflectConstruct = _isNativeReflectConstruct();
@@ -5675,6 +5688,60 @@ function _nonIterableSpread() {
5675
5688
  function _nonIterableRest() {
5676
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.");
5677
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
+ }
5678
5745
  function _toPrimitive(input, hint) {
5679
5746
  if (typeof input !== "object" || input === null)
5680
5747
  return input;
@@ -5697,13 +5764,16 @@ var TrackType = {
5697
5764
  METADATA: "metadata"
5698
5765
  };
5699
5766
  var VideoCodecType = {
5767
+ AV1: "av1",
5700
5768
  AVC: "avc",
5701
5769
  HEVC: "hevc"
5702
5770
  };
5703
5771
  var AudioCodecType = {
5704
5772
  AAC: "aac",
5705
5773
  G711PCMA: "g7110a",
5706
- G711PCMU: "g7110m"
5774
+ G711PCMU: "g7110m",
5775
+ OPUS: "opus",
5776
+ MP3: "mp3"
5707
5777
  };
5708
5778
  var WarningType = {
5709
5779
  LARGE_AV_SHIFT: "LARGE_AV_SHIFT",
@@ -5743,6 +5813,7 @@ var VideoTrack = /* @__PURE__ */ function() {
5743
5813
  _defineProperty(this, "isVideoEncryption", false);
5744
5814
  _defineProperty(this, "isAudioEncryption", false);
5745
5815
  _defineProperty(this, "isVideo", true);
5816
+ _defineProperty(this, "lastKeyFrameDts", 0);
5746
5817
  _defineProperty(this, "kid", null);
5747
5818
  _defineProperty(this, "pssh", null);
5748
5819
  _defineProperty(this, "ext", void 0);
@@ -5785,6 +5856,9 @@ var VideoTrack = /* @__PURE__ */ function() {
5785
5856
  }, {
5786
5857
  key: "exist",
5787
5858
  value: function exist() {
5859
+ if (/av01/.test(this.codec)) {
5860
+ return true;
5861
+ }
5788
5862
  return !!(this.pps.length && this.sps.length && this.codec);
5789
5863
  }
5790
5864
  }, {
@@ -5808,6 +5882,7 @@ var AudioTrack = /* @__PURE__ */ function() {
5808
5882
  _defineProperty(this, "codecType", AudioCodecType.AAC);
5809
5883
  _defineProperty(this, "pid", -1);
5810
5884
  _defineProperty(this, "codec", "");
5885
+ _defineProperty(this, "container", "");
5811
5886
  _defineProperty(this, "sequenceNumber", 0);
5812
5887
  _defineProperty(this, "sampleDuration", 0);
5813
5888
  _defineProperty(this, "timescale", 0);
@@ -5848,7 +5923,7 @@ var AudioTrack = /* @__PURE__ */ function() {
5848
5923
  }, {
5849
5924
  key: "exist",
5850
5925
  value: function exist() {
5851
- 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));
5852
5927
  }
5853
5928
  }, {
5854
5929
  key: "hasSample",
@@ -7236,6 +7311,119 @@ var TsFixer = /* @__PURE__ */ function() {
7236
7311
  }]);
7237
7312
  return TsFixer2;
7238
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
+ if (isFirefox) {
7378
+ track.codec = "mp3";
7379
+ } else {
7380
+ track.container = "audio/mpeg";
7381
+ }
7382
+ track.samples.push(sample);
7383
+ return {
7384
+ length: header.frameLength
7385
+ };
7386
+ }
7387
+ }
7388
+ }, {
7389
+ key: "parseHeader",
7390
+ value: function parseHeader(data, offset) {
7391
+ var mpegVersion = data[offset + 1] >> 3 & 3;
7392
+ var mpegLayer = data[offset + 1] >> 1 & 3;
7393
+ var bitRateIndex = data[offset + 2] >> 4 & 15;
7394
+ var sampleRateIndex = data[offset + 2] >> 2 & 3;
7395
+ if (mpegVersion !== 1 && bitRateIndex !== 0 && bitRateIndex !== 15 && sampleRateIndex !== 3) {
7396
+ var paddingBit = data[offset + 2] >> 1 & 1;
7397
+ var channelMode = data[offset + 3] >> 6;
7398
+ var columnInBitrates = mpegVersion === 3 ? 3 - mpegLayer : mpegLayer === 3 ? 3 : 4;
7399
+ var bitRate = BitratesMap[columnInBitrates * 14 + bitRateIndex - 1] * 1e3;
7400
+ var columnInSampleRates = mpegVersion === 3 ? 0 : mpegVersion === 2 ? 1 : 2;
7401
+ var sampleRate = FREQ[columnInSampleRates * 3 + sampleRateIndex];
7402
+ var channelCount = channelMode === 3 ? 1 : 2;
7403
+ var sampleCoefficient = SamplesCoefficients[mpegVersion][mpegLayer];
7404
+ var bytesInSlot = BytesInSlot[mpegLayer];
7405
+ var samplesPerFrame = sampleCoefficient * 8 * bytesInSlot;
7406
+ var frameLength = Math.floor(sampleCoefficient * bitRate / sampleRate + paddingBit) * bytesInSlot;
7407
+ if (chromeVersion === null) {
7408
+ var userAgent = navigator.userAgent || "";
7409
+ var result = userAgent.match(/Chrome\/(\d+)/i);
7410
+ chromeVersion = result ? parseInt(result[1]) : 0;
7411
+ }
7412
+ var needChromeFix = !!chromeVersion && chromeVersion <= 87;
7413
+ if (needChromeFix && mpegLayer === 2 && bitRate >= 224e3 && channelMode === 0) {
7414
+ data[offset + 3] = data[offset + 3] | 128;
7415
+ }
7416
+ return {
7417
+ sampleRate,
7418
+ channelCount,
7419
+ frameLength,
7420
+ samplesPerFrame
7421
+ };
7422
+ }
7423
+ }
7424
+ }]);
7425
+ return MPEG2;
7426
+ }();
7239
7427
  var logger$4 = new Logger$1("TsDemuxer");
7240
7428
  var TsDemuxer = /* @__PURE__ */ function() {
7241
7429
  function TsDemuxer2(videoTrack, audioTrack, metadataTrack) {
@@ -7319,6 +7507,13 @@ var TsDemuxer = /* @__PURE__ */ function() {
7319
7507
  case 15:
7320
7508
  audioTrack.pid = audioPid = esPid;
7321
7509
  break;
7510
+ case 3:
7511
+ case 4:
7512
+ if (audioTrack.pid === -1) {
7513
+ audioTrack.pid = audioPid = esPid;
7514
+ audioTrack.codecType = AudioCodecType.MP3;
7515
+ }
7516
+ break;
7322
7517
  case 27:
7323
7518
  if (videoPid !== -1)
7324
7519
  break;
@@ -7518,7 +7713,14 @@ var TsDemuxer = /* @__PURE__ */ function() {
7518
7713
  logger$4.warn("Cannot parse audio pes", this._audioPesData);
7519
7714
  return;
7520
7715
  }
7521
- this._parseAacData(pes);
7716
+ switch (this.audioTrack.codecType) {
7717
+ case AudioCodecType.AAC:
7718
+ this._parseAacData(pes);
7719
+ break;
7720
+ case AudioCodecType.MP3:
7721
+ this._parseMPEG(pes);
7722
+ break;
7723
+ }
7522
7724
  this._audioPesData = [];
7523
7725
  }
7524
7726
  }, {
@@ -7555,6 +7757,32 @@ var TsDemuxer = /* @__PURE__ */ function() {
7555
7757
  logger$4.warn("Cannot parse aac adts", pes);
7556
7758
  }
7557
7759
  }
7760
+ }, {
7761
+ key: "_parseMPEG",
7762
+ value: function _parseMPEG(pes) {
7763
+ var data = pes.data;
7764
+ var length = data.length;
7765
+ var frameIndex = 0;
7766
+ var offset = 0;
7767
+ var pts = pes.pts;
7768
+ if (pts === void 0) {
7769
+ logger$4.warn("[tsdemuxer]: MPEG PES unknown PTS");
7770
+ return;
7771
+ }
7772
+ while (offset < length) {
7773
+ if (MPEG.isHeader(data, offset)) {
7774
+ var frame = MPEG.appendFrame(this.audioTrack, data, offset, pts, frameIndex);
7775
+ if (frame) {
7776
+ offset += frame.length;
7777
+ frameIndex++;
7778
+ } else {
7779
+ break;
7780
+ }
7781
+ } else {
7782
+ offset++;
7783
+ }
7784
+ }
7785
+ }
7558
7786
  }], [{
7559
7787
  key: "probe",
7560
7788
  value: function probe(data) {
@@ -7601,7 +7829,7 @@ var ByteReader = /* @__PURE__ */ function() {
7601
7829
  _classCallCheck(this, ByteReader2);
7602
7830
  this.dv = new DataView(buf);
7603
7831
  this.start = this.offset = offset || this.dv.byteOffset;
7604
- this.end = len ? this.start + len : this.dv.byteLength;
7832
+ this.end = len ? this.start + len : this.start + this.dv.byteLength;
7605
7833
  }
7606
7834
  _createClass(ByteReader2, [{
7607
7835
  key: "buffer",
@@ -7703,7 +7931,7 @@ var ByteReader = /* @__PURE__ */ function() {
7703
7931
  value: function readToBuffer(len) {
7704
7932
  var buffer;
7705
7933
  if (this.offset || len) {
7706
- buffer = this.dv.buffer.slice(this.offset, len ? this.offset + len : void 0);
7934
+ buffer = this.dv.buffer.slice(this.offset, len ? this.offset + len : this.end);
7707
7935
  } else {
7708
7936
  buffer = this.dv.buffer;
7709
7937
  }
@@ -7756,6 +7984,47 @@ var ByteReader = /* @__PURE__ */ function() {
7756
7984
  }]);
7757
7985
  return ByteReader2;
7758
7986
  }();
7987
+ var BitReader = /* @__PURE__ */ function() {
7988
+ function BitReader2(val, size) {
7989
+ _classCallCheck(this, BitReader2);
7990
+ this.offset = 0;
7991
+ this.val = val;
7992
+ this.size = size;
7993
+ }
7994
+ _createClass(BitReader2, [{
7995
+ key: "skip",
7996
+ value: function skip(len) {
7997
+ this.offset += len;
7998
+ }
7999
+ }, {
8000
+ key: "read",
8001
+ value: function read(len) {
8002
+ var unreadLength = this.size - this.offset - len;
8003
+ if (unreadLength >= 0) {
8004
+ var bits = 0, i = 0;
8005
+ this.offset += len;
8006
+ if (this.size > 31) {
8007
+ for (; i < len; i++) {
8008
+ bits += Math.pow(2, i);
8009
+ }
8010
+ return this.val / Math.pow(2, unreadLength) & bits;
8011
+ } else {
8012
+ for (; i < len; i++) {
8013
+ bits += 1 << i;
8014
+ }
8015
+ return this.val >>> unreadLength & bits;
8016
+ }
8017
+ }
8018
+ throw new Error("the number of the read operation exceeds the total length limit of bits");
8019
+ }
8020
+ }], [{
8021
+ key: "fromByte",
8022
+ value: function fromByte(byte, len) {
8023
+ return new BitReader2(byte.read(len), len << 3);
8024
+ }
8025
+ }]);
8026
+ return BitReader2;
8027
+ }();
7759
8028
  var MP4Parser = /* @__PURE__ */ function() {
7760
8029
  function MP4Parser2() {
7761
8030
  _classCallCheck(this, MP4Parser2);
@@ -8095,6 +8364,8 @@ var MP4Parser = /* @__PURE__ */ function() {
8095
8364
  ret.entryCount = readBig32(data);
8096
8365
  ret.entries = MP4Parser2.findBox(data.subarray(4), [], start + 4).map(function(b) {
8097
8366
  switch (b.type) {
8367
+ case "av01":
8368
+ return MP4Parser2.av01(b);
8098
8369
  case "avc1":
8099
8370
  case "avc2":
8100
8371
  case "avc3":
@@ -8174,6 +8445,69 @@ var MP4Parser = /* @__PURE__ */ function() {
8174
8445
  }
8175
8446
  });
8176
8447
  }
8448
+ }, {
8449
+ key: "colr",
8450
+ value: function colr(box) {
8451
+ return parseBox(box, false, function(ret, data) {
8452
+ var byte = ByteReader.fromUint8(data);
8453
+ ret.data = box.data;
8454
+ ret.colorType = byte.readString(4);
8455
+ if (ret.colorType === "nclx") {
8456
+ ret.colorPrimaries = byte.read(2);
8457
+ ret.transferCharacteristics = byte.read(2);
8458
+ ret.matrixCoefficients = byte.read(2);
8459
+ ret.fullRangeFlag = byte.read(1) >> 7;
8460
+ } else if (ret.colorType === "rICC" || ret.colorType === "prof") {
8461
+ ret.iccProfile = data.readToUint8();
8462
+ }
8463
+ });
8464
+ }
8465
+ }, {
8466
+ key: "av01",
8467
+ value: function av01(box) {
8468
+ return parseBox(box, false, function(ret, data, start) {
8469
+ var bodyStart = parseVisualSampleEntry(ret, data);
8470
+ var bodyData = data.subarray(bodyStart);
8471
+ start += bodyStart;
8472
+ ret.av1C = MP4Parser2.av1C(MP4Parser2.findBox(bodyData, ["av1C"], start)[0]);
8473
+ ret.colr = MP4Parser2.colr(MP4Parser2.findBox(bodyData, ["colr"], start)[0]);
8474
+ });
8475
+ }
8476
+ }, {
8477
+ key: "av1C",
8478
+ value: function av1C(box) {
8479
+ return parseBox(box, false, function(ret, data) {
8480
+ ret.data = box.data;
8481
+ var byte = ByteReader.fromUint8(data);
8482
+ var bit = BitReader.fromByte(byte, 4);
8483
+ ret.marker = bit.read(1);
8484
+ ret.version = bit.read(7);
8485
+ ret.seqProfile = bit.read(3);
8486
+ ret.seqLevelIdx0 = bit.read(5);
8487
+ ret.seqTier0 = bit.read(1);
8488
+ ret.highBitdepth = bit.read(1);
8489
+ ret.twelveBit = bit.read(1);
8490
+ ret.monochrome = bit.read(1);
8491
+ ret.chromaSubsamplingX = bit.read(1);
8492
+ ret.chromaSubsamplingY = bit.read(1);
8493
+ ret.chromaSamplePosition = bit.read(2);
8494
+ ret.reserved = bit.read(3);
8495
+ ret.initialPresentationDelayPresent = bit.read(1);
8496
+ if (ret.initialPresentationDelayPresent) {
8497
+ ret.initialPresentationDelayMinusOne = bit.read(4);
8498
+ } else {
8499
+ ret.initialPresentationDelayMinusOne = 0;
8500
+ }
8501
+ ret.configOBUs = byte.readToUint8();
8502
+ var bitdepth;
8503
+ if (ret.seqLevelIdx0 === 2 && ret.highBitdepth === 1) {
8504
+ bitdepth = ret.twelveBit === 1 ? "12" : "10";
8505
+ } else if (ret.seqProfile <= 2) {
8506
+ bitdepth = ret.highBitdepth === 1 ? "10" : "08";
8507
+ }
8508
+ ret.codec = ["av01", ret.seqProfile, (ret.seqLevelIdx0 < 10 ? "0" + ret.seqLevelIdx0 : ret.seqLevelIdx0) + (ret.seqTier0 ? "H" : "M"), bitdepth].join(".");
8509
+ });
8510
+ }
8177
8511
  }, {
8178
8512
  key: "avc1",
8179
8513
  value: function avc1(box) {
@@ -8607,7 +8941,12 @@ var MP4Parser = /* @__PURE__ */ function() {
8607
8941
  if (e1.pasp) {
8608
8942
  v.sarRatio = [e1.pasp.hSpacing, e1.pasp.vSpacing];
8609
8943
  }
8610
- if (e1.hvcC) {
8944
+ if (e1.av1C) {
8945
+ v.codecType = VideoCodecType.AV1;
8946
+ v.codec = e1.av1C.codec;
8947
+ v.av1C = e1.av1C.data;
8948
+ v.colr = e1.colr.data;
8949
+ } else if (e1.hvcC) {
8611
8950
  v.codecType = VideoCodecType.HEVC;
8612
8951
  v.codec = e1.hvcC.codec;
8613
8952
  v.vps = e1.hvcC.vps;
@@ -8926,8 +9265,9 @@ function parseAudioSampleEntry(ret, data) {
8926
9265
  function parseBox(box, isFullBox, parse3) {
8927
9266
  if (!box)
8928
9267
  return;
8929
- if (box.size !== box.data.length)
9268
+ if (box.size !== box.data.length) {
8930
9269
  throw new Error("box ".concat(box.type, " size !== data.length"));
9270
+ }
8931
9271
  var ret = {
8932
9272
  start: box.start,
8933
9273
  size: box.size,
@@ -8966,11 +9306,167 @@ var toHex = function toHex2() {
8966
9306
  var FMP4Demuxer = /* @__PURE__ */ function() {
8967
9307
  function FMP4Demuxer2(videoTrack, audioTrack, metadataTrack) {
8968
9308
  _classCallCheck(this, FMP4Demuxer2);
9309
+ _defineProperty(this, "__loadedMoofWraps", []);
9310
+ _defineProperty(this, "__lastRemainData", null);
9311
+ _defineProperty(this, "__lastRemainDataStart", 0);
9312
+ _defineProperty(this, "__nextMoofStart", -1);
8969
9313
  this.videoTrack = videoTrack || new VideoTrack();
8970
9314
  this.audioTrack = audioTrack || new AudioTrack();
8971
9315
  this.metadataTrack = metadataTrack || new MetadataTrack();
8972
9316
  }
8973
9317
  _createClass(FMP4Demuxer2, [{
9318
+ key: "demuxPart",
9319
+ value: function demuxPart(partData, partDataStart, moov) {
9320
+ var _this = this;
9321
+ var videoTrack = this.videoTrack, audioTrack = this.audioTrack;
9322
+ var videoExist = videoTrack.exist();
9323
+ var audioExist = audioTrack.exist();
9324
+ var isAV01 = /av01/.test(videoTrack.codec);
9325
+ videoTrack.samples = [];
9326
+ audioTrack.samples = [];
9327
+ var data = partData;
9328
+ var dataStart = partDataStart;
9329
+ if (this.__lastRemainData) {
9330
+ var lastRemainDataEnd = this.__lastRemainDataStart + this.__lastRemainData.byteLength;
9331
+ var continuous = partDataStart <= lastRemainDataEnd && partDataStart > this.__lastRemainDataStart && partDataStart + partData.byteLength > lastRemainDataEnd;
9332
+ if (continuous) {
9333
+ var noDuplicateData = partData.subarray(this.__lastRemainData.byteLength + this.__lastRemainDataStart - partDataStart);
9334
+ data = concatUint8Array(this.__lastRemainData, noDuplicateData);
9335
+ dataStart = this.__lastRemainDataStart;
9336
+ this.__lastRemainData = null;
9337
+ } else {
9338
+ this.__lastRemainData = null;
9339
+ this.__lastRemainDataStart = 0;
9340
+ this.__nextMoofStart = -1;
9341
+ }
9342
+ }
9343
+ if (!moov) {
9344
+ var moovBox = MP4Parser.findBox(data, ["moov"])[0];
9345
+ if (!moovBox)
9346
+ throw new Error("cannot found moov box");
9347
+ moov = MP4Parser.moov(moovBox);
9348
+ }
9349
+ if (data) {
9350
+ var dataEnd = dataStart + data.byteLength;
9351
+ if (!videoExist && !audioExist) {
9352
+ MP4Parser.moovToTrack(moov, videoTrack, audioTrack);
9353
+ }
9354
+ var moofBoxes = [];
9355
+ if (this.__nextMoofStart < 0) {
9356
+ MP4Parser.findBox(data, ["moof"], dataStart).forEach(function(v) {
9357
+ return moofBoxes.push(v);
9358
+ });
9359
+ } else if (this.__nextMoofStart >= dataStart && this.__nextMoofStart <= dataEnd - 8) {
9360
+ MP4Parser.findBox(data.subarray(this.__nextMoofStart - dataStart), ["moof"], this.__nextMoofStart).forEach(function(v) {
9361
+ return moofBoxes.push(v);
9362
+ });
9363
+ }
9364
+ moofBoxes.filter(function(moofBox) {
9365
+ return moofBox.size <= moofBox.data.length;
9366
+ }).forEach(function(moofBox) {
9367
+ var moof = MP4Parser.moof(moofBox);
9368
+ _this.__nextMoofStart = moof.start + Math.max.apply(Math, _toConsumableArray(moof.traf.map(function(v) {
9369
+ return v.trun.samples.reduce(function(ret, w) {
9370
+ return ret + w.size;
9371
+ }, v.trun.dataOffset || 0);
9372
+ })));
9373
+ _this.__loadedMoofWraps.push({
9374
+ start: moof.start,
9375
+ nextMoofStart: _this.__nextMoofStart,
9376
+ moof
9377
+ });
9378
+ _this.__loadedMoofWraps.sort(function(p, n) {
9379
+ return p.start - n.start;
9380
+ });
9381
+ });
9382
+ var _iterator = _createForOfIteratorHelper(this.__loadedMoofWraps), _step;
9383
+ try {
9384
+ var _loop = function _loop2() {
9385
+ var moofWrap = _step.value;
9386
+ if (moofWrap.start > dataEnd || moofWrap.nextMoofStart < dataStart) {
9387
+ return "continue";
9388
+ }
9389
+ var moofStart = moofWrap.start;
9390
+ var tracks = MP4Parser.moofToSamples(moofWrap.moof, videoTrack, audioTrack);
9391
+ var videoBaseMediaDecodeTime = videoTrack.baseMediaDecodeTime;
9392
+ var audioBaseMediaDecodeTime = audioTrack.baseMediaDecodeTime;
9393
+ var nalSize;
9394
+ Object.keys(tracks).forEach(function(k) {
9395
+ if (videoTrack.id == k) {
9396
+ tracks[k].some(function(x) {
9397
+ var xStart = x.offset += moofStart;
9398
+ if (xStart < dataStart) {
9399
+ return;
9400
+ }
9401
+ if (xStart + x.size > dataEnd) {
9402
+ return true;
9403
+ }
9404
+ var sample = new VideoSample((x.pts || x.dts) + videoBaseMediaDecodeTime, x.dts + videoBaseMediaDecodeTime);
9405
+ sample.duration = x.duration;
9406
+ sample.gopId = x.gopId;
9407
+ if (x.keyframe)
9408
+ sample.setToKeyframe();
9409
+ var sampleData = data.subarray(xStart - dataStart, xStart - dataStart + x.size);
9410
+ sample.data = sampleData;
9411
+ if (!isAV01) {
9412
+ var start = 0;
9413
+ var len = sampleData.length - 1;
9414
+ while (start < len) {
9415
+ nalSize = readBig32(sampleData, start);
9416
+ start += 4;
9417
+ sample.units.push(sampleData.subarray(start, start + nalSize));
9418
+ start += nalSize;
9419
+ }
9420
+ }
9421
+ _this.__lastRemainDataStart = xStart + x.size;
9422
+ videoTrack.samples.push(sample);
9423
+ });
9424
+ } else if (audioTrack.id == k) {
9425
+ tracks[k].some(function(x) {
9426
+ var xStart = x.offset + moofStart;
9427
+ if (xStart < dataStart) {
9428
+ return;
9429
+ }
9430
+ if (xStart + x.size > dataEnd) {
9431
+ return true;
9432
+ }
9433
+ var sampleData = data.subarray(xStart - dataStart, xStart - dataStart + x.size);
9434
+ audioTrack.samples.push(new AudioSample(x.dts + audioBaseMediaDecodeTime, sampleData, x.duration));
9435
+ _this.__lastRemainDataStart = xStart + x.size;
9436
+ });
9437
+ }
9438
+ });
9439
+ };
9440
+ for (_iterator.s(); !(_step = _iterator.n()).done; ) {
9441
+ var _ret = _loop();
9442
+ if (_ret === "continue")
9443
+ continue;
9444
+ }
9445
+ } catch (err) {
9446
+ _iterator.e(err);
9447
+ } finally {
9448
+ _iterator.f();
9449
+ }
9450
+ }
9451
+ if (this.__lastRemainDataStart > dataStart && this.__lastRemainDataStart < data.byteLength + dataStart) {
9452
+ this.__lastRemainData = data.subarray(this.__lastRemainDataStart - dataStart);
9453
+ } else {
9454
+ this.__lastRemainData = data;
9455
+ this.__lastRemainDataStart = dataStart;
9456
+ }
9457
+ if (videoTrack.samples.length) {
9458
+ videoTrack.baseMediaDecodeTime = videoTrack.samples[0].pts;
9459
+ }
9460
+ if (audioTrack.samples.length) {
9461
+ audioTrack.baseMediaDecodeTime = audioTrack.samples[0].pts;
9462
+ }
9463
+ return {
9464
+ videoTrack,
9465
+ audioTrack,
9466
+ metadataTrack: this.metadataTrack
9467
+ };
9468
+ }
9469
+ }, {
8974
9470
  key: "demux",
8975
9471
  value: function demux(videoData, audioData) {
8976
9472
  var videoTrack = this.videoTrack, audioTrack = this.audioTrack;
@@ -9089,13 +9585,13 @@ var Buffer = /* @__PURE__ */ function() {
9089
9585
  _createClass(Buffer2, [{
9090
9586
  key: "write",
9091
9587
  value: function write() {
9092
- var self = this;
9588
+ var self2 = this;
9093
9589
  for (var _len2 = arguments.length, buffer = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
9094
9590
  buffer[_key2] = arguments[_key2];
9095
9591
  }
9096
9592
  buffer.forEach(function(item) {
9097
9593
  if (item) {
9098
- self.buffer = Concat(Uint8Array, self.buffer, item);
9594
+ self2.buffer = Concat(Uint8Array, self2.buffer, item);
9099
9595
  } else {
9100
9596
  window.console.warn(item);
9101
9597
  }
@@ -9462,10 +9958,16 @@ var MP4 = /* @__PURE__ */ function() {
9462
9958
  if (track.useEME && track.enca) {
9463
9959
  content = MP42.enca(track);
9464
9960
  } else {
9465
- content = MP42.mp4a(track);
9961
+ if (track.codecType === AudioCodecType.OPUS) {
9962
+ content = MP42.opus(track);
9963
+ } else {
9964
+ content = MP42.mp4a(track);
9965
+ }
9466
9966
  }
9467
9967
  } else if (track.useEME && track.encv) {
9468
9968
  content = MP42.encv(track);
9969
+ } else if (track.av1C) {
9970
+ content = MP42.av01(track);
9469
9971
  } else {
9470
9972
  content = MP42.avc1hev1(track);
9471
9973
  }
@@ -9679,12 +10181,9 @@ var MP4 = /* @__PURE__ */ function() {
9679
10181
  return MP42.box(MP42.types.sinf, content, MP42.box(MP42.types.frma, frma), MP42.box(MP42.types.schm, schm), schi);
9680
10182
  }
9681
10183
  }, {
9682
- key: "avc1hev1",
9683
- value: function avc1hev1(track) {
9684
- var isHevc = track.codecType === VideoCodecType.HEVC;
9685
- var typ = isHevc ? MP42.types.hvc1 : MP42.types.avc1;
9686
- var config = isHevc ? MP42.hvcC(track) : MP42.avcC(track);
9687
- var boxes = [new Uint8Array([
10184
+ key: "av01",
10185
+ value: function av01(track) {
10186
+ return MP42.box(MP42.types.av01, new Uint8Array([
9688
10187
  0,
9689
10188
  0,
9690
10189
  0,
@@ -9763,48 +10262,135 @@ var MP4 = /* @__PURE__ */ function() {
9763
10262
  24,
9764
10263
  17,
9765
10264
  17
9766
- ]), config];
9767
- if (isHevc) {
9768
- boxes.push(MP42.box(MP42.types.fiel, new Uint8Array([1, 0])));
9769
- } else if (track.sarRatio && track.sarRatio.length > 1) {
9770
- boxes.push(MP42.pasp(track.sarRatio));
9771
- }
9772
- return MP42.box.apply(MP42, [typ].concat(boxes));
10265
+ ]), track.av1C, track.colr);
9773
10266
  }
9774
10267
  }, {
9775
- key: "avcC",
9776
- value: function avcC(track) {
9777
- var _concat$concat2, _ref2;
9778
- var sps = [];
9779
- var pps = [];
9780
- var len;
9781
- track.sps.forEach(function(s) {
9782
- len = s.byteLength;
9783
- sps.push(len >>> 8 & 255);
9784
- sps.push(len & 255);
9785
- sps.push.apply(sps, _toConsumableArray(s));
9786
- });
9787
- track.pps.forEach(function(p) {
9788
- len = p.byteLength;
9789
- pps.push(len >>> 8 & 255);
9790
- pps.push(len & 255);
9791
- pps.push.apply(pps, _toConsumableArray(p));
9792
- });
9793
- return MP42.box(MP42.types.avcC, new Uint8Array((_concat$concat2 = (_ref2 = [
10268
+ key: "avc1hev1",
10269
+ value: function avc1hev1(track) {
10270
+ var isHevc = track.codecType === VideoCodecType.HEVC;
10271
+ var typ = isHevc ? MP42.types.hvc1 : MP42.types.avc1;
10272
+ var config = isHevc ? MP42.hvcC(track) : MP42.avcC(track);
10273
+ var boxes = [new Uint8Array([
10274
+ 0,
10275
+ 0,
10276
+ 0,
10277
+ 0,
10278
+ 0,
10279
+ 0,
10280
+ 0,
9794
10281
  1,
9795
- sps[3],
9796
- sps[4],
9797
- sps[5],
9798
- 252 | 3,
9799
- 224 | track.sps.length
9800
- ]).concat.apply(_ref2, sps).concat([track.pps.length])).concat.apply(_concat$concat2, pps)));
9801
- }
9802
- }, {
9803
- key: "hvcC",
9804
- value: function hvcC(track) {
9805
- var hvcC2 = track.hvcC;
9806
- if (hvcC2 instanceof ArrayBuffer || hvcC2 instanceof Uint8Array)
9807
- return hvcC2;
10282
+ 0,
10283
+ 0,
10284
+ 0,
10285
+ 0,
10286
+ 0,
10287
+ 0,
10288
+ 0,
10289
+ 0,
10290
+ 0,
10291
+ 0,
10292
+ 0,
10293
+ 0,
10294
+ 0,
10295
+ 0,
10296
+ 0,
10297
+ 0,
10298
+ track.width >> 8 & 255,
10299
+ track.width & 255,
10300
+ track.height >> 8 & 255,
10301
+ track.height & 255,
10302
+ 0,
10303
+ 72,
10304
+ 0,
10305
+ 0,
10306
+ 0,
10307
+ 72,
10308
+ 0,
10309
+ 0,
10310
+ 0,
10311
+ 0,
10312
+ 0,
10313
+ 0,
10314
+ 0,
10315
+ 1,
10316
+ 0,
10317
+ 0,
10318
+ 0,
10319
+ 0,
10320
+ 0,
10321
+ 0,
10322
+ 0,
10323
+ 0,
10324
+ 0,
10325
+ 0,
10326
+ 0,
10327
+ 0,
10328
+ 0,
10329
+ 0,
10330
+ 0,
10331
+ 0,
10332
+ 0,
10333
+ 0,
10334
+ 0,
10335
+ 0,
10336
+ 0,
10337
+ 0,
10338
+ 0,
10339
+ 0,
10340
+ 0,
10341
+ 0,
10342
+ 0,
10343
+ 0,
10344
+ 0,
10345
+ 0,
10346
+ 0,
10347
+ 0,
10348
+ 0,
10349
+ 24,
10350
+ 17,
10351
+ 17
10352
+ ]), config];
10353
+ if (isHevc) {
10354
+ boxes.push(MP42.box(MP42.types.fiel, new Uint8Array([1, 0])));
10355
+ } else if (track.sarRatio && track.sarRatio.length > 1) {
10356
+ boxes.push(MP42.pasp(track.sarRatio));
10357
+ }
10358
+ return MP42.box.apply(MP42, [typ].concat(boxes));
10359
+ }
10360
+ }, {
10361
+ key: "avcC",
10362
+ value: function avcC(track) {
10363
+ var _concat$concat2, _ref2;
10364
+ var sps = [];
10365
+ var pps = [];
10366
+ var len;
10367
+ track.sps.forEach(function(s) {
10368
+ len = s.byteLength;
10369
+ sps.push(len >>> 8 & 255);
10370
+ sps.push(len & 255);
10371
+ sps.push.apply(sps, _toConsumableArray(s));
10372
+ });
10373
+ track.pps.forEach(function(p) {
10374
+ len = p.byteLength;
10375
+ pps.push(len >>> 8 & 255);
10376
+ pps.push(len & 255);
10377
+ pps.push.apply(pps, _toConsumableArray(p));
10378
+ });
10379
+ return MP42.box(MP42.types.avcC, new Uint8Array((_concat$concat2 = (_ref2 = [
10380
+ 1,
10381
+ sps[3],
10382
+ sps[4],
10383
+ sps[5],
10384
+ 252 | 3,
10385
+ 224 | track.sps.length
10386
+ ]).concat.apply(_ref2, sps).concat([track.pps.length])).concat.apply(_concat$concat2, pps)));
10387
+ }
10388
+ }, {
10389
+ key: "hvcC",
10390
+ value: function hvcC(track) {
10391
+ var hvcC2 = track.hvcC;
10392
+ if (hvcC2 instanceof ArrayBuffer || hvcC2 instanceof Uint8Array)
10393
+ return hvcC2;
9808
10394
  var vps = track.vps, sps = track.sps, pps = track.pps;
9809
10395
  var data;
9810
10396
  if (hvcC2) {
@@ -10048,6 +10634,53 @@ var MP4 = /* @__PURE__ */ function() {
10048
10634
  )));
10049
10635
  return esds2;
10050
10636
  }
10637
+ }, {
10638
+ key: "opus",
10639
+ value: function opus(track) {
10640
+ var opusAudioDescription = new Uint8Array([
10641
+ 0,
10642
+ 0,
10643
+ 0,
10644
+ 0,
10645
+ 0,
10646
+ 0,
10647
+ 0,
10648
+ 1,
10649
+ 0,
10650
+ 0,
10651
+ 0,
10652
+ 0,
10653
+ 0,
10654
+ 0,
10655
+ 0,
10656
+ 0,
10657
+ 0,
10658
+ track.channelCount,
10659
+ 0,
10660
+ 16,
10661
+ 0,
10662
+ 0,
10663
+ 0,
10664
+ 0,
10665
+ track.sampleRate >> 8 & 255,
10666
+ track.sampleRate & 255,
10667
+ 0,
10668
+ 0
10669
+ ]);
10670
+ var opusSpecificConfig = track.config.length ? MP42.dOps(track) : [];
10671
+ return MP42.box(MP42.types.Opus, opusAudioDescription, opusSpecificConfig);
10672
+ }
10673
+ }, {
10674
+ key: "dOps",
10675
+ value: function dOps(track) {
10676
+ if (track.config) {
10677
+ track.config[4] = track.sampleRate >>> 24 & 255;
10678
+ track.config[5] = track.sampleRate >>> 16 & 255;
10679
+ track.config[6] = track.sampleRate >>> 8 & 255;
10680
+ track.config[7] = track.sampleRate & 255;
10681
+ return MP42.box(MP42.types.dOps, track.config);
10682
+ }
10683
+ }
10051
10684
  }, {
10052
10685
  key: "mvex",
10053
10686
  value: function mvex(tracks) {
@@ -10650,7 +11283,7 @@ var MP4 = /* @__PURE__ */ function() {
10650
11283
  }]);
10651
11284
  return MP42;
10652
11285
  }();
10653
- _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) {
11286
+ _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) {
10654
11287
  p[c] = [c.charCodeAt(0), c.charCodeAt(1), c.charCodeAt(2), c.charCodeAt(3)];
10655
11288
  return p;
10656
11289
  }, /* @__PURE__ */ Object.create(null)));
@@ -10985,30 +11618,46 @@ var FMP4Remuxer = /* @__PURE__ */ function() {
10985
11618
  };
10986
11619
  }
10987
11620
  var samples = track.samples;
11621
+ var isAV01 = /av01/.test(track.codec);
10988
11622
  var mdatSize = 0;
10989
- samples.forEach(function(s) {
10990
- mdatSize += s.units.reduce(function(t, c) {
10991
- return t + c.byteLength;
10992
- }, 0);
10993
- mdatSize += s.units.length * 4;
10994
- });
10995
- var mdata = new Uint8Array(mdatSize);
10996
- var mdatView = new DataView(mdata.buffer);
10997
- var _loop = function _loop2(_offset, _sample) {
10998
- _sample = samples[i];
10999
- var sampleSize = 0;
11000
- _sample.units.forEach(function(u) {
11001
- mdatView.setUint32(_offset, u.byteLength);
11002
- _offset += 4;
11003
- mdata.set(u, _offset);
11004
- _offset += u.byteLength;
11005
- sampleSize += 4 + u.byteLength;
11623
+ if (isAV01) {
11624
+ samples.forEach(function(s) {
11625
+ mdatSize += s.data.byteLength;
11006
11626
  });
11007
- _sample.size = sampleSize;
11008
- offset = _offset, sample = _sample;
11009
- };
11010
- for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
11011
- _loop(offset, sample);
11627
+ } else {
11628
+ samples.forEach(function(s) {
11629
+ mdatSize += s.units.reduce(function(t, c) {
11630
+ return t + c.byteLength;
11631
+ }, 0);
11632
+ mdatSize += s.units.length * 4;
11633
+ });
11634
+ }
11635
+ var mdata = new Uint8Array(mdatSize);
11636
+ if (isAV01) {
11637
+ for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
11638
+ sample = samples[i];
11639
+ mdata.set(sample.data, offset);
11640
+ sample.size = sample.data.byteLength;
11641
+ offset += sample.size;
11642
+ }
11643
+ } else {
11644
+ var mdatView = new DataView(mdata.buffer);
11645
+ var _loop = function _loop2(_offset2, _sample2) {
11646
+ _sample2 = samples[_i];
11647
+ var sampleSize = 0;
11648
+ _sample2.units.forEach(function(u) {
11649
+ mdatView.setUint32(_offset2, u.byteLength);
11650
+ _offset2 += 4;
11651
+ mdata.set(u, _offset2);
11652
+ _offset2 += u.byteLength;
11653
+ sampleSize += 4 + u.byteLength;
11654
+ });
11655
+ _sample2.size = sampleSize;
11656
+ _offset = _offset2, _sample = _sample2;
11657
+ };
11658
+ for (var _i = 0, _l = samples.length, _offset = 0, _sample; _i < _l; _i++) {
11659
+ _loop(_offset, _sample);
11660
+ }
11012
11661
  }
11013
11662
  var mdat = MP4.mdat(mdata);
11014
11663
  var moof = MP4.moof([track]);
@@ -11202,7 +11851,8 @@ var Transmuxer = /* @__PURE__ */ function() {
11202
11851
  timescale: audioTrack.timescale,
11203
11852
  firstDts: audioTrack.firstDts / videoTrack.timescale,
11204
11853
  firstPts: audioTrack.firstPts / videoTrack.timescale,
11205
- duration: audioTrack.samplesDuration / videoTrack.timescale
11854
+ duration: audioTrack.samplesDuration / videoTrack.timescale,
11855
+ container: audioTrack.container
11206
11856
  };
11207
11857
  var newId = "".concat(videoTrack.codec, "/").concat(videoTrack.width, "/").concat(videoTrack.height, "/").concat(audioTrack.codec, "/").concat(audioTrack.config);
11208
11858
  if (newId !== this._initSegmentId) {
@@ -11326,7 +11976,7 @@ var Transmuxer = /* @__PURE__ */ function() {
11326
11976
  }]);
11327
11977
  return Transmuxer2;
11328
11978
  }();
11329
- var _excluded = ["data"], _excluded2 = ["data"];
11979
+ var _excluded$1 = ["data"], _excluded2 = ["data"];
11330
11980
  var logger$2 = new Logger$2("BufferService");
11331
11981
  var BufferService = /* @__PURE__ */ function() {
11332
11982
  function BufferService2(hls) {
@@ -11492,7 +12142,8 @@ var BufferService = /* @__PURE__ */ function() {
11492
12142
  key: "appendBuffer",
11493
12143
  value: function() {
11494
12144
  var _appendBuffer = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee2(segment, audioSegment, videoChunk, audioChunk, discontinuity, contiguous, startTime) {
11495
- var p, needInit, _this$_transmuxer$tra, _this$_transmuxer$tra2, video, audio, isFirstAppend, mse, _p, videoData, videoRest, audioData, audioRest;
12145
+ var _this2 = this;
12146
+ var afterAppend, p, needInit, _this$_transmuxer$tra, _this$_transmuxer$tra2, video, audio, isFirstAppend, mse, _p, videoData, videoRest, audioData, audioRest;
11496
12147
  return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
11497
12148
  while (1)
11498
12149
  switch (_context2.prev = _context2.next) {
@@ -11503,8 +12154,18 @@ var BufferService = /* @__PURE__ */ function() {
11503
12154
  }
11504
12155
  return _context2.abrupt("return");
11505
12156
  case 2:
12157
+ afterAppend = function afterAppend2() {
12158
+ var _this2$hls;
12159
+ if ((_this2$hls = _this2.hls) !== null && _this2$hls !== void 0 && _this2$hls.emit) {
12160
+ var _this2$hls2;
12161
+ (_this2$hls2 = _this2.hls) === null || _this2$hls2 === void 0 ? void 0 : _this2$hls2.emit(EVENT.APPEND_BUFFER, {
12162
+ start: segment.start,
12163
+ end: segment.end
12164
+ });
12165
+ }
12166
+ };
11506
12167
  if (!this._directAppend) {
11507
- _context2.next = 7;
12168
+ _context2.next = 8;
11508
12169
  break;
11509
12170
  }
11510
12171
  p = [];
@@ -11512,8 +12173,8 @@ var BufferService = /* @__PURE__ */ function() {
11512
12173
  p.push(this._mse.append(MSE.VIDEO, videoChunk));
11513
12174
  if (audioChunk)
11514
12175
  p.push(this._mse.append(MSE.AUDIO, audioChunk));
11515
- return _context2.abrupt("return", Promise.all(p));
11516
- case 7:
12176
+ return _context2.abrupt("return", Promise.all(p).then(afterAppend));
12177
+ case 8:
11517
12178
  needInit = this._needInitSegment || discontinuity;
11518
12179
  _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];
11519
12180
  if (audioChunk && audioSegment) {
@@ -11529,21 +12190,22 @@ var BufferService = /* @__PURE__ */ function() {
11529
12190
  this.hls.emit(Event$1.NO_AUDIO_TRACK);
11530
12191
  }
11531
12192
  if (!this._softVideo) {
11532
- _context2.next = 18;
12193
+ _context2.next = 20;
11533
12194
  break;
11534
12195
  }
11535
12196
  this._softVideo.appendBuffer(video, audio);
11536
12197
  this._needInitSegment = false;
11537
- _context2.next = 28;
12198
+ afterAppend();
12199
+ _context2.next = 30;
11538
12200
  break;
11539
- case 18:
12201
+ case 20:
11540
12202
  if (!this._mse) {
11541
- _context2.next = 28;
12203
+ _context2.next = 30;
11542
12204
  break;
11543
12205
  }
11544
12206
  isFirstAppend = !this._sourceCreated;
11545
12207
  if (isFirstAppend) {
11546
- this._createMseSource(video === null || video === void 0 ? void 0 : video.codec, audio === null || audio === void 0 ? void 0 : audio.codec);
12208
+ 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);
11547
12209
  }
11548
12210
  this._needInitSegment = false;
11549
12211
  mse = this._mse;
@@ -11554,15 +12216,15 @@ var BufferService = /* @__PURE__ */ function() {
11554
12216
  });
11555
12217
  }
11556
12218
  if (video) {
11557
- videoData = video.data, videoRest = _objectWithoutProperties$1(video, _excluded);
12219
+ videoData = video.data, videoRest = _objectWithoutProperties$1(video, _excluded$1);
11558
12220
  _p.push(mse.append(MSE.VIDEO, videoData, videoRest));
11559
12221
  }
11560
12222
  if (audio) {
11561
12223
  audioData = audio.data, audioRest = _objectWithoutProperties$1(audio, _excluded2);
11562
12224
  _p.push(mse.append(MSE.AUDIO, audioData, audioRest));
11563
12225
  }
11564
- return _context2.abrupt("return", Promise.all(_p));
11565
- case 28:
12226
+ return _context2.abrupt("return", Promise.all(_p).then(afterAppend));
12227
+ case 30:
11566
12228
  case "end":
11567
12229
  return _context2.stop();
11568
12230
  }
@@ -11577,7 +12239,7 @@ var BufferService = /* @__PURE__ */ function() {
11577
12239
  key: "removeBuffer",
11578
12240
  value: function() {
11579
12241
  var _removeBuffer = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee3() {
11580
- var _this2 = this;
12242
+ var _this3 = this;
11581
12243
  var start, end, media, _args3 = arguments;
11582
12244
  return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
11583
12245
  while (1)
@@ -11593,7 +12255,7 @@ var BufferService = /* @__PURE__ */ function() {
11593
12255
  return _context3.abrupt("return");
11594
12256
  case 5:
11595
12257
  return _context3.abrupt("return", this._mse.clearBuffer(start, end).then(function() {
11596
- return _this2.hls.emit(EVENT.REMOVE_BUFFER, {
12258
+ return _this3.hls.emit(EVENT.REMOVE_BUFFER, {
11597
12259
  start,
11598
12260
  end,
11599
12261
  removeEnd: end
@@ -11774,30 +12436,51 @@ var BufferService = /* @__PURE__ */ function() {
11774
12436
  return setLiveSeekableRange;
11775
12437
  }()
11776
12438
  }, {
11777
- key: "destroy",
12439
+ key: "detachMedia",
11778
12440
  value: function() {
11779
- var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee9() {
11780
- var _this$_decryptor;
12441
+ var _detachMedia = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee9() {
11781
12442
  return _regeneratorRuntime$1().wrap(function _callee9$(_context9) {
11782
12443
  while (1)
11783
12444
  switch (_context9.prev = _context9.next) {
11784
12445
  case 0:
11785
- (_this$_decryptor = this._decryptor) === null || _this$_decryptor === void 0 ? void 0 : _this$_decryptor.destroy();
11786
12446
  if (!this._mse) {
11787
- _context9.next = 4;
12447
+ _context9.next = 3;
11788
12448
  break;
11789
12449
  }
11790
- _context9.next = 4;
12450
+ _context9.next = 3;
11791
12451
  return this._mse.unbindMedia();
11792
- case 4:
12452
+ case 3:
12453
+ case "end":
12454
+ return _context9.stop();
12455
+ }
12456
+ }, _callee9, this);
12457
+ }));
12458
+ function detachMedia() {
12459
+ return _detachMedia.apply(this, arguments);
12460
+ }
12461
+ return detachMedia;
12462
+ }()
12463
+ }, {
12464
+ key: "destroy",
12465
+ value: function() {
12466
+ var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee10() {
12467
+ var _this$_decryptor;
12468
+ return _regeneratorRuntime$1().wrap(function _callee10$(_context10) {
12469
+ while (1)
12470
+ switch (_context10.prev = _context10.next) {
12471
+ case 0:
12472
+ (_this$_decryptor = this._decryptor) === null || _this$_decryptor === void 0 ? void 0 : _this$_decryptor.destroy();
12473
+ _context10.next = 3;
12474
+ return this.detachMedia();
12475
+ case 3:
11793
12476
  this._decryptor = null;
11794
12477
  this._mse = null;
11795
12478
  this._softVideo = null;
11796
- case 7:
12479
+ case 6:
11797
12480
  case "end":
11798
- return _context9.stop();
12481
+ return _context10.stop();
11799
12482
  }
11800
- }, _callee9, this);
12483
+ }, _callee10, this);
11801
12484
  }));
11802
12485
  function destroy() {
11803
12486
  return _destroy.apply(this, arguments);
@@ -11806,7 +12489,7 @@ var BufferService = /* @__PURE__ */ function() {
11806
12489
  }()
11807
12490
  }, {
11808
12491
  key: "_createMseSource",
11809
- value: function _createMseSource(videoCodec, audioCodec) {
12492
+ value: function _createMseSource(videoCodec, audioCodec, container) {
11810
12493
  logger$2.debug("create mse source, videoCodec=".concat(videoCodec, ", audioCodec=").concat(audioCodec));
11811
12494
  var mse = this._mse;
11812
12495
  if (!mse)
@@ -11818,6 +12501,9 @@ var BufferService = /* @__PURE__ */ function() {
11818
12501
  if (audioCodec) {
11819
12502
  mse.createSource(MSE.AUDIO, "audio/mp4;codecs=".concat(audioCodec));
11820
12503
  this._sourceCreated = true;
12504
+ } else if (container) {
12505
+ mse.createSource(MSE.AUDIO, "".concat(container, ';codecs=""'));
12506
+ this._sourceCreated = true;
11821
12507
  }
11822
12508
  this.hls.emit(EVENT.SOURCEBUFFER_CREATED);
11823
12509
  }
@@ -12127,6 +12813,31 @@ var MediaSegmentKey = /* @__PURE__ */ function() {
12127
12813
  }]);
12128
12814
  return MediaSegmentKey2;
12129
12815
  }();
12816
+ var HlsUrlParameters = /* @__PURE__ */ function() {
12817
+ function HlsUrlParameters2(msn, part, skip) {
12818
+ _classCallCheck$3(this, HlsUrlParameters2);
12819
+ this.msn = msn;
12820
+ this.part = part;
12821
+ this.skip = skip;
12822
+ }
12823
+ _createClass$3(HlsUrlParameters2, [{
12824
+ key: "addDirectives",
12825
+ value: function addDirectives(uri) {
12826
+ var url = new self.URL(uri);
12827
+ if (this.msn !== void 0) {
12828
+ url.searchParams.set("_HLS_msn", this.msn.toString());
12829
+ }
12830
+ if (this.part) {
12831
+ url.searchParams.set("_HLS_part", this.part.toString());
12832
+ }
12833
+ if (this.skip) {
12834
+ url.searchParams.set("_HLS_skip", this.skip);
12835
+ }
12836
+ return url.href;
12837
+ }
12838
+ }]);
12839
+ return HlsUrlParameters2;
12840
+ }();
12130
12841
  var REGEXP_TAG = /^#(EXT[^:]*)(?::(.*))?$/;
12131
12842
  var REGEXP_ATTR = /([^=]+)=(?:"([^"]*)"|([^",]*))(?:,|$)/g;
12132
12843
  var REGEXP_ABSOLUTE_URL = /^(?:[a-zA-Z0-9+\-.]+:)?\/\//;
@@ -12365,7 +13076,7 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
12365
13076
  media.canBlockReload = _attr["CAN-BLOCK-RELOAD"] === "YES";
12366
13077
  media.partHoldBack = parseFloat(_attr["PART-HOLD-BACK"] || 0);
12367
13078
  media.canSkipUntil = parseFloat(_attr["CAN-SKIP-UNTIL"] || 0);
12368
- media.canSkipDateRanges = _attr["CAN-SKIP-DATERANGES"] === "YES";
13079
+ media.canSkipDateRanges = media.canSkipUntil > 0 && _attr["CAN-SKIP-DATERANGES"] === "YES";
12369
13080
  }
12370
13081
  break;
12371
13082
  case "ENDLIST":
@@ -12409,6 +13120,15 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
12409
13120
  }
12410
13121
  break;
12411
13122
  case "PRELOAD-HINT":
13123
+ {
13124
+ var _attr3 = parseAttr(data);
13125
+ media.preloadHint = _attr3;
13126
+ if (_attr3["TYPE"] === "PART" && _attr3["URI"]) {
13127
+ var tmp = _attr3["URI"].split(".ts")[0].split("-");
13128
+ media.nextSN = tmp[3];
13129
+ media.nextIndex = tmp[tmp.length - 1];
13130
+ }
13131
+ }
12412
13132
  break;
12413
13133
  case "PROGRAM-DATE-TIME":
12414
13134
  curSegment.dataTime = data;
@@ -12428,21 +13148,21 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
12428
13148
  break;
12429
13149
  case "KEY":
12430
13150
  {
12431
- var _attr3 = parseAttr(data);
12432
- if (_attr3.METHOD === "NONE") {
13151
+ var _attr4 = parseAttr(data);
13152
+ if (_attr4.METHOD === "NONE") {
12433
13153
  curKey = null;
12434
13154
  break;
12435
13155
  }
12436
13156
  curKey = new MediaSegmentKey();
12437
- curKey.method = _attr3.METHOD;
12438
- curKey.url = /^blob:/.test(_attr3.URI) ? _attr3.URI : getAbsoluteUrl(_attr3.URI, parentUrl);
12439
- curKey.keyFormat = _attr3.KEYFORMAT || "identity";
12440
- curKey.keyFormatVersions = _attr3.KEYFORMATVERSIONS;
13157
+ curKey.method = _attr4.METHOD;
13158
+ curKey.url = /^blob:/.test(_attr4.URI) ? _attr4.URI : getAbsoluteUrl(_attr4.URI, parentUrl);
13159
+ curKey.keyFormat = _attr4.KEYFORMAT || "identity";
13160
+ curKey.keyFormatVersions = _attr4.KEYFORMATVERSIONS;
12441
13161
  if (!curKey.isSupported()) {
12442
- throw new Error("encrypt ".concat(_attr3.METHOD, "/").concat(_attr3.KEYFORMAT, " is not supported"));
13162
+ throw new Error("encrypt ".concat(_attr4.METHOD, "/").concat(_attr4.KEYFORMAT, " is not supported"));
12443
13163
  }
12444
- if (_attr3.IV) {
12445
- var str = _attr3.IV.slice(2);
13164
+ if (_attr4.IV) {
13165
+ var str = _attr4.IV.slice(2);
12446
13166
  str = (str.length & 1 ? "0" : "") + str;
12447
13167
  curKey.iv = new Uint8Array(str.length / 2);
12448
13168
  for (var i = 0, l = str.length / 2; i < l; i++) {
@@ -12453,10 +13173,10 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
12453
13173
  break;
12454
13174
  case "MAP":
12455
13175
  {
12456
- var _attr4 = parseAttr(data);
12457
- curSegment.url = getAbsoluteUrl(_attr4.URI, parentUrl);
12458
- if (_attr4.BYTERANGE)
12459
- curSegment.setByteRange(_attr4.BYTERANGE);
13176
+ var _attr5 = parseAttr(data);
13177
+ curSegment.url = getAbsoluteUrl(_attr5.URI, parentUrl);
13178
+ if (_attr5.BYTERANGE)
13179
+ curSegment.setByteRange(_attr5.BYTERANGE);
12460
13180
  curSegment.isInitSegment = true;
12461
13181
  curSegment.sn = 0;
12462
13182
  if (curKey) {
@@ -12468,24 +13188,25 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
12468
13188
  break;
12469
13189
  case "SKIP":
12470
13190
  {
12471
- var _attr5 = parseAttr(data);
12472
- var skippedSegments = parseInt(_attr5["SKIPPED-SEGMENTS"], 10);
13191
+ var _attr6 = parseAttr(data);
13192
+ var skippedSegments = parseInt(_attr6["SKIPPED-SEGMENTS"], 10);
12473
13193
  if (skippedSegments <= Number.MAX_SAFE_INTEGER) {
12474
13194
  media.skippedSegments += skippedSegments;
13195
+ curSN += skippedSegments;
12475
13196
  }
12476
13197
  }
12477
13198
  break;
12478
13199
  case "DATERANGE":
12479
13200
  {
12480
- var _attr6 = parseAttr(data);
12481
- var dateRangeWithSameId = media.dateRanges[_attr6.ID];
12482
- _attr6._startDate = dateRangeWithSameId ? dateRangeWithSameId._startDate : new Date(_attr6["START-DATE"]);
12483
- var endDate = (dateRangeWithSameId === null || dateRangeWithSameId === void 0 ? void 0 : dateRangeWithSameId._endDate) || new Date(_attr6.END_DATE);
13201
+ var _attr7 = parseAttr(data);
13202
+ var dateRangeWithSameId = media.dateRanges[_attr7.ID];
13203
+ _attr7._startDate = dateRangeWithSameId ? dateRangeWithSameId._startDate : new Date(_attr7["START-DATE"]);
13204
+ var endDate = (dateRangeWithSameId === null || dateRangeWithSameId === void 0 ? void 0 : dateRangeWithSameId._endDate) || new Date(_attr7.END_DATE);
12484
13205
  if (Number.isFinite(endDate)) {
12485
- _attr6._endDate = endDate;
13206
+ _attr7._endDate = endDate;
12486
13207
  }
12487
- if (isValidDaterange(_attr6, dateRangeWithSameId) || media.skippedSegments) {
12488
- media.dateRanges[_attr6.ID] = _attr6;
13208
+ if (isValidDaterange(_attr7, dateRangeWithSameId) || media.skippedSegments) {
13209
+ media.dateRanges[_attr7.ID] = _attr7;
12489
13210
  }
12490
13211
  }
12491
13212
  break;
@@ -12682,6 +13403,13 @@ var ManifestLoader = /* @__PURE__ */ function() {
12682
13403
  playlist
12683
13404
  });
12684
13405
  } else {
13406
+ if (this._useLowLatency) {
13407
+ if (playlist.canBlockReload) {
13408
+ this.deliveryDirectives = new HlsUrlParameters(playlist.nextSN, playlist.nextIndex, "");
13409
+ } else {
13410
+ this.deliveryDirectives = null;
13411
+ }
13412
+ }
12685
13413
  this.hls.emit(Event$1.HLS_LEVEL_LOADED, {
12686
13414
  playlist
12687
13415
  });
@@ -12738,41 +13466,45 @@ var ManifestLoader = /* @__PURE__ */ function() {
12738
13466
  var retryCount = this.hls.config.pollRetryCount;
12739
13467
  var fn = /* @__PURE__ */ function() {
12740
13468
  var _ref2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee2() {
12741
- var res;
13469
+ var reqUrl, res;
12742
13470
  return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
12743
13471
  while (1)
12744
13472
  switch (_context2.prev = _context2.next) {
12745
13473
  case 0:
12746
13474
  clearTimeout(_this2._timer);
12747
- _context2.prev = 1;
12748
- _context2.next = 4;
12749
- return _this2.load(url, audioUrl, subtitleUrl);
12750
- case 4:
13475
+ reqUrl = url;
13476
+ _context2.prev = 2;
13477
+ if (_this2.deliveryDirectives) {
13478
+ reqUrl = _this2.deliveryDirectives.addDirectives(url);
13479
+ }
13480
+ _context2.next = 6;
13481
+ return _this2.load(reqUrl, audioUrl, subtitleUrl);
13482
+ case 6:
12751
13483
  res = _context2.sent;
12752
13484
  if (res[0]) {
12753
- _context2.next = 7;
13485
+ _context2.next = 9;
12754
13486
  break;
12755
13487
  }
12756
13488
  return _context2.abrupt("return");
12757
- case 7:
13489
+ case 9:
12758
13490
  retryCount = _this2.hls.config.pollRetryCount;
12759
13491
  cb(res[0], res[1], res[2]);
12760
- _context2.next = 15;
13492
+ _context2.next = 17;
12761
13493
  break;
12762
- case 11:
12763
- _context2.prev = 11;
12764
- _context2.t0 = _context2["catch"](1);
13494
+ case 13:
13495
+ _context2.prev = 13;
13496
+ _context2.t0 = _context2["catch"](2);
12765
13497
  retryCount--;
12766
13498
  if (retryCount <= 0) {
12767
13499
  errorCb(_context2.t0);
12768
13500
  }
12769
- case 15:
13501
+ case 17:
12770
13502
  _this2._timer = setTimeout(fn, time);
12771
- case 16:
13503
+ case 18:
12772
13504
  case "end":
12773
13505
  return _context2.stop();
12774
13506
  }
12775
- }, _callee2, null, [[1, 11]]);
13507
+ }, _callee2, null, [[2, 13]]);
12776
13508
  }));
12777
13509
  return function fn2() {
12778
13510
  return _ref2.apply(this, arguments);
@@ -13302,7 +14034,7 @@ var Playlist = /* @__PURE__ */ function() {
13302
14034
  }, {
13303
14035
  key: "clearOldSegment",
13304
14036
  value: function clearOldSegment() {
13305
- var maxPlaylistSize = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 50;
14037
+ var maxPlaylistSize = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.hls.config.maxPlaylistSize || 50;
13306
14038
  var stream = this.currentStream;
13307
14039
  if (!this.dvrWindow || !stream)
13308
14040
  return;
@@ -13813,7 +14545,6 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
13813
14545
  return;
13814
14546
  _this._startTick();
13815
14547
  var media = _this.media;
13816
- var buffered = Buffer$1.get(media);
13817
14548
  var segLoaderError = _this._segmentLoader.error;
13818
14549
  _this._onCheckQuotaExceeded();
13819
14550
  if (_this._isProcessQuotaExceeded) {
@@ -13830,7 +14561,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
13830
14561
  }
13831
14562
  return;
13832
14563
  }
13833
- if (Buffer$1.end(buffered) >= 0.1 && media.readyState) {
14564
+ if (media.readyState) {
13834
14565
  if (isMediaPlaying(media)) {
13835
14566
  _this._loadSegment();
13836
14567
  if (_this._gapService) {
@@ -13896,6 +14627,12 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
13896
14627
  var _this$_bufferService;
13897
14628
  return (_this$_bufferService = this._bufferService) === null || _this$_bufferService === void 0 ? void 0 : _this$_bufferService.baseDts;
13898
14629
  }
14630
+ }, {
14631
+ key: "abrSwitchPoint",
14632
+ get: function get() {
14633
+ var targetSeg = this._urlSwitching ? this._playlist.currentSegment : this._playlist.nextSegment;
14634
+ return targetSeg ? targetSeg.start + targetSeg.duration / 2 : null;
14635
+ }
13899
14636
  }, {
13900
14637
  key: "speedInfo",
13901
14638
  value: function speedInfo() {
@@ -13921,30 +14658,37 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
13921
14658
  }, {
13922
14659
  key: "load",
13923
14660
  value: function() {
13924
- var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee4(url) {
13925
- var reuseMse, _args4 = arguments;
14661
+ var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee4() {
14662
+ var url, options, reuseMse, _args4 = arguments;
13926
14663
  return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
13927
14664
  while (1)
13928
14665
  switch (_context4.prev = _context4.next) {
13929
14666
  case 0:
13930
- reuseMse = _args4.length > 1 && _args4[1] !== void 0 ? _args4[1] : false;
14667
+ url = _args4.length > 0 && _args4[0] !== void 0 ? _args4[0] : "";
14668
+ options = _args4.length > 1 && _args4[1] !== void 0 ? _args4[1] : {};
14669
+ reuseMse = typeof options === "boolean" ? options : !!(options !== null && options !== void 0 && options.reuseMse);
14670
+ if (_typeof$2(options) === "object" && options !== null && options !== void 0 && options.clearSwitchStatus) {
14671
+ this._urlSwitching = false;
14672
+ this._switchUrlOpts = null;
14673
+ this.config.startTime = void 0;
14674
+ }
13931
14675
  if (url)
13932
14676
  this.config.url = url;
13933
14677
  url = this.config.url;
13934
- _context4.next = 5;
14678
+ _context4.next = 8;
13935
14679
  return this._reset(reuseMse);
13936
- case 5:
13937
- _context4.next = 7;
14680
+ case 8:
14681
+ _context4.next = 10;
13938
14682
  return this._loadData(url);
13939
- case 7:
14683
+ case 10:
13940
14684
  this._startTick();
13941
- case 8:
14685
+ case 11:
13942
14686
  case "end":
13943
14687
  return _context4.stop();
13944
14688
  }
13945
14689
  }, _callee4, this);
13946
14690
  }));
13947
- function load(_x) {
14691
+ function load() {
13948
14692
  return _load.apply(this, arguments);
13949
14693
  }
13950
14694
  return load;
@@ -13953,7 +14697,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
13953
14697
  key: "_loadData",
13954
14698
  value: function() {
13955
14699
  var _loadData2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee5(url) {
13956
- var manifest, currentStream, _this$_switchUrlOpts, _this$_switchUrlOpts2, switchTimePoint, segIdx, nextSeg, bufferClearStartPoint, preIndex, startTime, _this$_switchUrlOpts3;
14700
+ var manifest, currentStream, preIndex, _this$_switchUrlOpts, _this$_switchUrlOpts3, _this$_switchUrlOpts4, _this$_switchUrlOpts2, switchTimePoint, segIdx, nextSeg, bufferClearStartPoint, startTime, _this$_switchUrlOpts5;
13957
14701
  return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
13958
14702
  while (1)
13959
14703
  switch (_context5.prev = _context5.next) {
@@ -13974,41 +14718,46 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
13974
14718
  case 5:
13975
14719
  manifest = _context5.sent;
13976
14720
  currentStream = this._playlist.currentStream;
13977
- if (!(this._urlSwitching && !this.isLive)) {
13978
- _context5.next = 17;
14721
+ if (!this._urlSwitching) {
14722
+ _context5.next = 23;
13979
14723
  break;
13980
14724
  }
14725
+ if (!this.isLive) {
14726
+ _context5.next = 14;
14727
+ break;
14728
+ }
14729
+ preIndex = this._playlist.setNextSegmentBySN(this._prevSegSn);
14730
+ logger.log("segment nb=".concat(this._prevSegSn, " index of ").concat(preIndex, " in the new playlist"));
14731
+ if (preIndex === -1) {
14732
+ this._prevSegCc = null;
14733
+ this._prevSegSn = null;
14734
+ }
14735
+ _context5.next = 23;
14736
+ break;
14737
+ case 14:
13981
14738
  if (currentStream.bitrate === 0 && (_this$_switchUrlOpts = this._switchUrlOpts) !== null && _this$_switchUrlOpts !== void 0 && _this$_switchUrlOpts.bitrate) {
13982
14739
  currentStream.bitrate = (_this$_switchUrlOpts2 = this._switchUrlOpts) === null || _this$_switchUrlOpts2 === void 0 ? void 0 : _this$_switchUrlOpts2.bitrate;
13983
14740
  }
13984
- switchTimePoint = this._getSeamlessSwitchPoint();
14741
+ 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();
13985
14742
  this.config.startTime = switchTimePoint;
13986
14743
  segIdx = this._playlist.findSegmentIndexByTime(switchTimePoint);
13987
14744
  nextSeg = this._playlist.getSegmentByIndex(segIdx + 1);
13988
14745
  if (!nextSeg) {
13989
- _context5.next = 17;
14746
+ _context5.next = 23;
13990
14747
  break;
13991
14748
  }
13992
14749
  bufferClearStartPoint = nextSeg.start;
13993
- _context5.next = 17;
14750
+ _context5.next = 23;
13994
14751
  return this._bufferService.removeBuffer(bufferClearStartPoint);
13995
- case 17:
13996
- if (this._urlSwitching && this.isLive) {
13997
- preIndex = this._playlist.setNextSegmentBySN(this._prevSegSn);
13998
- logger.log("segment nb=".concat(this._prevSegSn, " index of ").concat(preIndex, " in the new playlist"));
13999
- if (preIndex === -1) {
14000
- this._prevSegCc = null;
14001
- this._prevSegSn = null;
14002
- }
14003
- }
14752
+ case 23:
14004
14753
  if (manifest) {
14005
- _context5.next = 20;
14754
+ _context5.next = 25;
14006
14755
  break;
14007
14756
  }
14008
14757
  return _context5.abrupt("return");
14009
- case 20:
14758
+ case 25:
14010
14759
  if (!this.isLive) {
14011
- _context5.next = 31;
14760
+ _context5.next = 36;
14012
14761
  break;
14013
14762
  }
14014
14763
  this._bufferService.setLiveSeekableRange(0, 4294967295);
@@ -14021,35 +14770,35 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14021
14770
  if (!manifest.isMaster)
14022
14771
  this._pollM3U8(url);
14023
14772
  if (!(this._playlist.nbSegments < this.config.minSegmentsStartPlay)) {
14024
- _context5.next = 28;
14773
+ _context5.next = 33;
14025
14774
  break;
14026
14775
  }
14027
14776
  return _context5.abrupt("return");
14028
- case 28:
14029
- _context5.next = 30;
14777
+ case 33:
14778
+ _context5.next = 35;
14030
14779
  return this._loadSegment();
14031
- case 30:
14780
+ case 35:
14032
14781
  return _context5.abrupt("return");
14033
- case 31:
14034
- _context5.next = 33;
14782
+ case 36:
14783
+ _context5.next = 38;
14035
14784
  return this._bufferService.updateDuration(currentStream.totalDuration);
14036
- case 33:
14785
+ case 38:
14037
14786
  startTime = this.config.startTime;
14038
14787
  if (startTime) {
14039
- if (!((_this$_switchUrlOpts3 = this._switchUrlOpts) !== null && _this$_switchUrlOpts3 !== void 0 && _this$_switchUrlOpts3.seamless)) {
14788
+ if (!((_this$_switchUrlOpts5 = this._switchUrlOpts) !== null && _this$_switchUrlOpts5 !== void 0 && _this$_switchUrlOpts5.seamless)) {
14040
14789
  this.media.currentTime = startTime;
14041
14790
  }
14042
14791
  this._playlist.setNextSegmentByIndex(this._playlist.findSegmentIndexByTime(startTime) || 0);
14043
14792
  }
14044
- _context5.next = 37;
14793
+ _context5.next = 42;
14045
14794
  return this._loadSegment();
14046
- case 37:
14795
+ case 42:
14047
14796
  case "end":
14048
14797
  return _context5.stop();
14049
14798
  }
14050
14799
  }, _callee5, this);
14051
14800
  }));
14052
- function _loadData(_x2) {
14801
+ function _loadData(_x) {
14053
14802
  return _loadData2.apply(this, arguments);
14054
14803
  }
14055
14804
  return _loadData;
@@ -14063,18 +14812,20 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14063
14812
  switch (_context6.prev = _context6.next) {
14064
14813
  case 0:
14065
14814
  this.config.startTime = 0;
14066
- _context6.next = 3;
14815
+ this._urlSwitching = false;
14816
+ this._switchUrlOpts = null;
14817
+ _context6.next = 5;
14067
14818
  return this.load();
14068
- case 3:
14819
+ case 5:
14069
14820
  this._reloadOnPlay = false;
14070
14821
  return _context6.abrupt("return", this.media.play(!isPlayEmit));
14071
- case 5:
14822
+ case 7:
14072
14823
  case "end":
14073
14824
  return _context6.stop();
14074
14825
  }
14075
14826
  }, _callee6, this);
14076
14827
  }));
14077
- function replay(_x3) {
14828
+ function replay(_x2) {
14078
14829
  return _replay.apply(this, arguments);
14079
14830
  }
14080
14831
  return replay;
@@ -14179,7 +14930,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14179
14930
  }
14180
14931
  }, _callee7, this, [[18, 29]]);
14181
14932
  }));
14182
- function switchURL(_x4) {
14933
+ function switchURL(_x3) {
14183
14934
  return _switchURL.apply(this, arguments);
14184
14935
  }
14185
14936
  return switchURL;
@@ -14265,7 +15016,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14265
15016
  }
14266
15017
  }, _callee8, this, [[8, 16], [21, 31]]);
14267
15018
  }));
14268
- function switchStream(_x5) {
15019
+ function switchStream(_x4) {
14269
15020
  return _switchStream.apply(this, arguments);
14270
15021
  }
14271
15022
  return switchStream;
@@ -14351,7 +15102,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14351
15102
  }
14352
15103
  }, _callee9, this, [[10, 18], [22, 32]]);
14353
15104
  }));
14354
- function switchAudioStream(_x6) {
15105
+ function switchAudioStream(_x5) {
14355
15106
  return _switchAudioStream.apply(this, arguments);
14356
15107
  }
14357
15108
  return switchAudioStream;
@@ -14376,25 +15127,50 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14376
15127
  }
14377
15128
  }, _callee10, this);
14378
15129
  }));
14379
- function switchSubtitleStream(_x7) {
15130
+ function switchSubtitleStream(_x6) {
14380
15131
  return _switchSubtitleStream.apply(this, arguments);
14381
15132
  }
14382
15133
  return switchSubtitleStream;
14383
15134
  }()
14384
15135
  }, {
14385
- key: "destroy",
15136
+ key: "detachMedia",
14386
15137
  value: function() {
14387
- var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee11() {
14388
- var _this$_seiService2;
15138
+ var _detachMedia = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee11() {
14389
15139
  return _regeneratorRuntime$1().wrap(function _callee11$(_context11) {
14390
15140
  while (1)
14391
15141
  switch (_context11.prev = _context11.next) {
15142
+ case 0:
15143
+ if (!this._bufferService) {
15144
+ _context11.next = 3;
15145
+ break;
15146
+ }
15147
+ _context11.next = 3;
15148
+ return this._bufferService.detachMedia();
15149
+ case 3:
15150
+ case "end":
15151
+ return _context11.stop();
15152
+ }
15153
+ }, _callee11, this);
15154
+ }));
15155
+ function detachMedia() {
15156
+ return _detachMedia.apply(this, arguments);
15157
+ }
15158
+ return detachMedia;
15159
+ }()
15160
+ }, {
15161
+ key: "destroy",
15162
+ value: function() {
15163
+ var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee12() {
15164
+ var _this$_seiService2;
15165
+ return _regeneratorRuntime$1().wrap(function _callee12$(_context12) {
15166
+ while (1)
15167
+ switch (_context12.prev = _context12.next) {
14392
15168
  case 0:
14393
15169
  if (this.media) {
14394
- _context11.next = 2;
15170
+ _context12.next = 2;
14395
15171
  break;
14396
15172
  }
14397
- return _context11.abrupt("return");
15173
+ return _context12.abrupt("return");
14398
15174
  case 2:
14399
15175
  this.removeAllListeners();
14400
15176
  this._playlist.reset();
@@ -14405,15 +15181,15 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14405
15181
  this.media.removeEventListener("pause", this._onPause);
14406
15182
  this.media.removeEventListener("seeking", this._onSeeking);
14407
15183
  this.media.removeEventListener("timeupdate", this._onTimeupdate);
14408
- _context11.next = 13;
15184
+ _context12.next = 13;
14409
15185
  return Promise.all([this._clear(), this._bufferService.destroy()]);
14410
15186
  case 13:
14411
15187
  this.media = null;
14412
15188
  case 14:
14413
15189
  case "end":
14414
- return _context11.stop();
15190
+ return _context12.stop();
14415
15191
  }
14416
- }, _callee11, this);
15192
+ }, _callee12, this);
14417
15193
  }));
14418
15194
  function destroy() {
14419
15195
  return _destroy.apply(this, arguments);
@@ -14423,48 +15199,48 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14423
15199
  }, {
14424
15200
  key: "_loadM3U8",
14425
15201
  value: function() {
14426
- var _loadM3U = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee12(url) {
15202
+ var _loadM3U = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee13(url) {
14427
15203
  var playlist, _this$config$manifest, _this$config$manifest2, manifest, _ref4, _ref5, _this$_playlist$curre;
14428
- return _regeneratorRuntime$1().wrap(function _callee12$(_context12) {
15204
+ return _regeneratorRuntime$1().wrap(function _callee13$(_context13) {
14429
15205
  while (1)
14430
- switch (_context12.prev = _context12.next) {
15206
+ switch (_context13.prev = _context13.next) {
14431
15207
  case 0:
14432
- _context12.prev = 0;
15208
+ _context13.prev = 0;
14433
15209
  manifest = (_this$config$manifest = this.config.manifestList) === null || _this$config$manifest === void 0 ? void 0 : (_this$config$manifest2 = _this$config$manifest.filter(function(x) {
14434
15210
  return x.url === url;
14435
15211
  })[0]) === null || _this$config$manifest2 === void 0 ? void 0 : _this$config$manifest2.manifest;
14436
15212
  if (!manifest) {
14437
- _context12.next = 6;
15213
+ _context13.next = 6;
14438
15214
  break;
14439
15215
  }
14440
- _context12.t0 = this._manifestLoader.parseText(manifest, url);
14441
- _context12.next = 9;
15216
+ _context13.t0 = this._manifestLoader.parseText(manifest, url);
15217
+ _context13.next = 9;
14442
15218
  break;
14443
15219
  case 6:
14444
- _context12.next = 8;
15220
+ _context13.next = 8;
14445
15221
  return this._manifestLoader.load(url);
14446
15222
  case 8:
14447
- _context12.t0 = _context12.sent;
15223
+ _context13.t0 = _context13.sent;
14448
15224
  case 9:
14449
- _ref4 = _context12.t0;
15225
+ _ref4 = _context13.t0;
14450
15226
  _ref5 = _slicedToArray$1(_ref4, 1);
14451
15227
  playlist = _ref5[0];
14452
- _context12.next = 17;
15228
+ _context13.next = 17;
14453
15229
  break;
14454
15230
  case 14:
14455
- _context12.prev = 14;
14456
- _context12.t1 = _context12["catch"](0);
14457
- throw this._emitError(StreamingError.create(_context12.t1));
15231
+ _context13.prev = 14;
15232
+ _context13.t1 = _context13["catch"](0);
15233
+ throw this._emitError(StreamingError.create(_context13.t1));
14458
15234
  case 17:
14459
15235
  if (playlist) {
14460
- _context12.next = 19;
15236
+ _context13.next = 19;
14461
15237
  break;
14462
15238
  }
14463
- return _context12.abrupt("return");
15239
+ return _context13.abrupt("return");
14464
15240
  case 19:
14465
15241
  this._playlist.upsertPlaylist(playlist);
14466
15242
  if (!playlist.isMaster) {
14467
- _context12.next = 24;
15243
+ _context13.next = 24;
14468
15244
  break;
14469
15245
  }
14470
15246
  if ((_this$_playlist$curre = this._playlist.currentStream.subtitleStreams) !== null && _this$_playlist$curre !== void 0 && _this$_playlist$curre.length) {
@@ -14472,18 +15248,18 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14472
15248
  list: this._playlist.currentStream.subtitleStreams
14473
15249
  });
14474
15250
  }
14475
- _context12.next = 24;
15251
+ _context13.next = 24;
14476
15252
  return this._refreshM3U8();
14477
15253
  case 24:
14478
15254
  this.emit(Event$1.STREAM_PARSED);
14479
- return _context12.abrupt("return", playlist);
15255
+ return _context13.abrupt("return", playlist);
14480
15256
  case 26:
14481
15257
  case "end":
14482
- return _context12.stop();
15258
+ return _context13.stop();
14483
15259
  }
14484
- }, _callee12, this, [[0, 14]]);
15260
+ }, _callee13, this, [[0, 14]]);
14485
15261
  }));
14486
- function _loadM3U8(_x8) {
15262
+ function _loadM3U8(_x7) {
14487
15263
  return _loadM3U.apply(this, arguments);
14488
15264
  }
14489
15265
  return _loadM3U8;
@@ -14517,7 +15293,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14517
15293
  var isEmpty = this._playlist.isEmpty;
14518
15294
  var pollInterval;
14519
15295
  if (this._playlist.lowLatency) {
14520
- pollInterval = (this._playlist.currentStream.partTargetDuration * 2 || 0) * 1e3;
15296
+ pollInterval = (this._playlist.currentStream.partTargetDuration || 0) * 1e3;
14521
15297
  } else {
14522
15298
  var _this$_playlist$lastS;
14523
15299
  pollInterval = (((_this$_playlist$lastS = this._playlist.lastSegment) === null || _this$_playlist$lastS === void 0 ? void 0 : _this$_playlist$lastS.duration) || 0) * 1e3;
@@ -14545,53 +15321,53 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14545
15321
  }, {
14546
15322
  key: "_loadSegmentDirect",
14547
15323
  value: function() {
14548
- var _loadSegmentDirect2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee13(loadOnce) {
15324
+ var _loadSegmentDirect2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee14(loadOnce) {
14549
15325
  var seg, appended, cachedError, _this$_playlist$curre2, bufferEnd, sameStream;
14550
- return _regeneratorRuntime$1().wrap(function _callee13$(_context13) {
15326
+ return _regeneratorRuntime$1().wrap(function _callee14$(_context14) {
14551
15327
  while (1)
14552
- switch (_context13.prev = _context13.next) {
15328
+ switch (_context14.prev = _context14.next) {
14553
15329
  case 0:
14554
15330
  seg = this._playlist.nextSegment;
14555
15331
  if (seg) {
14556
- _context13.next = 3;
15332
+ _context14.next = 3;
14557
15333
  break;
14558
15334
  }
14559
- return _context13.abrupt("return");
15335
+ return _context14.abrupt("return");
14560
15336
  case 3:
14561
15337
  appended = false;
14562
15338
  cachedError = null;
14563
- _context13.prev = 5;
15339
+ _context14.prev = 5;
14564
15340
  this._segmentProcessing = true;
14565
15341
  logger.log("load segment, sn:".concat(seg.sn, ", [").concat(seg.start, ", ").concat(seg.end, "], partIndex:").concat(seg.partIndex));
14566
- _context13.next = 10;
15342
+ _context14.next = 10;
14567
15343
  return this._reqAndBufferSegment(seg, this._playlist.getAudioSegment(seg));
14568
15344
  case 10:
14569
- appended = _context13.sent;
14570
- _context13.next = 16;
15345
+ appended = _context14.sent;
15346
+ _context14.next = 16;
14571
15347
  break;
14572
15348
  case 13:
14573
- _context13.prev = 13;
14574
- _context13.t0 = _context13["catch"](5);
14575
- cachedError = _context13.t0;
15349
+ _context14.prev = 13;
15350
+ _context14.t0 = _context14["catch"](5);
15351
+ cachedError = _context14.t0;
14576
15352
  case 16:
14577
- _context13.prev = 16;
15353
+ _context14.prev = 16;
14578
15354
  this._segmentProcessing = false;
14579
- return _context13.finish(16);
15355
+ return _context14.finish(16);
14580
15356
  case 19:
14581
15357
  if (!cachedError) {
14582
- _context13.next = 26;
15358
+ _context14.next = 26;
14583
15359
  break;
14584
15360
  }
14585
15361
  if (!this._bufferService.isFull()) {
14586
- _context13.next = 25;
15362
+ _context14.next = 25;
14587
15363
  break;
14588
15364
  }
14589
15365
  logger.log("load segment, sn:".concat(seg.sn, ", partIndex:").concat(seg.partIndex));
14590
15366
  this._segmentProcessing = true;
14591
15367
  this._isProcessQuotaExceeded = true;
14592
- return _context13.abrupt("return", false);
15368
+ return _context14.abrupt("return", false);
14593
15369
  case 25:
14594
- return _context13.abrupt("return", this._emitError(StreamingError.create(cachedError)));
15370
+ return _context14.abrupt("return", this._emitError(StreamingError.create(cachedError)));
14595
15371
  case 26:
14596
15372
  if (appended) {
14597
15373
  bufferEnd = this.bufferInfo().end;
@@ -14617,14 +15393,14 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14617
15393
  this._loadSegment();
14618
15394
  }
14619
15395
  }
14620
- return _context13.abrupt("return", appended);
15396
+ return _context14.abrupt("return", appended);
14621
15397
  case 28:
14622
15398
  case "end":
14623
- return _context13.stop();
15399
+ return _context14.stop();
14624
15400
  }
14625
- }, _callee13, this, [[5, 13, 16, 19]]);
15401
+ }, _callee14, this, [[5, 13, 16, 19]]);
14626
15402
  }));
14627
- function _loadSegmentDirect(_x9) {
15403
+ function _loadSegmentDirect(_x8) {
14628
15404
  return _loadSegmentDirect2.apply(this, arguments);
14629
15405
  }
14630
15406
  return _loadSegmentDirect;
@@ -14632,45 +15408,45 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14632
15408
  }, {
14633
15409
  key: "_reqAndBufferSegment",
14634
15410
  value: function() {
14635
- var _reqAndBufferSegment2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee14(seg, audioSeg) {
15411
+ var _reqAndBufferSegment2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee15(seg, audioSeg) {
14636
15412
  var _this$_bufferService2;
14637
15413
  var cc, discontinuity, responses, data, sn, start, stream, before, contiguous, segStart;
14638
- return _regeneratorRuntime$1().wrap(function _callee14$(_context14) {
15414
+ return _regeneratorRuntime$1().wrap(function _callee15$(_context15) {
14639
15415
  while (1)
14640
- switch (_context14.prev = _context14.next) {
15416
+ switch (_context15.prev = _context15.next) {
14641
15417
  case 0:
14642
15418
  cc = seg ? seg.cc : audioSeg.cc;
14643
15419
  discontinuity = this._prevSegCc !== cc;
14644
15420
  responses = [];
14645
- _context14.prev = 3;
14646
- _context14.next = 6;
15421
+ _context15.prev = 3;
15422
+ _context15.next = 6;
14647
15423
  return this._segmentLoader.load(seg, audioSeg, discontinuity);
14648
15424
  case 6:
14649
- responses = _context14.sent;
14650
- _context14.next = 14;
15425
+ responses = _context15.sent;
15426
+ _context15.next = 14;
14651
15427
  break;
14652
15428
  case 9:
14653
- _context14.prev = 9;
14654
- _context14.t0 = _context14["catch"](3);
14655
- _context14.t0.fatal = false;
14656
- this._segmentLoader.error = _context14.t0;
14657
- throw _context14.t0;
15429
+ _context15.prev = 9;
15430
+ _context15.t0 = _context15["catch"](3);
15431
+ _context15.t0.fatal = false;
15432
+ this._segmentLoader.error = _context15.t0;
15433
+ throw _context15.t0;
14658
15434
  case 14:
14659
15435
  if (responses[0]) {
14660
- _context14.next = 16;
15436
+ _context15.next = 16;
14661
15437
  break;
14662
15438
  }
14663
- return _context14.abrupt("return");
15439
+ return _context15.abrupt("return");
14664
15440
  case 16:
14665
- _context14.next = 18;
15441
+ _context15.next = 18;
14666
15442
  return (_this$_bufferService2 = this._bufferService).decryptBuffer.apply(_this$_bufferService2, _toConsumableArray$2(responses));
14667
15443
  case 18:
14668
- data = _context14.sent;
15444
+ data = _context15.sent;
14669
15445
  if (data) {
14670
- _context14.next = 21;
15446
+ _context15.next = 21;
14671
15447
  break;
14672
15448
  }
14673
- return _context14.abrupt("return");
15449
+ return _context15.abrupt("return");
14674
15450
  case 21:
14675
15451
  sn = seg ? seg.sn : audioSeg.sn;
14676
15452
  start = seg ? seg.start : audioSeg.start;
@@ -14684,26 +15460,26 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14684
15460
  logger.warn("update the new playlist liveEdge, segment id=".concat(sn, ", buffer start=").concat(segStart, ", liveEdge=").concat(this._playlist.liveEdge));
14685
15461
  start = segStart;
14686
15462
  }
14687
- _context14.next = 30;
15463
+ _context15.next = 30;
14688
15464
  return this._bufferService.appendBuffer(seg, audioSeg, data[0], data[1], discontinuity, contiguous, start);
14689
15465
  case 30:
14690
15466
  this.emit(Event$1.APPEND_COST, {
14691
15467
  elapsed: Date.now() - before,
14692
15468
  url: seg.url
14693
15469
  });
14694
- _context14.next = 33;
15470
+ _context15.next = 33;
14695
15471
  return this._bufferService.evictBuffer(this.config.bufferBehind);
14696
15472
  case 33:
14697
15473
  this._prevSegCc = cc;
14698
15474
  this._prevSegSn = sn;
14699
- return _context14.abrupt("return", true);
15475
+ return _context15.abrupt("return", true);
14700
15476
  case 36:
14701
15477
  case "end":
14702
- return _context14.stop();
15478
+ return _context15.stop();
14703
15479
  }
14704
- }, _callee14, this, [[3, 9]]);
15480
+ }, _callee15, this, [[3, 9]]);
14705
15481
  }));
14706
- function _reqAndBufferSegment(_x10, _x11) {
15482
+ function _reqAndBufferSegment(_x9, _x10) {
14707
15483
  return _reqAndBufferSegment2.apply(this, arguments);
14708
15484
  }
14709
15485
  return _reqAndBufferSegment;
@@ -14711,11 +15487,11 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14711
15487
  }, {
14712
15488
  key: "_onCheckQuotaExceeded",
14713
15489
  value: function() {
14714
- var _onCheckQuotaExceeded2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee15() {
15490
+ var _onCheckQuotaExceeded2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee16() {
14715
15491
  var seekTime, buffered, inBuffered, i, bufferBehind, mediaTime;
14716
- return _regeneratorRuntime$1().wrap(function _callee15$(_context15) {
15492
+ return _regeneratorRuntime$1().wrap(function _callee16$(_context16) {
14717
15493
  while (1)
14718
- switch (_context15.prev = _context15.next) {
15494
+ switch (_context16.prev = _context16.next) {
14719
15495
  case 0:
14720
15496
  seekTime = this.media.currentTime;
14721
15497
  buffered = this.media.buffered;
@@ -14723,37 +15499,37 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14723
15499
  i = 0;
14724
15500
  case 4:
14725
15501
  if (!(i < buffered.length)) {
14726
- _context15.next = 11;
15502
+ _context16.next = 11;
14727
15503
  break;
14728
15504
  }
14729
15505
  if (!(buffered.start(0) >= seekTime && seekTime < buffered.end(i))) {
14730
- _context15.next = 8;
15506
+ _context16.next = 8;
14731
15507
  break;
14732
15508
  }
14733
15509
  inBuffered = true;
14734
- return _context15.abrupt("break", 11);
15510
+ return _context16.abrupt("break", 11);
14735
15511
  case 8:
14736
15512
  i++;
14737
- _context15.next = 4;
15513
+ _context16.next = 4;
14738
15514
  break;
14739
15515
  case 11:
14740
15516
  if (!this._bufferService.isFull()) {
14741
- _context15.next = 17;
15517
+ _context16.next = 17;
14742
15518
  break;
14743
15519
  }
14744
15520
  bufferBehind = inBuffered ? this.config.bufferBehind : 5;
14745
15521
  mediaTime = this.media.currentTime;
14746
15522
  if (!(mediaTime - bufferBehind > 0)) {
14747
- _context15.next = 17;
15523
+ _context16.next = 17;
14748
15524
  break;
14749
15525
  }
14750
- _context15.next = 17;
15526
+ _context16.next = 17;
14751
15527
  return this._bufferService.removeBuffer(0, mediaTime - bufferBehind);
14752
15528
  case 17:
14753
15529
  case "end":
14754
- return _context15.stop();
15530
+ return _context16.stop();
14755
15531
  }
14756
- }, _callee15, this);
15532
+ }, _callee16, this);
14757
15533
  }));
14758
15534
  function _onCheckQuotaExceeded() {
14759
15535
  return _onCheckQuotaExceeded2.apply(this, arguments);
@@ -14771,22 +15547,22 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14771
15547
  }, {
14772
15548
  key: "_clear",
14773
15549
  value: function() {
14774
- var _clear2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee16() {
14775
- return _regeneratorRuntime$1().wrap(function _callee16$(_context16) {
15550
+ var _clear2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee17() {
15551
+ return _regeneratorRuntime$1().wrap(function _callee17$(_context17) {
14776
15552
  while (1)
14777
- switch (_context16.prev = _context16.next) {
15553
+ switch (_context17.prev = _context17.next) {
14778
15554
  case 0:
14779
15555
  clearTimeout(this._disconnectTimer);
14780
15556
  this._stopTick();
14781
- _context16.next = 4;
15557
+ _context17.next = 4;
14782
15558
  return Promise.all([this._segmentLoader.cancel(), this._manifestLoader.stopPoll()]);
14783
15559
  case 4:
14784
15560
  this._segmentProcessing = false;
14785
15561
  case 5:
14786
15562
  case "end":
14787
- return _context16.stop();
15563
+ return _context17.stop();
14788
15564
  }
14789
- }, _callee16, this);
15565
+ }, _callee17, this);
14790
15566
  }));
14791
15567
  function _clear() {
14792
15568
  return _clear2.apply(this, arguments);
@@ -14796,14 +15572,14 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14796
15572
  }, {
14797
15573
  key: "_reset",
14798
15574
  value: function() {
14799
- var _reset2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee17() {
15575
+ var _reset2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee18() {
14800
15576
  var _this$_seiService3;
14801
- var reuseMse, _args17 = arguments;
14802
- return _regeneratorRuntime$1().wrap(function _callee17$(_context17) {
15577
+ var reuseMse, _args18 = arguments;
15578
+ return _regeneratorRuntime$1().wrap(function _callee18$(_context18) {
14803
15579
  while (1)
14804
- switch (_context17.prev = _context17.next) {
15580
+ switch (_context18.prev = _context18.next) {
14805
15581
  case 0:
14806
- reuseMse = _args17.length > 0 && _args17[0] !== void 0 ? _args17[0] : false;
15582
+ reuseMse = _args18.length > 0 && _args18[0] !== void 0 ? _args18[0] : false;
14807
15583
  this._reloadOnPlay = false;
14808
15584
  this._prevSegSn = null;
14809
15585
  this._prevSegCc = null;
@@ -14812,15 +15588,15 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14812
15588
  this._segmentLoader.reset();
14813
15589
  (_this$_seiService3 = this._seiService) === null || _this$_seiService3 === void 0 ? void 0 : _this$_seiService3.reset();
14814
15590
  this._stats.reset();
14815
- _context17.next = 11;
15591
+ _context18.next = 11;
14816
15592
  return this._clear();
14817
15593
  case 11:
14818
- return _context17.abrupt("return", this._bufferService.reset(reuseMse));
15594
+ return _context18.abrupt("return", this._bufferService.reset(reuseMse));
14819
15595
  case 12:
14820
15596
  case "end":
14821
- return _context17.stop();
15597
+ return _context18.stop();
14822
15598
  }
14823
- }, _callee17, this);
15599
+ }, _callee18, this);
14824
15600
  }));
14825
15601
  function _reset() {
14826
15602
  return _reset2.apply(this, arguments);
@@ -14938,7 +15714,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
14938
15714
  }]);
14939
15715
  return Hls2;
14940
15716
  }(EventEmitter);
14941
- _defineProperty$3(Hls, "version", "3.0.20-alpha.2");
15717
+ _defineProperty$3(Hls, "version", "3.0.21-rc.5");
14942
15718
  try {
14943
15719
  if (localStorage.getItem("xgd")) {
14944
15720
  Hls.enableLogger();
@@ -15029,6 +15805,7 @@ var PluginExtension = /* @__PURE__ */ function() {
15029
15805
  }]);
15030
15806
  return PluginExtension2;
15031
15807
  }();
15808
+ var _excluded = ["currentTime"];
15032
15809
  function parseSwitchUrlArgs(args, plugin) {
15033
15810
  var player = plugin.player;
15034
15811
  var curTime = player.currentTime;
@@ -15039,9 +15816,14 @@ function parseSwitchUrlArgs(args, plugin) {
15039
15816
  case "boolean":
15040
15817
  options.seamless = args;
15041
15818
  break;
15042
- case "object":
15043
- Object.assign(options, args);
15819
+ case "object": {
15820
+ var currentTime = args.currentTime, rest = _objectWithoutProperties$1(args, _excluded);
15821
+ Object.assign(options, rest);
15822
+ if (typeof currentTime === "number") {
15823
+ options.startTime = currentTime;
15824
+ }
15044
15825
  break;
15826
+ }
15045
15827
  }
15046
15828
  return options;
15047
15829
  }
@@ -15051,10 +15833,11 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
15051
15833
  function HlsPlugin2() {
15052
15834
  var _this;
15053
15835
  _classCallCheck$3(this, HlsPlugin2);
15054
- for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
15055
- _args[_key] = arguments[_key];
15836
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
15837
+ args[_key] = arguments[_key];
15056
15838
  }
15057
- _this = _super.call.apply(_super, [this].concat(_args));
15839
+ _this = _super.call.apply(_super, [this].concat(args));
15840
+ _defineProperty$3(_assertThisInitialized$2(_this), "logger", logger);
15058
15841
  _defineProperty$3(_assertThisInitialized$2(_this), "hls", null);
15059
15842
  _defineProperty$3(_assertThisInitialized$2(_this), "pluginExtension", null);
15060
15843
  _defineProperty$3(_assertThisInitialized$2(_this), "getStats", function() {
@@ -15066,24 +15849,6 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
15066
15849
  var lang = _ref.lang;
15067
15850
  (_this$hls2 = _this.hls) === null || _this$hls2 === void 0 ? void 0 : _this$hls2.switchSubtitleStream(lang);
15068
15851
  });
15069
- _defineProperty$3(_assertThisInitialized$2(_this), "_onSwitchURL", function(url, args) {
15070
- return new Promise(function(resolve, reject) {
15071
- var _assertThisInitialize = _assertThisInitialized$2(_this), player = _assertThisInitialize.player, hls = _assertThisInitialize.hls;
15072
- if (hls) {
15073
- var _this$player$config, _this$player$config$h;
15074
- var options = parseSwitchUrlArgs(args, _assertThisInitialized$2(_this));
15075
- player.config.url = url;
15076
- hls.switchURL(url, options).then(function() {
15077
- return resolve(true);
15078
- }).catch(reject);
15079
- 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) {
15080
- _this._keepPauseStatus();
15081
- }
15082
- } else {
15083
- reject();
15084
- }
15085
- });
15086
- });
15087
15852
  _defineProperty$3(_assertThisInitialized$2(_this), "_keepPauseStatus", function() {
15088
15853
  var paused = _this.player.paused;
15089
15854
  if (!paused)
@@ -15108,8 +15873,8 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
15108
15873
  }, {
15109
15874
  key: "softDecode",
15110
15875
  get: function get() {
15111
- var _this$player, _this$player$config2;
15112
- 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;
15876
+ var _this$player, _this$player$config;
15877
+ 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;
15113
15878
  return !!mediaType && mediaType !== "video" && mediaType !== "audio";
15114
15879
  }
15115
15880
  }, {
@@ -15117,13 +15882,35 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
15117
15882
  value: function beforePlayerInit() {
15118
15883
  var _this2 = this;
15119
15884
  var config = this.player.config;
15885
+ var mediaElem = this.player.media || this.player.video;
15120
15886
  var hlsOpts = config.hls || {};
15121
15887
  if (!config.url && !config.__allowHlsEmptyUrl__ || !hlsOpts.preferMMS && MSE.isMMSOnly()) {
15122
15888
  return;
15123
15889
  }
15124
15890
  if (this.hls)
15125
15891
  this.hls.destroy();
15126
- this.player.switchURL = this._onSwitchURL;
15892
+ var descriptor = Object.getOwnPropertyDescriptor(this.player, "switchURL");
15893
+ if (!descriptor || descriptor.writable) {
15894
+ this.player.switchURL = function(url, args) {
15895
+ return new Promise(function(resolve, reject) {
15896
+ var player = _this2.player, hls = _this2.hls;
15897
+ if (hls) {
15898
+ var _this2$player$config, _this2$player$config$;
15899
+ var options = parseSwitchUrlArgs(args, _this2);
15900
+ player.config.url = url;
15901
+ hls.switchURL(url, options).then(function() {
15902
+ return resolve(true);
15903
+ }).catch(reject);
15904
+ 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) {
15905
+ _this2._keepPauseStatus();
15906
+ }
15907
+ } else {
15908
+ reject();
15909
+ }
15910
+ });
15911
+ };
15912
+ }
15913
+ var onSwitchUrl = this.player.switchURL;
15127
15914
  this.player.handleSource = false;
15128
15915
  hlsOpts.innerDegrade = hlsOpts.innerDegrade || config.innerDegrade;
15129
15916
  if (hlsOpts.disconnectTime === null || hlsOpts.disconnectTime === void 0)
@@ -15131,7 +15918,7 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
15131
15918
  this.hls = new Hls(_objectSpread2$2({
15132
15919
  softDecode: this.softDecode,
15133
15920
  isLive: config.isLive,
15134
- media: this.player.media || this.player.video,
15921
+ media: mediaElem,
15135
15922
  startTime: config.startTime,
15136
15923
  url: config.url
15137
15924
  }, hlsOpts));
@@ -15149,7 +15936,7 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
15149
15936
  if (this.softDecode) {
15150
15937
  this.pluginExtension = new PluginExtension(_objectSpread2$2({
15151
15938
  isLive: config.isLive,
15152
- media: this.player.video
15939
+ media: mediaElem
15153
15940
  }, hlsOpts), this);
15154
15941
  this.player.forceDegradeToVideo = function() {
15155
15942
  var _this2$pluginExtensio;
@@ -15166,8 +15953,8 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
15166
15953
  return (_this2$hls2 = _this2.hls) === null || _this2$hls2 === void 0 ? void 0 : _this2$hls2.replay();
15167
15954
  });
15168
15955
  }
15956
+ this.on(URL_CHANGE, onSwitchUrl);
15169
15957
  this.on(SWITCH_SUBTITLE, this._onSwitchSubtitle);
15170
- this.on(URL_CHANGE, this._onSwitchURL);
15171
15958
  this.on(DESTROY, this.destroy.bind(this));
15172
15959
  this._transError();
15173
15960
  this._transCoreEvent(EVENT.TTFB);
@@ -15177,6 +15964,7 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
15177
15964
  this._transCoreEvent(EVENT.LOAD_RETRY);
15178
15965
  this._transCoreEvent(EVENT.SOURCEBUFFER_CREATED);
15179
15966
  this._transCoreEvent(EVENT.MEDIASOURCE_OPENED);
15967
+ this._transCoreEvent(EVENT.APPEND_BUFFER);
15180
15968
  this._transCoreEvent(EVENT.REMOVE_BUFFER);
15181
15969
  this._transCoreEvent(EVENT.BUFFEREOS);
15182
15970
  this._transCoreEvent(EVENT.KEYFRAME);
@@ -15196,7 +15984,9 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
15196
15984
  this._transCoreEvent(Event$1.SUBTITLE_PLAYLIST);
15197
15985
  this._transCoreEvent(Event$1.APPEND_COST);
15198
15986
  if (config.url) {
15199
- this.hls.load(config.url, true).catch(function(e) {
15987
+ this.hls.load(config.url, {
15988
+ reuseMse: true
15989
+ }).catch(function(e) {
15200
15990
  });
15201
15991
  }
15202
15992
  }