@byteplus/veplayer-plugin 2.4.0-rc.3 → 2.4.0-rc.4

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.
@@ -1644,7 +1644,7 @@
1644
1644
  }
1645
1645
  return offsetTime;
1646
1646
  };
1647
- var version = "3.0.17";
1647
+ var version = "3.0.19-rc.0";
1648
1648
  var ERROR_MAP = {
1649
1649
  1: 5101,
1650
1650
  2: 5102,
@@ -2893,6 +2893,7 @@
2893
2893
  MSE_APPEND_BUFFER: "MSE_APPEND_BUFFER",
2894
2894
  MSE_OTHER: "MSE_OTHER",
2895
2895
  MSE_FULL: "MSE_FULL",
2896
+ MSE_CHANGE_TYPE: "MSE_CHANGE_TYPE",
2896
2897
  OPTION: "OPTION",
2897
2898
  DASH: "DASH",
2898
2899
  LICENSE: "LICENSE",
@@ -2935,6 +2936,7 @@
2935
2936
  MSE_OTHER: 5202,
2936
2937
  MSE_FULL: 5203,
2937
2938
  MSE_HIJACK: 5204,
2939
+ MSE_CHANGE_TYPE: 5205,
2938
2940
  EME_HIJACK: 5301
2939
2941
  }), _defineProperty$1(_ERR_CODE, ERR.DRM, {
2940
2942
  LICENSE: 7100,
@@ -3270,7 +3272,7 @@
3270
3272
  queue.shift();
3271
3273
  }
3272
3274
  if (op) {
3273
- var _this2$_sourceBuffer$;
3275
+ var _this2$_sourceBuffer$, _op$context;
3274
3276
  var costtime = nowTime() - _this2._opst;
3275
3277
  _this2._logger.debug("UpdateEnd(".concat(type, "/").concat(op.opName, ")"), SafeJSON.stringify(getTimeRanges((_this2$_sourceBuffer$ = _this2._sourceBuffer[type]) === null || _this2$_sourceBuffer$ === void 0 ? void 0 : _this2$_sourceBuffer$.buffered)), costtime, op.context);
3276
3278
  op.promise.resolve({
@@ -3278,6 +3280,10 @@
3278
3280
  context: op.context,
3279
3281
  costtime
3280
3282
  });
3283
+ var callback = (_op$context = op.context) === null || _op$context === void 0 ? void 0 : _op$context.callback;
3284
+ if (callback && typeof callback === "function") {
3285
+ callback(op.context);
3286
+ }
3281
3287
  _this2._startQueue(type);
3282
3288
  }
3283
3289
  }
@@ -3539,10 +3545,15 @@
3539
3545
  var sb = this._sourceBuffer[type];
3540
3546
  if (!this.mediaSource || !sb || sb.mimeType === mimeType)
3541
3547
  return Promise.resolve();
3542
- if (typeof sb.changeType !== "function")
3543
- return Promise.reject();
3548
+ if (typeof sb.changeType !== "function") {
3549
+ return Promise.reject(new StreamingError(ERR.MEDIA, ERR.SUB_TYPES.MSE_CHANGE_TYPE, new Error("changeType is not a function")));
3550
+ }
3544
3551
  return this._enqueueOp(type, function() {
3545
- sb.changeType(mimeType);
3552
+ try {
3553
+ sb.changeType(mimeType);
3554
+ } catch (e) {
3555
+ throw new StreamingError(ERR.MEDIA, ERR.SUB_TYPES.MSE_CHANGE_TYPE, e);
3556
+ }
3546
3557
  sb.mimeType = mimeType;
3547
3558
  _this8._onSBUpdateEnd(type);
3548
3559
  }, "changeType", {
@@ -3792,11 +3803,14 @@
3792
3803
  } catch (error) {
3793
3804
  if (error && error.message && error.message.indexOf("SourceBuffer is full") >= 0) {
3794
3805
  this._mseFullFlag[type] = true;
3806
+ if (op.context && _typeof(op.context) === "object") {
3807
+ op.context.isFull = true;
3808
+ }
3795
3809
  this._logger.error("[MSE error], context,", op.context, " ,name,", op.opName, ",err,SourceBuffer is full");
3796
3810
  op.promise.reject(new StreamingError(ERR.MEDIA, ERR.SUB_TYPES.MSE_FULL, error));
3797
3811
  } else {
3798
3812
  this._logger.error(error);
3799
- op.promise.reject(new StreamingError(ERR.MEDIA, ERR.SUB_TYPES.MSE_OTHER, error));
3813
+ op.promise.reject(error.constructor === StreamingError ? error : new StreamingError(ERR.MEDIA, ERR.SUB_TYPES.MSE_OTHER, error));
3800
3814
  queue.shift();
3801
3815
  this._startQueue(type);
3802
3816
  }
@@ -5146,11 +5160,19 @@
5146
5160
  }]);
