@byteplus/veplayer-plugin 2.5.0-rc.1 → 2.6.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/esm/index.development.css +1 -1
  2. package/esm/index.development.js +1845 -530
  3. package/esm/index.production.css +1 -1
  4. package/esm/index.production.js +4 -4
  5. package/esm/veplayer.plugin.abr.development.js +12 -0
  6. package/esm/veplayer.plugin.abr.production.js +1 -1
  7. package/esm/veplayer.plugin.ad.development.css +1 -1
  8. package/esm/veplayer.plugin.ad.development.js +111 -39
  9. package/esm/veplayer.plugin.ad.production.css +1 -1
  10. package/esm/veplayer.plugin.ad.production.js +2 -2
  11. package/esm/veplayer.plugin.drm.development.js +12 -0
  12. package/esm/veplayer.plugin.drm.production.js +1 -1
  13. package/esm/veplayer.plugin.flv.development.js +670 -193
  14. package/esm/veplayer.plugin.flv.production.js +1 -1
  15. package/esm/veplayer.plugin.hls.development.js +1159 -369
  16. package/esm/veplayer.plugin.hls.production.js +1 -1
  17. package/esm/veplayer.plugin.mp4.development.js +13 -1
  18. package/esm/veplayer.plugin.mp4.production.js +1 -1
  19. package/esm/veplayer.plugin.rtm.development.js +13 -1
  20. package/esm/veplayer.plugin.rtm.production.js +1 -1
  21. package/esm/veplayer.plugin.shaka.development.js +12 -0
  22. package/esm/veplayer.plugin.shaka.production.js +1 -1
  23. package/package.json +1 -1
  24. package/umd/veplayer.plugin.abr.development.js +12 -0
  25. package/umd/veplayer.plugin.abr.production.js +1 -1
  26. package/umd/veplayer.plugin.ad.development.css +1 -1
  27. package/umd/veplayer.plugin.ad.development.js +111 -39
  28. package/umd/veplayer.plugin.ad.production.css +1 -1
  29. package/umd/veplayer.plugin.ad.production.js +1 -1
  30. package/umd/veplayer.plugin.drm.development.js +12 -0
  31. package/umd/veplayer.plugin.drm.production.js +1 -1
  32. package/umd/veplayer.plugin.flv.development.js +670 -193
  33. package/umd/veplayer.plugin.flv.production.js +1 -1
  34. package/umd/veplayer.plugin.hls.development.js +1126 -336
  35. package/umd/veplayer.plugin.hls.production.js +1 -1
  36. package/umd/veplayer.plugin.mp4.development.js +13 -1
  37. package/umd/veplayer.plugin.mp4.production.js +1 -1
  38. package/umd/veplayer.plugin.rtm.development.js +13 -1
  39. package/umd/veplayer.plugin.rtm.production.js +1 -1
  40. package/umd/veplayer.plugin.shaka.development.js +12 -0
  41. package/umd/veplayer.plugin.shaka.production.js +1 -1
@@ -1792,7 +1792,7 @@ var sniffer = {
1792
1792
  }
1793
1793
  }
1794
1794
  };
1795
- var version$4 = "3.0.20-alpha.4";
1795
+ var version$4 = "3.0.21-rc.3";
1796
1796
  var ERROR_MAP = {
1797
1797
  1: 5101,
1798
1798
  2: 5102,
@@ -2278,6 +2278,18 @@ var BasePlugin = /* @__PURE__ */ function() {
2278
2278
  }
2279
2279
  }
2280
2280
  }
