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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/esm/index.development.js +2267 -578
  2. package/esm/index.production.js +3 -3
  3. package/esm/veplayer.plugin.abr.development.js +71 -3
  4. package/esm/veplayer.plugin.abr.production.js +1 -1
  5. package/esm/veplayer.plugin.drm.development.js +71 -3
  6. package/esm/veplayer.plugin.drm.production.js +1 -1
  7. package/esm/veplayer.plugin.flv.development.js +729 -196
  8. package/esm/veplayer.plugin.flv.production.js +1 -1
  9. package/esm/veplayer.plugin.hls.development.js +1505 -378
  10. package/esm/veplayer.plugin.hls.production.js +1 -1
  11. package/esm/veplayer.plugin.mp4.development.js +73 -5
  12. package/esm/veplayer.plugin.mp4.production.js +1 -1
  13. package/esm/veplayer.plugin.rtm.development.js +213 -48
  14. package/esm/veplayer.plugin.rtm.production.js +1 -1
  15. package/esm/veplayer.plugin.shaka.development.js +72 -4
  16. package/esm/veplayer.plugin.shaka.production.js +1 -1
  17. package/package.json +1 -1
  18. package/umd/veplayer.plugin.abr.development.js +71 -3
  19. package/umd/veplayer.plugin.abr.production.js +1 -1
  20. package/umd/veplayer.plugin.drm.development.js +71 -3
  21. package/umd/veplayer.plugin.drm.production.js +1 -1
  22. package/umd/veplayer.plugin.flv.development.js +729 -196
  23. package/umd/veplayer.plugin.flv.production.js +1 -1
  24. package/umd/veplayer.plugin.hls.development.js +1472 -345
  25. package/umd/veplayer.plugin.hls.production.js +1 -1
  26. package/umd/veplayer.plugin.mp4.development.js +73 -5
  27. package/umd/veplayer.plugin.mp4.production.js +1 -1
  28. package/umd/veplayer.plugin.rtm.development.js +213 -48
  29. package/umd/veplayer.plugin.rtm.production.js +1 -1
  30. package/umd/veplayer.plugin.shaka.development.js +72 -4
  31. package/umd/veplayer.plugin.shaka.production.js +1 -1
@@ -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.21-rc.2";
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,16 @@
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",
5623
+ MP3: "mp3"
5537
5624
  };
5538
5625
  var WarningType = {
5539
5626
  LARGE_AV_SHIFT: "LARGE_AV_SHIFT",
@@ -5573,6 +5660,7 @@
5573
5660
  _defineProperty(this, "isVideoEncryption", false);
5574
5661
  _defineProperty(this, "isAudioEncryption", false);
5575
5662
  _defineProperty(this, "isVideo", true);
5663
+ _defineProperty(this, "lastKeyFrameDts", 0);
5576
5664
  _defineProperty(this, "kid", null);
5577
5665
  _defineProperty(this, "pssh", null);
5578
5666
  _defineProperty(this, "ext", void 0);
@@ -5615,6 +5703,9 @@
5615
5703
  }, {
5616
5704
  key: "exist",
5617
5705
  value: function exist() {
5706
+ if (/av01/.test(this.codec)) {
5707
+ return true;
5708
+ }
5618
5709
  return !!(this.pps.length && this.sps.length && this.codec);
5619
5710
  }
5620
5711
  }, {
@@ -5638,6 +5729,7 @@
5638
5729
  _defineProperty(this, "codecType", AudioCodecType.AAC);
5639
5730
  _defineProperty(this, "pid", -1);
5640
5731
  _defineProperty(this, "codec", "");
5732
+ _defineProperty(this, "container", "");
5641
5733
  _defineProperty(this, "sequenceNumber", 0);
5642
5734
  _defineProperty(this, "sampleDuration", 0);
5643
5735
  _defineProperty(this, "timescale", 0);
@@ -5678,7 +5770,7 @@
5678
5770
  }, {
5679
5771
  key: "exist",
5680
5772
  value: function exist() {
5681
- return !!(this.sampleRate && this.channelCount && this.codec && this.codecType === AudioCodecType.AAC);
5773
+ return !!(this.sampleRate && this.channelCount && (this.codec || this.container) && (this.codecType === AudioCodecType.AAC || this.codecType === AudioCodecType.G711PCMA || this.codecType === AudioCodecType.G711PCMU || this.codecType === AudioCodecType.OPUS || this.codecType === AudioCodecType.MP3));
5682
5774
  }
5683
5775
  }, {
5684
5776
  key: "hasSample",
@@ -5892,7 +5984,7 @@
5892
5984
  continue;
5893
5985
  }
5894
5986
  frameLength = (data[i + 3] & 3) << 11 | data[i + 4] << 3 | (data[i + 5] & 224) >> 5;
5895
- if (len - i < frameLength)
5987
+ if (!frameLength || len - i < frameLength)
5896
5988
  break;
5897
5989
  protectionSkipBytes = (~data[i + 1] & 1) * 2;
