@volcengine/veplayer-plugin 2.5.0-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 (43) hide show
  1. package/esm/index.d.ts +0 -1
  2. package/esm/index.development.css +0 -7
  3. package/esm/index.development.js +47254 -53339
  4. package/esm/index.production.css +1 -1
  5. package/esm/index.production.js +4 -13
  6. package/esm/veplayer.plugin.abr.development.js +12 -0
  7. package/esm/veplayer.plugin.abr.production.js +1 -1
  8. package/esm/veplayer.plugin.drm.development.js +12 -0
  9. package/esm/veplayer.plugin.drm.production.js +1 -1
  10. package/esm/veplayer.plugin.flv.development.js +670 -193
  11. package/esm/veplayer.plugin.flv.production.js +1 -1
  12. package/esm/veplayer.plugin.hls.development.js +1155 -371
  13. package/esm/veplayer.plugin.hls.production.js +1 -1
  14. package/esm/veplayer.plugin.mp4.development.js +13 -1
  15. package/esm/veplayer.plugin.mp4.production.js +1 -1
  16. package/esm/veplayer.plugin.rtm.development.js +154 -45
  17. package/esm/veplayer.plugin.rtm.production.js +1 -1
  18. package/esm/veplayer.plugin.shaka.development.js +12 -0
  19. package/esm/veplayer.plugin.shaka.production.js +1 -1
  20. package/package.json +1 -1
  21. package/umd/index.d.ts +0 -1
  22. package/umd/veplayer.plugin.abr.development.js +12 -0
  23. package/umd/veplayer.plugin.abr.production.js +1 -1
  24. package/umd/veplayer.plugin.drm.development.js +12 -0
  25. package/umd/veplayer.plugin.drm.production.js +1 -1
  26. package/umd/veplayer.plugin.flv.development.js +670 -193
  27. package/umd/veplayer.plugin.flv.production.js +1 -1
  28. package/umd/veplayer.plugin.hls.development.js +1122 -338
  29. package/umd/veplayer.plugin.hls.production.js +1 -1
  30. package/umd/veplayer.plugin.mp4.development.js +13 -1
  31. package/umd/veplayer.plugin.mp4.production.js +1 -1
  32. package/umd/veplayer.plugin.rtm.development.js +154 -45
  33. package/umd/veplayer.plugin.rtm.production.js +1 -1
  34. package/umd/veplayer.plugin.shaka.development.js +12 -0
  35. package/umd/veplayer.plugin.shaka.production.js +1 -1
  36. package/esm/veplayer.plugin.ad.development.css +0 -7
  37. package/esm/veplayer.plugin.ad.development.js +0 -9042
  38. package/esm/veplayer.plugin.ad.production.css +0 -1
  39. package/esm/veplayer.plugin.ad.production.js +0 -4
  40. package/umd/veplayer.plugin.ad.development.css +0 -7
  41. package/umd/veplayer.plugin.ad.development.js +0 -9045
  42. package/umd/veplayer.plugin.ad.production.css +0 -1
  43. package/umd/veplayer.plugin.ad.production.js +0 -1
@@ -1538,7 +1538,7 @@ util.getCurrentTimeByOffset = function(offsetTime, segments) {
1538
1538
  }
1539
1539
  return offsetTime;
1540
1540
  };
1541
- var version = "3.0.20-alpha.4";
1541
+ var version = "3.0.21-rc.2";
1542
1542
  var ERROR_MAP = {
1543
1543
  1: 5101,
1544
1544
  2: 5102,
@@ -2005,6 +2005,18 @@ var BasePlugin = /* @__PURE__ */ function() {
2005
2005
  }
2006
2006
  }
2007
2007
  }
2008
+ }, {
2009
+ key: "defineMethod",
2010
+ value: function defineMethod(Obj, map) {
2011
+ for (var key in map) {
2012
+ if (Object.prototype.hasOwnProperty.call(map, key) && typeof map[key] === "function") {
2013
+ Object.defineProperty(Obj, key, {
2014
+ configurable: true,
2015
+ value: map[key]
2016
+ });
2017
+ }
2018
+ }
2019
+ }
2008
2020
  }, {
2009
2021
  key: "defaultConfig",
2010
2022
  get: function get() {
@@ -2815,6 +2827,21 @@ var Buffer$1 = /* @__PURE__ */ function() {
2815
2827
  length: Buffer2.totalLength && Buffer2.totalLength(buffers)
2816
2828
  };
2817
2829
  }
2830
+ }, {
2831
+ key: "isBuffered",
2832
+ value: function isBuffered(media, pos) {
2833
+ if (media) {
2834
+ var buffered = Buffer2.get(media);
2835
+ if (buffered !== null && buffered !== void 0 && buffered.length) {
2836
+ for (var i = 0; i < buffered.length; i++) {
2837
+ if (pos >= buffered.start(i) && pos <= buffered.end(i)) {
2838
+ return true;
2839
+ }
2840
+ }
2841
+ }
2842
+ }
2843
+ return false;
2844
+ }
2818
2845
  }]);
2819
2846
  return Buffer2;
2820
2847
  }();
