@volcengine/veplayer-plugin 2.4.2-rc.2 → 2.4.3-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/esm/index.development.js +2048 -1313
  2. package/esm/index.production.js +4 -4
  3. package/esm/veplayer.plugin.abr.development.js +71 -3
  4. package/esm/veplayer.plugin.abr.production.js +1 -1
  5. package/esm/veplayer.plugin.drm.development.js +71 -3
  6. package/esm/veplayer.plugin.drm.production.js +1 -1
  7. package/esm/veplayer.plugin.flv.development.js +727 -196
  8. package/esm/veplayer.plugin.flv.production.js +1 -1
  9. package/esm/veplayer.plugin.hls.development.js +1237 -308
  10. package/esm/veplayer.plugin.hls.production.js +1 -1
  11. package/esm/veplayer.plugin.mp4.development.js +73 -5
  12. package/esm/veplayer.plugin.mp4.production.js +1 -1
  13. package/esm/veplayer.plugin.rtm.development.js +189 -778
  14. package/esm/veplayer.plugin.rtm.production.js +1 -1
  15. package/esm/veplayer.plugin.shaka.development.js +72 -4
  16. package/esm/veplayer.plugin.shaka.production.js +1 -1
  17. package/package.json +1 -1
  18. package/umd/veplayer.plugin.abr.development.js +71 -3
  19. package/umd/veplayer.plugin.abr.production.js +1 -1
  20. package/umd/veplayer.plugin.drm.development.js +71 -3
  21. package/umd/veplayer.plugin.drm.production.js +1 -1
  22. package/umd/veplayer.plugin.flv.development.js +727 -196
  23. package/umd/veplayer.plugin.flv.production.js +1 -1
  24. package/umd/veplayer.plugin.hls.development.js +1237 -308
  25. package/umd/veplayer.plugin.hls.production.js +1 -1
  26. package/umd/veplayer.plugin.mp4.development.js +73 -5
  27. package/umd/veplayer.plugin.mp4.production.js +1 -1
  28. package/umd/veplayer.plugin.rtm.development.js +189 -778
  29. package/umd/veplayer.plugin.rtm.production.js +1 -1
  30. package/umd/veplayer.plugin.shaka.development.js +72 -4
  31. package/umd/veplayer.plugin.shaka.production.js +1 -1
@@ -1538,7 +1538,7 @@ util.getCurrentTimeByOffset = function(offsetTime, segments) {
1538
1538
  }
1539
1539
  return offsetTime;
1540
1540
  };
