@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
@@ -1542,7 +1542,7 @@
1542
1542
  }
1543
1543
  return offsetTime;
1544
1544
  };
1545
- var version = "3.0.19-rc.0";
1545
+ var version = "3.0.20-rc.6";
1546
1546
  var ERROR_MAP = {
1547
1547
  1: 5101,
1548
1548
  2: 5102,
@@ -1650,8 +1650,7 @@
1650
1650
  }
1651
1651
  if (this.__hooks && this.__hooks[hookName]) {
1652
1652
  try {
1653
- var _this$__hooks$hookNam;
1654
- var preRet = (_this$__hooks$hookNam = this.__hooks[hookName]).call.apply(_this$__hooks$hookNam, [this, this].concat(Array.prototype.slice.call(arguments)));
1653
+ var preRet = runHooks(this, hookName, handler);
1655
1654
  if (preRet) {
1656
1655
  if (preRet.then) {
1657
1656
  preRet.then(function(isContinue) {
@@ -1676,6 +1675,19 @@
1676
1675
  }
1677
1676
  }.bind(this);
1678
1677
  }
1678
+ function findHookIndex(hookName, handler) {
1679
+ var __hooks = this.__hooks;
1680
+ if (!__hooks || !Array.isArray(__hooks[hookName])) {
1681
+ return -1;
1682
+ }
1683
+ var hookHandlers = __hooks[hookName];
1684
+ for (var i = 0; i < hookHandlers.length; i++) {
1685
+ if (hookHandlers[i] === handler) {
1686
+ return i;
1687
+ }
1688
+ }
1689
+ return -1;
1690
+ }
1679
1691
  function useHooks(hookName, handler) {
1680
1692
  var __hooks = this.__hooks;
1681
1693
  if (!__hooks) {
@@ -1685,7 +1697,12 @@
1685
1697
  console.warn("has no supported hook which name [".concat(hookName, "]"));
1686
1698
  return false;
1687
1699
  }
1688
- __hooks && (__hooks[hookName] = handler);
1700
+ if (!Array.isArray(__hooks[hookName])) {
1701
+ __hooks[hookName] = [];
1702
+ }
1703
+ if (findHookIndex.call(this, hookName, handler) === -1) {
1704
+ __hooks[hookName].push(handler);
1705
+ }
1689
1706
  return true;
1690
1707
  }
1691
1708
  function removeHooks(hookName, handler) {
@@ -1693,6 +1710,13 @@
1693
1710
  if (!__hooks) {
1694
1711
  return;
1695
1712
  }
1713
+ if (Array.isArray(__hooks[hookName])) {
1714
+ var hooks = __hooks[hookName];
1715
+ var index = findHookIndex.call(this, hookName, handler);
1716
+ if (index !== -1) {
1717
+ hooks.splice(index, 1);
1718
+ }
1719
+ }
1696
1720
  delete __hooks[hookName];
1697
1721
  }
1698
1722
  function hooksDescriptor(instance) {
@@ -1714,6 +1738,38 @@
1714
1738
  function delHooksDescriptor(instance) {
1715
1739
  instance.__hooks = null;
1716
1740
  }
1741
+ function runHooks(obj, hookName, handler) {
1742
+ for (var _len5 = arguments.length, args = new Array(_len5 > 3 ? _len5 - 3 : 0), _key5 = 3; _key5 < _len5; _key5++) {
1743
+ args[_key5 - 3] = arguments[_key5];
1744
+ }
1745
+ if (obj.__hooks && Array.isArray(obj.__hooks[hookName])) {
1746
+ var hooks = obj.__hooks[hookName];
1747
+ var index = -1;
1748
+ var runHooksRecursive = function runHooksRecursive2(obj2, hookName2, handler2) {
1749
+ for (var _len6 = arguments.length, args2 = new Array(_len6 > 3 ? _len6 - 3 : 0), _key6 = 3; _key6 < _len6; _key6++) {
1750
+ args2[_key6 - 3] = arguments[_key6];
1751
+ }
1752
+ index++;
1753
+ if (hooks.length === 0 || index === hooks.length) {
1754
+ return handler2.call.apply(handler2, [obj2, obj2].concat(args2));
1755
+ }
1756
+ var hook2 = hooks[index];
1757
+ var ret = hook2.call.apply(hook2, [obj2, obj2].concat(args2));
1758
+ if (ret && ret.then) {
1759
+ return ret.then(function(data) {
1760
+ return data === false ? null : runHooksRecursive2.apply(void 0, [obj2, hookName2, handler2].concat(args2));
1761
+ }).catch(function(e) {
1762
+ console.warn("[runHooks]".concat(hookName2, " reject"), e.message);
1763
+ });
1764
+ } else if (ret !== false) {
1765
+ return runHooksRecursive2.apply(void 0, [obj2, hookName2, handler2].concat(args2));
1766
+ }
1767
+ };
1768
+ return runHooksRecursive.apply(void 0, [obj, hookName, handler].concat(args));
1769
+ } else {
1770
+ return handler.call.apply(handler, [obj, obj].concat(args));
1771
+ }
1772
+ }
1717
1773
  function showErrorMsg(pluginName, msg) {
1718
1774
  XG_DEBUG.logError("[".concat(pluginName, "] event or callback cant be undefined or null when call ").concat(msg));
1719
1775
  }
@@ -1953,6 +2009,18 @@
1953
2009
  }
1954
2010
  }
1955
2011
  }
2012
+ }, {
2013
+ key: "defineMethod",
2014
+ value: function defineMethod(Obj, map) {
2015
+ for (var key in map) {
2016
+ if (Object.prototype.hasOwnProperty.call(map, key) && typeof map[key] === "function") {
2017
+ Object.defineProperty(Obj, key, {
2018
+ configurable: true,
2019
+ value: map[key]
2020
+ });
2021
+ }
2022
+ }
2023
+ }
1956
2024
  }, {
1957
2025
  key: "defaultConfig",
1958
2026
  get: function get() {
@@ -2763,6 +2831,21 @@
2763
2831
  length: Buffer2.totalLength && Buffer2.totalLength(buffers)
2764
2832
  };
2765
2833
  }
2834
+ }, {
2835
+ key: "isBuffered",
2836
+ value: function isBuffered(media, pos) {
2837
+ if (media) {
2838
+ var buffered = Buffer2.get(media);
2839
+ if (buffered !== null && buffered !== void 0 && buffered.length) {
2840
+ for (var i = 0; i < buffered.length; i++) {
2841
+ if (pos >= buffered.start(i) && pos <= buffered.end(i)) {
2842
+ return true;
2843
+ }
2844
+ }
2845
+ }
2846
+ }
2847
+ return false;
2848
+ }
2766
2849
  }]);
2767
2850
  return Buffer2;
2768
2851
  }();
@@ -2915,7 +2998,7 @@
2915
2998
  this.logCache.apply(this, [LogCacheLevel.DEBUG].concat(args));
2916
2999
  if (Logger2.disabled)
2917
3000
  return;
2918
- (_console = console).debug.apply(_console, [this._prefix, nowTime$1()].concat(args));
3001
+ (_console = console).debug.apply(_console, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
2919
3002
  }
2920
3003
  }, {
2921
3004
  key: "log",
@@ -2927,7 +3010,7 @@
2927
3010
  this.logCache.apply(this, [LogCacheLevel.LOG].concat(args));
2928
3011
  if (Logger2.disabled)
2929
3012
  return;
2930
- (_console2 = console).log.apply(_console2, [this._prefix, nowTime$1()].concat(args));
3013
+ (_console2 = console).log.apply(_console2, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
2931
3014
  }
2932
3015
  }, {
2933
3016
  key: "warn",
@@ -2939,7 +3022,7 @@
2939
3022
  this.logCache.apply(this, [LogCacheLevel.WARN].concat(args));
2940
3023
  if (Logger2.disabled)
2941
3024
  return;
2942
- (_console3 = console).warn.apply(_console3, [this._prefix, nowTime$1()].concat(args));
3025
+ (_console3 = console).warn.apply(_console3, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
2943
3026
  }
2944
3027
  }, {
2945
3028
  key: "error",
@@ -2951,7 +3034,7 @@
2951
3034
  this.logCache.apply(this, [LogCacheLevel.ERROR].concat(args));
2952
3035
  if (Logger2.disabled)
2953
3036
  return;
2954
- (_console4 = console).error.apply(_console4, [this._prefix, nowTime$1()].concat(args));
3037
+ (_console4 = console).error.apply(_console4, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
2955
3038
  }
2956
3039
  }, {
2957
3040
  key: "logCache",
@@ -2966,7 +3049,7 @@
2966
3049
  var finLogText = logText.map(function(item) {
2967
3050
  return logable(item);
2968
3051
  });
2969
- text = this._prefix + nowTime$1() + JSON.stringify(finLogText);
3052
+ text = "[".concat(nowTime$1(), "]") + this._prefix + JSON.stringify(finLogText);
2970
3053
  } catch (e) {
2971
3054
  return;
2972
3055
  }
@@ -3882,8 +3965,8 @@
3882
3965
  response
3883
3966
  };
3884
3967
  }
