@byteplus/veplayer-plugin 2.4.0-rc.0 → 2.4.0-rc.2

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.
@@ -5039,11 +5039,17 @@ var SeiService = /* @__PURE__ */ function() {
5039
5039
  }]);
5040
5040
  return SeiService2;
5041
5041
  }();
5042
+ var SKIP_SMALL_CHUNK = 1e3;
5043
+ var MAX_CHUNK_SAVE_SIZE = 50;
5044
+ var MAX_SEGMENT_SAVE_SIZE = 3;
5045
+ var LONGTIME_NO_RECEIVE = 3e3;
5042
5046
  var BandwidthService = /* @__PURE__ */ function() {
5043
- function BandwidthService2() {
5047
+ function BandwidthService2(opts) {
5044
5048
  _classCallCheck$2(this, BandwidthService2);
5045
- _defineProperty$1(this, "_chunkSpeeds", []);
5049
+ _defineProperty$1(this, "_chunkSpeed", 0);
5050
+ _defineProperty$1(this, "_chunkCache", []);
5046
5051
  _defineProperty$1(this, "_speeds", []);
5052
+ this._opts = opts || {};
5047
5053
  }
5048
5054
  _createClass$2(BandwidthService2, [{
5049
5055
  key: "addRecord",
@@ -5051,44 +5057,67 @@ var BandwidthService = /* @__PURE__ */ function() {
5051
5057
  if (!totalByte || !ms)
5052
5058
  return;
5053
5059
  this._speeds.push(8e3 * totalByte / ms);
5054
- this._speeds = this._speeds.slice(-3);
5060
+ this._speeds = this._speeds.slice(-MAX_SEGMENT_SAVE_SIZE);
5055
5061
  }
5056
5062
  }, {
5057
5063
  key: "addChunkRecord",
5058
5064
  value: function addChunkRecord(totalByte, ms) {
5059
- if (!totalByte || !ms)
5065
+ var _this$_opts, _this$_opts2;
5066
+ if (!totalByte || !ms || totalByte < (((_this$_opts = this._opts) === null || _this$_opts === void 0 ? void 0 : _this$_opts.skipChunkSize) || SKIP_SMALL_CHUNK))
5060
5067
  return;
5061
- this._chunkSpeeds.push(8e3 * totalByte / ms);
5062
- this._chunkSpeeds = this._chunkSpeeds.slice(-100);
5068
+ this._chunkSpeed = 8e3 * totalByte / ms;
5069
+ this._chunkCache.push({
5070
+ size: totalByte,
5071
+ duration: ms,
5072
+ timestamp: performance.now()
5073
+ });
5074
+ var size = ((_this$_opts2 = this._opts) === null || _this$_opts2 === void 0 ? void 0 : _this$_opts2.chunkCountForSpeed) || MAX_CHUNK_SAVE_SIZE;
5075
+ if (this._chunkCache.length > size) {
5076
+ this._chunkCache = this._chunkCache.slice(-size);
5077
+ }
5063
5078
  }
5064
5079
  }, {
5065
5080
  key: "getAvgSpeed",
5066
5081
  value: function getAvgSpeed() {
5067
- if (!this._chunkSpeeds.length && !this._speeds.length)
5082
+ var _this$_opts3;
5083
+ if (!this._chunkCache.length && !this._speeds.length)
5068
5084
  return 0;
5069
5085
  if (this._speeds.length) {
5070
5086
  return this._speeds.reduce(function(a, c) {
5071
5087
  return a += c;
5072
5088
  }) / this._speeds.length;
5073
5089
  }
5074
- return this._chunkSpeeds.reduce(function(a, c) {
5075
- return a += c;
5076
- }) / this._chunkSpeeds.length;
5090
+ var lastSample = this._chunkCache[this._chunkCache.length - 1];
5091
+ var cost = performance.now() - lastSample.timestamp;
5092
+ if (cost > (((_this$_opts3 = this._opts) === null || _this$_opts3 === void 0 ? void 0 : _this$_opts3.longtimeNoReceived) || LONGTIME_NO_RECEIVE)) {
5093
+ this._chunkCache.push({
5094
+ size: 0,
5095
+ duration: cost,
5096
+ timestamp: performance.now()
5097
+ });
5098
+ }
5099
+ var totalSize = this._chunkCache.reduce(function(a, c) {
5100
+ return a += c.size;
5101
+ }, 0);
5102
+ var totalDuration = this._chunkCache.reduce(function(a, c) {
5103
+ return a += c.duration;
5104
+ }, 0);
5105
+ return 8e3 * totalSize / totalDuration;
5077
5106
  }
5078
5107
  }, {
5079
5108
  key: "getLatestSpeed",
5080
5109
  value: function getLatestSpeed() {
5081
- if (!this._chunkSpeeds.length && !this._speeds.length)
5110
+ if (!this._chunkCache.length && !this._speeds.length)
5082
5111
  return 0;
5083
5112
  if (this._speeds.length) {
5084
5113
  return this._speeds[this._speeds.length - 1];
5085
5114
  }
5086
- return this._chunkSpeeds[this._chunkSpeeds.length - 1];
5115
+ return this._chunkSpeed;
5087
5116
  }
5088
5117
  }, {
5089
5118
  key: "reset",
5090
5119
  value: function reset() {
5091
- this._chunkSpeeds = [];
5120
+ this._chunkCache = [];
5092
5121
  this._speeds = [];
5093
5122
  }
5094
5123
  }]);
@@ -10024,7 +10053,10 @@ function getOption(opts) {
10024
10053
  onlyAudio: false,
10025
10054
  preferMMS: false,
10026
10055
  mseLowLatency: true,
10027
- durationForMSELowLatencyOff: 6
10056
+ durationForMSELowLatencyOff: 6,
10057
+ chunkCountForSpeed: 50,
10058
+ skipChunkSize: 1e3,
10059
+ longtimeNoReceived: 3e3
10028
10060
  }, opts);
10029
10061
  if (ret.isLive) {
10030
10062
  if (ret.preloadTime) {
@@ -10182,7 +10214,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10182
10214
  return _context.abrupt("return");
10183
10215
  case 40:
10184
10216
  maxReaderInterval = _this._opts.maxReaderInterval;
10185
- if (maxReaderInterval) {
10217
+ if (maxReaderInterval && _this._firstProgressEmit) {
10186
10218
  clearTimeout(_this._maxChunkWaitTimer);
10187
10219
  _this._maxChunkWaitTimer = setTimeout(function() {
10188
10220
  if (_this._disconnectRetryCount) {
@@ -10394,7 +10426,11 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10394
10426
  _this._disconnectRetryCount = _this._opts.disconnectRetryCount;
10395
10427
  _this._bufferService = new BufferService(_assertThisInitialized$3(_this), _this._opts.softDecode ? _this.media : void 0, _this._opts);
10396
10428
  _this._seiService = new SeiService(_assertThisInitialized$3(_this));
10397
- _this._bandwidthService = new BandwidthService();
10429
+ _this._bandwidthService = new BandwidthService({
10430
+ chunkCountForSpeed: _this._opts.chunkCountForSpeed,
10431
+ skipChunkSize: _this._opts.skipChunkSize,
10432
+ longtimeNoReceived: _this._opts.longtimeNoReceived
10433
+ });
10398
10434
  _this._stats = new MediaStatsService(_assertThisInitialized$3(_this));
10399
10435
  if (!_this._opts.softDecode) {
10400
10436
  _this._gapService = new GapService();
@@ -10411,7 +10447,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10411
10447
  _createClass$4(Flv2, [{
10412
10448
  key: "version",
10413
10449
  get: function get() {
10414
- return "3.0.17";
10450
+ return "3.0.18-alpha.3";
10415
10451
  }
10416
10452
  }, {
10417
10453
  key: "isLive",