1541
- var version = "3.0.19-rc.0";
1541
+ var version = "3.0.20-rc.6";
1542
1542
  var ERROR_MAP = {
1543
1543
  1: 5101,
1544
1544
  2: 5102,
@@ -1646,8 +1646,7 @@ function hook(hookName, handler) {
1646
1646
  }
1647
1647
  if (this.__hooks && this.__hooks[hookName]) {
1648
1648
  try {
1649
- var _this$__hooks$hookNam;
1650
- var preRet = (_this$__hooks$hookNam = this.__hooks[hookName]).call.apply(_this$__hooks$hookNam, [this, this].concat(Array.prototype.slice.call(arguments)));
1649
+ var preRet = runHooks(this, hookName, handler);
1651
1650
  if (preRet) {
1652
1651
  if (preRet.then) {
1653
1652
  preRet.then(function(isContinue) {
@@ -1672,6 +1671,19 @@ function hook(hookName, handler) {
1672
1671
  }
1673
1672
  }.bind(this);
1674
1673
  }
1674
+ function findHookIndex(hookName, handler) {
1675
+ var __hooks = this.__hooks;
1676
+ if (!__hooks || !Array.isArray(__hooks[hookName])) {
1677
+ return -1;
1678
+ }
1679
+ var hookHandlers = __hooks[hookName];
1680
+ for (var i = 0; i < hookHandlers.length; i++) {
1681
+ if (hookHandlers[i] === handler) {
1682
+ return i;
1683
+ }
1684
+ }
1685
+ return -1;
1686
+ }
1675
1687
  function useHooks(hookName, handler) {
1676
1688
  var __hooks = this.__hooks;
1677
1689
  if (!__hooks) {
@@ -1681,7 +1693,12 @@ function useHooks(hookName, handler) {
1681
1693
  console.warn("has no supported hook which name [".concat(hookName, "]"));
1682
1694
  return false;
1683
1695
  }
1684
- __hooks && (__hooks[hookName] = handler);
1696
+ if (!Array.isArray(__hooks[hookName])) {
1697
+ __hooks[hookName] = [];
1698
+ }
1699
+ if (findHookIndex.call(this, hookName, handler) === -1) {
1700
+ __hooks[hookName].push(handler);
1701
+ }
1685
1702
  return true;
1686
1703
  }
1687
1704
  function removeHooks(hookName, handler) {
@@ -1689,6 +1706,13 @@ function removeHooks(hookName, handler) {
1689
1706
  if (!__hooks) {
1690
1707
  return;
1691
1708
  }
1709
+ if (Array.isArray(__hooks[hookName])) {
1710
+ var hooks = __hooks[hookName];
1711
+ var index = findHookIndex.call(this, hookName, handler);
1712
+ if (index !== -1) {
1713
+ hooks.splice(index, 1);
1714
+ }
1715
+ }
1692
1716
  delete __hooks[hookName];
1693
1717
  }
1694
1718
  function hooksDescriptor(instance) {
@@ -1710,6 +1734,38 @@ function hooksDescriptor(instance) {
1710
1734
  function delHooksDescriptor(instance) {
1711
1735
  instance.__hooks = null;
1712
1736
  }
1737
+ function runHooks(obj, hookName, handler) {
1738
+ for (var _len5 = arguments.length, args = new Array(_len5 > 3 ? _len5 - 3 : 0), _key5 = 3; _key5 < _len5; _key5++) {
1739
+ args[_key5 - 3] = arguments[_key5];
1740
+ }
1741
+ if (obj.__hooks && Array.isArray(obj.__hooks[hookName])) {
1742
+ var hooks = obj.__hooks[hookName];
1743
+ var index = -1;
1744
+ var runHooksRecursive = function runHooksRecursive2(obj2, hookName2, handler2) {
1745
+ for (var _len6 = arguments.length, args2 = new Array(_len6 > 3 ? _len6 - 3 : 0), _key6 = 3; _key6 < _len6; _key6++) {
1746
+ args2[_key6 - 3] = arguments[_key6];
1747
+ }
1748
+ index++;
1749
+ if (hooks.length === 0 || index === hooks.length) {
1750
+ return handler2.call.apply(handler2, [obj2, obj2].concat(args2));
1751
+ }
1752
+ var hook2 = hooks[index];
1753
+ var ret = hook2.call.apply(hook2, [obj2, obj2].concat(args2));
1754
+ if (ret && ret.then) {
1755
+ return ret.then(function(data) {
1756
+ return data === false ? null : runHooksRecursive2.apply(void 0, [obj2, hookName2, handler2].concat(args2));
1757
+ }).catch(function(e) {
1758
+ console.warn("[runHooks]".concat(hookName2, " reject"), e.message);
1759
+ });
1760
+ } else if (ret !== false) {
1761
+ return runHooksRecursive2.apply(void 0, [obj2, hookName2, handler2].concat(args2));
1762
+ }
1763
+ };
1764
+ return runHooksRecursive.apply(void 0, [obj, hookName, handler].concat(args));
1765
+ } else {
1766
+ return handler.call.apply(handler, [obj, obj].concat(args));
1767
+ }
1768
+ }
1713
1769
  function showErrorMsg(pluginName, msg) {
1714
1770
  XG_DEBUG.logError("[".concat(pluginName, "] event or callback cant be undefined or null when call ").concat(msg));
1715
1771
  }
@@ -1949,6 +2005,18 @@ var BasePlugin = /* @__PURE__ */ function() {
1949
2005
  }
1950
2006
  }
1951
2007
  }
2008
+ }, {
2009
+ key: "defineMethod",
2010
+ value: function defineMethod(Obj, map) {
2011
+ for (var key in map) {
2012
+ if (Object.prototype.hasOwnProperty.call(map, key) && typeof map[key] === "function") {
2013
+ Object.defineProperty(Obj, key, {
2014
+ configurable: true,
2015
+ value: map[key]
2016
+ });
2017
+ }
2018
+ }
2019
+ }
1952
2020
  }, {
1953
2021
  key: "defaultConfig",
1954
2022
  get: function get() {
@@ -2759,6 +2827,21 @@ var Buffer$1 = /* @__PURE__ */ function() {
2759
2827
  length: Buffer2.totalLength && Buffer2.totalLength(buffers)
2760
2828
  };
2761
2829
  }
2830
+ }, {
2831
+ key: "isBuffered",
2832
+ value: function isBuffered(media, pos) {
2833
+ if (media) {
2834
+ var buffered = Buffer2.get(media);
2835
+ if (buffered !== null && buffered !== void 0 && buffered.length) {
2836
+ for (var i = 0; i < buffered.length; i++) {
2837
+ if (pos >= buffered.start(i) && pos <= buffered.end(i)) {
2838
+ return true;
2839
+ }
2840
+ }
2841
+ }
2842
+ }
2843
+ return false;
2844
+ }
2762
2845
  }]);
2763
2846
  return Buffer2;
2764
2847
  }();
@@ -2911,7 +2994,7 @@ var Logger$2 = /* @__PURE__ */ function() {
2911
2994
  this.logCache.apply(this, [LogCacheLevel.DEBUG].concat(args));
2912
2995
  if (Logger2.disabled)
2913
2996
  return;
2914
- (_console = console).debug.apply(_console, [this._prefix, nowTime$1()].concat(args));
2997
+ (_console = console).debug.apply(_console, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
2915
2998
  }
2916
2999
  }, {
2917
3000
  key: "log",
@@ -2923,7 +3006,7 @@ var Logger$2 = /* @__PURE__ */ function() {
2923
3006
  this.logCache.apply(this, [LogCacheLevel.LOG].concat(args));
2924
3007
  if (Logger2.disabled)
2925
3008
  return;
2926
- (_console2 = console).log.apply(_console2, [this._prefix, nowTime$1()].concat(args));
3009
+ (_console2 = console).log.apply(_console2, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
2927
3010
  }
2928
3011
  }, {
2929
3012
  key: "warn",
@@ -2935,7 +3018,7 @@ var Logger$2 = /* @__PURE__ */ function() {
2935
3018
  this.logCache.apply(this, [LogCacheLevel.WARN].concat(args));
2936
3019
  if (Logger2.disabled)
2937
3020
  return;
2938
- (_console3 = console).warn.apply(_console3, [this._prefix, nowTime$1()].concat(args));
3021
+ (_console3 = console).warn.apply(_console3, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
2939
3022
  }
2940
3023
  }, {
2941
3024
  key: "error",
@@ -2947,7 +3030,7 @@ var Logger$2 = /* @__PURE__ */ function() {
2947
3030
  this.logCache.apply(this, [LogCacheLevel.ERROR].concat(args));
2948
3031
  if (Logger2.disabled)
2949
3032
  return;
2950
- (_console4 = console).error.apply(_console4, [this._prefix, nowTime$1()].concat(args));
3033
+ (_console4 = console).error.apply(_console4, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
2951
3034
  }
2952
3035
  }, {
2953
3036
  key: "logCache",
@@ -2962,7 +3045,7 @@ var Logger$2 = /* @__PURE__ */ function() {
2962
3045
  var finLogText = logText.map(function(item) {
2963
3046
  return logable(item);
2964
3047
  });
2965
- text = this._prefix + nowTime$1() + JSON.stringify(finLogText);
3048
+ text = "[".concat(nowTime$1(), "]") + this._prefix + JSON.stringify(finLogText);
2966
3049
  } catch (e) {
2967
3050
  return;
2968
3051
  }
@@ -3878,8 +3961,8 @@ function createResponse(data, done, response, contentLength, age, startTime, fir
3878
3961
  response
3879
3962
  };
3880
3963
  }
3881
- function calculateSpeed(byteLen, millisec) {
3882
- return Math.round(byteLen * 8 * 1e3 / millisec / 1024);
3964
+ function calculateSpeed(byteLen, milliSecond) {
3965
+ return Math.round(byteLen * 8 * 1e3 / milliSecond / 1024);
3883
3966
  }
3884
3967
  var EVENT = {
3885
3968
  ERROR: "error",
@@ -3891,6 +3974,7 @@ var EVENT = {
3891
3974
  SOURCEBUFFER_CREATED: "core.sourcebuffercreated",
3892
3975
  MEDIASOURCE_OPENED: "core.mediasourceopened",
3893
3976
  ANALYZE_DURATION_EXCEEDED: "core.analyzedurationexceeded",
3977
+ APPEND_BUFFER: "core.appendbuffer",
3894
3978
  REMOVE_BUFFER: "core.removebuffer",
3895
3979
  BUFFEREOS: "core.buffereos",
3896
3980
  KEYFRAME: "core.keyframe",
@@ -5523,13 +5607,15 @@ var TrackType = {
5523
5607
  METADATA: "metadata"
5524
5608
  };
5525
5609
  var VideoCodecType = {
5610
+ AV1: "av1",
5526
5611
  AVC: "avc",
5527
5612
  HEVC: "hevc"
5528
5613
  };
5529
5614
  var AudioCodecType = {
5530
5615
  AAC: "aac",
5531
5616
  G711PCMA: "g7110a",
5532
- G711PCMU: "g7110m"
5617
+ G711PCMU: "g7110m",
5618
+ OPUS: "opus"
5533
5619
  };
5534
5620
  var WarningType = {
5535
5621
  LARGE_AV_SHIFT: "LARGE_AV_SHIFT",
@@ -5569,6 +5655,7 @@ var VideoTrack = /* @__PURE__ */ function() {
5569
5655
  _defineProperty(this, "isVideoEncryption", false);
5570
5656
  _defineProperty(this, "isAudioEncryption", false);
5571
5657
  _defineProperty(this, "isVideo", true);
5658
+ _defineProperty(this, "lastKeyFrameDts", 0);
5572
5659
  _defineProperty(this, "kid", null);
5573
5660
  _defineProperty(this, "pssh", null);
5574
5661
  _defineProperty(this, "ext", void 0);
@@ -5611,6 +5698,9 @@ var VideoTrack = /* @__PURE__ */ function() {
5611
5698
  }, {
5612
5699
  key: "exist",
5613
5700
  value: function exist() {
5701
+ if (/av01/.test(this.codec)) {
5702
+ return true;
5703
+ }
5614
5704
  return !!(this.pps.length && this.sps.length && this.codec);
5615
5705
  }
5616
5706
  }, {
@@ -5674,7 +5764,7 @@ var AudioTrack = /* @__PURE__ */ function() {
5674
5764
  }, {
5675
5765
  key: "exist",
5676
5766
  value: function exist() {
5677
- return !!(this.sampleRate && this.channelCount && this.codec && this.codecType === AudioCodecType.AAC);
5767
+ return !!(this.sampleRate && this.channelCount && this.codec && (this.codecType === AudioCodecType.AAC || this.codecType === AudioCodecType.G711PCMA || this.codecType === AudioCodecType.G711PCMU || this.codecType === AudioCodecType.OPUS));
5678
5768
  }
5679
5769
  }, {
5680
5770
  key: "hasSample",
@@ -5888,7 +5978,7 @@ var AAC = /* @__PURE__ */ function() {
5888
5978
  continue;
5889
5979
  }
5890
5980
  frameLength = (data[i + 3] & 3) << 11 | data[i + 4] << 3 | (data[i + 5] & 224) >> 5;
5891
- if (len - i < frameLength)
5981
+ if (!frameLength || len - i < frameLength)
5892
5982
  break;
5893
5983
  protectionSkipBytes = (~data[i + 1] & 1) * 2;
5894
5984
  frames.push({
@@ -6022,14 +6112,57 @@ var AAC = /* @__PURE__ */ function() {
6022
6112
  return AAC2;
6023
6113
  }();
6024
6114
  _defineProperty(AAC, "FREQ", [96e3, 88200, 64e3, 48e3, 44100, 32e3, 24e3, 22050, 16e3, 12e3, 11025, 8e3, 7350]);
6115
+ var OPUS = /* @__PURE__ */ function() {
6116
+ function OPUS2() {
6117
+ _classCallCheck$1(this, OPUS2);
6118
+ }
6119
+ _createClass$1(OPUS2, null, [{
6120
+ key: "getFrameDuration",
6121
+ value: function getFrameDuration(samples) {
6122
+ return 20;
6123
+ }
6124
+ }, {
6125
+ key: "parseHeaderPackets",
6126
+ value: function parseHeaderPackets(data) {
6127
+ if (!data.length)
6128
+ return;
6129
+ var dv = new DataView(data.buffer, data.byteOffset, data.byteLength);
6130
+ var magicSignature = "";
6131
+ for (var i = 0; i < 8; i++) {
6132
+ magicSignature += String.fromCodePoint(data[i]);
6133
+ }
6134
+ if (magicSignature !== "OpusHead") {
6135
+ throw new Error("Invalid Opus MagicSignature");
6136
+ }
6137
+ var channelCount = data[9];
6138
+ console.log("Pre-skip", data[10], data[11]);
6139
+ var sampleRate = dv.getUint32(12, true);
6140
+ var outputGain = dv.getInt16(16, true);
6141
+ if (!sampleRate)
6142
+ return;
6143
+ var codec = "opus";
6144
+ var originCodec = "opus";
6145
+ var config = new Uint8Array(data.buffer, data.byteOffset + 8, data.byteLength - 8);
6146
+ return {
6147
+ outputGain,
6148
+ sampleRate,
6149
+ channelCount,
6150
+ config,
6151
+ codec,
6152
+ originCodec
6153
+ };
6154
+ }
6155
+ }]);
6156
+ return OPUS2;
6157
+ }();
6025
6158
  var LARGE_AV_FIRST_FRAME_GAP = 500;
6026
6159
  var AUDIO_GAP_OVERLAP_THRESHOLD_COUNT = 3;
6027
6160
  var MAX_SILENT_FRAME_DURATION = 1e3;
6028
- var AUDIO_EXCETION_LOG_EMIT_DURATION = 5e3;
6161
+ var AUDIO_EXCEPTION_LOG_EMIT_DURATION = 5e3;
6029
6162
  var MAX_VIDEO_FRAME_DURATION = 1e3;
6030
6163
  var MAX_DTS_DELTA_WITH_NEXT_CHUNK = 200;
6031
- var VIDEO_EXCETION_LOG_EMIT_DURATION = 5e3;
6032
- var TRACK_BREACKED_CHECK_TIME = 5;
6164
+ var VIDEO_EXCEPTION_LOG_EMIT_DURATION = 5e3;
6165
+ var TRACK_BROKEN_CHECK_TIME = 5;
6033
6166
  var FlvFixer = /* @__PURE__ */ function() {
6034
6167
  function FlvFixer2(videoTrack, audioTrack, metadataTrack) {
6035
6168
  _classCallCheck$1(this, FlvFixer2);
@@ -6145,7 +6278,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6145
6278
  var firstSample = samples[0];
6146
6279
  var vDelta = this._videoNextDts - firstSample.dts;
6147
6280
  if (Math.abs(vDelta) > MAX_DTS_DELTA_WITH_NEXT_CHUNK) {
6148
- if (Math.abs(firstSample.dts - this._lastVideoExceptionChunkFirstDtsDot) > VIDEO_EXCETION_LOG_EMIT_DURATION) {
6281
+ if (Math.abs(firstSample.dts - this._lastVideoExceptionChunkFirstDtsDot) > VIDEO_EXCEPTION_LOG_EMIT_DURATION) {
6149
6282
  var _samples$;
6150
6283
  this._lastVideoExceptionChunkFirstDtsDot = firstSample.dts;
6151
6284
  videoTrack.warnings.push({
@@ -6156,7 +6289,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6156
6289
  sampleDuration: vDelta
6157
6290
  });
6158
6291
  }
6159
- if (this._videoTimestampBreak >= TRACK_BREACKED_CHECK_TIME) {
6292
+ if (this._videoTimestampBreak >= TRACK_BROKEN_CHECK_TIME) {
6160
6293
  this._videoNextDts = firstSample.dts;
6161
6294
  this._videoTimestampBreak = 0;
6162
6295
  } else {
@@ -6179,7 +6312,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6179
6312
  }
6180
6313
  if (sampleDuration > MAX_VIDEO_FRAME_DURATION || sampleDuration < 0) {
6181
6314
  this._videoTimestampBreak++;
6182
- if (Math.abs(dts - this._lastVideoExceptionLargeGapDot) > VIDEO_EXCETION_LOG_EMIT_DURATION) {
6315
+ if (Math.abs(dts - this._lastVideoExceptionLargeGapDot) > VIDEO_EXCEPTION_LOG_EMIT_DURATION) {
6183
6316
  this._lastVideoExceptionLargeGapDot = dts;
6184
6317
  videoTrack.warnings.push({
6185
6318
  type: WarningType.LARGE_VIDEO_GAP,
@@ -6260,10 +6393,27 @@ var FlvFixer = /* @__PURE__ */ function() {
6260
6393
  key: "_doFixAudioInternal",
6261
6394
  value: function _doFixAudioInternal(audioTrack, samples, timescale) {
6262
6395
  if (!audioTrack.sampleDuration) {
6263
- audioTrack.sampleDuration = audioTrack.codecType === AudioCodecType.AAC ? AAC.getFrameDuration(audioTrack.timescale, timescale) : this._getG711Duration(audioTrack);
6396
+ switch (audioTrack.codecType) {
6397
+ case AudioCodecType.AAC: {
6398
+ audioTrack.sampleDuration = AAC.getFrameDuration(audioTrack.timescale, timescale);
6399
+ break;
6400
+ }
6401
+ case AudioCodecType.OPUS: {
6402
+ audioTrack.sampleDuration = OPUS.getFrameDuration(audioTrack.samples, timescale);
6403
+ break;
6404
+ }
6405
+ case AudioCodecType.G711PCMA:
6406
+ case AudioCodecType.G711PCMU: {
6407
+ audioTrack.sampleDuration = this._getG711Duration(audioTrack);
6408
+ break;
6409
+ }
6410
+ default:
6411
+ console.error("can't fix audio codecType:", audioTrack.codecType);
6412
+ break;
6413
+ }
6264
6414
  }
6265
6415
  var refSampleDuration = audioTrack.sampleDuration;
6266
- var sampleDurationInSampleRate = audioTrack.codecType === AudioCodecType.AAC ? 1024 : refSampleDuration * audioTrack.timescale / 1e3;
6416
+ var sampleDurationInSampleRate = audioTrack.codecType === AudioCodecType.OPUS ? 20 : audioTrack.codecType === AudioCodecType.AAC ? 1024 : refSampleDuration * audioTrack.timescale / 1e3;
6267
6417
  if (this._audioNextPts === void 0) {
6268
6418
  var samp0 = samples[0];
6269
6419
  this._audioNextPts = samp0.pts;
@@ -6272,7 +6422,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6272
6422
  var nextPts = this._audioNextPts;
6273
6423
  var sample = samples[i];
6274
6424
  var delta = sample.pts - nextPts;
6275
- if (i === 0 && this._audioTimestampBreak >= TRACK_BREACKED_CHECK_TIME && this._keyFrameInNextChunk) {
6425
+ if (i === 0 && this._audioTimestampBreak >= TRACK_BROKEN_CHECK_TIME && this._keyFrameInNextChunk) {
6276
6426
  nextPts = this._audioNextPts = sample.dts;
6277
6427
  delta = 0;
6278
6428
  this._audioTimestampBreak = 0;
@@ -6280,7 +6430,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6280
6430
  if (!this._audioTimestampBreak && delta >= AUDIO_GAP_OVERLAP_THRESHOLD_COUNT * refSampleDuration && delta <= MAX_SILENT_FRAME_DURATION && !isSafari) {
6281
6431
  var silentFrame = this._getSilentFrame(audioTrack) || samples[0].data.subarray();
6282
6432
  var count = Math.floor(delta / refSampleDuration);
6283
- if (Math.abs(sample.pts - this._lastAudioExceptionGapDot) > AUDIO_EXCETION_LOG_EMIT_DURATION) {
6433
+ if (Math.abs(sample.pts - this._lastAudioExceptionGapDot) > AUDIO_EXCEPTION_LOG_EMIT_DURATION) {
6284
6434
  this._lastAudioExceptionGapDot = sample.pts;
6285
6435
  audioTrack.warnings.push({
6286
6436
  type: WarningType.AUDIO_FILLED,
@@ -6300,7 +6450,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6300
6450
  }
6301
6451
  i--;
6302
6452
  } else if (delta <= -AUDIO_GAP_OVERLAP_THRESHOLD_COUNT * refSampleDuration && delta >= -1 * MAX_SILENT_FRAME_DURATION) {
6303
- if (Math.abs(sample.pts - this._lastAudioExceptionOverlapDot) > AUDIO_EXCETION_LOG_EMIT_DURATION) {
6453
+ if (Math.abs(sample.pts - this._lastAudioExceptionOverlapDot) > AUDIO_EXCEPTION_LOG_EMIT_DURATION) {
6304
6454
  this._lastAudioExceptionOverlapDot = sample.pts;
6305
6455
  audioTrack.warnings.push({
6306
6456
  type: WarningType.AUDIO_DROPPED,
@@ -6315,7 +6465,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6315
6465
  } else {
6316
6466
  if (Math.abs(delta) > MAX_SILENT_FRAME_DURATION) {
6317
6467
  this._audioTimestampBreak++;
6318
- if (Math.abs(sample.pts - this._lastAudioExceptionLargeGapDot) > AUDIO_EXCETION_LOG_EMIT_DURATION) {
6468
+ if (Math.abs(sample.pts - this._lastAudioExceptionLargeGapDot) > AUDIO_EXCEPTION_LOG_EMIT_DURATION) {
6319
6469
  this._lastAudioExceptionLargeGapDot = sample.pts;
6320
6470
  audioTrack.warnings.push({
6321
6471
  type: WarningType.LARGE_AUDIO_GAP,
@@ -6328,8 +6478,15 @@ var FlvFixer = /* @__PURE__ */ function() {
6328
6478
  });
6329
6479
  }
6330
6480
  }
6331
- sample.dts = sample.pts = nextPts;
6332
- sample.duration = sampleDurationInSampleRate;
6481
+ if (audioTrack.codecType === AudioCodecType.OPUS) {
6482
+ var lastSample = samples[samples.length - 1];
6483
+ if (lastSample) {
6484
+ lastSample.duration = sample.pts - lastSample.pts;
6485
+ }
6486
+ } else {
6487
+ sample.dts = sample.pts = nextPts;
6488
+ sample.duration = sampleDurationInSampleRate;
6489
+ }
6333
6490
  this._audioNextPts += refSampleDuration;
6334
6491
  }
6335
6492
  }
@@ -7288,6 +7445,13 @@ var AMF = /* @__PURE__ */ function() {
7288
7445
  }]);
7289
7446
  return AMF2;
7290
7447
  }();
7448
+ var FlvSoundFormat = {
7449
+ MP3: 2,
7450
+ G711A: 7,
7451
+ G711M: 8,
7452
+ AAC: 10,
7453
+ OPUS: 13
7454
+ };
7291
7455
  var logger$2 = new Logger$1("FlvDemuxer");
7292
7456
  var FlvDemuxer = /* @__PURE__ */ function() {
7293
7457
  function FlvDemuxer2(videoTrack, audioTrack, metadataTrack) {
@@ -7304,8 +7468,10 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7304
7468
  _createClass$1(FlvDemuxer2, [{
7305
7469
  key: "demux",
7306
7470
  value: function demux(data) {
7471
+ var _scriptDataObject$dat;
7307
7472
  var discontinuity = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
7308
7473
  var contiguous = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
7474
+ var seamlessLoadingSwitching = arguments.length > 3 ? arguments[3] : void 0;
7309
7475
  var audioTrack = this.audioTrack, videoTrack = this.videoTrack, metadataTrack = this.metadataTrack;
7310
7476
  if (discontinuity || !contiguous) {
7311
7477
  this._remainingData = null;
@@ -7363,6 +7529,8 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7363
7529
  if (tagType === 8) {
7364
7530
  this._parseAudio(bodyData, timestamp);
7365
7531
  } else if (tagType === 9) {
7532
+ if (seamlessLoadingSwitching)
7533
+ this.seamlessLoadingSwitching = true;
7366
7534
  this._parseVideo(bodyData, timestamp);
7367
7535
  } else if (tagType === 18) {
7368
7536
  this._parseScript(bodyData, timestamp);
@@ -7380,13 +7548,31 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7380
7548
  this._remainingData = data.subarray(offset);
7381
7549
  }
7382
7550
  audioTrack.formatTimescale = videoTrack.formatTimescale = videoTrack.timescale = metadataTrack.timescale = 1e3;
7383
- audioTrack.timescale = audioTrack.sampleRate || 0;
7551
+ audioTrack.timescale = audioTrack.codecType === AudioCodecType.OPUS ? 1e3 : audioTrack.sampleRate || 0;
7384
7552
  if (!audioTrack.exist() && audioTrack.hasSample()) {
7385
7553
  audioTrack.reset();
7386
7554
  }
7387
7555
  if (!videoTrack.exist() && videoTrack.hasSample()) {
7388
7556
  videoTrack.reset();
7389
7557
  }
7558
+ var scriptDataObject = metadataTrack.flvScriptSamples[metadataTrack.flvScriptSamples.length - 1];
7559
+ var metaData = scriptDataObject === null || scriptDataObject === void 0 ? void 0 : (_scriptDataObject$dat = scriptDataObject.data) === null || _scriptDataObject$dat === void 0 ? void 0 : _scriptDataObject$dat.onMetaData;
7560
+ if (metaData) {
7561
+ if (videoTrack !== null && videoTrack !== void 0 && videoTrack.exist()) {
7562
+ if (metaData.hasOwnProperty("duration")) {
7563
+ videoTrack.duration = metaData.duration * 1e3;
7564
+ }
7565
+ if (metaData.hasOwnProperty("width") && metaData.hasOwnProperty("height")) {
7566
+ videoTrack.width = metaData.width;
7567
+ videoTrack.height = metaData.height;
7568
+ }
7569
+ }
7570
+ if (audioTrack !== null && audioTrack !== void 0 && audioTrack.exist()) {
7571
+ if (metaData.hasOwnProperty("duration")) {
7572
+ audioTrack.duration = metaData.duration * 1e3;
7573
+ }
7574
+ }
7575
+ }
7390
7576
  return {
7391
7577
  videoTrack,
7392
7578
  audioTrack,
@@ -7405,8 +7591,8 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7405
7591
  }
7406
7592
  }, {
7407
7593
  key: "demuxAndFix",
7408
- value: function demuxAndFix(data, discontinuity, contiguous, startTime) {
7409
- this.demux(data, discontinuity, contiguous);
7594
+ value: function demuxAndFix(data, discontinuity, contiguous, startTime, seamlessLoadingSwitching) {
7595
+ this.demux(data, discontinuity, contiguous, seamlessLoadingSwitching);
7410
7596
  return this.fix(startTime, discontinuity, contiguous);
7411
7597
  }
7412
7598
  }, {
@@ -7416,12 +7602,12 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7416
7602
  return;
7417
7603
  var format = (data[0] & 240) >>> 4;
7418
7604
  var track = this.audioTrack;
7419
- if (format !== 10 && format !== 7 && format !== 8) {
7605
+ if (format !== FlvSoundFormat.AAC && format !== FlvSoundFormat.G711A && format !== FlvSoundFormat.G711M && format !== FlvSoundFormat.OPUS) {
7420
7606
  logger$2.warn("Unsupported sound format: ".concat(format));
7421
7607
  track.reset();
7422
7608
  return;
7423
7609
  }
7424
- if (format !== 10) {
7610
+ if (format !== FlvSoundFormat.AAC && format !== FlvSoundFormat.OPUS) {
7425
7611
  var soundRate = (data[0] & 12) >> 2;
7426
7612
  var soundSize = (data[0] & 2) >> 1;
7427
7613
  var soundType = data[0] & 1;
@@ -7429,10 +7615,49 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7429
7615
  track.sampleSize = soundSize ? 16 : 8;
7430
7616
  track.channelCount = soundType + 1;
7431
7617
  }
7432
- if (format === 10) {
7433
- this._parseAac(data, pts);
7434
- } else {
7435
- this._parseG711(data, pts, format);
7618
+ switch (format) {
7619
+ case FlvSoundFormat.G711A:
7620
+ case FlvSoundFormat.G711M:
7621
+ this._parseG711(data, pts, format);
7622
+ break;
7623
+ case FlvSoundFormat.AAC:
7624
+ this._parseAac(data, pts);
7625
+ break;
7626
+ case FlvSoundFormat.OPUS:
7627
+ this._parseOpus(data, pts);
7628
+ break;
7629
+ }
7630
+ }
7631
+ }, {
7632
+ key: "_parseOpus",
7633
+ value: function _parseOpus(data, pts) {
7634
+ var track = this.audioTrack;
7635
+ var packetType = data[1];
7636
+ track.codecType = AudioCodecType.OPUS;
7637
+ switch (packetType) {
7638
+ case 0: {
7639
+ var ret = OPUS.parseHeaderPackets(data.subarray(2));
7640
+ if (ret) {
7641
+ track.codec = ret.codec;
7642
+ track.channelCount = ret.channelCount;
7643
+ track.sampleRate = ret.sampleRate;
7644
+ track.config = ret.config;
7645
+ track.sampleDuration = OPUS.getFrameDuration([], track.timescale);
7646
+ } else {
7647
+ track.reset();
7648
+ logger$2.warn("Cannot parse AudioSpecificConfig", data);
7649
+ }
7650
+ break;
7651
+ }
7652
+ case 1: {
7653
+ if (pts === void 0 || pts === null)
7654
+ return;
7655
+ var newSample = new AudioSample(pts, data.subarray(2), track.sampleDuration);
7656
+ track.samples.push(newSample);
7657
+ break;
7658
+ }
7659
+ default:
7660
+ logger$2.warn("Unknown OpusPacketType: ".concat(packetType));
7436
7661
  }
7437
7662
  }
7438
7663
  }, {
@@ -7520,8 +7745,13 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7520
7745
  units = this._checkAddMetaNalToUnits(isHevc, units, track);
7521
7746
  if (units && units.length) {
7522
7747
  var sample = new VideoSample(dts + cts, dts, units);
7748
+ if (this.seamlessLoadingSwitching && dts < track.lastKeyFrameDts) {
7749
+ return;
7750
+ }
7751
+ this.seamlessLoadingSwitching = false;
7523
7752
  if (frameType === 1) {
7524
7753
  sample.setToKeyframe();
7754
+ track.lastKeyFrameDts = dts;
7525
7755
  }
7526
7756
  track.samples.push(sample);
7527
7757
  units.forEach(function(unit) {
@@ -7995,10 +8225,16 @@ var MP4 = /* @__PURE__ */ function() {
7995
8225
  if (track.useEME && track.enca) {
7996
8226
  content = MP42.enca(track);
7997
8227
  } else {
7998
- content = MP42.mp4a(track);
8228
+ if (track.codecType === AudioCodecType.OPUS) {
8229
+ content = MP42.opus(track);
8230
+ } else {
8231
+ content = MP42.mp4a(track);
8232
+ }
7999
8233
  }
8000
8234
  } else if (track.useEME && track.encv) {
8001
8235
  content = MP42.encv(track);
8236
+ } else if (track.av1C) {
8237
+ content = MP42.av01(track);
8002
8238
  } else {
8003
8239
  content = MP42.avc1hev1(track);
8004
8240
  }
@@ -8211,6 +8447,90 @@ var MP4 = /* @__PURE__ */ function() {
8211
8447
  var schi = MP42.schi(data);
8212
8448
  return MP42.box(MP42.types.sinf, content, MP42.box(MP42.types.frma, frma), MP42.box(MP42.types.schm, schm), schi);
8213
8449
  }
8450
+ }, {
8451
+ key: "av01",
8452
+ value: function av01(track) {
8453
+ return MP42.box(MP42.types.av01, new Uint8Array([
8454
+ 0,
8455
+ 0,
8456
+ 0,
8457
+ 0,
8458
+ 0,
8459
+ 0,
8460
+ 0,
8461
+ 1,
8462
+ 0,
8463
+ 0,
8464
+ 0,
8465
+ 0,
8466
+ 0,
8467
+ 0,
8468
+ 0,
8469
+ 0,
8470
+ 0,
8471
+ 0,
8472
+ 0,
8473
+ 0,
8474
+ 0,
8475
+ 0,
8476
+ 0,
8477
+ 0,
8478
+ track.width >> 8 & 255,
8479
+ track.width & 255,
8480
+ track.height >> 8 & 255,
8481
+ track.height & 255,
8482
+ 0,
8483
+ 72,
8484
+ 0,
8485
+ 0,
8486
+ 0,
8487
+ 72,
8488
+ 0,
8489
+ 0,
8490
+ 0,
8491
+ 0,
8492
+ 0,
8493
+ 0,
8494
+ 0,
8495
+ 1,
8496
+ 0,
8497
+ 0,
8498
+ 0,
8499
+ 0,
8500
+ 0,
8501
+ 0,
8502
+ 0,
8503
+ 0,
8504
+ 0,
8505
+ 0,
8506
+ 0,
8507
+ 0,
8508
+ 0,
8509
+ 0,
8510
+ 0,
8511
+ 0,
8512
+ 0,
8513
+ 0,
8514
+ 0,
8515
+ 0,
8516
+ 0,
8517
+ 0,
8518
+ 0,
8519
+ 0,
8520
+ 0,
8521
+ 0,
8522
+ 0,
8523
+ 0,
8524
+ 0,
8525
+ 0,
8526
+ 0,
8527
+ 0,
8528
+ 0,
8529
+ 24,
8530
+ 17,
8531
+ 17
8532
+ ]), track.av1C, track.colr);
8533
+ }
8214
8534
  }, {
8215
8535
  key: "avc1hev1",
8216
8536
  value: function avc1hev1(track) {
@@ -8581,6 +8901,53 @@ var MP4 = /* @__PURE__ */ function() {
8581
8901
  )));
8582
8902
  return esds2;
8583
8903
  }
8904
+ }, {
8905
+ key: "opus",
8906
+ value: function opus(track) {
8907
+ var opusAudioDescription = new Uint8Array([
8908
+ 0,
8909
+ 0,
8910
+ 0,
8911
+ 0,
8912
+ 0,
8913
+ 0,
8914
+ 0,
8915
+ 1,
8916
+ 0,
8917
+ 0,
8918
+ 0,
8919
+ 0,
8920
+ 0,
8921
+ 0,
8922
+ 0,
8923
+ 0,
8924
+ 0,
8925
+ track.channelCount,
8926
+ 0,
8927
+ 16,
8928
+ 0,
8929
+ 0,
8930
+ 0,
8931
+ 0,
8932
+ track.sampleRate >> 8 & 255,
8933
+ track.sampleRate & 255,
8934
+ 0,
8935
+ 0
8936
+ ]);
8937
+ var opusSpecificConfig = track.config.length ? MP42.dOps(track) : [];
8938
+ return MP42.box(MP42.types.Opus, opusAudioDescription, opusSpecificConfig);
8939
+ }
8940
+ }, {
8941
+ key: "dOps",
8942
+ value: function dOps(track) {
8943
+ if (track.config) {
8944
+ track.config[4] = track.sampleRate >>> 24 & 255;
8945
+ track.config[5] = track.sampleRate >>> 16 & 255;
8946
+ track.config[6] = track.sampleRate >>> 8 & 255;
8947
+ track.config[7] = track.sampleRate & 255;
8948
+ return MP42.box(MP42.types.dOps, track.config);
8949
+ }
8950
+ }
8584
8951
  }, {
8585
8952
  key: "mvex",
8586
8953
  value: function mvex(tracks) {
@@ -9183,7 +9550,7 @@ var MP4 = /* @__PURE__ */ function() {
9183
9550
  }]);
9184
9551
  return MP42;
9185
9552
  }();
9186
- _defineProperty(MP4, "types", ["avc1", "avcC", "hvc1", "hvcC", "dinf", "dref", "esds", "ftyp", "hdlr", "mdat", "mdhd", "mdia", "mfhd", "minf", "moof", "moov", "mp4a", "mvex", "mvhd", "pasp", "stbl", "stco", "stsc", "stsd", "stsz", "stts", "tfdt", "tfhd", "traf", "trak", "trex", "tkhd", "vmhd", "smhd", "ctts", "stss", "styp", "pssh", "sidx", "sbgp", "saiz", "saio", "senc", "trun", "encv", "enca", "sinf", "btrt", "frma", "tenc", "schm", "schi", "mehd", "fiel", "sdtp"].reduce(function(p, c) {
9553
+ _defineProperty(MP4, "types", ["Opus", "dOps", "av01", "av1C", "avc1", "avcC", "hvc1", "hvcC", "dinf", "dref", "esds", "ftyp", "hdlr", "mdat", "mdhd", "mdia", "mfhd", "minf", "moof", "moov", "mp4a", "mvex", "mvhd", "pasp", "stbl", "stco", "stsc", "stsd", "stsz", "stts", "tfdt", "tfhd", "traf", "trak", "trex", "tkhd", "vmhd", "smhd", "ctts", "stss", "styp", "pssh", "sidx", "sbgp", "saiz", "saio", "senc", "trun", "encv", "enca", "sinf", "btrt", "frma", "tenc", "schm", "schi", "mehd", "fiel", "sdtp"].reduce(function(p, c) {
9187
9554
  p[c] = [c.charCodeAt(0), c.charCodeAt(1), c.charCodeAt(2), c.charCodeAt(3)];
9188
9555
  return p;
9189
9556
  }, /* @__PURE__ */ Object.create(null)));
@@ -9518,30 +9885,46 @@ var FMP4Remuxer = /* @__PURE__ */ function() {
9518
9885
  };
9519
9886
  }
9520
9887
  var samples = track.samples;
9888
+ var isAV01 = /av01/.test(track.codec);
9521
9889
  var mdatSize = 0;
9522
- samples.forEach(function(s) {
9523
- mdatSize += s.units.reduce(function(t, c) {
9524
- return t + c.byteLength;
9525
- }, 0);
9526
- mdatSize += s.units.length * 4;
9527
- });
9528
- var mdata = new Uint8Array(mdatSize);
9529
- var mdatView = new DataView(mdata.buffer);
9530
- var _loop = function _loop2(_offset, _sample) {
9531
- _sample = samples[i];
9532
- var sampleSize = 0;
9533
- _sample.units.forEach(function(u) {
9534
- mdatView.setUint32(_offset, u.byteLength);
9535
- _offset += 4;
9536
- mdata.set(u, _offset);
9537
- _offset += u.byteLength;
9538
- sampleSize += 4 + u.byteLength;
9890
+ if (isAV01) {
9891
+ samples.forEach(function(s) {
9892
+ mdatSize += s.data.byteLength;
9539
9893
  });
9540
- _sample.size = sampleSize;
9541
- offset = _offset, sample = _sample;
9542
- };
9543
- for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
9544
- _loop(offset, sample);
9894
+ } else {
9895
+ samples.forEach(function(s) {
9896
+ mdatSize += s.units.reduce(function(t, c) {
9897
+ return t + c.byteLength;
9898
+ }, 0);
9899
+ mdatSize += s.units.length * 4;
9900
+ });
9901
+ }
9902
+ var mdata = new Uint8Array(mdatSize);
9903
+ if (isAV01) {
9904
+ for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
9905
+ sample = samples[i];
9906
+ mdata.set(sample.data, offset);
9907
+ sample.size = sample.data.byteLength;
9908
+ offset += sample.size;
9909
+ }
9910
+ } else {
9911
+ var mdatView = new DataView(mdata.buffer);
9912
+ var _loop = function _loop2(_offset2, _sample2) {
9913
+ _sample2 = samples[_i];
9914
+ var sampleSize = 0;
9915
+ _sample2.units.forEach(function(u) {
9916
+ mdatView.setUint32(_offset2, u.byteLength);
9917
+ _offset2 += 4;
9918
+ mdata.set(u, _offset2);
9919
+ _offset2 += u.byteLength;
9920
+ sampleSize += 4 + u.byteLength;
9921
+ });
9922
+ _sample2.size = sampleSize;
9923
+ _offset = _offset2, _sample = _sample2;
9924
+ };
9925
+ for (var _i = 0, _l = samples.length, _offset = 0, _sample; _i < _l; _i++) {
9926
+ _loop(_offset, _sample);
9927
+ }
9545
9928
  }
9546
9929
  var mdat = MP4.mdat(mdata);
9547
9930
  var moof = MP4.moof([track]);
@@ -9571,6 +9954,55 @@ var FMP4Remuxer = /* @__PURE__ */ function() {
9571
9954
  }]);
9572
9955
  return FMP4Remuxer2;
9573
9956
  }();
9957
+ var TransferCost = /* @__PURE__ */ function() {
9958
+ function TransferCost2() {
9959
+ _classCallCheck$4(this, TransferCost2);
9960
+ _defineProperty$3(this, "_ttfb", 0);
9961
+ _defineProperty$3(this, "_demuxStart", 0);
9962
+ _defineProperty$3(this, "_demuxEnd", 0);
9963
+ _defineProperty$3(this, "_demuxCost", 0);
9964
+ _defineProperty$3(this, "_remuxStart", 0);
9965
+ _defineProperty$3(this, "_remuxEnd", 0);
9966
+ _defineProperty$3(this, "_remuxCost", 0);
9967
+ _defineProperty$3(this, "_appendStart", 0);
9968
+ _defineProperty$3(this, "_appendEnd", 0);
9969
+ _defineProperty$3(this, "_appendCost", 0);
9970
+ }
9971
+ _createClass$4(TransferCost2, [{
9972
+ key: "set",
9973
+ value: function set(event, value) {
9974
+ this["_".concat(event)] = value;
9975
+ }
9976
+ }, {
9977
+ key: "start",
9978
+ value: function start(event) {
9979
+ this["_".concat(event, "Start")] = Date.now();
9980
+ }
9981
+ }, {
9982
+ key: "end",
9983
+ value: function end(event) {
9984
+ this["_".concat(event, "End")] = Date.now();
9985
+ this["_".concat(event, "Cost")] = this["_".concat(event, "Cost")] + (this["_".concat(event, "End")] - this["_".concat(event, "Start")]);
9986
+ }
9987
+ }, {
9988
+ key: "transferCost",
9989
+ get: function get() {
9990
+ return {
9991
+ ttfbCost: this._ttfb,
9992
+ demuxCost: this._demuxCost,
9993
+ remuxCost: this._remuxCost,
9994
+ appendCost: this._appendCost
9995
+ };
9996
+ }
9997
+ }]);
9998
+ return TransferCost2;
9999
+ }();
10000
+ var TRANSFER_EVENT = {
10001
+ TTFB: "ttfb",
10002
+ DEMUX: "demux",
10003
+ REMUX: "remux",
10004
+ APPEND: "append"
10005
+ };
9574
10006
  var logger$1 = new Logger$2("BufferService");
9575
10007
  var BufferService = /* @__PURE__ */ function() {
9576
10008
  function BufferService2(flv, softVideo) {
@@ -9658,7 +10090,8 @@ var BufferService = /* @__PURE__ */ function() {
9658
10090
  this._contiguous = false;
9659
10091
  this._sourceCreated = false;
9660
10092
  this._initSegmentId = "";
9661
- case 11:
10093
+ this.resetSeamlessSwitchStats();
10094
+ case 12:
9662
10095
  case "end":
9663
10096
  return _context.stop();
9664
10097
  }
@@ -9669,6 +10102,15 @@ var BufferService = /* @__PURE__ */ function() {
9669
10102
  }
9670
10103
  return reset;
9671
10104
  }()
10105
+ }, {
10106
+ key: "resetSeamlessSwitchStats",
10107
+ value: function resetSeamlessSwitchStats() {
10108
+ this.seamlessLoadingSwitch = null;
10109
+ this.seamlessLoadingSwitching = false;
10110
+ if (this._demuxer) {
10111
+ this._demuxer.seamlessLoadingSwitching = false;
10112
+ }
10113
+ }
9672
10114
  }, {
9673
10115
  key: "endOfStream",
9674
10116
  value: function() {
@@ -9774,32 +10216,56 @@ var BufferService = /* @__PURE__ */ function() {
9774
10216
  key: "appendBuffer",
9775
10217
  value: function() {
9776
10218
  var _appendBuffer = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee5(chunk) {
9777
- var demuxer, videoTrack, audioTrack, metadataTrack, videoExist, audioExist, duration, track, videoType, audioType, mse, newId, remuxResult, p;
10219
+ var _this = this;
10220
+ var switchingNoReset, demuxer, videoTrack, audioTrack, metadataTrack, idx, videoExist, audioExist, duration, track, videoType, audioType, mse, afterAppend, newId, remuxResult, p;
9778
10221
  return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
9779
10222
  while (1)
9780
10223
  switch (_context5.prev = _context5.next) {
9781
10224
  case 0:
10225
+ switchingNoReset = false;
9782
10226
  if (this._cachedBuffer) {
9783
10227
  chunk = concatUint8Array$1(this._cachedBuffer, chunk);
9784
10228
  this._cachedBuffer = null;
9785
10229
  }
9786
10230
  demuxer = this._demuxer;
9787
10231
  if (!(!chunk || !chunk.length || !demuxer)) {
9788
- _context5.next = 4;
10232
+ _context5.next = 5;
9789
10233
  break;
9790
10234
  }
9791
10235
  return _context5.abrupt("return");
9792
- case 4:
9793
- _context5.prev = 4;
9794
- demuxer.demuxAndFix(chunk, this._discontinuity, this._contiguous, this._demuxStartTime);
9795
- _context5.next = 11;
10236
+ case 5:
10237
+ _context5.prev = 5;
10238
+ this.flv._transferCost.start(TRANSFER_EVENT.DEMUX);
10239
+ demuxer.demuxAndFix(chunk, this.seamlessLoadingSwitching || this._discontinuity, this._contiguous, this._demuxStartTime, this.seamlessLoadingSwitching);
10240
+ this.seamlessLoadingSwitching = false;
10241
+ this.flv._transferCost.end(TRANSFER_EVENT.DEMUX);
10242
+ _context5.next = 15;
9796
10243
  break;
9797
- case 8:
9798
- _context5.prev = 8;
9799
- _context5.t0 = _context5["catch"](4);
10244
+ case 12:
10245
+ _context5.prev = 12;
10246
+ _context5.t0 = _context5["catch"](5);
9800
10247
  throw new StreamingError(ERR.DEMUX, ERR.SUB_TYPES.FLV, _context5.t0);
9801
- case 11:
10248
+ case 15:
9802
10249
  videoTrack = demuxer.videoTrack, audioTrack = demuxer.audioTrack, metadataTrack = demuxer.metadataTrack;
10250
+ if (!this.seamlessLoadingSwitch) {
10251
+ _context5.next = 25;
10252
+ break;
10253
+ }
10254
+ idx = videoTrack.samples.findIndex(function(sample) {
10255
+ return sample.originDts === videoTrack.lastKeyFrameDts;
10256
+ });
10257
+ if (!(idx >= 0)) {
10258
+ _context5.next = 25;
10259
+ break;
10260
+ }
10261
+ videoTrack.samples.splice(idx);
10262
+ _context5.next = 22;
10263
+ return this.seamlessLoadingSwitch();
10264
+ case 22:
10265
+ this.seamlessLoadingSwitch = null;
10266
+ chunk = null;
10267
+ switchingNoReset = true;
10268
+ case 25:
9803
10269
  videoExist = videoTrack.exist();
9804
10270
  audioExist = audioTrack.exist();
9805
10271
  if (this._opts.onlyAudio) {
@@ -9811,7 +10277,7 @@ var BufferService = /* @__PURE__ */ function() {
9811
10277
  audioTrack.present = false;
9812
10278
  }
9813
10279
  if (!(!videoExist && videoTrack.present || !audioExist && audioTrack.present)) {
9814
- _context5.next = 29;
10280
+ _context5.next = 42;
9815
10281
  break;
9816
10282
  }
9817
10283
  duration = 0;
@@ -9820,7 +10286,7 @@ var BufferService = /* @__PURE__ */ function() {
9820
10286
  duration = (track.samples[track.samples.length - 1].originPts - track.samples[0].originPts) / track.timescale * 1e3;
9821
10287
  }
9822
10288
  if (!(duration > this._opts.analyzeDuration)) {
9823
- _context5.next = 27;
10289
+ _context5.next = 40;
9824
10290
  break;
9825
10291
  }
9826
10292
  logger$1.warn("analyze duration exceeded, ".concat(duration, "ms"), track);
@@ -9829,19 +10295,28 @@ var BufferService = /* @__PURE__ */ function() {
9829
10295
  this.flv.emit(EVENT.ANALYZE_DURATION_EXCEEDED, {
9830
10296
  duration
9831
10297
  });
9832
- _context5.next = 29;
10298
+ _context5.next = 42;
9833
10299
  break;
9834
- case 27:
10300
+ case 40:
9835
10301
  this._cachedBuffer = chunk;
9836
10302
  return _context5.abrupt("return");
9837
- case 29:
10303
+ case 42:
9838
10304
  videoType = videoTrack.type;
9839
10305
  audioType = audioTrack.type;
9840
10306
  this._fireEvents(videoTrack, audioTrack, metadataTrack);
9841
- this._discontinuity = false;
9842
- this._contiguous = true;
9843
- this._demuxStartTime = 0;
10307
+ if (!switchingNoReset) {
10308
+ this._discontinuity = false;
10309
+ this._contiguous = true;
10310
+ this._demuxStartTime = 0;
10311
+ }
9844
10312
  mse = this._mse;
10313
+ afterAppend = function afterAppend2() {
10314
+ var _this$flv;
10315
+ if ((_this$flv = _this.flv) !== null && _this$flv !== void 0 && _this$flv.emit) {
10316
+ var _this$flv2;
10317
+ (_this$flv2 = _this.flv) === null || _this$flv2 === void 0 ? void 0 : _this$flv2.emit(EVENT.APPEND_BUFFER, {});
10318
+ }
10319
+ };
9845
10320
  this.flv.emit(EVENT.DEMUXED_TRACK, {
9846
10321
  videoTrack
9847
10322
  });
@@ -9852,16 +10327,16 @@ var BufferService = /* @__PURE__ */ function() {
9852
10327
  this._emitMetaParsedEvent(videoTrack, audioTrack);
9853
10328
  }
9854
10329
  if (!mse) {
9855
- _context5.next = 66;
10330
+ _context5.next = 81;
9856
10331
  break;
9857
10332
  }
9858
10333
  if (this._sourceCreated) {
9859
- _context5.next = 47;
10334
+ _context5.next = 59;
9860
10335
  break;
9861
10336
  }
9862
- _context5.next = 43;
10337
+ _context5.next = 55;
9863
10338
  return mse.open();
9864
- case 43:
10339
+ case 55:
9865
10340
  if (videoExist) {
9866
10341
  logger$1.log("codec: video/mp4;codecs=".concat(videoTrack.codec));
9867
10342
  mse.createSource(videoType, "video/mp4;codecs=".concat(videoTrack.codec));
@@ -9872,26 +10347,28 @@ var BufferService = /* @__PURE__ */ function() {
9872
10347
  }
9873
10348
  this._sourceCreated = true;
9874
10349
  this.flv.emit(EVENT.SOURCEBUFFER_CREATED);
9875
- case 47:
9876
- _context5.prev = 47;
10350
+ case 59:
10351
+ _context5.prev = 59;
9877
10352
  if (this._needInitSegment && !this._opts.mseLowLatency) {
9878
10353
  videoTrack.duration = this._opts.durationForMSELowLatencyOff * videoTrack.timescale;
9879
10354
  audioTrack.duration = this._opts.durationForMSELowLatencyOff * audioExist.timescale;
9880
10355
  }
10356
+ this.flv._transferCost.start(TRANSFER_EVENT.REMUX);
9881
10357
  remuxResult = this._remuxer.remux(this._needInitSegment);
9882
- _context5.next = 55;
10358
+ this.flv._transferCost.end(TRANSFER_EVENT.REMUX);
10359
+ _context5.next = 69;
9883
10360
  break;
9884
- case 52:
9885
- _context5.prev = 52;
9886
- _context5.t1 = _context5["catch"](47);
10361
+ case 66:
10362
+ _context5.prev = 66;
10363
+ _context5.t1 = _context5["catch"](59);
9887
10364
  throw new StreamingError(ERR.REMUX, ERR.SUB_TYPES.FMP4, _context5.t1);
9888
- case 55:
10365
+ case 69:
9889
10366
  if (!(this._needInitSegment && !remuxResult.videoInitSegment && !remuxResult.audioInitSegment)) {
9890
- _context5.next = 57;
10367
+ _context5.next = 71;
9891
10368
  break;
9892
10369
  }
9893
10370
  return _context5.abrupt("return");
9894
- case 57:
10371
+ case 71:
9895
10372
  this._needInitSegment = false;
9896
10373
  p = [];
9897
10374
  if (remuxResult.videoInitSegment)
@@ -9902,16 +10379,21 @@ var BufferService = /* @__PURE__ */ function() {
9902
10379
  p.push(mse.append(videoType, remuxResult.videoSegment));
9903
10380
  if (remuxResult.audioSegment)
9904
10381
  p.push(mse.append(audioType, remuxResult.audioSegment));
9905
- return _context5.abrupt("return", Promise.all(p));
9906
- case 66:
10382
+ this.flv._transferCost.start(TRANSFER_EVENT.APPEND);
10383
+ return _context5.abrupt("return", Promise.all(p).then(afterAppend).then(function() {
10384
+ _this.flv._transferCost.end(TRANSFER_EVENT.APPEND);
10385
+ afterAppend();
10386
+ }));
10387
+ case 81:
9907
10388
  if (this._softVideo) {
9908
10389
  this._softVideo.appendBuffer(videoTrack, audioTrack);
10390
+ afterAppend();
9909
10391
  }
9910
- case 67:
10392
+ case 82:
9911
10393
  case "end":
9912
10394
  return _context5.stop();
9913
10395
  }
9914
- }, _callee5, this, [[4, 8], [47, 52]]);
10396
+ }, _callee5, this, [[5, 12], [59, 66]]);
9915
10397
  }));
9916
10398
  function appendBuffer(_x2) {
9917
10399
  return _appendBuffer.apply(this, arguments);
@@ -9922,7 +10404,7 @@ var BufferService = /* @__PURE__ */ function() {
9922
10404
  key: "evictBuffer",
9923
10405
  value: function() {
9924
10406
  var _evictBuffer = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee6(bufferBehind) {
9925
- var _this = this;
10407
+ var _this2 = this;
9926
10408
  var media, currentTime, removeEnd, start;
9927
10409
  return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
9928
10410
  while (1)
@@ -9951,7 +10433,7 @@ var BufferService = /* @__PURE__ */ function() {
9951
10433
  return _context6.abrupt("return");
9952
10434
  case 10:
9953
10435
  return _context6.abrupt("return", this._mse.clearBuffer(0, removeEnd).then(function() {
9954
- return _this.flv.emit(EVENT.REMOVE_BUFFER, {
10436
+ return _this2.flv.emit(EVENT.REMOVE_BUFFER, {
9955
10437
  removeEnd
9956
10438
  });
9957
10439
  }));
@@ -10001,16 +10483,16 @@ var BufferService = /* @__PURE__ */ function() {
10001
10483
  }, {
10002
10484
  key: "_fireEvents",
10003
10485
  value: function _fireEvents(videoTrack, audioTrack, metadataTrack) {
10004
- var _this2 = this;
10005
- logger$1.debug(videoTrack.samples, audioTrack.samples);
10486
+ var _this3 = this;
10487
+ logger$1.debug("videoTrack samples count: ".concat(videoTrack.samples.length, ", audioTrack samples count: ").concat(audioTrack.samples.length));
10006
10488
  metadataTrack.flvScriptSamples.forEach(function(sample) {
10007
- _this2.flv.emit(EVENT.FLV_SCRIPT_DATA, sample);
10489
+ _this3.flv.emit(EVENT.FLV_SCRIPT_DATA, sample);
10008
10490
  logger$1.debug("flvScriptData", sample);
10009
10491
  });
10010
10492
  videoTrack.samples.forEach(function(sample) {
10011
10493
  if (sample.keyframe) {
10012
- _this2.flv.emit(EVENT.KEYFRAME, {
10013
- pts: sample.pts
10494
+ _this3.flv.emit(EVENT.KEYFRAME, {
10495
+ pts: sample.originPts
10014
10496
  });
10015
10497
  }
10016
10498
  });
@@ -10028,7 +10510,7 @@ var BufferService = /* @__PURE__ */ function() {
10028
10510
  break;
10029
10511
  }
10030
10512
  if (type)
10031
- _this2.flv.emit(EVENT.STREAM_EXCEPTION, _objectSpread2$2(_objectSpread2$2({}, warn), {}, {
10513
+ _this3.flv.emit(EVENT.STREAM_EXCEPTION, _objectSpread2$2(_objectSpread2$2({}, warn), {}, {
10032
10514
  type
10033
10515
  }));
10034
10516
  logger$1.warn("video exception", warn);
@@ -10047,13 +10529,13 @@ var BufferService = /* @__PURE__ */ function() {
10047
10529
  break;
10048
10530
  }
10049
10531
  if (type)
10050
- _this2.flv.emit(EVENT.STREAM_EXCEPTION, _objectSpread2$2(_objectSpread2$2({}, warn), {}, {
10532
+ _this3.flv.emit(EVENT.STREAM_EXCEPTION, _objectSpread2$2(_objectSpread2$2({}, warn), {}, {
10051
10533
  type
10052
10534
  }));
10053
10535
  logger$1.warn("audio exception", warn);
10054
10536
  });
10055
10537
  metadataTrack.seiSamples.forEach(function(sei) {
10056
- _this2.flv.emit(EVENT.SEI, _objectSpread2$2(_objectSpread2$2({}, sei), {}, {
10538
+ _this3.flv.emit(EVENT.SEI, _objectSpread2$2(_objectSpread2$2({}, sei), {}, {
10057
10539
  sei: {
10058
10540
  code: sei.data.type,
10059
10541
  content: sei.data.payload,
@@ -10088,7 +10570,8 @@ function getOption(opts) {
10088
10570
  durationForMSELowLatencyOff: 6,
10089
10571
  chunkCountForSpeed: 50,
10090
10572
  skipChunkSize: 1e3,
10091
- longtimeNoReceived: 3e3
10573
+ longtimeNoReceived: 3e3,
10574
+ enableStartGapJump: true
10092
10575
  }, opts);
10093
10576
  if (ret.isLive) {
10094
10577
  if (ret.preloadTime) {
@@ -10156,7 +10639,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10156
10639
  _defineProperty$3(_assertThisInitialized$3(_this), "_acceptRanges", true);
10157
10640
  _defineProperty$3(_assertThisInitialized$3(_this), "_onProgress", /* @__PURE__ */ function() {
10158
10641
  var _ref2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee(chunk, done, _ref, response) {
10159
- var startTime, endTime, st, firstByteTime, _this$_mediaLoader, headers, _this$_bufferService, remaining, maxReaderInterval;
10642
+ var startTime, endTime, st, firstByteTime, _this$_mediaLoader, headers, elapsed, _this$_bufferService, remaining, maxReaderInterval;
10160
10643
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
10161
10644
  while (1)
10162
10645
  switch (_context.prev = _context.next) {
@@ -10164,7 +10647,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10164
10647
  startTime = _ref.startTime, endTime = _ref.endTime, st = _ref.st, firstByteTime = _ref.firstByteTime;
10165
10648
  _this._loading = !done;
10166
10649
  if (_this._firstProgressEmit) {
10167
- _context.next = 11;
10650
+ _context.next = 13;
10168
10651
  break;
10169
10652
  }
10170
10653
  if (_this.media) {
@@ -10175,49 +10658,51 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10175
10658
  return _context.abrupt("return");
10176
10659
  case 6:
10177
10660
  headers = response.headers;
10661
+ elapsed = st ? firstByteTime - st : endTime - startTime;
10178
10662
  _this.emit(EVENT.TTFB, {
10179
10663
  url: _this._opts.url,
10180
10664
  responseUrl: response.url,
10181
- elapsed: st ? firstByteTime - st : endTime - startTime
10665
+ elapsed
10182
10666
  });
10183
10667
  _this.emit(EVENT.LOAD_RESPONSE_HEADERS, {
10184
10668
  headers
10185
10669
  });
10670
+ _this._transferCost.set(TRANSFER_EVENT.TTFB, elapsed);
10186
10671
  _this._acceptRanges = !!(headers !== null && headers !== void 0 && headers.get("Accept-Ranges")) || !!(headers !== null && headers !== void 0 && headers.get("Content-Range"));
10187
10672
  _this._firstProgressEmit = true;
10188
- case 11:
10673
+ case 13:
10189
10674
  if (_this._bufferService) {
10190
- _context.next = 13;
10675
+ _context.next = 15;
10191
10676
  break;
10192
10677
  }
10193
10678
  return _context.abrupt("return");
10194
- case 13:
10679
+ case 15:
10195
10680
  clearTimeout(_this._maxChunkWaitTimer);
10196
10681
  _this._bandwidthService.addChunkRecord(chunk === null || chunk === void 0 ? void 0 : chunk.byteLength, endTime - startTime);
10197
- _context.prev = 15;
10198
- _context.next = 18;
10682
+ _context.prev = 17;
10683
+ _context.next = 20;
10199
10684
  return _this._bufferService.appendBuffer(chunk);
10200
- case 18:
10685
+ case 20:
10201
10686
  (_this$_bufferService = _this._bufferService) === null || _this$_bufferService === void 0 ? void 0 : _this$_bufferService.evictBuffer(_this._opts.bufferBehind);
10202
- _context.next = 31;
10687
+ _context.next = 33;
10203
10688
  break;
10204
- case 21:
10205
- _context.prev = 21;
10206
- _context.t0 = _context["catch"](15);
10689
+ case 23:
10690
+ _context.prev = 23;
10691
+ _context.t0 = _context["catch"](17);
10207
10692
  if (!(!_this.isLive && _this._bufferService.isFull())) {
10208
- _context.next = 30;
10693
+ _context.next = 32;
10209
10694
  break;
10210
10695
  }
10211
- _context.next = 26;
10696
+ _context.next = 28;
10212
10697
  return _this._mediaLoader.cancel();
10213
- case 26:
10698
+ case 28:
10214
10699
  _this._loading = false;
10215
10700
  remaining = _this.bufferInfo().remaining;
10216
10701
  _this._opts.preloadTime = parseInt(remaining) / 2;
10217
10702
  return _context.abrupt("return");
10218
- case 30:
10703
+ case 32:
10219
10704
  return _context.abrupt("return", _this._emitError(StreamingError.create(_context.t0)));
10220
- case 31:
10705
+ case 33:
10221
10706
  if (_this._urlSwitching) {
10222
10707
  _this._urlSwitching = false;
10223
10708
  _this.emit(EVENT.SWITCH_URL_SUCCESS, {
@@ -10229,7 +10714,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10229
10714
  _this._tick();
10230
10715
  }
10231
10716
  if (!(done && !_this.media.seeking)) {
10232
- _context.next = 38;
10717
+ _context.next = 40;
10233
10718
  break;
10234
10719
  }
10235
10720
  _this.emit(EVENT.LOAD_COMPLETE);
@@ -10238,13 +10723,13 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10238
10723
  _this._end();
10239
10724
  }
10240
10725
  return _context.abrupt("return");
10241
- case 38:
10726
+ case 40:
10242
10727
  if (_this.isLive) {
10243
- _context.next = 40;
10728
+ _context.next = 42;
10244
10729
  break;
10245
10730
  }
10246
10731
  return _context.abrupt("return");
10247
- case 40:
10732
+ case 42:
10248
10733
  maxReaderInterval = _this._opts.maxReaderInterval;
10249
10734
  if (maxReaderInterval && _this._firstProgressEmit) {
10250
10735
  clearTimeout(_this._maxChunkWaitTimer);
@@ -10258,11 +10743,11 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10258
10743
  _this._end();
10259
10744
  }, maxReaderInterval);
10260
10745
  }
10261
- case 42:
10746
+ case 44:
10262
10747
  case "end":
10263
10748
  return _context.stop();
10264
10749
  }
10265
- }, _callee, null, [[15, 21]]);
10750
+ }, _callee, null, [[17, 23]]);
10266
10751
  }));
10267
10752
  return function(_x, _x2, _x3, _x4) {
10268
10753
  return _ref2.apply(this, arguments);
@@ -10295,19 +10780,19 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10295
10780
  if (bufferEnd < MAX_HOLE || !media.readyState)
10296
10781
  return;
10297
10782
  var opts = _this._opts;
10298
- if (isMediaPlaying(media)) {
10783
+ if (isMediaPlaying(media) && media.currentTime) {
10299
10784
  if (_this._gapService) {
10300
10785
  _this._gapService.do(media, opts.maxJumpDistance, _this.isLive, 3);
10301
10786
  }
10302
10787
  } else {
10303
- if (!media.currentTime && _this._gapService) {
10788
+ if (!media.currentTime && _this._gapService && opts.enableStartGapJump) {
10304
10789
  var gapJump = _this._opts.mseLowLatency || _this._opts.mseLowLatency === false && _this.bufferInfo(MAX_START_GAP).nextStart;
10305
10790
  if (gapJump) {
10306
10791
  _this._gapService.do(media, opts.maxJumpDistance, _this.isLive, 3);
10307
10792
  }
10308
10793
  return;
10309
10794
  }
10310
- if (opts.isLive && media.readyState === 4 && bufferEnd > opts.disconnectTime) {
10795
+ if (opts.isLive && media.readyState === 4 && bufferEnd - media.currentTime > opts.disconnectTime) {
10311
10796
  _this.disconnect();
10312
10797
  }
10313
10798
  }
@@ -10456,6 +10941,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10456
10941
  responseType: "arraybuffer"
10457
10942
  }));
10458
10943
  _this._disconnectRetryCount = _this._opts.disconnectRetryCount;
10944
+ _this._transferCost = new TransferCost();
10459
10945
  _this._bufferService = new BufferService(_assertThisInitialized$3(_this), _this._opts.softDecode ? _this.media : void 0, _this._opts);
10460
10946
  _this._seiService = new SeiService(_assertThisInitialized$3(_this));
10461
10947
  _this._bandwidthService = new BandwidthService({
@@ -10479,7 +10965,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10479
10965
  _createClass$4(Flv2, [{
10480
10966
  key: "version",
10481
10967
  get: function get() {
10482
- return "3.0.19-rc.0";
10968
+ return "3.0.20-rc.6";
10483
10969
  }
10484
10970
  }, {
10485
10971
  key: "isLive",
@@ -10595,9 +11081,9 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10595
11081
  return this._clear();
10596
11082
  case 8:
10597
11083
  setTimeout(function() {
11084
+ _this2._seamlessSwitching = true;
10598
11085
  _this2._loadData(_this2._opts.url);
10599
11086
  _this2._bufferService.seamlessSwitch();
10600
- _this2._seamlessSwitching = true;
10601
11087
  });
10602
11088
  _context5.next = 13;
10603
11089
  break;
@@ -10621,50 +11107,82 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10621
11107
  }, {
10622
11108
  key: "disconnect",
10623
11109
  value: function disconnect() {
11110
+ var _this$_bufferService4;
10624
11111
  logger.debug("disconnect!");
11112
+ (_this$_bufferService4 = this._bufferService) === null || _this$_bufferService4 === void 0 ? void 0 : _this$_bufferService4.resetSeamlessSwitchStats();
10625
11113
  return this._clear();
10626
11114
  }
10627
11115
  }, {
10628
11116
  key: "switchURL",
10629
11117
  value: function() {
10630
- var _switchURL = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee6(url, seamless) {
11118
+ var _switchURL = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee7(url, seamless) {
10631
11119
  var _this3 = this;
10632
- return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
11120
+ return _regeneratorRuntime$1().wrap(function _callee7$(_context7) {
10633
11121
  while (1)
10634
- switch (_context6.prev = _context6.next) {
11122
+ switch (_context7.prev = _context7.next) {
10635
11123
  case 0:
10636
11124
  if (this._bufferService) {
10637
- _context6.next = 2;
11125
+ _context7.next = 2;
10638
11126
  break;
10639
11127
  }
10640
- return _context6.abrupt("return");
11128
+ return _context7.abrupt("return");
10641
11129
  case 2:
10642
11130
  this._resetDisconnectCount();
11131
+ if (!(this._loading && seamless)) {
11132
+ _context7.next = 6;
11133
+ break;
11134
+ }
11135
+ this._bufferService.seamlessLoadingSwitch = /* @__PURE__ */ function() {
11136
+ var _ref5 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee6(pts) {
11137
+ return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
11138
+ while (1)
11139
+ switch (_context6.prev = _context6.next) {
11140
+ case 0:
11141
+ _context6.next = 2;
11142
+ return _this3._clear();
11143
+ case 2:
11144
+ _this3._bufferService.seamlessLoadingSwitching = true;
11145
+ _this3._urlSwitching = true;
11146
+ _this3._seamlessSwitching = true;
11147
+ _this3._bufferService.seamlessSwitch();
11148
+ _this3._loadData(url);
11149
+ case 7:
11150
+ case "end":
11151
+ return _context6.stop();
11152
+ }
11153
+ }, _callee6);
11154
+ }));
11155
+ return function(_x8) {
11156
+ return _ref5.apply(this, arguments);
11157
+ };
11158
+ }();
11159
+ return _context7.abrupt("return");
11160
+ case 6:
10643
11161
  if (!(!seamless || !this._opts.isLive)) {
10644
- _context6.next = 8;
11162
+ _context7.next = 11;
10645
11163
  break;
10646
11164
  }
10647
- _context6.next = 6;
11165
+ _context7.next = 9;
10648
11166
  return this.load(url);
10649
- case 6:
11167
+ case 9:
10650
11168
  this._urlSwitching = true;
10651
- return _context6.abrupt("return", this.media.play(true).catch(function() {
11169
+ return _context7.abrupt("return", this.media.play(true).catch(function() {
10652
11170
  }));
10653
- case 8:
10654
- _context6.next = 10;
11171
+ case 11:
11172
+ _context7.next = 13;
10655
11173
  return this._clear();
10656
- case 10:
11174
+ case 13:
10657
11175
  setTimeout(function() {
10658
11176
  _this3._urlSwitching = true;
10659
11177
  _this3._seamlessSwitching = true;
10660
11178
  _this3._loadData(url);
10661
11179
  _this3._bufferService.seamlessSwitch();
10662
11180
  });
10663
- case 11:
11181
+ case 14:
10664
11182
  case "end":
10665
- return _context6.stop();
11183
+ return _context7.stop();
10666
11184
  }
10667
- }, _callee6, this);
11185
+ }, _callee7, this);
10668
11186
  }));
10669
11187
  function switchURL(_x6, _x7) {
10670
11188
  return _switchURL.apply(this, arguments);
@@ -10674,16 +11192,16 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10674
11192
  }, {
10675
11193
  key: "destroy",
10676
11194
  value: function() {
10677
- var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee7() {
10678
- return _regeneratorRuntime$1().wrap(function _callee7$(_context7) {
11195
+ var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee8() {
11196
+ return _regeneratorRuntime$1().wrap(function _callee8$(_context8) {
10679
11197
  while (1)
10680
- switch (_context7.prev = _context7.next) {
11198
+ switch (_context8.prev = _context8.next) {
10681
11199
  case 0:
10682
11200
  if (this.media) {
10683
- _context7.next = 2;
11201
+ _context8.next = 2;
10684
11202
  break;
10685
11203
  }
10686
- return _context7.abrupt("return");
11204
+ return _context8.abrupt("return");
10687
11205
  case 2:
10688
11206
  this.removeAllListeners();
10689
11207
  this._seiService.reset();
@@ -10693,16 +11211,16 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10693
11211
  this.media.removeEventListener("timeupdate", this._onTimeupdate);
10694
11212
  this.media.removeEventListener("waiting", this._onWaiting);
10695
11213
  this.media.removeEventListener("progress", this._onBufferUpdate);
10696
- _context7.next = 12;
11214
+ _context8.next = 12;
10697
11215
  return Promise.all([this._clear(), this._bufferService.destroy()]);
10698
11216
  case 12:
10699
11217
  this.media = null;
10700
11218
  this._bufferService = null;
10701
11219
  case 14:
10702
11220
  case "end":
10703
- return _context7.stop();
11221
+ return _context8.stop();
10704
11222
  }
10705
- }, _callee7, this);
11223
+ }, _callee8, this);
10706
11224
  }));
10707
11225
  function destroy() {
10708
11226
  return _destroy.apply(this, arguments);
@@ -10731,26 +11249,26 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10731
11249
  }, {
10732
11250
  key: "_reset",
10733
11251
  value: function() {
10734
- var _reset2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee8() {
10735
- var reuseMse, _args8 = arguments;
10736
- return _regeneratorRuntime$1().wrap(function _callee8$(_context8) {
11252
+ var _reset2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee9() {
11253
+ var reuseMse, _args9 = arguments;
11254
+ return _regeneratorRuntime$1().wrap(function _callee9$(_context9) {
10737
11255
  while (1)
10738
- switch (_context8.prev = _context8.next) {
11256
+ switch (_context9.prev = _context9.next) {
10739
11257
  case 0:
10740
- reuseMse = _args8.length > 0 && _args8[0] !== void 0 ? _args8[0] : false;
11258
+ reuseMse = _args9.length > 0 && _args9[0] !== void 0 ? _args9[0] : false;
10741
11259
  this._seiService.reset();
10742
11260
  this._bandwidthService.reset();
10743
11261
  this._stats.reset();
10744
- _context8.next = 6;
11262
+ _context9.next = 6;
10745
11263
  return this._clear();
10746
11264
  case 6:
10747
- _context8.next = 8;
11265
+ _context9.next = 8;
10748
11266
  return this._bufferService.reset(reuseMse);
10749
11267
  case 8:
10750
11268
  case "end":
10751
- return _context8.stop();
11269
+ return _context9.stop();
10752
11270
  }
10753
- }, _callee8, this);
11271
+ }, _callee9, this);
10754
11272
  }));
10755
11273
  function _reset() {
10756
11274
  return _reset2.apply(this, arguments);
@@ -10760,17 +11278,17 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10760
11278
  }, {
10761
11279
  key: "_loadData",
10762
11280
  value: function() {
10763
- var _loadData2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee9(url, range) {
11281
+ var _loadData2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee10(url, range) {
10764
11282
  var finnalUrl;
10765
- return _regeneratorRuntime$1().wrap(function _callee9$(_context9) {
11283
+ return _regeneratorRuntime$1().wrap(function _callee10$(_context10) {
10766
11284
  while (1)
10767
- switch (_context9.prev = _context9.next) {
11285
+ switch (_context10.prev = _context10.next) {
10768
11286
  case 0:
10769
11287
  if (url)
10770
11288
  this._opts.url = url;
10771
11289
  finnalUrl = url = this._opts.url;
10772
11290
  if (url) {
10773
- _context9.next = 4;
11291
+ _context10.next = 4;
10774
11292
  break;
10775
11293
  }
10776
11294
  throw new Error("Source url is missing");
@@ -10785,34 +11303,34 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10785
11303
  });
10786
11304
  logger.debug("load data, loading:", this._loading, finnalUrl);
10787
11305
  if (!this._loading) {
10788
- _context9.next = 11;
11306
+ _context10.next = 11;
10789
11307
  break;
10790
11308
  }
10791
- _context9.next = 11;
11309
+ _context10.next = 11;
10792
11310
  return this._mediaLoader.cancel();
10793
11311
  case 11:
10794
11312
  this._loading = true;
10795
- _context9.prev = 12;
10796
- _context9.next = 15;
11313
+ _context10.prev = 12;
11314
+ _context10.next = 15;
10797
11315
  return this._mediaLoader.load({
10798
11316
  url: finnalUrl,
10799
11317
  range
10800
11318
  });
10801
11319
  case 15:
10802
- _context9.next = 21;
11320
+ _context10.next = 21;
10803
11321
  break;
10804
11322
  case 17:
10805
- _context9.prev = 17;
10806
- _context9.t0 = _context9["catch"](12);
11323
+ _context10.prev = 17;
11324
+ _context10.t0 = _context10["catch"](12);
10807
11325
  this._loading = false;
10808
- return _context9.abrupt("return", this._emitError(StreamingError.network(_context9.t0), false));
11326
+ return _context10.abrupt("return", this._emitError(StreamingError.network(_context10.t0), false));
10809
11327
  case 21:
10810
11328
  case "end":
10811
- return _context9.stop();
11329
+ return _context10.stop();
10812
11330
  }
10813
- }, _callee9, this, [[12, 17]]);
11331
+ }, _callee10, this, [[12, 17]]);
10814
11332
  }));
10815
- function _loadData(_x8, _x9) {
11333
+ function _loadData(_x9, _x10) {
10816
11334
  return _loadData2.apply(this, arguments);
10817
11335
  }
10818
11336
  return _loadData;
@@ -10820,16 +11338,16 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10820
11338
  }, {
10821
11339
  key: "_clear",
10822
11340
  value: function() {
10823
- var _clear2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee10() {
10824
- return _regeneratorRuntime$1().wrap(function _callee10$(_context10) {
11341
+ var _clear2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee11() {
11342
+ return _regeneratorRuntime$1().wrap(function _callee11$(_context11) {
10825
11343
  while (1)
10826
- switch (_context10.prev = _context10.next) {
11344
+ switch (_context11.prev = _context11.next) {
10827
11345
  case 0:
10828
11346
  if (!this._mediaLoader) {
10829
- _context10.next = 3;
11347
+ _context11.next = 3;
10830
11348
  break;
10831
11349
  }
10832
- _context10.next = 3;
11350
+ _context11.next = 3;
10833
11351
  return this._mediaLoader.cancel();
10834
11352
  case 3:
10835
11353
  clearTimeout(this._maxChunkWaitTimer);
@@ -10838,9 +11356,9 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10838
11356
  this._firstProgressEmit = false;
10839
11357
  case 7:
10840
11358
  case "end":
10841
- return _context10.stop();
11359
+ return _context11.stop();
10842
11360
  }
10843
- }, _callee10, this);
11361
+ }, _callee11, this);
10844
11362
  }));
10845
11363
  function _clear() {
10846
11364
  return _clear2.apply(this, arguments);
@@ -10927,9 +11445,13 @@ var PluginExtension = /* @__PURE__ */ function() {
10927
11445
  _createClass$4(PluginExtension2, [{
10928
11446
  key: "_init",
10929
11447
  value: function _init() {
10930
- var _this$_opts2 = this._opts, media = _this$_opts2.media, preloadTime = _this$_opts2.preloadTime, innerDegrade = _this$_opts2.innerDegrade, decodeMode = _this$_opts2.decodeMode;
11448
+ 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;
10931
11449
  if (!media)
10932
11450
  return;
11451
+ if (!isLive && media.setPlayMode) {
11452
+ media.setPlayMode("VOD");
11453
+ return;
11454
+ }
10933
11455
  if (innerDegrade) {
10934
11456
  media.setAttribute("innerdegrade", innerDegrade);
10935
11457
  }
@@ -10967,6 +11489,7 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
10967
11489
  args[_key] = arguments[_key];
10968
11490
  }
10969
11491
  _this = _super.call.apply(_super, [this].concat(args));
11492
+ _defineProperty$3(_assertThisInitialized$3(_this), "logger", logger);
10970
11493
  _defineProperty$3(_assertThisInitialized$3(_this), "flv", null);
10971
11494
  _defineProperty$3(_assertThisInitialized$3(_this), "pluginExtension", null);
10972
11495
  _defineProperty$3(_assertThisInitialized$3(_this), "getStats", function() {
@@ -11034,11 +11557,17 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
11034
11557
  var _this$flv3;
11035
11558
  return (_this$flv3 = this.flv) === null || _this$flv3 === void 0 ? void 0 : _this$flv3.loader;
11036
11559
  }
11560
+ }, {
11561
+ key: "transferCost",
11562
+ get: function get() {
11563
+ return this.flv._transferCost.transferCost;
11564
+ }
11037
11565
  }, {
11038
11566
  key: "beforePlayerInit",
11039
11567
  value: function beforePlayerInit() {
11040
11568
  var _this2 = this;
11041
11569
  var config = this.player.config;
11570
+ var mediaElem = this.player.media || this.player.video;
11042
11571
  if (!config.url)
11043
11572
  return;
11044
11573
  if (this.flv)
@@ -11051,10 +11580,10 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
11051
11580
  this.flv = new Flv(_objectSpread2$2({
11052
11581
  softDecode: this.softDecode,
11053
11582
  isLive: config.isLive,
11054
- media: this.player.video,
11583
+ media: mediaElem,
11055
11584
  preProcessUrl: function preProcessUrl(url, ext) {
11056
- var _this2$player$preProc, _this2$player;
11057
- 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)) || {
11585
+ var _this2$player, _this2$player$preProc;
11586
+ 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)) || {
11058
11587
  url,
11059
11588
  ext
11060
11589
  };
@@ -11073,7 +11602,8 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
11073
11602
  }
11074
11603
  if (this.softDecode) {
11075
11604
  this.pluginExtension = new PluginExtension(_objectSpread2$2({
11076
- media: this.player.video
11605
+ media: this.player.video,
11606
+ isLive: config.isLive
11077
11607
  }, config.flv), this);
11078
11608
  this.player.forceDegradeToVideo = function() {
11079
11609
  var _this2$pluginExtensio;
@@ -11100,6 +11630,7 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
11100
11630
  this._transCoreEvent(EVENT.LOAD_RETRY);
11101
11631
  this._transCoreEvent(EVENT.SOURCEBUFFER_CREATED);
11102
11632
  this._transCoreEvent(EVENT.ANALYZE_DURATION_EXCEEDED);
11633
+ this._transCoreEvent(EVENT.APPEND_BUFFER);
11103
11634
  this._transCoreEvent(EVENT.REMOVE_BUFFER);
11104
11635
  this._transCoreEvent(EVENT.BUFFEREOS);
11105
11636
  this._transCoreEvent(EVENT.KEYFRAME);