@volcengine/veplayer-plugin 2.4.0-rc.1 → 2.4.0-rc.3

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,19 @@ 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
+ _defineProperty$1(this, "_totalSize", 0);
5053
+ _defineProperty$1(this, "_totalCost", 0);
5054
+ this._opts = opts || {};
5047
5055
  }
5048
5056
  _createClass$2(BandwidthService2, [{
5049
5057
  key: "addRecord",
@@ -5051,45 +5059,82 @@ var BandwidthService = /* @__PURE__ */ function() {
5051
5059
  if (!totalByte || !ms)
5052
5060
  return;
5053
5061
  this._speeds.push(8e3 * totalByte / ms);
5054
- this._speeds = this._speeds.slice(-3);
5062
+ this._speeds = this._speeds.slice(-MAX_SEGMENT_SAVE_SIZE);
5055
5063
  }
5056
5064
  }, {
5057
5065
  key: "addChunkRecord",
5058
5066
  value: function addChunkRecord(totalByte, ms) {
5059
- if (!totalByte || !ms)
5067
+ var _this$_opts, _this$_opts2;
5068
+ if (!totalByte || !ms || totalByte < (((_this$_opts = this._opts) === null || _this$_opts === void 0 ? void 0 : _this$_opts.skipChunkSize) || SKIP_SMALL_CHUNK))
5060
5069
  return;
5061
- this._chunkSpeeds.push(8e3 * totalByte / ms);
5062
- this._chunkSpeeds = this._chunkSpeeds.slice(-100);
5070
+ this._totalSize += totalByte;
5071
+ this._totalCost += ms;
5072
+ this._chunkSpeed = 8e3 * totalByte / ms;
5073
+ this._chunkCache.push({
5074
+ size: totalByte,
5075
+ duration: ms,
5076
+ timestamp: performance.now()
5077
+ });
5078
+ var size = ((_this$_opts2 = this._opts) === null || _this$_opts2 === void 0 ? void 0 : _this$_opts2.chunkCountForSpeed) || MAX_CHUNK_SAVE_SIZE;
5079
+ if (this._chunkCache.length > size) {
5080
+ this._chunkCache = this._chunkCache.slice(-size);
5081
+ }
5063
5082
  }
5064
5083
  }, {
5065
5084
  key: "getAvgSpeed",
5066
5085
  value: function getAvgSpeed() {
5067
- if (!this._chunkSpeeds.length && !this._speeds.length)
5086
+ var _this$_opts3;
5087
+ if (!this._chunkCache.length && !this._speeds.length)
5068
5088
  return 0;
5069
5089
  if (this._speeds.length) {
5070
5090
  return this._speeds.reduce(function(a, c) {
5071
5091
  return a += c;
5072
5092
  }) / this._speeds.length;
5073
5093
  }
5074
- return this._chunkSpeeds.reduce(function(a, c) {
5075
- return a += c;
5076
- }) / this._chunkSpeeds.length;
5094
+ var lastSample = this._chunkCache[this._chunkCache.length - 1];
5095
+ var cost = performance.now() - lastSample.timestamp;
5096
+ if (cost > (((_this$_opts3 = this._opts) === null || _this$_opts3 === void 0 ? void 0 : _this$_opts3.longtimeNoReceived) || LONGTIME_NO_RECEIVE)) {
5097
+ this._chunkCache.push({
5098
+ size: 0,
5099
+ duration: cost,
5100
+ timestamp: performance.now()
5101
+ });
5102
+ }
5103
+ var totalSize = this._chunkCache.reduce(function(a, c) {
5104
+ return a += c.size;
5105
+ }, 0);
5106
+ var totalDuration = this._chunkCache.reduce(function(a, c) {
5107
+ return a += c.duration;
5108
+ }, 0);
5109
+ return 8e3 * totalSize / totalDuration;
5077
5110
  }
5078
5111
  }, {
5079
5112
  key: "getLatestSpeed",
5080
5113
  value: function getLatestSpeed() {
5081
- if (!this._chunkSpeeds.length && !this._speeds.length)
5114
+ if (!this._chunkCache.length && !this._speeds.length)
5082
5115
  return 0;
5083
5116
  if (this._speeds.length) {
5084
5117
  return this._speeds[this._speeds.length - 1];
5085
5118
  }
5086
- return this._chunkSpeeds[this._chunkSpeeds.length - 1];
5119
+ return this._chunkSpeed;
5120
+ }
5121
+ }, {
5122
+ key: "getTotalSize",
5123
+ value: function getTotalSize() {
5124
+ return this._totalSize;
5125
+ }
5126
+ }, {
5127
+ key: "getTotalCost",
5128
+ value: function getTotalCost() {
5129
+ return this._totalCost;
5087
5130
  }
5088
5131
  }, {
5089
5132
  key: "reset",
5090
5133
  value: function reset() {
5091
- this._chunkSpeeds = [];
5134
+ this._chunkCache = [];
5092
5135
  this._speeds = [];
5136
+ this._totalSize = 0;
5137
+ this._totalCost = 0;
5093
5138
  }
5094
5139
  }]);