5898
5990
  frames.push({
@@ -6026,14 +6118,57 @@
6026
6118
  return AAC2;
6027
6119
  }();
6028
6120
  _defineProperty(AAC, "FREQ", [96e3, 88200, 64e3, 48e3, 44100, 32e3, 24e3, 22050, 16e3, 12e3, 11025, 8e3, 7350]);
6121
+ var OPUS = /* @__PURE__ */ function() {
6122
+ function OPUS2() {
6123
+ _classCallCheck$1(this, OPUS2);
6124
+ }
6125
+ _createClass$1(OPUS2, null, [{
6126
+ key: "getFrameDuration",
6127
+ value: function getFrameDuration(samples) {
6128
+ return 20;
6129
+ }
6130
+ }, {
6131
+ key: "parseHeaderPackets",
6132
+ value: function parseHeaderPackets(data) {
6133
+ if (!data.length)
6134
+ return;
6135
+ var dv = new DataView(data.buffer, data.byteOffset, data.byteLength);
6136
+ var magicSignature = "";
6137
+ for (var i = 0; i < 8; i++) {
6138
+ magicSignature += String.fromCodePoint(data[i]);
6139
+ }
6140
+ if (magicSignature !== "OpusHead") {
6141
+ throw new Error("Invalid Opus MagicSignature");
6142
+ }
6143
+ var channelCount = data[9];
6144
+ console.log("Pre-skip", data[10], data[11]);
6145
+ var sampleRate = dv.getUint32(12, true);
6146
+ var outputGain = dv.getInt16(16, true);
6147
+ if (!sampleRate)
6148
+ return;
6149
+ var codec = "opus";
6150
+ var originCodec = "opus";
6151
+ var config = new Uint8Array(data.buffer, data.byteOffset + 8, data.byteLength - 8);
6152
+ return {
6153
+ outputGain,
6154
+ sampleRate,
6155
+ channelCount,
6156
+ config,
6157
+ codec,
6158
+ originCodec
6159
+ };
6160
+ }
6161
+ }]);
6162
+ return OPUS2;
6163
+ }();
6029
6164
  var LARGE_AV_FIRST_FRAME_GAP = 500;
6030
6165
  var AUDIO_GAP_OVERLAP_THRESHOLD_COUNT = 3;
6031
6166
  var MAX_SILENT_FRAME_DURATION = 1e3;
6032
- var AUDIO_EXCETION_LOG_EMIT_DURATION = 5e3;
6167
+ var AUDIO_EXCEPTION_LOG_EMIT_DURATION = 5e3;
6033
6168
  var MAX_VIDEO_FRAME_DURATION = 1e3;
6034
6169
  var MAX_DTS_DELTA_WITH_NEXT_CHUNK = 200;
6035
- var VIDEO_EXCETION_LOG_EMIT_DURATION = 5e3;
6036
- var TRACK_BREACKED_CHECK_TIME = 5;
6170
+ var VIDEO_EXCEPTION_LOG_EMIT_DURATION = 5e3;
6171
+ var TRACK_BROKEN_CHECK_TIME = 5;
6037
6172
  var FlvFixer = /* @__PURE__ */ function() {
6038
6173
  function FlvFixer2(videoTrack, audioTrack, metadataTrack) {
6039
6174
  _classCallCheck$1(this, FlvFixer2);
@@ -6149,7 +6284,7 @@
6149
6284
  var firstSample = samples[0];
6150
6285
  var vDelta = this._videoNextDts - firstSample.dts;
6151
6286
  if (Math.abs(vDelta) > MAX_DTS_DELTA_WITH_NEXT_CHUNK) {
6152
- if (Math.abs(firstSample.dts - this._lastVideoExceptionChunkFirstDtsDot) > VIDEO_EXCETION_LOG_EMIT_DURATION) {
6287
+ if (Math.abs(firstSample.dts - this._lastVideoExceptionChunkFirstDtsDot) > VIDEO_EXCEPTION_LOG_EMIT_DURATION) {
6153
6288
  var _samples$;
6154
6289
  this._lastVideoExceptionChunkFirstDtsDot = firstSample.dts;
6155
6290
  videoTrack.warnings.push({
@@ -6160,7 +6295,7 @@
6160
6295
  sampleDuration: vDelta
6161
6296
  });
6162
6297
  }
6163
- if (this._videoTimestampBreak >= TRACK_BREACKED_CHECK_TIME) {
6298
+ if (this._videoTimestampBreak >= TRACK_BROKEN_CHECK_TIME) {
6164
6299
  this._videoNextDts = firstSample.dts;
6165
6300
  this._videoTimestampBreak = 0;
6166
6301
  } else {
@@ -6183,7 +6318,7 @@
6183
6318
  }
6184
6319
  if (sampleDuration > MAX_VIDEO_FRAME_DURATION || sampleDuration < 0) {
6185
6320
  this._videoTimestampBreak++;
6186
- if (Math.abs(dts - this._lastVideoExceptionLargeGapDot) > VIDEO_EXCETION_LOG_EMIT_DURATION) {
6321
+ if (Math.abs(dts - this._lastVideoExceptionLargeGapDot) > VIDEO_EXCEPTION_LOG_EMIT_DURATION) {
6187
6322
  this._lastVideoExceptionLargeGapDot = dts;
6188
6323
  videoTrack.warnings.push({
6189
6324
  type: WarningType.LARGE_VIDEO_GAP,
@@ -6264,10 +6399,27 @@
6264
6399
  key: "_doFixAudioInternal",
6265
6400
  value: function _doFixAudioInternal(audioTrack, samples, timescale) {
6266
6401
  if (!audioTrack.sampleDuration) {
6267
- audioTrack.sampleDuration = audioTrack.codecType === AudioCodecType.AAC ? AAC.getFrameDuration(audioTrack.timescale, timescale) : this._getG711Duration(audioTrack);
6402
+ switch (audioTrack.codecType) {
6403
+ case AudioCodecType.AAC: {
6404
+ audioTrack.sampleDuration = AAC.getFrameDuration(audioTrack.timescale, timescale);
6405
+ break;
6406
+ }
6407
+ case AudioCodecType.OPUS: {
6408
+ audioTrack.sampleDuration = OPUS.getFrameDuration(audioTrack.samples, timescale);
6409
+ break;
6410
+ }
6411
+ case AudioCodecType.G711PCMA:
6412
+ case AudioCodecType.G711PCMU: {
6413
+ audioTrack.sampleDuration = this._getG711Duration(audioTrack);
6414
+ break;
6415
+ }
6416
+ default:
6417
+ console.error("can't fix audio codecType:", audioTrack.codecType);
6418
+ break;
6419
+ }
6268
6420
  }
6269
6421
  var refSampleDuration = audioTrack.sampleDuration;
6270
- var sampleDurationInSampleRate = audioTrack.codecType === AudioCodecType.AAC ? 1024 : refSampleDuration * audioTrack.timescale / 1e3;
6422
+ var sampleDurationInSampleRate = audioTrack.codecType === AudioCodecType.OPUS ? 20 : audioTrack.codecType === AudioCodecType.AAC ? 1024 : refSampleDuration * audioTrack.timescale / 1e3;
6271
6423
  if (this._audioNextPts === void 0) {
6272
6424
  var samp0 = samples[0];
6273
6425
  this._audioNextPts = samp0.pts;
@@ -6276,7 +6428,7 @@
6276
6428
  var nextPts = this._audioNextPts;
6277
6429
  var sample = samples[i];
6278
6430
  var delta = sample.pts - nextPts;
6279
- if (i === 0 && this._audioTimestampBreak >= TRACK_BREACKED_CHECK_TIME && this._keyFrameInNextChunk) {
6431
+ if (i === 0 && this._audioTimestampBreak >= TRACK_BROKEN_CHECK_TIME && this._keyFrameInNextChunk) {
6280
6432
  nextPts = this._audioNextPts = sample.dts;
6281
6433
  delta = 0;
6282
6434
  this._audioTimestampBreak = 0;
@@ -6284,7 +6436,7 @@
6284
6436
  if (!this._audioTimestampBreak && delta >= AUDIO_GAP_OVERLAP_THRESHOLD_COUNT * refSampleDuration && delta <= MAX_SILENT_FRAME_DURATION && !isSafari) {
6285
6437
  var silentFrame = this._getSilentFrame(audioTrack) || samples[0].data.subarray();
6286
6438
  var count = Math.floor(delta / refSampleDuration);
6287
- if (Math.abs(sample.pts - this._lastAudioExceptionGapDot) > AUDIO_EXCETION_LOG_EMIT_DURATION) {
6439
+ if (Math.abs(sample.pts - this._lastAudioExceptionGapDot) > AUDIO_EXCEPTION_LOG_EMIT_DURATION) {
6288
6440
  this._lastAudioExceptionGapDot = sample.pts;
6289
6441
  audioTrack.warnings.push({
6290
6442
  type: WarningType.AUDIO_FILLED,
@@ -6304,7 +6456,7 @@
6304
6456
  }
6305
6457
  i--;
6306
6458
  } 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) {
6459
+ if (Math.abs(sample.pts - this._lastAudioExceptionOverlapDot) > AUDIO_EXCEPTION_LOG_EMIT_DURATION) {
6308
6460
  this._lastAudioExceptionOverlapDot = sample.pts;
6309
6461
  audioTrack.warnings.push({
6310
6462
  type: WarningType.AUDIO_DROPPED,
@@ -6319,7 +6471,7 @@
6319
6471
  } else {
6320
6472
  if (Math.abs(delta) > MAX_SILENT_FRAME_DURATION) {
6321
6473
  this._audioTimestampBreak++;
6322
- if (Math.abs(sample.pts - this._lastAudioExceptionLargeGapDot) > AUDIO_EXCETION_LOG_EMIT_DURATION) {
6474
+ if (Math.abs(sample.pts - this._lastAudioExceptionLargeGapDot) > AUDIO_EXCEPTION_LOG_EMIT_DURATION) {
6323
6475
  this._lastAudioExceptionLargeGapDot = sample.pts;
6324
6476
  audioTrack.warnings.push({
6325
6477
  type: WarningType.LARGE_AUDIO_GAP,
@@ -6332,8 +6484,15 @@
6332
6484
  });
6333
6485
  }
6334
6486
  }
6335
- sample.dts = sample.pts = nextPts;
6336
- sample.duration = sampleDurationInSampleRate;
6487
+ if (audioTrack.codecType === AudioCodecType.OPUS) {
6488
+ var lastSample = samples[samples.length - 1];
6489
+ if (lastSample) {
6490
+ lastSample.duration = sample.pts - lastSample.pts;
6491
+ }
6492
+ } else {
6493
+ sample.dts = sample.pts = nextPts;
6494
+ sample.duration = sampleDurationInSampleRate;
6495
+ }
6337
6496
  this._audioNextPts += refSampleDuration;
6338
6497
  }
6339
6498
  }
@@ -7292,6 +7451,13 @@
7292
7451
  }]);
7293
7452
  return AMF2;
7294
7453
  }();
7454
+ var FlvSoundFormat = {
7455
+ MP3: 2,
7456
+ G711A: 7,
7457
+ G711M: 8,
7458
+ AAC: 10,
7459
+ OPUS: 13
7460
+ };
7295
7461
  var logger$2 = new Logger$1("FlvDemuxer");
7296
7462
  var FlvDemuxer = /* @__PURE__ */ function() {
7297
7463
  function FlvDemuxer2(videoTrack, audioTrack, metadataTrack) {
@@ -7308,8 +7474,10 @@
7308
7474
  _createClass$1(FlvDemuxer2, [{
7309
7475
  key: "demux",
7310
7476
  value: function demux(data) {
7477
+ var _scriptDataObject$dat;
7311
7478
  var discontinuity = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
7312
7479
  var contiguous = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
7480
+ var seamlessLoadingSwitching = arguments.length > 3 ? arguments[3] : void 0;
7313
7481
  var audioTrack = this.audioTrack, videoTrack = this.videoTrack, metadataTrack = this.metadataTrack;
7314
7482
  if (discontinuity || !contiguous) {
7315
7483
  this._remainingData = null;
@@ -7367,6 +7535,8 @@
7367
7535
  if (tagType === 8) {
7368
7536
  this._parseAudio(bodyData, timestamp);
7369
7537
  } else if (tagType === 9) {
7538
+ if (seamlessLoadingSwitching)
7539
+ this.seamlessLoadingSwitching = true;
7370
7540
  this._parseVideo(bodyData, timestamp);
7371
7541
  } else if (tagType === 18) {
7372
7542
  this._parseScript(bodyData, timestamp);
@@ -7384,13 +7554,31 @@
7384
7554
  this._remainingData = data.subarray(offset);
7385
7555
  }
7386
7556
  audioTrack.formatTimescale = videoTrack.formatTimescale = videoTrack.timescale = metadataTrack.timescale = 1e3;
7387
- audioTrack.timescale = audioTrack.sampleRate || 0;
7557
+ audioTrack.timescale = audioTrack.codecType === AudioCodecType.OPUS ? 1e3 : audioTrack.sampleRate || 0;
7388
7558
  if (!audioTrack.exist() && audioTrack.hasSample()) {
7389
7559
  audioTrack.reset();
7390
7560
  }
7391
7561
  if (!videoTrack.exist() && videoTrack.hasSample()) {
7392
7562
  videoTrack.reset();
7393
7563
  }
7564
+ var scriptDataObject = metadataTrack.flvScriptSamples[metadataTrack.flvScriptSamples.length - 1];
7565
+ var metaData = scriptDataObject === null || scriptDataObject === void 0 ? void 0 : (_scriptDataObject$dat = scriptDataObject.data) === null || _scriptDataObject$dat === void 0 ? void 0 : _scriptDataObject$dat.onMetaData;
7566
+ if (metaData) {
7567
+ if (videoTrack !== null && videoTrack !== void 0 && videoTrack.exist()) {
7568
+ if (metaData.hasOwnProperty("duration")) {
7569
+ videoTrack.duration = metaData.duration * 1e3;
7570
+ }
7571
+ if (metaData.hasOwnProperty("width") && metaData.hasOwnProperty("height")) {
7572
+ videoTrack.width = metaData.width;
7573
+ videoTrack.height = metaData.height;
7574
+ }
7575
+ }
7576
+ if (audioTrack !== null && audioTrack !== void 0 && audioTrack.exist()) {
7577
+ if (metaData.hasOwnProperty("duration")) {
7578
+ audioTrack.duration = metaData.duration * 1e3;
7579
+ }
7580
+ }
7581
+ }
7394
7582
  return {
7395
7583
  videoTrack,
7396
7584
  audioTrack,
@@ -7409,8 +7597,8 @@
7409
7597
  }
7410
7598
  }, {
7411
7599
  key: "demuxAndFix",
7412
- value: function demuxAndFix(data, discontinuity, contiguous, startTime) {
7413
- this.demux(data, discontinuity, contiguous);
7600
+ value: function demuxAndFix(data, discontinuity, contiguous, startTime, seamlessLoadingSwitching) {
7601
+ this.demux(data, discontinuity, contiguous, seamlessLoadingSwitching);
7414
7602
  return this.fix(startTime, discontinuity, contiguous);
7415
7603
  }
7416
7604
  }, {
@@ -7420,12 +7608,12 @@
7420
7608
  return;
7421
7609
  var format = (data[0] & 240) >>> 4;
7422
7610
  var track = this.audioTrack;
7423
- if (format !== 10 && format !== 7 && format !== 8) {
7611
+ if (format !== FlvSoundFormat.AAC && format !== FlvSoundFormat.G711A && format !== FlvSoundFormat.G711M && format !== FlvSoundFormat.OPUS) {
7424
7612
  logger$2.warn("Unsupported sound format: ".concat(format));
7425
7613
  track.reset();
7426
7614
  return;
7427
7615
  }
7428
- if (format !== 10) {
7616
+ if (format !== FlvSoundFormat.AAC && format !== FlvSoundFormat.OPUS) {
7429
7617
  var soundRate = (data[0] & 12) >> 2;
7430
7618
  var soundSize = (data[0] & 2) >> 1;
7431
7619
  var soundType = data[0] & 1;
@@ -7433,10 +7621,49 @@
7433
7621
  track.sampleSize = soundSize ? 16 : 8;
7434
7622
  track.channelCount = soundType + 1;
7435
7623
  }
7436
- if (format === 10) {
7437
- this._parseAac(data, pts);
7438
- } else {
7439
- this._parseG711(data, pts, format);
7624
+ switch (format) {
7625
+ case FlvSoundFormat.G711A:
7626
+ case FlvSoundFormat.G711M:
7627
+ this._parseG711(data, pts, format);
7628
+ break;
7629
+ case FlvSoundFormat.AAC:
7630
+ this._parseAac(data, pts);
7631
+ break;
7632
+ case FlvSoundFormat.OPUS:
7633
+ this._parseOpus(data, pts);
7634
+ break;
7635
+ }
7636
+ }
7637
+ }, {
7638
+ key: "_parseOpus",
7639
+ value: function _parseOpus(data, pts) {
7640
+ var track = this.audioTrack;
7641
+ var packetType = data[1];
7642
+ track.codecType = AudioCodecType.OPUS;
7643
+ switch (packetType) {
7644
+ case 0: {
7645
+ var ret = OPUS.parseHeaderPackets(data.subarray(2));
7646
+ if (ret) {
7647
+ track.codec = ret.codec;
7648
+ track.channelCount = ret.channelCount;
7649
+ track.sampleRate = ret.sampleRate;
7650
+ track.config = ret.config;
7651
+ track.sampleDuration = OPUS.getFrameDuration([], track.timescale);
7652
+ } else {
7653
+ track.reset();
7654
+ logger$2.warn("Cannot parse AudioSpecificConfig", data);
7655
+ }
7656
+ break;
7657
+ }
7658
+ case 1: {
7659
+ if (pts === void 0 || pts === null)
7660
+ return;
7661
+ var newSample = new AudioSample(pts, data.subarray(2), track.sampleDuration);
7662
+ track.samples.push(newSample);
7663
+ break;
7664
+ }
7665
+ default:
7666
+ logger$2.warn("Unknown OpusPacketType: ".concat(packetType));
7440
7667
  }
7441
7668
  }
7442
7669
  }, {
@@ -7524,8 +7751,13 @@
7524
7751
  units = this._checkAddMetaNalToUnits(isHevc, units, track);
7525
7752
  if (units && units.length) {
7526
7753
  var sample = new VideoSample(dts + cts, dts, units);
7754
+ if (this.seamlessLoadingSwitching && dts < track.lastKeyFrameDts) {
7755
+ return;
7756
+ }
7757
+ this.seamlessLoadingSwitching = false;
7527
7758
  if (frameType === 1) {
7528
7759
  sample.setToKeyframe();
7760
+ track.lastKeyFrameDts = dts;
7529
7761
  }
7530
7762
  track.samples.push(sample);
7531
7763
  units.forEach(function(unit) {
@@ -7999,10 +8231,16 @@
7999
8231
  if (track.useEME && track.enca) {
8000
8232
  content = MP42.enca(track);
8001
8233
  } else {
8002
- content = MP42.mp4a(track);
8234
+ if (track.codecType === AudioCodecType.OPUS) {
8235
+ content = MP42.opus(track);
8236
+ } else {
8237
+ content = MP42.mp4a(track);
8238
+ }
8003
8239
  }
8004
8240
  } else if (track.useEME && track.encv) {
8005
8241
  content = MP42.encv(track);
8242
+ } else if (track.av1C) {
8243
+ content = MP42.av01(track);
8006
8244
  } else {
8007
8245
  content = MP42.avc1hev1(track);
8008
8246
  }
@@ -8215,6 +8453,90 @@
8215
8453
  var schi = MP42.schi(data);
8216
8454
  return MP42.box(MP42.types.sinf, content, MP42.box(MP42.types.frma, frma), MP42.box(MP42.types.schm, schm), schi);
8217
8455
  }
8456
+ }, {
8457
+ key: "av01",
8458
+ value: function av01(track) {
8459
+ return MP42.box(MP42.types.av01, new Uint8Array([
8460
+ 0,
8461
+ 0,
8462
+ 0,
8463
+ 0,
8464
+ 0,
8465
+ 0,
8466
+ 0,
8467
+ 1,
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
+ 0,
8483
+ 0,
8484
+ track.width >> 8 & 255,
8485
+ track.width & 255,
8486
+ track.height >> 8 & 255,
8487
+ track.height & 255,
8488
+ 0,
8489
+ 72,
8490
+ 0,
8491
+ 0,
8492
+ 0,
8493
+ 72,
8494
+ 0,
8495
+ 0,
8496
+ 0,
8497
+ 0,
8498
+ 0,
8499
+ 0,
8500
+ 0,
8501
+ 1,
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
+ 0,
8534
+ 0,
8535
+ 24,
8536
+ 17,
8537
+ 17
8538
+ ]), track.av1C, track.colr);
8539
+ }
8218
8540
  }, {
8219
8541
  key: "avc1hev1",
8220
8542
  value: function avc1hev1(track) {
@@ -8585,6 +8907,53 @@
8585
8907
  )));
8586
8908
  return esds2;
8587
8909
  }
8910
+ }, {
8911
+ key: "opus",
8912
+ value: function opus(track) {
8913
+ var opusAudioDescription = new Uint8Array([
8914
+ 0,
8915
+ 0,
8916
+ 0,
8917
+ 0,
8918
+ 0,
8919
+ 0,
8920
+ 0,
8921
+ 1,
8922
+ 0,
8923
+ 0,
8924
+ 0,
8925
+ 0,
8926
+ 0,
8927
+ 0,
8928
+ 0,
8929
+ 0,
8930
+ 0,
8931
+ track.channelCount,
8932
+ 0,
8933
+ 16,
8934
+ 0,
8935
+ 0,
8936
+ 0,
8937
+ 0,
8938
+ track.sampleRate >> 8 & 255,
8939
+ track.sampleRate & 255,
8940
+ 0,
8941
+ 0
8942
+ ]);
8943
+ var opusSpecificConfig = track.config.length ? MP42.dOps(track) : [];
8944
+ return MP42.box(MP42.types.Opus, opusAudioDescription, opusSpecificConfig);
8945
+ }
8946
+ }, {
8947
+ key: "dOps",
8948
+ value: function dOps(track) {
8949
+ if (track.config) {
8950
+ track.config[4] = track.sampleRate >>> 24 & 255;
8951
+ track.config[5] = track.sampleRate >>> 16 & 255;
8952
+ track.config[6] = track.sampleRate >>> 8 & 255;
8953
+ track.config[7] = track.sampleRate & 255;
8954
+ return MP42.box(MP42.types.dOps, track.config);
8955
+ }
8956
+ }
8588
8957
  }, {
8589
8958
  key: "mvex",
8590
8959
  value: function mvex(tracks) {
@@ -9187,7 +9556,7 @@
9187
9556
  }]);
9188
9557
  return MP42;
9189
9558
  }();
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) {
9559
+ _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
9560
  p[c] = [c.charCodeAt(0), c.charCodeAt(1), c.charCodeAt(2), c.charCodeAt(3)];
9192
9561
  return p;
9193
9562
  }, /* @__PURE__ */ Object.create(null)));
@@ -9522,30 +9891,46 @@
9522
9891
  };
9523
9892
  }
9524
9893
  var samples = track.samples;
9894
+ var isAV01 = /av01/.test(track.codec);
9525
9895
  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;
9896
+ if (isAV01) {
9897
+ samples.forEach(function(s) {
9898
+ mdatSize += s.data.byteLength;
9543
9899
  });
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);
9900
+ } else {
9901
+ samples.forEach(function(s) {
9902
+ mdatSize += s.units.reduce(function(t, c) {
9903
+ return t + c.byteLength;
9904
+ }, 0);
9905
+ mdatSize += s.units.length * 4;
9906
+ });
9907
+ }
9908
+ var mdata = new Uint8Array(mdatSize);
9909
+ if (isAV01) {
9910
+ for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
9911
+ sample = samples[i];
9912
+ mdata.set(sample.data, offset);
9913
+ sample.size = sample.data.byteLength;
9914
+ offset += sample.size;
9915
+ }
9916
+ } else {
9917
+ var mdatView = new DataView(mdata.buffer);
9918
+ var _loop = function _loop2(_offset2, _sample2) {
9919
+ _sample2 = samples[_i];
9920
+ var sampleSize = 0;
9921
+ _sample2.units.forEach(function(u) {
9922
+ mdatView.setUint32(_offset2, u.byteLength);
9923
+ _offset2 += 4;
9924
+ mdata.set(u, _offset2);
9925
+ _offset2 += u.byteLength;
9926
+ sampleSize += 4 + u.byteLength;
9927
+ });
9928
+ _sample2.size = sampleSize;
9929
+ _offset = _offset2, _sample = _sample2;
9930
+ };
9931
+ for (var _i = 0, _l = samples.length, _offset = 0, _sample; _i < _l; _i++) {
9932
+ _loop(_offset, _sample);
9933
+ }
9549
9934
  }
9550
9935
  var mdat = MP4.mdat(mdata);
9551
9936
  var moof = MP4.moof([track]);
@@ -9575,6 +9960,55 @@
9575
9960
  }]);
9576
9961
  return FMP4Remuxer2;
9577
9962
  }();
9963
+ var TransferCost = /* @__PURE__ */ function() {
9964
+ function TransferCost2() {
9965
+ _classCallCheck$4(this, TransferCost2);
9966
+ _defineProperty$3(this, "_ttfb", 0);
9967
+ _defineProperty$3(this, "_demuxStart", 0);
9968
+ _defineProperty$3(this, "_demuxEnd", 0);
9969
+ _defineProperty$3(this, "_demuxCost", 0);
9970
+ _defineProperty$3(this, "_remuxStart", 0);
9971
+ _defineProperty$3(this, "_remuxEnd", 0);
9972
+ _defineProperty$3(this, "_remuxCost", 0);
9973
+ _defineProperty$3(this, "_appendStart", 0);
9974
+ _defineProperty$3(this, "_appendEnd", 0);
9975
+ _defineProperty$3(this, "_appendCost", 0);
9976
+ }
9977
+ _createClass$4(TransferCost2, [{
9978
+ key: "set",
9979
+ value: function set(event, value) {
9980
+ this["_".concat(event)] = value;
9981
+ }
9982
+ }, {
9983
+ key: "start",
9984
+ value: function start(event) {
9985
+ this["_".concat(event, "Start")] = Date.now();
9986
+ }
9987
+ }, {
9988
+ key: "end",
9989
+ value: function end(event) {
9990
+ this["_".concat(event, "End")] = Date.now();
9991
+ this["_".concat(event, "Cost")] = this["_".concat(event, "Cost")] + (this["_".concat(event, "End")] - this["_".concat(event, "Start")]);
9992
+ }
9993
+ }, {
9994
+ key: "transferCost",
9995
+ get: function get() {
9996
+ return {
9997
+ ttfbCost: this._ttfb,
9998
+ demuxCost: this._demuxCost,
9999
+ remuxCost: this._remuxCost,
10000
+ appendCost: this._appendCost
10001
+ };
10002
+ }
10003
+ }]);
10004
+ return TransferCost2;
10005
+ }();
10006
+ var TRANSFER_EVENT = {
10007
+ TTFB: "ttfb",
10008
+ DEMUX: "demux",
10009
+ REMUX: "remux",
10010
+ APPEND: "append"
10011
+ };
9578
10012
  var logger$1 = new Logger$2("BufferService");
9579
10013
  var BufferService = /* @__PURE__ */ function() {
9580
10014
  function BufferService2(flv, softVideo) {
@@ -9662,7 +10096,8 @@
9662
10096
  this._contiguous = false;
9663
10097
  this._sourceCreated = false;
9664
10098
  this._initSegmentId = "";
9665
- case 11:
10099
+ this.resetSeamlessSwitchStats();
10100
+ case 12:
9666
10101
  case "end":
9667
10102
  return _context.stop();
9668
10103
  }
@@ -9673,6 +10108,15 @@
9673
10108
  }
9674
10109
  return reset;
9675
10110
  }()
10111
+ }, {
10112
+ key: "resetSeamlessSwitchStats",
10113
+ value: function resetSeamlessSwitchStats() {
10114
+ this.seamlessLoadingSwitch = null;
10115
+ this.seamlessLoadingSwitching = false;
10116
+ if (this._demuxer) {
10117
+ this._demuxer.seamlessLoadingSwitching = false;
10118
+ }
10119
+ }
9676
10120
  }, {
9677
10121
  key: "endOfStream",
9678
10122
  value: function() {
@@ -9778,32 +10222,56 @@
9778
10222
  key: "appendBuffer",
9779
10223
  value: function() {
9780
10224
  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;
10225
+ var _this = this;
10226
+ var switchingNoReset, demuxer, videoTrack, audioTrack, metadataTrack, idx, videoExist, audioExist, duration, track, videoType, audioType, mse, afterAppend, newId, remuxResult, p;
9782
10227
  return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
9783
10228
  while (1)
9784
10229
  switch (_context5.prev = _context5.next) {
9785
10230
  case 0:
10231
+ switchingNoReset = false;
9786
10232
  if (this._cachedBuffer) {
9787
10233
  chunk = concatUint8Array$1(this._cachedBuffer, chunk);
9788
10234
  this._cachedBuffer = null;
9789
10235
  }
9790
10236
  demuxer = this._demuxer;
9791
10237
  if (!(!chunk || !chunk.length || !demuxer)) {
9792
- _context5.next = 4;
10238
+ _context5.next = 5;
9793
10239
  break;
9794
10240
  }
9795
10241
  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;
10242
+ case 5:
10243
+ _context5.prev = 5;
10244
+ this.flv._transferCost.start(TRANSFER_EVENT.DEMUX);
10245
+ demuxer.demuxAndFix(chunk, this.seamlessLoadingSwitching || this._discontinuity, this._contiguous, this._demuxStartTime, this.seamlessLoadingSwitching);
10246
+ this.seamlessLoadingSwitching = false;
10247
+ this.flv._transferCost.end(TRANSFER_EVENT.DEMUX);
10248
+ _context5.next = 15;
9800
10249
  break;
9801
- case 8:
9802
- _context5.prev = 8;
9803
- _context5.t0 = _context5["catch"](4);
10250
+ case 12:
10251
+ _context5.prev = 12;
10252
+ _context5.t0 = _context5["catch"](5);
9804
10253
  throw new StreamingError(ERR.DEMUX, ERR.SUB_TYPES.FLV, _context5.t0);
9805
- case 11:
10254
+ case 15:
9806
10255
  videoTrack = demuxer.videoTrack, audioTrack = demuxer.audioTrack, metadataTrack = demuxer.metadataTrack;
10256
+ if (!this.seamlessLoadingSwitch) {
10257
+ _context5.next = 25;
10258
+ break;
10259
+ }
10260
+ idx = videoTrack.samples.findIndex(function(sample) {
10261
+ return sample.originDts === videoTrack.lastKeyFrameDts;
10262
+ });
10263
+ if (!(idx >= 0)) {
10264
+ _context5.next = 25;
10265
+ break;
10266
+ }
10267
+ videoTrack.samples.splice(idx);
10268
+ _context5.next = 22;
10269
+ return this.seamlessLoadingSwitch();
10270
+ case 22:
10271
+ this.seamlessLoadingSwitch = null;
10272
+ chunk = null;
10273
+ switchingNoReset = true;
10274
+ case 25:
9807
10275
  videoExist = videoTrack.exist();
9808
10276
  audioExist = audioTrack.exist();
9809
10277
  if (this._opts.onlyAudio) {
@@ -9815,7 +10283,7 @@
9815
10283
  audioTrack.present = false;
9816
10284
  }
9817
10285
  if (!(!videoExist && videoTrack.present || !audioExist && audioTrack.present)) {
9818
- _context5.next = 29;
10286
+ _context5.next = 42;
9819
10287
  break;
9820
10288
  }
9821
10289
  duration = 0;
@@ -9824,7 +10292,7 @@
9824
10292
  duration = (track.samples[track.samples.length - 1].originPts - track.samples[0].originPts) / track.timescale * 1e3;
9825
10293
  }
9826
10294
  if (!(duration > this._opts.analyzeDuration)) {
9827
- _context5.next = 27;
10295
+ _context5.next = 40;
9828
10296
  break;
9829
10297
  }
9830
10298
  logger$1.warn("analyze duration exceeded, ".concat(duration, "ms"), track);
@@ -9833,19 +10301,28 @@
9833
10301
  this.flv.emit(EVENT.ANALYZE_DURATION_EXCEEDED, {
9834
10302
  duration
9835
10303
  });
9836
- _context5.next = 29;
10304
+ _context5.next = 42;
9837
10305
  break;
9838
- case 27:
10306
+ case 40:
9839
10307
  this._cachedBuffer = chunk;
9840
10308
  return _context5.abrupt("return");
9841
- case 29:
10309
+ case 42:
9842
10310
  videoType = videoTrack.type;
9843
10311
  audioType = audioTrack.type;
9844
10312
  this._fireEvents(videoTrack, audioTrack, metadataTrack);
9845
- this._discontinuity = false;
9846
- this._contiguous = true;
9847
- this._demuxStartTime = 0;
10313
+ if (!switchingNoReset) {
10314
+ this._discontinuity = false;
10315
+ this._contiguous = true;
10316
+ this._demuxStartTime = 0;
10317
+ }
9848
10318
  mse = this._mse;
10319
+ afterAppend = function afterAppend2() {
10320
+ var _this$flv;
10321
+ if ((_this$flv = _this.flv) !== null && _this$flv !== void 0 && _this$flv.emit) {
10322
+ var _this$flv2;
10323
+ (_this$flv2 = _this.flv) === null || _this$flv2 === void 0 ? void 0 : _this$flv2.emit(EVENT.APPEND_BUFFER, {});
10324
+ }
10325
+ };
9849
10326
  this.flv.emit(EVENT.DEMUXED_TRACK, {
9850
10327
  videoTrack
9851
10328
  });
@@ -9856,16 +10333,16 @@
9856
10333
  this._emitMetaParsedEvent(videoTrack, audioTrack);
9857
10334
  }
9858
10335
  if (!mse) {
9859
- _context5.next = 66;
10336
+ _context5.next = 81;
9860
10337
  break;
9861
10338
  }
9862
10339
  if (this._sourceCreated) {
9863
- _context5.next = 47;
10340
+ _context5.next = 59;
9864
10341
  break;
9865
10342
  }
9866
- _context5.next = 43;
10343
+ _context5.next = 55;
9867
10344
  return mse.open();
9868
- case 43:
10345
+ case 55:
9869
10346
  if (videoExist) {
9870
10347
  logger$1.log("codec: video/mp4;codecs=".concat(videoTrack.codec));
9871
10348
  mse.createSource(videoType, "video/mp4;codecs=".concat(videoTrack.codec));
@@ -9876,26 +10353,28 @@
9876
10353
  }
9877
10354
  this._sourceCreated = true;
9878
10355
  this.flv.emit(EVENT.SOURCEBUFFER_CREATED);
9879
- case 47:
9880
- _context5.prev = 47;
10356
+ case 59:
10357
+ _context5.prev = 59;
9881
10358
  if (this._needInitSegment && !this._opts.mseLowLatency) {
9882
10359
  videoTrack.duration = this._opts.durationForMSELowLatencyOff * videoTrack.timescale;
9883
10360
  audioTrack.duration = this._opts.durationForMSELowLatencyOff * audioExist.timescale;
9884
10361
  }
10362
+ this.flv._transferCost.start(TRANSFER_EVENT.REMUX);
9885
10363
  remuxResult = this._remuxer.remux(this._needInitSegment);
9886
- _context5.next = 55;
10364
+ this.flv._transferCost.end(TRANSFER_EVENT.REMUX);
10365
+ _context5.next = 69;
9887
10366
  break;
9888
- case 52:
9889
- _context5.prev = 52;
9890
- _context5.t1 = _context5["catch"](47);
10367
+ case 66:
10368
+ _context5.prev = 66;
10369
+ _context5.t1 = _context5["catch"](59);
9891
10370
  throw new StreamingError(ERR.REMUX, ERR.SUB_TYPES.FMP4, _context5.t1);
9892
- case 55:
10371
+ case 69:
9893
10372
  if (!(this._needInitSegment && !remuxResult.videoInitSegment && !remuxResult.audioInitSegment)) {
9894
- _context5.next = 57;
10373
+ _context5.next = 71;
9895
10374
  break;
9896
10375
  }
9897
10376
  return _context5.abrupt("return");
9898
- case 57:
10377
+ case 71:
9899
10378
  this._needInitSegment = false;
9900
10379
  p = [];
9901
10380
  if (remuxResult.videoInitSegment)
@@ -9906,16 +10385,21 @@
9906
10385
  p.push(mse.append(videoType, remuxResult.videoSegment));
9907
10386
  if (remuxResult.audioSegment)
9908
10387
  p.push(mse.append(audioType, remuxResult.audioSegment));
9909
- return _context5.abrupt("return", Promise.all(p));
9910
- case 66:
10388
+ this.flv._transferCost.start(TRANSFER_EVENT.APPEND);
10389
+ return _context5.abrupt("return", Promise.all(p).then(afterAppend).then(function() {
10390
+ _this.flv._transferCost.end(TRANSFER_EVENT.APPEND);
10391
+ afterAppend();
10392
+ }));
10393
+ case 81:
9911
10394
  if (this._softVideo) {
9912
10395
  this._softVideo.appendBuffer(videoTrack, audioTrack);
10396
+ afterAppend();
9913
10397
  }
9914
- case 67:
10398
+ case 82:
9915
10399
  case "end":
9916
10400
  return _context5.stop();
9917
10401
  }
9918
- }, _callee5, this, [[4, 8], [47, 52]]);
10402
+ }, _callee5, this, [[5, 12], [59, 66]]);
9919
10403
  }));
9920
10404
  function appendBuffer(_x2) {
9921
10405
  return _appendBuffer.apply(this, arguments);
@@ -9926,7 +10410,7 @@
9926
10410
  key: "evictBuffer",
9927
10411
  value: function() {
9928
10412
  var _evictBuffer = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee6(bufferBehind) {
9929
- var _this = this;
10413
+ var _this2 = this;
9930
10414
  var media, currentTime, removeEnd, start;
9931
10415
  return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
9932
10416
  while (1)
@@ -9955,7 +10439,7 @@
9955
10439
  return _context6.abrupt("return");
9956
10440
  case 10:
9957
10441
  return _context6.abrupt("return", this._mse.clearBuffer(0, removeEnd).then(function() {
9958
- return _this.flv.emit(EVENT.REMOVE_BUFFER, {
10442
+ return _this2.flv.emit(EVENT.REMOVE_BUFFER, {
9959
10443
  removeEnd
9960
10444
  });
9961
10445
  }));
@@ -10005,16 +10489,16 @@
10005
10489
  }, {
10006
10490
  key: "_fireEvents",
10007
10491
  value: function _fireEvents(videoTrack, audioTrack, metadataTrack) {
10008
- var _this2 = this;
10009
- logger$1.debug(videoTrack.samples, audioTrack.samples);
10492
+ var _this3 = this;
10493
+ logger$1.debug("videoTrack samples count: ".concat(videoTrack.samples.length, ", audioTrack samples count: ").concat(audioTrack.samples.length));
10010
10494
  metadataTrack.flvScriptSamples.forEach(function(sample) {
10011
- _this2.flv.emit(EVENT.FLV_SCRIPT_DATA, sample);
10495
+ _this3.flv.emit(EVENT.FLV_SCRIPT_DATA, sample);
10012
10496
  logger$1.debug("flvScriptData", sample);
10013
10497
  });
10014
10498
  videoTrack.samples.forEach(function(sample) {
10015
10499
  if (sample.keyframe) {
10016
- _this2.flv.emit(EVENT.KEYFRAME, {
10017
- pts: sample.pts
10500
+ _this3.flv.emit(EVENT.KEYFRAME, {
10501
+ pts: sample.originPts
10018
10502
  });
10019
10503
  }
10020
10504
  });
@@ -10032,7 +10516,7 @@
10032
10516
  break;
10033
10517
  }
10034
10518
  if (type)
10035
- _this2.flv.emit(EVENT.STREAM_EXCEPTION, _objectSpread2$2(_objectSpread2$2({}, warn), {}, {
10519
+ _this3.flv.emit(EVENT.STREAM_EXCEPTION, _objectSpread2$2(_objectSpread2$2({}, warn), {}, {
10036
10520
  type
10037
10521
  }));
10038
10522
  logger$1.warn("video exception", warn);
@@ -10051,13 +10535,13 @@
10051
10535
  break;
10052
10536
  }
10053
10537
  if (type)
10054
- _this2.flv.emit(EVENT.STREAM_EXCEPTION, _objectSpread2$2(_objectSpread2$2({}, warn), {}, {
10538
+ _this3.flv.emit(EVENT.STREAM_EXCEPTION, _objectSpread2$2(_objectSpread2$2({}, warn), {}, {
10055
10539
  type
10056
10540
  }));
10057
10541
  logger$1.warn("audio exception", warn);
10058
10542
  });
10059
10543
  metadataTrack.seiSamples.forEach(function(sei) {
10060
- _this2.flv.emit(EVENT.SEI, _objectSpread2$2(_objectSpread2$2({}, sei), {}, {
10544
+ _this3.flv.emit(EVENT.SEI, _objectSpread2$2(_objectSpread2$2({}, sei), {}, {
10061
10545
  sei: {
10062
10546
  code: sei.data.type,
10063
10547
  content: sei.data.payload,
@@ -10092,7 +10576,8 @@
10092
10576
  durationForMSELowLatencyOff: 6,
10093
10577
  chunkCountForSpeed: 50,
10094
10578
  skipChunkSize: 1e3,
10095
- longtimeNoReceived: 3e3
10579
+ longtimeNoReceived: 3e3,
10580
+ enableStartGapJump: true
10096
10581
  }, opts);
10097
10582
  if (ret.isLive) {
10098
10583
  if (ret.preloadTime) {
@@ -10160,7 +10645,7 @@
10160
10645
  _defineProperty$3(_assertThisInitialized$3(_this), "_acceptRanges", true);
10161
10646
  _defineProperty$3(_assertThisInitialized$3(_this), "_onProgress", /* @__PURE__ */ function() {
10162
10647
  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;
10648
+ var startTime, endTime, st, firstByteTime, _this$_mediaLoader, headers, elapsed, _this$_bufferService, remaining, maxReaderInterval;
10164
10649
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
10165
10650
  while (1)
10166
10651
  switch (_context.prev = _context.next) {
@@ -10168,7 +10653,7 @@
10168
10653
  startTime = _ref.startTime, endTime = _ref.endTime, st = _ref.st, firstByteTime = _ref.firstByteTime;
10169
10654
  _this._loading = !done;
10170
10655
  if (_this._firstProgressEmit) {
10171
- _context.next = 11;
10656
+ _context.next = 13;
10172
10657
  break;
10173
10658
  }
10174
10659
  if (_this.media) {
@@ -10179,49 +10664,51 @@
10179
10664
  return _context.abrupt("return");
10180
10665
  case 6:
10181
10666
  headers = response.headers;
10667
+ elapsed = st ? firstByteTime - st : endTime - startTime;
10182
10668
  _this.emit(EVENT.TTFB, {
10183
10669
  url: _this._opts.url,
10184
10670
  responseUrl: response.url,
10185
- elapsed: st ? firstByteTime - st : endTime - startTime
10671
+ elapsed
10186
10672
  });
10187
10673
  _this.emit(EVENT.LOAD_RESPONSE_HEADERS, {
10188
10674
  headers
10189
10675
  });
10676
+ _this._transferCost.set(TRANSFER_EVENT.TTFB, elapsed);
10190
10677
  _this._acceptRanges = !!(headers !== null && headers !== void 0 && headers.get("Accept-Ranges")) || !!(headers !== null && headers !== void 0 && headers.get("Content-Range"));
10191
10678
  _this._firstProgressEmit = true;
10192
- case 11:
10679
+ case 13:
10193
10680
  if (_this._bufferService) {
10194
- _context.next = 13;
10681
+ _context.next = 15;
10195
10682
  break;
10196
10683
  }
10197
10684
  return _context.abrupt("return");
10198
- case 13:
10685
+ case 15:
10199
10686
  clearTimeout(_this._maxChunkWaitTimer);
10200
10687
  _this._bandwidthService.addChunkRecord(chunk === null || chunk === void 0 ? void 0 : chunk.byteLength, endTime - startTime);
10201
- _context.prev = 15;
10202
- _context.next = 18;
10688
+ _context.prev = 17;
10689
+ _context.next = 20;
10203
10690
  return _this._bufferService.appendBuffer(chunk);
10204
- case 18:
10691
+ case 20:
10205
10692
  (_this$_bufferService = _this._bufferService) === null || _this$_bufferService === void 0 ? void 0 : _this$_bufferService.evictBuffer(_this._opts.bufferBehind);
10206
- _context.next = 31;
10693
+ _context.next = 33;
10207
10694
  break;
10208
- case 21:
10209
- _context.prev = 21;
10210
- _context.t0 = _context["catch"](15);
10695
+ case 23:
10696
+ _context.prev = 23;
10697
+ _context.t0 = _context["catch"](17);
10211
10698
  if (!(!_this.isLive && _this._bufferService.isFull())) {
10212
- _context.next = 30;
10699
+ _context.next = 32;
10213
10700
  break;
10214
10701
  }
10215
- _context.next = 26;
10702
+ _context.next = 28;
10216
10703
  return _this._mediaLoader.cancel();
10217
- case 26:
10704
+ case 28:
10218
10705
  _this._loading = false;
10219
10706
  remaining = _this.bufferInfo().remaining;
10220
10707
  _this._opts.preloadTime = parseInt(remaining) / 2;
10221
10708
  return _context.abrupt("return");
10222
- case 30:
10709
+ case 32:
10223
10710
  return _context.abrupt("return", _this._emitError(StreamingError.create(_context.t0)));
10224
- case 31:
10711
+ case 33:
10225
10712
  if (_this._urlSwitching) {
10226
10713
  _this._urlSwitching = false;
10227
10714
  _this.emit(EVENT.SWITCH_URL_SUCCESS, {
@@ -10233,7 +10720,7 @@
10233
10720
  _this._tick();
10234
10721
  }
10235
10722
  if (!(done && !_this.media.seeking)) {
10236
- _context.next = 38;
10723
+ _context.next = 40;
10237
10724
  break;
10238
10725
  }
10239
10726
  _this.emit(EVENT.LOAD_COMPLETE);
@@ -10242,13 +10729,13 @@
10242
10729
  _this._end();
10243
10730
  }
10244
10731
  return _context.abrupt("return");
10245
- case 38:
10732
+ case 40:
10246
10733
  if (_this.isLive) {
10247
- _context.next = 40;
10734
+ _context.next = 42;
10248
10735
  break;
10249
10736
  }
10250
10737
  return _context.abrupt("return");
10251
- case 40:
10738
+ case 42:
10252
10739
  maxReaderInterval = _this._opts.maxReaderInterval;
10253
10740
  if (maxReaderInterval && _this._firstProgressEmit) {
10254
10741
  clearTimeout(_this._maxChunkWaitTimer);
@@ -10262,11 +10749,11 @@
10262
10749
  _this._end();
10263
10750
  }, maxReaderInterval);
10264
10751
  }
10265
- case 42:
10752
+ case 44:
10266
10753
  case "end":
10267
10754
  return _context.stop();
10268
10755
  }
10269
- }, _callee, null, [[15, 21]]);
10756
+ }, _callee, null, [[17, 23]]);
10270
10757
  }));
10271
10758
  return function(_x, _x2, _x3, _x4) {
10272
10759
  return _ref2.apply(this, arguments);
@@ -10299,19 +10786,19 @@
10299
10786
  if (bufferEnd < MAX_HOLE || !media.readyState)
10300
10787
  return;
10301
10788
  var opts = _this._opts;
10302
- if (isMediaPlaying(media)) {
10789
+ if (isMediaPlaying(media) && media.currentTime) {
10303
10790
  if (_this._gapService) {
10304
10791
  _this._gapService.do(media, opts.maxJumpDistance, _this.isLive, 3);
10305
10792
  }
10306
10793
  } else {
10307
- if (!media.currentTime && _this._gapService) {
10794
+ if (!media.currentTime && _this._gapService && opts.enableStartGapJump) {
10308
10795
  var gapJump = _this._opts.mseLowLatency || _this._opts.mseLowLatency === false && _this.bufferInfo(MAX_START_GAP).nextStart;
10309
10796
  if (gapJump) {
10310
10797
  _this._gapService.do(media, opts.maxJumpDistance, _this.isLive, 3);
10311
10798
  }
10312
10799
  return;
10313
10800
  }
10314
- if (opts.isLive && media.readyState === 4 && bufferEnd > opts.disconnectTime) {
10801
+ if (opts.isLive && media.readyState === 4 && bufferEnd - media.currentTime > opts.disconnectTime) {
10315
10802
  _this.disconnect();
10316
10803
  }
10317
10804
  }
@@ -10460,6 +10947,7 @@
10460
10947
  responseType: "arraybuffer"
10461
10948
  }));
10462
10949
  _this._disconnectRetryCount = _this._opts.disconnectRetryCount;
10950
+ _this._transferCost = new TransferCost();
10463
10951
  _this._bufferService = new BufferService(_assertThisInitialized$3(_this), _this._opts.softDecode ? _this.media : void 0, _this._opts);
10464
10952
  _this._seiService = new SeiService(_assertThisInitialized$3(_this));
10465
10953
  _this._bandwidthService = new BandwidthService({
@@ -10483,7 +10971,7 @@
10483
10971
  _createClass$4(Flv2, [{
10484
10972
  key: "version",
10485
10973
  get: function get() {
10486
- return "3.0.19-rc.0";
10974
+ return "3.0.21-rc.2";
10487
10975
  }
10488
10976
  }, {
10489
10977
  key: "isLive",
@@ -10599,9 +11087,9 @@
10599
11087
  return this._clear();
10600
11088
  case 8:
10601
11089
  setTimeout(function() {
11090
+ _this2._seamlessSwitching = true;
10602
11091
  _this2._loadData(_this2._opts.url);
10603
11092
  _this2._bufferService.seamlessSwitch();
10604
- _this2._seamlessSwitching = true;
10605
11093
  });
10606
11094
  _context5.next = 13;
10607
11095
  break;
@@ -10625,50 +11113,82 @@
10625
11113
  }, {
10626
11114
  key: "disconnect",
10627
11115
  value: function disconnect() {
11116
+ var _this$_bufferService4;
10628
11117
  logger.debug("disconnect!");
11118
+ (_this$_bufferService4 = this._bufferService) === null || _this$_bufferService4 === void 0 ? void 0 : _this$_bufferService4.resetSeamlessSwitchStats();
10629
11119
  return this._clear();
10630
11120
  }
10631
11121
  }, {
10632
11122
  key: "switchURL",
10633
11123
  value: function() {
10634
- var _switchURL = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee6(url, seamless) {
11124
+ var _switchURL = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee7(url, seamless) {
10635
11125
  var _this3 = this;
10636
- return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
11126
+ return _regeneratorRuntime$1().wrap(function _callee7$(_context7) {
10637
11127
  while (1)
10638
- switch (_context6.prev = _context6.next) {
11128
+ switch (_context7.prev = _context7.next) {
10639
11129
  case 0:
10640
11130
  if (this._bufferService) {
10641
- _context6.next = 2;
11131
+ _context7.next = 2;
10642
11132
  break;
10643
11133
  }
10644
- return _context6.abrupt("return");
11134
+ return _context7.abrupt("return");
10645
11135
  case 2:
10646
11136
  this._resetDisconnectCount();
11137
+ if (!(this._loading && seamless)) {
11138
+ _context7.next = 6;
11139
+ break;
11140
+ }
11141
+ this._bufferService.seamlessLoadingSwitch = /* @__PURE__ */ function() {
11142
+ var _ref5 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee6(pts) {
11143
+ return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
11144
+ while (1)
11145
+ switch (_context6.prev = _context6.next) {
11146
+ case 0:
11147
+ _context6.next = 2;
11148
+ return _this3._clear();
11149
+ case 2:
11150
+ _this3._bufferService.seamlessLoadingSwitching = true;
11151
+ _this3._urlSwitching = true;
11152
+ _this3._seamlessSwitching = true;
11153
+ _this3._bufferService.seamlessSwitch();
11154
+ _this3._loadData(url);
11155
+ case 7:
11156
+ case "end":
11157
+ return _context6.stop();
11158
+ }
11159
+ }, _callee6);
11160
+ }));
11161
+ return function(_x8) {
11162
+ return _ref5.apply(this, arguments);
11163
+ };
11164
+ }();
11165
+ return _context7.abrupt("return");
11166
+ case 6:
10647
11167
  if (!(!seamless || !this._opts.isLive)) {
10648
- _context6.next = 8;
11168
+ _context7.next = 11;
10649
11169
  break;
10650
11170
  }
10651
- _context6.next = 6;
11171
+ _context7.next = 9;
10652
11172
  return this.load(url);
10653
- case 6:
11173
+ case 9:
10654
11174
  this._urlSwitching = true;
10655
- return _context6.abrupt("return", this.media.play(true).catch(function() {
11175
+ return _context7.abrupt("return", this.media.play(true).catch(function() {
10656
11176
  }));
10657
- case 8:
10658
- _context6.next = 10;
11177
+ case 11:
11178
+ _context7.next = 13;
10659
11179
  return this._clear();
10660
- case 10:
11180
+ case 13:
10661
11181
  setTimeout(function() {
10662
11182
  _this3._urlSwitching = true;
10663
11183
  _this3._seamlessSwitching = true;
10664
11184
  _this3._loadData(url);
10665
11185
  _this3._bufferService.seamlessSwitch();
10666
11186
  });
10667
- case 11:
11187
+ case 14:
10668
11188
  case "end":
10669
- return _context6.stop();
11189
+ return _context7.stop();
10670
11190
  }
10671
- }, _callee6, this);
11191
+ }, _callee7, this);
10672
11192
  }));
10673
11193
  function switchURL(_x6, _x7) {
10674
11194
  return _switchURL.apply(this, arguments);
@@ -10678,16 +11198,16 @@
10678
11198
  }, {
10679
11199
  key: "destroy",
10680
11200
  value: function() {
10681
- var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee7() {
10682
- return _regeneratorRuntime$1().wrap(function _callee7$(_context7) {
11201
+ var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee8() {
11202
+ return _regeneratorRuntime$1().wrap(function _callee8$(_context8) {
10683
11203
  while (1)
10684
- switch (_context7.prev = _context7.next) {
11204
+ switch (_context8.prev = _context8.next) {
10685
11205
  case 0:
10686
11206
  if (this.media) {
10687
- _context7.next = 2;
11207
+ _context8.next = 2;
10688
11208
  break;
10689
11209
  }
10690
- return _context7.abrupt("return");
11210
+ return _context8.abrupt("return");
10691
11211
  case 2:
10692
11212
  this.removeAllListeners();
10693
11213
  this._seiService.reset();
@@ -10697,16 +11217,16 @@
10697
11217
  this.media.removeEventListener("timeupdate", this._onTimeupdate);
10698
11218
  this.media.removeEventListener("waiting", this._onWaiting);
10699
11219
  this.media.removeEventListener("progress", this._onBufferUpdate);
10700
- _context7.next = 12;
11220
+ _context8.next = 12;
10701
11221
  return Promise.all([this._clear(), this._bufferService.destroy()]);
10702
11222
  case 12:
10703
11223
  this.media = null;
10704
11224
  this._bufferService = null;
10705
11225
  case 14:
10706
11226
  case "end":
10707
- return _context7.stop();
11227
+ return _context8.stop();
10708
11228
  }
10709
- }, _callee7, this);
11229
+ }, _callee8, this);
10710
11230
  }));
10711
11231
  function destroy() {
10712
11232
  return _destroy.apply(this, arguments);
@@ -10735,26 +11255,26 @@
10735
11255
  }, {
10736
11256
  key: "_reset",
10737
11257
  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) {
11258
+ var _reset2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee9() {
11259
+ var reuseMse, _args9 = arguments;
11260
+ return _regeneratorRuntime$1().wrap(function _callee9$(_context9) {
10741
11261
  while (1)
10742
- switch (_context8.prev = _context8.next) {
11262
+ switch (_context9.prev = _context9.next) {
10743
11263
  case 0:
10744
- reuseMse = _args8.length > 0 && _args8[0] !== void 0 ? _args8[0] : false;
11264
+ reuseMse = _args9.length > 0 && _args9[0] !== void 0 ? _args9[0] : false;
10745
11265
  this._seiService.reset();
10746
11266
  this._bandwidthService.reset();
10747
11267
  this._stats.reset();
10748
- _context8.next = 6;
11268
+ _context9.next = 6;
10749
11269
  return this._clear();
10750
11270
  case 6:
10751
- _context8.next = 8;
11271
+ _context9.next = 8;
10752
11272
  return this._bufferService.reset(reuseMse);
10753
11273
  case 8:
10754
11274
  case "end":
10755
- return _context8.stop();
11275
+ return _context9.stop();
10756
11276
  }
10757
- }, _callee8, this);
11277
+ }, _callee9, this);
10758
11278
  }));
10759
11279
  function _reset() {
10760
11280
  return _reset2.apply(this, arguments);
@@ -10764,17 +11284,17 @@
10764
11284
  }, {
10765
11285
  key: "_loadData",
10766
11286
  value: function() {
10767
- var _loadData2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee9(url, range) {
11287
+ var _loadData2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee10(url, range) {
10768
11288
  var finnalUrl;
10769
- return _regeneratorRuntime$1().wrap(function _callee9$(_context9) {
11289
+ return _regeneratorRuntime$1().wrap(function _callee10$(_context10) {
10770
11290
  while (1)
10771
- switch (_context9.prev = _context9.next) {
11291
+ switch (_context10.prev = _context10.next) {
10772
11292
  case 0:
10773
11293
  if (url)
10774
11294
  this._opts.url = url;
10775
11295
  finnalUrl = url = this._opts.url;
10776
11296
  if (url) {
10777
- _context9.next = 4;
11297
+ _context10.next = 4;
10778
11298
  break;
10779
11299
  }
10780
11300
  throw new Error("Source url is missing");
@@ -10789,34 +11309,34 @@
10789
11309
  });
10790
11310
  logger.debug("load data, loading:", this._loading, finnalUrl);
10791
11311
  if (!this._loading) {
10792
- _context9.next = 11;
11312
+ _context10.next = 11;
10793
11313
  break;
10794
11314
  }
10795
- _context9.next = 11;
11315
+ _context10.next = 11;
10796
11316
  return this._mediaLoader.cancel();
10797
11317
  case 11:
10798
11318
  this._loading = true;
10799
- _context9.prev = 12;
10800
- _context9.next = 15;
11319
+ _context10.prev = 12;
11320
+ _context10.next = 15;
10801
11321
  return this._mediaLoader.load({
10802
11322
  url: finnalUrl,
10803
11323
  range
10804
11324
  });
10805
11325
  case 15:
10806
- _context9.next = 21;
11326
+ _context10.next = 21;
10807
11327
  break;
10808
11328
  case 17:
10809
- _context9.prev = 17;
10810
- _context9.t0 = _context9["catch"](12);
11329
+ _context10.prev = 17;
11330
+ _context10.t0 = _context10["catch"](12);
10811
11331
  this._loading = false;
10812
- return _context9.abrupt("return", this._emitError(StreamingError.network(_context9.t0), false));
11332
+ return _context10.abrupt("return", this._emitError(StreamingError.network(_context10.t0), false));
10813
11333
  case 21:
10814
11334
  case "end":
10815
- return _context9.stop();
11335
+ return _context10.stop();
10816
11336
  }
10817
- }, _callee9, this, [[12, 17]]);
11337
+ }, _callee10, this, [[12, 17]]);
10818
11338
  }));
10819
- function _loadData(_x8, _x9) {
11339
+ function _loadData(_x9, _x10) {
10820
11340
  return _loadData2.apply(this, arguments);
10821
11341
  }
10822
11342
  return _loadData;
@@ -10824,16 +11344,16 @@
10824
11344
  }, {
10825
11345
  key: "_clear",
10826
11346
  value: function() {
10827
- var _clear2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee10() {
10828
- return _regeneratorRuntime$1().wrap(function _callee10$(_context10) {
11347
+ var _clear2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee11() {
11348
+ return _regeneratorRuntime$1().wrap(function _callee11$(_context11) {
10829
11349
  while (1)
10830
- switch (_context10.prev = _context10.next) {
11350
+ switch (_context11.prev = _context11.next) {
10831
11351
  case 0:
10832
11352
  if (!this._mediaLoader) {
10833
- _context10.next = 3;
11353
+ _context11.next = 3;
10834
11354
  break;
10835
11355
  }
10836
- _context10.next = 3;
11356
+ _context11.next = 3;
10837
11357
  return this._mediaLoader.cancel();
10838
11358
  case 3:
10839
11359
  clearTimeout(this._maxChunkWaitTimer);
@@ -10842,9 +11362,9 @@
10842
11362
  this._firstProgressEmit = false;
10843
11363
  case 7:
10844
11364
  case "end":
10845
- return _context10.stop();
11365
+ return _context11.stop();
10846
11366
  }
10847
- }, _callee10, this);
11367
+ }, _callee11, this);
10848
11368
  }));
10849
11369
  function _clear() {
10850
11370
  return _clear2.apply(this, arguments);
@@ -10931,9 +11451,13 @@
10931
11451
  _createClass$4(PluginExtension2, [{
10932
11452
  key: "_init",
10933
11453
  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;
11454
+ 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
11455
  if (!media)
10936
11456
  return;
11457
+ if (!isLive && media.setPlayMode) {
11458
+ media.setPlayMode("VOD");
11459
+ return;
11460
+ }
10937
11461
  if (innerDegrade) {
10938
11462
  media.setAttribute("innerdegrade", innerDegrade);
10939
11463
  }
@@ -10971,6 +11495,7 @@
10971
11495
  args[_key] = arguments[_key];
10972
11496
  }
10973
11497
  _this = _super.call.apply(_super, [this].concat(args));
11498
+ _defineProperty$3(_assertThisInitialized$3(_this), "logger", logger);
10974
11499
  _defineProperty$3(_assertThisInitialized$3(_this), "flv", null);
10975
11500
  _defineProperty$3(_assertThisInitialized$3(_this), "pluginExtension", null);
10976
11501
  _defineProperty$3(_assertThisInitialized$3(_this), "getStats", function() {
@@ -11038,11 +11563,17 @@
11038
11563
  var _this$flv3;
11039
11564
  return (_this$flv3 = this.flv) === null || _this$flv3 === void 0 ? void 0 : _this$flv3.loader;
11040
11565
  }
11566
+ }, {
11567
+ key: "transferCost",
11568
+ get: function get() {
11569
+ return this.flv._transferCost.transferCost;
11570
+ }
11041
11571
  }, {
11042
11572
  key: "beforePlayerInit",
11043
11573
  value: function beforePlayerInit() {
11044
11574
  var _this2 = this;
11045
11575
  var config = this.player.config;
11576
+ var mediaElem = this.player.media || this.player.video;
11046
11577
  if (!config.url)
11047
11578
  return;
11048
11579
  if (this.flv)
@@ -11055,10 +11586,10 @@
11055
11586
  this.flv = new Flv(_objectSpread2$2({
11056
11587
  softDecode: this.softDecode,
11057
11588
  isLive: config.isLive,
11058
- media: this.player.video,
11589
+ media: mediaElem,
11059
11590
  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)) || {
11591
+ var _this2$player, _this2$player$preProc;
11592
+ 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
11593
  url,
11063
11594
  ext
11064
11595
  };
@@ -11077,7 +11608,8 @@
11077
11608
  }
11078
11609
  if (this.softDecode) {
11079
11610
  this.pluginExtension = new PluginExtension(_objectSpread2$2({
11080
- media: this.player.video
11611
+ media: this.player.video,
11612
+ isLive: config.isLive
11081
11613
  }, config.flv), this);
11082
11614
  this.player.forceDegradeToVideo = function() {
11083
11615
  var _this2$pluginExtensio;
@@ -11104,6 +11636,7 @@
11104
11636
  this._transCoreEvent(EVENT.LOAD_RETRY);
11105
11637
  this._transCoreEvent(EVENT.SOURCEBUFFER_CREATED);
11106
11638
  this._transCoreEvent(EVENT.ANALYZE_DURATION_EXCEEDED);
11639
+ this._transCoreEvent(EVENT.APPEND_BUFFER);
11107
11640
  this._transCoreEvent(EVENT.REMOVE_BUFFER);
11108
11641
  this._transCoreEvent(EVENT.BUFFEREOS);
11109
11642
  this._transCoreEvent(EVENT.KEYFRAME);