3885
- function calculateSpeed(byteLen, millisec) {
3886
- return Math.round(byteLen * 8 * 1e3 / millisec / 1024);
3968
+ function calculateSpeed(byteLen, milliSecond) {
3969
+ return Math.round(byteLen * 8 * 1e3 / milliSecond / 1024);
3887
3970
  }
3888
3971
  var EVENT = {
3889
3972
  ERROR: "error",
@@ -3895,6 +3978,7 @@
3895
3978
  SOURCEBUFFER_CREATED: "core.sourcebuffercreated",
3896
3979
  MEDIASOURCE_OPENED: "core.mediasourceopened",
3897
3980
  ANALYZE_DURATION_EXCEEDED: "core.analyzedurationexceeded",
3981
+ APPEND_BUFFER: "core.appendbuffer",
3898
3982
  REMOVE_BUFFER: "core.removebuffer",
3899
3983
  BUFFEREOS: "core.buffereos",
3900
3984
  KEYFRAME: "core.keyframe",
@@ -5527,13 +5611,15 @@
5527
5611
  METADATA: "metadata"
5528
5612
  };
5529
5613
  var VideoCodecType = {
5614
+ AV1: "av1",
5530
5615
  AVC: "avc",
5531
5616
  HEVC: "hevc"
5532
5617
  };
5533
5618
  var AudioCodecType = {
5534
5619
  AAC: "aac",
5535
5620
  G711PCMA: "g7110a",
5536
- G711PCMU: "g7110m"
5621
+ G711PCMU: "g7110m",
5622
+ OPUS: "opus"
5537
5623
  };
5538
5624
  var WarningType = {
5539
5625
  LARGE_AV_SHIFT: "LARGE_AV_SHIFT",
@@ -5573,6 +5659,7 @@
5573
5659
  _defineProperty(this, "isVideoEncryption", false);
5574
5660
  _defineProperty(this, "isAudioEncryption", false);
5575
5661
  _defineProperty(this, "isVideo", true);
5662
+ _defineProperty(this, "lastKeyFrameDts", 0);
5576
5663
  _defineProperty(this, "kid", null);
5577
5664
  _defineProperty(this, "pssh", null);
5578
5665
  _defineProperty(this, "ext", void 0);
@@ -5615,6 +5702,9 @@
5615
5702
  }, {
5616
5703
  key: "exist",
5617
5704
  value: function exist() {
5705
+ if (/av01/.test(this.codec)) {
5706
+ return true;
5707
+ }
5618
5708
  return !!(this.pps.length && this.sps.length && this.codec);
5619
5709
  }
5620
5710
  }, {
@@ -5678,7 +5768,7 @@
5678
5768
  }, {
5679
5769
  key: "exist",
5680
5770
  value: function exist() {
5681
- return !!(this.sampleRate && this.channelCount && this.codec && this.codecType === AudioCodecType.AAC);
5771
+ return !!(this.sampleRate && this.channelCount && this.codec && (this.codecType === AudioCodecType.AAC || this.codecType === AudioCodecType.G711PCMA || this.codecType === AudioCodecType.G711PCMU || this.codecType === AudioCodecType.OPUS));
5682
5772
  }
5683
5773
  }, {
5684
5774
  key: "hasSample",
@@ -5892,7 +5982,7 @@
5892
5982
  continue;
5893
5983
  }
5894
5984
  frameLength = (data[i + 3] & 3) << 11 | data[i + 4] << 3 | (data[i + 5] & 224) >> 5;
5895
- if (len - i < frameLength)
5985
+ if (!frameLength || len - i < frameLength)
5896
5986
  break;
5897
5987
  protectionSkipBytes = (~data[i + 1] & 1) * 2;
5898
5988
  frames.push({
@@ -6026,14 +6116,57 @@
6026
6116
  return AAC2;
6027
6117
  }();
6028
6118
  _defineProperty(AAC, "FREQ", [96e3, 88200, 64e3, 48e3, 44100, 32e3, 24e3, 22050, 16e3, 12e3, 11025, 8e3, 7350]);
6119
+ var OPUS = /* @__PURE__ */ function() {
6120
+ function OPUS2() {
6121
+ _classCallCheck$1(this, OPUS2);
6122
+ }
6123
+ _createClass$1(OPUS2, null, [{
6124
+ key: "getFrameDuration",
6125
+ value: function getFrameDuration(samples) {
6126
+ return 20;
6127
+ }
6128
+ }, {
6129
+ key: "parseHeaderPackets",
6130
+ value: function parseHeaderPackets(data) {
6131
+ if (!data.length)
6132
+ return;
6133
+ var dv = new DataView(data.buffer, data.byteOffset, data.byteLength);
6134
+ var magicSignature = "";
6135
+ for (var i = 0; i < 8; i++) {
6136
+ magicSignature += String.fromCodePoint(data[i]);
6137
+ }
6138
+ if (magicSignature !== "OpusHead") {
6139
+ throw new Error("Invalid Opus MagicSignature");
6140
+ }
6141
+ var channelCount = data[9];
6142
+ console.log("Pre-skip", data[10], data[11]);
6143
+ var sampleRate = dv.getUint32(12, true);
6144
+ var outputGain = dv.getInt16(16, true);
6145
+ if (!sampleRate)
6146
+ return;
6147
+ var codec = "opus";
6148
+ var originCodec = "opus";
6149
+ var config = new Uint8Array(data.buffer, data.byteOffset + 8, data.byteLength - 8);
6150
+ return {
6151
+ outputGain,
6152
+ sampleRate,
6153
+ channelCount,
6154
+ config,
6155
+ codec,
6156
+ originCodec
6157
+ };
6158
+ }
6159
+ }]);
6160
+ return OPUS2;
6161
+ }();
6029
6162
  var LARGE_AV_FIRST_FRAME_GAP = 500;
6030
6163
  var AUDIO_GAP_OVERLAP_THRESHOLD_COUNT = 3;
6031
6164
  var MAX_SILENT_FRAME_DURATION = 1e3;
6032
- var AUDIO_EXCETION_LOG_EMIT_DURATION = 5e3;
6165
+ var AUDIO_EXCEPTION_LOG_EMIT_DURATION = 5e3;
6033
6166
  var MAX_VIDEO_FRAME_DURATION = 1e3;
6034
6167
  var MAX_DTS_DELTA_WITH_NEXT_CHUNK = 200;
6035
- var VIDEO_EXCETION_LOG_EMIT_DURATION = 5e3;
6036
- var TRACK_BREACKED_CHECK_TIME = 5;
6168
+ var VIDEO_EXCEPTION_LOG_EMIT_DURATION = 5e3;
6169
+ var TRACK_BROKEN_CHECK_TIME = 5;
6037
6170
  var FlvFixer = /* @__PURE__ */ function() {
6038
6171
  function FlvFixer2(videoTrack, audioTrack, metadataTrack) {
6039
6172
  _classCallCheck$1(this, FlvFixer2);
@@ -6149,7 +6282,7 @@
6149
6282
  var firstSample = samples[0];
6150
6283
  var vDelta = this._videoNextDts - firstSample.dts;
6151
6284
  if (Math.abs(vDelta) > MAX_DTS_DELTA_WITH_NEXT_CHUNK) {
6152
- if (Math.abs(firstSample.dts - this._lastVideoExceptionChunkFirstDtsDot) > VIDEO_EXCETION_LOG_EMIT_DURATION) {
6285
+ if (Math.abs(firstSample.dts - this._lastVideoExceptionChunkFirstDtsDot) > VIDEO_EXCEPTION_LOG_EMIT_DURATION) {
6153
6286
  var _samples$;
6154
6287
  this._lastVideoExceptionChunkFirstDtsDot = firstSample.dts;
6155
6288
  videoTrack.warnings.push({
@@ -6160,7 +6293,7 @@
6160
6293
  sampleDuration: vDelta
6161
6294
  });
6162
6295
  }
6163
- if (this._videoTimestampBreak >= TRACK_BREACKED_CHECK_TIME) {
6296
+ if (this._videoTimestampBreak >= TRACK_BROKEN_CHECK_TIME) {
6164
6297
  this._videoNextDts = firstSample.dts;
6165
6298
  this._videoTimestampBreak = 0;
6166
6299
  } else {
@@ -6183,7 +6316,7 @@
6183
6316
  }
6184
6317
  if (sampleDuration > MAX_VIDEO_FRAME_DURATION || sampleDuration < 0) {
6185
6318
  this._videoTimestampBreak++;
6186
- if (Math.abs(dts - this._lastVideoExceptionLargeGapDot) > VIDEO_EXCETION_LOG_EMIT_DURATION) {
6319
+ if (Math.abs(dts - this._lastVideoExceptionLargeGapDot) > VIDEO_EXCEPTION_LOG_EMIT_DURATION) {
6187
6320
  this._lastVideoExceptionLargeGapDot = dts;
6188
6321
  videoTrack.warnings.push({
6189
6322
  type: WarningType.LARGE_VIDEO_GAP,
@@ -6264,10 +6397,27 @@
6264
6397
  key: "_doFixAudioInternal",
6265
6398
  value: function _doFixAudioInternal(audioTrack, samples, timescale) {
6266
6399
  if (!audioTrack.sampleDuration) {
6267
- audioTrack.sampleDuration = audioTrack.codecType === AudioCodecType.AAC ? AAC.getFrameDuration(audioTrack.timescale, timescale) : this._getG711Duration(audioTrack);
6400
+ switch (audioTrack.codecType) {
6401
+ case AudioCodecType.AAC: {
6402
+ audioTrack.sampleDuration = AAC.getFrameDuration(audioTrack.timescale, timescale);
6403
+ break;
6404
+ }
6405
+ case AudioCodecType.OPUS: {
6406
+ audioTrack.sampleDuration = OPUS.getFrameDuration(audioTrack.samples, timescale);
6407
+ break;
6408
+ }
6409
+ case AudioCodecType.G711PCMA:
6410
+ case AudioCodecType.G711PCMU: {
6411
+ audioTrack.sampleDuration = this._getG711Duration(audioTrack);
6412
+ break;
6413
+ }
6414
+ default:
6415
+ console.error("can't fix audio codecType:", audioTrack.codecType);
6416
+ break;
6417
+ }
6268
6418
  }
6269
6419
  var refSampleDuration = audioTrack.sampleDuration;
6270
- var sampleDurationInSampleRate = audioTrack.codecType === AudioCodecType.AAC ? 1024 : refSampleDuration * audioTrack.timescale / 1e3;
6420
+ var sampleDurationInSampleRate = audioTrack.codecType === AudioCodecType.OPUS ? 20 : audioTrack.codecType === AudioCodecType.AAC ? 1024 : refSampleDuration * audioTrack.timescale / 1e3;
6271
6421
  if (this._audioNextPts === void 0) {
6272
6422
  var samp0 = samples[0];
6273
6423
  this._audioNextPts = samp0.pts;
@@ -6276,7 +6426,7 @@
6276
6426
  var nextPts = this._audioNextPts;
6277
6427
  var sample = samples[i];
6278
6428
  var delta = sample.pts - nextPts;
6279
- if (i === 0 && this._audioTimestampBreak >= TRACK_BREACKED_CHECK_TIME && this._keyFrameInNextChunk) {
6429
+ if (i === 0 && this._audioTimestampBreak >= TRACK_BROKEN_CHECK_TIME && this._keyFrameInNextChunk) {
6280
6430
  nextPts = this._audioNextPts = sample.dts;
6281
6431
  delta = 0;
6282
6432
  this._audioTimestampBreak = 0;
@@ -6284,7 +6434,7 @@
6284
6434
  if (!this._audioTimestampBreak && delta >= AUDIO_GAP_OVERLAP_THRESHOLD_COUNT * refSampleDuration && delta <= MAX_SILENT_FRAME_DURATION && !isSafari) {
6285
6435
  var silentFrame = this._getSilentFrame(audioTrack) || samples[0].data.subarray();
6286
6436
  var count = Math.floor(delta / refSampleDuration);
6287
- if (Math.abs(sample.pts - this._lastAudioExceptionGapDot) > AUDIO_EXCETION_LOG_EMIT_DURATION) {
6437
+ if (Math.abs(sample.pts - this._lastAudioExceptionGapDot) > AUDIO_EXCEPTION_LOG_EMIT_DURATION) {
6288
6438
  this._lastAudioExceptionGapDot = sample.pts;
6289
6439
  audioTrack.warnings.push({
6290
6440
  type: WarningType.AUDIO_FILLED,
@@ -6304,7 +6454,7 @@
6304
6454
  }
6305
6455
  i--;
6306
6456
  } else if (delta <= -AUDIO_GAP_OVERLAP_THRESHOLD_COUNT * refSampleDuration && delta >= -1 * MAX_SILENT_FRAME_DURATION) {
6307
- if (Math.abs(sample.pts - this._lastAudioExceptionOverlapDot) > AUDIO_EXCETION_LOG_EMIT_DURATION) {
6457
+ if (Math.abs(sample.pts - this._lastAudioExceptionOverlapDot) > AUDIO_EXCEPTION_LOG_EMIT_DURATION) {
6308
6458
  this._lastAudioExceptionOverlapDot = sample.pts;
6309
6459
  audioTrack.warnings.push({
6310
6460
  type: WarningType.AUDIO_DROPPED,
@@ -6319,7 +6469,7 @@
6319
6469
  } else {
6320
6470
  if (Math.abs(delta) > MAX_SILENT_FRAME_DURATION) {
6321
6471
  this._audioTimestampBreak++;
6322
- if (Math.abs(sample.pts - this._lastAudioExceptionLargeGapDot) > AUDIO_EXCETION_LOG_EMIT_DURATION) {
6472
+ if (Math.abs(sample.pts - this._lastAudioExceptionLargeGapDot) > AUDIO_EXCEPTION_LOG_EMIT_DURATION) {
6323
6473
  this._lastAudioExceptionLargeGapDot = sample.pts;
6324
6474
  audioTrack.warnings.push({
6325
6475
  type: WarningType.LARGE_AUDIO_GAP,
@@ -6332,8 +6482,15 @@
6332
6482
  });
6333
6483
  }
6334
6484
  }
6335
- sample.dts = sample.pts = nextPts;
6336
- sample.duration = sampleDurationInSampleRate;
6485
+ if (audioTrack.codecType === AudioCodecType.OPUS) {
6486
+ var lastSample = samples[samples.length - 1];
6487
+ if (lastSample) {
6488
+ lastSample.duration = sample.pts - lastSample.pts;
6489
+ }
6490
+ } else {
6491
+ sample.dts = sample.pts = nextPts;
6492
+ sample.duration = sampleDurationInSampleRate;
6493
+ }
6337
6494
  this._audioNextPts += refSampleDuration;
6338
6495
  }
6339
6496
  }
@@ -7292,6 +7449,13 @@
7292
7449
  }]);
7293
7450
  return AMF2;
7294
7451
  }();
7452
+ var FlvSoundFormat = {
7453
+ MP3: 2,
7454
+ G711A: 7,
7455
+ G711M: 8,
7456
+ AAC: 10,
7457
+ OPUS: 13
7458
+ };
7295
7459
  var logger$2 = new Logger$1("FlvDemuxer");
7296
7460
  var FlvDemuxer = /* @__PURE__ */ function() {
7297
7461
  function FlvDemuxer2(videoTrack, audioTrack, metadataTrack) {
@@ -7308,8 +7472,10 @@
7308
7472
  _createClass$1(FlvDemuxer2, [{
7309
7473
  key: "demux",
7310
7474
  value: function demux(data) {
7475
+ var _scriptDataObject$dat;
7311
7476
  var discontinuity = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
7312
7477
  var contiguous = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
7478
+ var seamlessLoadingSwitching = arguments.length > 3 ? arguments[3] : void 0;
7313
7479
  var audioTrack = this.audioTrack, videoTrack = this.videoTrack, metadataTrack = this.metadataTrack;
7314
7480
  if (discontinuity || !contiguous) {
7315
7481
  this._remainingData = null;
@@ -7367,6 +7533,8 @@
7367
7533
  if (tagType === 8) {
7368
7534
  this._parseAudio(bodyData, timestamp);
7369
7535
  } else if (tagType === 9) {
7536
+ if (seamlessLoadingSwitching)
7537
+ this.seamlessLoadingSwitching = true;
7370
7538
  this._parseVideo(bodyData, timestamp);
7371
7539
  } else if (tagType === 18) {
7372
7540
  this._parseScript(bodyData, timestamp);
@@ -7384,13 +7552,31 @@
7384
7552
  this._remainingData = data.subarray(offset);
7385
7553
  }
7386
7554
  audioTrack.formatTimescale = videoTrack.formatTimescale = videoTrack.timescale = metadataTrack.timescale = 1e3;
7387
- audioTrack.timescale = audioTrack.sampleRate || 0;
7555
+ audioTrack.timescale = audioTrack.codecType === AudioCodecType.OPUS ? 1e3 : audioTrack.sampleRate || 0;
7388
7556
  if (!audioTrack.exist() && audioTrack.hasSample()) {
7389
7557
  audioTrack.reset();
7390
7558
  }
7391
7559
  if (!videoTrack.exist() && videoTrack.hasSample()) {
7392
7560
  videoTrack.reset();
7393
7561
  }
7562
+ var scriptDataObject = metadataTrack.flvScriptSamples[metadataTrack.flvScriptSamples.length - 1];
7563
+ var metaData = scriptDataObject === null || scriptDataObject === void 0 ? void 0 : (_scriptDataObject$dat = scriptDataObject.data) === null || _scriptDataObject$dat === void 0 ? void 0 : _scriptDataObject$dat.onMetaData;
7564
+ if (metaData) {
7565
+ if (videoTrack !== null && videoTrack !== void 0 && videoTrack.exist()) {
7566
+ if (metaData.hasOwnProperty("duration")) {
7567
+ videoTrack.duration = metaData.duration * 1e3;
7568
+ }
7569
+ if (metaData.hasOwnProperty("width") && metaData.hasOwnProperty("height")) {
7570
+ videoTrack.width = metaData.width;
7571
+ videoTrack.height = metaData.height;
7572
+ }
7573
+ }
7574
+ if (audioTrack !== null && audioTrack !== void 0 && audioTrack.exist()) {
7575
+ if (metaData.hasOwnProperty("duration")) {
7576
+ audioTrack.duration = metaData.duration * 1e3;
7577
+ }
7578
+ }
7579
+ }
7394
7580
  return {
7395
7581
  videoTrack,
7396
7582
  audioTrack,
@@ -7409,8 +7595,8 @@
7409
7595
  }
7410
7596
  }, {
7411
7597
  key: "demuxAndFix",
7412
- value: function demuxAndFix(data, discontinuity, contiguous, startTime) {
7413
- this.demux(data, discontinuity, contiguous);
7598
+ value: function demuxAndFix(data, discontinuity, contiguous, startTime, seamlessLoadingSwitching) {
7599
+ this.demux(data, discontinuity, contiguous, seamlessLoadingSwitching);
7414
7600
  return this.fix(startTime, discontinuity, contiguous);
7415
7601
  }
7416
7602
  }, {
@@ -7420,12 +7606,12 @@
7420
7606
  return;
7421
7607
  var format = (data[0] & 240) >>> 4;
7422
7608
  var track = this.audioTrack;
7423
- if (format !== 10 && format !== 7 && format !== 8) {
7609
+ if (format !== FlvSoundFormat.AAC && format !== FlvSoundFormat.G711A && format !== FlvSoundFormat.G711M && format !== FlvSoundFormat.OPUS) {
7424
7610
  logger$2.warn("Unsupported sound format: ".concat(format));
7425
7611
  track.reset();
7426
7612
  return;
7427
7613
  }
7428
- if (format !== 10) {
7614
+ if (format !== FlvSoundFormat.AAC && format !== FlvSoundFormat.OPUS) {
7429
7615
  var soundRate = (data[0] & 12) >> 2;
7430
7616
  var soundSize = (data[0] & 2) >> 1;
7431
7617
  var soundType = data[0] & 1;
@@ -7433,10 +7619,49 @@
7433
7619
  track.sampleSize = soundSize ? 16 : 8;
7434
7620
  track.channelCount = soundType + 1;
7435
7621
  }
7436
- if (format === 10) {
7437
- this._parseAac(data, pts);
7438
- } else {
7439
- this._parseG711(data, pts, format);
7622
+ switch (format) {
7623
+ case FlvSoundFormat.G711A:
7624
+ case FlvSoundFormat.G711M:
7625
+ this._parseG711(data, pts, format);
7626
+ break;
7627
+ case FlvSoundFormat.AAC:
7628
+ this._parseAac(data, pts);
7629
+ break;
7630
+ case FlvSoundFormat.OPUS:
7631
+ this._parseOpus(data, pts);
7632
+ break;
7633
+ }
7634
+ }
7635
+ }, {
7636
+ key: "_parseOpus",
7637
+ value: function _parseOpus(data, pts) {
7638
+ var track = this.audioTrack;
7639
+ var packetType = data[1];
7640
+ track.codecType = AudioCodecType.OPUS;
7641
+ switch (packetType) {
7642
+ case 0: {
7643
+ var ret = OPUS.parseHeaderPackets(data.subarray(2));
7644
+ if (ret) {
7645
+ track.codec = ret.codec;
7646
+ track.channelCount = ret.channelCount;
7647
+ track.sampleRate = ret.sampleRate;
7648
+ track.config = ret.config;
7649
+ track.sampleDuration = OPUS.getFrameDuration([], track.timescale);
7650
+ } else {
7651
+ track.reset();
7652
+ logger$2.warn("Cannot parse AudioSpecificConfig", data);
7653
+ }
7654
+ break;
7655
+ }
7656
+ case 1: {
7657
+ if (pts === void 0 || pts === null)
7658
+ return;
7659
+ var newSample = new AudioSample(pts, data.subarray(2), track.sampleDuration);
7660
+ track.samples.push(newSample);
7661
+ break;
7662
+ }
7663
+ default:
7664
+ logger$2.warn("Unknown OpusPacketType: ".concat(packetType));
7440
7665
  }
7441
7666
  }
7442
7667
  }, {
@@ -7524,8 +7749,13 @@
7524
7749
  units = this._checkAddMetaNalToUnits(isHevc, units, track);
7525
7750
  if (units && units.length) {
7526
7751
  var sample = new VideoSample(dts + cts, dts, units);
7752
+ if (this.seamlessLoadingSwitching && dts < track.lastKeyFrameDts) {
7753
+ return;
7754
+ }
7755
+ this.seamlessLoadingSwitching = false;
7527
7756
  if (frameType === 1) {
7528
7757
  sample.setToKeyframe();
7758
+ track.lastKeyFrameDts = dts;
7529
7759
  }
7530
7760
  track.samples.push(sample);
7531
7761
  units.forEach(function(unit) {
@@ -7999,10 +8229,16 @@
7999
8229
  if (track.useEME && track.enca) {
8000
8230
  content = MP42.enca(track);
8001
8231
  } else {
8002
- content = MP42.mp4a(track);
8232
+ if (track.codecType === AudioCodecType.OPUS) {
8233
+ content = MP42.opus(track);
8234
+ } else {
8235
+ content = MP42.mp4a(track);
8236
+ }
8003
8237
  }
8004
8238
  } else if (track.useEME && track.encv) {
8005
8239
  content = MP42.encv(track);
8240
+ } else if (track.av1C) {
8241
+ content = MP42.av01(track);
8006
8242
  } else {
8007
8243
  content = MP42.avc1hev1(track);
8008
8244
  }
@@ -8215,6 +8451,90 @@
8215
8451
  var schi = MP42.schi(data);
8216
8452
  return MP42.box(MP42.types.sinf, content, MP42.box(MP42.types.frma, frma), MP42.box(MP42.types.schm, schm), schi);
8217
8453
  }
8454
+ }, {
8455
+ key: "av01",
8456
+ value: function av01(track) {
8457
+ return MP42.box(MP42.types.av01, new Uint8Array([
8458
+ 0,
8459
+ 0,
8460
+ 0,
8461
+ 0,
8462
+ 0,
8463
+ 0,
8464
+ 0,
8465
+ 1,
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
+ 0,
8479
+ 0,
8480
+ 0,
8481
+ 0,
8482
+ track.width >> 8 & 255,
8483
+ track.width & 255,
8484
+ track.height >> 8 & 255,
8485
+ track.height & 255,
8486
+ 0,
8487
+ 72,
8488
+ 0,
8489
+ 0,
8490
+ 0,
8491
+ 72,
8492
+ 0,
8493
+ 0,
8494
+ 0,
8495
+ 0,
8496
+ 0,
8497
+ 0,
8498
+ 0,
8499
+ 1,
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
+ 0,
8530
+ 0,
8531
+ 0,
8532
+ 0,
8533
+ 24,
8534
+ 17,
8535
+ 17
8536
+ ]), track.av1C, track.colr);
8537
+ }
8218
8538
  }, {
8219
8539
  key: "avc1hev1",
8220
8540
  value: function avc1hev1(track) {
@@ -8585,6 +8905,53 @@
8585
8905
  )));
8586
8906
  return esds2;
8587
8907
  }
8908
+ }, {
8909
+ key: "opus",
8910
+ value: function opus(track) {
8911
+ var opusAudioDescription = new Uint8Array([
8912
+ 0,
8913
+ 0,
8914
+ 0,
8915
+ 0,
8916
+ 0,
8917
+ 0,
8918
+ 0,
8919
+ 1,
8920
+ 0,
8921
+ 0,
8922
+ 0,
8923
+ 0,
8924
+ 0,
8925
+ 0,
8926
+ 0,
8927
+ 0,
8928
+ 0,
8929
+ track.channelCount,
8930
+ 0,
8931
+ 16,
8932
+ 0,
8933
+ 0,
8934
+ 0,
8935
+ 0,
8936
+ track.sampleRate >> 8 & 255,
8937
+ track.sampleRate & 255,
8938
+ 0,
8939
+ 0
8940
+ ]);
8941
+ var opusSpecificConfig = track.config.length ? MP42.dOps(track) : [];
8942
+ return MP42.box(MP42.types.Opus, opusAudioDescription, opusSpecificConfig);
8943
+ }
8944
+ }, {
8945
+ key: "dOps",
8946
+ value: function dOps(track) {
8947
+ if (track.config) {
8948
+ track.config[4] = track.sampleRate >>> 24 & 255;
8949
+ track.config[5] = track.sampleRate >>> 16 & 255;
8950
+ track.config[6] = track.sampleRate >>> 8 & 255;
8951
+ track.config[7] = track.sampleRate & 255;
8952
+ return MP42.box(MP42.types.dOps, track.config);
8953
+ }
8954
+ }
8588
8955
  }, {
8589
8956
  key: "mvex",
8590
8957
  value: function mvex(tracks) {
@@ -9187,7 +9554,7 @@
9187
9554
  }]);
9188
9555
  return MP42;
9189
9556
  }();
9190
- _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) {
9557
+ _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) {
9191
9558
  p[c] = [c.charCodeAt(0), c.charCodeAt(1), c.charCodeAt(2), c.charCodeAt(3)];
9192
9559
  return p;
9193
9560
  }, /* @__PURE__ */ Object.create(null)));
@@ -9522,30 +9889,46 @@
9522
9889
  };
9523
9890
  }
9524
9891
  var samples = track.samples;
9892
+ var isAV01 = /av01/.test(track.codec);
9525
9893
  var mdatSize = 0;
9526
- samples.forEach(function(s) {
9527
- mdatSize += s.units.reduce(function(t, c) {
9528
- return t + c.byteLength;
9529
- }, 0);
9530
- mdatSize += s.units.length * 4;
9531
- });
9532
- var mdata = new Uint8Array(mdatSize);
9533
- var mdatView = new DataView(mdata.buffer);
9534
- var _loop = function _loop2(_offset, _sample) {
9535
- _sample = samples[i];
9536
- var sampleSize = 0;
9537
- _sample.units.forEach(function(u) {
9538
- mdatView.setUint32(_offset, u.byteLength);
9539
- _offset += 4;
9540
- mdata.set(u, _offset);
9541
- _offset += u.byteLength;
9542
- sampleSize += 4 + u.byteLength;
9894
+ if (isAV01) {
9895
+ samples.forEach(function(s) {
9896
+ mdatSize += s.data.byteLength;
9543
9897
  });
9544
- _sample.size = sampleSize;
9545
- offset = _offset, sample = _sample;
9546
- };
9547
- for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
9548
- _loop(offset, sample);
9898
+ } else {
9899
+ samples.forEach(function(s) {
9900
+ mdatSize += s.units.reduce(function(t, c) {
9901
+ return t + c.byteLength;
9902
+ }, 0);
9903
+ mdatSize += s.units.length * 4;
9904
+ });
9905
+ }
9906
+ var mdata = new Uint8Array(mdatSize);
9907
+ if (isAV01) {
9908
+ for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
9909
+ sample = samples[i];
9910
+ mdata.set(sample.data, offset);
9911
+ sample.size = sample.data.byteLength;
9912
+ offset += sample.size;
9913
+ }
9914
+ } else {
9915
+ var mdatView = new DataView(mdata.buffer);
9916
+ var _loop = function _loop2(_offset2, _sample2) {
9917
+ _sample2 = samples[_i];
9918
+ var sampleSize = 0;
9919
+ _sample2.units.forEach(function(u) {
9920
+ mdatView.setUint32(_offset2, u.byteLength);
9921
+ _offset2 += 4;
9922
+ mdata.set(u, _offset2);
9923
+ _offset2 += u.byteLength;
9924
+ sampleSize += 4 + u.byteLength;
9925
+ });
9926
+ _sample2.size = sampleSize;
9927
+ _offset = _offset2, _sample = _sample2;
9928
+ };
9929
+ for (var _i = 0, _l = samples.length, _offset = 0, _sample; _i < _l; _i++) {
9930
+ _loop(_offset, _sample);
9931
+ }
9549
9932
  }
9550
9933
  var mdat = MP4.mdat(mdata);
9551
9934
  var moof = MP4.moof([track]);
@@ -9575,6 +9958,55 @@
9575
9958
  }]);
9576
9959
  return FMP4Remuxer2;
9577
9960
  }();
9961
+ var TransferCost = /* @__PURE__ */ function() {
9962
+ function TransferCost2() {
9963
+ _classCallCheck$4(this, TransferCost2);
9964
+ _defineProperty$3(this, "_ttfb", 0);
9965
+ _defineProperty$3(this, "_demuxStart", 0);
9966
+ _defineProperty$3(this, "_demuxEnd", 0);
9967
+ _defineProperty$3(this, "_demuxCost", 0);
9968
+ _defineProperty$3(this, "_remuxStart", 0);
9969
+ _defineProperty$3(this, "_remuxEnd", 0);
9970
+ _defineProperty$3(this, "_remuxCost", 0);
9971
+ _defineProperty$3(this, "_appendStart", 0);
9972
+ _defineProperty$3(this, "_appendEnd", 0);
9973
+ _defineProperty$3(this, "_appendCost", 0);
9974
+ }
9975
+ _createClass$4(TransferCost2, [{
9976
+ key: "set",
9977
+ value: function set(event, value) {
9978
+ this["_".concat(event)] = value;
9979
+ }
9980
+ }, {
9981
+ key: "start",
9982
+ value: function start(event) {
9983
+ this["_".concat(event, "Start")] = Date.now();
9984
+ }
9985
+ }, {
9986
+ key: "end",
9987
+ value: function end(event) {
9988
+ this["_".concat(event, "End")] = Date.now();
9989
+ this["_".concat(event, "Cost")] = this["_".concat(event, "Cost")] + (this["_".concat(event, "End")] - this["_".concat(event, "Start")]);
9990
+ }
9991
+ }, {
9992
+ key: "transferCost",
9993
+ get: function get() {
9994
+ return {
9995
+ ttfbCost: this._ttfb,
9996
+ demuxCost: this._demuxCost,
9997
+ remuxCost: this._remuxCost,
9998
+ appendCost: this._appendCost
9999
+ };
10000
+ }
10001
+ }]);
10002
+ return TransferCost2;
10003
+ }();
10004
+ var TRANSFER_EVENT = {
10005
+ TTFB: "ttfb",
10006
+ DEMUX: "demux",
10007
+ REMUX: "remux",
10008
+ APPEND: "append"
10009
+ };
9578
10010
  var logger$1 = new Logger$2("BufferService");
9579
10011
  var BufferService = /* @__PURE__ */ function() {
9580
10012
  function BufferService2(flv, softVideo) {
@@ -9662,7 +10094,8 @@
9662
10094
  this._contiguous = false;
9663
10095
  this._sourceCreated = false;
9664
10096
  this._initSegmentId = "";
9665
- case 11:
10097
+ this.resetSeamlessSwitchStats();
10098
+ case 12:
9666
10099
  case "end":
9667
10100
  return _context.stop();
9668
10101
  }
@@ -9673,6 +10106,15 @@
9673
10106
  }
9674
10107
  return reset;
9675
10108
  }()
10109
+ }, {
10110
+ key: "resetSeamlessSwitchStats",
10111
+ value: function resetSeamlessSwitchStats() {
10112
+ this.seamlessLoadingSwitch = null;
10113
+ this.seamlessLoadingSwitching = false;
10114
+ if (this._demuxer) {
10115
+ this._demuxer.seamlessLoadingSwitching = false;
10116
+ }
10117
+ }
9676
10118
  }, {
9677
10119
  key: "endOfStream",
9678
10120
  value: function() {
@@ -9778,32 +10220,56 @@
9778
10220
  key: "appendBuffer",
9779
10221
  value: function() {
9780
10222
  var _appendBuffer = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee5(chunk) {
9781
- var demuxer, videoTrack, audioTrack, metadataTrack, videoExist, audioExist, duration, track, videoType, audioType, mse, newId, remuxResult, p;
10223
+ var _this = this;
10224
+ var switchingNoReset, demuxer, videoTrack, audioTrack, metadataTrack, idx, videoExist, audioExist, duration, track, videoType, audioType, mse, afterAppend, newId, remuxResult, p;
9782
10225
  return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
9783
10226
  while (1)
9784
10227
  switch (_context5.prev = _context5.next) {
9785
10228
  case 0:
10229
+ switchingNoReset = false;
9786
10230
  if (this._cachedBuffer) {
9787
10231
  chunk = concatUint8Array$1(this._cachedBuffer, chunk);
9788
10232
  this._cachedBuffer = null;
9789
10233
  }
9790
10234
  demuxer = this._demuxer;
9791
10235
  if (!(!chunk || !chunk.length || !demuxer)) {
9792
- _context5.next = 4;
10236
+ _context5.next = 5;
9793
10237
  break;
9794
10238
  }
9795
10239
  return _context5.abrupt("return");
9796
- case 4:
9797
- _context5.prev = 4;
9798
- demuxer.demuxAndFix(chunk, this._discontinuity, this._contiguous, this._demuxStartTime);
9799
- _context5.next = 11;
10240
+ case 5:
10241
+ _context5.prev = 5;
10242
+ this.flv._transferCost.start(TRANSFER_EVENT.DEMUX);
10243
+ demuxer.demuxAndFix(chunk, this.seamlessLoadingSwitching || this._discontinuity, this._contiguous, this._demuxStartTime, this.seamlessLoadingSwitching);
10244
+ this.seamlessLoadingSwitching = false;
10245
+ this.flv._transferCost.end(TRANSFER_EVENT.DEMUX);
10246
+ _context5.next = 15;
9800
10247
  break;
9801
- case 8:
9802
- _context5.prev = 8;
9803
- _context5.t0 = _context5["catch"](4);
10248
+ case 12:
10249
+ _context5.prev = 12;
10250
+ _context5.t0 = _context5["catch"](5);
9804
10251
  throw new StreamingError(ERR.DEMUX, ERR.SUB_TYPES.FLV, _context5.t0);
9805
- case 11:
10252
+ case 15:
9806
10253
  videoTrack = demuxer.videoTrack, audioTrack = demuxer.audioTrack, metadataTrack = demuxer.metadataTrack;
10254
+ if (!this.seamlessLoadingSwitch) {
10255
+ _context5.next = 25;
10256
+ break;
10257
+ }
10258
+ idx = videoTrack.samples.findIndex(function(sample) {
10259
+ return sample.originDts === videoTrack.lastKeyFrameDts;
10260
+ });
10261
+ if (!(idx >= 0)) {
10262
+ _context5.next = 25;
10263
+ break;
10264
+ }
10265
+ videoTrack.samples.splice(idx);
10266
+ _context5.next = 22;
10267
+ return this.seamlessLoadingSwitch();
10268
+ case 22:
10269
+ this.seamlessLoadingSwitch = null;
10270
+ chunk = null;
10271
+ switchingNoReset = true;
10272
+ case 25:
9807
10273
  videoExist = videoTrack.exist();
9808
10274
  audioExist = audioTrack.exist();
9809
10275
  if (this._opts.onlyAudio) {
@@ -9815,7 +10281,7 @@
9815
10281
  audioTrack.present = false;
9816
10282
  }
9817
10283
  if (!(!videoExist && videoTrack.present || !audioExist && audioTrack.present)) {
9818
- _context5.next = 29;
10284
+ _context5.next = 42;
9819
10285
  break;
9820
10286
  }
9821
10287
  duration = 0;
@@ -9824,7 +10290,7 @@
9824
10290
  duration = (track.samples[track.samples.length - 1].originPts - track.samples[0].originPts) / track.timescale * 1e3;
9825
10291
  }
9826
10292
  if (!(duration > this._opts.analyzeDuration)) {
9827
- _context5.next = 27;
10293
+ _context5.next = 40;
9828
10294
  break;
9829
10295
  }
9830
10296
  logger$1.warn("analyze duration exceeded, ".concat(duration, "ms"), track);
@@ -9833,19 +10299,28 @@
9833
10299
  this.flv.emit(EVENT.ANALYZE_DURATION_EXCEEDED, {
9834
10300
  duration
9835
10301
  });
9836
- _context5.next = 29;
10302
+ _context5.next = 42;
9837
10303
  break;
9838
- case 27:
10304
+ case 40:
9839
10305
  this._cachedBuffer = chunk;
9840
10306
  return _context5.abrupt("return");
9841
- case 29:
10307
+ case 42:
9842
10308
  videoType = videoTrack.type;
9843
10309
  audioType = audioTrack.type;
9844
10310
  this._fireEvents(videoTrack, audioTrack, metadataTrack);
9845
- this._discontinuity = false;
9846
- this._contiguous = true;
9847
- this._demuxStartTime = 0;
10311
+ if (!switchingNoReset) {
10312
+ this._discontinuity = false;
10313
+ this._contiguous = true;
10314
+ this._demuxStartTime = 0;
10315
+ }
9848
10316
  mse = this._mse;
10317
+ afterAppend = function afterAppend2() {
10318
+ var _this$flv;
10319
+ if ((_this$flv = _this.flv) !== null && _this$flv !== void 0 && _this$flv.emit) {
10320
+ var _this$flv2;
10321
+ (_this$flv2 = _this.flv) === null || _this$flv2 === void 0 ? void 0 : _this$flv2.emit(EVENT.APPEND_BUFFER, {});
10322
+ }
10323
+ };
9849
10324
  this.flv.emit(EVENT.DEMUXED_TRACK, {
9850
10325
  videoTrack
9851
10326
  });
@@ -9856,16 +10331,16 @@
9856
10331
  this._emitMetaParsedEvent(videoTrack, audioTrack);
9857
10332
  }
9858
10333
  if (!mse) {
9859
- _context5.next = 66;
10334
+ _context5.next = 81;
9860
10335
  break;
9861
10336
  }
9862
10337
  if (this._sourceCreated) {
9863
- _context5.next = 47;
10338
+ _context5.next = 59;
9864
10339
  break;
9865
10340
  }
9866
- _context5.next = 43;
10341
+ _context5.next = 55;
9867
10342
  return mse.open();
9868
- case 43:
10343
+ case 55:
9869
10344
  if (videoExist) {
9870
10345
  logger$1.log("codec: video/mp4;codecs=".concat(videoTrack.codec));
9871
10346
  mse.createSource(videoType, "video/mp4;codecs=".concat(videoTrack.codec));
@@ -9876,26 +10351,28 @@
9876
10351
  }
9877
10352
  this._sourceCreated = true;
9878
10353
  this.flv.emit(EVENT.SOURCEBUFFER_CREATED);
9879
- case 47:
9880
- _context5.prev = 47;
10354
+ case 59:
10355
+ _context5.prev = 59;
9881
10356
  if (this._needInitSegment && !this._opts.mseLowLatency) {
9882
10357
  videoTrack.duration = this._opts.durationForMSELowLatencyOff * videoTrack.timescale;
9883
10358
  audioTrack.duration = this._opts.durationForMSELowLatencyOff * audioExist.timescale;
9884
10359
  }
10360
+ this.flv._transferCost.start(TRANSFER_EVENT.REMUX);
9885
10361
  remuxResult = this._remuxer.remux(this._needInitSegment);
9886
- _context5.next = 55;
10362
+ this.flv._transferCost.end(TRANSFER_EVENT.REMUX);
10363
+ _context5.next = 69;
9887
10364
  break;
9888
- case 52:
9889
- _context5.prev = 52;
9890
- _context5.t1 = _context5["catch"](47);
10365
+ case 66:
10366
+ _context5.prev = 66;
10367
+ _context5.t1 = _context5["catch"](59);
9891
10368
  throw new StreamingError(ERR.REMUX, ERR.SUB_TYPES.FMP4, _context5.t1);
9892
- case 55:
10369
+ case 69:
9893
10370
  if (!(this._needInitSegment && !remuxResult.videoInitSegment && !remuxResult.audioInitSegment)) {
9894
- _context5.next = 57;
10371
+ _context5.next = 71;
9895
10372
  break;
9896
10373
  }
9897
10374
  return _context5.abrupt("return");
9898
- case 57:
10375
+ case 71:
9899
10376
  this._needInitSegment = false;
9900
10377
  p = [];
9901
10378
  if (remuxResult.videoInitSegment)
@@ -9906,16 +10383,21 @@
9906
10383
  p.push(mse.append(videoType, remuxResult.videoSegment));
9907
10384
  if (remuxResult.audioSegment)
9908
10385
  p.push(mse.append(audioType, remuxResult.audioSegment));
9909
- return _context5.abrupt("return", Promise.all(p));
9910
- case 66:
10386
+ this.flv._transferCost.start(TRANSFER_EVENT.APPEND);
10387
+ return _context5.abrupt("return", Promise.all(p).then(afterAppend).then(function() {
10388
+ _this.flv._transferCost.end(TRANSFER_EVENT.APPEND);
10389
+ afterAppend();
10390
+ }));
10391
+ case 81:
9911
10392
  if (this._softVideo) {
9912
10393
  this._softVideo.appendBuffer(videoTrack, audioTrack);
10394
+ afterAppend();
9913
10395
  }
9914
- case 67:
10396
+ case 82:
9915
10397
  case "end":
9916
10398
  return _context5.stop();
9917
10399
  }
9918
- }, _callee5, this, [[4, 8], [47, 52]]);
10400
+ }, _callee5, this, [[5, 12], [59, 66]]);
9919
10401
  }));
9920
10402
  function appendBuffer(_x2) {
9921
10403
  return _appendBuffer.apply(this, arguments);
@@ -9926,7 +10408,7 @@
9926
10408
  key: "evictBuffer",
9927
10409
  value: function() {
9928
10410
  var _evictBuffer = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee6(bufferBehind) {
9929
- var _this = this;
10411
+ var _this2 = this;
9930
10412
  var media, currentTime, removeEnd, start;
9931
10413
  return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
9932
10414
  while (1)
@@ -9955,7 +10437,7 @@
9955
10437
  return _context6.abrupt("return");
9956
10438
  case 10:
9957
10439
  return _context6.abrupt("return", this._mse.clearBuffer(0, removeEnd).then(function() {
9958
- return _this.flv.emit(EVENT.REMOVE_BUFFER, {
10440
+ return _this2.flv.emit(EVENT.REMOVE_BUFFER, {
9959
10441
  removeEnd
9960
10442
  });
9961
10443
  }));
@@ -10005,16 +10487,16 @@
10005
10487
  }, {
10006
10488
  key: "_fireEvents",
10007
10489
  value: function _fireEvents(videoTrack, audioTrack, metadataTrack) {
10008
- var _this2 = this;
10009
- logger$1.debug(videoTrack.samples, audioTrack.samples);
10490
+ var _this3 = this;
10491
+ logger$1.debug("videoTrack samples count: ".concat(videoTrack.samples.length, ", audioTrack samples count: ").concat(audioTrack.samples.length));
10010
10492
  metadataTrack.flvScriptSamples.forEach(function(sample) {
10011
- _this2.flv.emit(EVENT.FLV_SCRIPT_DATA, sample);
10493
+ _this3.flv.emit(EVENT.FLV_SCRIPT_DATA, sample);
10012
10494
  logger$1.debug("flvScriptData", sample);
10013
10495
  });
10014
10496
  videoTrack.samples.forEach(function(sample) {
10015
10497
  if (sample.keyframe) {
10016
- _this2.flv.emit(EVENT.KEYFRAME, {
10017
- pts: sample.pts
10498
+ _this3.flv.emit(EVENT.KEYFRAME, {
10499
+ pts: sample.originPts
10018
10500
  });
10019
10501
  }
10020
10502
  });
@@ -10032,7 +10514,7 @@
10032
10514
  break;
10033
10515
  }
10034
10516
  if (type)
10035
- _this2.flv.emit(EVENT.STREAM_EXCEPTION, _objectSpread2$2(_objectSpread2$2({}, warn), {}, {
10517
+ _this3.flv.emit(EVENT.STREAM_EXCEPTION, _objectSpread2$2(_objectSpread2$2({}, warn), {}, {
10036
10518
  type
10037
10519
  }));
10038
10520
  logger$1.warn("video exception", warn);
@@ -10051,13 +10533,13 @@
10051
10533
  break;
10052
10534
  }
10053
10535
  if (type)
10054
- _this2.flv.emit(EVENT.STREAM_EXCEPTION, _objectSpread2$2(_objectSpread2$2({}, warn), {}, {
10536
+ _this3.flv.emit(EVENT.STREAM_EXCEPTION, _objectSpread2$2(_objectSpread2$2({}, warn), {}, {
10055
10537
  type
10056
10538
  }));
10057
10539
  logger$1.warn("audio exception", warn);
10058
10540
  });
10059
10541
  metadataTrack.seiSamples.forEach(function(sei) {
10060
- _this2.flv.emit(EVENT.SEI, _objectSpread2$2(_objectSpread2$2({}, sei), {}, {
10542
+ _this3.flv.emit(EVENT.SEI, _objectSpread2$2(_objectSpread2$2({}, sei), {}, {
10061
10543
  sei: {
10062
10544
  code: sei.data.type,
10063
10545
  content: sei.data.payload,
@@ -10092,7 +10574,8 @@
10092
10574
  durationForMSELowLatencyOff: 6,
10093
10575
  chunkCountForSpeed: 50,
10094
10576
  skipChunkSize: 1e3,
10095
- longtimeNoReceived: 3e3
10577
+ longtimeNoReceived: 3e3,
10578
+ enableStartGapJump: true
10096
10579
  }, opts);
10097
10580
  if (ret.isLive) {
10098
10581
  if (ret.preloadTime) {
@@ -10160,7 +10643,7 @@
10160
10643
  _defineProperty$3(_assertThisInitialized$3(_this), "_acceptRanges", true);
10161
10644
  _defineProperty$3(_assertThisInitialized$3(_this), "_onProgress", /* @__PURE__ */ function() {
10162
10645
  var _ref2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee(chunk, done, _ref, response) {
10163
- var startTime, endTime, st, firstByteTime, _this$_mediaLoader, headers, _this$_bufferService, remaining, maxReaderInterval;
10646
+ var startTime, endTime, st, firstByteTime, _this$_mediaLoader, headers, elapsed, _this$_bufferService, remaining, maxReaderInterval;
10164
10647
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
10165
10648
  while (1)
10166
10649
  switch (_context.prev = _context.next) {
@@ -10168,7 +10651,7 @@
10168
10651
  startTime = _ref.startTime, endTime = _ref.endTime, st = _ref.st, firstByteTime = _ref.firstByteTime;
10169
10652
  _this._loading = !done;
10170
10653
  if (_this._firstProgressEmit) {
10171
- _context.next = 11;
10654
+ _context.next = 13;
10172
10655
  break;
10173
10656
  }
10174
10657
  if (_this.media) {
@@ -10179,49 +10662,51 @@
10179
10662
  return _context.abrupt("return");
10180
10663
  case 6:
10181
10664
  headers = response.headers;
10665
+ elapsed = st ? firstByteTime - st : endTime - startTime;
10182
10666
  _this.emit(EVENT.TTFB, {
10183
10667
  url: _this._opts.url,
10184
10668
  responseUrl: response.url,
10185
- elapsed: st ? firstByteTime - st : endTime - startTime
10669
+ elapsed
10186
10670
  });
10187
10671
  _this.emit(EVENT.LOAD_RESPONSE_HEADERS, {
10188
10672
  headers
10189
10673
  });
10674
+ _this._transferCost.set(TRANSFER_EVENT.TTFB, elapsed);
10190
10675
  _this._acceptRanges = !!(headers !== null && headers !== void 0 && headers.get("Accept-Ranges")) || !!(headers !== null && headers !== void 0 && headers.get("Content-Range"));
10191
10676
  _this._firstProgressEmit = true;
10192
- case 11:
10677
+ case 13:
10193
10678
  if (_this._bufferService) {
10194
- _context.next = 13;
10679
+ _context.next = 15;
10195
10680
  break;
10196
10681
  }
10197
10682
  return _context.abrupt("return");
10198
- case 13:
10683
+ case 15:
10199
10684
  clearTimeout(_this._maxChunkWaitTimer);
10200
10685
  _this._bandwidthService.addChunkRecord(chunk === null || chunk === void 0 ? void 0 : chunk.byteLength, endTime - startTime);
10201
- _context.prev = 15;
10202
- _context.next = 18;
10686
+ _context.prev = 17;
10687
+ _context.next = 20;
10203
10688
  return _this._bufferService.appendBuffer(chunk);
10204
- case 18:
10689
+ case 20:
10205
10690
  (_this$_bufferService = _this._bufferService) === null || _this$_bufferService === void 0 ? void 0 : _this$_bufferService.evictBuffer(_this._opts.bufferBehind);
10206
- _context.next = 31;
10691
+ _context.next = 33;
10207
10692
  break;
10208
- case 21:
10209
- _context.prev = 21;
10210
- _context.t0 = _context["catch"](15);
10693
+ case 23:
10694
+ _context.prev = 23;
10695
+ _context.t0 = _context["catch"](17);
10211
10696
  if (!(!_this.isLive && _this._bufferService.isFull())) {
10212
- _context.next = 30;
10697
+ _context.next = 32;
10213
10698
  break;
10214
10699
  }
10215
- _context.next = 26;
10700
+ _context.next = 28;
10216
10701
  return _this._mediaLoader.cancel();
10217
- case 26:
10702
+ case 28:
10218
10703
  _this._loading = false;
10219
10704
  remaining = _this.bufferInfo().remaining;
10220
10705
  _this._opts.preloadTime = parseInt(remaining) / 2;
10221
10706
  return _context.abrupt("return");
10222
- case 30:
10707
+ case 32:
10223
10708
  return _context.abrupt("return", _this._emitError(StreamingError.create(_context.t0)));
10224
- case 31:
10709
+ case 33:
10225
10710
  if (_this._urlSwitching) {
10226
10711
  _this._urlSwitching = false;
10227
10712
  _this.emit(EVENT.SWITCH_URL_SUCCESS, {
@@ -10233,7 +10718,7 @@
10233
10718
  _this._tick();
10234
10719
  }
10235
10720
  if (!(done && !_this.media.seeking)) {
10236
- _context.next = 38;
10721
+ _context.next = 40;
10237
10722
  break;
10238
10723
  }
10239
10724
  _this.emit(EVENT.LOAD_COMPLETE);
@@ -10242,13 +10727,13 @@
10242
10727
  _this._end();
10243
10728
  }
10244
10729
  return _context.abrupt("return");
10245
- case 38:
10730
+ case 40:
10246
10731
  if (_this.isLive) {
10247
- _context.next = 40;
10732
+ _context.next = 42;
10248
10733
  break;
10249
10734
  }
10250
10735
  return _context.abrupt("return");
10251
- case 40:
10736
+ case 42:
10252
10737
  maxReaderInterval = _this._opts.maxReaderInterval;
10253
10738
  if (maxReaderInterval && _this._firstProgressEmit) {
10254
10739
  clearTimeout(_this._maxChunkWaitTimer);
@@ -10262,11 +10747,11 @@
10262
10747
  _this._end();
10263
10748
  }, maxReaderInterval);
10264
10749
  }
10265
- case 42:
10750
+ case 44:
10266
10751
  case "end":
10267
10752
  return _context.stop();
10268
10753
  }
10269
- }, _callee, null, [[15, 21]]);
10754
+ }, _callee, null, [[17, 23]]);
10270
10755
  }));
10271
10756
  return function(_x, _x2, _x3, _x4) {
10272
10757
  return _ref2.apply(this, arguments);
@@ -10299,19 +10784,19 @@
10299
10784
  if (bufferEnd < MAX_HOLE || !media.readyState)
10300
10785
  return;
10301
10786
  var opts = _this._opts;
10302
- if (isMediaPlaying(media)) {
10787
+ if (isMediaPlaying(media) && media.currentTime) {
10303
10788
  if (_this._gapService) {
10304
10789
  _this._gapService.do(media, opts.maxJumpDistance, _this.isLive, 3);
10305
10790
  }
10306
10791
  } else {
10307
- if (!media.currentTime && _this._gapService) {
10792
+ if (!media.currentTime && _this._gapService && opts.enableStartGapJump) {
10308
10793
  var gapJump = _this._opts.mseLowLatency || _this._opts.mseLowLatency === false && _this.bufferInfo(MAX_START_GAP).nextStart;
10309
10794
  if (gapJump) {
10310
10795
  _this._gapService.do(media, opts.maxJumpDistance, _this.isLive, 3);
10311
10796
  }
10312
10797
  return;
10313
10798
  }
10314
- if (opts.isLive && media.readyState === 4 && bufferEnd > opts.disconnectTime) {
10799
+ if (opts.isLive && media.readyState === 4 && bufferEnd - media.currentTime > opts.disconnectTime) {
10315
10800
  _this.disconnect();
10316
10801
  }
10317
10802
  }
@@ -10460,6 +10945,7 @@
10460
10945
  responseType: "arraybuffer"
10461
10946
  }));
10462
10947
  _this._disconnectRetryCount = _this._opts.disconnectRetryCount;
10948
+ _this._transferCost = new TransferCost();
10463
10949
  _this._bufferService = new BufferService(_assertThisInitialized$3(_this), _this._opts.softDecode ? _this.media : void 0, _this._opts);
10464
10950
  _this._seiService = new SeiService(_assertThisInitialized$3(_this));
10465
10951
  _this._bandwidthService = new BandwidthService({
@@ -10483,7 +10969,7 @@
10483
10969
  _createClass$4(Flv2, [{
10484
10970
  key: "version",
10485
10971
  get: function get() {
10486
- return "3.0.19-rc.0";
10972
+ return "3.0.20-rc.6";
10487
10973
  }
10488
10974
  }, {
10489
10975
  key: "isLive",
@@ -10599,9 +11085,9 @@
10599
11085
  return this._clear();
10600
11086
  case 8:
10601
11087
  setTimeout(function() {
11088
+ _this2._seamlessSwitching = true;
10602
11089
  _this2._loadData(_this2._opts.url);
10603
11090
  _this2._bufferService.seamlessSwitch();
10604
- _this2._seamlessSwitching = true;
10605
11091
  });
10606
11092
  _context5.next = 13;
10607
11093
  break;
@@ -10625,50 +11111,82 @@
10625
11111
  }, {
10626
11112
  key: "disconnect",
10627
11113
  value: function disconnect() {
11114
+ var _this$_bufferService4;
10628
11115
  logger.debug("disconnect!");
11116
+ (_this$_bufferService4 = this._bufferService) === null || _this$_bufferService4 === void 0 ? void 0 : _this$_bufferService4.resetSeamlessSwitchStats();
10629
11117
  return this._clear();
10630
11118
  }
10631
11119
  }, {
10632
11120
  key: "switchURL",
10633
11121
  value: function() {
10634
- var _switchURL = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee6(url, seamless) {
11122
+ var _switchURL = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee7(url, seamless) {
10635
11123
  var _this3 = this;
10636
- return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
11124
+ return _regeneratorRuntime$1().wrap(function _callee7$(_context7) {
10637
11125
  while (1)
10638
- switch (_context6.prev = _context6.next) {
11126
+ switch (_context7.prev = _context7.next) {
10639
11127
  case 0:
10640
11128
  if (this._bufferService) {
10641
- _context6.next = 2;
11129
+ _context7.next = 2;
10642
11130
  break;
10643
11131
  }
10644
- return _context6.abrupt("return");
11132
+ return _context7.abrupt("return");
10645
11133
  case 2:
10646
11134
  this._resetDisconnectCount();
11135
+ if (!(this._loading && seamless)) {
11136
+ _context7.next = 6;
11137
+ break;
11138
+ }
11139
+ this._bufferService.seamlessLoadingSwitch = /* @__PURE__ */ function() {
11140
+ var _ref5 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee6(pts) {
11141
+ return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
11142
+ while (1)
11143
+ switch (_context6.prev = _context6.next) {
11144
+ case 0:
11145
+ _context6.next = 2;
11146
+ return _this3._clear();
11147
+ case 2:
11148
+ _this3._bufferService.seamlessLoadingSwitching = true;
11149
+ _this3._urlSwitching = true;
11150
+ _this3._seamlessSwitching = true;
11151
+ _this3._bufferService.seamlessSwitch();
11152
+ _this3._loadData(url);
11153
+ case 7:
11154
+ case "end":
11155
+ return _context6.stop();
11156
+ }
11157
+ }, _callee6);
11158
+ }));
11159
+ return function(_x8) {
11160
+ return _ref5.apply(this, arguments);
11161
+ };
11162
+ }();
11163
+ return _context7.abrupt("return");
11164
+ case 6:
10647
11165
  if (!(!seamless || !this._opts.isLive)) {
10648
- _context6.next = 8;
11166
+ _context7.next = 11;
10649
11167
  break;
10650
11168
  }
10651
- _context6.next = 6;
11169
+ _context7.next = 9;
10652
11170
  return this.load(url);
10653
- case 6:
11171
+ case 9:
10654
11172
  this._urlSwitching = true;
10655
- return _context6.abrupt("return", this.media.play(true).catch(function() {
11173
+ return _context7.abrupt("return", this.media.play(true).catch(function() {
10656
11174
  }));
10657
- case 8:
10658
- _context6.next = 10;
11175
+ case 11:
11176
+ _context7.next = 13;
10659
11177
  return this._clear();
10660
- case 10:
11178
+ case 13:
10661
11179
  setTimeout(function() {
10662
11180
  _this3._urlSwitching = true;
10663
11181
  _this3._seamlessSwitching = true;
10664
11182
  _this3._loadData(url);
10665
11183
  _this3._bufferService.seamlessSwitch();
10666
11184
  });
10667
- case 11:
11185
+ case 14:
10668
11186
  case "end":
10669
- return _context6.stop();
11187
+ return _context7.stop();
10670
11188
  }
10671
- }, _callee6, this);
11189
+ }, _callee7, this);
10672
11190
  }));
10673
11191
  function switchURL(_x6, _x7) {
10674
11192
  return _switchURL.apply(this, arguments);
@@ -10678,16 +11196,16 @@
10678
11196
  }, {
10679
11197
  key: "destroy",
10680
11198
  value: function() {
10681
- var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee7() {
10682
- return _regeneratorRuntime$1().wrap(function _callee7$(_context7) {
11199
+ var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee8() {
11200
+ return _regeneratorRuntime$1().wrap(function _callee8$(_context8) {
10683
11201
  while (1)
10684
- switch (_context7.prev = _context7.next) {
11202
+ switch (_context8.prev = _context8.next) {
10685
11203
  case 0:
10686
11204
  if (this.media) {
10687
- _context7.next = 2;
11205
+ _context8.next = 2;
10688
11206
  break;
10689
11207
  }
10690
- return _context7.abrupt("return");
11208
+ return _context8.abrupt("return");
10691
11209
  case 2:
10692
11210
  this.removeAllListeners();
10693
11211
  this._seiService.reset();
@@ -10697,16 +11215,16 @@
10697
11215
  this.media.removeEventListener("timeupdate", this._onTimeupdate);
10698
11216
  this.media.removeEventListener("waiting", this._onWaiting);
10699
11217
  this.media.removeEventListener("progress", this._onBufferUpdate);
10700
- _context7.next = 12;
11218
+ _context8.next = 12;
10701
11219
  return Promise.all([this._clear(), this._bufferService.destroy()]);
10702
11220
  case 12:
10703
11221
  this.media = null;
10704
11222
  this._bufferService = null;
10705
11223
  case 14:
10706
11224
  case "end":
10707
- return _context7.stop();
11225
+ return _context8.stop();
10708
11226
  }
10709
- }, _callee7, this);
11227
+ }, _callee8, this);
10710
11228
  }));
10711
11229
  function destroy() {
10712
11230
  return _destroy.apply(this, arguments);
@@ -10735,26 +11253,26 @@
10735
11253
  }, {
10736
11254
  key: "_reset",
10737
11255
  value: function() {
10738
- var _reset2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee8() {
10739
- var reuseMse, _args8 = arguments;
10740
- return _regeneratorRuntime$1().wrap(function _callee8$(_context8) {
11256
+ var _reset2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee9() {
11257
+ var reuseMse, _args9 = arguments;
11258
+ return _regeneratorRuntime$1().wrap(function _callee9$(_context9) {
10741
11259
  while (1)
10742
- switch (_context8.prev = _context8.next) {
11260
+ switch (_context9.prev = _context9.next) {
10743
11261
  case 0:
10744
- reuseMse = _args8.length > 0 && _args8[0] !== void 0 ? _args8[0] : false;
11262
+ reuseMse = _args9.length > 0 && _args9[0] !== void 0 ? _args9[0] : false;
10745
11263
  this._seiService.reset();
10746
11264
  this._bandwidthService.reset();
10747
11265
  this._stats.reset();
10748
- _context8.next = 6;
11266
+ _context9.next = 6;
10749
11267
  return this._clear();
10750
11268
  case 6:
10751
- _context8.next = 8;
11269
+ _context9.next = 8;
10752
11270
  return this._bufferService.reset(reuseMse);
10753
11271
  case 8:
10754
11272
  case "end":
10755
- return _context8.stop();
11273
+ return _context9.stop();
10756
11274
  }
10757
- }, _callee8, this);
11275
+ }, _callee9, this);
10758
11276
  }));
10759
11277
  function _reset() {
10760
11278
  return _reset2.apply(this, arguments);
@@ -10764,17 +11282,17 @@
10764
11282
  }, {
10765
11283
  key: "_loadData",
10766
11284
  value: function() {
10767
- var _loadData2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee9(url, range) {
11285
+ var _loadData2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee10(url, range) {
10768
11286
  var finnalUrl;
10769
- return _regeneratorRuntime$1().wrap(function _callee9$(_context9) {
11287
+ return _regeneratorRuntime$1().wrap(function _callee10$(_context10) {
10770
11288
  while (1)
10771
- switch (_context9.prev = _context9.next) {
11289
+ switch (_context10.prev = _context10.next) {
10772
11290
  case 0:
10773
11291
  if (url)
10774
11292
  this._opts.url = url;
10775
11293
  finnalUrl = url = this._opts.url;
10776
11294
  if (url) {
10777
- _context9.next = 4;
11295
+ _context10.next = 4;
10778
11296
  break;
10779
11297
  }
10780
11298
  throw new Error("Source url is missing");
@@ -10789,34 +11307,34 @@
10789
11307
  });
10790
11308
  logger.debug("load data, loading:", this._loading, finnalUrl);
10791
11309
  if (!this._loading) {
10792
- _context9.next = 11;
11310
+ _context10.next = 11;
10793
11311
  break;
10794
11312
  }
10795
- _context9.next = 11;
11313
+ _context10.next = 11;
10796
11314
  return this._mediaLoader.cancel();
10797
11315
  case 11:
10798
11316
  this._loading = true;
10799
- _context9.prev = 12;
10800
- _context9.next = 15;
11317
+ _context10.prev = 12;
11318
+ _context10.next = 15;
10801
11319
  return this._mediaLoader.load({
10802
11320
  url: finnalUrl,
10803
11321
  range
10804
11322
  });
10805
11323
  case 15:
10806
- _context9.next = 21;
11324
+ _context10.next = 21;
10807
11325
  break;
10808
11326
  case 17:
10809
- _context9.prev = 17;
10810
- _context9.t0 = _context9["catch"](12);
11327
+ _context10.prev = 17;
11328
+ _context10.t0 = _context10["catch"](12);
10811
11329
  this._loading = false;
10812
- return _context9.abrupt("return", this._emitError(StreamingError.network(_context9.t0), false));
11330
+ return _context10.abrupt("return", this._emitError(StreamingError.network(_context10.t0), false));
10813
11331
  case 21:
10814
11332
  case "end":
10815
- return _context9.stop();
11333
+ return _context10.stop();
10816
11334
  }
10817
- }, _callee9, this, [[12, 17]]);
11335
+ }, _callee10, this, [[12, 17]]);
10818
11336
  }));
10819
- function _loadData(_x8, _x9) {
11337
+ function _loadData(_x9, _x10) {
10820
11338
  return _loadData2.apply(this, arguments);
10821
11339
  }
10822
11340
  return _loadData;
@@ -10824,16 +11342,16 @@
10824
11342
  }, {
10825
11343
  key: "_clear",
10826
11344
  value: function() {
10827
- var _clear2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee10() {
10828
- return _regeneratorRuntime$1().wrap(function _callee10$(_context10) {
11345
+ var _clear2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee11() {
11346
+ return _regeneratorRuntime$1().wrap(function _callee11$(_context11) {
10829
11347
  while (1)
10830
- switch (_context10.prev = _context10.next) {
11348
+ switch (_context11.prev = _context11.next) {
10831
11349
  case 0:
10832
11350
  if (!this._mediaLoader) {
10833
- _context10.next = 3;
11351
+ _context11.next = 3;
10834
11352
  break;
10835
11353
  }
10836
- _context10.next = 3;
11354
+ _context11.next = 3;
10837
11355
  return this._mediaLoader.cancel();
10838
11356
  case 3:
10839
11357
  clearTimeout(this._maxChunkWaitTimer);
@@ -10842,9 +11360,9 @@
10842
11360
  this._firstProgressEmit = false;
10843
11361
  case 7:
10844
11362
  case "end":
10845
- return _context10.stop();
11363
+ return _context11.stop();
10846
11364
  }
10847
- }, _callee10, this);
11365
+ }, _callee11, this);
10848
11366
  }));
10849
11367
  function _clear() {
10850
11368
  return _clear2.apply(this, arguments);
@@ -10931,9 +11449,13 @@
10931
11449
  _createClass$4(PluginExtension2, [{
10932
11450
  key: "_init",
10933
11451
  value: function _init() {
10934
- var _this$_opts2 = this._opts, media = _this$_opts2.media, preloadTime = _this$_opts2.preloadTime, innerDegrade = _this$_opts2.innerDegrade, decodeMode = _this$_opts2.decodeMode;
11452
+ 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;
10935
11453
  if (!media)
10936
11454
  return;
11455
+ if (!isLive && media.setPlayMode) {
11456
+ media.setPlayMode("VOD");
11457
+ return;
11458
+ }
10937
11459
  if (innerDegrade) {
10938
11460
  media.setAttribute("innerdegrade", innerDegrade);
10939
11461
  }
@@ -10971,6 +11493,7 @@
10971
11493
  args[_key] = arguments[_key];
10972
11494
  }
10973
11495
  _this = _super.call.apply(_super, [this].concat(args));
11496
+ _defineProperty$3(_assertThisInitialized$3(_this), "logger", logger);
10974
11497
  _defineProperty$3(_assertThisInitialized$3(_this), "flv", null);
10975
11498
  _defineProperty$3(_assertThisInitialized$3(_this), "pluginExtension", null);
10976
11499
  _defineProperty$3(_assertThisInitialized$3(_this), "getStats", function() {
@@ -11038,11 +11561,17 @@
11038
11561
  var _this$flv3;
11039
11562
  return (_this$flv3 = this.flv) === null || _this$flv3 === void 0 ? void 0 : _this$flv3.loader;
11040
11563
  }
11564
+ }, {
11565
+ key: "transferCost",
11566
+ get: function get() {
11567
+ return this.flv._transferCost.transferCost;
11568
+ }
11041
11569
  }, {
11042
11570
  key: "beforePlayerInit",
11043
11571
  value: function beforePlayerInit() {
11044
11572
  var _this2 = this;
11045
11573
  var config = this.player.config;
11574
+ var mediaElem = this.player.media || this.player.video;
11046
11575
  if (!config.url)
11047
11576
  return;
11048
11577
  if (this.flv)
@@ -11055,10 +11584,10 @@
11055
11584
  this.flv = new Flv(_objectSpread2$2({
11056
11585
  softDecode: this.softDecode,
11057
11586
  isLive: config.isLive,
11058
- media: this.player.video,
11587
+ media: mediaElem,
11059
11588
  preProcessUrl: function preProcessUrl(url, ext) {
11060
- var _this2$player$preProc, _this2$player;
11061
- 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)) || {
11589
+ var _this2$player, _this2$player$preProc;
11590
+ 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)) || {
11062
11591
  url,
11063
11592
  ext
11064
11593
  };
@@ -11077,7 +11606,8 @@
11077
11606
  }
11078
11607
  if (this.softDecode) {
11079
11608
  this.pluginExtension = new PluginExtension(_objectSpread2$2({
11080
- media: this.player.video
11609
+ media: this.player.video,
11610
+ isLive: config.isLive
11081
11611
  }, config.flv), this);
11082
11612
  this.player.forceDegradeToVideo = function() {
11083
11613
  var _this2$pluginExtensio;
@@ -11104,6 +11634,7 @@
11104
11634
  this._transCoreEvent(EVENT.LOAD_RETRY);
11105
11635
  this._transCoreEvent(EVENT.SOURCEBUFFER_CREATED);
11106
11636
  this._transCoreEvent(EVENT.ANALYZE_DURATION_EXCEEDED);
11637
+ this._transCoreEvent(EVENT.APPEND_BUFFER);
11107
11638
  this._transCoreEvent(EVENT.REMOVE_BUFFER);
11108
11639
  this._transCoreEvent(EVENT.BUFFEREOS);
11109
11640
  this._transCoreEvent(EVENT.KEYFRAME);