5147
5161
  return SeiService2;
5148
5162
  }();
5163
+ var SKIP_SMALL_CHUNK = 1e3;
5164
+ var MAX_CHUNK_SAVE_SIZE = 50;
5165
+ var MAX_SEGMENT_SAVE_SIZE = 3;
5166
+ var LONGTIME_NO_RECEIVE = 3e3;
5149
5167
  var BandwidthService = /* @__PURE__ */ function() {
5150
- function BandwidthService2() {
5168
+ function BandwidthService2(opts) {
5151
5169
  _classCallCheck$1(this, BandwidthService2);
5152
- _defineProperty$1(this, "_chunkSpeeds", []);
5170
+ _defineProperty$1(this, "_chunkSpeed", 0);
5171
+ _defineProperty$1(this, "_chunkCache", []);
5153
5172
  _defineProperty$1(this, "_speeds", []);
5173
+ _defineProperty$1(this, "_totalSize", 0);
5174
+ _defineProperty$1(this, "_totalCost", 0);
5175
+ this._opts = opts || {};
5154
5176
  }
5155
5177
  _createClass$1(BandwidthService2, [{
5156
5178
  key: "addRecord",
@@ -5158,45 +5180,82 @@
5158
5180
  if (!totalByte || !ms)
5159
5181
  return;
5160
5182
  this._speeds.push(8e3 * totalByte / ms);
5161
- this._speeds = this._speeds.slice(-3);
5183
+ this._speeds = this._speeds.slice(-MAX_SEGMENT_SAVE_SIZE);
5162
5184
  }
5163
5185
  }, {
5164
5186
  key: "addChunkRecord",
5165
5187
  value: function addChunkRecord(totalByte, ms) {
5166
- if (!totalByte || !ms)
5188
+ var _this$_opts, _this$_opts2;
5189
+ if (!totalByte || !ms || totalByte < (((_this$_opts = this._opts) === null || _this$_opts === void 0 ? void 0 : _this$_opts.skipChunkSize) || SKIP_SMALL_CHUNK))
5167
5190
  return;
5168
- this._chunkSpeeds.push(8e3 * totalByte / ms);
5169
- this._chunkSpeeds = this._chunkSpeeds.slice(-100);
5191
+ this._totalSize += totalByte;
5192
+ this._totalCost += ms;
5193
+ this._chunkSpeed = 8e3 * totalByte / ms;
5194
+ this._chunkCache.push({
5195
+ size: totalByte,
5196
+ duration: ms,
5197
+ timestamp: performance.now()
5198
+ });
5199
+ var size = ((_this$_opts2 = this._opts) === null || _this$_opts2 === void 0 ? void 0 : _this$_opts2.chunkCountForSpeed) || MAX_CHUNK_SAVE_SIZE;
5200
+ if (this._chunkCache.length > size) {
5201
+ this._chunkCache = this._chunkCache.slice(-size);
5202
+ }
5170
5203
  }
5171
5204
  }, {
5172
5205
  key: "getAvgSpeed",
5173
5206
  value: function getAvgSpeed() {
5174
- if (!this._chunkSpeeds.length && !this._speeds.length)
5207
+ var _this$_opts3;
5208
+ if (!this._chunkCache.length && !this._speeds.length)
5175
5209
  return 0;
5176
5210
  if (this._speeds.length) {
5177
5211
  return this._speeds.reduce(function(a, c) {
5178
5212
  return a += c;
5179
5213
  }) / this._speeds.length;
5180
5214
  }
5181
- return this._chunkSpeeds.reduce(function(a, c) {
5182
- return a += c;
5183
- }) / this._chunkSpeeds.length;
5215
+ var lastSample = this._chunkCache[this._chunkCache.length - 1];
5216
+ var cost = performance.now() - lastSample.timestamp;
5217
+ if (cost > (((_this$_opts3 = this._opts) === null || _this$_opts3 === void 0 ? void 0 : _this$_opts3.longtimeNoReceived) || LONGTIME_NO_RECEIVE)) {
5218
+ this._chunkCache.push({
5219
+ size: 0,
5220
+ duration: cost,
5221
+ timestamp: performance.now()
5222
+ });
5223
+ }
5224
+ var totalSize = this._chunkCache.reduce(function(a, c) {
5225
+ return a += c.size;
5226
+ }, 0);
5227
+ var totalDuration = this._chunkCache.reduce(function(a, c) {
5228
+ return a += c.duration;
5229
+ }, 0);
5230
+ return 8e3 * totalSize / totalDuration;
5184
5231
  }
5185
5232
  }, {
5186
5233
  key: "getLatestSpeed",
5187
5234
  value: function getLatestSpeed() {
5188
- if (!this._chunkSpeeds.length && !this._speeds.length)
5235
+ if (!this._chunkCache.length && !this._speeds.length)
5189
5236
  return 0;
5190
5237
  if (this._speeds.length) {
5191
5238
  return this._speeds[this._speeds.length - 1];
5192
5239
  }
5193
- return this._chunkSpeeds[this._chunkSpeeds.length - 1];
5240
+ return this._chunkSpeed;
5241
+ }
5242
+ }, {
5243
+ key: "getTotalSize",
5244
+ value: function getTotalSize() {
5245
+ return this._totalSize;
5246
+ }
5247
+ }, {
5248
+ key: "getTotalCost",
5249
+ value: function getTotalCost() {
5250
+ return this._totalCost;
5194
5251
  }
5195
5252
  }, {
5196
5253
  key: "reset",
5197
5254
  value: function reset() {
5198
- this._chunkSpeeds = [];
5255
+ this._chunkCache = [];
5199
5256
  this._speeds = [];
5257
+ this._totalSize = 0;
5258
+ this._totalCost = 0;
5200
5259
  }
5201
5260
  }]);
5202
5261
  return BandwidthService2;
@@ -5325,13 +5384,15 @@
5325
5384
  _createClass$1(MediaStatsService2, [{
5326
5385
  key: "getStats",
5327
5386
  value: function getStats() {
5328
- var _this$_core, _this$_core2, _this$_core2$speedInf, _this$_core3, _this$_core3$speedInf, _this$_core4, _this$_core4$bufferIn;
5387
+ 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;
5329
5388
  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;
5330
5389
  return _objectSpread2(_objectSpread2({}, this._stats.getStats()), {}, {
5331
5390
  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,
5332
5391
  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,
5392
+ 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,
5393
+ 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,
5333
5394
  currentTime,
5334
- 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,
5395
+ 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,
5335
5396
  decodeFps
5336
5397
  });
5337
5398
  }
@@ -11207,7 +11268,9 @@
11207
11268
  mse = this._mse;
11208
11269
  _p = [];
11209
11270
  if (needInit && !isFirstAppend) {
11210
- this._handleCodecChange(video, audio);
11271
+ this._handleCodecChange(video, audio).forEach(function(task) {
11272
+ return _p.push(task);
11273
+ });
11211
11274
  }
11212
11275
  if (video) {
11213
11276
  videoData = video.data, videoRest = _objectWithoutProperties$1(video, _excluded);
@@ -11480,6 +11543,7 @@
11480
11543
  }, {
11481
11544
  key: "_handleCodecChange",
11482
11545
  value: function _handleCodecChange(video, audio) {
11546
+ var tasks = [];
11483
11547
  var mse = this._mse;
11484
11548
  var codecList = [{
11485
11549
  type: MSE.VIDEO,
@@ -11496,10 +11560,11 @@
11496
11560
  if (sourceBuffer) {
11497
11561
  var codec = codecs.split(",")[0];
11498
11562
  if (!new RegExp(codec, "ig").test(sourceBuffer.mimeType)) {
11499
- mse.changeType(type, "".concat(type, "/mp4;codecs=").concat(codecs));
11563
+ tasks.push(mse.changeType(type, "".concat(type, "/mp4;codecs=").concat(codecs)));
11500
11564
  }
11501
11565
  }
11502
11566
  });
11567
+ return tasks;
11503
11568
  }
11504
11569
  }, {
11505
11570
  key: "seamlessSwitch",
@@ -11558,10 +11623,21 @@
11558
11623
  };
11559
11624
  var KeySystems = {
11560
11625
  CLEAR_KEY: "org.w3.clearkey",
11561
- FAIRPLAY: "com.apple.streamingkeydelivery",
11562
- WIDEVINE: "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed",
11563
- PLAYREADY: "com.microsoft.playready"
11626
+ FAIRPLAY: ["urn:uuid:94ce86fb-07ff-4f43-adb8-93d2fa968ca2", "com.apple.streamingkeydelivery"],
11627
+ WIDEVINE: ["urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed", "com.widevine.alpha", "com.widevine"],
11628
+ PLAYREADY: ["urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95", "com.microsoft.playready"]
11564
11629
  };
11630
+ function flatArray(arr) {
11631
+ var ret = [];
11632
+ for (var i = 0; i < arr.length; i++) {
11633
+ if (Array.isArray(arr[i])) {
11634
+ ret = ret.concat(flatArray(arr[i]));
11635
+ } else {
11636
+ ret.push(arr[i]);
11637
+ }
11638
+ }
11639
+ return ret;
11640
+ }
11565
11641
  var MediaStream = /* @__PURE__ */ _createClass$3(function MediaStream2() {
11566
11642
  _classCallCheck$3(this, MediaStream2);
11567
11643
  _defineProperty$3(this, "id", 0);
@@ -11738,7 +11814,7 @@
11738
11814
  }, {
11739
11815
  key: "isValidKeySystem",
11740
11816
  value: function isValidKeySystem() {
11741
- var isKeyFormatValid = [KeySystems.CLEAR_KEY, KeySystems.FAIRPLAY, KeySystems.WIDEVINE, KeySystems.PLAYREADY].indexOf(this.keyFormat) > -1;
11817
+ var isKeyFormatValid = flatArray([KeySystems.CLEAR_KEY, KeySystems.FAIRPLAY, KeySystems.WIDEVINE, KeySystems.PLAYREADY]).indexOf(this.keyFormat) > -1;
11742
11818
  if (!isKeyFormatValid) {
11743
11819
  return false;
11744
11820
  }
@@ -14523,7 +14599,7 @@
14523
14599
  }]);
14524
14600
  return Hls2;
14525
14601
  }(EventEmitter);
14526
- _defineProperty$3(Hls, "version", "3.0.17");
14602
+ _defineProperty$3(Hls, "version", "3.0.19-rc.0");
14527
14603
  try {
14528
14604
  if (localStorage.getItem("xgd")) {
14529
14605
  Hls.enableLogger();