@byteplus/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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byteplus/veplayer-plugin",
3
- "version": "2.4.0-rc.1",
3
+ "version": "2.4.0-rc.3",
4
4
  "main": "./umd/index.production.js",
5
5
  "module": "./esm/index.production.js",
6
6
  "browser": "./umd/index.production.js",
@@ -5043,11 +5043,19 @@
5043
5043
  }]);
5044
5044
  return SeiService2;
5045
5045
  }();
5046
+ var SKIP_SMALL_CHUNK = 1e3;
5047
+ var MAX_CHUNK_SAVE_SIZE = 50;
5048
+ var MAX_SEGMENT_SAVE_SIZE = 3;
5049
+ var LONGTIME_NO_RECEIVE = 3e3;
5046
5050
  var BandwidthService = /* @__PURE__ */ function() {
5047
- function BandwidthService2() {
5051
+ function BandwidthService2(opts) {
5048
5052
  _classCallCheck$2(this, BandwidthService2);
5049
- _defineProperty$1(this, "_chunkSpeeds", []);
5053
+ _defineProperty$1(this, "_chunkSpeed", 0);
5054
+ _defineProperty$1(this, "_chunkCache", []);
5050
5055
  _defineProperty$1(this, "_speeds", []);
5056
+ _defineProperty$1(this, "_totalSize", 0);
5057
+ _defineProperty$1(this, "_totalCost", 0);
5058
+ this._opts = opts || {};
5051
5059
  }
5052
5060
  _createClass$2(BandwidthService2, [{
5053
5061
  key: "addRecord",
@@ -5055,45 +5063,82 @@
5055
5063
  if (!totalByte || !ms)
5056
5064
  return;
5057
5065
  this._speeds.push(8e3 * totalByte / ms);
5058
- this._speeds = this._speeds.slice(-3);
5066
+ this._speeds = this._speeds.slice(-MAX_SEGMENT_SAVE_SIZE);
5059
5067
  }
5060
5068
  }, {
5061
5069
  key: "addChunkRecord",
5062
5070
  value: function addChunkRecord(totalByte, ms) {
5063
- if (!totalByte || !ms)
5071
+ var _this$_opts, _this$_opts2;
5072
+ if (!totalByte || !ms || totalByte < (((_this$_opts = this._opts) === null || _this$_opts === void 0 ? void 0 : _this$_opts.skipChunkSize) || SKIP_SMALL_CHUNK))
5064
5073
  return;
5065
- this._chunkSpeeds.push(8e3 * totalByte / ms);
5066
- this._chunkSpeeds = this._chunkSpeeds.slice(-100);
5074
+ this._totalSize += totalByte;
5075
+ this._totalCost += ms;
5076
+ this._chunkSpeed = 8e3 * totalByte / ms;
5077
+ this._chunkCache.push({
5078
+ size: totalByte,
5079
+ duration: ms,
5080
+ timestamp: performance.now()
5081
+ });
5082
+ var size = ((_this$_opts2 = this._opts) === null || _this$_opts2 === void 0 ? void 0 : _this$_opts2.chunkCountForSpeed) || MAX_CHUNK_SAVE_SIZE;
5083
+ if (this._chunkCache.length > size) {
5084
+ this._chunkCache = this._chunkCache.slice(-size);
5085
+ }
5067
5086
  }
5068
5087
  }, {
5069
5088
  key: "getAvgSpeed",
5070
5089
  value: function getAvgSpeed() {
5071
- if (!this._chunkSpeeds.length && !this._speeds.length)
5090
+ var _this$_opts3;
5091
+ if (!this._chunkCache.length && !this._speeds.length)
5072
5092
  return 0;
5073
5093
  if (this._speeds.length) {
5074
5094
  return this._speeds.reduce(function(a, c) {
5075
5095
  return a += c;
5076
5096
  }) / this._speeds.length;
5077
5097
  }
5078
- return this._chunkSpeeds.reduce(function(a, c) {
5079
- return a += c;
5080
- }) / this._chunkSpeeds.length;
5098
+ var lastSample = this._chunkCache[this._chunkCache.length - 1];
5099
+ var cost = performance.now() - lastSample.timestamp;
5100
+ if (cost > (((_this$_opts3 = this._opts) === null || _this$_opts3 === void 0 ? void 0 : _this$_opts3.longtimeNoReceived) || LONGTIME_NO_RECEIVE)) {
5101
+ this._chunkCache.push({
5102
+ size: 0,
5103
+ duration: cost,
5104
+ timestamp: performance.now()
5105
+ });
5106
+ }
5107
+ var totalSize = this._chunkCache.reduce(function(a, c) {
5108
+ return a += c.size;
5109
+ }, 0);
5110
+ var totalDuration = this._chunkCache.reduce(function(a, c) {
5111
+ return a += c.duration;
5112
+ }, 0);
5113
+ return 8e3 * totalSize / totalDuration;
5081
5114
  }
5082
5115
  }, {
5083
5116
  key: "getLatestSpeed",
5084
5117
  value: function getLatestSpeed() {
5085
- if (!this._chunkSpeeds.length && !this._speeds.length)
5118
+ if (!this._chunkCache.length && !this._speeds.length)
5086
5119
  return 0;
5087
5120
  if (this._speeds.length) {
5088
5121
  return this._speeds[this._speeds.length - 1];
5089
5122
  }
5090
- return this._chunkSpeeds[this._chunkSpeeds.length - 1];
5123
+ return this._chunkSpeed;
5124
+ }
5125
+ }, {
5126
+ key: "getTotalSize",
5127
+ value: function getTotalSize() {
5128
+ return this._totalSize;
5129
+ }
5130
+ }, {
5131
+ key: "getTotalCost",
5132
+ value: function getTotalCost() {
5133
+ return this._totalCost;
5091
5134
  }
5092
5135
  }, {
5093
5136
  key: "reset",
5094
5137
  value: function reset() {
5095
- this._chunkSpeeds = [];
5138
+ this._chunkCache = [];
5096
5139
  this._speeds = [];
5140
+ this._totalSize = 0;
5141
+ this._totalCost = 0;
5097
5142
  }
5098
5143
  }]);
5099
5144
  return BandwidthService2;
@@ -5222,13 +5267,15 @@
5222
5267
  _createClass$2(MediaStatsService2, [{
5223
5268
  key: "getStats",
5224
5269
  value: function getStats() {
5225
- var _this$_core, _this$_core2, _this$_core2$speedInf, _this$_core3, _this$_core3$speedInf, _this$_core4, _this$_core4$bufferIn;
5270
+ 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;
5226
5271
  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;
5227
5272
  return _objectSpread2(_objectSpread2({}, this._stats.getStats()), {}, {
5228
5273
  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,
5229
5274
  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,
5275
+ 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,
5276
+ 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,
5230
5277
  currentTime,
5231
- 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,
5278
+ 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,
5232
5279
  decodeFps
5233
5280
  });
5234
5281
  }
@@ -10028,7 +10075,10 @@
10028
10075
  onlyAudio: false,
10029
10076
  preferMMS: false,
10030
10077
  mseLowLatency: true,
10031
- durationForMSELowLatencyOff: 6
10078
+ durationForMSELowLatencyOff: 6,
10079
+ chunkCountForSpeed: 50,
10080
+ skipChunkSize: 1e3,
10081
+ longtimeNoReceived: 3e3
10032
10082
  }, opts);
10033
10083
  if (ret.isLive) {
10034
10084
  if (ret.preloadTime) {
@@ -10186,7 +10236,7 @@
10186
10236
  return _context.abrupt("return");
10187
10237
  case 40:
10188
10238
  maxReaderInterval = _this._opts.maxReaderInterval;
10189
- if (maxReaderInterval) {
10239
+ if (maxReaderInterval && _this._firstProgressEmit) {
10190
10240
  clearTimeout(_this._maxChunkWaitTimer);
10191
10241
  _this._maxChunkWaitTimer = setTimeout(function() {
10192
10242
  if (_this._disconnectRetryCount) {
@@ -10398,7 +10448,11 @@
10398
10448
  _this._disconnectRetryCount = _this._opts.disconnectRetryCount;
10399
10449
  _this._bufferService = new BufferService(_assertThisInitialized$3(_this), _this._opts.softDecode ? _this.media : void 0, _this._opts);
10400
10450
  _this._seiService = new SeiService(_assertThisInitialized$3(_this));
10401
- _this._bandwidthService = new BandwidthService();
10451
+ _this._bandwidthService = new BandwidthService({
10452
+ chunkCountForSpeed: _this._opts.chunkCountForSpeed,
10453
+ skipChunkSize: _this._opts.skipChunkSize,
10454
+ longtimeNoReceived: _this._opts.longtimeNoReceived
10455
+ });
10402
10456
  _this._stats = new MediaStatsService(_assertThisInitialized$3(_this));
10403
10457
  if (!_this._opts.softDecode) {
10404
10458
  _this._gapService = new GapService();
@@ -10415,7 +10469,7 @@
10415
10469
  _createClass$4(Flv2, [{
10416
10470
  key: "version",
10417
10471
  get: function get() {
10418
- return "3.0.17";
10472
+ return "3.0.18-alpha.5";
10419
10473
  }
10420
10474
  }, {
10421
10475
  key: "isLive",
@@ -10449,7 +10503,9 @@
10449
10503
  value: function speedInfo() {
10450
10504
  return {
10451
10505
  speed: this._bandwidthService.getLatestSpeed(),
10452
- avgSpeed: this._bandwidthService.getAvgSpeed()
10506
+ avgSpeed: this._bandwidthService.getAvgSpeed(),
10507
+ totalSize: this._bandwidthService.getTotalSize(),
10508
+ totalCost: this._bandwidthService.getTotalCost()
10453
10509
  };
10454
10510
  }
10455
10511
  }, {
@@ -10739,7 +10795,7 @@
10739
10795
  _context9.prev = 17;
10740
10796
  _context9.t0 = _context9["catch"](12);
10741
10797
  this._loading = false;
10742
- return _context9.abrupt("return", this._emitError(StreamingError.network(_context9.t0)));
10798
+ return _context9.abrupt("return", this._emitError(StreamingError.network(_context9.t0), false));
10743
10799
  case 21:
10744
10800
  case "end":
10745
10801
  return _context9.stop();