@byteplus/veplayer 2.12.2-rc.0 → 2.13.1-rc.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.
package/esm/index.d.ts CHANGED
@@ -5080,7 +5080,6 @@ declare namespace error {
5080
5080
  declare namespace event {
5081
5081
  const BaseEvents: {
5082
5082
  SEI: string;
5083
- SEI_IN_TIME: string;
5084
5083
  PLAYER_CREATE_FINISH: string;
5085
5084
  FALLBACK_ERROR: string;
5086
5085
  FALLBACK: string;
@@ -5125,7 +5124,6 @@ declare namespace event {
5125
5124
  };
5126
5125
  const Events: {
5127
5126
  SEI: string;
5128
- SEI_IN_TIME: string;
5129
5127
  PLAYER_CREATE_FINISH: string;
5130
5128
  FALLBACK_ERROR: string;
5131
5129
  FALLBACK: string;
@@ -26733,7 +26733,6 @@ function normalizeNumber(value, transform) {
26733
26733
  return transform ? transform(value) : value.toString();
26734
26734
  }
26735
26735
  function getDefaultRow(data2) {
26736
- var _a;
26737
26736
  return {
26738
26737
  rows: [
26739
26738
  {
@@ -26774,7 +26773,10 @@ function getDefaultRow(data2) {
26774
26773
  {
26775
26774
  key: "bufferEnd",
26776
26775
  labelTextKey: "BUFFER_END",
26777
- value: normalizeNumber(Number((_a = data2.bufferEnd) == null ? void 0 : _a.toFixed(2)))
26776
+ value: normalizeNumber(
26777
+ data2.bufferEnd,
26778
+ (value) => Number(value.toFixed(2)).toString()
26779
+ )
26778
26780
  },
26779
26781
  {
26780
26782
  key: "currentTime",
@@ -29239,8 +29241,6 @@ const licenseManager$1 = new LicenseManager();
29239
29241
  const BaseEvents = {
29240
29242
  // sei
29241
29243
  SEI: "sei",
29242
- // sei,在播放时间对齐到该 sei 的时间戳时抛出
29243
- SEI_IN_TIME: "seiInTime",
29244
29244
  // 播放器完成创建
29245
29245
  PLAYER_CREATE_FINISH: "playerCreateFinish",
29246
29246
  FALLBACK_ERROR: "fallbackError",
@@ -51018,6 +51018,79 @@ class LiveVeStrategy {
51018
51018
  }
51019
51019
  }
51020
51020
  const liveVeStrategy = new LiveVeStrategy();
51021
+ const isNumber = (value) => typeof value === "number" && Number.isFinite(value);
51022
+ const getTimestamp = (delaySEI, currentKey, legacyKey) => {
51023
+ const currentValue = delaySEI[currentKey];
51024
+ if (isNumber(currentValue)) {
51025
+ return currentValue;
51026
+ }
51027
+ const legacyValue = delaySEI[legacyKey];
51028
+ return isNumber(legacyValue) ? legacyValue : void 0;
51029
+ };
51030
+ const utf8ArrayToString = (array) => {
51031
+ let result = "";
51032
+ let index = 0;
51033
+ while (index < array.length) {
51034
+ const first = array[index++];
51035
+ if (first < 128) {
51036
+ result += String.fromCharCode(first);
51037
+ } else if (first < 224) {
51038
+ const second = array[index++];
51039
+ result += String.fromCharCode((first & 31) << 6 | second & 63);
51040
+ } else {
51041
+ const second = array[index++];
51042
+ const third = array[index++];
51043
+ result += String.fromCharCode(
51044
+ (first & 15) << 12 | (second & 63) << 6 | third & 63
51045
+ );
51046
+ }
51047
+ }
51048
+ return result;
51049
+ };
51050
+ const getSEIDelayStats = (sei, bufferTime = 0, now3 = Date.now()) => {
51051
+ if ((sei == null ? void 0 : sei.code) !== 100 || !sei.content) {
51052
+ return;
51053
+ }
51054
+ try {
51055
+ const rawSEI = utf8ArrayToString(sei.content);
51056
+ const jsonStart = rawSEI.indexOf("{");
51057
+ const jsonEnd = rawSEI.lastIndexOf("}");
51058
+ if (jsonStart < 0 || jsonEnd < jsonStart) {
51059
+ return;
51060
+ }
51061
+ const seiContent = JSON.parse(rawSEI.slice(jsonStart, jsonEnd + 1));
51062
+ const delaySEI = seiContent == null ? void 0 : seiContent.video_e2e_delay;
51063
+ if (!delaySEI || typeof delaySEI !== "object") {
51064
+ return;
51065
+ }
51066
+ const push3 = getTimestamp(delaySEI, "push_edge_ts", "push_node");
51067
+ const source = getTimestamp(delaySEI, "source_ts", "source_node");
51068
+ const cmafSource = getTimestamp(
51069
+ delaySEI,
51070
+ "cmaf_source_ts",
51071
+ "cmaf_source_node"
51072
+ );
51073
+ const hlsSource = getTimestamp(
51074
+ delaySEI,
51075
+ "hls_source_ts",
51076
+ "hls_source_node"
51077
+ );
51078
+ const pull = getTimestamp(delaySEI, "pull_edge_ts", "pull_node");
51079
+ const start = push3 ?? source;
51080
+ const end = pull ?? hlsSource ?? cmafSource;
51081
+ if (!isNumber(start) || !isNumber(end)) {
51082
+ return;
51083
+ }
51084
+ const delayS2S = end - start;
51085
+ const safeBufferTime = isNumber(bufferTime) ? Math.max(0, bufferTime) : 0;
51086
+ return {
51087
+ delay_s2s: delayS2S,
51088
+ delay_s2e: delayS2S + Math.max(0, now3 - end) + safeBufferTime
51089
+ };
51090
+ } catch (e2) {
51091
+ return;
51092
+ }
51093
+ };
51021
51094
  const DEFAULT_PLUGINS = window["VePlayer"].DEFAULT_PLUGINS;
51022
51095
  const VePlayerBase = window["VePlayer"].VePlayerBase;
51023
51096
  const VeI18n = window["VePlayer"].VeI18n;
@@ -51060,6 +51133,22 @@ class VePlayerLive extends VePlayerBase {
51060
51133
  * @hidden
51061
51134
  */
51062
51135
  __publicField(this, "_protocolManager");
51136
+ __publicField(this, "_seiDelayStats", {});
51137
+ __publicField(this, "_resetSEIDelayStats", () => {
51138
+ this._seiDelayStats = {};
51139
+ });
51140
+ __publicField(this, "_handleSEI", (data2) => {
51141
+ const stats = getSEIDelayStats(data2 == null ? void 0 : data2.sei, this._getPlayerBufferTime());
51142
+ if (stats) {
51143
+ this._seiDelayStats = stats;
51144
+ }
51145
+ });
51146
+ this.on(Events$1.SEI, this._handleSEI);
51147
+ this.on(Events$1.URL_CHANGE, this._resetSEIDelayStats);
51148
+ this.on(Events$1.SOURCE_CHANGE, this._resetSEIDelayStats);
51149
+ this.on(Events$1.DEFINITION_CHANGE, this._resetSEIDelayStats);
51150
+ this.on(Events$1.REPLAY, this._resetSEIDelayStats);
51151
+ this.on(Events$1.FALLBACK, this._resetSEIDelayStats);
51063
51152
  }
51064
51153
  /** {zh}
51065
51154
  * @brief 获取已经播放的时长,不包含暂停和等待时间,单位为秒。
@@ -51101,6 +51190,22 @@ class VePlayerLive extends VePlayerBase {
51101
51190
  var _a, _b;
51102
51191
  return (_b = (_a = this._player.plugins) == null ? void 0 : _a.hls) == null ? void 0 : _b.hls;
51103
51192
  }
51193
+ /** {zh}
51194
+ * @hidden
51195
+ */
51196
+ /** {en}
51197
+ * @hidden
51198
+ */
51199
+ destroy() {
51200
+ this.off(Events$1.SEI, this._handleSEI);
51201
+ this.off(Events$1.URL_CHANGE, this._resetSEIDelayStats);
51202
+ this.off(Events$1.SOURCE_CHANGE, this._resetSEIDelayStats);
51203
+ this.off(Events$1.DEFINITION_CHANGE, this._resetSEIDelayStats);
51204
+ this.off(Events$1.REPLAY, this._resetSEIDelayStats);
51205
+ this.off(Events$1.FALLBACK, this._resetSEIDelayStats);
51206
+ this._resetSEIDelayStats();
51207
+ super.destroy();
51208
+ }
51104
51209
  /** {zh}
51105
51210
  * @brief 调用此方法开启直播日志上报。
51106
51211
  */
@@ -51237,7 +51342,8 @@ class VePlayerLive extends VePlayerBase {
51237
51342
  */
51238
51343
  async getRTMStats() {
51239
51344
  var _a, _b, _c;
51240
- return (_c = (_b = (_a = this._player) == null ? void 0 : _a.plugins) == null ? void 0 : _b.rts) == null ? void 0 : _c.getStatsSnapshoot();
51345
+ const stats = await ((_c = (_b = (_a = this._player) == null ? void 0 : _a.plugins) == null ? void 0 : _b.rts) == null ? void 0 : _c.getStatsSnapshoot());
51346
+ return this._mergeSEIDelayStats(stats);
51241
51347
  }
51242
51348
  /** {zh}
51243
51349
  * @brief 获取 FLV 拉流的播放信息。
@@ -51248,7 +51354,8 @@ class VePlayerLive extends VePlayerBase {
51248
51354
  */
51249
51355
  getFLVStats() {
51250
51356
  var _a, _b, _c;
51251
- return (_c = (_b = (_a = this._player) == null ? void 0 : _a.plugins) == null ? void 0 : _b.flv) == null ? void 0 : _c.getStats();
51357
+ const stats = (_c = (_b = (_a = this._player) == null ? void 0 : _a.plugins) == null ? void 0 : _b.flv) == null ? void 0 : _c.getStats();
51358
+ return this._mergeSEIDelayStats(stats);
51252
51359
  }
51253
51360
  /** {zh}
51254
51361
  * @brief 获取 HLS 拉流的播放信息。
@@ -51260,8 +51367,9 @@ class VePlayerLive extends VePlayerBase {
51260
51367
  * @hidden
51261
51368
  */
51262
51369
  getHLSStats() {
51263
- var _a, _b, _c;
51264
- return (_c = (_b = (_a = this._player) == null ? void 0 : _a.plugins) == null ? void 0 : _b.hls) == null ? void 0 : _c.getStats();
51370
+ var _a, _b, _c, _d;
51371
+ const stats = ((_d = (_c = (_b = (_a = this._player) == null ? void 0 : _a.plugins) == null ? void 0 : _b.hls) == null ? void 0 : _c.getStats) == null ? void 0 : _d.call(_c)) ?? {};
51372
+ return this._mergeSEIDelayStats(stats);
51265
51373
  }
51266
51374
  /** {en}
51267
51375
  * @brief This method is used to update the playlist, supporting updates to source, resolution, and related information.
@@ -51289,6 +51397,40 @@ class VePlayerLive extends VePlayerBase {
51289
51397
  }
51290
51398
  return super.updatePlaylist(playlist, target);
51291
51399
  }
51400
+ _getPlayerBufferTime() {
51401
+ var _a, _b, _c, _d, _e2;
51402
+ try {
51403
+ const rtm = ((_b = (_a = this._player) == null ? void 0 : _a.plugins) == null ? void 0 : _b.rts) ?? ((_d = (_c = this._player) == null ? void 0 : _c.plugins) == null ? void 0 : _d.rtm);
51404
+ if (rtm) {
51405
+ const jitterBufferDelay = rtm.jitterBufferDelay;
51406
+ if (Number.isFinite(jitterBufferDelay) && jitterBufferDelay >= 0) {
51407
+ return jitterBufferDelay;
51408
+ }
51409
+ }
51410
+ } catch (e2) {
51411
+ }
51412
+ const video = (_e2 = this._player) == null ? void 0 : _e2.video;
51413
+ const buffered = video == null ? void 0 : video.buffered;
51414
+ if (!video || !(buffered == null ? void 0 : buffered.length)) {
51415
+ return 0;
51416
+ }
51417
+ try {
51418
+ return Math.trunc(
51419
+ (buffered.end(buffered.length - 1) - video.currentTime) * 1e3
51420
+ );
51421
+ } catch (e2) {
51422
+ return 0;
51423
+ }
51424
+ }
51425
+ _mergeSEIDelayStats(stats) {
51426
+ if (!stats) {
51427
+ return stats;
51428
+ }
51429
+ return {
51430
+ ...stats,
51431
+ ...this._seiDelayStats
51432
+ };
51433
+ }
51292
51434
  }
51293
51435
  async function createLivePlayer(options) {
51294
51436
  var _a, _b, _c, _d, _e2, _f, _g, _h, _i2, _j, _k;
@@ -51321,6 +51463,10 @@ async function createLivePlayer(options) {
51321
51463
  playerOptions,
51322
51464
  recommendation
51323
51465
  );
51466
+ finalOptions.rtm = {
51467
+ enableSei: true,
51468
+ ...finalOptions.rtm
51469
+ };
51324
51470
  await liveLicenseManager.create();
51325
51471
  const licenseFatalError = liveLicenseManager.getLicenseFatalError();
51326
51472
  const protocolManager = await ProtocolManager.create(finalOptions);