@@ -2967,7 +2994,7 @@ var Logger$2 = /* @__PURE__ */ function() {
2967
2994
  this.logCache.apply(this, [LogCacheLevel.DEBUG].concat(args));
2968
2995
  if (Logger2.disabled)
2969
2996
  return;
2970
- (_console = console).debug.apply(_console, [this._prefix, nowTime$1()].concat(args));
2997
+ (_console = console).debug.apply(_console, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
2971
2998
  }
2972
2999
  }, {
2973
3000
  key: "log",
@@ -2979,7 +3006,7 @@ var Logger$2 = /* @__PURE__ */ function() {
2979
3006
  this.logCache.apply(this, [LogCacheLevel.LOG].concat(args));
2980
3007
  if (Logger2.disabled)
2981
3008
  return;
2982
- (_console2 = console).log.apply(_console2, [this._prefix, nowTime$1()].concat(args));
3009
+ (_console2 = console).log.apply(_console2, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
2983
3010
  }
2984
3011
  }, {
2985
3012
  key: "warn",
@@ -2991,7 +3018,7 @@ var Logger$2 = /* @__PURE__ */ function() {
2991
3018
  this.logCache.apply(this, [LogCacheLevel.WARN].concat(args));
2992
3019
  if (Logger2.disabled)
2993
3020
  return;
2994
- (_console3 = console).warn.apply(_console3, [this._prefix, nowTime$1()].concat(args));
3021
+ (_console3 = console).warn.apply(_console3, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
2995
3022
  }
2996
3023
  }, {
2997
3024
  key: "error",
@@ -3003,7 +3030,7 @@ var Logger$2 = /* @__PURE__ */ function() {
3003
3030
  this.logCache.apply(this, [LogCacheLevel.ERROR].concat(args));
3004
3031
  if (Logger2.disabled)
3005
3032
  return;
3006
- (_console4 = console).error.apply(_console4, [this._prefix, nowTime$1()].concat(args));
3033
+ (_console4 = console).error.apply(_console4, ["[".concat(nowTime$1(), "]"), this._prefix].concat(args));
3007
3034
  }
3008
3035
  }, {
3009
3036
  key: "logCache",
@@ -3018,7 +3045,7 @@ var Logger$2 = /* @__PURE__ */ function() {
3018
3045
  var finLogText = logText.map(function(item) {
3019
3046
  return logable(item);
3020
3047
  });
3021
- text = this._prefix + nowTime$1() + JSON.stringify(finLogText);
3048
+ text = "[".concat(nowTime$1(), "]") + this._prefix + JSON.stringify(finLogText);
3022
3049
  } catch (e) {
3023
3050
  return;
3024
3051
  }
@@ -3934,8 +3961,8 @@ function createResponse(data, done, response, contentLength, age, startTime, fir
3934
3961
  response
3935
3962
  };
3936
3963
  }
3937
- function calculateSpeed(byteLen, millisec) {
3938
- return Math.round(byteLen * 8 * 1e3 / millisec / 1024);
3964
+ function calculateSpeed(byteLen, milliSecond) {
3965
+ return Math.round(byteLen * 8 * 1e3 / milliSecond / 1024);
3939
3966
  }
3940
3967
  var EVENT = {
3941
3968
  ERROR: "error",
@@ -3947,6 +3974,7 @@ var EVENT = {
3947
3974
  SOURCEBUFFER_CREATED: "core.sourcebuffercreated",
3948
3975
  MEDIASOURCE_OPENED: "core.mediasourceopened",
3949
3976
  ANALYZE_DURATION_EXCEEDED: "core.analyzedurationexceeded",
3977
+ APPEND_BUFFER: "core.appendbuffer",
3950
3978
  REMOVE_BUFFER: "core.removebuffer",
3951
3979
  BUFFEREOS: "core.buffereos",
3952
3980
  KEYFRAME: "core.keyframe",
@@ -5579,13 +5607,16 @@ var TrackType = {
5579
5607
  METADATA: "metadata"
5580
5608
  };
5581
5609
  var VideoCodecType = {
5610
+ AV1: "av1",
5582
5611
  AVC: "avc",
5583
5612
  HEVC: "hevc"
5584
5613
  };
5585
5614
  var AudioCodecType = {
5586
5615
  AAC: "aac",
5587
5616
  G711PCMA: "g7110a",
5588
- G711PCMU: "g7110m"
5617
+ G711PCMU: "g7110m",
5618
+ OPUS: "opus",
5619
+ MP3: "mp3"
5589
5620
  };
5590
5621
  var WarningType = {
5591
5622
  LARGE_AV_SHIFT: "LARGE_AV_SHIFT",
@@ -5625,6 +5656,7 @@ var VideoTrack = /* @__PURE__ */ function() {
5625
5656
  _defineProperty(this, "isVideoEncryption", false);
5626
5657
  _defineProperty(this, "isAudioEncryption", false);
5627
5658
  _defineProperty(this, "isVideo", true);
5659
+ _defineProperty(this, "lastKeyFrameDts", 0);
5628
5660
  _defineProperty(this, "kid", null);
5629
5661
  _defineProperty(this, "pssh", null);
5630
5662
  _defineProperty(this, "ext", void 0);
@@ -5667,6 +5699,9 @@ var VideoTrack = /* @__PURE__ */ function() {
5667
5699
  }, {
5668
5700
  key: "exist",
5669
5701
  value: function exist() {
5702
+ if (/av01/.test(this.codec)) {
5703
+ return true;
5704
+ }
5670
5705
  return !!(this.pps.length && this.sps.length && this.codec);
5671
5706
  }
5672
5707
  }, {
@@ -5690,6 +5725,7 @@ var AudioTrack = /* @__PURE__ */ function() {
5690
5725
  _defineProperty(this, "codecType", AudioCodecType.AAC);
5691
5726
  _defineProperty(this, "pid", -1);
5692
5727
  _defineProperty(this, "codec", "");
5728
+ _defineProperty(this, "container", "");
5693
5729
  _defineProperty(this, "sequenceNumber", 0);
5694
5730
  _defineProperty(this, "sampleDuration", 0);
5695
5731
  _defineProperty(this, "timescale", 0);
@@ -5730,7 +5766,7 @@ var AudioTrack = /* @__PURE__ */ function() {
5730
5766
  }, {
5731
5767
  key: "exist",
5732
5768
  value: function exist() {
5733
- return !!(this.sampleRate && this.channelCount && this.codec && this.codecType === AudioCodecType.AAC);
5769
+ 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));
5734
5770
  }
5735
5771
  }, {
5736
5772
  key: "hasSample",
@@ -5944,7 +5980,7 @@ var AAC = /* @__PURE__ */ function() {
5944
5980
  continue;
5945
5981
  }
5946
5982
  frameLength = (data[i + 3] & 3) << 11 | data[i + 4] << 3 | (data[i + 5] & 224) >> 5;
5947
- if (len - i < frameLength)
5983
+ if (!frameLength || len - i < frameLength)
5948
5984
  break;
5949
5985
  protectionSkipBytes = (~data[i + 1] & 1) * 2;
5950
5986
  frames.push({
@@ -6078,14 +6114,57 @@ var AAC = /* @__PURE__ */ function() {
6078
6114
  return AAC2;
6079
6115
  }();
6080
6116
  _defineProperty(AAC, "FREQ", [96e3, 88200, 64e3, 48e3, 44100, 32e3, 24e3, 22050, 16e3, 12e3, 11025, 8e3, 7350]);
6117
+ var OPUS = /* @__PURE__ */ function() {
6118
+ function OPUS2() {
6119
+ _classCallCheck$1(this, OPUS2);
6120
+ }
6121
+ _createClass$1(OPUS2, null, [{
6122
+ key: "getFrameDuration",
6123
+ value: function getFrameDuration(samples) {
6124
+ return 20;
6125
+ }
6126
+ }, {
6127
+ key: "parseHeaderPackets",
6128
+ value: function parseHeaderPackets(data) {
6129
+ if (!data.length)
6130
+ return;
6131
+ var dv = new DataView(data.buffer, data.byteOffset, data.byteLength);
6132
+ var magicSignature = "";
6133
+ for (var i = 0; i < 8; i++) {
6134
+ magicSignature += String.fromCodePoint(data[i]);
6135
+ }
6136
+ if (magicSignature !== "OpusHead") {
6137
+ throw new Error("Invalid Opus MagicSignature");
6138
+ }
6139
+ var channelCount = data[9];
6140
+ console.log("Pre-skip", data[10], data[11]);
6141
+ var sampleRate = dv.getUint32(12, true);
6142
+ var outputGain = dv.getInt16(16, true);
6143
+ if (!sampleRate)
6144
+ return;
6145
+ var codec = "opus";
6146
+ var originCodec = "opus";
6147
+ var config = new Uint8Array(data.buffer, data.byteOffset + 8, data.byteLength - 8);
6148
+ return {
6149
+ outputGain,
6150
+ sampleRate,
6151
+ channelCount,
6152
+ config,
6153
+ codec,
6154
+ originCodec
6155
+ };
6156
+ }
6157
+ }]);
6158
+ return OPUS2;
6159
+ }();
6081
6160
  var LARGE_AV_FIRST_FRAME_GAP = 500;
6082
6161
  var AUDIO_GAP_OVERLAP_THRESHOLD_COUNT = 3;
6083
6162
  var MAX_SILENT_FRAME_DURATION = 1e3;
6084
- var AUDIO_EXCETION_LOG_EMIT_DURATION = 5e3;
6163
+ var AUDIO_EXCEPTION_LOG_EMIT_DURATION = 5e3;
6085
6164
  var MAX_VIDEO_FRAME_DURATION = 1e3;
6086
6165
  var MAX_DTS_DELTA_WITH_NEXT_CHUNK = 200;
6087
- var VIDEO_EXCETION_LOG_EMIT_DURATION = 5e3;
6088
- var TRACK_BREACKED_CHECK_TIME = 5;
6166
+ var VIDEO_EXCEPTION_LOG_EMIT_DURATION = 5e3;
6167
+ var TRACK_BROKEN_CHECK_TIME = 5;
6089
6168
  var FlvFixer = /* @__PURE__ */ function() {
6090
6169
  function FlvFixer2(videoTrack, audioTrack, metadataTrack) {
6091
6170
  _classCallCheck$1(this, FlvFixer2);
@@ -6201,7 +6280,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6201
6280
  var firstSample = samples[0];
6202
6281
  var vDelta = this._videoNextDts - firstSample.dts;
6203
6282
  if (Math.abs(vDelta) > MAX_DTS_DELTA_WITH_NEXT_CHUNK) {
6204
- if (Math.abs(firstSample.dts - this._lastVideoExceptionChunkFirstDtsDot) > VIDEO_EXCETION_LOG_EMIT_DURATION) {
6283
+ if (Math.abs(firstSample.dts - this._lastVideoExceptionChunkFirstDtsDot) > VIDEO_EXCEPTION_LOG_EMIT_DURATION) {
6205
6284
  var _samples$;
6206
6285
  this._lastVideoExceptionChunkFirstDtsDot = firstSample.dts;
6207
6286
  videoTrack.warnings.push({
@@ -6212,7 +6291,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6212
6291
  sampleDuration: vDelta
6213
6292
  });
6214
6293
  }
6215
- if (this._videoTimestampBreak >= TRACK_BREACKED_CHECK_TIME) {
6294
+ if (this._videoTimestampBreak >= TRACK_BROKEN_CHECK_TIME) {
6216
6295
  this._videoNextDts = firstSample.dts;
6217
6296
  this._videoTimestampBreak = 0;
6218
6297
  } else {
@@ -6235,7 +6314,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6235
6314
  }
6236
6315
  if (sampleDuration > MAX_VIDEO_FRAME_DURATION || sampleDuration < 0) {
6237
6316
  this._videoTimestampBreak++;
6238
- if (Math.abs(dts - this._lastVideoExceptionLargeGapDot) > VIDEO_EXCETION_LOG_EMIT_DURATION) {
6317
+ if (Math.abs(dts - this._lastVideoExceptionLargeGapDot) > VIDEO_EXCEPTION_LOG_EMIT_DURATION) {
6239
6318
  this._lastVideoExceptionLargeGapDot = dts;
6240
6319
  videoTrack.warnings.push({
6241
6320
  type: WarningType.LARGE_VIDEO_GAP,
@@ -6316,10 +6395,27 @@ var FlvFixer = /* @__PURE__ */ function() {
6316
6395
  key: "_doFixAudioInternal",
6317
6396
  value: function _doFixAudioInternal(audioTrack, samples, timescale) {
6318
6397
  if (!audioTrack.sampleDuration) {
6319
- audioTrack.sampleDuration = audioTrack.codecType === AudioCodecType.AAC ? AAC.getFrameDuration(audioTrack.timescale, timescale) : this._getG711Duration(audioTrack);
6398
+ switch (audioTrack.codecType) {
6399
+ case AudioCodecType.AAC: {
6400
+ audioTrack.sampleDuration = AAC.getFrameDuration(audioTrack.timescale, timescale);
6401
+ break;
6402
+ }
6403
+ case AudioCodecType.OPUS: {
6404
+ audioTrack.sampleDuration = OPUS.getFrameDuration(audioTrack.samples, timescale);
6405
+ break;
6406
+ }
6407
+ case AudioCodecType.G711PCMA:
6408
+ case AudioCodecType.G711PCMU: {
6409
+ audioTrack.sampleDuration = this._getG711Duration(audioTrack);
6410
+ break;
6411
+ }
6412
+ default:
6413
+ console.error("can't fix audio codecType:", audioTrack.codecType);
6414
+ break;
6415
+ }
6320
6416
  }
6321
6417
  var refSampleDuration = audioTrack.sampleDuration;
6322
- var sampleDurationInSampleRate = audioTrack.codecType === AudioCodecType.AAC ? 1024 : refSampleDuration * audioTrack.timescale / 1e3;
6418
+ var sampleDurationInSampleRate = audioTrack.codecType === AudioCodecType.OPUS ? 20 : audioTrack.codecType === AudioCodecType.AAC ? 1024 : refSampleDuration * audioTrack.timescale / 1e3;
6323
6419
  if (this._audioNextPts === void 0) {
6324
6420
  var samp0 = samples[0];
6325
6421
  this._audioNextPts = samp0.pts;
@@ -6328,7 +6424,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6328
6424
  var nextPts = this._audioNextPts;
6329
6425
  var sample = samples[i];
6330
6426
  var delta = sample.pts - nextPts;
6331
- if (i === 0 && this._audioTimestampBreak >= TRACK_BREACKED_CHECK_TIME && this._keyFrameInNextChunk) {
6427
+ if (i === 0 && this._audioTimestampBreak >= TRACK_BROKEN_CHECK_TIME && this._keyFrameInNextChunk) {
6332
6428
  nextPts = this._audioNextPts = sample.dts;
6333
6429
  delta = 0;
6334
6430
  this._audioTimestampBreak = 0;
@@ -6336,7 +6432,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6336
6432
  if (!this._audioTimestampBreak && delta >= AUDIO_GAP_OVERLAP_THRESHOLD_COUNT * refSampleDuration && delta <= MAX_SILENT_FRAME_DURATION && !isSafari) {
6337
6433
  var silentFrame = this._getSilentFrame(audioTrack) || samples[0].data.subarray();
6338
6434
  var count = Math.floor(delta / refSampleDuration);
6339
- if (Math.abs(sample.pts - this._lastAudioExceptionGapDot) > AUDIO_EXCETION_LOG_EMIT_DURATION) {
6435
+ if (Math.abs(sample.pts - this._lastAudioExceptionGapDot) > AUDIO_EXCEPTION_LOG_EMIT_DURATION) {
6340
6436
  this._lastAudioExceptionGapDot = sample.pts;
6341
6437
  audioTrack.warnings.push({
6342
6438
  type: WarningType.AUDIO_FILLED,
@@ -6356,7 +6452,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6356
6452
  }
6357
6453
  i--;
6358
6454
  } else if (delta <= -AUDIO_GAP_OVERLAP_THRESHOLD_COUNT * refSampleDuration && delta >= -1 * MAX_SILENT_FRAME_DURATION) {
6359
- if (Math.abs(sample.pts - this._lastAudioExceptionOverlapDot) > AUDIO_EXCETION_LOG_EMIT_DURATION) {
6455
+ if (Math.abs(sample.pts - this._lastAudioExceptionOverlapDot) > AUDIO_EXCEPTION_LOG_EMIT_DURATION) {
6360
6456
  this._lastAudioExceptionOverlapDot = sample.pts;
6361
6457
  audioTrack.warnings.push({
6362
6458
  type: WarningType.AUDIO_DROPPED,
@@ -6371,7 +6467,7 @@ var FlvFixer = /* @__PURE__ */ function() {
6371
6467
  } else {
6372
6468
  if (Math.abs(delta) > MAX_SILENT_FRAME_DURATION) {
6373
6469
  this._audioTimestampBreak++;
6374
- if (Math.abs(sample.pts - this._lastAudioExceptionLargeGapDot) > AUDIO_EXCETION_LOG_EMIT_DURATION) {
6470
+ if (Math.abs(sample.pts - this._lastAudioExceptionLargeGapDot) > AUDIO_EXCEPTION_LOG_EMIT_DURATION) {
6375
6471
  this._lastAudioExceptionLargeGapDot = sample.pts;
6376
6472
  audioTrack.warnings.push({
6377
6473
  type: WarningType.LARGE_AUDIO_GAP,
@@ -6384,8 +6480,15 @@ var FlvFixer = /* @__PURE__ */ function() {
6384
6480
  });
6385
6481
  }
6386
6482
  }
6387
- sample.dts = sample.pts = nextPts;
6388
- sample.duration = sampleDurationInSampleRate;
6483
+ if (audioTrack.codecType === AudioCodecType.OPUS) {
6484
+ var lastSample = samples[samples.length - 1];
6485
+ if (lastSample) {
6486
+ lastSample.duration = sample.pts - lastSample.pts;
6487
+ }
6488
+ } else {
6489
+ sample.dts = sample.pts = nextPts;
6490
+ sample.duration = sampleDurationInSampleRate;
6491
+ }
6389
6492
  this._audioNextPts += refSampleDuration;
6390
6493
  }
6391
6494
  }
@@ -7344,6 +7447,13 @@ var AMF = /* @__PURE__ */ function() {
7344
7447
  }]);
7345
7448
  return AMF2;
7346
7449
  }();
7450
+ var FlvSoundFormat = {
7451
+ MP3: 2,
7452
+ G711A: 7,
7453
+ G711M: 8,
7454
+ AAC: 10,
7455
+ OPUS: 13
7456
+ };
7347
7457
  var logger$2 = new Logger$1("FlvDemuxer");
7348
7458
  var FlvDemuxer = /* @__PURE__ */ function() {
7349
7459
  function FlvDemuxer2(videoTrack, audioTrack, metadataTrack) {
@@ -7360,8 +7470,10 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7360
7470
  _createClass$1(FlvDemuxer2, [{
7361
7471
  key: "demux",
7362
7472
  value: function demux(data) {
7473
+ var _scriptDataObject$dat;
7363
7474
  var discontinuity = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
7364
7475
  var contiguous = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
7476
+ var seamlessLoadingSwitching = arguments.length > 3 ? arguments[3] : void 0;
7365
7477
  var audioTrack = this.audioTrack, videoTrack = this.videoTrack, metadataTrack = this.metadataTrack;
7366
7478
  if (discontinuity || !contiguous) {
7367
7479
  this._remainingData = null;
@@ -7419,6 +7531,8 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7419
7531
  if (tagType === 8) {
7420
7532
  this._parseAudio(bodyData, timestamp);
7421
7533
  } else if (tagType === 9) {
7534
+ if (seamlessLoadingSwitching)
7535
+ this.seamlessLoadingSwitching = true;
7422
7536
  this._parseVideo(bodyData, timestamp);
7423
7537
  } else if (tagType === 18) {
7424
7538
  this._parseScript(bodyData, timestamp);
@@ -7436,13 +7550,31 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7436
7550
  this._remainingData = data.subarray(offset);
7437
7551
  }
7438
7552
  audioTrack.formatTimescale = videoTrack.formatTimescale = videoTrack.timescale = metadataTrack.timescale = 1e3;
7439
- audioTrack.timescale = audioTrack.sampleRate || 0;
7553
+ audioTrack.timescale = audioTrack.codecType === AudioCodecType.OPUS ? 1e3 : audioTrack.sampleRate || 0;
7440
7554
  if (!audioTrack.exist() && audioTrack.hasSample()) {
7441
7555
  audioTrack.reset();
7442
7556
  }
7443
7557
  if (!videoTrack.exist() && videoTrack.hasSample()) {
7444
7558
  videoTrack.reset();
7445
7559
  }
7560
+ var scriptDataObject = metadataTrack.flvScriptSamples[metadataTrack.flvScriptSamples.length - 1];
7561
+ var metaData = scriptDataObject === null || scriptDataObject === void 0 ? void 0 : (_scriptDataObject$dat = scriptDataObject.data) === null || _scriptDataObject$dat === void 0 ? void 0 : _scriptDataObject$dat.onMetaData;
7562
+ if (metaData) {
7563
+ if (videoTrack !== null && videoTrack !== void 0 && videoTrack.exist()) {
7564
+ if (metaData.hasOwnProperty("duration")) {
7565
+ videoTrack.duration = metaData.duration * 1e3;
7566
+ }
7567
+ if (metaData.hasOwnProperty("width") && metaData.hasOwnProperty("height")) {
7568
+ videoTrack.width = metaData.width;
7569
+ videoTrack.height = metaData.height;
7570
+ }
7571
+ }
7572
+ if (audioTrack !== null && audioTrack !== void 0 && audioTrack.exist()) {
7573
+ if (metaData.hasOwnProperty("duration")) {
7574
+ audioTrack.duration = metaData.duration * 1e3;
7575
+ }
7576
+ }
7577
+ }
7446
7578
  return {
7447
7579
  videoTrack,
7448
7580
  audioTrack,
@@ -7461,8 +7593,8 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7461
7593
  }
7462
7594
  }, {
7463
7595
  key: "demuxAndFix",
7464
- value: function demuxAndFix(data, discontinuity, contiguous, startTime) {
7465
- this.demux(data, discontinuity, contiguous);
7596
+ value: function demuxAndFix(data, discontinuity, contiguous, startTime, seamlessLoadingSwitching) {
7597
+ this.demux(data, discontinuity, contiguous, seamlessLoadingSwitching);
7466
7598
  return this.fix(startTime, discontinuity, contiguous);
7467
7599
  }
7468
7600
  }, {
@@ -7472,12 +7604,12 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7472
7604
  return;
7473
7605
  var format = (data[0] & 240) >>> 4;
7474
7606
  var track = this.audioTrack;
7475
- if (format !== 10 && format !== 7 && format !== 8) {
7607
+ if (format !== FlvSoundFormat.AAC && format !== FlvSoundFormat.G711A && format !== FlvSoundFormat.G711M && format !== FlvSoundFormat.OPUS) {
7476
7608
  logger$2.warn("Unsupported sound format: ".concat(format));
7477
7609
  track.reset();
7478
7610
  return;
7479
7611
  }
7480
- if (format !== 10) {
7612
+ if (format !== FlvSoundFormat.AAC && format !== FlvSoundFormat.OPUS) {
7481
7613
  var soundRate = (data[0] & 12) >> 2;
7482
7614
  var soundSize = (data[0] & 2) >> 1;
7483
7615
  var soundType = data[0] & 1;
@@ -7485,10 +7617,49 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7485
7617
  track.sampleSize = soundSize ? 16 : 8;
7486
7618
  track.channelCount = soundType + 1;
7487
7619
  }
7488
- if (format === 10) {
7489
- this._parseAac(data, pts);
7490
- } else {
7491
- this._parseG711(data, pts, format);
7620
+ switch (format) {
7621
+ case FlvSoundFormat.G711A:
7622
+ case FlvSoundFormat.G711M:
7623
+ this._parseG711(data, pts, format);
7624
+ break;
7625
+ case FlvSoundFormat.AAC:
7626
+ this._parseAac(data, pts);
7627
+ break;
7628
+ case FlvSoundFormat.OPUS:
7629
+ this._parseOpus(data, pts);
7630
+ break;
7631
+ }
7632
+ }
7633
+ }, {
7634
+ key: "_parseOpus",
7635
+ value: function _parseOpus(data, pts) {
7636
+ var track = this.audioTrack;
7637
+ var packetType = data[1];
7638
+ track.codecType = AudioCodecType.OPUS;
7639
+ switch (packetType) {
7640
+ case 0: {
7641
+ var ret = OPUS.parseHeaderPackets(data.subarray(2));
7642
+ if (ret) {
7643
+ track.codec = ret.codec;
7644
+ track.channelCount = ret.channelCount;
7645
+ track.sampleRate = ret.sampleRate;
7646
+ track.config = ret.config;
7647
+ track.sampleDuration = OPUS.getFrameDuration([], track.timescale);
7648
+ } else {
7649
+ track.reset();
7650
+ logger$2.warn("Cannot parse AudioSpecificConfig", data);
7651
+ }
7652
+ break;
7653
+ }
7654
+ case 1: {
7655
+ if (pts === void 0 || pts === null)
7656
+ return;
7657
+ var newSample = new AudioSample(pts, data.subarray(2), track.sampleDuration);
7658
+ track.samples.push(newSample);
7659
+ break;
7660
+ }
7661
+ default:
7662
+ logger$2.warn("Unknown OpusPacketType: ".concat(packetType));
7492
7663
  }
7493
7664
  }
7494
7665
  }, {
@@ -7576,8 +7747,13 @@ var FlvDemuxer = /* @__PURE__ */ function() {
7576
7747
  units = this._checkAddMetaNalToUnits(isHevc, units, track);
7577
7748
  if (units && units.length) {
7578
7749
  var sample = new VideoSample(dts + cts, dts, units);
7750
+ if (this.seamlessLoadingSwitching && dts < track.lastKeyFrameDts) {
7751
+ return;
7752
+ }
7753
+ this.seamlessLoadingSwitching = false;
7579
7754
  if (frameType === 1) {
7580
7755
  sample.setToKeyframe();
7756
+ track.lastKeyFrameDts = dts;
7581
7757
  }
7582
7758
  track.samples.push(sample);
7583
7759
  units.forEach(function(unit) {
@@ -8051,10 +8227,16 @@ var MP4 = /* @__PURE__ */ function() {
8051
8227
  if (track.useEME && track.enca) {
8052
8228
  content = MP42.enca(track);
8053
8229
  } else {
8054
- content = MP42.mp4a(track);
8230
+ if (track.codecType === AudioCodecType.OPUS) {
8231
+ content = MP42.opus(track);
8232
+ } else {
8233
+ content = MP42.mp4a(track);
8234
+ }
8055
8235
  }
8056
8236
  } else if (track.useEME && track.encv) {
8057
8237
  content = MP42.encv(track);
8238
+ } else if (track.av1C) {
8239
+ content = MP42.av01(track);
8058
8240
  } else {
8059
8241
  content = MP42.avc1hev1(track);
8060
8242
  }
@@ -8267,6 +8449,90 @@ var MP4 = /* @__PURE__ */ function() {
8267
8449
  var schi = MP42.schi(data);
8268
8450
  return MP42.box(MP42.types.sinf, content, MP42.box(MP42.types.frma, frma), MP42.box(MP42.types.schm, schm), schi);
8269
8451
  }
8452
+ }, {
8453
+ key: "av01",
8454
+ value: function av01(track) {
8455
+ return MP42.box(MP42.types.av01, new Uint8Array([
8456
+ 0,
8457
+ 0,
8458
+ 0,
8459
+ 0,
8460
+ 0,
8461
+ 0,
8462
+ 0,
8463
+ 1,
8464
+ 0,
8465
+ 0,
8466
+ 0,
8467
+ 0,
8468
+ 0,
8469
+ 0,
8470
+ 0,
8471
+ 0,
8472
+ 0,
8473
+ 0,
8474
+ 0,
8475
+ 0,
8476
+ 0,
8477
+ 0,
8478
+ 0,
8479
+ 0,
8480
+ track.width >> 8 & 255,
8481
+ track.width & 255,
8482
+ track.height >> 8 & 255,
8483
+ track.height & 255,
8484
+ 0,
8485
+ 72,
8486
+ 0,
8487
+ 0,
8488
+ 0,
8489
+ 72,
8490
+ 0,
8491
+ 0,
8492
+ 0,
8493
+ 0,
8494
+ 0,
8495
+ 0,
8496
+ 0,
8497
+ 1,
8498
+ 0,
8499
+ 0,
8500
+ 0,
8501
+ 0,
8502
+ 0,
8503
+ 0,
8504
+ 0,
8505
+ 0,
8506
+ 0,
8507
+ 0,
8508
+ 0,
8509
+ 0,
8510
+ 0,
8511
+ 0,
8512
+ 0,
8513
+ 0,
8514
+ 0,
8515
+ 0,
8516
+ 0,
8517
+ 0,
8518
+ 0,
8519
+ 0,
8520
+ 0,
8521
+ 0,
8522
+ 0,
8523
+ 0,
8524
+ 0,
8525
+ 0,
8526
+ 0,
8527
+ 0,
8528
+ 0,
8529
+ 0,
8530
+ 0,
8531
+ 24,
8532
+ 17,
8533
+ 17
8534
+ ]), track.av1C, track.colr);
8535
+ }
8270
8536
  }, {
8271
8537
  key: "avc1hev1",
8272
8538
  value: function avc1hev1(track) {
@@ -8637,6 +8903,53 @@ var MP4 = /* @__PURE__ */ function() {
8637
8903
  )));
8638
8904
  return esds2;
8639
8905
  }
8906
+ }, {
8907
+ key: "opus",
8908
+ value: function opus(track) {
8909
+ var opusAudioDescription = new Uint8Array([
8910
+ 0,
8911
+ 0,
8912
+ 0,
8913
+ 0,
8914
+ 0,
8915
+ 0,
8916
+ 0,
8917
+ 1,
8918
+ 0,
8919
+ 0,
8920
+ 0,
8921
+ 0,
8922
+ 0,
8923
+ 0,
8924
+ 0,
8925
+ 0,
8926
+ 0,
8927
+ track.channelCount,
8928
+ 0,
8929
+ 16,
8930
+ 0,
8931
+ 0,
8932
+ 0,
8933
+ 0,
8934
+ track.sampleRate >> 8 & 255,
8935
+ track.sampleRate & 255,
8936
+ 0,
8937
+ 0
8938
+ ]);
8939
+ var opusSpecificConfig = track.config.length ? MP42.dOps(track) : [];
8940
+ return MP42.box(MP42.types.Opus, opusAudioDescription, opusSpecificConfig);
8941
+ }
8942
+ }, {
8943
+ key: "dOps",
8944
+ value: function dOps(track) {
8945
+ if (track.config) {
8946
+ track.config[4] = track.sampleRate >>> 24 & 255;
8947
+ track.config[5] = track.sampleRate >>> 16 & 255;
8948
+ track.config[6] = track.sampleRate >>> 8 & 255;
8949
+ track.config[7] = track.sampleRate & 255;
8950
+ return MP42.box(MP42.types.dOps, track.config);
8951
+ }
8952
+ }
8640
8953
  }, {
8641
8954
  key: "mvex",
8642
8955
  value: function mvex(tracks) {
@@ -9239,7 +9552,7 @@ var MP4 = /* @__PURE__ */ function() {
9239
9552
  }]);
9240
9553
  return MP42;
9241
9554
  }();
9242
- _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) {
9555
+ _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) {
9243
9556
  p[c] = [c.charCodeAt(0), c.charCodeAt(1), c.charCodeAt(2), c.charCodeAt(3)];
9244
9557
  return p;
9245
9558
  }, /* @__PURE__ */ Object.create(null)));
@@ -9574,30 +9887,46 @@ var FMP4Remuxer = /* @__PURE__ */ function() {
9574
9887
  };
9575
9888
  }
9576
9889
  var samples = track.samples;
9890
+ var isAV01 = /av01/.test(track.codec);
9577
9891
  var mdatSize = 0;
9578
- samples.forEach(function(s) {
9579
- mdatSize += s.units.reduce(function(t, c) {
9580
- return t + c.byteLength;
9581
- }, 0);
9582
- mdatSize += s.units.length * 4;
9583
- });
9584
- var mdata = new Uint8Array(mdatSize);
9585
- var mdatView = new DataView(mdata.buffer);
9586
- var _loop = function _loop2(_offset, _sample) {
9587
- _sample = samples[i];
9588
- var sampleSize = 0;
9589
- _sample.units.forEach(function(u) {
9590
- mdatView.setUint32(_offset, u.byteLength);
9591
- _offset += 4;
9592
- mdata.set(u, _offset);
9593
- _offset += u.byteLength;
9594
- sampleSize += 4 + u.byteLength;
9892
+ if (isAV01) {
9893
+ samples.forEach(function(s) {
9894
+ mdatSize += s.data.byteLength;
9895
+ });
9896
+ } else {
9897
+ samples.forEach(function(s) {
9898
+ mdatSize += s.units.reduce(function(t, c) {
9899
+ return t + c.byteLength;
9900
+ }, 0);
9901
+ mdatSize += s.units.length * 4;
9595
9902
  });
9596
- _sample.size = sampleSize;
9597
- offset = _offset, sample = _sample;
9598
- };
9599
- for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
9600
- _loop(offset, sample);
9903
+ }
9904
+ var mdata = new Uint8Array(mdatSize);
9905
+ if (isAV01) {
9906
+ for (var i = 0, l = samples.length, offset = 0, sample; i < l; i++) {
9907
+ sample = samples[i];
9908
+ mdata.set(sample.data, offset);
9909
+ sample.size = sample.data.byteLength;
9910
+ offset += sample.size;
9911
+ }
9912
+ } else {
9913
+ var mdatView = new DataView(mdata.buffer);
9914
+ var _loop = function _loop2(_offset2, _sample2) {
9915
+ _sample2 = samples[_i];
9916
+ var sampleSize = 0;
9917
+ _sample2.units.forEach(function(u) {
9918
+ mdatView.setUint32(_offset2, u.byteLength);
9919
+ _offset2 += 4;
9920
+ mdata.set(u, _offset2);
9921
+ _offset2 += u.byteLength;
9922
+ sampleSize += 4 + u.byteLength;
9923
+ });
9924
+ _sample2.size = sampleSize;
9925
+ _offset = _offset2, _sample = _sample2;
9926
+ };
9927
+ for (var _i = 0, _l = samples.length, _offset = 0, _sample; _i < _l; _i++) {
9928
+ _loop(_offset, _sample);
9929
+ }
9601
9930
  }
9602
9931
  var mdat = MP4.mdat(mdata);
9603
9932
  var moof = MP4.moof([track]);
@@ -9627,6 +9956,55 @@ var FMP4Remuxer = /* @__PURE__ */ function() {
9627
9956
  }]);
9628
9957
  return FMP4Remuxer2;
9629
9958
  }();
9959
+ var TransferCost = /* @__PURE__ */ function() {
9960
+ function TransferCost2() {
9961
+ _classCallCheck$4(this, TransferCost2);
9962
+ _defineProperty$3(this, "_ttfb", 0);
9963
+ _defineProperty$3(this, "_demuxStart", 0);
9964
+ _defineProperty$3(this, "_demuxEnd", 0);
9965
+ _defineProperty$3(this, "_demuxCost", 0);
9966
+ _defineProperty$3(this, "_remuxStart", 0);
9967
+ _defineProperty$3(this, "_remuxEnd", 0);
9968
+ _defineProperty$3(this, "_remuxCost", 0);
9969
+ _defineProperty$3(this, "_appendStart", 0);
9970
+ _defineProperty$3(this, "_appendEnd", 0);
9971
+ _defineProperty$3(this, "_appendCost", 0);
9972
+ }
9973
+ _createClass$4(TransferCost2, [{
9974
+ key: "set",
9975
+ value: function set(event, value) {
9976
+ this["_".concat(event)] = value;
9977
+ }
9978
+ }, {
9979
+ key: "start",
9980
+ value: function start(event) {
9981
+ this["_".concat(event, "Start")] = Date.now();
9982
+ }
9983
+ }, {
9984
+ key: "end",
9985
+ value: function end(event) {
9986
+ this["_".concat(event, "End")] = Date.now();
9987
+ this["_".concat(event, "Cost")] = this["_".concat(event, "Cost")] + (this["_".concat(event, "End")] - this["_".concat(event, "Start")]);
9988
+ }
9989
+ }, {
9990
+ key: "transferCost",
9991
+ get: function get() {
9992
+ return {
9993
+ ttfbCost: this._ttfb,
9994
+ demuxCost: this._demuxCost,
9995
+ remuxCost: this._remuxCost,
9996
+ appendCost: this._appendCost
9997
+ };
9998
+ }
9999
+ }]);
10000
+ return TransferCost2;
10001
+ }();
10002
+ var TRANSFER_EVENT = {
10003
+ TTFB: "ttfb",
10004
+ DEMUX: "demux",
10005
+ REMUX: "remux",
10006
+ APPEND: "append"
10007
+ };
9630
10008
  var logger$1 = new Logger$2("BufferService");
9631
10009
  var BufferService = /* @__PURE__ */ function() {
9632
10010
  function BufferService2(flv, softVideo) {
@@ -9714,7 +10092,8 @@ var BufferService = /* @__PURE__ */ function() {
9714
10092
  this._contiguous = false;
9715
10093
  this._sourceCreated = false;
9716
10094
  this._initSegmentId = "";
9717
- case 11:
10095
+ this.resetSeamlessSwitchStats();
10096
+ case 12:
9718
10097
  case "end":
9719
10098
  return _context.stop();
9720
10099
  }
@@ -9725,6 +10104,15 @@ var BufferService = /* @__PURE__ */ function() {
9725
10104
  }
9726
10105
  return reset;
9727
10106
  }()
10107
+ }, {
10108
+ key: "resetSeamlessSwitchStats",
10109
+ value: function resetSeamlessSwitchStats() {
10110
+ this.seamlessLoadingSwitch = null;
10111
+ this.seamlessLoadingSwitching = false;
10112
+ if (this._demuxer) {
10113
+ this._demuxer.seamlessLoadingSwitching = false;
10114
+ }
10115
+ }
9728
10116
  }, {
9729
10117
  key: "endOfStream",
9730
10118
  value: function() {
@@ -9830,32 +10218,56 @@ var BufferService = /* @__PURE__ */ function() {
9830
10218
  key: "appendBuffer",
9831
10219
  value: function() {
9832
10220
  var _appendBuffer = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee5(chunk) {
9833
- var demuxer, videoTrack, audioTrack, metadataTrack, videoExist, audioExist, duration, track, videoType, audioType, mse, newId, remuxResult, p;
10221
+ var _this = this;
10222
+ var switchingNoReset, demuxer, videoTrack, audioTrack, metadataTrack, idx, videoExist, audioExist, duration, track, videoType, audioType, mse, afterAppend, newId, remuxResult, p;
9834
10223
  return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
9835
10224
  while (1)
9836
10225
  switch (_context5.prev = _context5.next) {
9837
10226
  case 0:
10227
+ switchingNoReset = false;
9838
10228
  if (this._cachedBuffer) {
9839
10229
  chunk = concatUint8Array$1(this._cachedBuffer, chunk);
9840
10230
  this._cachedBuffer = null;
9841
10231
  }
9842
10232
  demuxer = this._demuxer;
9843
10233
  if (!(!chunk || !chunk.length || !demuxer)) {
9844
- _context5.next = 4;
10234
+ _context5.next = 5;
9845
10235
  break;
9846
10236
  }
9847
10237
  return _context5.abrupt("return");
9848
- case 4:
9849
- _context5.prev = 4;
9850
- demuxer.demuxAndFix(chunk, this._discontinuity, this._contiguous, this._demuxStartTime);
9851
- _context5.next = 11;
10238
+ case 5:
10239
+ _context5.prev = 5;
10240
+ this.flv._transferCost.start(TRANSFER_EVENT.DEMUX);
10241
+ demuxer.demuxAndFix(chunk, this.seamlessLoadingSwitching || this._discontinuity, this._contiguous, this._demuxStartTime, this.seamlessLoadingSwitching);
10242
+ this.seamlessLoadingSwitching = false;
10243
+ this.flv._transferCost.end(TRANSFER_EVENT.DEMUX);
10244
+ _context5.next = 15;
9852
10245
  break;
9853
- case 8:
9854
- _context5.prev = 8;
9855
- _context5.t0 = _context5["catch"](4);
10246
+ case 12:
10247
+ _context5.prev = 12;
10248
+ _context5.t0 = _context5["catch"](5);
9856
10249
  throw new StreamingError(ERR.DEMUX, ERR.SUB_TYPES.FLV, _context5.t0);
9857
- case 11:
10250
+ case 15:
9858
10251
  videoTrack = demuxer.videoTrack, audioTrack = demuxer.audioTrack, metadataTrack = demuxer.metadataTrack;
10252
+ if (!this.seamlessLoadingSwitch) {
10253
+ _context5.next = 25;
10254
+ break;
10255
+ }
10256
+ idx = videoTrack.samples.findIndex(function(sample) {
10257
+ return sample.originDts === videoTrack.lastKeyFrameDts;
10258
+ });
10259
+ if (!(idx >= 0)) {
10260
+ _context5.next = 25;
10261
+ break;
10262
+ }
10263
+ videoTrack.samples.splice(idx);
10264
+ _context5.next = 22;
10265
+ return this.seamlessLoadingSwitch();
10266
+ case 22:
10267
+ this.seamlessLoadingSwitch = null;
10268
+ chunk = null;
10269
+ switchingNoReset = true;
10270
+ case 25:
9859
10271
  videoExist = videoTrack.exist();
9860
10272
  audioExist = audioTrack.exist();
9861
10273
  if (this._opts.onlyAudio) {
@@ -9867,7 +10279,7 @@ var BufferService = /* @__PURE__ */ function() {
9867
10279
  audioTrack.present = false;
9868
10280
  }
9869
10281
  if (!(!videoExist && videoTrack.present || !audioExist && audioTrack.present)) {
9870
- _context5.next = 29;
10282
+ _context5.next = 42;
9871
10283
  break;
9872
10284
  }
9873
10285
  duration = 0;
@@ -9876,7 +10288,7 @@ var BufferService = /* @__PURE__ */ function() {
9876
10288
  duration = (track.samples[track.samples.length - 1].originPts - track.samples[0].originPts) / track.timescale * 1e3;
9877
10289
  }
9878
10290
  if (!(duration > this._opts.analyzeDuration)) {
9879
- _context5.next = 27;
10291
+ _context5.next = 40;
9880
10292
  break;
9881
10293
  }
9882
10294
  logger$1.warn("analyze duration exceeded, ".concat(duration, "ms"), track);
@@ -9885,19 +10297,28 @@ var BufferService = /* @__PURE__ */ function() {
9885
10297
  this.flv.emit(EVENT.ANALYZE_DURATION_EXCEEDED, {
9886
10298
  duration
9887
10299
  });
9888
- _context5.next = 29;
10300
+ _context5.next = 42;
9889
10301
  break;
9890
- case 27:
10302
+ case 40:
9891
10303
  this._cachedBuffer = chunk;
9892
10304
  return _context5.abrupt("return");
9893
- case 29:
10305
+ case 42:
9894
10306
  videoType = videoTrack.type;
9895
10307
  audioType = audioTrack.type;
9896
10308
  this._fireEvents(videoTrack, audioTrack, metadataTrack);
9897
- this._discontinuity = false;
9898
- this._contiguous = true;
9899
- this._demuxStartTime = 0;
10309
+ if (!switchingNoReset) {
10310
+ this._discontinuity = false;
10311
+ this._contiguous = true;
10312
+ this._demuxStartTime = 0;
10313
+ }
9900
10314
  mse = this._mse;
10315
+ afterAppend = function afterAppend2() {
10316
+ var _this$flv;
10317
+ if ((_this$flv = _this.flv) !== null && _this$flv !== void 0 && _this$flv.emit) {
10318
+ var _this$flv2;
10319
+ (_this$flv2 = _this.flv) === null || _this$flv2 === void 0 ? void 0 : _this$flv2.emit(EVENT.APPEND_BUFFER, {});
10320
+ }
10321
+ };
9901
10322
  this.flv.emit(EVENT.DEMUXED_TRACK, {
9902
10323
  videoTrack
9903
10324
  });
@@ -9908,16 +10329,16 @@ var BufferService = /* @__PURE__ */ function() {
9908
10329
  this._emitMetaParsedEvent(videoTrack, audioTrack);
9909
10330
  }
9910
10331
  if (!mse) {
9911
- _context5.next = 66;
10332
+ _context5.next = 81;
9912
10333
  break;
9913
10334
  }
9914
10335
  if (this._sourceCreated) {
9915
- _context5.next = 47;
10336
+ _context5.next = 59;
9916
10337
  break;
9917
10338
  }
9918
- _context5.next = 43;
10339
+ _context5.next = 55;
9919
10340
  return mse.open();
9920
- case 43:
10341
+ case 55:
9921
10342
  if (videoExist) {
9922
10343
  logger$1.log("codec: video/mp4;codecs=".concat(videoTrack.codec));
9923
10344
  mse.createSource(videoType, "video/mp4;codecs=".concat(videoTrack.codec));
@@ -9928,26 +10349,28 @@ var BufferService = /* @__PURE__ */ function() {
9928
10349
  }
9929
10350
  this._sourceCreated = true;
9930
10351
  this.flv.emit(EVENT.SOURCEBUFFER_CREATED);
9931
- case 47:
9932
- _context5.prev = 47;
10352
+ case 59:
10353
+ _context5.prev = 59;
9933
10354
  if (this._needInitSegment && !this._opts.mseLowLatency) {
9934
10355
  videoTrack.duration = this._opts.durationForMSELowLatencyOff * videoTrack.timescale;
9935
10356
  audioTrack.duration = this._opts.durationForMSELowLatencyOff * audioExist.timescale;
9936
10357
  }
10358
+ this.flv._transferCost.start(TRANSFER_EVENT.REMUX);
9937
10359
  remuxResult = this._remuxer.remux(this._needInitSegment);
9938
- _context5.next = 55;
10360
+ this.flv._transferCost.end(TRANSFER_EVENT.REMUX);
10361
+ _context5.next = 69;
9939
10362
  break;
9940
- case 52:
9941
- _context5.prev = 52;
9942
- _context5.t1 = _context5["catch"](47);
10363
+ case 66:
10364
+ _context5.prev = 66;
10365
+ _context5.t1 = _context5["catch"](59);
9943
10366
  throw new StreamingError(ERR.REMUX, ERR.SUB_TYPES.FMP4, _context5.t1);
9944
- case 55:
10367
+ case 69:
9945
10368
  if (!(this._needInitSegment && !remuxResult.videoInitSegment && !remuxResult.audioInitSegment)) {
9946
- _context5.next = 57;
10369
+ _context5.next = 71;
9947
10370
  break;
9948
10371
  }
9949
10372
  return _context5.abrupt("return");
9950
- case 57:
10373
+ case 71:
9951
10374
  this._needInitSegment = false;
9952
10375
  p = [];
9953
10376
  if (remuxResult.videoInitSegment)
@@ -9958,16 +10381,21 @@ var BufferService = /* @__PURE__ */ function() {
9958
10381
  p.push(mse.append(videoType, remuxResult.videoSegment));
9959
10382
  if (remuxResult.audioSegment)
9960
10383
  p.push(mse.append(audioType, remuxResult.audioSegment));
9961
- return _context5.abrupt("return", Promise.all(p));
9962
- case 66:
10384
+ this.flv._transferCost.start(TRANSFER_EVENT.APPEND);
10385
+ return _context5.abrupt("return", Promise.all(p).then(afterAppend).then(function() {
10386
+ _this.flv._transferCost.end(TRANSFER_EVENT.APPEND);
10387
+ afterAppend();
10388
+ }));
10389
+ case 81:
9963
10390
  if (this._softVideo) {
9964
10391
  this._softVideo.appendBuffer(videoTrack, audioTrack);
10392
+ afterAppend();
9965
10393
  }
9966
- case 67:
10394
+ case 82:
9967
10395
  case "end":
9968
10396
  return _context5.stop();
9969
10397
  }
9970
- }, _callee5, this, [[4, 8], [47, 52]]);
10398
+ }, _callee5, this, [[5, 12], [59, 66]]);
9971
10399
  }));
9972
10400
  function appendBuffer(_x2) {
9973
10401
  return _appendBuffer.apply(this, arguments);
@@ -9978,7 +10406,7 @@ var BufferService = /* @__PURE__ */ function() {
9978
10406
  key: "evictBuffer",
9979
10407
  value: function() {
9980
10408
  var _evictBuffer = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee6(bufferBehind) {
9981
- var _this = this;
10409
+ var _this2 = this;
9982
10410
  var media, currentTime, removeEnd, start;
9983
10411
  return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
9984
10412
  while (1)
@@ -10007,7 +10435,7 @@ var BufferService = /* @__PURE__ */ function() {
10007
10435
  return _context6.abrupt("return");
10008
10436
  case 10:
10009
10437
  return _context6.abrupt("return", this._mse.clearBuffer(0, removeEnd).then(function() {
10010
- return _this.flv.emit(EVENT.REMOVE_BUFFER, {
10438
+ return _this2.flv.emit(EVENT.REMOVE_BUFFER, {
10011
10439
  removeEnd
10012
10440
  });
10013
10441
  }));
@@ -10057,16 +10485,16 @@ var BufferService = /* @__PURE__ */ function() {
10057
10485
  }, {
10058
10486
  key: "_fireEvents",
10059
10487
  value: function _fireEvents(videoTrack, audioTrack, metadataTrack) {
10060
- var _this2 = this;
10061
- logger$1.debug(videoTrack.samples, audioTrack.samples);
10488
+ var _this3 = this;
10489
+ logger$1.debug("videoTrack samples count: ".concat(videoTrack.samples.length, ", audioTrack samples count: ").concat(audioTrack.samples.length));
10062
10490
  metadataTrack.flvScriptSamples.forEach(function(sample) {
10063
- _this2.flv.emit(EVENT.FLV_SCRIPT_DATA, sample);
10491
+ _this3.flv.emit(EVENT.FLV_SCRIPT_DATA, sample);
10064
10492
  logger$1.debug("flvScriptData", sample);
10065
10493
  });
10066
10494
  videoTrack.samples.forEach(function(sample) {
10067
10495
  if (sample.keyframe) {
10068
- _this2.flv.emit(EVENT.KEYFRAME, {
10069
- pts: sample.pts
10496
+ _this3.flv.emit(EVENT.KEYFRAME, {
10497
+ pts: sample.originPts
10070
10498
  });
10071
10499
  }
10072
10500
  });
@@ -10084,7 +10512,7 @@ var BufferService = /* @__PURE__ */ function() {
10084
10512
  break;
10085
10513
  }
10086
10514
  if (type)
10087
- _this2.flv.emit(EVENT.STREAM_EXCEPTION, _objectSpread2$2(_objectSpread2$2({}, warn), {}, {
10515
+ _this3.flv.emit(EVENT.STREAM_EXCEPTION, _objectSpread2$2(_objectSpread2$2({}, warn), {}, {
10088
10516
  type
10089
10517
  }));
10090
10518
  logger$1.warn("video exception", warn);
@@ -10103,13 +10531,13 @@ var BufferService = /* @__PURE__ */ function() {
10103
10531
  break;
10104
10532
  }
10105
10533
  if (type)
10106
- _this2.flv.emit(EVENT.STREAM_EXCEPTION, _objectSpread2$2(_objectSpread2$2({}, warn), {}, {
10534
+ _this3.flv.emit(EVENT.STREAM_EXCEPTION, _objectSpread2$2(_objectSpread2$2({}, warn), {}, {
10107
10535
  type
10108
10536
  }));
10109
10537
  logger$1.warn("audio exception", warn);
10110
10538
  });
10111
10539
  metadataTrack.seiSamples.forEach(function(sei) {
10112
- _this2.flv.emit(EVENT.SEI, _objectSpread2$2(_objectSpread2$2({}, sei), {}, {
10540
+ _this3.flv.emit(EVENT.SEI, _objectSpread2$2(_objectSpread2$2({}, sei), {}, {
10113
10541
  sei: {
10114
10542
  code: sei.data.type,
10115
10543
  content: sei.data.payload,
@@ -10144,7 +10572,8 @@ function getOption(opts) {
10144
10572
  durationForMSELowLatencyOff: 6,
10145
10573
  chunkCountForSpeed: 50,
10146
10574
  skipChunkSize: 1e3,
10147
- longtimeNoReceived: 3e3
10575
+ longtimeNoReceived: 3e3,
10576
+ enableStartGapJump: true
10148
10577
  }, opts);
10149
10578
  if (ret.isLive) {
10150
10579
  if (ret.preloadTime) {
@@ -10212,7 +10641,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10212
10641
  _defineProperty$3(_assertThisInitialized$3(_this), "_acceptRanges", true);
10213
10642
  _defineProperty$3(_assertThisInitialized$3(_this), "_onProgress", /* @__PURE__ */ function() {
10214
10643
  var _ref2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee(chunk, done, _ref, response) {
10215
- var startTime, endTime, st, firstByteTime, _this$_mediaLoader, headers, _this$_bufferService, remaining, maxReaderInterval;
10644
+ var startTime, endTime, st, firstByteTime, _this$_mediaLoader, headers, elapsed, _this$_bufferService, remaining, maxReaderInterval;
10216
10645
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
10217
10646
  while (1)
10218
10647
  switch (_context.prev = _context.next) {
@@ -10220,7 +10649,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10220
10649
  startTime = _ref.startTime, endTime = _ref.endTime, st = _ref.st, firstByteTime = _ref.firstByteTime;
10221
10650
  _this._loading = !done;
10222
10651
  if (_this._firstProgressEmit) {
10223
- _context.next = 11;
10652
+ _context.next = 13;
10224
10653
  break;
10225
10654
  }
10226
10655
  if (_this.media) {
@@ -10231,49 +10660,51 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10231
10660
  return _context.abrupt("return");
10232
10661
  case 6:
10233
10662
  headers = response.headers;
10663
+ elapsed = st ? firstByteTime - st : endTime - startTime;
10234
10664
  _this.emit(EVENT.TTFB, {
10235
10665
  url: _this._opts.url,
10236
10666
  responseUrl: response.url,
10237
- elapsed: st ? firstByteTime - st : endTime - startTime
10667
+ elapsed
10238
10668
  });
10239
10669
  _this.emit(EVENT.LOAD_RESPONSE_HEADERS, {
10240
10670
  headers
10241
10671
  });
10672
+ _this._transferCost.set(TRANSFER_EVENT.TTFB, elapsed);
10242
10673
  _this._acceptRanges = !!(headers !== null && headers !== void 0 && headers.get("Accept-Ranges")) || !!(headers !== null && headers !== void 0 && headers.get("Content-Range"));
10243
10674
  _this._firstProgressEmit = true;
10244
- case 11:
10675
+ case 13:
10245
10676
  if (_this._bufferService) {
10246
- _context.next = 13;
10677
+ _context.next = 15;
10247
10678
  break;
10248
10679
  }
10249
10680
  return _context.abrupt("return");
10250
- case 13:
10681
+ case 15:
10251
10682
  clearTimeout(_this._maxChunkWaitTimer);
10252
10683
  _this._bandwidthService.addChunkRecord(chunk === null || chunk === void 0 ? void 0 : chunk.byteLength, endTime - startTime);
10253
- _context.prev = 15;
10254
- _context.next = 18;
10684
+ _context.prev = 17;
10685
+ _context.next = 20;
10255
10686
  return _this._bufferService.appendBuffer(chunk);
10256
- case 18:
10687
+ case 20:
10257
10688
  (_this$_bufferService = _this._bufferService) === null || _this$_bufferService === void 0 ? void 0 : _this$_bufferService.evictBuffer(_this._opts.bufferBehind);
10258
- _context.next = 31;
10689
+ _context.next = 33;
10259
10690
  break;
10260
- case 21:
10261
- _context.prev = 21;
10262
- _context.t0 = _context["catch"](15);
10691
+ case 23:
10692
+ _context.prev = 23;
10693
+ _context.t0 = _context["catch"](17);
10263
10694
  if (!(!_this.isLive && _this._bufferService.isFull())) {
10264
- _context.next = 30;
10695
+ _context.next = 32;
10265
10696
  break;
10266
10697
  }
10267
- _context.next = 26;
10698
+ _context.next = 28;
10268
10699
  return _this._mediaLoader.cancel();
10269
- case 26:
10700
+ case 28:
10270
10701
  _this._loading = false;
10271
10702
  remaining = _this.bufferInfo().remaining;
10272
10703
  _this._opts.preloadTime = parseInt(remaining) / 2;
10273
10704
  return _context.abrupt("return");
10274
- case 30:
10705
+ case 32:
10275
10706
  return _context.abrupt("return", _this._emitError(StreamingError.create(_context.t0)));
10276
- case 31:
10707
+ case 33:
10277
10708
  if (_this._urlSwitching) {
10278
10709
  _this._urlSwitching = false;
10279
10710
  _this.emit(EVENT.SWITCH_URL_SUCCESS, {
@@ -10285,7 +10716,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10285
10716
  _this._tick();
10286
10717
  }
10287
10718
  if (!(done && !_this.media.seeking)) {
10288
- _context.next = 38;
10719
+ _context.next = 40;
10289
10720
  break;
10290
10721
  }
10291
10722
  _this.emit(EVENT.LOAD_COMPLETE);
@@ -10294,13 +10725,13 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10294
10725
  _this._end();
10295
10726
  }
10296
10727
  return _context.abrupt("return");
10297
- case 38:
10728
+ case 40:
10298
10729
  if (_this.isLive) {
10299
- _context.next = 40;
10730
+ _context.next = 42;
10300
10731
  break;
10301
10732
  }
10302
10733
  return _context.abrupt("return");
10303
- case 40:
10734
+ case 42:
10304
10735
  maxReaderInterval = _this._opts.maxReaderInterval;
10305
10736
  if (maxReaderInterval && _this._firstProgressEmit) {
10306
10737
  clearTimeout(_this._maxChunkWaitTimer);
@@ -10314,11 +10745,11 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10314
10745
  _this._end();
10315
10746
  }, maxReaderInterval);
10316
10747
  }
10317
- case 42:
10748
+ case 44:
10318
10749
  case "end":
10319
10750
  return _context.stop();
10320
10751
  }
10321
- }, _callee, null, [[15, 21]]);
10752
+ }, _callee, null, [[17, 23]]);
10322
10753
  }));
10323
10754
  return function(_x, _x2, _x3, _x4) {
10324
10755
  return _ref2.apply(this, arguments);
@@ -10351,19 +10782,19 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10351
10782
  if (bufferEnd < MAX_HOLE || !media.readyState)
10352
10783
  return;
10353
10784
  var opts = _this._opts;
10354
- if (isMediaPlaying(media)) {
10785
+ if (isMediaPlaying(media) && media.currentTime) {
10355
10786
  if (_this._gapService) {
10356
10787
  _this._gapService.do(media, opts.maxJumpDistance, _this.isLive, 3);
10357
10788
  }
10358
10789
  } else {
10359
- if (!media.currentTime && _this._gapService) {
10790
+ if (!media.currentTime && _this._gapService && opts.enableStartGapJump) {
10360
10791
  var gapJump = _this._opts.mseLowLatency || _this._opts.mseLowLatency === false && _this.bufferInfo(MAX_START_GAP).nextStart;
10361
10792
  if (gapJump) {
10362
10793
  _this._gapService.do(media, opts.maxJumpDistance, _this.isLive, 3);
10363
10794
  }
10364
10795
  return;
10365
10796
  }
10366
- if (opts.isLive && media.readyState === 4 && bufferEnd > opts.disconnectTime) {
10797
+ if (opts.isLive && media.readyState === 4 && bufferEnd - media.currentTime > opts.disconnectTime) {
10367
10798
  _this.disconnect();
10368
10799
  }
10369
10800
  }
@@ -10512,6 +10943,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10512
10943
  responseType: "arraybuffer"
10513
10944
  }));
10514
10945
  _this._disconnectRetryCount = _this._opts.disconnectRetryCount;
10946
+ _this._transferCost = new TransferCost();
10515
10947
  _this._bufferService = new BufferService(_assertThisInitialized$3(_this), _this._opts.softDecode ? _this.media : void 0, _this._opts);
10516
10948
  _this._seiService = new SeiService(_assertThisInitialized$3(_this));
10517
10949
  _this._bandwidthService = new BandwidthService({
@@ -10535,7 +10967,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10535
10967
  _createClass$4(Flv2, [{
10536
10968
  key: "version",
10537
10969
  get: function get() {
10538
- return "3.0.19-rc.0";
10970
+ return "3.0.21-rc.2";
10539
10971
  }
10540
10972
  }, {
10541
10973
  key: "isLive",
@@ -10651,9 +11083,9 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10651
11083
  return this._clear();
10652
11084
  case 8:
10653
11085
  setTimeout(function() {
11086
+ _this2._seamlessSwitching = true;
10654
11087
  _this2._loadData(_this2._opts.url);
10655
11088
  _this2._bufferService.seamlessSwitch();
10656
- _this2._seamlessSwitching = true;
10657
11089
  });
10658
11090
  _context5.next = 13;
10659
11091
  break;
@@ -10677,50 +11109,82 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10677
11109
  }, {
10678
11110
  key: "disconnect",
10679
11111
  value: function disconnect() {
11112
+ var _this$_bufferService4;
10680
11113
  logger.debug("disconnect!");
11114
+ (_this$_bufferService4 = this._bufferService) === null || _this$_bufferService4 === void 0 ? void 0 : _this$_bufferService4.resetSeamlessSwitchStats();
10681
11115
  return this._clear();
10682
11116
  }
10683
11117
  }, {
10684
11118
  key: "switchURL",
10685
11119
  value: function() {
10686
- var _switchURL = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee6(url, seamless) {
11120
+ var _switchURL = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee7(url, seamless) {
10687
11121
  var _this3 = this;
10688
- return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
11122
+ return _regeneratorRuntime$1().wrap(function _callee7$(_context7) {
10689
11123
  while (1)
10690
- switch (_context6.prev = _context6.next) {
11124
+ switch (_context7.prev = _context7.next) {
10691
11125
  case 0:
10692
11126
  if (this._bufferService) {
10693
- _context6.next = 2;
11127
+ _context7.next = 2;
10694
11128
  break;
10695
11129
  }
10696
- return _context6.abrupt("return");
11130
+ return _context7.abrupt("return");
10697
11131
  case 2:
10698
11132
  this._resetDisconnectCount();
11133
+ if (!(this._loading && seamless)) {
11134
+ _context7.next = 6;
11135
+ break;
11136
+ }
11137
+ this._bufferService.seamlessLoadingSwitch = /* @__PURE__ */ function() {
11138
+ var _ref5 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee6(pts) {
11139
+ return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
11140
+ while (1)
11141
+ switch (_context6.prev = _context6.next) {
11142
+ case 0:
11143
+ _context6.next = 2;
11144
+ return _this3._clear();
11145
+ case 2:
11146
+ _this3._bufferService.seamlessLoadingSwitching = true;
11147
+ _this3._urlSwitching = true;
11148
+ _this3._seamlessSwitching = true;
11149
+ _this3._bufferService.seamlessSwitch();
11150
+ _this3._loadData(url);
11151
+ case 7:
11152
+ case "end":
11153
+ return _context6.stop();
11154
+ }
11155
+ }, _callee6);
11156
+ }));
11157
+ return function(_x8) {
11158
+ return _ref5.apply(this, arguments);
11159
+ };
11160
+ }();
11161
+ return _context7.abrupt("return");
11162
+ case 6:
10699
11163
  if (!(!seamless || !this._opts.isLive)) {
10700
- _context6.next = 8;
11164
+ _context7.next = 11;
10701
11165
  break;
10702
11166
  }
10703
- _context6.next = 6;
11167
+ _context7.next = 9;
10704
11168
  return this.load(url);
10705
- case 6:
11169
+ case 9:
10706
11170
  this._urlSwitching = true;
10707
- return _context6.abrupt("return", this.media.play(true).catch(function() {
11171
+ return _context7.abrupt("return", this.media.play(true).catch(function() {
10708
11172
  }));
10709
- case 8:
10710
- _context6.next = 10;
11173
+ case 11:
11174
+ _context7.next = 13;
10711
11175
  return this._clear();
10712
- case 10:
11176
+ case 13:
10713
11177
  setTimeout(function() {
10714
11178
  _this3._urlSwitching = true;
10715
11179
  _this3._seamlessSwitching = true;
10716
11180
  _this3._loadData(url);
10717
11181
  _this3._bufferService.seamlessSwitch();
10718
11182
  });
10719
- case 11:
11183
+ case 14:
10720
11184
  case "end":
10721
- return _context6.stop();
11185
+ return _context7.stop();
10722
11186
  }
10723
- }, _callee6, this);
11187
+ }, _callee7, this);
10724
11188
  }));
10725
11189
  function switchURL(_x6, _x7) {
10726
11190
  return _switchURL.apply(this, arguments);
@@ -10730,16 +11194,16 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10730
11194
  }, {
10731
11195
  key: "destroy",
10732
11196
  value: function() {
10733
- var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee7() {
10734
- return _regeneratorRuntime$1().wrap(function _callee7$(_context7) {
11197
+ var _destroy = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee8() {
11198
+ return _regeneratorRuntime$1().wrap(function _callee8$(_context8) {
10735
11199
  while (1)
10736
- switch (_context7.prev = _context7.next) {
11200
+ switch (_context8.prev = _context8.next) {
10737
11201
  case 0:
10738
11202
  if (this.media) {
10739
- _context7.next = 2;
11203
+ _context8.next = 2;
10740
11204
  break;
10741
11205
  }
10742
- return _context7.abrupt("return");
11206
+ return _context8.abrupt("return");
10743
11207
  case 2:
10744
11208
  this.removeAllListeners();
10745
11209
  this._seiService.reset();
@@ -10749,16 +11213,16 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10749
11213
  this.media.removeEventListener("timeupdate", this._onTimeupdate);
10750
11214
  this.media.removeEventListener("waiting", this._onWaiting);
10751
11215
  this.media.removeEventListener("progress", this._onBufferUpdate);
10752
- _context7.next = 12;
11216
+ _context8.next = 12;
10753
11217
  return Promise.all([this._clear(), this._bufferService.destroy()]);
10754
11218
  case 12:
10755
11219
  this.media = null;
10756
11220
  this._bufferService = null;
10757
11221
  case 14:
10758
11222
  case "end":
10759
- return _context7.stop();
11223
+ return _context8.stop();
10760
11224
  }
10761
- }, _callee7, this);
11225
+ }, _callee8, this);
10762
11226
  }));
10763
11227
  function destroy() {
10764
11228
  return _destroy.apply(this, arguments);
@@ -10787,26 +11251,26 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10787
11251
  }, {
10788
11252
  key: "_reset",
10789
11253
  value: function() {
10790
- var _reset2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee8() {
10791
- var reuseMse, _args8 = arguments;
10792
- return _regeneratorRuntime$1().wrap(function _callee8$(_context8) {
11254
+ var _reset2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee9() {
11255
+ var reuseMse, _args9 = arguments;
11256
+ return _regeneratorRuntime$1().wrap(function _callee9$(_context9) {
10793
11257
  while (1)
10794
- switch (_context8.prev = _context8.next) {
11258
+ switch (_context9.prev = _context9.next) {
10795
11259
  case 0:
10796
- reuseMse = _args8.length > 0 && _args8[0] !== void 0 ? _args8[0] : false;
11260
+ reuseMse = _args9.length > 0 && _args9[0] !== void 0 ? _args9[0] : false;
10797
11261
  this._seiService.reset();
10798
11262
  this._bandwidthService.reset();
10799
11263
  this._stats.reset();
10800
- _context8.next = 6;
11264
+ _context9.next = 6;
10801
11265
  return this._clear();
10802
11266
  case 6:
10803
- _context8.next = 8;
11267
+ _context9.next = 8;
10804
11268
  return this._bufferService.reset(reuseMse);
10805
11269
  case 8:
10806
11270
  case "end":
10807
- return _context8.stop();
11271
+ return _context9.stop();
10808
11272
  }
10809
- }, _callee8, this);
11273
+ }, _callee9, this);
10810
11274
  }));
10811
11275
  function _reset() {
10812
11276
  return _reset2.apply(this, arguments);
@@ -10816,17 +11280,17 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10816
11280
  }, {
10817
11281
  key: "_loadData",
10818
11282
  value: function() {
10819
- var _loadData2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee9(url, range) {
11283
+ var _loadData2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee10(url, range) {
10820
11284
  var finnalUrl;
10821
- return _regeneratorRuntime$1().wrap(function _callee9$(_context9) {
11285
+ return _regeneratorRuntime$1().wrap(function _callee10$(_context10) {
10822
11286
  while (1)
10823
- switch (_context9.prev = _context9.next) {
11287
+ switch (_context10.prev = _context10.next) {
10824
11288
  case 0:
10825
11289
  if (url)
10826
11290
  this._opts.url = url;
10827
11291
  finnalUrl = url = this._opts.url;
10828
11292
  if (url) {
10829
- _context9.next = 4;
11293
+ _context10.next = 4;
10830
11294
  break;
10831
11295
  }
10832
11296
  throw new Error("Source url is missing");
@@ -10841,34 +11305,34 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10841
11305
  });
10842
11306
  logger.debug("load data, loading:", this._loading, finnalUrl);
10843
11307
  if (!this._loading) {
10844
- _context9.next = 11;
11308
+ _context10.next = 11;
10845
11309
  break;
10846
11310
  }
10847
- _context9.next = 11;
11311
+ _context10.next = 11;
10848
11312
  return this._mediaLoader.cancel();
10849
11313
  case 11:
10850
11314
  this._loading = true;
10851
- _context9.prev = 12;
10852
- _context9.next = 15;
11315
+ _context10.prev = 12;
11316
+ _context10.next = 15;
10853
11317
  return this._mediaLoader.load({
10854
11318
  url: finnalUrl,
10855
11319
  range
10856
11320
  });
10857
11321
  case 15:
10858
- _context9.next = 21;
11322
+ _context10.next = 21;
10859
11323
  break;
10860
11324
  case 17:
10861
- _context9.prev = 17;
10862
- _context9.t0 = _context9["catch"](12);
11325
+ _context10.prev = 17;
11326
+ _context10.t0 = _context10["catch"](12);
10863
11327
  this._loading = false;
10864
- return _context9.abrupt("return", this._emitError(StreamingError.network(_context9.t0), false));
11328
+ return _context10.abrupt("return", this._emitError(StreamingError.network(_context10.t0), false));
10865
11329
  case 21:
10866
11330
  case "end":
10867
- return _context9.stop();
11331
+ return _context10.stop();
10868
11332
  }
10869
- }, _callee9, this, [[12, 17]]);
11333
+ }, _callee10, this, [[12, 17]]);
10870
11334
  }));
10871
- function _loadData(_x8, _x9) {
11335
+ function _loadData(_x9, _x10) {
10872
11336
  return _loadData2.apply(this, arguments);
10873
11337
  }
10874
11338
  return _loadData;
@@ -10876,16 +11340,16 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10876
11340
  }, {
10877
11341
  key: "_clear",
10878
11342
  value: function() {
10879
- var _clear2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee10() {
10880
- return _regeneratorRuntime$1().wrap(function _callee10$(_context10) {
11343
+ var _clear2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee11() {
11344
+ return _regeneratorRuntime$1().wrap(function _callee11$(_context11) {
10881
11345
  while (1)
10882
- switch (_context10.prev = _context10.next) {
11346
+ switch (_context11.prev = _context11.next) {
10883
11347
  case 0:
10884
11348
  if (!this._mediaLoader) {
10885
- _context10.next = 3;
11349
+ _context11.next = 3;
10886
11350
  break;
10887
11351
  }
10888
- _context10.next = 3;
11352
+ _context11.next = 3;
10889
11353
  return this._mediaLoader.cancel();
10890
11354
  case 3:
10891
11355
  clearTimeout(this._maxChunkWaitTimer);
@@ -10894,9 +11358,9 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10894
11358
  this._firstProgressEmit = false;
10895
11359
  case 7:
10896
11360
  case "end":
10897
- return _context10.stop();
11361
+ return _context11.stop();
10898
11362
  }
10899
- }, _callee10, this);
11363
+ }, _callee11, this);
10900
11364
  }));
10901
11365
  function _clear() {
10902
11366
  return _clear2.apply(this, arguments);
@@ -10983,9 +11447,13 @@ var PluginExtension = /* @__PURE__ */ function() {
10983
11447
  _createClass$4(PluginExtension2, [{
10984
11448
  key: "_init",
10985
11449
  value: function _init() {
10986
- var _this$_opts2 = this._opts, media = _this$_opts2.media, preloadTime = _this$_opts2.preloadTime, innerDegrade = _this$_opts2.innerDegrade, decodeMode = _this$_opts2.decodeMode;
11450
+ 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;
10987
11451
  if (!media)
10988
11452
  return;
11453
+ if (!isLive && media.setPlayMode) {
11454
+ media.setPlayMode("VOD");
11455
+ return;
11456
+ }
10989
11457
  if (innerDegrade) {
10990
11458
  media.setAttribute("innerdegrade", innerDegrade);
10991
11459
  }
@@ -11023,6 +11491,7 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
11023
11491
  args[_key] = arguments[_key];
11024
11492
  }
11025
11493
  _this = _super.call.apply(_super, [this].concat(args));
11494
+ _defineProperty$3(_assertThisInitialized$3(_this), "logger", logger);
11026
11495
  _defineProperty$3(_assertThisInitialized$3(_this), "flv", null);
11027
11496
  _defineProperty$3(_assertThisInitialized$3(_this), "pluginExtension", null);
11028
11497
  _defineProperty$3(_assertThisInitialized$3(_this), "getStats", function() {
@@ -11090,11 +11559,17 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
11090
11559
  var _this$flv3;
11091
11560
  return (_this$flv3 = this.flv) === null || _this$flv3 === void 0 ? void 0 : _this$flv3.loader;
11092
11561
  }
11562
+ }, {
11563
+ key: "transferCost",
11564
+ get: function get() {
11565
+ return this.flv._transferCost.transferCost;
11566
+ }
11093
11567
  }, {
11094
11568
  key: "beforePlayerInit",
11095
11569
  value: function beforePlayerInit() {
11096
11570
  var _this2 = this;
11097
11571
  var config = this.player.config;
11572
+ var mediaElem = this.player.media || this.player.video;
11098
11573
  if (!config.url)
11099
11574
  return;
11100
11575
  if (this.flv)
@@ -11107,10 +11582,10 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
11107
11582
  this.flv = new Flv(_objectSpread2$2({
11108
11583
  softDecode: this.softDecode,
11109
11584
  isLive: config.isLive,
11110
- media: this.player.video,
11585
+ media: mediaElem,
11111
11586
  preProcessUrl: function preProcessUrl(url, ext) {
11112
- var _this2$player$preProc, _this2$player;
11113
- 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)) || {
11587
+ var _this2$player, _this2$player$preProc;
11588
+ 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)) || {
11114
11589
  url,
11115
11590
  ext
11116
11591
  };
@@ -11129,7 +11604,8 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
11129
11604
  }
11130
11605
  if (this.softDecode) {
11131
11606
  this.pluginExtension = new PluginExtension(_objectSpread2$2({
11132
- media: this.player.video
11607
+ media: this.player.video,
11608
+ isLive: config.isLive
11133
11609
  }, config.flv), this);
11134
11610
  this.player.forceDegradeToVideo = function() {
11135
11611
  var _this2$pluginExtensio;
@@ -11156,6 +11632,7 @@ var FlvPlugin = /* @__PURE__ */ function(_BasePlugin) {
11156
11632
  this._transCoreEvent(EVENT.LOAD_RETRY);
11157
11633
  this._transCoreEvent(EVENT.SOURCEBUFFER_CREATED);
11158
11634
  this._transCoreEvent(EVENT.ANALYZE_DURATION_EXCEEDED);
11635
+ this._transCoreEvent(EVENT.APPEND_BUFFER);
11159
11636
  this._transCoreEvent(EVENT.REMOVE_BUFFER);
11160
11637
  this._transCoreEvent(EVENT.BUFFEREOS);
11161
11638
  this._transCoreEvent(EVENT.KEYFRAME);