5095
5140
  return BandwidthService2;
@@ -5218,13 +5263,15 @@ var MediaStatsService = /* @__PURE__ */ function() {
5218
5263
  _createClass$2(MediaStatsService2, [{
5219
5264
  key: "getStats",
5220
5265
  value: function getStats() {
5221
- var _this$_core, _this$_core2, _this$_core2$speedInf, _this$_core3, _this$_core3$speedInf, _this$_core4, _this$_core4$bufferIn;
5266
+ var _this$_core, _this$_core2, _this$_core2$speedInf, _this$_core3, _this$_core3$speedInf, _this$_core4, _this$_core4$speedInf, _this$_core5, _this$_core5$speedInf, _this$_core6, _this$_core6$bufferIn;
5222
5267
  var _ref2 = ((_this$_core = this._core) === null || _this$_core === void 0 ? void 0 : _this$_core.media) || {}, _ref2$currentTime = _ref2.currentTime, currentTime = _ref2$currentTime === void 0 ? 0 : _ref2$currentTime, _ref2$decodeFps = _ref2.decodeFps, decodeFps = _ref2$decodeFps === void 0 ? 0 : _ref2$decodeFps;
5223
5268
  return _objectSpread2(_objectSpread2({}, this._stats.getStats()), {}, {
5224
5269
  downloadSpeed: ((_this$_core2 = this._core) === null || _this$_core2 === void 0 ? void 0 : (_this$_core2$speedInf = _this$_core2.speedInfo) === null || _this$_core2$speedInf === void 0 ? void 0 : _this$_core2$speedInf.call(_this$_core2).speed) || 0,
5225
5270
  avgSpeed: ((_this$_core3 = this._core) === null || _this$_core3 === void 0 ? void 0 : (_this$_core3$speedInf = _this$_core3.speedInfo) === null || _this$_core3$speedInf === void 0 ? void 0 : _this$_core3$speedInf.call(_this$_core3).avgSpeed) || 0,
5271
+ totalReceivedByte: ((_this$_core4 = this._core) === null || _this$_core4 === void 0 ? void 0 : (_this$_core4$speedInf = _this$_core4.speedInfo) === null || _this$_core4$speedInf === void 0 ? void 0 : _this$_core4$speedInf.call(_this$_core4).totalSize) || 0,
5272
+ totalReceivedCost: ((_this$_core5 = this._core) === null || _this$_core5 === void 0 ? void 0 : (_this$_core5$speedInf = _this$_core5.speedInfo) === null || _this$_core5$speedInf === void 0 ? void 0 : _this$_core5$speedInf.call(_this$_core5).totalCost) || 0,
5226
5273
  currentTime,
5227
- bufferEnd: ((_this$_core4 = this._core) === null || _this$_core4 === void 0 ? void 0 : (_this$_core4$bufferIn = _this$_core4.bufferInfo()) === null || _this$_core4$bufferIn === void 0 ? void 0 : _this$_core4$bufferIn.remaining) || 0,
5274
+ bufferEnd: ((_this$_core6 = this._core) === null || _this$_core6 === void 0 ? void 0 : (_this$_core6$bufferIn = _this$_core6.bufferInfo()) === null || _this$_core6$bufferIn === void 0 ? void 0 : _this$_core6$bufferIn.remaining) || 0,
5228
5275
  decodeFps
5229
5276
  });
5230
5277
  }
@@ -10024,7 +10071,10 @@ function getOption(opts) {
10024
10071
  onlyAudio: false,
10025
10072
  preferMMS: false,
10026
10073
  mseLowLatency: true,
10027
- durationForMSELowLatencyOff: 6
10074
+ durationForMSELowLatencyOff: 6,
10075
+ chunkCountForSpeed: 50,
10076
+ skipChunkSize: 1e3,
10077
+ longtimeNoReceived: 3e3
10028
10078
  }, opts);
10029
10079
  if (ret.isLive) {
10030
10080
  if (ret.preloadTime) {
@@ -10182,7 +10232,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10182
10232
  return _context.abrupt("return");
10183
10233
  case 40:
10184
10234
  maxReaderInterval = _this._opts.maxReaderInterval;
10185
- if (maxReaderInterval) {
10235
+ if (maxReaderInterval && _this._firstProgressEmit) {
10186
10236
  clearTimeout(_this._maxChunkWaitTimer);
10187
10237
  _this._maxChunkWaitTimer = setTimeout(function() {
10188
10238
  if (_this._disconnectRetryCount) {
@@ -10394,7 +10444,11 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10394
10444
  _this._disconnectRetryCount = _this._opts.disconnectRetryCount;
10395
10445
  _this._bufferService = new BufferService(_assertThisInitialized$3(_this), _this._opts.softDecode ? _this.media : void 0, _this._opts);
10396
10446
  _this._seiService = new SeiService(_assertThisInitialized$3(_this));
10397
- _this._bandwidthService = new BandwidthService();
10447
+ _this._bandwidthService = new BandwidthService({
10448
+ chunkCountForSpeed: _this._opts.chunkCountForSpeed,
10449
+ skipChunkSize: _this._opts.skipChunkSize,
10450
+ longtimeNoReceived: _this._opts.longtimeNoReceived
10451
+ });
10398
10452
  _this._stats = new MediaStatsService(_assertThisInitialized$3(_this));
10399
10453
  if (!_this._opts.softDecode) {
10400
10454
  _this._gapService = new GapService();
@@ -10411,7 +10465,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10411
10465
  _createClass$4(Flv2, [{
10412
10466
  key: "version",
10413
10467
  get: function get() {
10414
- return "3.0.17";
10468
+ return "3.0.18-alpha.5";
10415
10469
  }
10416
10470
  }, {
10417
10471
  key: "isLive",
@@ -10445,7 +10499,9 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10445
10499
  value: function speedInfo() {
10446
10500
  return {
10447
10501
  speed: this._bandwidthService.getLatestSpeed(),
10448
- avgSpeed: this._bandwidthService.getAvgSpeed()
10502
+ avgSpeed: this._bandwidthService.getAvgSpeed(),
10503
+ totalSize: this._bandwidthService.getTotalSize(),
10504
+ totalCost: this._bandwidthService.getTotalCost()
10449
10505
  };
10450
10506
  }
10451
10507
  }, {
@@ -10735,7 +10791,7 @@ var Flv = /* @__PURE__ */ function(_EventEmitter) {
10735
10791
  _context9.prev = 17;
10736
10792
  _context9.t0 = _context9["catch"](12);
10737
10793
  this._loading = false;
10738
- return _context9.abrupt("return", this._emitError(StreamingError.network(_context9.t0)));
10794
+ return _context9.abrupt("return", this._emitError(StreamingError.network(_context9.t0), false));
10739
10795
  case 21:
10740
10796
  case "end":
10741
10797
  return _context9.stop();