@give-tech/ec-player 0.0.1-beta.52 → 0.0.1-beta.53

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/dist/index.js CHANGED
@@ -3370,6 +3370,8 @@ class FLVPlayer extends BasePlayer {
3370
3370
  this.playStartTimeOffset = 0;
3371
3371
  this.resyncCount = 0;
3372
3372
  this._lastRafTime = 0;
3373
+ this._prevRenderDts = -1;
3374
+ this._frameIntervalSamples = [];
3373
3375
  this.renderLoop = () => {
3374
3376
  if (!this.isPlaying) return;
3375
3377
  this.updateState({
@@ -3444,6 +3446,15 @@ class FLVPlayer extends BasePlayer {
3444
3446
  const frameToRender = this._timedFrameBuffer.shift();
3445
3447
  this.renderFrame(frameToRender, now);
3446
3448
  this.lastRenderedDts = frameToRender.dts;
3449
+ if (this._prevRenderDts >= 0) {
3450
+ this._frameIntervalSamples.push(frameToRender.dts - this._prevRenderDts);
3451
+ if (this._frameIntervalSamples.length >= 30) {
3452
+ const avg = this._frameIntervalSamples.reduce((a, b) => a + b, 0) / this._frameIntervalSamples.length;
3453
+ console.log("[FLVPlayer] 帧率诊断: 平均帧间隔", avg.toFixed(1), "ms, 约", (1e3 / avg).toFixed(1), "fps, 样本数:", this._frameIntervalSamples.length);
3454
+ this._frameIntervalSamples = [];
3455
+ }
3456
+ }
3457
+ this._prevRenderDts = frameToRender.dts;
3447
3458
  const lag = currentTargetPts - frameToRender.dts;
3448
3459
  if (lag > 1e3) {
3449
3460
  this.playStartTime = now;
@@ -3704,6 +3715,8 @@ class FLVPlayer extends BasePlayer {
3704
3715
  this.playStartTime = performance.now();
3705
3716
  this.playStartTimeOffset = 0;
3706
3717
  this._lastRafTime = 0;
3718
+ this._prevRenderDts = -1;
3719
+ this._frameIntervalSamples = [];
3707
3720
  console.log("[FLVPlayer] Play time initialized, firstFrameDts:", this.firstFrameDts);
3708
3721
  }
3709
3722
  this.isPlaying = true;
@@ -4378,6 +4391,9 @@ class Canvas2DRenderer {
4378
4391
  this.frameCount = 0;
4379
4392
  this.lastFpsUpdate = performance.now();
4380
4393
  this.lastFps = 0;
4394
+ this.cachedImageData = null;
4395
+ this.cachedWidth = 0;
4396
+ this.cachedHeight = 0;
4381
4397
  this.canvas = canvas;
4382
4398
  this.ctx = canvas.getContext("2d");
4383
4399
  if (!this.ctx) {
@@ -4396,8 +4412,13 @@ class Canvas2DRenderer {
4396
4412
  if (this.canvas.width !== width || this.canvas.height !== height) {
4397
4413
  this.canvas.width = width;
4398
4414
  this.canvas.height = height;
4415
+ this.cachedImageData = this.ctx.createImageData(width, height);
4416
+ this.cachedWidth = width;
4417
+ this.cachedHeight = height;
4399
4418
  }
4400
- const imageData = new ImageData(new Uint8ClampedArray(data), width, height);
4419
+ const imageData = this.cachedImageData;
4420
+ const dest = imageData.data;
4421
+ dest.set(data);
4401
4422
  this.ctx.putImageData(imageData, 0, 0);
4402
4423
  }
4403
4424
  updateFps() {
@@ -4810,12 +4831,12 @@ const _EnvDetector = class _EnvDetector {
4810
4831
  // function index: 0
4811
4832
  // Code section (10)
4812
4833
  10,
4813
- 19,
4834
+ 23,
4814
4835
  1,
4815
- // section id=10, size=19, 1 func
4816
- 17,
4836
+ // section id=10, size=23, 1 func
4837
+ 21,
4817
4838
  0,
4818
- // func body size=17, 0 locals
4839
+ // func body size=21, 0 locals
4819
4840
  // v128.const i32x4 0 0 0 0
4820
4841
  253,
4821
4842
  12,