2281
+ }, {
2282
+ key: "defineMethod",
2283
+ value: function defineMethod(Obj, map7) {
2284
+ for (var key2 in map7) {
2285
+ if (Object.prototype.hasOwnProperty.call(map7, key2) && typeof map7[key2] === "function") {
2286
+ Object.defineProperty(Obj, key2, {
2287
+ configurable: true,
2288
+ value: map7[key2]
2289
+ });
2290
+ }
2291
+ }
2292
+ }
2281
2293
  }, {
2282
2294
  key: "defaultConfig",
2283
2295
  get: function get3() {
@@ -4237,7 +4249,7 @@ var Fullscreen = /* @__PURE__ */ function(_IconPlugin) {
4237
4249
  }, {
4238
4250
  key: "toggleFullScreen",
4239
4251
  value: function toggleFullScreen(e) {
4240
- if (e) {
4252
+ if (e instanceof Event) {
4241
4253
  e.preventDefault();
4242
4254
  e.stopPropagation();
4243
4255
  }
@@ -5628,7 +5640,7 @@ function _arrayLikeToArray$e(arr, len) {
5628
5640
  arr2[i] = arr[i];
5629
5641
  return arr2;
5630
5642
  }
5631
- function _createForOfIteratorHelper$4(o, allowArrayLike) {
5643
+ function _createForOfIteratorHelper$5(o, allowArrayLike) {
5632
5644
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
5633
5645
  if (!it) {
5634
5646
  if (Array.isArray(o) || (it = _unsupportedIterableToArray$e(o)) || allowArrayLike && o && typeof o.length === "number") {
@@ -5816,6 +5828,21 @@ var Buffer$6 = /* @__PURE__ */ function() {
5816
5828
  length: Buffer22.totalLength && Buffer22.totalLength(buffers)
5817
5829
  };
5818
5830
  }
5831
+ }, {
5832
+ key: "isBuffered",
5833
+ value: function isBuffered(media, pos) {
5834
+ if (media) {
5835
+ var buffered = Buffer22.get(media);
5836
+ if (buffered !== null && buffered !== void 0 && buffered.length) {
5837
+ for (var i = 0; i < buffered.length; i++) {
5838
+ if (pos >= buffered.start(i) && pos <= buffered.end(i)) {
5839
+ return true;
5840
+ }
5841
+ }
5842
+ }
5843
+ }
5844
+ return false;
5845
+ }
5819
5846
  }]);
5820
5847
  return Buffer22;
5821
5848
  }();
@@ -5968,7 +5995,7 @@ var Logger$b = /* @__PURE__ */ function() {
5968
5995
  this.logCache.apply(this, [LogCacheLevel$3.DEBUG].concat(args));
5969
5996
  if (Logger2.disabled)
5970
5997
  return;
5971
- (_console = console).debug.apply(_console, [this._prefix, nowTime$8()].concat(args));
5998
+ (_console = console).debug.apply(_console, ["[".concat(nowTime$8(), "]"), this._prefix].concat(args));
5972
5999
  }
5973
6000
  }, {
5974
6001
  key: "log",
@@ -5980,7 +6007,7 @@ var Logger$b = /* @__PURE__ */ function() {
5980
6007
  this.logCache.apply(this, [LogCacheLevel$3.LOG].concat(args));
5981
6008
  if (Logger2.disabled)
5982
6009
  return;
5983
- (_console2 = console).log.apply(_console2, [this._prefix, nowTime$8()].concat(args));
6010
+ (_console2 = console).log.apply(_console2, ["[".concat(nowTime$8(), "]"), this._prefix].concat(args));
5984
6011
  }
5985
6012
  }, {
5986
6013
  key: "warn",
@@ -5992,7 +6019,7 @@ var Logger$b = /* @__PURE__ */ function() {
5992
6019
  this.logCache.apply(this, [LogCacheLevel$3.WARN].concat(args));
5993
6020
  if (Logger2.disabled)
5994
6021
  return;
5995
- (_console3 = console).warn.apply(_console3, [this._prefix, nowTime$8()].concat(args));
6022
+ (_console3 = console).warn.apply(_console3, ["[".concat(nowTime$8(), "]"), this._prefix].concat(args));
5996
6023
  }
5997
6024
  }, {
5998
6025
  key: "error",
@@ -6004,7 +6031,7 @@ var Logger$b = /* @__PURE__ */ function() {
6004
6031
  this.logCache.apply(this, [LogCacheLevel$3.ERROR].concat(args));
6005
6032
  if (Logger2.disabled)
6006
6033
  return;
6007
- (_console4 = console).error.apply(_console4, [this._prefix, nowTime$8()].concat(args));
6034
+ (_console4 = console).error.apply(_console4, ["[".concat(nowTime$8(), "]"), this._prefix].concat(args));
6008
6035
  }
6009
6036
  }, {
6010
6037
  key: "logCache",
@@ -6019,7 +6046,7 @@ var Logger$b = /* @__PURE__ */ function() {
6019
6046
  var finLogText = logText.map(function(item) {
6020
6047
  return logable$3(item);
6021
6048
  });
6022
- text = this._prefix + nowTime$8() + JSON.stringify(finLogText);
6049
+ text = "[".concat(nowTime$8(), "]") + this._prefix + JSON.stringify(finLogText);
6023
6050
  } catch (e) {
6024
6051
  return;
6025
6052
  }
@@ -6935,8 +6962,8 @@ function createResponse$3(data2, done, response, contentLength, age, startTime,
6935
6962
  response
6936
6963
  };
6937
6964
  }
6938
- function calculateSpeed$3(byteLen, millisec) {
6939
- return Math.round(byteLen * 8 * 1e3 / millisec / 1024);
6965
+ function calculateSpeed$3(byteLen, milliSecond) {
6966
+ return Math.round(byteLen * 8 * 1e3 / milliSecond / 1024);
6940
6967
  }
6941
6968
  var EVENT$3 = {
6942
6969
  ERROR: "error",
@@ -6948,6 +6975,7 @@ var EVENT$3 = {
6948
6975
  SOURCEBUFFER_CREATED: "core.sourcebuffercreated",
6949
6976
  MEDIASOURCE_OPENED: "core.mediasourceopened",
6950
6977
  ANALYZE_DURATION_EXCEEDED: "core.analyzedurationexceeded",
6978
+ APPEND_BUFFER: "core.appendbuffer",
6951
6979
  REMOVE_BUFFER: "core.removebuffer",
6952
6980
  BUFFEREOS: "core.buffereos",
6953
6981
  KEYFRAME: "core.keyframe",
@@ -7720,7 +7748,7 @@ var XhrLoader$3 = /* @__PURE__ */ function(_EventEmitter) {
7720
7748
  value: function _getHeaders(xhr) {
7721
7749
  var headerLines = xhr.getAllResponseHeaders().trim().split("\r\n");
7722
7750
  var headers = {};
7723
- var _iterator = _createForOfIteratorHelper$4(headerLines), _step;
7751
+ var _iterator = _createForOfIteratorHelper$5(headerLines), _step;
7724
7752
  try {
7725
7753
  for (_iterator.s(); !(_step = _iterator.n()).done; ) {
7726
7754
  var header = _step.value;
@@ -7742,7 +7770,7 @@ var XhrLoader$3 = /* @__PURE__ */ function(_EventEmitter) {
7742
7770
  }]);
7743
7771
  return XhrLoader2;
7744
7772
  }(EventEmitter$1);
7745
- var _excluded$5 = ["retry", "retryDelay", "onRetryError", "transformError"];
7773
+ var _excluded$6 = ["retry", "retryDelay", "onRetryError", "transformError"];
7746
7774
  var Task$3 = /* @__PURE__ */ function() {
7747
7775
  function Task2(type, config) {
7748
7776
  _classCallCheck$k(this, Task2);
@@ -7762,7 +7790,7 @@ var Task$3 = /* @__PURE__ */ function() {
7762
7790
  key: "exec",
7763
7791
  value: function exec2() {
7764
7792
  var _this = this;
7765
- var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties$5(_this$_config, _excluded$5);
7793
+ var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties$5(_this$_config, _excluded$6);
7766
7794
  var request = /* @__PURE__ */ function() {
7767
7795
  var _ref = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee() {
7768
7796
  var response, error, isRetry;
@@ -8580,13 +8608,16 @@ var TrackType$3 = {
8580
8608
  METADATA: "metadata"
8581
8609
  };
8582
8610
  var VideoCodecType$3 = {
8611
+ AV1: "av1",
8583
8612
  AVC: "avc",
8584
8613
  HEVC: "hevc"
8585
8614
  };
8586
8615
  var AudioCodecType$2 = {
8587
8616
  AAC: "aac",
8588
8617
  G711PCMA: "g7110a",
8589
- G711PCMU: "g7110m"
8618
+ G711PCMU: "g7110m",
8619
+ OPUS: "opus",
8620
+ MP3: "mp3"
8590
8621
  };
8591
8622
  var WarningType$1 = {
8592
8623
  LARGE_AV_SHIFT: "LARGE_AV_SHIFT",
@@ -8626,6 +8657,7 @@ var VideoTrack$2 = /* @__PURE__ */ function() {
8626
8657
  _defineProperty$h(this, "isVideoEncryption", false);
8627
8658
  _defineProperty$h(this, "isAudioEncryption", false);
8628
8659
  _defineProperty$h(this, "isVideo", true);
8660
+ _defineProperty$h(this, "lastKeyFrameDts", 0);
8629
8661
  _defineProperty$h(this, "kid", null);
8630
8662
  _defineProperty$h(this, "pssh", null);
8631
8663
  _defineProperty$h(this, "ext", void 0);
@@ -8668,6 +8700,9 @@ var VideoTrack$2 = /* @__PURE__ */ function() {
8668
8700
  }, {
8669
8701
  key: "exist",
8670
8702
  value: function exist() {
8703
+ if (/av01/.test(this.codec)) {
8704
+ return true;
8705
+ }
8671
8706
  return !!(this.pps.length && this.sps.length && this.codec);
8672
8707
  }
8673
8708
  }, {
@@ -8691,6 +8726,7 @@ var AudioTrack$2 = /* @__PURE__ */ function() {
8691
8726
  _defineProperty$h(this, "codecType", AudioCodecType$2.AAC);
8692
8727
  _defineProperty$h(this, "pid", -1);
8693
8728
  _defineProperty$h(this, "codec", "");
8729
+ _defineProperty$h(this, "container", "");
8694
8730
  _defineProperty$h(this, "sequenceNumber", 0);
8695
8731
  _defineProperty$h(this, "sampleDuration", 0);
8696
8732
  _defineProperty$h(this, "timescale", 0);
@@ -8731,7 +8767,7 @@ var AudioTrack$2 = /* @__PURE__ */ function() {
8731
8767
  }, {
8732
8768
  key: "exist",
8733
8769
  value: function exist() {
8734
- return !!(this.sampleRate && this.channelCount && this.codec && this.codecType === AudioCodecType$2.AAC);
8770
+ return !!(this.sampleRate && this.channelCount && (this.codec || this.container) && (this.codecType === AudioCodecType$2.AAC || this.codecType === AudioCodecType$2.G711PCMA || this.codecType === AudioCodecType$2.G711PCMU || this.codecType === AudioCodecType$2.OPUS || this.codecType === AudioCodecType$2.MP3));
8735
8771
  }
8736
8772
  }, {
8737
8773
  key: "hasSample",
@@ -8945,7 +8981,7 @@ var AAC$2 = /* @__PURE__ */ function() {
8945
8981
  continue;
8946
8982
  }
8947
8983
  frameLength = (data2[i + 3] & 3) << 11 | data2[i + 4] << 3 | (data2[i + 5] & 224) >> 5;
8948
- if (len - i < frameLength)
8984
+ if (!frameLength || len - i < frameLength)
8949
8985
  break;
8950
8986
  protectionSkipBytes = (~data2[i + 1] & 1) * 2;
8951
8987
  frames.push({
@@ -9079,14 +9115,57 @@ var AAC$2 = /* @__PURE__ */ function() {
9079
9115
  return AAC2;
9080
9116
  }();
9081
9117
  _defineProperty$h(AAC$2, "FREQ", [96e3, 88200, 64e3, 48e3, 44100, 32e3, 24e3, 22050, 16e3, 12e3, 11025, 8e3, 7350]);
9118
+ var OPUS = /* @__PURE__ */ function() {
9119
+ function OPUS2() {
9120
+ _classCallCheck$j(this, OPUS2);
9121
+ }
9122
+ _createClass$j(OPUS2, null, [{
9123
+ key: "getFrameDuration",
9124
+ value: function getFrameDuration(samples) {
9125
+ return 20;
9126
+ }
9127
+ }, {
9128
+ key: "parseHeaderPackets",
9129
+ value: function parseHeaderPackets(data2) {
9130
+ if (!data2.length)
9131
+ return;
9132
+ var dv = new DataView(data2.buffer, data2.byteOffset, data2.byteLength);
9133
+ var magicSignature = "";
9134
+ for (var i = 0; i < 8; i++) {
9135
+ magicSignature += String.fromCodePoint(data2[i]);
9136
+ }
9137
+ if (magicSignature !== "OpusHead") {
9138
+ throw new Error("Invalid Opus MagicSignature");
9139
+ }
9140
+ var channelCount = data2[9];
9141
+ console.log("Pre-skip", data2[10], data2[11]);
9142
+ var sampleRate = dv.getUint32(12, true);
9143
+ var outputGain = dv.getInt16(16, true);
9144
+ if (!sampleRate)
9145
+ return;
9146
+ var codec = "opus";
9147
+ var originCodec = "opus";
9148
+ var config = new Uint8Array(data2.buffer, data2.byteOffset + 8, data2.byteLength - 8);
9149
+ return {
9150
+ outputGain,
9151
+ sampleRate,
9152
+ channelCount,
9153
+ config,
9154
+ codec,
9155
+ originCodec
9156
+ };
9157
+ }
9158
+ }]);
9159
+ return OPUS2;
9160
+ }();
9082
9161
  var LARGE_AV_FIRST_FRAME_GAP$1 = 500;
9083
9162
  var AUDIO_GAP_OVERLAP_THRESHOLD_COUNT$1 = 3;
9084
9163
  var MAX_SILENT_FRAME_DURATION$1 = 1e3;
9085
- var AUDIO_EXCETION_LOG_EMIT_DURATION$1 = 5e3;
9164
+ var AUDIO_EXCEPTION_LOG_EMIT_DURATION = 5e3;
9086
9165
  var MAX_VIDEO_FRAME_DURATION$1 = 1e3;
9087
9166
  var MAX_DTS_DELTA_WITH_NEXT_CHUNK$1 = 200;
9088
- var VIDEO_EXCETION_LOG_EMIT_DURATION = 5e3;
9089
- var TRACK_BREACKED_CHECK_TIME = 5;
9167
+ var VIDEO_EXCEPTION_LOG_EMIT_DURATION = 5e3;
9168
+ var TRACK_BROKEN_CHECK_TIME = 5;
9090
9169
  var FlvFixer = /* @__PURE__ */ function() {
9091
9170
  function FlvFixer2(videoTrack, audioTrack, metadataTrack) {
9092
9171
  _classCallCheck$j(this, FlvFixer2);
@@ -9202,7 +9281,7 @@ var FlvFixer = /* @__PURE__ */ function() {
9202
9281
  var firstSample = samples[0];
9203
9282
  var vDelta = this._videoNextDts - firstSample.dts;
9204
9283
  if (Math.abs(vDelta) > MAX_DTS_DELTA_WITH_NEXT_CHUNK$1) {
9205
- if (Math.abs(firstSample.dts - this._lastVideoExceptionChunkFirstDtsDot) > VIDEO_EXCETION_LOG_EMIT_DURATION) {
9284
+ if (Math.abs(firstSample.dts - this._lastVideoExceptionChunkFirstDtsDot) > VIDEO_EXCEPTION_LOG_EMIT_DURATION) {
9206
9285
  var _samples$;
9207
9286
  this._lastVideoExceptionChunkFirstDtsDot = firstSample.dts;
9208
9287
  videoTrack.warnings.push({
@@ -9213,7 +9292,7 @@ var FlvFixer = /* @__PURE__ */ function() {
9213
9292
  sampleDuration: vDelta
9214
9293
  });
9215
9294
  }
9216
- if (this._videoTimestampBreak >= TRACK_BREACKED_CHECK_TIME) {
9295
+ if (this._videoTimestampBreak >= TRACK_BROKEN_CHECK_TIME) {
9217
9296
  this._videoNextDts = firstSample.dts;
9218
9297
  this._videoTimestampBreak = 0;
9219
9298
  } else {
@@ -9236,7 +9315,7 @@ var FlvFixer = /* @__PURE__ */ function() {
9236
9315
  }
9237
9316
  if (sampleDuration > MAX_VIDEO_FRAME_DURATION$1 || sampleDuration < 0) {
9238
9317
  this._videoTimestampBreak++;
9239
- if (Math.abs(dts - this._lastVideoExceptionLargeGapDot) > VIDEO_EXCETION_LOG_EMIT_DURATION) {
9318
+ if (Math.abs(dts - this._lastVideoExceptionLargeGapDot) > VIDEO_EXCEPTION_LOG_EMIT_DURATION) {
9240
9319
  this._lastVideoExceptionLargeGapDot = dts;
9241
9320
  videoTrack.warnings.push({
9242
9321
  type: WarningType$1.LARGE_VIDEO_GAP,
@@ -9317,10 +9396,27 @@ var FlvFixer = /* @__PURE__ */ function() {
9317
9396
  key: "_doFixAudioInternal",
9318
9397
  value: function _doFixAudioInternal(audioTrack, samples, timescale) {
9319
9398
  if (!audioTrack.sampleDuration) {
9320
- audioTrack.sampleDuration = audioTrack.codecType === AudioCodecType$2.AAC ? AAC$2.getFrameDuration(audioTrack.timescale, timescale) : this._getG711Duration(audioTrack);
9399
+ switch (audioTrack.codecType) {
9400
+ case AudioCodecType$2.AAC: {
9401
+ audioTrack.sampleDuration = AAC$2.getFrameDuration(audioTrack.timescale, timescale);
9402
+ break;
9403
+ }
9404
+ case AudioCodecType$2.OPUS: {
9405
+ audioTrack.sampleDuration = OPUS.getFrameDuration(audioTrack.samples, timescale);
9406
+ break;
9407
+ }
9408
+ case AudioCodecType$2.G711PCMA:
9409
+ case AudioCodecType$2.G711PCMU: {
9410
+ audioTrack.sampleDuration = this._getG711Duration(audioTrack);
9411
+ break;
9412
+ }
9413
+ default:
9414
+ console.error("can't fix audio codecType:", audioTrack.codecType);
9415
+ break;
9416
+ }
9321
9417
  }
9322
9418
  var refSampleDuration = audioTrack.sampleDuration;
9323
- var sampleDurationInSampleRate = audioTrack.codecType === AudioCodecType$2.AAC ? 1024 : refSampleDuration * audioTrack.timescale / 1e3;
9419
+ var sampleDurationInSampleRate = audioTrack.codecType === AudioCodecType$2.OPUS ? 20 : audioTrack.codecType === AudioCodecType$2.AAC ? 1024 : refSampleDuration * audioTrack.timescale / 1e3;
9324
9420
  if (this._audioNextPts === void 0) {
9325
9421
  var samp0 = samples[0];
9326
9422
  this._audioNextPts = samp0.pts;
@@ -9329,7 +9425,7 @@ var FlvFixer = /* @__PURE__ */ function() {
9329
9425
  var nextPts = this._audioNextPts;
9330
9426
  var sample = samples[i];
9331
9427
  var delta = sample.pts - nextPts;
9332
- if (i === 0 && this._audioTimestampBreak >= TRACK_BREACKED_CHECK_TIME && this._keyFrameInNextChunk) {
9428
+ if (i === 0 && this._audioTimestampBreak >= TRACK_BROKEN_CHECK_TIME && this._keyFrameInNextChunk) {
9333
9429
  nextPts = this._audioNextPts = sample.dts;
9334
9430
  delta = 0;
9335
9431
  this._audioTimestampBreak = 0;
@@ -9337,7 +9433,7 @@ var FlvFixer = /* @__PURE__ */ function() {
9337
9433
  if (!this._audioTimestampBreak && delta >= AUDIO_GAP_OVERLAP_THRESHOLD_COUNT$1 * refSampleDuration && delta <= MAX_SILENT_FRAME_DURATION$1 && !isSafari$1) {
9338
9434
  var silentFrame = this._getSilentFrame(audioTrack) || samples[0].data.subarray();
9339
9435
  var count = Math.floor(delta / refSampleDuration);
9340
- if (Math.abs(sample.pts - this._lastAudioExceptionGapDot) > AUDIO_EXCETION_LOG_EMIT_DURATION$1) {
9436
+ if (Math.abs(sample.pts - this._lastAudioExceptionGapDot) > AUDIO_EXCEPTION_LOG_EMIT_DURATION) {
9341
9437
  this._lastAudioExceptionGapDot = sample.pts;
9342
9438
  audioTrack.warnings.push({
9343
9439
  type: WarningType$1.AUDIO_FILLED,
@@ -9357,7 +9453,7 @@ var FlvFixer = /* @__PURE__ */ function() {
9357
9453
  }
9358
9454
  i--;
9359
9455
  } else if (delta <= -AUDIO_GAP_OVERLAP_THRESHOLD_COUNT$1 * refSampleDuration && delta >= -1 * MAX_SILENT_FRAME_DURATION$1) {
9360
- if (Math.abs(sample.pts - this._lastAudioExceptionOverlapDot) > AUDIO_EXCETION_LOG_EMIT_DURATION$1) {
9456
+ if (Math.abs(sample.pts - this._lastAudioExceptionOverlapDot) > AUDIO_EXCEPTION_LOG_EMIT_DURATION) {
9361
9457
  this._lastAudioExceptionOverlapDot = sample.pts;
9362
9458
  audioTrack.warnings.push({
9363
9459
  type: WarningType$1.AUDIO_DROPPED,
@@ -9372,7 +9468,7 @@ var FlvFixer = /* @__PURE__ */ function() {
9372
9468
  } else {
9373
9469
  if (Math.abs(delta) > MAX_SILENT_FRAME_DURATION$1) {
9374
9470
  this._audioTimestampBreak++;
9375
- if (Math.abs(sample.pts - this._lastAudioExceptionLargeGapDot) > AUDIO_EXCETION_LOG_EMIT_DURATION$1) {
9471
+ if (Math.abs(sample.pts - this._lastAudioExceptionLargeGapDot) > AUDIO_EXCEPTION_LOG_EMIT_DURATION) {
9376
9472
  this._lastAudioExceptionLargeGapDot = sample.pts;
9377
9473
  audioTrack.warnings.push({
9378
9474
  type: WarningType$1.LARGE_AUDIO_GAP,
@@ -9385,8 +9481,15 @@ var FlvFixer = /* @__PURE__ */ function() {
9385
9481
  });
9386
9482
  }
9387
9483
  }
9388
- sample.dts = sample.pts = nextPts;
9389
- sample.duration = sampleDurationInSampleRate;
9484
+ if (audioTrack.codecType === AudioCodecType$2.OPUS) {
9485
+ var lastSample = samples[samples.length - 1];
9486
+ if (lastSample) {
9487
+ lastSample.duration = sample.pts - lastSample.pts;
9488
+ }
9489
+ } else {
9490
+ sample.dts = sample.pts = nextPts;
9491
+ sample.duration = sampleDurationInSampleRate;
9492
+ }
9390
9493
  this._audioNextPts += refSampleDuration;
9391
9494
  }
9392
9495
  }
@@ -10345,6 +10448,13 @@ var AMF = /* @__PURE__ */ function() {
10345
10448
  }]);
10346
10449
  return AMF2;
10347
10450
  }();
10451
+ var FlvSoundFormat = {
10452
+ MP3: 2,
10453
+ G711A: 7,
10454
+ G711M: 8,
10455
+ AAC: 10,
10456
+ OPUS: 13
10457
+ };
10348
10458
  var logger$c = new Logger$a("FlvDemuxer");
10349
10459
  var FlvDemuxer = /* @__PURE__ */ function() {
10350
10460
  function FlvDemuxer2(videoTrack, audioTrack, metadataTrack) {
@@ -10361,8 +10471,10 @@ var FlvDemuxer = /* @__PURE__ */ function() {
10361
10471
  _createClass$j(FlvDemuxer2, [{
10362
10472
  key: "demux",
10363
10473
  value: function demux(data2) {
10474
+ var _scriptDataObject$dat;
10364
10475
  var discontinuity = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
10365
10476
  var contiguous = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
10477
+ var seamlessLoadingSwitching = arguments.length > 3 ? arguments[3] : void 0;
10366
10478
  var audioTrack = this.audioTrack, videoTrack = this.videoTrack, metadataTrack = this.metadataTrack;
10367
10479
  if (discontinuity || !contiguous) {
10368
10480
  this._remainingData = null;
@@ -10420,6 +10532,8 @@ var FlvDemuxer = /* @__PURE__ */ function() {
10420
10532
  if (tagType === 8) {
10421
10533
  this._parseAudio(bodyData, timestamp);
10422
10534
  } else if (tagType === 9) {
10535
+ if (seamlessLoadingSwitching)
10536
+ this.seamlessLoadingSwitching = true;
10423
10537
  this._parseVideo(bodyData, timestamp);
10424
10538
  } else if (tagType === 18) {
10425
10539
  this._parseScript(bodyData, timestamp);
@@ -10437,13 +10551,31 @@ var FlvDemuxer = /* @__PURE__ */ function() {
10437
10551
  this._remainingData = data2.subarray(offset);
10438
10552
  }
10439
10553
  audioTrack.formatTimescale = videoTrack.formatTimescale = videoTrack.timescale = metadataTrack.timescale = 1e3;
10440
- audioTrack.timescale = audioTrack.sampleRate || 0;
10554
+ audioTrack.timescale = audioTrack.codecType === AudioCodecType$2.OPUS ? 1e3 : audioTrack.sampleRate || 0;
10441
10555
  if (!audioTrack.exist() && audioTrack.hasSample()) {
10442
10556
  audioTrack.reset();
10443
10557
  }
10444
10558
  if (!videoTrack.exist() && videoTrack.hasSample()) {
10445
10559
  videoTrack.reset();
10446
10560
  }
10561
+ var scriptDataObject = metadataTrack.flvScriptSamples[metadataTrack.flvScriptSamples.length - 1];
10562
+ var metaData = scriptDataObject === null || scriptDataObject === void 0 ? void 0 : (_scriptDataObject$dat = scriptDataObject.data) === null || _scriptDataObject$dat === void 0 ? void 0 : _scriptDataObject$dat.onMetaData;
10563
+ if (metaData) {
10564
+ if (videoTrack !== null && videoTrack !== void 0 && videoTrack.exist()) {
10565
+ if (metaData.hasOwnProperty("duration")) {
10566
+ videoTrack.duration = metaData.duration * 1e3;
10567
+ }
10568
+ if (metaData.hasOwnProperty("width") && metaData.hasOwnProperty("height")) {
10569
+ videoTrack.width = metaData.width;
10570
+ videoTrack.height = metaData.height;
10571
+ }
10572
+ }
10573
+ if (audioTrack !== null && audioTrack !== void 0 && audioTrack.exist()) {
10574
+ if (metaData.hasOwnProperty("duration")) {
10575
+ audioTrack.duration = metaData.duration * 1e3;
10576
+ }
10577
+ }
10578
+ }
10447
10579
  return {
10448
10580
  videoTrack,
10449
10581
  audioTrack,
@@ -10462,8 +10594,8 @@ var FlvDemuxer = /* @__PURE__ */ function() {
10462
10594
  }
10463
10595
  }, {
10464
10596
  key: "demuxAndFix",
10465
- value: function demuxAndFix(data2, discontinuity, contiguous, startTime) {
10466
- this.demux(data2, discontinuity, contiguous);
10597
+ value: function demuxAndFix(data2, discontinuity, contiguous, startTime, seamlessLoadingSwitching) {
10598
+ this.demux(data2, discontinuity, contiguous, seamlessLoadingSwitching);
10467
10599
  return this.fix(startTime, discontinuity, contiguous);
10468
10600
  }
10469
10601
  }, {
@@ -10473,12 +10605,12 @@ var FlvDemuxer = /* @__PURE__ */ function() {
10473
10605
  return;
10474
10606
  var format2 = (data2[0] & 240) >>> 4;
10475
10607
  var track = this.audioTrack;
10476
- if (format2 !== 10 && format2 !== 7 && format2 !== 8) {
10608
+ if (format2 !== FlvSoundFormat.AAC && format2 !== FlvSoundFormat.G711A && format2 !== FlvSoundFormat.G711M && format2 !== FlvSoundFormat.OPUS) {
10477
10609
  logger$c.warn("Unsupported sound format: ".concat(format2));
10478
10610
  track.reset();
10479
10611
  return;
10480
10612
  }
10481
- if (format2 !== 10) {
10613
+ if (format2 !== FlvSoundFormat.AAC && format2 !== FlvSoundFormat.OPUS) {
10482
10614
  var soundRate = (data2[0] & 12) >> 2;
10483
10615
  var soundSize = (data2[0] & 2) >> 1;
10484
10616
  var soundType = data2[0] & 1;
@@ -10486,10 +10618,49 @@ var FlvDemuxer = /* @__PURE__ */ function() {
10486
10618
  track.sampleSize = soundSize ? 16 : 8;
10487
10619
  track.channelCount = soundType + 1;
10488
10620
  }
10489
- if (format2 === 10) {
10490
- this._parseAac(data2, pts);
10491
- } else {
10492
- this._parseG711(data2, pts, format2);
10621
+ switch (format2) {
10622
+ case FlvSoundFormat.G711A:
10623
+ case FlvSoundFormat.G711M:
10624
+ this._parseG711(data2, pts, format2);
10625
+ break;
10626
+ case FlvSoundFormat.AAC:
10627
+ this._parseAac(data2, pts);
10628
+ break;
10629
+ case FlvSoundFormat.OPUS:
10630
+ this._parseOpus(data2, pts);
10631
+ break;
10632
+ }
10633
+ }
10634
+ }, {
10635
+ key: "_parseOpus",
10636
+ value: function _parseOpus(data2, pts) {
10637
+ var track = this.audioTrack;
10638
+ var packetType = data2[1];
10639
+ track.codecType = AudioCodecType$2.OPUS;
10640
+ switch (packetType) {
10641
+ case 0: {
10642
+ var ret = OPUS.parseHeaderPackets(data2.subarray(2));
10643
+ if (ret) {
10644
+ track.codec = ret.codec;
10645
+ track.channelCount = ret.channelCount;
10646
+ track.sampleRate = ret.sampleRate;
10647
+ track.config = ret.config;
10648
+ track.sampleDuration = OPUS.getFrameDuration([], track.timescale);
10649
+ } else {
10650
+ track.reset();
10651
+ logger$c.warn("Cannot parse AudioSpecificConfig", data2);
10652
+ }
10653
+ break;
10654
+ }
10655
+ case 1: {
10656
+ if (pts === void 0 || pts === null)
10657
+ return;
10658
+ var newSample = new AudioSample$2(pts, data2.subarray(2), track.sampleDuration);
10659
+ track.samples.push(newSample);
10660
+ break;
10661
+ }
10662
+ default:
10663
+ logger$c.warn("Unknown OpusPacketType: ".concat(packetType));
10493
10664
  }
10494
10665
  }
10495
10666
  }, {
@@ -10577,8 +10748,13 @@ var FlvDemuxer = /* @__PURE__ */ function() {
10577
10748
  units = this._checkAddMetaNalToUnits(isHevc, units, track);
10578
10749
  if (units && units.length) {
10579
10750
  var sample = new VideoSample$2(dts + cts, dts, units);
10751
+ if (this.seamlessLoadingSwitching && dts < track.lastKeyFrameDts) {
10752
+ return;
10753
+ }
10754
+ this.seamlessLoadingSwitching = false;
10580
10755
  if (frameType === 1) {
10581
10756
  sample.setToKeyframe();
10757
+ track.lastKeyFrameDts = dts;
10582
10758
  }
10583
10759
  track.samples.push(sample);
10584
10760
  units.forEach(function(unit) {
@@ -11052,10 +11228,16 @@ var MP4$4 = /* @__PURE__ */ function() {
11052
11228
  if (track.useEME && track.enca) {
11053
11229
  content = MP42.enca(track);
11054
11230
  } else {
11055
- content = MP42.mp4a(track);
11231
+ if (track.codecType === AudioCodecType$2.OPUS) {
11232
+ content = MP42.opus(track);
11233
+ } else {
11234
+ content = MP42.mp4a(track);
11235
+ }
11056
11236
  }
11057
11237
  } else if (track.useEME && track.encv) {
11058
11238
  content = MP42.encv(track);
11239
+ } else if (track.av1C) {
11240
+ content = MP42.av01(track);
11059
11241
  } else {
11060
11242
  content = MP42.avc1hev1(track);
11061
11243
  }
@@ -11268,6 +11450,90 @@ var MP4$4 = /* @__PURE__ */ function() {
11268
11450
  var schi = MP42.schi(data2);
11269
11451
  return MP42.box(MP42.types.sinf, content, MP42.box(MP42.types.frma, frma), MP42.box(MP42.types.schm, schm), schi);
11270
11452
  }
11453
+ }, {
11454
+ key: "av01",
11455
+ value: function av01(track) {
11456
+ return MP42.box(MP42.types.av01, new Uint8Array([
11457
+ 0,
11458
+ 0,
11459
+ 0,
11460
+ 0,
11461
+ 0,
11462
+ 0,
11463
+ 0,
11464
+ 1,
11465
+ 0,
11466
+ 0,
11467
+ 0,
11468
+ 0,
11469
+ 0,
11470
+ 0,
11471
+ 0,
11472
+ 0,
11473
+ 0,
11474
+ 0,
11475
+ 0,
11476
+ 0,
11477
+ 0,
11478
+ 0,
11479
+ 0,
11480
+ 0,
11481
+ track.width >> 8 & 255,
11482
+ track.width & 255,
11483
+ track.height >> 8 & 255,
11484
+ track.height & 255,
11485
+ 0,
11486
+ 72,
11487
+ 0,
11488
+ 0,
11489
+ 0,
11490
+ 72,
11491
+ 0,
11492
+ 0,
11493
+ 0,
11494
+ 0,
11495
+ 0,
11496
+ 0,
11497
+ 0,
11498
+ 1,
11499
+ 0,
11500
+ 0,
11501
+ 0,
11502
+ 0,
11503
+ 0,
11504
+ 0,
11505
+ 0,
11506
+ 0,
11507
+ 0,
11508
+ 0,
11509
+ 0,
11510
+ 0,
11511
+ 0,
11512
+ 0,
11513
+ 0,
11514
+ 0,
11515
+ 0,
11516
+ 0,
11517
+ 0,
11518
+ 0,
11519
+ 0,
11520
+ 0,
11521
+ 0,
11522
+ 0,
11523
+ 0,
11524
+ 0,
11525
+ 0,
11526
+ 0,
11527
+ 0,
11528
+ 0,
11529
+ 0,
11530
+ 0,
11531
+ 0,
11532
+ 24,
11533
+ 17,
11534
+ 17
11535
+ ]), track.av1C, track.colr);
11536
+ }
11271
11537
  }, {
11272
11538
  key: "avc1hev1",
11273
11539
  value: function avc1hev1(track) {
@@ -11638,6 +11904,53 @@ var MP4$4 = /* @__PURE__ */ function() {
11638
11904
  )));
11639
11905
  return esds2;
11640
11906
  }
11907
+ }, {
11908
+ key: "opus",
11909
+ value: function opus(track) {
11910
+ var opusAudioDescription = new Uint8Array([
11911
+ 0,
11912
+ 0,
11913
+ 0,
11914
+ 0,
11915
+ 0,
11916
+ 0,
11917
+ 0,
11918
+ 1,
11919
+ 0,
11920
+ 0,
11921
+ 0,
11922
+ 0,
11923
+ 0,
11924
+ 0,
11925
+ 0,
11926
+ 0,
11927
+ 0,
11928
+ track.channelCount,
11929
+ 0,
11930
+ 16,
11931
+ 0,
11932
+ 0,
11933
+ 0,
11934
+ 0,
11935
+ track.sampleRate >> 8 & 255,
11936
+ track.sampleRate & 255,
11937
+ 0,
11938
+ 0
11939
+ ]);
11940
+ var opusSpecificConfig = track.config.length ? MP42.dOps(track) : [];
11941
+ return MP42.box(MP42.types.Opus, opusAudioDescription, opusSpecificConfig);
11942
+ }
11943
+ }, {
11944
+ key: "dOps",
11945
+ value: function dOps(track) {
11946
+ if (track.config) {
11947
+ track.config[4] = track.sampleRate >>> 24 & 255;
11948
+ track.config[5] = track.sampleRate >>> 16 & 255;
11949
+ track.config[6] = track.sampleRate >>> 8 & 255;
11950
+ track.config[7] = track.sampleRate & 255;
11951
+ return MP42.box(MP42.types.dOps, track.config);
11952
+ }
11953
+ }
11641
11954
  }, {
11642
11955
  key: "mvex",
11643
11956
  value: function mvex(tracks) {
@@ -12240,7 +12553,7 @@ var MP4$4 = /* @__PURE__ */ function() {
12240
12553
  }]);
12241
12554
  return MP42;
12242
12555
  }();
12243
- _defineProperty$h(MP4$4, "types", ["avc1", "avcC", "hvc1", "hvcC", "dinf", "dref", "esds", "ftyp", "hdlr", "mdat", "mdhd", "mdia", "mfhd", "minf", "moof", "moov", "mp4a", "mvex", "mvhd", "pasp", "stbl", "stco", "stsc", "stsd", "stsz", "stts", "tfdt", "tfhd", "traf", "trak", "trex", "tkhd", "vmhd", "smhd", "ctts", "stss", "styp", "pssh", "sidx", "sbgp", "saiz", "saio", "senc", "trun", "encv", "enca", "sinf", "btrt", "frma", "tenc", "schm", "schi", "mehd", "fiel", "sdtp"].reduce(function(p, c) {
12556
+ _defineProperty$h(MP4$4, "types", ["Opus", "dOps", "av01", "av1C", "avc1", "avcC", "hvc1", "hvcC", "dinf", "dref", "esds", "ftyp", "hdlr", "mdat", "mdhd", "mdia", "mfhd", "minf", "moof", "moov", "mp4a", "mvex", "mvhd", "pasp", "stbl", "stco", "stsc", "stsd", "stsz", "stts", "tfdt", "tfhd", "traf", "trak", "trex", "tkhd", "vmhd", "smhd", "ctts", "stss", "styp", "pssh", "sidx", "sbgp", "saiz", "saio", "senc", "trun", "encv", "enca", "sinf", "btrt", "frma", "tenc", "schm", "schi", "mehd", "fiel", "sdtp"].reduce(function(p, c) {
12244
12557
  p[c] = [c.charCodeAt(0), c.charCodeAt(1), c.charCodeAt(2), c.charCodeAt(3)];
12245
12558
  return p;
12246
12559
  }, /* @__PURE__ */ Object.create(null)));
@@ -12575,30 +12888,46 @@ var FMP4Remuxer$3 = /* @__PURE__ */ function() {
12575
12888
  };
12576
12889
  }
12577
12890
  var samples = track.samples;
12891
+ var isAV01 = /av01/.test(track.codec);
12578
12892
  var mdatSize = 0;
12579
- samples.forEach(function(s) {
12580
- mdatSize += s.units.reduce(function(t, c) {
12581
- return t + c.byteLength;
12582
- }, 0);
12583
- mdatSize += s.units.length * 4;
12584
- });
12585
- var mdata = new Uint8Array(mdatSize);
12586
- var mdatView = new DataView(mdata.buffer);
12587
- var _loop = function _loop2(_offset, _sample) {
12588
- _sample = samples[i];
12589
- var sampleSize = 0;
12590
- _sample.units.forEach(function(u) {
12591
- mdatView.setUint32(_offset, u.byteLength);
12592
- _offset += 4;
12593
- mdata.set(u, _offset);
12594
- _offset += u.byteLength;
12595
- sampleSize += 4 + u.byteLength;
12893
+ if (isAV01) {
12894
+ samples.forEach(function(s) {
12895
+ mdatSize += s.data.byteLength;
12596
12896
  });
12597
- _sample.size = sampleSize;
12598
- offset = _offset, sample = _sample;
12599
- };
12600
- for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
12601
- _loop(offset, sample);
12897
+ } else {
12898
+ samples.forEach(function(s) {
12899
+ mdatSize += s.units.reduce(function(t, c) {
12900
+ return t + c.byteLength;
12901
+ }, 0);
12902
+ mdatSize += s.units.length * 4;
12903
+ });
12904
+ }
12905
+ var mdata = new Uint8Array(mdatSize);
12906
+ if (isAV01) {
12907
+ for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
12908
+ sample = samples[i];
12909
+ mdata.set(sample.data, offset);
12910
+ sample.size = sample.data.byteLength;
12911
+ offset += sample.size;
12912
+ }
12913
+ } else {
12914
+ var mdatView = new DataView(mdata.buffer);
12915
+ var _loop = function _loop2(_offset2, _sample2) {
12916
+ _sample2 = samples[_i];
12917
+ var sampleSize = 0;
12918
+ _sample2.units.forEach(function(u) {
12919
+ mdatView.setUint32(_offset2, u.byteLength);
12920
+ _offset2 += 4;
12921
+ mdata.set(u, _offset2);
12922
+ _offset2 += u.byteLength;
12923
+ sampleSize += 4 + u.byteLength;
12924
+ });
12925
+ _sample2.size = sampleSize;
12926
+ _offset = _offset2, _sample = _sample2;
12927
+ };
12928
+ for (var _i = 0, _l = samples.length, _offset = 0, _sample; _i < _l; _i++) {
12929
+ _loop(_offset, _sample);
12930
+ }
12602
12931
  }
12603
12932
  var mdat = MP4$4.mdat(mdata);
12604
12933
  var moof = MP4$4.moof([track]);
@@ -14295,6 +14624,55 @@ const NoPadding = {
14295
14624
  unpad() {
14296
14625
  }
14297
14626
  };
14627
+ var TransferCost = /* @__PURE__ */ function() {
14628
+ function TransferCost2() {
14629
+ _classCallCheck$m(this, TransferCost2);
14630
+ _defineProperty$k(this, "_ttfb", 0);
14631
+ _defineProperty$k(this, "_demuxStart", 0);
14632
+ _defineProperty$k(this, "_demuxEnd", 0);
14633
+ _defineProperty$k(this, "_demuxCost", 0);
14634
+ _defineProperty$k(this, "_remuxStart", 0);
14635
+ _defineProperty$k(this, "_remuxEnd", 0);
14636
+ _defineProperty$k(this, "_remuxCost", 0);
14637
+ _defineProperty$k(this, "_appendStart", 0);
14638
+ _defineProperty$k(this, "_appendEnd", 0);
14639
+ _defineProperty$k(this, "_appendCost", 0);
14640
+ }
14641
+ _createClass$m(TransferCost2, [{
14642
+ key: "set",
14643
+ value: function set5(event, value2) {
14644
+ this["_".concat(event)] = value2;
14645
+ }
14646
+ }, {
14647
+ key: "start",
14648
+ value: function start(event) {
14649
+ this["_".concat(event, "Start")] = Date.now();
14650
+ }
14651
+ }, {
14652
+ key: "end",
14653
+ value: function end(event) {
14654
+ this["_".concat(event, "End")] = Date.now();
14655
+ this["_".concat(event, "Cost")] = this["_".concat(event, "Cost")] + (this["_".concat(event, "End")] - this["_".concat(event, "Start")]);
14656
+ }
14657
+ }, {
14658
+ key: "transferCost",
14659
+ get: function get3() {
14660
+ return {
14661
+ ttfbCost: this._ttfb,
14662
+ demuxCost: this._demuxCost,
14663
+ remuxCost: this._remuxCost,
14664
+ appendCost: this._appendCost
14665
+ };
14666
+ }
14667
+ }]);
14668
+ return TransferCost2;
14669
+ }();
14670
+ var TRANSFER_EVENT = {
14671
+ TTFB: "ttfb",
14672
+ DEMUX: "demux",
14673
+ REMUX: "remux",
14674
+ APPEND: "append"
14675
+ };
14298
14676
  var logger$b = new Logger$b("BufferService");
14299
14677
  var BufferService$1 = /* @__PURE__ */ function() {
14300
14678
  function BufferService2(flv, softVideo) {
@@ -14382,7 +14760,8 @@ var BufferService$1 = /* @__PURE__ */ function() {
14382
14760
  this._contiguous = false;
14383
14761
  this._sourceCreated = false;
14384
14762
  this._initSegmentId = "";
14385
- case 11:
14763
+ this.resetSeamlessSwitchStats();
14764
+ case 12:
14386
14765
  case "end":
14387
14766
  return _context.stop();
14388
14767
  }
@@ -14393,6 +14772,15 @@ var BufferService$1 = /* @__PURE__ */ function() {
14393
14772
  }
14394
14773
  return reset;
14395
14774
  }()
14775
+ }, {
14776
+ key: "resetSeamlessSwitchStats",
14777
+ value: function resetSeamlessSwitchStats() {
14778
+ this.seamlessLoadingSwitch = null;
14779
+ this.seamlessLoadingSwitching = false;
14780
+ if (this._demuxer) {
14781
+ this._demuxer.seamlessLoadingSwitching = false;
14782
+ }
14783
+ }
14396
14784
  }, {
14397
14785
  key: "endOfStream",
14398
14786
  value: function() {
@@ -14498,32 +14886,56 @@ var BufferService$1 = /* @__PURE__ */ function() {
14498
14886
  key: "appendBuffer",
14499
14887
  value: function() {
14500
14888
  var _appendBuffer = _asyncToGenerator$b(/* @__PURE__ */ _regeneratorRuntime$b().mark(function _callee5(chunk) {
14501
- var demuxer, videoTrack, audioTrack, metadataTrack, videoExist, audioExist, duration, track, videoType, audioType, mse, newId, remuxResult, p;
14889
+ var _this = this;
14890
+ var switchingNoReset, demuxer, videoTrack, audioTrack, metadataTrack, idx, videoExist, audioExist, duration, track, videoType, audioType, mse, afterAppend, newId, remuxResult, p;
14502
14891
  return _regeneratorRuntime$b().wrap(function _callee5$(_context5) {
14503
14892
  while (1)
14504
14893
  switch (_context5.prev = _context5.next) {
14505
14894
  case 0:
14895
+ switchingNoReset = false;
14506
14896
  if (this._cachedBuffer) {
14507
14897
  chunk = concatUint8Array$6(this._cachedBuffer, chunk);
14508
14898
  this._cachedBuffer = null;
14509
14899
  }
14510
14900
  demuxer = this._demuxer;
14511
14901
  if (!(!chunk || !chunk.length || !demuxer)) {
14512
- _context5.next = 4;
14902
+ _context5.next = 5;
14513
14903
  break;
14514
14904
  }
14515
14905
  return _context5.abrupt("return");
14516
- case 4:
14517
- _context5.prev = 4;
14518
- demuxer.demuxAndFix(chunk, this._discontinuity, this._contiguous, this._demuxStartTime);
14519
- _context5.next = 11;
14906
+ case 5:
14907
+ _context5.prev = 5;
14908
+ this.flv._transferCost.start(TRANSFER_EVENT.DEMUX);
14909
+ demuxer.demuxAndFix(chunk, this.seamlessLoadingSwitching || this._discontinuity, this._contiguous, this._demuxStartTime, this.seamlessLoadingSwitching);
14910
+ this.seamlessLoadingSwitching = false;
14911
+ this.flv._transferCost.end(TRANSFER_EVENT.DEMUX);
14912
+ _context5.next = 15;
14520
14913
  break;
14521
- case 8:
14522
- _context5.prev = 8;
14523
- _context5.t0 = _context5["catch"](4);
14914
+ case 12:
14915
+ _context5.prev = 12;
14916
+ _context5.t0 = _context5["catch"](5);
14524
14917
  throw new StreamingError$3(ERR$3.DEMUX, ERR$3.SUB_TYPES.FLV, _context5.t0);
14525
- case 11:
14918
+ case 15:
14526
14919
  videoTrack = demuxer.videoTrack, audioTrack = demuxer.audioTrack, metadataTrack = demuxer.metadataTrack;
14920
+ if (!this.seamlessLoadingSwitch) {
14921
+ _context5.next = 25;
14922
+ break;
14923
+ }
14924
+ idx = videoTrack.samples.findIndex(function(sample) {
14925
+ return sample.originDts === videoTrack.lastKeyFrameDts;
14926
+ });
14927
+ if (!(idx >= 0)) {
14928
+ _context5.next = 25;
14929
+ break;
14930
+ }
14931
+ videoTrack.samples.splice(idx);
14932
+ _context5.next = 22;
14933
+ return this.seamlessLoadingSwitch();
14934
+ case 22:
14935
+ this.seamlessLoadingSwitch = null;
14936
+ chunk = null;
14937
+ switchingNoReset = true;
14938
+ case 25:
14527
14939
  videoExist = videoTrack.exist();
14528
14940
  audioExist = audioTrack.exist();
14529
14941
  if (this._opts.onlyAudio) {
@@ -14535,7 +14947,7 @@ var BufferService$1 = /* @__PURE__ */ function() {
14535
14947
  audioTrack.present = false;
14536
14948
  }
14537
14949
  if (!(!videoExist && videoTrack.present || !audioExist && audioTrack.present)) {
14538
- _context5.next = 29;
14950
+ _context5.next = 42;
14539
14951
  break;
14540
14952
  }
14541
14953
  duration = 0;
@@ -14544,7 +14956,7 @@ var BufferService$1 = /* @__PURE__ */ function() {
14544
14956
  duration = (track.samples[track.samples.length - 1].originPts - track.samples[0].originPts) / track.timescale * 1e3;
14545
14957
  }
14546
14958
  if (!(duration > this._opts.analyzeDuration)) {
14547
- _context5.next = 27;
14959
+ _context5.next = 40;
14548
14960
  break;
14549
14961
  }
14550
14962
  logger$b.warn("analyze duration exceeded, ".concat(duration, "ms"), track);
@@ -14553,19 +14965,28 @@ var BufferService$1 = /* @__PURE__ */ function() {
14553
14965
  this.flv.emit(EVENT$3.ANALYZE_DURATION_EXCEEDED, {
14554
14966
  duration
14555
14967
  });
14556
- _context5.next = 29;
14968
+ _context5.next = 42;
14557
14969
  break;
14558
- case 27:
14970
+ case 40:
14559
14971
  this._cachedBuffer = chunk;
14560
14972
  return _context5.abrupt("return");
14561
- case 29:
14973
+ case 42:
14562
14974
  videoType = videoTrack.type;
14563
14975
  audioType = audioTrack.type;
14564
14976
  this._fireEvents(videoTrack, audioTrack, metadataTrack);
14565
- this._discontinuity = false;
14566
- this._contiguous = true;
14567
- this._demuxStartTime = 0;
14977
+ if (!switchingNoReset) {
14978
+ this._discontinuity = false;
14979
+ this._contiguous = true;
14980
+ this._demuxStartTime = 0;
14981
+ }
14568
14982
  mse = this._mse;
14983
+ afterAppend = function afterAppend2() {
14984
+ var _this$flv;
14985
+ if ((_this$flv = _this.flv) !== null && _this$flv !== void 0 && _this$flv.emit) {
14986
+ var _this$flv2;
14987
+ (_this$flv2 = _this.flv) === null || _this$flv2 === void 0 ? void 0 : _this$flv2.emit(EVENT$3.APPEND_BUFFER, {});
14988
+ }
14989
+ };
14569
14990
  this.flv.emit(EVENT$3.DEMUXED_TRACK, {
14570
14991
  videoTrack
14571
14992
  });
@@ -14576,16 +14997,16 @@ var BufferService$1 = /* @__PURE__ */ function() {
14576
14997
  this._emitMetaParsedEvent(videoTrack, audioTrack);
14577
14998
  }
14578
14999
  if (!mse) {
14579
- _context5.next = 66;
15000
+ _context5.next = 81;
14580
15001
  break;
14581
15002
  }
14582
15003
  if (this._sourceCreated) {
14583
- _context5.next = 47;
15004
+ _context5.next = 59;
14584
15005
  break;
14585
15006
  }
14586
- _context5.next = 43;
15007
+ _context5.next = 55;
14587
15008
  return mse.open();
14588
- case 43:
15009
+ case 55:
14589
15010
  if (videoExist) {
14590
15011
  logger$b.log("codec: video/mp4;codecs=".concat(videoTrack.codec));
14591
15012
  mse.createSource(videoType, "video/mp4;codecs=".concat(videoTrack.codec));
@@ -14596,26 +15017,28 @@ var BufferService$1 = /* @__PURE__ */ function() {
14596
15017
  }
14597
15018
  this._sourceCreated = true;
14598
15019
  this.flv.emit(EVENT$3.SOURCEBUFFER_CREATED);
14599
- case 47:
14600
- _context5.prev = 47;
15020
+ case 59:
15021
+ _context5.prev = 59;
14601
15022
  if (this._needInitSegment && !this._opts.mseLowLatency) {
14602
15023
  videoTrack.duration = this._opts.durationForMSELowLatencyOff * videoTrack.timescale;
14603
15024
  audioTrack.duration = this._opts.durationForMSELowLatencyOff * audioExist.timescale;
14604
15025
  }
15026
+ this.flv._transferCost.start(TRANSFER_EVENT.REMUX);
14605
15027
  remuxResult = this._remuxer.remux(this._needInitSegment);
14606
- _context5.next = 55;
15028
+ this.flv._transferCost.end(TRANSFER_EVENT.REMUX);
15029
+ _context5.next = 69;
14607
15030
  break;
14608
- case 52:
14609
- _context5.prev = 52;
14610
- _context5.t1 = _context5["catch"](47);
15031
+ case 66:
15032
+ _context5.prev = 66;
15033
+ _context5.t1 = _context5["catch"](59);
14611
15034
  throw new StreamingError$3(ERR$3.REMUX, ERR$3.SUB_TYPES.FMP4, _context5.t1);
14612
- case 55:
15035
+ case 69:
14613
15036
  if (!(this._needInitSegment && !remuxResult.videoInitSegment && !remuxResult.audioInitSegment)) {
14614
- _context5.next = 57;
15037
+ _context5.next = 71;
14615
15038
  break;
14616
15039
  }
14617
15040
  return _context5.abrupt("return");
14618
- case 57:
15041
+ case 71:
14619
15042
  this._needInitSegment = false;
14620
15043
  p = [];
14621
15044
  if (remuxResult.videoInitSegment)
@@ -14626,16 +15049,21 @@ var BufferService$1 = /* @__PURE__ */ function() {
14626
15049
  p.push(mse.append(videoType, remuxResult.videoSegment));
14627
15050
  if (remuxResult.audioSegment)
14628
15051
  p.push(mse.append(audioType, remuxResult.audioSegment));
14629
- return _context5.abrupt("return", Promise.all(p));
14630
- case 66:
15052
+ this.flv._transferCost.start(TRANSFER_EVENT.APPEND);
15053
+ return _context5.abrupt("return", Promise.all(p).then(afterAppend).then(function() {
15054
+ _this.flv._transferCost.end(TRANSFER_EVENT.APPEND);
15055
+ afterAppend();
15056
+ }));
15057
+ case 81:
14631
15058
  if (this._softVideo) {
14632
15059
  this._softVideo.appendBuffer(videoTrack, audioTrack);
15060
+ afterAppend();
14633
15061
  }
14634
- case 67:
15062
+ case 82:
14635
15063
  case "end":
14636
15064
  return _context5.stop();
14637
15065
  }
14638
- }, _callee5, this, [[4, 8], [47, 52]]);
15066
+ }, _callee5, this, [[5, 12], [59, 66]]);
14639
15067
  }));
14640
15068
  function appendBuffer(_x2) {
14641
15069
  return _appendBuffer.apply(this, arguments);
@@ -14646,7 +15074,7 @@ var BufferService$1 = /* @__PURE__ */ function() {
14646
15074
  key: "evictBuffer",
14647
15075
  value: function() {
14648
15076
  var _evictBuffer = _asyncToGenerator$b(/* @__PURE__ */ _regeneratorRuntime$b().mark(function _callee6(bufferBehind) {
14649
- var _this = this;
15077
+ var _this2 = this;
14650
15078
  var media, currentTime, removeEnd, start;
14651
15079
  return _regeneratorRuntime$b().wrap(function _callee6$(_context6) {
14652
15080
  while (1)
@@ -14675,7 +15103,7 @@ var BufferService$1 = /* @__PURE__ */ function() {
14675
15103
  return _context6.abrupt("return");
14676
15104
  case 10:
14677
15105
  return _context6.abrupt("return", this._mse.clearBuffer(0, removeEnd).then(function() {
14678
- return _this.flv.emit(EVENT$3.REMOVE_BUFFER, {
15106
+ return _this2.flv.emit(EVENT$3.REMOVE_BUFFER, {
14679
15107
  removeEnd
14680
15108
  });
14681
15109
  }));
@@ -14725,16 +15153,16 @@ var BufferService$1 = /* @__PURE__ */ function() {
14725
15153
  }, {
14726
15154
  key: "_fireEvents",
14727
15155
  value: function _fireEvents(videoTrack, audioTrack, metadataTrack) {
14728
- var _this2 = this;
14729
- logger$b.debug(videoTrack.samples, audioTrack.samples);
15156
+ var _this3 = this;
15157
+ logger$b.debug("videoTrack samples count: ".concat(videoTrack.samples.length, ", audioTrack samples count: ").concat(audioTrack.samples.length));
14730
15158
  metadataTrack.flvScriptSamples.forEach(function(sample) {
14731
- _this2.flv.emit(EVENT$3.FLV_SCRIPT_DATA, sample);
15159
+ _this3.flv.emit(EVENT$3.FLV_SCRIPT_DATA, sample);
14732
15160
  logger$b.debug("flvScriptData", sample);
14733
15161
  });
14734
15162
  videoTrack.samples.forEach(function(sample) {
14735
15163
  if (sample.keyframe) {
14736
- _this2.flv.emit(EVENT$3.KEYFRAME, {
14737
- pts: sample.pts
15164
+ _this3.flv.emit(EVENT$3.KEYFRAME, {
15165
+ pts: sample.originPts
14738
15166
  });
14739
15167
  }
14740
15168
  });
@@ -14752,7 +15180,7 @@ var BufferService$1 = /* @__PURE__ */ function() {
14752
15180
  break;
14753
15181
  }
14754
15182
  if (type)
14755
- _this2.flv.emit(EVENT$3.STREAM_EXCEPTION, _objectSpread2$b(_objectSpread2$b({}, warn), {}, {
15183
+ _this3.flv.emit(EVENT$3.STREAM_EXCEPTION, _objectSpread2$b(_objectSpread2$b({}, warn), {}, {
14756
15184
  type
14757
15185
  }));
14758
15186
  logger$b.warn("video exception", warn);
@@ -14771,13 +15199,13 @@ var BufferService$1 = /* @__PURE__ */ function() {
14771
15199
  break;
14772
15200
  }
14773
15201
  if (type)
14774
- _this2.flv.emit(EVENT$3.STREAM_EXCEPTION, _objectSpread2$b(_objectSpread2$b({}, warn), {}, {
15202
+ _this3.flv.emit(EVENT$3.STREAM_EXCEPTION, _objectSpread2$b(_objectSpread2$b({}, warn), {}, {
14775
15203
  type
14776
15204
  }));
14777
15205
  logger$b.warn("audio exception", warn);
14778
15206
  });
14779
15207
  metadataTrack.seiSamples.forEach(function(sei) {
14780
- _this2.flv.emit(EVENT$3.SEI, _objectSpread2$b(_objectSpread2$b({}, sei), {}, {
15208
+ _this3.flv.emit(EVENT$3.SEI, _objectSpread2$b(_objectSpread2$b({}, sei), {}, {
14781
15209
  sei: {
14782
15210
  code: sei.data.type,
14783
15211
  content: sei.data.payload,
@@ -14812,7 +15240,8 @@ function getOption$1(opts) {
14812
15240
  durationForMSELowLatencyOff: 6,
14813
15241
  chunkCountForSpeed: 50,
14814
15242
  skipChunkSize: 1e3,
14815
- longtimeNoReceived: 3e3
15243
+ longtimeNoReceived: 3e3,
15244
+ enableStartGapJump: true
14816
15245
  }, opts);
14817
15246
  if (ret.isLive) {
14818
15247
  if (ret.preloadTime) {
@@ -14880,7 +15309,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
14880
15309
  _defineProperty$k(_assertThisInitialized$i(_this), "_acceptRanges", true);
14881
15310
  _defineProperty$k(_assertThisInitialized$i(_this), "_onProgress", /* @__PURE__ */ function() {
14882
15311
  var _ref2 = _asyncToGenerator$b(/* @__PURE__ */ _regeneratorRuntime$b().mark(function _callee(chunk, done, _ref, response) {
14883
- var startTime, endTime, st, firstByteTime, _this$_mediaLoader, headers, _this$_bufferService, remaining, maxReaderInterval;
15312
+ var startTime, endTime, st, firstByteTime, _this$_mediaLoader, headers, elapsed, _this$_bufferService, remaining, maxReaderInterval;
14884
15313
  return _regeneratorRuntime$b().wrap(function _callee$(_context) {
14885
15314
  while (1)
14886
15315
  switch (_context.prev = _context.next) {
@@ -14888,7 +15317,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
14888
15317
  startTime = _ref.startTime, endTime = _ref.endTime, st = _ref.st, firstByteTime = _ref.firstByteTime;
14889
15318
  _this._loading = !done;
14890
15319
  if (_this._firstProgressEmit) {
14891
- _context.next = 11;
15320
+ _context.next = 13;
14892
15321
  break;
14893
15322
  }
14894
15323
  if (_this.media) {
@@ -14899,49 +15328,51 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
14899
15328
  return _context.abrupt("return");
14900
15329
  case 6:
14901
15330
  headers = response.headers;
15331
+ elapsed = st ? firstByteTime - st : endTime - startTime;
14902
15332
  _this.emit(EVENT$3.TTFB, {
14903
15333
  url: _this._opts.url,
14904
15334
  responseUrl: response.url,
14905
- elapsed: st ? firstByteTime - st : endTime - startTime
15335
+ elapsed
14906
15336
  });
14907
15337
  _this.emit(EVENT$3.LOAD_RESPONSE_HEADERS, {
14908
15338
  headers
14909
15339
  });
15340
+ _this._transferCost.set(TRANSFER_EVENT.TTFB, elapsed);
14910
15341
  _this._acceptRanges = !!(headers !== null && headers !== void 0 && headers.get("Accept-Ranges")) || !!(headers !== null && headers !== void 0 && headers.get("Content-Range"));
14911
15342
  _this._firstProgressEmit = true;
14912
- case 11:
15343
+ case 13:
14913
15344
  if (_this._bufferService) {
14914
- _context.next = 13;
15345
+ _context.next = 15;
14915
15346
  break;
14916
15347
  }
14917
15348
  return _context.abrupt("return");
14918
- case 13:
15349
+ case 15:
14919
15350
  clearTimeout(_this._maxChunkWaitTimer);
14920
15351
  _this._bandwidthService.addChunkRecord(chunk === null || chunk === void 0 ? void 0 : chunk.byteLength, endTime - startTime);
14921
- _context.prev = 15;
14922
- _context.next = 18;
15352
+ _context.prev = 17;
15353
+ _context.next = 20;
14923
15354
  return _this._bufferService.appendBuffer(chunk);
14924
- case 18:
15355
+ case 20:
14925
15356
  (_this$_bufferService = _this._bufferService) === null || _this$_bufferService === void 0 ? void 0 : _this$_bufferService.evictBuffer(_this._opts.bufferBehind);
14926
- _context.next = 31;
15357
+ _context.next = 33;
14927
15358
  break;
14928
- case 21:
14929
- _context.prev = 21;
14930
- _context.t0 = _context["catch"](15);
15359
+ case 23:
15360
+ _context.prev = 23;
15361
+ _context.t0 = _context["catch"](17);
14931
15362
  if (!(!_this.isLive && _this._bufferService.isFull())) {
14932
- _context.next = 30;
15363
+ _context.next = 32;
14933
15364
  break;
14934
15365
  }
14935
- _context.next = 26;
15366
+ _context.next = 28;
14936
15367
  return _this._mediaLoader.cancel();
14937
- case 26:
15368
+ case 28:
14938
15369
  _this._loading = false;
14939
15370
  remaining = _this.bufferInfo().remaining;
14940
15371
  _this._opts.preloadTime = parseInt(remaining) / 2;
14941
15372
  return _context.abrupt("return");
14942
- case 30:
15373
+ case 32:
14943
15374
  return _context.abrupt("return", _this._emitError(StreamingError$3.create(_context.t0)));
14944
- case 31:
15375
+ case 33:
14945
15376
  if (_this._urlSwitching) {
14946
15377
  _this._urlSwitching = false;
14947
15378
  _this.emit(EVENT$3.SWITCH_URL_SUCCESS, {
@@ -14953,7 +15384,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
14953
15384
  _this._tick();
14954
15385
  }
14955
15386
  if (!(done && !_this.media.seeking)) {
14956
- _context.next = 38;
15387
+ _context.next = 40;
14957
15388
  break;
14958
15389
  }
14959
15390
  _this.emit(EVENT$3.LOAD_COMPLETE);
@@ -14962,13 +15393,13 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
14962
15393
  _this._end();
14963
15394
  }
14964
15395
  return _context.abrupt("return");
14965
- case 38:
15396
+ case 40:
14966
15397
  if (_this.isLive) {
14967
- _context.next = 40;
15398
+ _context.next = 42;
14968
15399
  break;
14969
15400
  }
14970
15401
  return _context.abrupt("return");
14971
- case 40:
15402
+ case 42:
14972
15403
  maxReaderInterval = _this._opts.maxReaderInterval;
14973
15404
  if (maxReaderInterval && _this._firstProgressEmit) {
14974
15405
  clearTimeout(_this._maxChunkWaitTimer);
@@ -14982,11 +15413,11 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
14982
15413
  _this._end();
14983
15414
  }, maxReaderInterval);
14984
15415
  }
14985
- case 42:
15416
+ case 44:
14986
15417
  case "end":
14987
15418
  return _context.stop();
14988
15419
  }
14989
- }, _callee, null, [[15, 21]]);
15420
+ }, _callee, null, [[17, 23]]);
14990
15421
  }));
14991
15422
  return function(_x, _x2, _x3, _x4) {
14992
15423
  return _ref2.apply(this, arguments);
@@ -15019,19 +15450,19 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
15019
15450
  if (bufferEnd < MAX_HOLE || !media.readyState)
15020
15451
  return;
15021
15452
  var opts = _this._opts;
15022
- if (isMediaPlaying$1(media)) {
15453
+ if (isMediaPlaying$1(media) && media.currentTime) {
15023
15454
  if (_this._gapService) {
15024
15455
  _this._gapService.do(media, opts.maxJumpDistance, _this.isLive, 3);
15025
15456
  }
15026
15457
  } else {
15027
- if (!media.currentTime && _this._gapService) {
15458
+ if (!media.currentTime && _this._gapService && opts.enableStartGapJump) {
15028
15459
  var gapJump = _this._opts.mseLowLatency || _this._opts.mseLowLatency === false && _this.bufferInfo(MAX_START_GAP).nextStart;
15029
15460
  if (gapJump) {
15030
15461
  _this._gapService.do(media, opts.maxJumpDistance, _this.isLive, 3);
15031
15462
  }
15032
15463
  return;
15033
15464
  }
15034
- if (opts.isLive && media.readyState === 4 && bufferEnd > opts.disconnectTime) {
15465
+ if (opts.isLive && media.readyState === 4 && bufferEnd - media.currentTime > opts.disconnectTime) {
15035
15466
  _this.disconnect();
15036
15467
  }
15037
15468
  }
@@ -15180,6 +15611,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
15180
15611
  responseType: "arraybuffer"
15181
15612
  }));
15182
15613
  _this._disconnectRetryCount = _this._opts.disconnectRetryCount;
15614
+ _this._transferCost = new TransferCost();
15183
15615
  _this._bufferService = new BufferService$1(_assertThisInitialized$i(_this), _this._opts.softDecode ? _this.media : void 0, _this._opts);
15184
15616
  _this._seiService = new SeiService$1(_assertThisInitialized$i(_this));
15185
15617
  _this._bandwidthService = new BandwidthService$1({
@@ -15203,7 +15635,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
15203
15635
  _createClass$m(Flv2, [{
15204
15636
  key: "version",
15205
15637
  get: function get3() {
15206
- return "3.0.19-rc.0";
15638
+ return "3.0.21-rc.3";
15207
15639
  }
15208
15640
  }, {
15209
15641
  key: "isLive",
@@ -15319,9 +15751,9 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
15319
15751
  return this._clear();
15320
15752
  case 8:
15321
15753
  setTimeout(function() {
15754
+ _this2._seamlessSwitching = true;
15322
15755
  _this2._loadData(_this2._opts.url);
15323
15756
  _this2._bufferService.seamlessSwitch();
15324
- _this2._seamlessSwitching = true;
15325
15757
  });
15326
15758
  _context5.next = 13;
15327
15759
  break;
@@ -15345,50 +15777,82 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
15345
15777
  }, {
15346
15778
  key: "disconnect",
15347
15779
  value: function disconnect() {
15780
+ var _this$_bufferService4;
15348
15781
  logger$a.debug("disconnect!");
15782
+ (_this$_bufferService4 = this._bufferService) === null || _this$_bufferService4 === void 0 ? void 0 : _this$_bufferService4.resetSeamlessSwitchStats();
15349
15783
  return this._clear();
15350
15784
  }
15351
15785
  }, {
15352
15786
  key: "switchURL",
15353
15787
  value: function() {
15354
- var _switchURL = _asyncToGenerator$b(/* @__PURE__ */ _regeneratorRuntime$b().mark(function _callee6(url, seamless) {
15788
+ var _switchURL = _asyncToGenerator$b(/* @__PURE__ */ _regeneratorRuntime$b().mark(function _callee7(url, seamless) {
15355
15789
  var _this3 = this;
15356
- return _regeneratorRuntime$b().wrap(function _callee6$(_context6) {
15790
+ return _regeneratorRuntime$b().wrap(function _callee7$(_context7) {
15357
15791
  while (1)
15358
- switch (_context6.prev = _context6.next) {
15792
+ switch (_context7.prev = _context7.next) {
15359
15793
  case 0:
15360
15794
  if (this._bufferService) {
15361
- _context6.next = 2;
15795
+ _context7.next = 2;
15362
15796
  break;
15363
15797
  }
15364
- return _context6.abrupt("return");
15798
+ return _context7.abrupt("return");
15365
15799
  case 2:
15366
15800
  this._resetDisconnectCount();
15801
+ if (!(this._loading && seamless)) {
15802
+ _context7.next = 6;
15803
+ break;
15804
+ }
15805
+ this._bufferService.seamlessLoadingSwitch = /* @__PURE__ */ function() {
15806
+ var _ref5 = _asyncToGenerator$b(/* @__PURE__ */ _regeneratorRuntime$b().mark(function _callee6(pts) {
15807
+ return _regeneratorRuntime$b().wrap(function _callee6$(_context6) {
15808
+ while (1)
15809
+ switch (_context6.prev = _context6.next) {
15810
+ case 0:
15811
+ _context6.next = 2;
15812
+ return _this3._clear();
15813
+ case 2:
15814
+ _this3._bufferService.seamlessLoadingSwitching = true;
15815
+ _this3._urlSwitching = true;
15816
+ _this3._seamlessSwitching = true;
15817
+ _this3._bufferService.seamlessSwitch();
15818
+ _this3._loadData(url);
15819
+ case 7:
15820
+ case "end":
15821
+ return _context6.stop();
15822
+ }
15823
+ }, _callee6);
15824
+ }));
15825
+ return function(_x8) {
15826
+ return _ref5.apply(this, arguments);
15827
+ };
15828
+ }();
15829
+ return _context7.abrupt("return");
15830
+ case 6:
15367
15831
  if (!(!seamless || !this._opts.isLive)) {
15368
- _context6.next = 8;
15832
+ _context7.next = 11;
15369
15833
  break;
15370
15834
  }
15371
- _context6.next = 6;
15835
+ _context7.next = 9;
15372
15836
  return this.load(url);
15373
- case 6:
15837
+ case 9:
15374
15838
  this._urlSwitching = true;
15375
- return _context6.abrupt("return", this.media.play(true).catch(function() {
15839
+ return _context7.abrupt("return", this.media.play(true).catch(function() {
15376
15840
  }));
15377
- case 8:
15378
- _context6.next = 10;
15841
+ case 11:
15842
+ _context7.next = 13;
15379
15843
  return this._clear();
15380
- case 10:
15844
+ case 13:
15381
15845
  setTimeout(function() {
15382
15846
  _this3._urlSwitching = true;
15383
15847
  _this3._seamlessSwitching = true;
15384
15848
  _this3._loadData(url);
15385
15849
  _this3._bufferService.seamlessSwitch();
15386
15850
  });
15387
- case 11:
15851
+ case 14:
15388
15852
  case "end":
15389
- return _context6.stop();
15853
+ return _context7.stop();
15390
15854
  }
15391
- }, _callee6, this);
15855
+ }, _callee7, this);
15392
15856
  }));
15393
15857
  function switchURL(_x6, _x7) {
15394
15858
  return _switchURL.apply(this, arguments);
@@ -15398,16 +15862,16 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
15398
15862
  }, {
15399
15863
  key: "destroy",
15400
15864
  value: function() {
15401
- var _destroy = _asyncToGenerator$b(/* @__PURE__ */ _regeneratorRuntime$b().mark(function _callee7() {
15402
- return _regeneratorRuntime$b().wrap(function _callee7$(_context7) {
15865
+ var _destroy = _asyncToGenerator$b(/* @__PURE__ */ _regeneratorRuntime$b().mark(function _callee8() {
15866
+ return _regeneratorRuntime$b().wrap(function _callee8$(_context8) {
15403
15867
  while (1)
15404
- switch (_context7.prev = _context7.next) {
15868
+ switch (_context8.prev = _context8.next) {
15405
15869
  case 0:
15406
15870
  if (this.media) {
15407
- _context7.next = 2;
15871
+ _context8.next = 2;
15408
15872
  break;
15409
15873
  }
15410
- return _context7.abrupt("return");
15874
+ return _context8.abrupt("return");
15411
15875
  case 2:
15412
15876
  this.removeAllListeners();
15413
15877
  this._seiService.reset();
@@ -15417,16 +15881,16 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
15417
15881
  this.media.removeEventListener("timeupdate", this._onTimeupdate);
15418
15882
  this.media.removeEventListener("waiting", this._onWaiting);
15419
15883
  this.media.removeEventListener("progress", this._onBufferUpdate);
15420
- _context7.next = 12;
15884
+ _context8.next = 12;
15421
15885
  return Promise.all([this._clear(), this._bufferService.destroy()]);
15422
15886
  case 12:
15423
15887
  this.media = null;
15424
15888
  this._bufferService = null;
15425
15889
  case 14:
15426
15890
  case "end":
15427
- return _context7.stop();
15891
+ return _context8.stop();
15428
15892
  }
15429
- }, _callee7, this);
15893
+ }, _callee8, this);
15430
15894
  }));
15431
15895
  function destroy() {
15432
15896
  return _destroy.apply(this, arguments);
@@ -15455,26 +15919,26 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
15455
15919
  }, {
15456
15920
  key: "_reset",
15457
15921
  value: function() {
15458
- var _reset2 = _asyncToGenerator$b(/* @__PURE__ */ _regeneratorRuntime$b().mark(function _callee8() {
15459
- var reuseMse, _args8 = arguments;
15460
- return _regeneratorRuntime$b().wrap(function _callee8$(_context8) {
15922
+ var _reset2 = _asyncToGenerator$b(/* @__PURE__ */ _regeneratorRuntime$b().mark(function _callee9() {
15923
+ var reuseMse, _args9 = arguments;
15924
+ return _regeneratorRuntime$b().wrap(function _callee9$(_context9) {
15461
15925
  while (1)
15462
- switch (_context8.prev = _context8.next) {
15926
+ switch (_context9.prev = _context9.next) {
15463
15927
  case 0:
15464
- reuseMse = _args8.length > 0 && _args8[0] !== void 0 ? _args8[0] : false;
15928
+ reuseMse = _args9.length > 0 && _args9[0] !== void 0 ? _args9[0] : false;
15465
15929
  this._seiService.reset();
15466
15930
  this._bandwidthService.reset();
15467
15931
  this._stats.reset();
15468
- _context8.next = 6;
15932
+ _context9.next = 6;
15469
15933
  return this._clear();
15470
15934
  case 6:
15471
- _context8.next = 8;
15935
+ _context9.next = 8;
15472
15936
  return this._bufferService.reset(reuseMse);
15473
15937
  case 8:
15474
15938
  case "end":
15475
- return _context8.stop();
15939
+ return _context9.stop();
15476
15940
  }
15477
- }, _callee8, this);
15941
+ }, _callee9, this);
15478
15942
  }));
15479
15943
  function _reset() {
15480
15944
  return _reset2.apply(this, arguments);
@@ -15484,17 +15948,17 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
15484
15948
  }, {
15485
15949
  key: "_loadData",
15486
15950
  value: function() {
15487
- var _loadData2 = _asyncToGenerator$b(/* @__PURE__ */ _regeneratorRuntime$b().mark(function _callee9(url, range) {
15951
+ var _loadData2 = _asyncToGenerator$b(/* @__PURE__ */ _regeneratorRuntime$b().mark(function _callee10(url, range) {
15488
15952
  var finnalUrl;
15489
- return _regeneratorRuntime$b().wrap(function _callee9$(_context9) {
15953
+ return _regeneratorRuntime$b().wrap(function _callee10$(_context10) {
15490
15954
  while (1)
15491
- switch (_context9.prev = _context9.next) {
15955
+ switch (_context10.prev = _context10.next) {
15492
15956
  case 0:
15493
15957
  if (url)
15494
15958
  this._opts.url = url;
15495
15959
  finnalUrl = url = this._opts.url;
15496
15960
  if (url) {
15497
- _context9.next = 4;
15961
+ _context10.next = 4;
15498
15962
  break;
15499
15963
  }
15500
15964
  throw new Error("Source url is missing");
@@ -15509,34 +15973,34 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
15509
15973
  });
15510
15974
  logger$a.debug("load data, loading:", this._loading, finnalUrl);
15511
15975
  if (!this._loading) {
15512
- _context9.next = 11;
15976
+ _context10.next = 11;
15513
15977
  break;
15514
15978
  }
15515
- _context9.next = 11;
15979
+ _context10.next = 11;
15516
15980
  return this._mediaLoader.cancel();
15517
15981
  case 11:
15518
15982
  this._loading = true;
15519
- _context9.prev = 12;
15520
- _context9.next = 15;
15983
+ _context10.prev = 12;
15984
+ _context10.next = 15;
15521
15985
  return this._mediaLoader.load({
15522
15986
  url: finnalUrl,
15523
15987
  range
15524
15988
  });
15525
15989
  case 15:
15526
- _context9.next = 21;
15990
+ _context10.next = 21;
15527
15991
  break;
15528
15992
  case 17:
15529
- _context9.prev = 17;
15530
- _context9.t0 = _context9["catch"](12);
15993
+ _context10.prev = 17;
15994
+ _context10.t0 = _context10["catch"](12);
15531
15995
  this._loading = false;
15532
- return _context9.abrupt("return", this._emitError(StreamingError$3.network(_context9.t0), false));
15996
+ return _context10.abrupt("return", this._emitError(StreamingError$3.network(_context10.t0), false));
15533
15997
  case 21:
15534
15998
  case "end":
15535
- return _context9.stop();
15999
+ return _context10.stop();
15536
16000
  }
15537
- }, _callee9, this, [[12, 17]]);
16001
+ }, _callee10, this, [[12, 17]]);
15538
16002
  }));
15539
- function _loadData(_x8, _x9) {
16003
+ function _loadData(_x9, _x10) {
15540
16004
  return _loadData2.apply(this, arguments);
15541
16005
  }
15542
16006
  return _loadData;
@@ -15544,16 +16008,16 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
15544
16008
  }, {
15545
16009
  key: "_clear",
15546
16010
  value: function() {
15547
- var _clear2 = _asyncToGenerator$b(/* @__PURE__ */ _regeneratorRuntime$b().mark(function _callee10() {
15548
- return _regeneratorRuntime$b().wrap(function _callee10$(_context10) {
16011
+ var _clear2 = _asyncToGenerator$b(/* @__PURE__ */ _regeneratorRuntime$b().mark(function _callee11() {
16012
+ return _regeneratorRuntime$b().wrap(function _callee11$(_context11) {
15549
16013
  while (1)
15550
- switch (_context10.prev = _context10.next) {
16014
+ switch (_context11.prev = _context11.next) {
15551
16015
  case 0:
15552
16016
  if (!this._mediaLoader) {
15553
- _context10.next = 3;
16017
+ _context11.next = 3;
15554
16018
  break;
15555
16019
  }
15556
- _context10.next = 3;
16020
+ _context11.next = 3;
15557
16021
  return this._mediaLoader.cancel();
15558
16022
  case 3:
15559
16023
  clearTimeout(this._maxChunkWaitTimer);
@@ -15562,9 +16026,9 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
15562
16026
  this._firstProgressEmit = false;
15563
16027
  case 7:
15564
16028
  case "end":
15565
- return _context10.stop();
16029
+ return _context11.stop();
15566
16030
  }
15567
- }, _callee10, this);
16031
+ }, _callee11, this);
15568
16032
  }));
15569
16033
  function _clear() {
15570
16034
  return _clear2.apply(this, arguments);
@@ -15651,9 +16115,13 @@ var PluginExtension$1 = /* @__PURE__ */ function() {
15651
16115
  _createClass$m(PluginExtension2, [{
15652
16116
  key: "_init",
15653
16117
  value: function _init() {
15654
- var _this$_opts2 = this._opts, media = _this$_opts2.media, preloadTime = _this$_opts2.preloadTime, innerDegrade = _this$_opts2.innerDegrade, decodeMode = _this$_opts2.decodeMode;
16118
+ var _this$_opts2 = this._opts, media = _this$_opts2.media, isLive = _this$_opts2.isLive, preloadTime = _this$_opts2.preloadTime, innerDegrade = _this$_opts2.innerDegrade, decodeMode = _this$_opts2.decodeMode;
15655
16119
  if (!media)
15656
16120
  return;
16121
+ if (!isLive && media.setPlayMode) {
16122
+ media.setPlayMode("VOD");
16123
+ return;
16124
+ }
15657
16125
  if (innerDegrade) {
15658
16126
  media.setAttribute("innerdegrade", innerDegrade);
15659
16127
  }
@@ -15691,6 +16159,7 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
15691
16159
  args[_key] = arguments[_key];
15692
16160
  }
15693
16161
  _this = _super.call.apply(_super, [this].concat(args));
16162
+ _defineProperty$k(_assertThisInitialized$i(_this), "logger", logger$a);
15694
16163
  _defineProperty$k(_assertThisInitialized$i(_this), "flv", null);
15695
16164
  _defineProperty$k(_assertThisInitialized$i(_this), "pluginExtension", null);
15696
16165
  _defineProperty$k(_assertThisInitialized$i(_this), "getStats", function() {
@@ -15758,11 +16227,17 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
15758
16227
  var _this$flv3;
15759
16228
  return (_this$flv3 = this.flv) === null || _this$flv3 === void 0 ? void 0 : _this$flv3.loader;
15760
16229
  }
16230
+ }, {
16231
+ key: "transferCost",
16232
+ get: function get3() {
16233
+ return this.flv._transferCost.transferCost;
16234
+ }
15761
16235
  }, {
15762
16236
  key: "beforePlayerInit",
15763
16237
  value: function beforePlayerInit() {
15764
16238
  var _this2 = this;
15765
16239
  var config = this.player.config;
16240
+ var mediaElem = this.player.media || this.player.video;
15766
16241
  if (!config.url)
15767
16242
  return;
15768
16243
  if (this.flv)
@@ -15775,10 +16250,10 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
15775
16250
  this.flv = new Flv(_objectSpread2$b({
15776
16251
  softDecode: this.softDecode,
15777
16252
  isLive: config.isLive,
15778
- media: this.player.video,
16253
+ media: mediaElem,
15779
16254
  preProcessUrl: function preProcessUrl(url, ext) {
15780
- var _this2$player$preProc, _this2$player;
15781
- return ((_this2$player$preProc = (_this2$player = _this2.player).preProcessUrl) === null || _this2$player$preProc === void 0 ? void 0 : _this2$player$preProc.call(_this2$player, url, ext)) || {
16255
+ var _this2$player, _this2$player$preProc;
16256
+ return ((_this2$player = _this2.player) === null || _this2$player === void 0 ? void 0 : (_this2$player$preProc = _this2$player.preProcessUrl) === null || _this2$player$preProc === void 0 ? void 0 : _this2$player$preProc.call(_this2$player, url, ext)) || {
15782
16257
  url,
15783
16258
  ext
15784
16259
  };
@@ -15797,7 +16272,8 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
15797
16272
  }
15798
16273
  if (this.softDecode) {
15799
16274
  this.pluginExtension = new PluginExtension$1(_objectSpread2$b({
15800
- media: this.player.video
16275
+ media: this.player.video,
16276
+ isLive: config.isLive
15801
16277
  }, config.flv), this);
15802
16278
  this.player.forceDegradeToVideo = function() {
15803
16279
  var _this2$pluginExtensio;
@@ -15824,6 +16300,7 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
15824
16300
  this._transCoreEvent(EVENT$3.LOAD_RETRY);
15825
16301
  this._transCoreEvent(EVENT$3.SOURCEBUFFER_CREATED);
15826
16302
  this._transCoreEvent(EVENT$3.ANALYZE_DURATION_EXCEEDED);
16303
+ this._transCoreEvent(EVENT$3.APPEND_BUFFER);
15827
16304
  this._transCoreEvent(EVENT$3.REMOVE_BUFFER);
15828
16305
  this._transCoreEvent(EVENT$3.BUFFEREOS);
15829
16306
  this._transCoreEvent(EVENT$3.KEYFRAME);
@@ -30821,7 +31298,7 @@ function _arrayLikeToArray$c(arr, len) {
30821
31298
  arr2[i] = arr[i];
30822
31299
  return arr2;
30823
31300
  }
30824
- function _createForOfIteratorHelper$3(o, allowArrayLike) {
31301
+ function _createForOfIteratorHelper$4(o, allowArrayLike) {
30825
31302
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
30826
31303
  if (!it) {
30827
31304
  if (Array.isArray(o) || (it = _unsupportedIterableToArray$c(o)) || allowArrayLike && o && typeof o.length === "number") {
@@ -32102,7 +32579,7 @@ var XhrLoader$2 = /* @__PURE__ */ function(_EventEmitter) {
32102
32579
  value: function _getHeaders(xhr) {
32103
32580
  var headerLines = xhr.getAllResponseHeaders().trim().split("\r\n");
32104
32581
  var headers = {};
32105
- var _iterator = _createForOfIteratorHelper$3(headerLines), _step;
32582
+ var _iterator = _createForOfIteratorHelper$4(headerLines), _step;
32106
32583
  try {
32107
32584
  for (_iterator.s(); !(_step = _iterator.n()).done; ) {
32108
32585
  var header = _step.value;
@@ -32124,7 +32601,7 @@ var XhrLoader$2 = /* @__PURE__ */ function(_EventEmitter) {
32124
32601
  }]);
32125
32602
  return XhrLoader2;
32126
32603
  }(EventEmitter$1);
32127
- var _excluded$4 = ["retry", "retryDelay", "onRetryError", "transformError"];
32604
+ var _excluded$5 = ["retry", "retryDelay", "onRetryError", "transformError"];
32128
32605
  var Task$2 = /* @__PURE__ */ function() {
32129
32606
  function Task2(type, config) {
32130
32607
  _classCallCheck$g(this, Task2);
@@ -32144,7 +32621,7 @@ var Task$2 = /* @__PURE__ */ function() {
32144
32621
  key: "exec",
32145
32622
  value: function exec2() {
32146
32623
  var _this = this;
32147
- var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties$4(_this$_config, _excluded$4);
32624
+ var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties$4(_this$_config, _excluded$5);
32148
32625
  var request = /* @__PURE__ */ function() {
32149
32626
  var _ref = _asyncToGenerator$8(/* @__PURE__ */ _regeneratorRuntime$8().mark(function _callee() {
32150
32627
  var response, error, isRetry;
@@ -35258,7 +35735,7 @@ function _arrayLikeToArray$a(arr, len) {
35258
35735
  arr2[i] = arr[i];
35259
35736
  return arr2;
35260
35737
  }
35261
- function _createForOfIteratorHelper$2(o, allowArrayLike) {
35738
+ function _createForOfIteratorHelper$3(o, allowArrayLike) {
35262
35739
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
35263
35740
  if (!it) {
35264
35741
  if (Array.isArray(o) || (it = _unsupportedIterableToArray$a(o)) || allowArrayLike && o && typeof o.length === "number") {
@@ -35613,7 +36090,7 @@ var Logger$7 = /* @__PURE__ */ function() {
35613
36090
  this.logCache.apply(this, [LogCacheLevel$1.DEBUG].concat(args));
35614
36091
  if (Logger2.disabled)
35615
36092
  return;
35616
- (_console = console).debug.apply(_console, [this._prefix, nowTime$5()].concat(args));
36093
+ (_console = console).debug.apply(_console, ["[".concat(nowTime$5(), "]"), this._prefix].concat(args));
35617
36094
  }
35618
36095
  }, {
35619
36096
  key: "log",
@@ -35625,7 +36102,7 @@ var Logger$7 = /* @__PURE__ */ function() {
35625
36102
  this.logCache.apply(this, [LogCacheLevel$1.LOG].concat(args));
35626
36103
  if (Logger2.disabled)
35627
36104
  return;
35628
- (_console2 = console).log.apply(_console2, [this._prefix, nowTime$5()].concat(args));
36105
+ (_console2 = console).log.apply(_console2, ["[".concat(nowTime$5(), "]"), this._prefix].concat(args));
35629
36106
  }
35630
36107
  }, {
35631
36108
  key: "warn",
@@ -35637,7 +36114,7 @@ var Logger$7 = /* @__PURE__ */ function() {
35637
36114
  this.logCache.apply(this, [LogCacheLevel$1.WARN].concat(args));
35638
36115
  if (Logger2.disabled)
35639
36116
  return;
35640
- (_console3 = console).warn.apply(_console3, [this._prefix, nowTime$5()].concat(args));
36117
+ (_console3 = console).warn.apply(_console3, ["[".concat(nowTime$5(), "]"), this._prefix].concat(args));
35641
36118
  }
35642
36119
  }, {
35643
36120
  key: "error",
@@ -35649,7 +36126,7 @@ var Logger$7 = /* @__PURE__ */ function() {
35649
36126
  this.logCache.apply(this, [LogCacheLevel$1.ERROR].concat(args));
35650
36127
  if (Logger2.disabled)
35651
36128
  return;
35652
- (_console4 = console).error.apply(_console4, [this._prefix, nowTime$5()].concat(args));
36129
+ (_console4 = console).error.apply(_console4, ["[".concat(nowTime$5(), "]"), this._prefix].concat(args));
35653
36130
  }
35654
36131
  }, {
35655
36132
  key: "logCache",
@@ -35664,7 +36141,7 @@ var Logger$7 = /* @__PURE__ */ function() {
35664
36141
  var finLogText = logText.map(function(item) {
35665
36142
  return logable$1(item);
35666
36143
  });
35667
- text = this._prefix + nowTime$5() + JSON.stringify(finLogText);
36144
+ text = "[".concat(nowTime$5(), "]") + this._prefix + JSON.stringify(finLogText);
35668
36145
  } catch (e) {
35669
36146
  return;
35670
36147
  }
@@ -36580,8 +37057,8 @@ function createResponse$1(data2, done, response, contentLength, age, startTime,
36580
37057
  response
36581
37058
  };
36582
37059
  }
36583
- function calculateSpeed$1(byteLen, millisec) {
36584
- return Math.round(byteLen * 8 * 1e3 / millisec / 1024);
37060
+ function calculateSpeed$1(byteLen, milliSecond) {
37061
+ return Math.round(byteLen * 8 * 1e3 / milliSecond / 1024);
36585
37062
  }
36586
37063
  var EVENT$1 = {
36587
37064
  ERROR: "error",
@@ -36593,6 +37070,7 @@ var EVENT$1 = {
36593
37070
  SOURCEBUFFER_CREATED: "core.sourcebuffercreated",
36594
37071
  MEDIASOURCE_OPENED: "core.mediasourceopened",
36595
37072
  ANALYZE_DURATION_EXCEEDED: "core.analyzedurationexceeded",
37073
+ APPEND_BUFFER: "core.appendbuffer",
36596
37074
  REMOVE_BUFFER: "core.removebuffer",
36597
37075
  BUFFEREOS: "core.buffereos",
36598
37076
  KEYFRAME: "core.keyframe",
@@ -37365,7 +37843,7 @@ var XhrLoader$1 = /* @__PURE__ */ function(_EventEmitter) {
37365
37843
  value: function _getHeaders(xhr) {
37366
37844
  var headerLines = xhr.getAllResponseHeaders().trim().split("\r\n");
37367
37845
  var headers = {};
37368
- var _iterator = _createForOfIteratorHelper$2(headerLines), _step;
37846
+ var _iterator = _createForOfIteratorHelper$3(headerLines), _step;
37369
37847
  try {
37370
37848
  for (_iterator.s(); !(_step = _iterator.n()).done; ) {
37371
37849
  var header = _step.value;
@@ -37387,7 +37865,7 @@ var XhrLoader$1 = /* @__PURE__ */ function(_EventEmitter) {
37387
37865
  }]);
37388
37866
  return XhrLoader2;
37389
37867
  }(EventEmitter$1);
37390
- var _excluded$3 = ["retry", "retryDelay", "onRetryError", "transformError"];
37868
+ var _excluded$4 = ["retry", "retryDelay", "onRetryError", "transformError"];
37391
37869
  var Task$1 = /* @__PURE__ */ function() {
37392
37870
  function Task2(type, config) {
37393
37871
  _classCallCheck$e(this, Task2);
@@ -37407,7 +37885,7 @@ var Task$1 = /* @__PURE__ */ function() {
37407
37885
  key: "exec",
37408
37886
  value: function exec2() {
37409
37887
  var _this = this;
37410
- var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties$2(_this$_config, _excluded$3);
37888
+ var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties$2(_this$_config, _excluded$4);
37411
37889
  var request = /* @__PURE__ */ function() {
37412
37890
  var _ref = _asyncToGenerator$6(/* @__PURE__ */ _regeneratorRuntime$6().mark(function _callee() {
37413
37891
  var response, error, isRetry;
@@ -38203,6 +38681,60 @@ function _nonIterableSpread$6() {
38203
38681
  function _nonIterableRest$5() {
38204
38682
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
38205
38683
  }
38684
+ function _createForOfIteratorHelper$2(o, allowArrayLike) {
38685
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
38686
+ if (!it) {
38687
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray$9(o)) || allowArrayLike && o && typeof o.length === "number") {
38688
+ if (it)
38689
+ o = it;
38690
+ var i = 0;
38691
+ var F = function() {
38692
+ };
38693
+ return {
38694
+ s: F,
38695
+ n: function() {
38696
+ if (i >= o.length)
38697
+ return {
38698
+ done: true
38699
+ };
38700
+ return {
38701
+ done: false,
38702
+ value: o[i++]
38703
+ };
38704
+ },
38705
+ e: function(e) {
38706
+ throw e;
38707
+ },
38708
+ f: F
38709
+ };
38710
+ }
38711
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
38712
+ }
38713
+ var normalCompletion = true, didErr = false, err;
38714
+ return {
38715
+ s: function() {
38716
+ it = it.call(o);
38717
+ },
38718
+ n: function() {
38719
+ var step = it.next();
38720
+ normalCompletion = step.done;
38721
+ return step;
38722
+ },
38723
+ e: function(e) {
38724
+ didErr = true;
38725
+ err = e;
38726
+ },
38727
+ f: function() {
38728
+ try {
38729
+ if (!normalCompletion && it.return != null)
38730
+ it.return();
38731
+ } finally {
38732
+ if (didErr)
38733
+ throw err;
38734
+ }
38735
+ }
38736
+ };
38737
+ }
38206
38738
  function _toPrimitive$3(input, hint) {
38207
38739
  if (typeof input !== "object" || input === null)
38208
38740
  return input;
@@ -38225,13 +38757,16 @@ var TrackType$2 = {
38225
38757
  METADATA: "metadata"
38226
38758
  };
38227
38759
  var VideoCodecType$2 = {
38760
+ AV1: "av1",
38228
38761
  AVC: "avc",
38229
38762
  HEVC: "hevc"
38230
38763
  };
38231
38764
  var AudioCodecType$1 = {
38232
38765
  AAC: "aac",
38233
38766
  G711PCMA: "g7110a",
38234
- G711PCMU: "g7110m"
38767
+ G711PCMU: "g7110m",
38768
+ OPUS: "opus",
38769
+ MP3: "mp3"
38235
38770
  };
38236
38771
  var WarningType = {
38237
38772
  LARGE_AV_SHIFT: "LARGE_AV_SHIFT",
@@ -38271,6 +38806,7 @@ var VideoTrack$1 = /* @__PURE__ */ function() {
38271
38806
  _defineProperty$b(this, "isVideoEncryption", false);
38272
38807
  _defineProperty$b(this, "isAudioEncryption", false);
38273
38808
  _defineProperty$b(this, "isVideo", true);
38809
+ _defineProperty$b(this, "lastKeyFrameDts", 0);
38274
38810
  _defineProperty$b(this, "kid", null);
38275
38811
  _defineProperty$b(this, "pssh", null);
38276
38812
  _defineProperty$b(this, "ext", void 0);
@@ -38313,6 +38849,9 @@ var VideoTrack$1 = /* @__PURE__ */ function() {
38313
38849
  }, {
38314
38850
  key: "exist",
38315
38851
  value: function exist() {
38852
+ if (/av01/.test(this.codec)) {
38853
+ return true;
38854
+ }
38316
38855
  return !!(this.pps.length && this.sps.length && this.codec);
38317
38856
  }
38318
38857
  }, {
@@ -38336,6 +38875,7 @@ var AudioTrack$1 = /* @__PURE__ */ function() {
38336
38875
  _defineProperty$b(this, "codecType", AudioCodecType$1.AAC);
38337
38876
  _defineProperty$b(this, "pid", -1);
38338
38877
  _defineProperty$b(this, "codec", "");
38878
+ _defineProperty$b(this, "container", "");
38339
38879
  _defineProperty$b(this, "sequenceNumber", 0);
38340
38880
  _defineProperty$b(this, "sampleDuration", 0);
38341
38881
  _defineProperty$b(this, "timescale", 0);
@@ -38376,7 +38916,7 @@ var AudioTrack$1 = /* @__PURE__ */ function() {
38376
38916
  }, {
38377
38917
  key: "exist",
38378
38918
  value: function exist() {
38379
- return !!(this.sampleRate && this.channelCount && this.codec && this.codecType === AudioCodecType$1.AAC);
38919
+ return !!(this.sampleRate && this.channelCount && (this.codec || this.container) && (this.codecType === AudioCodecType$1.AAC || this.codecType === AudioCodecType$1.G711PCMA || this.codecType === AudioCodecType$1.G711PCMU || this.codecType === AudioCodecType$1.OPUS || this.codecType === AudioCodecType$1.MP3));
38380
38920
  }
38381
38921
  }, {
38382
38922
  key: "hasSample",
@@ -39764,6 +40304,119 @@ var TsFixer = /* @__PURE__ */ function() {
39764
40304
  }]);
39765
40305
  return TsFixer2;
39766
40306
  }();
40307
+ 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];
40308
+ var FREQ = [44100, 48e3, 32e3, 22050, 24e3, 16e3, 11025, 12e3, 8e3];
40309
+ var SamplesCoefficients = [
40310
+ [
40311
+ 0,
40312
+ 72,
40313
+ 144,
40314
+ 12
40315
+ ],
40316
+ [
40317
+ 0,
40318
+ 0,
40319
+ 0,
40320
+ 0
40321
+ ],
40322
+ [
40323
+ 0,
40324
+ 72,
40325
+ 144,
40326
+ 12
40327
+ ],
40328
+ [
40329
+ 0,
40330
+ 144,
40331
+ 144,
40332
+ 12
40333
+ ]
40334
+ ];
40335
+ var BytesInSlot = [
40336
+ 0,
40337
+ 1,
40338
+ 1,
40339
+ 4
40340
+ ];
40341
+ var chromeVersion = null;
40342
+ var MPEG = /* @__PURE__ */ function() {
40343
+ function MPEG2() {
40344
+ _classCallCheck$d(this, MPEG2);
40345
+ }
40346
+ _createClass$d(MPEG2, null, [{
40347
+ key: "isHeader",
40348
+ value: function isHeader(data2, offset) {
40349
+ return offset + 1 < data2.length && data2[offset] === 255 && (data2[offset + 1] & 224) === 224 && (data2[offset + 1] & 6) !== 0;
40350
+ }
40351
+ }, {
40352
+ key: "appendFrame",
40353
+ value: function appendFrame(track, data2, offset, pts, frameIndex) {
40354
+ if (offset + 24 > data2.length) {
40355
+ return;
40356
+ }
40357
+ var header = MPEG2.parseHeader(data2, offset);
40358
+ if (header && offset + header.frameLength <= data2.length) {
40359
+ var frameDuration = header.samplesPerFrame * 9e4 / header.sampleRate;
40360
+ var stamp = pts + frameIndex * frameDuration;
40361
+ var sample = {
40362
+ data: data2.subarray(offset, offset + header.frameLength),
40363
+ pts: stamp,
40364
+ dts: stamp
40365
+ };
40366
+ sample.size = sample.data.byteLength;
40367
+ track.config = [];
40368
+ track.channelCount = header.channelCount;
40369
+ track.sampleRate = header.sampleRate;
40370
+ if (isFirefox$1) {
40371
+ track.codec = "mp3";
40372
+ } else {
40373
+ track.container = "audio/mpeg";
40374
+ }
40375
+ track.samples.push(sample);
40376
+ return {
40377
+ length: header.frameLength
40378
+ };
40379
+ }
40380
+ }
40381
+ }, {
40382
+ key: "parseHeader",
40383
+ value: function parseHeader(data2, offset) {
40384
+ var mpegVersion = data2[offset + 1] >> 3 & 3;
40385
+ var mpegLayer = data2[offset + 1] >> 1 & 3;
40386
+ var bitRateIndex = data2[offset + 2] >> 4 & 15;
40387
+ var sampleRateIndex = data2[offset + 2] >> 2 & 3;
40388
+ if (mpegVersion !== 1 && bitRateIndex !== 0 && bitRateIndex !== 15 && sampleRateIndex !== 3) {
40389
+ var paddingBit = data2[offset + 2] >> 1 & 1;
40390
+ var channelMode = data2[offset + 3] >> 6;
40391
+ var columnInBitrates = mpegVersion === 3 ? 3 - mpegLayer : mpegLayer === 3 ? 3 : 4;
40392
+ var bitRate = BitratesMap[columnInBitrates * 14 + bitRateIndex - 1] * 1e3;
40393
+ var columnInSampleRates = mpegVersion === 3 ? 0 : mpegVersion === 2 ? 1 : 2;
40394
+ var sampleRate = FREQ[columnInSampleRates * 3 + sampleRateIndex];
40395
+ var channelCount = channelMode === 3 ? 1 : 2;
40396
+ var sampleCoefficient = SamplesCoefficients[mpegVersion][mpegLayer];
40397
+ var bytesInSlot = BytesInSlot[mpegLayer];
40398
+ var samplesPerFrame = sampleCoefficient * 8 * bytesInSlot;
40399
+ var frameLength = Math.floor(sampleCoefficient * bitRate / sampleRate + paddingBit) * bytesInSlot;
40400
+ if (chromeVersion === null) {
40401
+ var userAgent2 = navigator.userAgent || "";
40402
+ var result = userAgent2.match(/Chrome\/(\d+)/i);
40403
+ chromeVersion = result ? parseInt(result[1]) : 0;
40404
+ }
40405
+ var needChromeFix = !!chromeVersion && chromeVersion <= 87;
40406
+ if (needChromeFix && mpegLayer === 2 && bitRate >= 224e3 && channelMode === 0) {
40407
+ data2[offset + 3] = data2[offset + 3] | 128;
40408
+ }
40409
+ return {
40410
+ sampleRate,
40411
+ channelCount,
40412
+ frameLength,
40413
+ samplesPerFrame
40414
+ };
40415
+ }
40416
+ }
40417
+ }]);
40418
+ return MPEG2;
40419
+ }();
39767
40420
  var logger$8 = new Logger$6("TsDemuxer");
39768
40421
  var TsDemuxer = /* @__PURE__ */ function() {
39769
40422
  function TsDemuxer2(videoTrack, audioTrack, metadataTrack) {
@@ -39847,6 +40500,13 @@ var TsDemuxer = /* @__PURE__ */ function() {
39847
40500
  case 15:
39848
40501
  audioTrack.pid = audioPid = esPid;
39849
40502
  break;
40503
+ case 3:
40504
+ case 4:
40505
+ if (audioTrack.pid === -1) {
40506
+ audioTrack.pid = audioPid = esPid;
40507
+ audioTrack.codecType = AudioCodecType$1.MP3;
40508
+ }
40509
+ break;
39850
40510
  case 27:
39851
40511
  if (videoPid !== -1)
39852
40512
  break;
@@ -40046,7 +40706,14 @@ var TsDemuxer = /* @__PURE__ */ function() {
40046
40706
  logger$8.warn("Cannot parse audio pes", this._audioPesData);
40047
40707
  return;
40048
40708
  }
40049
- this._parseAacData(pes);
40709
+ switch (this.audioTrack.codecType) {
40710
+ case AudioCodecType$1.AAC:
40711
+ this._parseAacData(pes);
40712
+ break;
40713
+ case AudioCodecType$1.MP3:
40714
+ this._parseMPEG(pes);
40715
+ break;
40716
+ }
40050
40717
  this._audioPesData = [];
40051
40718
  }
40052
40719
  }, {
@@ -40083,6 +40750,32 @@ var TsDemuxer = /* @__PURE__ */ function() {
40083
40750
  logger$8.warn("Cannot parse aac adts", pes);
40084
40751
  }
40085
40752
  }
40753
+ }, {
40754
+ key: "_parseMPEG",
40755
+ value: function _parseMPEG(pes) {
40756
+ var data2 = pes.data;
40757
+ var length = data2.length;
40758
+ var frameIndex = 0;
40759
+ var offset = 0;
40760
+ var pts = pes.pts;
40761
+ if (pts === void 0) {
40762
+ logger$8.warn("[tsdemuxer]: MPEG PES unknown PTS");
40763
+ return;
40764
+ }
40765
+ while (offset < length) {
40766
+ if (MPEG.isHeader(data2, offset)) {
40767
+ var frame = MPEG.appendFrame(this.audioTrack, data2, offset, pts, frameIndex);
40768
+ if (frame) {
40769
+ offset += frame.length;
40770
+ frameIndex++;
40771
+ } else {
40772
+ break;
40773
+ }
40774
+ } else {
40775
+ offset++;
40776
+ }
40777
+ }
40778
+ }
40086
40779
  }], [{
40087
40780
  key: "probe",
40088
40781
  value: function probe(data2) {
@@ -40129,7 +40822,7 @@ var ByteReader = /* @__PURE__ */ function() {
40129
40822
  _classCallCheck$d(this, ByteReader2);
40130
40823
  this.dv = new DataView(buf);
40131
40824
  this.start = this.offset = offset || this.dv.byteOffset;
40132
- this.end = len ? this.start + len : this.dv.byteLength;
40825
+ this.end = len ? this.start + len : this.start + this.dv.byteLength;
40133
40826
  }
40134
40827
  _createClass$d(ByteReader2, [{
40135
40828
  key: "buffer",
@@ -40231,7 +40924,7 @@ var ByteReader = /* @__PURE__ */ function() {
40231
40924
  value: function readToBuffer(len) {
40232
40925
  var buffer2;
40233
40926
  if (this.offset || len) {
40234
- buffer2 = this.dv.buffer.slice(this.offset, len ? this.offset + len : void 0);
40927
+ buffer2 = this.dv.buffer.slice(this.offset, len ? this.offset + len : this.end);
40235
40928
  } else {
40236
40929
  buffer2 = this.dv.buffer;
40237
40930
  }
@@ -40284,6 +40977,47 @@ var ByteReader = /* @__PURE__ */ function() {
40284
40977
  }]);
40285
40978
  return ByteReader2;
40286
40979
  }();
40980
+ var BitReader = /* @__PURE__ */ function() {
40981
+ function BitReader2(val, size) {
40982
+ _classCallCheck$d(this, BitReader2);
40983
+ this.offset = 0;
40984
+ this.val = val;
40985
+ this.size = size;
40986
+ }
40987
+ _createClass$d(BitReader2, [{
40988
+ key: "skip",
40989
+ value: function skip(len) {
40990
+ this.offset += len;
40991
+ }
40992
+ }, {
40993
+ key: "read",
40994
+ value: function read(len) {
40995
+ var unreadLength = this.size - this.offset - len;
40996
+ if (unreadLength >= 0) {
40997
+ var bits = 0, i = 0;
40998
+ this.offset += len;
40999
+ if (this.size > 31) {
41000
+ for (; i < len; i++) {
41001
+ bits += Math.pow(2, i);
41002
+ }
41003
+ return this.val / Math.pow(2, unreadLength) & bits;
41004
+ } else {
41005
+ for (; i < len; i++) {
41006
+ bits += 1 << i;
41007
+ }
41008
+ return this.val >>> unreadLength & bits;
41009
+ }
41010
+ }
41011
+ throw new Error("the number of the read operation exceeds the total length limit of bits");
41012
+ }
41013
+ }], [{
41014
+ key: "fromByte",
41015
+ value: function fromByte(byte, len) {
41016
+ return new BitReader2(byte.read(len), len << 3);
41017
+ }
41018
+ }]);
41019
+ return BitReader2;
41020
+ }();
40287
41021
  var MP4Parser$1 = /* @__PURE__ */ function() {
40288
41022
  function MP4Parser2() {
40289
41023
  _classCallCheck$d(this, MP4Parser2);
@@ -40623,6 +41357,8 @@ var MP4Parser$1 = /* @__PURE__ */ function() {
40623
41357
  ret.entryCount = readBig32$1(data2);
40624
41358
  ret.entries = MP4Parser2.findBox(data2.subarray(4), [], start + 4).map(function(b) {
40625
41359
  switch (b.type) {
41360
+ case "av01":
41361
+ return MP4Parser2.av01(b);
40626
41362
  case "avc1":
40627
41363
  case "avc2":
40628
41364
  case "avc3":
@@ -40702,6 +41438,69 @@ var MP4Parser$1 = /* @__PURE__ */ function() {
40702
41438
  }
40703
41439
  });
40704
41440
  }
41441
+ }, {
41442
+ key: "colr",
41443
+ value: function colr(box) {
41444
+ return parseBox$1(box, false, function(ret, data2) {
41445
+ var byte = ByteReader.fromUint8(data2);
41446
+ ret.data = box.data;
41447
+ ret.colorType = byte.readString(4);
41448
+ if (ret.colorType === "nclx") {
41449
+ ret.colorPrimaries = byte.read(2);
41450
+ ret.transferCharacteristics = byte.read(2);
41451
+ ret.matrixCoefficients = byte.read(2);
41452
+ ret.fullRangeFlag = byte.read(1) >> 7;
41453
+ } else if (ret.colorType === "rICC" || ret.colorType === "prof") {
41454
+ ret.iccProfile = data2.readToUint8();
41455
+ }
41456
+ });
41457
+ }
41458
+ }, {
41459
+ key: "av01",
41460
+ value: function av01(box) {
41461
+ return parseBox$1(box, false, function(ret, data2, start) {
41462
+ var bodyStart = parseVisualSampleEntry$1(ret, data2);
41463
+ var bodyData = data2.subarray(bodyStart);
41464
+ start += bodyStart;
41465
+ ret.av1C = MP4Parser2.av1C(MP4Parser2.findBox(bodyData, ["av1C"], start)[0]);
41466
+ ret.colr = MP4Parser2.colr(MP4Parser2.findBox(bodyData, ["colr"], start)[0]);
41467
+ });
41468
+ }
41469
+ }, {
41470
+ key: "av1C",
41471
+ value: function av1C(box) {
41472
+ return parseBox$1(box, false, function(ret, data2) {
41473
+ ret.data = box.data;
41474
+ var byte = ByteReader.fromUint8(data2);
41475
+ var bit = BitReader.fromByte(byte, 4);
41476
+ ret.marker = bit.read(1);
41477
+ ret.version = bit.read(7);
41478
+ ret.seqProfile = bit.read(3);
41479
+ ret.seqLevelIdx0 = bit.read(5);
41480
+ ret.seqTier0 = bit.read(1);
41481
+ ret.highBitdepth = bit.read(1);
41482
+ ret.twelveBit = bit.read(1);
41483
+ ret.monochrome = bit.read(1);
41484
+ ret.chromaSubsamplingX = bit.read(1);
41485
+ ret.chromaSubsamplingY = bit.read(1);
41486
+ ret.chromaSamplePosition = bit.read(2);
41487
+ ret.reserved = bit.read(3);
41488
+ ret.initialPresentationDelayPresent = bit.read(1);
41489
+ if (ret.initialPresentationDelayPresent) {
41490
+ ret.initialPresentationDelayMinusOne = bit.read(4);
41491
+ } else {
41492
+ ret.initialPresentationDelayMinusOne = 0;
41493
+ }
41494
+ ret.configOBUs = byte.readToUint8();
41495
+ var bitdepth;
41496
+ if (ret.seqLevelIdx0 === 2 && ret.highBitdepth === 1) {
41497
+ bitdepth = ret.twelveBit === 1 ? "12" : "10";
41498
+ } else if (ret.seqProfile <= 2) {
41499
+ bitdepth = ret.highBitdepth === 1 ? "10" : "08";
41500
+ }
41501
+ ret.codec = ["av01", ret.seqProfile, (ret.seqLevelIdx0 < 10 ? "0" + ret.seqLevelIdx0 : ret.seqLevelIdx0) + (ret.seqTier0 ? "H" : "M"), bitdepth].join(".");
41502
+ });
41503
+ }
40705
41504
  }, {
40706
41505
  key: "avc1",
40707
41506
  value: function avc1(box) {
@@ -41135,7 +41934,12 @@ var MP4Parser$1 = /* @__PURE__ */ function() {
41135
41934
  if (e1.pasp) {
41136
41935
  v.sarRatio = [e1.pasp.hSpacing, e1.pasp.vSpacing];
41137
41936
  }
41138
- if (e1.hvcC) {
41937
+ if (e1.av1C) {
41938
+ v.codecType = VideoCodecType$2.AV1;
41939
+ v.codec = e1.av1C.codec;
41940
+ v.av1C = e1.av1C.data;
41941
+ v.colr = e1.colr.data;
41942
+ } else if (e1.hvcC) {
41139
41943
  v.codecType = VideoCodecType$2.HEVC;
41140
41944
  v.codec = e1.hvcC.codec;
41141
41945
  v.vps = e1.hvcC.vps;
@@ -41454,8 +42258,9 @@ function parseAudioSampleEntry$1(ret, data2) {
41454
42258
  function parseBox$1(box, isFullBox, parse4) {
41455
42259
  if (!box)
41456
42260
  return;
41457
- if (box.size !== box.data.length)
42261
+ if (box.size !== box.data.length) {
41458
42262
  throw new Error("box ".concat(box.type, " size !== data.length"));
42263
+ }
41459
42264
  var ret = {
41460
42265
  start: box.start,
41461
42266
  size: box.size,
@@ -41494,11 +42299,167 @@ var toHex$1 = function toHex2() {
41494
42299
  var FMP4Demuxer = /* @__PURE__ */ function() {
41495
42300
  function FMP4Demuxer2(videoTrack, audioTrack, metadataTrack) {
41496
42301
  _classCallCheck$d(this, FMP4Demuxer2);
42302
+ _defineProperty$b(this, "__loadedMoofWraps", []);
42303
+ _defineProperty$b(this, "__lastRemainData", null);
42304
+ _defineProperty$b(this, "__lastRemainDataStart", 0);
42305
+ _defineProperty$b(this, "__nextMoofStart", -1);
41497
42306
  this.videoTrack = videoTrack || new VideoTrack$1();
41498
42307
  this.audioTrack = audioTrack || new AudioTrack$1();
41499
42308
  this.metadataTrack = metadataTrack || new MetadataTrack$1();
41500
42309
  }
41501
42310
  _createClass$d(FMP4Demuxer2, [{
42311
+ key: "demuxPart",
42312
+ value: function demuxPart(partData, partDataStart, moov) {
42313
+ var _this = this;
42314
+ var videoTrack = this.videoTrack, audioTrack = this.audioTrack;
42315
+ var videoExist = videoTrack.exist();
42316
+ var audioExist = audioTrack.exist();
42317
+ var isAV01 = /av01/.test(videoTrack.codec);
42318
+ videoTrack.samples = [];
42319
+ audioTrack.samples = [];
42320
+ var data2 = partData;
42321
+ var dataStart = partDataStart;
42322
+ if (this.__lastRemainData) {
42323
+ var lastRemainDataEnd = this.__lastRemainDataStart + this.__lastRemainData.byteLength;
42324
+ var continuous = partDataStart <= lastRemainDataEnd && partDataStart > this.__lastRemainDataStart && partDataStart + partData.byteLength > lastRemainDataEnd;
42325
+ if (continuous) {
42326
+ var noDuplicateData = partData.subarray(this.__lastRemainData.byteLength + this.__lastRemainDataStart - partDataStart);
42327
+ data2 = concatUint8Array$3(this.__lastRemainData, noDuplicateData);
42328
+ dataStart = this.__lastRemainDataStart;
42329
+ this.__lastRemainData = null;
42330
+ } else {
42331
+ this.__lastRemainData = null;
42332
+ this.__lastRemainDataStart = 0;
42333
+ this.__nextMoofStart = -1;
42334
+ }
42335
+ }
42336
+ if (!moov) {
42337
+ var moovBox = MP4Parser$1.findBox(data2, ["moov"])[0];
42338
+ if (!moovBox)
42339
+ throw new Error("cannot found moov box");
42340
+ moov = MP4Parser$1.moov(moovBox);
42341
+ }
42342
+ if (data2) {
42343
+ var dataEnd = dataStart + data2.byteLength;
42344
+ if (!videoExist && !audioExist) {
42345
+ MP4Parser$1.moovToTrack(moov, videoTrack, audioTrack);
42346
+ }
42347
+ var moofBoxes = [];
42348
+ if (this.__nextMoofStart < 0) {
42349
+ MP4Parser$1.findBox(data2, ["moof"], dataStart).forEach(function(v) {
42350
+ return moofBoxes.push(v);
42351
+ });
42352
+ } else if (this.__nextMoofStart >= dataStart && this.__nextMoofStart <= dataEnd - 8) {
42353
+ MP4Parser$1.findBox(data2.subarray(this.__nextMoofStart - dataStart), ["moof"], this.__nextMoofStart).forEach(function(v) {
42354
+ return moofBoxes.push(v);
42355
+ });
42356
+ }
42357
+ moofBoxes.filter(function(moofBox) {
42358
+ return moofBox.size <= moofBox.data.length;
42359
+ }).forEach(function(moofBox) {
42360
+ var moof = MP4Parser$1.moof(moofBox);
42361
+ _this.__nextMoofStart = moof.start + Math.max.apply(Math, _toConsumableArray$6(moof.traf.map(function(v) {
42362
+ return v.trun.samples.reduce(function(ret, w) {
42363
+ return ret + w.size;
42364
+ }, v.trun.dataOffset || 0);
42365
+ })));
42366
+ _this.__loadedMoofWraps.push({
42367
+ start: moof.start,
42368
+ nextMoofStart: _this.__nextMoofStart,
42369
+ moof
42370
+ });
42371
+ _this.__loadedMoofWraps.sort(function(p, n) {
42372
+ return p.start - n.start;
42373
+ });
42374
+ });
42375
+ var _iterator = _createForOfIteratorHelper$2(this.__loadedMoofWraps), _step;
42376
+ try {
42377
+ var _loop = function _loop2() {
42378
+ var moofWrap = _step.value;
42379
+ if (moofWrap.start > dataEnd || moofWrap.nextMoofStart < dataStart) {
42380
+ return "continue";
42381
+ }
42382
+ var moofStart = moofWrap.start;
42383
+ var tracks = MP4Parser$1.moofToSamples(moofWrap.moof, videoTrack, audioTrack);
42384
+ var videoBaseMediaDecodeTime = videoTrack.baseMediaDecodeTime;
42385
+ var audioBaseMediaDecodeTime = audioTrack.baseMediaDecodeTime;
42386
+ var nalSize;
42387
+ Object.keys(tracks).forEach(function(k) {
42388
+ if (videoTrack.id == k) {
42389
+ tracks[k].some(function(x2) {
42390
+ var xStart = x2.offset += moofStart;
42391
+ if (xStart < dataStart) {
42392
+ return;
42393
+ }
42394
+ if (xStart + x2.size > dataEnd) {
42395
+ return true;
42396
+ }
42397
+ var sample = new VideoSample$1((x2.pts || x2.dts) + videoBaseMediaDecodeTime, x2.dts + videoBaseMediaDecodeTime);
42398
+ sample.duration = x2.duration;
42399
+ sample.gopId = x2.gopId;
42400
+ if (x2.keyframe)
42401
+ sample.setToKeyframe();
42402
+ var sampleData = data2.subarray(xStart - dataStart, xStart - dataStart + x2.size);
42403
+ sample.data = sampleData;
42404
+ if (!isAV01) {
42405
+ var start = 0;
42406
+ var len = sampleData.length - 1;
42407
+ while (start < len) {
42408
+ nalSize = readBig32$1(sampleData, start);
42409
+ start += 4;
42410
+ sample.units.push(sampleData.subarray(start, start + nalSize));
42411
+ start += nalSize;
42412
+ }
42413
+ }
42414
+ _this.__lastRemainDataStart = xStart + x2.size;
42415
+ videoTrack.samples.push(sample);
42416
+ });
42417
+ } else if (audioTrack.id == k) {
42418
+ tracks[k].some(function(x2) {
42419
+ var xStart = x2.offset + moofStart;
42420
+ if (xStart < dataStart) {
42421
+ return;
42422
+ }
42423
+ if (xStart + x2.size > dataEnd) {
42424
+ return true;
42425
+ }
42426
+ var sampleData = data2.subarray(xStart - dataStart, xStart - dataStart + x2.size);
42427
+ audioTrack.samples.push(new AudioSample$1(x2.dts + audioBaseMediaDecodeTime, sampleData, x2.duration));
42428
+ _this.__lastRemainDataStart = xStart + x2.size;
42429
+ });
42430
+ }
42431
+ });
42432
+ };
42433
+ for (_iterator.s(); !(_step = _iterator.n()).done; ) {
42434
+ var _ret = _loop();
42435
+ if (_ret === "continue")
42436
+ continue;
42437
+ }
42438
+ } catch (err) {
42439
+ _iterator.e(err);
42440
+ } finally {
42441
+ _iterator.f();
42442
+ }
42443
+ }
42444
+ if (this.__lastRemainDataStart > dataStart && this.__lastRemainDataStart < data2.byteLength + dataStart) {
42445
+ this.__lastRemainData = data2.subarray(this.__lastRemainDataStart - dataStart);
42446
+ } else {
42447
+ this.__lastRemainData = data2;
42448
+ this.__lastRemainDataStart = dataStart;
42449
+ }
42450
+ if (videoTrack.samples.length) {
42451
+ videoTrack.baseMediaDecodeTime = videoTrack.samples[0].pts;
42452
+ }
42453
+ if (audioTrack.samples.length) {
42454
+ audioTrack.baseMediaDecodeTime = audioTrack.samples[0].pts;
42455
+ }
42456
+ return {
42457
+ videoTrack,
42458
+ audioTrack,
42459
+ metadataTrack: this.metadataTrack
42460
+ };
42461
+ }
42462
+ }, {
41502
42463
  key: "demux",
41503
42464
  value: function demux(videoData, audioData) {
41504
42465
  var videoTrack = this.videoTrack, audioTrack = this.audioTrack;
@@ -41990,10 +42951,16 @@ var MP4$3 = /* @__PURE__ */ function() {
41990
42951
  if (track.useEME && track.enca) {
41991
42952
  content = MP42.enca(track);
41992
42953
  } else {
41993
- content = MP42.mp4a(track);
42954
+ if (track.codecType === AudioCodecType$1.OPUS) {
42955
+ content = MP42.opus(track);
42956
+ } else {
42957
+ content = MP42.mp4a(track);
42958
+ }
41994
42959
  }
41995
42960
  } else if (track.useEME && track.encv) {
41996
42961
  content = MP42.encv(track);
42962
+ } else if (track.av1C) {
42963
+ content = MP42.av01(track);
41997
42964
  } else {
41998
42965
  content = MP42.avc1hev1(track);
41999
42966
  }
@@ -42206,6 +43173,90 @@ var MP4$3 = /* @__PURE__ */ function() {
42206
43173
  var schi = MP42.schi(data2);
42207
43174
  return MP42.box(MP42.types.sinf, content, MP42.box(MP42.types.frma, frma), MP42.box(MP42.types.schm, schm), schi);
42208
43175
  }
43176
+ }, {
43177
+ key: "av01",
43178
+ value: function av01(track) {
43179
+ return MP42.box(MP42.types.av01, new Uint8Array([
43180
+ 0,
43181
+ 0,
43182
+ 0,
43183
+ 0,
43184
+ 0,
43185
+ 0,
43186
+ 0,
43187
+ 1,
43188
+ 0,
43189
+ 0,
43190
+ 0,
43191
+ 0,
43192
+ 0,
43193
+ 0,
43194
+ 0,
43195
+ 0,
43196
+ 0,
43197
+ 0,
43198
+ 0,
43199
+ 0,
43200
+ 0,
43201
+ 0,
43202
+ 0,
43203
+ 0,
43204
+ track.width >> 8 & 255,
43205
+ track.width & 255,
43206
+ track.height >> 8 & 255,
43207
+ track.height & 255,
43208
+ 0,
43209
+ 72,
43210
+ 0,
43211
+ 0,
43212
+ 0,
43213
+ 72,
43214
+ 0,
43215
+ 0,
43216
+ 0,
43217
+ 0,
43218
+ 0,
43219
+ 0,
43220
+ 0,
43221
+ 1,
43222
+ 0,
43223
+ 0,
43224
+ 0,
43225
+ 0,
43226
+ 0,
43227
+ 0,
43228
+ 0,
43229
+ 0,
43230
+ 0,
43231
+ 0,
43232
+ 0,
43233
+ 0,
43234
+ 0,
43235
+ 0,
43236
+ 0,
43237
+ 0,
43238
+ 0,
43239
+ 0,
43240
+ 0,
43241
+ 0,
43242
+ 0,
43243
+ 0,
43244
+ 0,
43245
+ 0,
43246
+ 0,
43247
+ 0,
43248
+ 0,
43249
+ 0,
43250
+ 0,
43251
+ 0,
43252
+ 0,
43253
+ 0,
43254
+ 0,
43255
+ 24,
43256
+ 17,
43257
+ 17
43258
+ ]), track.av1C, track.colr);
43259
+ }
42209
43260
  }, {
42210
43261
  key: "avc1hev1",
42211
43262
  value: function avc1hev1(track) {
@@ -42576,6 +43627,53 @@ var MP4$3 = /* @__PURE__ */ function() {
42576
43627
  )));
42577
43628
  return esds2;
42578
43629
  }
43630
+ }, {
43631
+ key: "opus",
43632
+ value: function opus(track) {
43633
+ var opusAudioDescription = new Uint8Array([
43634
+ 0,
43635
+ 0,
43636
+ 0,
43637
+ 0,
43638
+ 0,
43639
+ 0,
43640
+ 0,
43641
+ 1,
43642
+ 0,
43643
+ 0,
43644
+ 0,
43645
+ 0,
43646
+ 0,
43647
+ 0,
43648
+ 0,
43649
+ 0,
43650
+ 0,
43651
+ track.channelCount,
43652
+ 0,
43653
+ 16,
43654
+ 0,
43655
+ 0,
43656
+ 0,
43657
+ 0,
43658
+ track.sampleRate >> 8 & 255,
43659
+ track.sampleRate & 255,
43660
+ 0,
43661
+ 0
43662
+ ]);
43663
+ var opusSpecificConfig = track.config.length ? MP42.dOps(track) : [];
43664
+ return MP42.box(MP42.types.Opus, opusAudioDescription, opusSpecificConfig);
43665
+ }
43666
+ }, {
43667
+ key: "dOps",
43668
+ value: function dOps(track) {
43669
+ if (track.config) {
43670
+ track.config[4] = track.sampleRate >>> 24 & 255;
43671
+ track.config[5] = track.sampleRate >>> 16 & 255;
43672
+ track.config[6] = track.sampleRate >>> 8 & 255;
43673
+ track.config[7] = track.sampleRate & 255;
43674
+ return MP42.box(MP42.types.dOps, track.config);
43675
+ }
43676
+ }
42579
43677
  }, {
42580
43678
  key: "mvex",
42581
43679
  value: function mvex(tracks) {
@@ -43178,7 +44276,7 @@ var MP4$3 = /* @__PURE__ */ function() {
43178
44276
  }]);
43179
44277
  return MP42;
43180
44278
  }();
43181
- _defineProperty$b(MP4$3, "types", ["avc1", "avcC", "hvc1", "hvcC", "dinf", "dref", "esds", "ftyp", "hdlr", "mdat", "mdhd", "mdia", "mfhd", "minf", "moof", "moov", "mp4a", "mvex", "mvhd", "pasp", "stbl", "stco", "stsc", "stsd", "stsz", "stts", "tfdt", "tfhd", "traf", "trak", "trex", "tkhd", "vmhd", "smhd", "ctts", "stss", "styp", "pssh", "sidx", "sbgp", "saiz", "saio", "senc", "trun", "encv", "enca", "sinf", "btrt", "frma", "tenc", "schm", "schi", "mehd", "fiel", "sdtp"].reduce(function(p, c) {
44279
+ _defineProperty$b(MP4$3, "types", ["Opus", "dOps", "av01", "av1C", "avc1", "avcC", "hvc1", "hvcC", "dinf", "dref", "esds", "ftyp", "hdlr", "mdat", "mdhd", "mdia", "mfhd", "minf", "moof", "moov", "mp4a", "mvex", "mvhd", "pasp", "stbl", "stco", "stsc", "stsd", "stsz", "stts", "tfdt", "tfhd", "traf", "trak", "trex", "tkhd", "vmhd", "smhd", "ctts", "stss", "styp", "pssh", "sidx", "sbgp", "saiz", "saio", "senc", "trun", "encv", "enca", "sinf", "btrt", "frma", "tenc", "schm", "schi", "mehd", "fiel", "sdtp"].reduce(function(p, c) {
43182
44280
  p[c] = [c.charCodeAt(0), c.charCodeAt(1), c.charCodeAt(2), c.charCodeAt(3)];
43183
44281
  return p;
43184
44282
  }, /* @__PURE__ */ Object.create(null)));
@@ -43513,30 +44611,46 @@ var FMP4Remuxer$2 = /* @__PURE__ */ function() {
43513
44611
  };
43514
44612
  }
43515
44613
  var samples = track.samples;
44614
+ var isAV01 = /av01/.test(track.codec);
43516
44615
  var mdatSize = 0;
43517
- samples.forEach(function(s) {
43518
- mdatSize += s.units.reduce(function(t, c) {
43519
- return t + c.byteLength;
43520
- }, 0);
43521
- mdatSize += s.units.length * 4;
43522
- });
43523
- var mdata = new Uint8Array(mdatSize);
43524
- var mdatView = new DataView(mdata.buffer);
43525
- var _loop = function _loop2(_offset, _sample) {
43526
- _sample = samples[i];
43527
- var sampleSize = 0;
43528
- _sample.units.forEach(function(u) {
43529
- mdatView.setUint32(_offset, u.byteLength);
43530
- _offset += 4;
43531
- mdata.set(u, _offset);
43532
- _offset += u.byteLength;
43533
- sampleSize += 4 + u.byteLength;
44616
+ if (isAV01) {
44617
+ samples.forEach(function(s) {
44618
+ mdatSize += s.data.byteLength;
44619
+ });
44620
+ } else {
44621
+ samples.forEach(function(s) {
44622
+ mdatSize += s.units.reduce(function(t, c) {
44623
+ return t + c.byteLength;
44624
+ }, 0);
44625
+ mdatSize += s.units.length * 4;
43534
44626
  });
43535
- _sample.size = sampleSize;
43536
- offset = _offset, sample = _sample;
43537
- };
43538
- for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
43539
- _loop(offset, sample);
44627
+ }
44628
+ var mdata = new Uint8Array(mdatSize);
44629
+ if (isAV01) {
44630
+ for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
44631
+ sample = samples[i];
44632
+ mdata.set(sample.data, offset);
44633
+ sample.size = sample.data.byteLength;
44634
+ offset += sample.size;
44635
+ }
44636
+ } else {
44637
+ var mdatView = new DataView(mdata.buffer);
44638
+ var _loop = function _loop2(_offset2, _sample2) {
44639
+ _sample2 = samples[_i];
44640
+ var sampleSize = 0;
44641
+ _sample2.units.forEach(function(u) {
44642
+ mdatView.setUint32(_offset2, u.byteLength);
44643
+ _offset2 += 4;
44644
+ mdata.set(u, _offset2);
44645
+ _offset2 += u.byteLength;
44646
+ sampleSize += 4 + u.byteLength;
44647
+ });
44648
+ _sample2.size = sampleSize;
44649
+ _offset = _offset2, _sample = _sample2;
44650
+ };
44651
+ for (var _i = 0, _l = samples.length, _offset = 0, _sample; _i < _l; _i++) {
44652
+ _loop(_offset, _sample);
44653
+ }
43540
44654
  }
43541
44655
  var mdat = MP4$3.mdat(mdata);
43542
44656
  var moof = MP4$3.moof([track]);
@@ -43730,7 +44844,8 @@ var Transmuxer = /* @__PURE__ */ function() {
43730
44844
  timescale: audioTrack.timescale,
43731
44845
  firstDts: audioTrack.firstDts / videoTrack.timescale,
43732
44846
  firstPts: audioTrack.firstPts / videoTrack.timescale,
43733
- duration: audioTrack.samplesDuration / videoTrack.timescale
44847
+ duration: audioTrack.samplesDuration / videoTrack.timescale,
44848
+ container: audioTrack.container
43734
44849
  };
43735
44850
  var newId = "".concat(videoTrack.codec, "/").concat(videoTrack.width, "/").concat(videoTrack.height, "/").concat(audioTrack.codec, "/").concat(audioTrack.config);
43736
44851
  if (newId !== this._initSegmentId) {
@@ -43854,7 +44969,7 @@ var Transmuxer = /* @__PURE__ */ function() {
43854
44969
  }]);
43855
44970
  return Transmuxer2;
43856
44971
  }();
43857
- var _excluded$2 = ["data"], _excluded2 = ["data"];
44972
+ var _excluded$3 = ["data"], _excluded2 = ["data"];
43858
44973
  var logger$6 = new Logger$7("BufferService");
43859
44974
  var BufferService = /* @__PURE__ */ function() {
43860
44975
  function BufferService2(hls) {
@@ -44020,7 +45135,8 @@ var BufferService = /* @__PURE__ */ function() {
44020
45135
  key: "appendBuffer",
44021
45136
  value: function() {
44022
45137
  var _appendBuffer = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee2(segment, audioSegment, videoChunk, audioChunk, discontinuity, contiguous, startTime) {
44023
- var p, needInit, _this$_transmuxer$tra, _this$_transmuxer$tra2, video2, audio2, isFirstAppend, mse, _p, videoData, videoRest, audioData, audioRest;
45138
+ var _this2 = this;
45139
+ var afterAppend, p, needInit, _this$_transmuxer$tra, _this$_transmuxer$tra2, video2, audio2, isFirstAppend, mse, _p, videoData, videoRest, audioData, audioRest;
44024
45140
  return _regeneratorRuntime$7().wrap(function _callee2$(_context2) {
44025
45141
  while (1)
44026
45142
  switch (_context2.prev = _context2.next) {
@@ -44031,8 +45147,18 @@ var BufferService = /* @__PURE__ */ function() {
44031
45147
  }
44032
45148
  return _context2.abrupt("return");
44033
45149
  case 2:
45150
+ afterAppend = function afterAppend2() {
45151
+ var _this2$hls;
45152
+ if ((_this2$hls = _this2.hls) !== null && _this2$hls !== void 0 && _this2$hls.emit) {
45153
+ var _this2$hls2;
45154
+ (_this2$hls2 = _this2.hls) === null || _this2$hls2 === void 0 ? void 0 : _this2$hls2.emit(EVENT$1.APPEND_BUFFER, {
45155
+ start: segment.start,
45156
+ end: segment.end
45157
+ });
45158
+ }
45159
+ };
44034
45160
  if (!this._directAppend) {
44035
- _context2.next = 7;
45161
+ _context2.next = 8;
44036
45162
  break;
44037
45163
  }
44038
45164
  p = [];
@@ -44040,8 +45166,8 @@ var BufferService = /* @__PURE__ */ function() {
44040
45166
  p.push(this._mse.append(MSE$2.VIDEO, videoChunk));
44041
45167
  if (audioChunk)
44042
45168
  p.push(this._mse.append(MSE$2.AUDIO, audioChunk));
44043
- return _context2.abrupt("return", Promise.all(p));
44044
- case 7:
45169
+ return _context2.abrupt("return", Promise.all(p).then(afterAppend));
45170
+ case 8:
44045
45171
  needInit = this._needInitSegment || discontinuity;
44046
45172
  _this$_transmuxer$tra = this._transmuxer.transmux(videoChunk, audioChunk, needInit, contiguous, startTime, this._needInitSegment || discontinuity), _this$_transmuxer$tra2 = _slicedToArray$6(_this$_transmuxer$tra, 2), video2 = _this$_transmuxer$tra2[0], audio2 = _this$_transmuxer$tra2[1];
44047
45173
  if (audioChunk && audioSegment) {
@@ -44057,21 +45183,22 @@ var BufferService = /* @__PURE__ */ function() {
44057
45183
  this.hls.emit(Event$1.NO_AUDIO_TRACK);
44058
45184
  }
44059
45185
  if (!this._softVideo) {
44060
- _context2.next = 18;
45186
+ _context2.next = 20;
44061
45187
  break;
44062
45188
  }
44063
45189
  this._softVideo.appendBuffer(video2, audio2);
44064
45190
  this._needInitSegment = false;
44065
- _context2.next = 28;
45191
+ afterAppend();
45192
+ _context2.next = 30;
44066
45193
  break;
44067
- case 18:
45194
+ case 20:
44068
45195
  if (!this._mse) {
44069
- _context2.next = 28;
45196
+ _context2.next = 30;
44070
45197
  break;
44071
45198
  }
44072
45199
  isFirstAppend = !this._sourceCreated;
44073
45200
  if (isFirstAppend) {
44074
- this._createMseSource(video2 === null || video2 === void 0 ? void 0 : video2.codec, audio2 === null || audio2 === void 0 ? void 0 : audio2.codec);
45201
+ this._createMseSource(video2 === null || video2 === void 0 ? void 0 : video2.codec, audio2 === null || audio2 === void 0 ? void 0 : audio2.codec, audio2 === null || audio2 === void 0 ? void 0 : audio2.container);
44075
45202
  }
44076
45203
  this._needInitSegment = false;
44077
45204
  mse = this._mse;
@@ -44082,15 +45209,15 @@ var BufferService = /* @__PURE__ */ function() {
44082
45209
  });
44083
45210
  }
44084
45211
  if (video2) {
44085
- videoData = video2.data, videoRest = _objectWithoutProperties$3(video2, _excluded$2);
45212
+ videoData = video2.data, videoRest = _objectWithoutProperties$3(video2, _excluded$3);
44086
45213
  _p.push(mse.append(MSE$2.VIDEO, videoData, videoRest));
44087
45214
  }
44088
45215
  if (audio2) {
44089
45216
  audioData = audio2.data, audioRest = _objectWithoutProperties$3(audio2, _excluded2);
44090
45217
  _p.push(mse.append(MSE$2.AUDIO, audioData, audioRest));
44091
45218
  }
44092
- return _context2.abrupt("return", Promise.all(_p));
44093
- case 28:
45219
+ return _context2.abrupt("return", Promise.all(_p).then(afterAppend));
45220
+ case 30:
44094
45221
  case "end":
44095
45222
  return _context2.stop();
44096
45223
  }
@@ -44105,7 +45232,7 @@ var BufferService = /* @__PURE__ */ function() {
44105
45232
  key: "removeBuffer",
44106
45233
  value: function() {
44107
45234
  var _removeBuffer = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee3() {
44108
- var _this2 = this;
45235
+ var _this3 = this;
44109
45236
  var start, end, media, _args3 = arguments;
44110
45237
  return _regeneratorRuntime$7().wrap(function _callee3$(_context3) {
44111
45238
  while (1)
@@ -44121,7 +45248,7 @@ var BufferService = /* @__PURE__ */ function() {
44121
45248
  return _context3.abrupt("return");
44122
45249
  case 5:
44123
45250
  return _context3.abrupt("return", this._mse.clearBuffer(start, end).then(function() {
44124
- return _this2.hls.emit(EVENT$1.REMOVE_BUFFER, {
45251
+ return _this3.hls.emit(EVENT$1.REMOVE_BUFFER, {
44125
45252
  start,
44126
45253
  end,
44127
45254
  removeEnd: end
@@ -44302,30 +45429,51 @@ var BufferService = /* @__PURE__ */ function() {
44302
45429
  return setLiveSeekableRange;
44303
45430
  }()
44304
45431
  }, {
44305
- key: "destroy",
45432
+ key: "detachMedia",
44306
45433
  value: function() {
44307
- var _destroy = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee9() {
44308
- var _this$_decryptor;
45434
+ var _detachMedia = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee9() {
44309
45435
  return _regeneratorRuntime$7().wrap(function _callee9$(_context9) {
44310
45436
  while (1)
44311
45437
  switch (_context9.prev = _context9.next) {
44312
45438
  case 0:
44313
- (_this$_decryptor = this._decryptor) === null || _this$_decryptor === void 0 ? void 0 : _this$_decryptor.destroy();
44314
45439
  if (!this._mse) {
44315
- _context9.next = 4;
45440
+ _context9.next = 3;
44316
45441
  break;
44317
45442
  }
44318
- _context9.next = 4;
45443
+ _context9.next = 3;
44319
45444
  return this._mse.unbindMedia();
44320
- case 4:
45445
+ case 3:
45446
+ case "end":
45447
+ return _context9.stop();
45448
+ }
45449
+ }, _callee9, this);
45450
+ }));
45451
+ function detachMedia() {
45452
+ return _detachMedia.apply(this, arguments);
45453
+ }
45454
+ return detachMedia;
45455
+ }()
45456
+ }, {
45457
+ key: "destroy",
45458
+ value: function() {
45459
+ var _destroy = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee10() {
45460
+ var _this$_decryptor;
45461
+ return _regeneratorRuntime$7().wrap(function _callee10$(_context10) {
45462
+ while (1)
45463
+ switch (_context10.prev = _context10.next) {
45464
+ case 0:
45465
+ (_this$_decryptor = this._decryptor) === null || _this$_decryptor === void 0 ? void 0 : _this$_decryptor.destroy();
45466
+ _context10.next = 3;
45467
+ return this.detachMedia();
45468
+ case 3:
44321
45469
  this._decryptor = null;
44322
45470
  this._mse = null;
44323
45471
  this._softVideo = null;
44324
- case 7:
45472
+ case 6:
44325
45473
  case "end":
44326
- return _context9.stop();
45474
+ return _context10.stop();
44327
45475
  }
44328
- }, _callee9, this);
45476
+ }, _callee10, this);
44329
45477
  }));
44330
45478
  function destroy() {
44331
45479
  return _destroy.apply(this, arguments);
@@ -44334,7 +45482,7 @@ var BufferService = /* @__PURE__ */ function() {
44334
45482
  }()
44335
45483
  }, {
44336
45484
  key: "_createMseSource",
44337
- value: function _createMseSource(videoCodec, audioCodec) {
45485
+ value: function _createMseSource(videoCodec, audioCodec, container) {
44338
45486
  logger$6.debug("create mse source, videoCodec=".concat(videoCodec, ", audioCodec=").concat(audioCodec));
44339
45487
  var mse = this._mse;
44340
45488
  if (!mse)
@@ -44346,6 +45494,9 @@ var BufferService = /* @__PURE__ */ function() {
44346
45494
  if (audioCodec) {
44347
45495
  mse.createSource(MSE$2.AUDIO, "audio/mp4;codecs=".concat(audioCodec));
44348
45496
  this._sourceCreated = true;
45497
+ } else if (container) {
45498
+ mse.createSource(MSE$2.AUDIO, "".concat(container, ';codecs=""'));
45499
+ this._sourceCreated = true;
44349
45500
  }
44350
45501
  this.hls.emit(EVENT$1.SOURCEBUFFER_CREATED);
44351
45502
  }
@@ -44655,6 +45806,31 @@ var MediaSegmentKey = /* @__PURE__ */ function() {
44655
45806
  }]);
44656
45807
  return MediaSegmentKey2;
44657
45808
  }();
45809
+ var HlsUrlParameters = /* @__PURE__ */ function() {
45810
+ function HlsUrlParameters2(msn, part, skip) {
45811
+ _classCallCheck$f(this, HlsUrlParameters2);
45812
+ this.msn = msn;
45813
+ this.part = part;
45814
+ this.skip = skip;
45815
+ }
45816
+ _createClass$f(HlsUrlParameters2, [{
45817
+ key: "addDirectives",
45818
+ value: function addDirectives(uri) {
45819
+ var url = new self.URL(uri);
45820
+ if (this.msn !== void 0) {
45821
+ url.searchParams.set("_HLS_msn", this.msn.toString());
45822
+ }
45823
+ if (this.part) {
45824
+ url.searchParams.set("_HLS_part", this.part.toString());
45825
+ }
45826
+ if (this.skip) {
45827
+ url.searchParams.set("_HLS_skip", this.skip);
45828
+ }
45829
+ return url.href;
45830
+ }
45831
+ }]);
45832
+ return HlsUrlParameters2;
45833
+ }();
44658
45834
  var REGEXP_TAG = /^#(EXT[^:]*)(?::(.*))?$/;
44659
45835
  var REGEXP_ATTR = /([^=]+)=(?:"([^"]*)"|([^",]*))(?:,|$)/g;
44660
45836
  var REGEXP_ABSOLUTE_URL = /^(?:[a-zA-Z0-9+\-.]+:)?\/\//;
@@ -44893,7 +46069,7 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
44893
46069
  media.canBlockReload = _attr["CAN-BLOCK-RELOAD"] === "YES";
44894
46070
  media.partHoldBack = parseFloat(_attr["PART-HOLD-BACK"] || 0);
44895
46071
  media.canSkipUntil = parseFloat(_attr["CAN-SKIP-UNTIL"] || 0);
44896
- media.canSkipDateRanges = _attr["CAN-SKIP-DATERANGES"] === "YES";
46072
+ media.canSkipDateRanges = media.canSkipUntil > 0 && _attr["CAN-SKIP-DATERANGES"] === "YES";
44897
46073
  }
44898
46074
  break;
44899
46075
  case "ENDLIST":
@@ -44937,6 +46113,15 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
44937
46113
  }
44938
46114
  break;
44939
46115
  case "PRELOAD-HINT":
46116
+ {
46117
+ var _attr3 = parseAttr(data2);
46118
+ media.preloadHint = _attr3;
46119
+ if (_attr3["TYPE"] === "PART" && _attr3["URI"]) {
46120
+ var tmp = _attr3["URI"].split(".ts")[0].split("-");
46121
+ media.nextSN = tmp[3];
46122
+ media.nextIndex = tmp[tmp.length - 1];
46123
+ }
46124
+ }
44940
46125
  break;
44941
46126
  case "PROGRAM-DATE-TIME":
44942
46127
  curSegment.dataTime = data2;
@@ -44956,21 +46141,21 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
44956
46141
  break;
44957
46142
  case "KEY":
44958
46143
  {
44959
- var _attr3 = parseAttr(data2);
44960
- if (_attr3.METHOD === "NONE") {
46144
+ var _attr4 = parseAttr(data2);
46145
+ if (_attr4.METHOD === "NONE") {
44961
46146
  curKey = null;
44962
46147
  break;
44963
46148
  }
44964
46149
  curKey = new MediaSegmentKey();
44965
- curKey.method = _attr3.METHOD;
44966
- curKey.url = /^blob:/.test(_attr3.URI) ? _attr3.URI : getAbsoluteUrl(_attr3.URI, parentUrl);
44967
- curKey.keyFormat = _attr3.KEYFORMAT || "identity";
44968
- curKey.keyFormatVersions = _attr3.KEYFORMATVERSIONS;
46150
+ curKey.method = _attr4.METHOD;
46151
+ curKey.url = /^blob:/.test(_attr4.URI) ? _attr4.URI : getAbsoluteUrl(_attr4.URI, parentUrl);
46152
+ curKey.keyFormat = _attr4.KEYFORMAT || "identity";
46153
+ curKey.keyFormatVersions = _attr4.KEYFORMATVERSIONS;
44969
46154
  if (!curKey.isSupported()) {
44970
- throw new Error("encrypt ".concat(_attr3.METHOD, "/").concat(_attr3.KEYFORMAT, " is not supported"));
46155
+ throw new Error("encrypt ".concat(_attr4.METHOD, "/").concat(_attr4.KEYFORMAT, " is not supported"));
44971
46156
  }
44972
- if (_attr3.IV) {
44973
- var str2 = _attr3.IV.slice(2);
46157
+ if (_attr4.IV) {
46158
+ var str2 = _attr4.IV.slice(2);
44974
46159
  str2 = (str2.length & 1 ? "0" : "") + str2;
44975
46160
  curKey.iv = new Uint8Array(str2.length / 2);
44976
46161
  for (var i = 0, l = str2.length / 2; i < l; i++) {
@@ -44981,10 +46166,10 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
44981
46166
  break;
44982
46167
  case "MAP":
44983
46168
  {
44984
- var _attr4 = parseAttr(data2);
44985
- curSegment.url = getAbsoluteUrl(_attr4.URI, parentUrl);
44986
- if (_attr4.BYTERANGE)
44987
- curSegment.setByteRange(_attr4.BYTERANGE);
46169
+ var _attr5 = parseAttr(data2);
46170
+ curSegment.url = getAbsoluteUrl(_attr5.URI, parentUrl);
46171
+ if (_attr5.BYTERANGE)
46172
+ curSegment.setByteRange(_attr5.BYTERANGE);
44988
46173
  curSegment.isInitSegment = true;
44989
46174
  curSegment.sn = 0;
44990
46175
  if (curKey) {
@@ -44996,24 +46181,25 @@ function parseMediaPlaylist(lines, parentUrl, useLowLatency) {
44996
46181
  break;
44997
46182
  case "SKIP":
44998
46183
  {
44999
- var _attr5 = parseAttr(data2);
45000
- var skippedSegments = parseInt(_attr5["SKIPPED-SEGMENTS"], 10);
46184
+ var _attr6 = parseAttr(data2);
46185
+ var skippedSegments = parseInt(_attr6["SKIPPED-SEGMENTS"], 10);
45001
46186
  if (skippedSegments <= Number.MAX_SAFE_INTEGER) {
45002
46187
  media.skippedSegments += skippedSegments;
46188
+ curSN += skippedSegments;
45003
46189
  }
45004
46190
  }
45005
46191
  break;
45006
46192
  case "DATERANGE":
45007
46193
  {
45008
- var _attr6 = parseAttr(data2);
45009
- var dateRangeWithSameId = media.dateRanges[_attr6.ID];
45010
- _attr6._startDate = dateRangeWithSameId ? dateRangeWithSameId._startDate : new Date(_attr6["START-DATE"]);
45011
- var endDate = (dateRangeWithSameId === null || dateRangeWithSameId === void 0 ? void 0 : dateRangeWithSameId._endDate) || new Date(_attr6.END_DATE);
46194
+ var _attr7 = parseAttr(data2);
46195
+ var dateRangeWithSameId = media.dateRanges[_attr7.ID];
46196
+ _attr7._startDate = dateRangeWithSameId ? dateRangeWithSameId._startDate : new Date(_attr7["START-DATE"]);
46197
+ var endDate = (dateRangeWithSameId === null || dateRangeWithSameId === void 0 ? void 0 : dateRangeWithSameId._endDate) || new Date(_attr7.END_DATE);
45012
46198
  if (Number.isFinite(endDate)) {
45013
- _attr6._endDate = endDate;
46199
+ _attr7._endDate = endDate;
45014
46200
  }
45015
- if (isValidDaterange(_attr6, dateRangeWithSameId) || media.skippedSegments) {
45016
- media.dateRanges[_attr6.ID] = _attr6;
46201
+ if (isValidDaterange(_attr7, dateRangeWithSameId) || media.skippedSegments) {
46202
+ media.dateRanges[_attr7.ID] = _attr7;
45017
46203
  }
45018
46204
  }
45019
46205
  break;
@@ -45210,6 +46396,13 @@ var ManifestLoader = /* @__PURE__ */ function() {
45210
46396
  playlist
45211
46397
  });
45212
46398
  } else {
46399
+ if (this._useLowLatency) {
46400
+ if (playlist.canBlockReload) {
46401
+ this.deliveryDirectives = new HlsUrlParameters(playlist.nextSN, playlist.nextIndex, "");
46402
+ } else {
46403
+ this.deliveryDirectives = null;
46404
+ }
46405
+ }
45213
46406
  this.hls.emit(Event$1.HLS_LEVEL_LOADED, {
45214
46407
  playlist
45215
46408
  });
@@ -45266,41 +46459,45 @@ var ManifestLoader = /* @__PURE__ */ function() {
45266
46459
  var retryCount = this.hls.config.pollRetryCount;
45267
46460
  var fn = /* @__PURE__ */ function() {
45268
46461
  var _ref2 = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee2() {
45269
- var res;
46462
+ var reqUrl, res;
45270
46463
  return _regeneratorRuntime$7().wrap(function _callee2$(_context2) {
45271
46464
  while (1)
45272
46465
  switch (_context2.prev = _context2.next) {
45273
46466
  case 0:
45274
46467
  clearTimeout(_this2._timer);
45275
- _context2.prev = 1;
45276
- _context2.next = 4;
45277
- return _this2.load(url, audioUrl, subtitleUrl);
45278
- case 4:
46468
+ reqUrl = url;
46469
+ _context2.prev = 2;
46470
+ if (_this2.deliveryDirectives) {
46471
+ reqUrl = _this2.deliveryDirectives.addDirectives(url);
46472
+ }
46473
+ _context2.next = 6;
46474
+ return _this2.load(reqUrl, audioUrl, subtitleUrl);
46475
+ case 6:
45279
46476
  res = _context2.sent;
45280
46477
  if (res[0]) {
45281
- _context2.next = 7;
46478
+ _context2.next = 9;
45282
46479
  break;
45283
46480
  }
45284
46481
  return _context2.abrupt("return");
45285
- case 7:
46482
+ case 9:
45286
46483
  retryCount = _this2.hls.config.pollRetryCount;
45287
46484
  cb(res[0], res[1], res[2]);
45288
- _context2.next = 15;
46485
+ _context2.next = 17;
45289
46486
  break;
45290
- case 11:
45291
- _context2.prev = 11;
45292
- _context2.t0 = _context2["catch"](1);
46487
+ case 13:
46488
+ _context2.prev = 13;
46489
+ _context2.t0 = _context2["catch"](2);
45293
46490
  retryCount--;
45294
46491
  if (retryCount <= 0) {
45295
46492
  errorCb(_context2.t0);
45296
46493
  }
45297
- case 15:
46494
+ case 17:
45298
46495
  _this2._timer = setTimeout(fn, time);
45299
- case 16:
46496
+ case 18:
45300
46497
  case "end":
45301
46498
  return _context2.stop();
45302
46499
  }
45303
- }, _callee2, null, [[1, 11]]);
46500
+ }, _callee2, null, [[2, 13]]);
45304
46501
  }));
45305
46502
  return function fn2() {
45306
46503
  return _ref2.apply(this, arguments);
@@ -45830,7 +47027,7 @@ var Playlist = /* @__PURE__ */ function() {
45830
47027
  }, {
45831
47028
  key: "clearOldSegment",
45832
47029
  value: function clearOldSegment() {
45833
- var maxPlaylistSize = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 50;
47030
+ var maxPlaylistSize = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.hls.config.maxPlaylistSize || 50;
45834
47031
  var stream = this.currentStream;
45835
47032
  if (!this.dvrWindow || !stream)
45836
47033
  return;
@@ -46341,7 +47538,6 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
46341
47538
  return;
46342
47539
  _this._startTick();
46343
47540
  var media = _this.media;
46344
- var buffered = Buffer$4.get(media);
46345
47541
  var segLoaderError = _this._segmentLoader.error;
46346
47542
  _this._onCheckQuotaExceeded();
46347
47543
  if (_this._isProcessQuotaExceeded) {
@@ -46358,7 +47554,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
46358
47554
  }
46359
47555
  return;
46360
47556
  }
46361
- if (Buffer$4.end(buffered) >= 0.1 && media.readyState) {
47557
+ if (media.readyState) {
46362
47558
  if (isMediaPlaying(media)) {
46363
47559
  _this._loadSegment();
46364
47560
  if (_this._gapService) {
@@ -46424,6 +47620,12 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
46424
47620
  var _this$_bufferService;
46425
47621
  return (_this$_bufferService = this._bufferService) === null || _this$_bufferService === void 0 ? void 0 : _this$_bufferService.baseDts;
46426
47622
  }
47623
+ }, {
47624
+ key: "abrSwitchPoint",
47625
+ get: function get3() {
47626
+ var targetSeg = this._urlSwitching ? this._playlist.currentSegment : this._playlist.nextSegment;
47627
+ return targetSeg ? targetSeg.start + targetSeg.duration / 2 : null;
47628
+ }
46427
47629
  }, {
46428
47630
  key: "speedInfo",
46429
47631
  value: function speedInfo() {
@@ -46449,30 +47651,37 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
46449
47651
  }, {
46450
47652
  key: "load",
46451
47653
  value: function() {
46452
- var _load = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee4(url) {
46453
- var reuseMse, _args4 = arguments;
47654
+ var _load = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee4() {
47655
+ var url, options, reuseMse, _args4 = arguments;
46454
47656
  return _regeneratorRuntime$7().wrap(function _callee4$(_context4) {
46455
47657
  while (1)
46456
47658
  switch (_context4.prev = _context4.next) {
46457
47659
  case 0:
46458
- reuseMse = _args4.length > 1 && _args4[1] !== void 0 ? _args4[1] : false;
47660
+ url = _args4.length > 0 && _args4[0] !== void 0 ? _args4[0] : "";
47661
+ options = _args4.length > 1 && _args4[1] !== void 0 ? _args4[1] : {};
47662
+ reuseMse = typeof options === "boolean" ? options : !!(options !== null && options !== void 0 && options.reuseMse);
47663
+ if (_typeof$8(options) === "object" && options !== null && options !== void 0 && options.clearSwitchStatus) {
47664
+ this._urlSwitching = false;
47665
+ this._switchUrlOpts = null;
47666
+ this.config.startTime = void 0;
47667
+ }
46459
47668
  if (url)
46460
47669
  this.config.url = url;
46461
47670
  url = this.config.url;
46462
- _context4.next = 5;
47671
+ _context4.next = 8;
46463
47672
  return this._reset(reuseMse);
46464
- case 5:
46465
- _context4.next = 7;
47673
+ case 8:
47674
+ _context4.next = 10;
46466
47675
  return this._loadData(url);
46467
- case 7:
47676
+ case 10:
46468
47677
  this._startTick();
46469
- case 8:
47678
+ case 11:
46470
47679
  case "end":
46471
47680
  return _context4.stop();
46472
47681
  }
46473
47682
  }, _callee4, this);
46474
47683
  }));
46475
- function load(_x) {
47684
+ function load() {
46476
47685
  return _load.apply(this, arguments);
46477
47686
  }
46478
47687
  return load;
@@ -46481,7 +47690,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
46481
47690
  key: "_loadData",
46482
47691
  value: function() {
46483
47692
  var _loadData2 = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee5(url) {
46484
- var manifest, currentStream, _this$_switchUrlOpts, _this$_switchUrlOpts2, switchTimePoint, segIdx, nextSeg, bufferClearStartPoint, preIndex, startTime, _this$_switchUrlOpts3;
47693
+ var manifest, currentStream, preIndex, _this$_switchUrlOpts, _this$_switchUrlOpts3, _this$_switchUrlOpts4, _this$_switchUrlOpts2, switchTimePoint, segIdx, nextSeg, bufferClearStartPoint, startTime, _this$_switchUrlOpts5;
46485
47694
  return _regeneratorRuntime$7().wrap(function _callee5$(_context5) {
46486
47695
  while (1)
46487
47696
  switch (_context5.prev = _context5.next) {
@@ -46502,41 +47711,46 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
46502
47711
  case 5:
46503
47712
  manifest = _context5.sent;
46504
47713
  currentStream = this._playlist.currentStream;
46505
- if (!(this._urlSwitching && !this.isLive)) {
46506
- _context5.next = 17;
47714
+ if (!this._urlSwitching) {
47715
+ _context5.next = 23;
46507
47716
  break;
46508
47717
  }
47718
+ if (!this.isLive) {
47719
+ _context5.next = 14;
47720
+ break;
47721
+ }
47722
+ preIndex = this._playlist.setNextSegmentBySN(this._prevSegSn);
47723
+ logger$4.log("segment nb=".concat(this._prevSegSn, " index of ").concat(preIndex, " in the new playlist"));
47724
+ if (preIndex === -1) {
47725
+ this._prevSegCc = null;
47726
+ this._prevSegSn = null;
47727
+ }
47728
+ _context5.next = 23;
47729
+ break;
47730
+ case 14:
46509
47731
  if (currentStream.bitrate === 0 && (_this$_switchUrlOpts = this._switchUrlOpts) !== null && _this$_switchUrlOpts !== void 0 && _this$_switchUrlOpts.bitrate) {
46510
47732
  currentStream.bitrate = (_this$_switchUrlOpts2 = this._switchUrlOpts) === null || _this$_switchUrlOpts2 === void 0 ? void 0 : _this$_switchUrlOpts2.bitrate;
46511
47733
  }
46512
- switchTimePoint = this._getSeamlessSwitchPoint();
47734
+ 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();
46513
47735
  this.config.startTime = switchTimePoint;
46514
47736
  segIdx = this._playlist.findSegmentIndexByTime(switchTimePoint);
46515
47737
  nextSeg = this._playlist.getSegmentByIndex(segIdx + 1);
46516
47738
  if (!nextSeg) {
46517
- _context5.next = 17;
47739
+ _context5.next = 23;
46518
47740
  break;
46519
47741
  }
46520
47742
  bufferClearStartPoint = nextSeg.start;
46521
- _context5.next = 17;
47743
+ _context5.next = 23;
46522
47744
  return this._bufferService.removeBuffer(bufferClearStartPoint);
46523
- case 17:
46524
- if (this._urlSwitching && this.isLive) {
46525
- preIndex = this._playlist.setNextSegmentBySN(this._prevSegSn);
46526
- logger$4.log("segment nb=".concat(this._prevSegSn, " index of ").concat(preIndex, " in the new playlist"));
46527
- if (preIndex === -1) {
46528
- this._prevSegCc = null;
46529
- this._prevSegSn = null;
46530
- }
46531
- }
47745
+ case 23:
46532
47746
  if (manifest) {
46533
- _context5.next = 20;
47747
+ _context5.next = 25;
46534
47748
  break;
46535
47749
  }
46536
47750
  return _context5.abrupt("return");
46537
- case 20:
47751
+ case 25:
46538
47752
  if (!this.isLive) {
46539
- _context5.next = 31;
47753
+ _context5.next = 36;
46540
47754
  break;
46541
47755
  }
46542
47756
  this._bufferService.setLiveSeekableRange(0, 4294967295);
@@ -46549,35 +47763,35 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
46549
47763
  if (!manifest.isMaster)
46550
47764
  this._pollM3U8(url);
46551
47765
  if (!(this._playlist.nbSegments < this.config.minSegmentsStartPlay)) {
46552
- _context5.next = 28;
47766
+ _context5.next = 33;
46553
47767
  break;
46554
47768
  }
46555
47769
  return _context5.abrupt("return");
46556
- case 28:
46557
- _context5.next = 30;
47770
+ case 33:
47771
+ _context5.next = 35;
46558
47772
  return this._loadSegment();
46559
- case 30:
47773
+ case 35:
46560
47774
  return _context5.abrupt("return");
46561
- case 31:
46562
- _context5.next = 33;
47775
+ case 36:
47776
+ _context5.next = 38;
46563
47777
  return this._bufferService.updateDuration(currentStream.totalDuration);
46564
- case 33:
47778
+ case 38:
46565
47779
  startTime = this.config.startTime;
46566
47780
  if (startTime) {
46567
- if (!((_this$_switchUrlOpts3 = this._switchUrlOpts) !== null && _this$_switchUrlOpts3 !== void 0 && _this$_switchUrlOpts3.seamless)) {
47781
+ if (!((_this$_switchUrlOpts5 = this._switchUrlOpts) !== null && _this$_switchUrlOpts5 !== void 0 && _this$_switchUrlOpts5.seamless)) {
46568
47782
  this.media.currentTime = startTime;
46569
47783
  }
46570
47784
  this._playlist.setNextSegmentByIndex(this._playlist.findSegmentIndexByTime(startTime) || 0);
46571
47785
  }
46572
- _context5.next = 37;
47786
+ _context5.next = 42;
46573
47787
  return this._loadSegment();
46574
- case 37:
47788
+ case 42:
46575
47789
  case "end":
46576
47790
  return _context5.stop();
46577
47791
  }
46578
47792
  }, _callee5, this);
46579
47793
  }));
46580
- function _loadData(_x2) {
47794
+ function _loadData(_x) {
46581
47795
  return _loadData2.apply(this, arguments);
46582
47796
  }
46583
47797
  return _loadData;
@@ -46591,18 +47805,20 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
46591
47805
  switch (_context6.prev = _context6.next) {
46592
47806
  case 0:
46593
47807
  this.config.startTime = 0;
46594
- _context6.next = 3;
47808
+ this._urlSwitching = false;
47809
+ this._switchUrlOpts = null;
47810
+ _context6.next = 5;
46595
47811
  return this.load();
46596
- case 3:
47812
+ case 5:
46597
47813
  this._reloadOnPlay = false;
46598
47814
  return _context6.abrupt("return", this.media.play(!isPlayEmit));
46599
- case 5:
47815
+ case 7:
46600
47816
  case "end":
46601
47817
  return _context6.stop();
46602
47818
  }
46603
47819
  }, _callee6, this);
46604
47820
  }));
46605
- function replay(_x3) {
47821
+ function replay(_x2) {
46606
47822
  return _replay.apply(this, arguments);
46607
47823
  }
46608
47824
  return replay;
@@ -46707,7 +47923,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
46707
47923
  }
46708
47924
  }, _callee7, this, [[18, 29]]);
46709
47925
  }));
46710
- function switchURL(_x4) {
47926
+ function switchURL(_x3) {
46711
47927
  return _switchURL.apply(this, arguments);
46712
47928
  }
46713
47929
  return switchURL;
@@ -46793,7 +48009,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
46793
48009
  }
46794
48010
  }, _callee8, this, [[8, 16], [21, 31]]);
46795
48011
  }));
46796
- function switchStream(_x5) {
48012
+ function switchStream(_x4) {
46797
48013
  return _switchStream.apply(this, arguments);
46798
48014
  }
46799
48015
  return switchStream;
@@ -46879,7 +48095,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
46879
48095
  }
46880
48096
  }, _callee9, this, [[10, 18], [22, 32]]);
46881
48097
  }));
46882
- function switchAudioStream(_x6) {
48098
+ function switchAudioStream(_x5) {
46883
48099
  return _switchAudioStream.apply(this, arguments);
46884
48100
  }
46885
48101
  return switchAudioStream;
@@ -46904,25 +48120,50 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
46904
48120
  }
46905
48121
  }, _callee10, this);
46906
48122
  }));
46907
- function switchSubtitleStream(_x7) {
48123
+ function switchSubtitleStream(_x6) {
46908
48124
  return _switchSubtitleStream.apply(this, arguments);
46909
48125
  }
46910
48126
  return switchSubtitleStream;
46911
48127
  }()
46912
48128
  }, {
46913
- key: "destroy",
48129
+ key: "detachMedia",
46914
48130
  value: function() {
46915
- var _destroy = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee11() {
46916
- var _this$_seiService2;
48131
+ var _detachMedia = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee11() {
46917
48132
  return _regeneratorRuntime$7().wrap(function _callee11$(_context11) {
46918
48133
  while (1)
46919
48134
  switch (_context11.prev = _context11.next) {
48135
+ case 0:
48136
+ if (!this._bufferService) {
48137
+ _context11.next = 3;
48138
+ break;
48139
+ }
48140
+ _context11.next = 3;
48141
+ return this._bufferService.detachMedia();
48142
+ case 3:
48143
+ case "end":
48144
+ return _context11.stop();
48145
+ }
48146
+ }, _callee11, this);
48147
+ }));
48148
+ function detachMedia() {
48149
+ return _detachMedia.apply(this, arguments);
48150
+ }
48151
+ return detachMedia;
48152
+ }()
48153
+ }, {
48154
+ key: "destroy",
48155
+ value: function() {
48156
+ var _destroy = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee12() {
48157
+ var _this$_seiService2;
48158
+ return _regeneratorRuntime$7().wrap(function _callee12$(_context12) {
48159
+ while (1)
48160
+ switch (_context12.prev = _context12.next) {
46920
48161
  case 0:
46921
48162
  if (this.media) {
46922
- _context11.next = 2;
48163
+ _context12.next = 2;
46923
48164
  break;
46924
48165
  }
46925
- return _context11.abrupt("return");
48166
+ return _context12.abrupt("return");
46926
48167
  case 2:
46927
48168
  this.removeAllListeners();
46928
48169
  this._playlist.reset();
@@ -46933,15 +48174,15 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
46933
48174
  this.media.removeEventListener("pause", this._onPause);
46934
48175
  this.media.removeEventListener("seeking", this._onSeeking);
46935
48176
  this.media.removeEventListener("timeupdate", this._onTimeupdate);
46936
- _context11.next = 13;
48177
+ _context12.next = 13;
46937
48178
  return Promise.all([this._clear(), this._bufferService.destroy()]);
46938
48179
  case 13:
46939
48180
  this.media = null;
46940
48181
  case 14:
46941
48182
  case "end":
46942
- return _context11.stop();
48183
+ return _context12.stop();
46943
48184
  }
46944
- }, _callee11, this);
48185
+ }, _callee12, this);
46945
48186
  }));
46946
48187
  function destroy() {
46947
48188
  return _destroy.apply(this, arguments);
@@ -46951,48 +48192,48 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
46951
48192
  }, {
46952
48193
  key: "_loadM3U8",
46953
48194
  value: function() {
46954
- var _loadM3U = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee12(url) {
48195
+ var _loadM3U = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee13(url) {
46955
48196
  var playlist, _this$config$manifest, _this$config$manifest2, manifest, _ref4, _ref5, _this$_playlist$curre;
46956
- return _regeneratorRuntime$7().wrap(function _callee12$(_context12) {
48197
+ return _regeneratorRuntime$7().wrap(function _callee13$(_context13) {
46957
48198
  while (1)
46958
- switch (_context12.prev = _context12.next) {
48199
+ switch (_context13.prev = _context13.next) {
46959
48200
  case 0:
46960
- _context12.prev = 0;
48201
+ _context13.prev = 0;
46961
48202
  manifest = (_this$config$manifest = this.config.manifestList) === null || _this$config$manifest === void 0 ? void 0 : (_this$config$manifest2 = _this$config$manifest.filter(function(x2) {
46962
48203
  return x2.url === url;
46963
48204
  })[0]) === null || _this$config$manifest2 === void 0 ? void 0 : _this$config$manifest2.manifest;
46964
48205
  if (!manifest) {
46965
- _context12.next = 6;
48206
+ _context13.next = 6;
46966
48207
  break;
46967
48208
  }
46968
- _context12.t0 = this._manifestLoader.parseText(manifest, url);
46969
- _context12.next = 9;
48209
+ _context13.t0 = this._manifestLoader.parseText(manifest, url);
48210
+ _context13.next = 9;
46970
48211
  break;
46971
48212
  case 6:
46972
- _context12.next = 8;
48213
+ _context13.next = 8;
46973
48214
  return this._manifestLoader.load(url);
46974
48215
  case 8:
46975
- _context12.t0 = _context12.sent;
48216
+ _context13.t0 = _context13.sent;
46976
48217
  case 9:
46977
- _ref4 = _context12.t0;
48218
+ _ref4 = _context13.t0;
46978
48219
  _ref5 = _slicedToArray$6(_ref4, 1);
46979
48220
  playlist = _ref5[0];
46980
- _context12.next = 17;
48221
+ _context13.next = 17;
46981
48222
  break;
46982
48223
  case 14:
46983
- _context12.prev = 14;
46984
- _context12.t1 = _context12["catch"](0);
46985
- throw this._emitError(StreamingError$1.create(_context12.t1));
48224
+ _context13.prev = 14;
48225
+ _context13.t1 = _context13["catch"](0);
48226
+ throw this._emitError(StreamingError$1.create(_context13.t1));
46986
48227
  case 17:
46987
48228
  if (playlist) {
46988
- _context12.next = 19;
48229
+ _context13.next = 19;
46989
48230
  break;
46990
48231
  }
46991
- return _context12.abrupt("return");
48232
+ return _context13.abrupt("return");
46992
48233
  case 19:
46993
48234
  this._playlist.upsertPlaylist(playlist);
46994
48235
  if (!playlist.isMaster) {
46995
- _context12.next = 24;
48236
+ _context13.next = 24;
46996
48237
  break;
46997
48238
  }
46998
48239
  if ((_this$_playlist$curre = this._playlist.currentStream.subtitleStreams) !== null && _this$_playlist$curre !== void 0 && _this$_playlist$curre.length) {
@@ -47000,18 +48241,18 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
47000
48241
  list: this._playlist.currentStream.subtitleStreams
47001
48242
  });
47002
48243
  }
47003
- _context12.next = 24;
48244
+ _context13.next = 24;
47004
48245
  return this._refreshM3U8();
47005
48246
  case 24:
47006
48247
  this.emit(Event$1.STREAM_PARSED);
47007
- return _context12.abrupt("return", playlist);
48248
+ return _context13.abrupt("return", playlist);
47008
48249
  case 26:
47009
48250
  case "end":
47010
- return _context12.stop();
48251
+ return _context13.stop();
47011
48252
  }
47012
- }, _callee12, this, [[0, 14]]);
48253
+ }, _callee13, this, [[0, 14]]);
47013
48254
  }));
47014
- function _loadM3U8(_x8) {
48255
+ function _loadM3U8(_x7) {
47015
48256
  return _loadM3U.apply(this, arguments);
47016
48257
  }
47017
48258
  return _loadM3U8;
@@ -47045,7 +48286,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
47045
48286
  var isEmpty = this._playlist.isEmpty;
47046
48287
  var pollInterval;
47047
48288
  if (this._playlist.lowLatency) {
47048
- pollInterval = (this._playlist.currentStream.partTargetDuration * 2 || 0) * 1e3;
48289
+ pollInterval = (this._playlist.currentStream.partTargetDuration || 0) * 1e3;
47049
48290
  } else {
47050
48291
  var _this$_playlist$lastS;
47051
48292
  pollInterval = (((_this$_playlist$lastS = this._playlist.lastSegment) === null || _this$_playlist$lastS === void 0 ? void 0 : _this$_playlist$lastS.duration) || 0) * 1e3;
@@ -47073,53 +48314,53 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
47073
48314
  }, {
47074
48315
  key: "_loadSegmentDirect",
47075
48316
  value: function() {
47076
- var _loadSegmentDirect2 = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee13(loadOnce) {
48317
+ var _loadSegmentDirect2 = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee14(loadOnce) {
47077
48318
  var seg, appended, cachedError, _this$_playlist$curre2, bufferEnd, sameStream;
47078
- return _regeneratorRuntime$7().wrap(function _callee13$(_context13) {
48319
+ return _regeneratorRuntime$7().wrap(function _callee14$(_context14) {
47079
48320
  while (1)
47080
- switch (_context13.prev = _context13.next) {
48321
+ switch (_context14.prev = _context14.next) {
47081
48322
  case 0:
47082
48323
  seg = this._playlist.nextSegment;
47083
48324
  if (seg) {
47084
- _context13.next = 3;
48325
+ _context14.next = 3;
47085
48326
  break;
47086
48327
  }
47087
- return _context13.abrupt("return");
48328
+ return _context14.abrupt("return");
47088
48329
  case 3:
47089
48330
  appended = false;
47090
48331
  cachedError = null;
47091
- _context13.prev = 5;
48332
+ _context14.prev = 5;
47092
48333
  this._segmentProcessing = true;
47093
48334
  logger$4.log("load segment, sn:".concat(seg.sn, ", [").concat(seg.start, ", ").concat(seg.end, "], partIndex:").concat(seg.partIndex));
47094
- _context13.next = 10;
48335
+ _context14.next = 10;
47095
48336
  return this._reqAndBufferSegment(seg, this._playlist.getAudioSegment(seg));
47096
48337
  case 10:
47097
- appended = _context13.sent;
47098
- _context13.next = 16;
48338
+ appended = _context14.sent;
48339
+ _context14.next = 16;
47099
48340
  break;
47100
48341
  case 13:
47101
- _context13.prev = 13;
47102
- _context13.t0 = _context13["catch"](5);
47103
- cachedError = _context13.t0;
48342
+ _context14.prev = 13;
48343
+ _context14.t0 = _context14["catch"](5);
48344
+ cachedError = _context14.t0;
47104
48345
  case 16:
47105
- _context13.prev = 16;
48346
+ _context14.prev = 16;
47106
48347
  this._segmentProcessing = false;
47107
- return _context13.finish(16);
48348
+ return _context14.finish(16);
47108
48349
  case 19:
47109
48350
  if (!cachedError) {
47110
- _context13.next = 26;
48351
+ _context14.next = 26;
47111
48352
  break;
47112
48353
  }
47113
48354
  if (!this._bufferService.isFull()) {
47114
- _context13.next = 25;
48355
+ _context14.next = 25;
47115
48356
  break;
47116
48357
  }
47117
48358
  logger$4.log("load segment, sn:".concat(seg.sn, ", partIndex:").concat(seg.partIndex));
47118
48359
  this._segmentProcessing = true;
47119
48360
  this._isProcessQuotaExceeded = true;
47120
- return _context13.abrupt("return", false);
48361
+ return _context14.abrupt("return", false);
47121
48362
  case 25:
47122
- return _context13.abrupt("return", this._emitError(StreamingError$1.create(cachedError)));
48363
+ return _context14.abrupt("return", this._emitError(StreamingError$1.create(cachedError)));
47123
48364
  case 26:
47124
48365
  if (appended) {
47125
48366
  bufferEnd = this.bufferInfo().end;
@@ -47145,14 +48386,14 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
47145
48386
  this._loadSegment();
47146
48387
  }
47147
48388
  }
47148
- return _context13.abrupt("return", appended);
48389
+ return _context14.abrupt("return", appended);
47149
48390
  case 28:
47150
48391
  case "end":
47151
- return _context13.stop();
48392
+ return _context14.stop();
47152
48393
  }
47153
- }, _callee13, this, [[5, 13, 16, 19]]);
48394
+ }, _callee14, this, [[5, 13, 16, 19]]);
47154
48395
  }));
47155
- function _loadSegmentDirect(_x9) {
48396
+ function _loadSegmentDirect(_x8) {
47156
48397
  return _loadSegmentDirect2.apply(this, arguments);
47157
48398
  }
47158
48399
  return _loadSegmentDirect;
@@ -47160,45 +48401,45 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
47160
48401
  }, {
47161
48402
  key: "_reqAndBufferSegment",
47162
48403
  value: function() {
47163
- var _reqAndBufferSegment2 = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee14(seg, audioSeg) {
48404
+ var _reqAndBufferSegment2 = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee15(seg, audioSeg) {
47164
48405
  var _this$_bufferService2;
47165
48406
  var cc, discontinuity, responses, data2, sn, start, stream, before, contiguous, segStart;
47166
- return _regeneratorRuntime$7().wrap(function _callee14$(_context14) {
48407
+ return _regeneratorRuntime$7().wrap(function _callee15$(_context15) {
47167
48408
  while (1)
47168
- switch (_context14.prev = _context14.next) {
48409
+ switch (_context15.prev = _context15.next) {
47169
48410
  case 0:
47170
48411
  cc = seg ? seg.cc : audioSeg.cc;
47171
48412
  discontinuity = this._prevSegCc !== cc;
47172
48413
  responses = [];
47173
- _context14.prev = 3;
47174
- _context14.next = 6;
48414
+ _context15.prev = 3;
48415
+ _context15.next = 6;
47175
48416
  return this._segmentLoader.load(seg, audioSeg, discontinuity);
47176
48417
  case 6:
47177
- responses = _context14.sent;
47178
- _context14.next = 14;
48418
+ responses = _context15.sent;
48419
+ _context15.next = 14;
47179
48420
  break;
47180
48421
  case 9:
47181
- _context14.prev = 9;
47182
- _context14.t0 = _context14["catch"](3);
47183
- _context14.t0.fatal = false;
47184
- this._segmentLoader.error = _context14.t0;
47185
- throw _context14.t0;
48422
+ _context15.prev = 9;
48423
+ _context15.t0 = _context15["catch"](3);
48424
+ _context15.t0.fatal = false;
48425
+ this._segmentLoader.error = _context15.t0;
48426
+ throw _context15.t0;
47186
48427
  case 14:
47187
48428
  if (responses[0]) {
47188
- _context14.next = 16;
48429
+ _context15.next = 16;
47189
48430
  break;
47190
48431
  }
47191
- return _context14.abrupt("return");
48432
+ return _context15.abrupt("return");
47192
48433
  case 16:
47193
- _context14.next = 18;
48434
+ _context15.next = 18;
47194
48435
  return (_this$_bufferService2 = this._bufferService).decryptBuffer.apply(_this$_bufferService2, _toConsumableArray$7(responses));
47195
48436
  case 18:
47196
- data2 = _context14.sent;
48437
+ data2 = _context15.sent;
47197
48438
  if (data2) {
47198
- _context14.next = 21;
48439
+ _context15.next = 21;
47199
48440
  break;
47200
48441
  }
47201
- return _context14.abrupt("return");
48442
+ return _context15.abrupt("return");
47202
48443
  case 21:
47203
48444
  sn = seg ? seg.sn : audioSeg.sn;
47204
48445
  start = seg ? seg.start : audioSeg.start;
@@ -47212,26 +48453,26 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
47212
48453
  logger$4.warn("update the new playlist liveEdge, segment id=".concat(sn, ", buffer start=").concat(segStart, ", liveEdge=").concat(this._playlist.liveEdge));
47213
48454
  start = segStart;
47214
48455
  }
47215
- _context14.next = 30;
48456
+ _context15.next = 30;
47216
48457
  return this._bufferService.appendBuffer(seg, audioSeg, data2[0], data2[1], discontinuity, contiguous, start);
47217
48458
  case 30:
47218
48459
  this.emit(Event$1.APPEND_COST, {
47219
48460
  elapsed: Date.now() - before,
47220
48461
  url: seg.url
47221
48462
  });
47222
- _context14.next = 33;
48463
+ _context15.next = 33;
47223
48464
  return this._bufferService.evictBuffer(this.config.bufferBehind);
47224
48465
  case 33:
47225
48466
  this._prevSegCc = cc;
47226
48467
  this._prevSegSn = sn;
47227
- return _context14.abrupt("return", true);
48468
+ return _context15.abrupt("return", true);
47228
48469
  case 36:
47229
48470
  case "end":
47230
- return _context14.stop();
48471
+ return _context15.stop();
47231
48472
  }
47232
- }, _callee14, this, [[3, 9]]);
48473
+ }, _callee15, this, [[3, 9]]);
47233
48474
  }));
47234
- function _reqAndBufferSegment(_x10, _x11) {
48475
+ function _reqAndBufferSegment(_x9, _x10) {
47235
48476
  return _reqAndBufferSegment2.apply(this, arguments);
47236
48477
  }
47237
48478
  return _reqAndBufferSegment;
@@ -47239,11 +48480,11 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
47239
48480
  }, {
47240
48481
  key: "_onCheckQuotaExceeded",
47241
48482
  value: function() {
47242
- var _onCheckQuotaExceeded2 = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee15() {
48483
+ var _onCheckQuotaExceeded2 = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee16() {
47243
48484
  var seekTime, buffered, inBuffered, i, bufferBehind, mediaTime;
47244
- return _regeneratorRuntime$7().wrap(function _callee15$(_context15) {
48485
+ return _regeneratorRuntime$7().wrap(function _callee16$(_context16) {
47245
48486
  while (1)
47246
- switch (_context15.prev = _context15.next) {
48487
+ switch (_context16.prev = _context16.next) {
47247
48488
  case 0:
47248
48489
  seekTime = this.media.currentTime;
47249
48490
  buffered = this.media.buffered;
@@ -47251,37 +48492,37 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
47251
48492
  i = 0;
47252
48493
  case 4:
47253
48494
  if (!(i < buffered.length)) {
47254
- _context15.next = 11;
48495
+ _context16.next = 11;
47255
48496
  break;
47256
48497
  }
47257
48498
  if (!(buffered.start(0) >= seekTime && seekTime < buffered.end(i))) {
47258
- _context15.next = 8;
48499
+ _context16.next = 8;
47259
48500
  break;
47260
48501
  }
47261
48502
  inBuffered = true;
47262
- return _context15.abrupt("break", 11);
48503
+ return _context16.abrupt("break", 11);
47263
48504
  case 8:
47264
48505
  i++;
47265
- _context15.next = 4;
48506
+ _context16.next = 4;
47266
48507
  break;
47267
48508
  case 11:
47268
48509
  if (!this._bufferService.isFull()) {
47269
- _context15.next = 17;
48510
+ _context16.next = 17;
47270
48511
  break;
47271
48512
  }
47272
48513
  bufferBehind = inBuffered ? this.config.bufferBehind : 5;
47273
48514
  mediaTime = this.media.currentTime;
47274
48515
  if (!(mediaTime - bufferBehind > 0)) {
47275
- _context15.next = 17;
48516
+ _context16.next = 17;
47276
48517
  break;
47277
48518
  }
47278
- _context15.next = 17;
48519
+ _context16.next = 17;
47279
48520
  return this._bufferService.removeBuffer(0, mediaTime - bufferBehind);
47280
48521
  case 17:
47281
48522
  case "end":
47282
- return _context15.stop();
48523
+ return _context16.stop();
47283
48524
  }
47284
- }, _callee15, this);
48525
+ }, _callee16, this);
47285
48526
  }));
47286
48527
  function _onCheckQuotaExceeded() {
47287
48528
  return _onCheckQuotaExceeded2.apply(this, arguments);
@@ -47299,22 +48540,22 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
47299
48540
  }, {
47300
48541
  key: "_clear",
47301
48542
  value: function() {
47302
- var _clear2 = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee16() {
47303
- return _regeneratorRuntime$7().wrap(function _callee16$(_context16) {
48543
+ var _clear2 = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee17() {
48544
+ return _regeneratorRuntime$7().wrap(function _callee17$(_context17) {
47304
48545
  while (1)
47305
- switch (_context16.prev = _context16.next) {
48546
+ switch (_context17.prev = _context17.next) {
47306
48547
  case 0:
47307
48548
  clearTimeout(this._disconnectTimer);
47308
48549
  this._stopTick();
47309
- _context16.next = 4;
48550
+ _context17.next = 4;
47310
48551
  return Promise.all([this._segmentLoader.cancel(), this._manifestLoader.stopPoll()]);
47311
48552
  case 4:
47312
48553
  this._segmentProcessing = false;
47313
48554
  case 5:
47314
48555
  case "end":
47315
- return _context16.stop();
48556
+ return _context17.stop();
47316
48557
  }
47317
- }, _callee16, this);
48558
+ }, _callee17, this);
47318
48559
  }));
47319
48560
  function _clear() {
47320
48561
  return _clear2.apply(this, arguments);
@@ -47324,14 +48565,14 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
47324
48565
  }, {
47325
48566
  key: "_reset",
47326
48567
  value: function() {
47327
- var _reset2 = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee17() {
48568
+ var _reset2 = _asyncToGenerator$7(/* @__PURE__ */ _regeneratorRuntime$7().mark(function _callee18() {
47328
48569
  var _this$_seiService3;
47329
- var reuseMse, _args17 = arguments;
47330
- return _regeneratorRuntime$7().wrap(function _callee17$(_context17) {
48570
+ var reuseMse, _args18 = arguments;
48571
+ return _regeneratorRuntime$7().wrap(function _callee18$(_context18) {
47331
48572
  while (1)
47332
- switch (_context17.prev = _context17.next) {
48573
+ switch (_context18.prev = _context18.next) {
47333
48574
  case 0:
47334
- reuseMse = _args17.length > 0 && _args17[0] !== void 0 ? _args17[0] : false;
48575
+ reuseMse = _args18.length > 0 && _args18[0] !== void 0 ? _args18[0] : false;
47335
48576
  this._reloadOnPlay = false;
47336
48577
  this._prevSegSn = null;
47337
48578
  this._prevSegCc = null;
@@ -47340,15 +48581,15 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
47340
48581
  this._segmentLoader.reset();
47341
48582
  (_this$_seiService3 = this._seiService) === null || _this$_seiService3 === void 0 ? void 0 : _this$_seiService3.reset();
47342
48583
  this._stats.reset();
47343
- _context17.next = 11;
48584
+ _context18.next = 11;
47344
48585
  return this._clear();
47345
48586
  case 11:
47346
- return _context17.abrupt("return", this._bufferService.reset(reuseMse));
48587
+ return _context18.abrupt("return", this._bufferService.reset(reuseMse));
47347
48588
  case 12:
47348
48589
  case "end":
47349
- return _context17.stop();
48590
+ return _context18.stop();
47350
48591
  }
47351
- }, _callee17, this);
48592
+ }, _callee18, this);
47352
48593
  }));
47353
48594
  function _reset() {
47354
48595
  return _reset2.apply(this, arguments);
@@ -47466,7 +48707,7 @@ var Hls = /* @__PURE__ */ function(_EventEmitter) {
47466
48707
  }]);
47467
48708
  return Hls2;
47468
48709
  }(EventEmitter$1);
47469
- _defineProperty$d(Hls, "version", "3.0.20-alpha.2");
48710
+ _defineProperty$d(Hls, "version", "3.0.21-rc.3");
47470
48711
  try {
47471
48712
  if (localStorage.getItem("xgd")) {
47472
48713
  Hls.enableLogger();
@@ -47557,6 +48798,7 @@ var PluginExtension = /* @__PURE__ */ function() {
47557
48798
  }]);
47558
48799
  return PluginExtension2;
47559
48800
  }();
48801
+ var _excluded$2 = ["currentTime"];
47560
48802
  function parseSwitchUrlArgs(args, plugin2) {
47561
48803
  var player = plugin2.player;
47562
48804
  var curTime = player.currentTime;
@@ -47567,9 +48809,14 @@ function parseSwitchUrlArgs(args, plugin2) {
47567
48809
  case "boolean":
47568
48810
  options.seamless = args;
47569
48811
  break;
47570
- case "object":
47571
- Object.assign(options, args);
48812
+ case "object": {
48813
+ var currentTime = args.currentTime, rest = _objectWithoutProperties$3(args, _excluded$2);
48814
+ Object.assign(options, rest);
48815
+ if (typeof currentTime === "number") {
48816
+ options.startTime = currentTime;
48817
+ }
47572
48818
  break;
48819
+ }
47573
48820
  }
47574
48821
  return options;
47575
48822
  }
@@ -47579,10 +48826,11 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
47579
48826
  function HlsPlugin2() {
47580
48827
  var _this;
47581
48828
  _classCallCheck$f(this, HlsPlugin2);
47582
- for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
47583
- _args[_key] = arguments[_key];
48829
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
48830
+ args[_key] = arguments[_key];
47584
48831
  }
47585
- _this = _super.call.apply(_super, [this].concat(_args));
48832
+ _this = _super.call.apply(_super, [this].concat(args));
48833
+ _defineProperty$d(_assertThisInitialized$b(_this), "logger", logger$4);
47586
48834
  _defineProperty$d(_assertThisInitialized$b(_this), "hls", null);
47587
48835
  _defineProperty$d(_assertThisInitialized$b(_this), "pluginExtension", null);
47588
48836
  _defineProperty$d(_assertThisInitialized$b(_this), "getStats", function() {
@@ -47594,24 +48842,6 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
47594
48842
  var lang = _ref.lang;
47595
48843
  (_this$hls2 = _this.hls) === null || _this$hls2 === void 0 ? void 0 : _this$hls2.switchSubtitleStream(lang);
47596
48844
  });
47597
- _defineProperty$d(_assertThisInitialized$b(_this), "_onSwitchURL", function(url, args) {
47598
- return new Promise(function(resolve3, reject3) {
47599
- var _assertThisInitialize = _assertThisInitialized$b(_this), player = _assertThisInitialize.player, hls = _assertThisInitialize.hls;
47600
- if (hls) {
47601
- var _this$player$config, _this$player$config$h;
47602
- var options = parseSwitchUrlArgs(args, _assertThisInitialized$b(_this));
47603
- player.config.url = url;
47604
- hls.switchURL(url, options).then(function() {
47605
- return resolve3(true);
47606
- }).catch(reject3);
47607
- 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) {
47608
- _this._keepPauseStatus();
47609
- }
47610
- } else {
47611
- reject3();
47612
- }
47613
- });
47614
- });
47615
48845
  _defineProperty$d(_assertThisInitialized$b(_this), "_keepPauseStatus", function() {
47616
48846
  var paused = _this.player.paused;
47617
48847
  if (!paused)
@@ -47636,8 +48866,8 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
47636
48866
  }, {
47637
48867
  key: "softDecode",
47638
48868
  get: function get3() {
47639
- var _this$player, _this$player$config2;
47640
- 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;
48869
+ var _this$player, _this$player$config;
48870
+ 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;
47641
48871
  return !!mediaType && mediaType !== "video" && mediaType !== "audio";
47642
48872
  }
47643
48873
  }, {
@@ -47645,13 +48875,35 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
47645
48875
  value: function beforePlayerInit() {
47646
48876
  var _this2 = this;
47647
48877
  var config = this.player.config;
48878
+ var mediaElem = this.player.media || this.player.video;
47648
48879
  var hlsOpts = config.hls || {};
47649
48880
  if (!config.url && !config.__allowHlsEmptyUrl__ || !hlsOpts.preferMMS && MSE$2.isMMSOnly()) {
47650
48881
  return;
47651
48882
  }
47652
48883
  if (this.hls)
47653
48884
  this.hls.destroy();
47654
- this.player.switchURL = this._onSwitchURL;
48885
+ var descriptor = Object.getOwnPropertyDescriptor(this.player, "switchURL");
48886
+ if (!descriptor || descriptor.writable) {
48887
+ this.player.switchURL = function(url, args) {
48888
+ return new Promise(function(resolve3, reject3) {
48889
+ var player = _this2.player, hls = _this2.hls;
48890
+ if (hls) {
48891
+ var _this2$player$config, _this2$player$config$;
48892
+ var options = parseSwitchUrlArgs(args, _this2);
48893
+ player.config.url = url;
48894
+ hls.switchURL(url, options).then(function() {
48895
+ return resolve3(true);
48896
+ }).catch(reject3);
48897
+ 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) {
48898
+ _this2._keepPauseStatus();
48899
+ }
48900
+ } else {
48901
+ reject3();
48902
+ }
48903
+ });
48904
+ };
48905
+ }
48906
+ var onSwitchUrl = this.player.switchURL;
47655
48907
  this.player.handleSource = false;
47656
48908
  hlsOpts.innerDegrade = hlsOpts.innerDegrade || config.innerDegrade;
47657
48909
  if (hlsOpts.disconnectTime === null || hlsOpts.disconnectTime === void 0)
@@ -47659,7 +48911,7 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
47659
48911
  this.hls = new Hls(_objectSpread2$6({
47660
48912
  softDecode: this.softDecode,
47661
48913
  isLive: config.isLive,
47662
- media: this.player.media || this.player.video,
48914
+ media: mediaElem,
47663
48915
  startTime: config.startTime,
47664
48916
  url: config.url
47665
48917
  }, hlsOpts));
@@ -47677,7 +48929,7 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
47677
48929
  if (this.softDecode) {
47678
48930
  this.pluginExtension = new PluginExtension(_objectSpread2$6({
47679
48931
  isLive: config.isLive,
47680
- media: this.player.video
48932
+ media: mediaElem
47681
48933
  }, hlsOpts), this);
47682
48934
  this.player.forceDegradeToVideo = function() {
47683
48935
  var _this2$pluginExtensio;
@@ -47694,8 +48946,8 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
47694
48946
  return (_this2$hls2 = _this2.hls) === null || _this2$hls2 === void 0 ? void 0 : _this2$hls2.replay();
47695
48947
  });
47696
48948
  }
48949
+ this.on(URL_CHANGE, onSwitchUrl);
47697
48950
  this.on(SWITCH_SUBTITLE, this._onSwitchSubtitle);
47698
- this.on(URL_CHANGE, this._onSwitchURL);
47699
48951
  this.on(DESTROY, this.destroy.bind(this));
47700
48952
  this._transError();
47701
48953
  this._transCoreEvent(EVENT$1.TTFB);
@@ -47705,6 +48957,7 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
47705
48957
  this._transCoreEvent(EVENT$1.LOAD_RETRY);
47706
48958
  this._transCoreEvent(EVENT$1.SOURCEBUFFER_CREATED);
47707
48959
  this._transCoreEvent(EVENT$1.MEDIASOURCE_OPENED);
48960
+ this._transCoreEvent(EVENT$1.APPEND_BUFFER);
47708
48961
  this._transCoreEvent(EVENT$1.REMOVE_BUFFER);
47709
48962
  this._transCoreEvent(EVENT$1.BUFFEREOS);
47710
48963
  this._transCoreEvent(EVENT$1.KEYFRAME);
@@ -47724,7 +48977,9 @@ var HlsPlugin = /* @__PURE__ */ function(_BasePlugin) {
47724
48977
  this._transCoreEvent(Event$1.SUBTITLE_PLAYLIST);
47725
48978
  this._transCoreEvent(Event$1.APPEND_COST);
47726
48979
  if (config.url) {
47727
- this.hls.load(config.url, true).catch(function(e) {
48980
+ this.hls.load(config.url, {
48981
+ reuseMse: true
48982
+ }).catch(function(e) {
47728
48983
  });
47729
48984
  }
47730
48985
  }
@@ -70478,8 +71733,11 @@ var AD_START = "ad_start";
70478
71733
  var AD_PLAY = "ad_play";
70479
71734
  var AD_PAUSE = "ad_pause";
70480
71735
  var AD_TIME_UPDATE = "ad_time_update";
71736
+ var AD_SKIPPED = "ad_skipped";
71737
+ var AD_ERROR = "ad_error";
70481
71738
  var AD_COMPLETE = "ad_complete";
70482
71739
  var AD_ALL_COMPLETED = "ad_all_completed";
71740
+ var IMA_SDK_LOAD_START = "ima_sdk_load_start";
70483
71741
  var IMA_SDK_LOAD_SUCCESS = "ima_sdk_load_success";
70484
71742
  var IMA_SDK_LOAD_ERROR = "ima_sdk_load_error";
70485
71743
  var IMA_AD_LOADER_READY = "ima_ad_loader_ready";
@@ -71561,16 +72819,18 @@ var ImaAdManager = /* @__PURE__ */ function(_BaseAdManager) {
71561
72819
  _this._handleAdError(ev.getError());
71562
72820
  });
71563
72821
  _defineProperty$6(_assertThisInitialized$5(_this), "_handleAdError", function(error) {
71564
- var _this$adsManager3;
72822
+ var _this$adsManager3, _this$plugin, _this$plugin2;
71565
72823
  logger$1.log("AdError", error);
71566
72824
  _this.shouldBlockVideoContent = false;
71567
72825
  _this.isLinearAdRunning = false;
71568
72826
  (_this$adsManager3 = _this.adsManager) === null || _this$adsManager3 === void 0 ? void 0 : _this$adsManager3.destroy();
71569
- _this.player.emit(IMA_AD_ERROR, error);
72827
+ (_this$plugin = _this.plugin) === null || _this$plugin === void 0 ? void 0 : _this$plugin.emit(IMA_AD_ERROR, error);
72828
+ (_this$plugin2 = _this.plugin) === null || _this$plugin2 === void 0 ? void 0 : _this$plugin2.emit(AD_ERROR, error);
71570
72829
  });
71571
72830
  _defineProperty$6(_assertThisInitialized$5(_this), "onAdEvent", function(ev) {
71572
72831
  var _assertThisInitialize2 = _assertThisInitialized$5(_this), player = _assertThisInitialize2.player;
71573
72832
  var ad = ev === null || ev === void 0 ? void 0 : ev.getAd();
72833
+ var adData = (ev === null || ev === void 0 ? void 0 : ev.getAdData()) || (ad === null || ad === void 0 ? void 0 : ad.data);
71574
72834
  var intervalTimer;
71575
72835
  var printJsonLog = false;
71576
72836
  switch (ev === null || ev === void 0 ? void 0 : ev.type) {
@@ -71581,7 +72841,7 @@ var ImaAdManager = /* @__PURE__ */ function(_BaseAdManager) {
71581
72841
  break;
71582
72842
  }
71583
72843
  case google.ima.AdEvent.Type.LOADED: {
71584
- var _ev$getAdData = ev.getAdData(), adPodInfo = _ev$getAdData.adPodInfo;
72844
+ var _ref = adData || {}, adPodInfo = _ref.adPodInfo;
71585
72845
  var isPreroll = (adPodInfo === null || adPodInfo === void 0 ? void 0 : adPodInfo.podIndex) === 0;
71586
72846
  printJsonLog = true;
71587
72847
  if (isPreroll) {
@@ -71592,8 +72852,13 @@ var ImaAdManager = /* @__PURE__ */ function(_BaseAdManager) {
71592
72852
  _this.tryContentPlay();
71593
72853
  }
71594
72854
  }
72855
+ _this.emit(IMA_AD_LOADED, {
72856
+ ad,
72857
+ isPreroll
72858
+ });
71595
72859
  _this.plugin.emit(IMA_AD_LOADED, {
71596
- ad
72860
+ ad,
72861
+ isPreroll
71597
72862
  });
71598
72863
  break;
71599
72864
  }
@@ -71642,8 +72907,14 @@ var ImaAdManager = /* @__PURE__ */ function(_BaseAdManager) {
71642
72907
  });
71643
72908
  break;
71644
72909
  }
72910
+ case google.ima.AdEvent.Type.SKIPPED: {
72911
+ _this.plugin.emit(AD_SKIPPED, {
72912
+ ad
72913
+ });
72914
+ break;
72915
+ }
71645
72916
  case google.ima.AdEvent.Type.AD_PROGRESS: {
71646
- var _ev$getAdData2 = ev.getAdData(), currentTime = _ev$getAdData2.currentTime, duration = _ev$getAdData2.duration;
72917
+ var _ev$getAdData = ev.getAdData(), currentTime = _ev$getAdData.currentTime, duration = _ev$getAdData.duration;
71647
72918
  Object.assign(_this.context, {
71648
72919
  currentTime,
71649
72920
  duration
@@ -71654,14 +72925,21 @@ var ImaAdManager = /* @__PURE__ */ function(_BaseAdManager) {
71654
72925
  break;
71655
72926
  }
71656
72927
  case google.ima.AdEvent.Type.COMPLETE: {
72928
+ var _ref2 = adData || {}, _adPodInfo = _ref2.adPodInfo;
72929
+ var hasNextInPod = false;
71657
72930
  if (ad !== null && ad !== void 0 && ad.isLinear()) {
72931
+ if (_adPodInfo) {
72932
+ hasNextInPod = _adPodInfo.adPosition < _adPodInfo.totalAds;
72933
+ }
71658
72934
  clearInterval(intervalTimer);
71659
72935
  }
71660
72936
  _this.plugin.emit(IMA_AD_COMPLETE, {
71661
- ad
72937
+ ad,
72938
+ hasNextInPod
71662
72939
  });
71663
72940
  _this.plugin.emit(AD_COMPLETE, {
71664
- ad
72941
+ ad,
72942
+ hasNextInPod
71665
72943
  });
71666
72944
  break;
71667
72945
  }
@@ -71700,30 +72978,31 @@ var ImaAdManager = /* @__PURE__ */ function(_BaseAdManager) {
71700
72978
  case 0:
71701
72979
  this.shouldBlockVideoContent = !!(this.config.adTagUrl || this.config.adsResponse || this.config.adsRequest);
71702
72980
  _context.prev = 1;
71703
- _context.next = 4;
72981
+ this.emit(IMA_SDK_LOAD_START);
72982
+ _context.next = 5;
71704
72983
  return this._loadIMASdk();
71705
- case 4:
72984
+ case 5:
71706
72985
  this.emit(IMA_SDK_LOAD_SUCCESS);
71707
- _context.next = 13;
72986
+ _context.next = 14;
71708
72987
  break;
71709
- case 7:
71710
- _context.prev = 7;
72988
+ case 8:
72989
+ _context.prev = 8;
71711
72990
  _context.t0 = _context["catch"](1);
71712
72991
  logger$1.error("google.ima sdk is not loaded, due to error", (_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message) || _context.t0);
71713
72992
  this.emit(IMA_SDK_LOAD_ERROR);
71714
72993
  this.shouldBlockVideoContent = false;
71715
72994
  return _context.abrupt("return");
71716
- case 13:
72995
+ case 14:
71717
72996
  this._initConfig();
71718
72997
  this._initMediaEvents();
71719
72998
  this._initContainer();
71720
72999
  this._initLoader();
71721
73000
  this._initAdsRequest();
71722
- case 18:
73001
+ case 19:
71723
73002
  case "end":
71724
73003
  return _context.stop();
71725
73004
  }
71726
- }, _callee, this, [[1, 7]]);
73005
+ }, _callee, this, [[1, 8]]);
71727
73006
  }));
71728
73007
  function init() {
71729
73008
  return _init.apply(this, arguments);
@@ -71980,14 +73259,14 @@ var ImaAdManager = /* @__PURE__ */ function(_BaseAdManager) {
71980
73259
  _context3.next = 4;
71981
73260
  return Promise.all([autoplay ? index.video({
71982
73261
  timeout
71983
- }).then(function(_ref) {
71984
- var result = _ref.result;
73262
+ }).then(function(_ref3) {
73263
+ var result = _ref3.result;
71985
73264
  return result;
71986
73265
  }) : Promise.resolve(false), autoplay && this.player.config.autoplayMuted ? index.video({
71987
73266
  timeout,
71988
73267
  muted: true
71989
- }).then(function(_ref2) {
71990
- var result = _ref2.result;
73268
+ }).then(function(_ref4) {
73269
+ var result = _ref4.result;
71991
73270
  return result;
71992
73271
  }) : Promise.resolve(false)]);
71993
73272
  case 4:
@@ -72013,7 +73292,8 @@ var ImaAdManager = /* @__PURE__ */ function(_BaseAdManager) {
72013
73292
  return ImaAdManager2;
72014
73293
  }(BaseAdManager);
72015
73294
  var AD_STATE_CLASS = {
72016
- START: "xgplayer-ad-start"
73295
+ START: "xgplayer-ad-start",
73296
+ UI_SHOW: "xgplayer-ad-show-ui"
72017
73297
  };
72018
73298
  var AdPlayIcon = /* @__PURE__ */ function(_PlayIcon) {
72019
73299
  _inherits$5(AdPlayIcon2, _PlayIcon);
@@ -72165,9 +73445,9 @@ var AdTimeIcon = /* @__PURE__ */ function(_TimeIcon) {
72165
73445
  return AdTimeIcon2;
72166
73446
  }(Time);
72167
73447
  var AdUIManager = /* @__PURE__ */ function() {
72168
- function AdUIManager2(config, _ref) {
72169
- var player = _ref.player, plugin2 = _ref.plugin;
73448
+ function AdUIManager2(config, options) {
72170
73449
  _classCallCheck$8(this, AdUIManager2);
73450
+ var player = options.player, plugin2 = options.plugin;
72171
73451
  this.player = player;
72172
73452
  this.config = config;
72173
73453
  this.adPlugin = plugin2;
@@ -72182,8 +73462,8 @@ var AdUIManager = /* @__PURE__ */ function() {
72182
73462
  key: "init",
72183
73463
  value: function init() {
72184
73464
  var player = this.player, adUIPlugins = this.adUIPlugins, fragment = this.fragment, decoratedAdPluginList = this.decoratedAdPluginList;
72185
- decoratedAdPluginList.forEach(function(_ref2) {
72186
- var _ref3 = _slicedToArray$2(_ref2, 2), targetClass = _ref3[0], decoratorClass = _ref3[1];
73465
+ decoratedAdPluginList.forEach(function(_ref) {
73466
+ var _ref2 = _slicedToArray$2(_ref, 2), targetClass = _ref2[0], decoratorClass = _ref2[1];
72187
73467
  var targetPlugin = player.getPlugin(targetClass.pluginName);
72188
73468
  if (targetPlugin) {
72189
73469
  var newDecoratorPlugin = null;
@@ -72196,6 +73476,15 @@ var AdUIManager = /* @__PURE__ */ function() {
72196
73476
  }
72197
73477
  });
72198
73478
  }
73479
+ }, {
73480
+ key: "destroy",
73481
+ value: function destroy() {
73482
+ this.fragment = null;
73483
+ this.adUIPlugins = [];
73484
+ this.decoratedAdPluginList = [];
73485
+ this.adPlugin = null;
73486
+ this.player = null;
73487
+ }
72199
73488
  }, {
72200
73489
  key: "initEvents",
72201
73490
  value: function initEvents() {
@@ -72211,7 +73500,16 @@ var AdUIManager = /* @__PURE__ */ function() {
72211
73500
  adPlugin.on(AD_START, function() {
72212
73501
  _this.showAdContainer();
72213
73502
  });
72214
- adPlugin.on(AD_COMPLETE, function() {
73503
+ adPlugin.on(AD_COMPLETE, function(_ref3) {
73504
+ var hasNextInPod = _ref3.hasNextInPod;
73505
+ if (!hasNextInPod) {
73506
+ _this.hideAdContainer();
73507
+ }
73508
+ });
73509
+ adPlugin.on(AD_SKIPPED, function() {
73510
+ _this.hideAdContainer();
73511
+ });
73512
+ adPlugin.on(AD_ERROR, function() {
72215
73513
  _this.hideAdContainer();
72216
73514
  });
72217
73515
  }
@@ -72267,6 +73565,7 @@ var AdUIManager = /* @__PURE__ */ function() {
72267
73565
  this.hideControls();
72268
73566
  }
72269
73567
  this.showAdContainer();
73568
+ player.addClass(AD_STATE_CLASS.UI_SHOW);
72270
73569
  }
72271
73570
  }, {
72272
73571
  key: "hideAdUI",
@@ -72317,6 +73616,7 @@ var AdUIManager = /* @__PURE__ */ function() {
72317
73616
  }, 10);
72318
73617
  });
72319
73618
  }
73619
+ player.removeClass(AD_STATE_CLASS.UI_SHOW);
72320
73620
  }
72321
73621
  }, {
72322
73622
  key: "hideControls",
@@ -72393,7 +73693,7 @@ var AdsPlugin$1 = /* @__PURE__ */ function(_Plugin) {
72393
73693
  _createClass$8(AdsPlugin2, [{
72394
73694
  key: "version",
72395
73695
  get: function get3() {
72396
- return "3.0.20-alpha.7";
73696
+ return "3.0.20-alpha.8";
72397
73697
  }
72398
73698
  }, {
72399
73699
  key: "paused",
@@ -72462,6 +73762,18 @@ var AdsPlugin$1 = /* @__PURE__ */ function(_Plugin) {
72462
73762
  config: this.config.ima,
72463
73763
  displayContainer: this.root
72464
73764
  });
73765
+ this.csManager.once(IMA_SDK_LOAD_START, function() {
73766
+ _this.uiManager.showAdContainer();
73767
+ });
73768
+ this.csManager.on(IMA_SDK_LOAD_ERROR, function() {
73769
+ _this.uiManager.hideAdContainer();
73770
+ });
73771
+ this.csManager.once(IMA_AD_LOADED, function(_ref) {
73772
+ var isPreroll = _ref.isPreroll;
73773
+ if (!isPreroll) {
73774
+ _this.uiManager.hideAdContainer();
73775
+ }
73776
+ });
72465
73777
  this.csManager.once(IMA_READY_TO_PLAY, function() {
72466
73778
  var _this$initPromise;
72467
73779
  (_this$initPromise = _this.initPromise) === null || _this$initPromise === void 0 ? void 0 : _this$initPromise.resolve();
@@ -72501,8 +73813,10 @@ var AdsPlugin$1 = /* @__PURE__ */ function(_Plugin) {
72501
73813
  }, {
72502
73814
  key: "destroy",
72503
73815
  value: function destroy() {
72504
- var _this$csManager9;
73816
+ var _this$csManager9, _this$uiManager;
73817
+ this.offAll();
72505
73818
  (_this$csManager9 = this.csManager) === null || _this$csManager9 === void 0 ? void 0 : _this$csManager9.destroy();
73819
+ (_this$uiManager = this.uiManager) === null || _this$uiManager === void 0 ? void 0 : _this$uiManager.destroy();
72506
73820
  }
72507
73821
  }, {
72508
73822
  key: "reset",
@@ -76557,7 +77871,7 @@ var sort$1 = sort$2;
76557
77871
  var sort5 = sort$1;
76558
77872
  var _sortInstanceProperty = /* @__PURE__ */ getDefaultExportFromCjs(sort5);
76559
77873
  function scheduleToVmap(schedule) {
76560
- var _context;
77874
+ var _context, _context2;
76561
77875
  if (!schedule || !schedule.length) {
76562
77876
  return;
76563
77877
  }
@@ -76567,7 +77881,10 @@ function scheduleToVmap(schedule) {
76567
77881
  var midRollCount = 0;
76568
77882
  var curMidRoll;
76569
77883
  var curMidRollAdsCount = 0;
76570
- _forEachInstanceProperty(_context = _sortInstanceProperty(schedule).call(schedule, function(a, b) {
77884
+ _forEachInstanceProperty(_context = _sortInstanceProperty(_context2 = _filterInstanceProperty(schedule).call(schedule, function(_ref) {
77885
+ var offset = _ref.offset;
77886
+ return offset === "pre" || offset === "post" || /^(\d\d):([0-5]\d):([0-5]\d)(.\d\d\d)?$/.test(offset);
77887
+ })).call(_context2, function(a, b) {
76571
77888
  if (a.offset === "pre" || b.offset === "post") {
76572
77889
  return -1;
76573
77890
  }
@@ -76575,9 +77892,9 @@ function scheduleToVmap(schedule) {
76575
77892
  return 1;
76576
77893
  }
76577
77894
  return Date.parse("2024-01-01T".concat(a.offset)) < Date.parse("2024-01-01T".concat(b.offset)) ? -1 : 1;
76578
- })).call(_context, function(_ref) {
76579
- var _context2;
76580
- var offset = _ref.offset, type = _ref.type, tag = _ref.tag;
77895
+ })).call(_context, function(_ref2) {
77896
+ var _context3;
77897
+ var offset = _ref2.offset, type = _ref2.type, tag = _ref2.tag;
76581
77898
  var timeOffset;
76582
77899
  var breakId;
76583
77900
  switch (offset) {
@@ -76607,7 +77924,7 @@ function scheduleToVmap(schedule) {
76607
77924
  adBreakElement.setAttribute("breakType", type || "linear");
76608
77925
  root[0].appendChild(adBreakElement);
76609
77926
  var adSourceElement = vmapXml.createElement("vmap:AdSource");
76610
- adSourceElement.setAttribute("id", _concatInstanceProperty(_context2 = "".concat(breakId, "-ad-")).call(_context2, curMidRollAdsCount));
77927
+ adSourceElement.setAttribute("id", _concatInstanceProperty(_context3 = "".concat(breakId, "-ad-")).call(_context3, curMidRollAdsCount));
76611
77928
  adSourceElement.setAttribute("allowMultipleAds", "true");
76612
77929
  adSourceElement.setAttribute("followRedirects", "true");
76613
77930
  adBreakElement.appendChild(adSourceElement);
@@ -76641,10 +77958,10 @@ var AdsPlugin = /* @__PURE__ */ function(_XGAdsPlugin) {
76641
77958
  var ad = _ref.ad;
76642
77959
  if (isPrerollAd(ad)) {
76643
77960
  var _this$player$plugins$, _this$player$plugins$2;
76644
- (_this$player$plugins$ = (_this$player$plugins$2 = _this.player.plugins.autoplayplugin).handleAutoplayStart) === null || _this$player$plugins$ === void 0 ? void 0 : _this$player$plugins$.call(_this$player$plugins$2);
77961
+ (_this$player$plugins$ = _this.player.plugins.autoplayplugin) === null || _this$player$plugins$ === void 0 || (_this$player$plugins$2 = _this$player$plugins$.handleAutoplayStart) === null || _this$player$plugins$2 === void 0 ? void 0 : _this$player$plugins$2.call(_this$player$plugins$);
76645
77962
  _this.player.once(VOLUME_CHANGE, function() {
76646
77963
  var _this$player$plugins$3, _this$player$plugins$4;
76647
- (_this$player$plugins$3 = (_this$player$plugins$4 = _this.player.plugins.autoplayplugin).initState) === null || _this$player$plugins$3 === void 0 ? void 0 : _this$player$plugins$3.call(_this$player$plugins$4);
77964
+ (_this$player$plugins$3 = _this.player.plugins.autoplayplugin) === null || _this$player$plugins$3 === void 0 || (_this$player$plugins$4 = _this$player$plugins$3.initState) === null || _this$player$plugins$4 === void 0 ? void 0 : _this$player$plugins$4.call(_this$player$plugins$3);
76648
77965
  });
76649
77966
  }
76650
77967
  });
@@ -76685,9 +78002,7 @@ var AdsPlugin = /* @__PURE__ */ function(_XGAdsPlugin) {
76685
78002
  if (!((_this$config$ima2 = this.config.ima) !== null && _this$config$ima2 !== void 0 && _this$config$ima2.adTagUrl) && (_this$config$ima3 = this.config.ima) !== null && _this$config$ima3 !== void 0 && (_this$config$ima3 = _this$config$ima3.schedule) !== null && _this$config$ima3 !== void 0 && _this$config$ima3.length) {
76686
78003
  this.config.ima.adsResponse = scheduleToVmap(this.config.ima.schedule);
76687
78004
  }
76688
- if (this.player.plugins.autoplayplugin) {
76689
- this.player.once(AD_PLAY, this._handlePrerollMuted);
76690
- }
78005
+ this.player.once(AD_PLAY, this._handlePrerollMuted);
76691
78006
  }
76692
78007
  }], [{
76693
78008
  key: "pluginName",