@give-tech/ec-player 0.0.1-beta.13 → 0.0.1-beta.15

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
@@ -1548,9 +1548,14 @@ class HLSPlayer extends BasePlayer {
1548
1548
  this.lastRenderTime = 0;
1549
1549
  this.playStartTime = 0;
1550
1550
  this.accumulatedMediaTime = 0;
1551
+ this._lastLogTime = 0;
1551
1552
  this.renderLoop = (timestamp = 0) => {
1552
1553
  if (!this.isPlaying) return;
1553
1554
  const now = performance.now();
1555
+ if (!this._lastLogTime || now - this._lastLogTime > 1e3) {
1556
+ this._lastLogTime = now;
1557
+ console.log("[renderLoop] frameBuffer=", this.frameBuffer.length, "renderer=", !!this.renderer);
1558
+ }
1554
1559
  const downloaded = this.isFMP4 ? this.sampleQueue.length : this.nalQueue.length;
1555
1560
  const segments = this.isFMP4 ? this.fmp4Segments : this.segments;
1556
1561
  const totalSegments = segments.length;
@@ -1567,9 +1572,13 @@ class HLSPlayer extends BasePlayer {
1567
1572
  if (this.playStartTime === 0) {
1568
1573
  this.playStartTime = now;
1569
1574
  this.accumulatedMediaTime = 0;
1575
+ console.log("[renderLoop] Init: timescale=", timescale);
1570
1576
  }
1571
1577
  const elapsedWallTime = now - this.playStartTime;
1572
1578
  const frameDurationMs = frame.duration ? frame.duration * 1e3 / timescale : 33.33;
1579
+ if (Math.floor(elapsedWallTime / 1e3) !== Math.floor((elapsedWallTime - 20) / 1e3)) {
1580
+ console.log("[renderLoop] elapsed=", Math.floor(elapsedWallTime), "accumulated=", Math.floor(this.accumulatedMediaTime), "frameDuration=", frame.duration, "frameDurationMs=", frameDurationMs.toFixed(2), "frameBuffer=", this.frameBuffer.length);
1581
+ }
1573
1582
  const bufferMs = 50;
1574
1583
  if (elapsedWallTime >= this.accumulatedMediaTime - bufferMs) {
1575
1584
  this.frameBuffer.shift();
@@ -1582,7 +1591,11 @@ class HLSPlayer extends BasePlayer {
1582
1591
  this.callbacks.onFrameRender?.(frame);
1583
1592
  }
1584
1593
  } else {
1585
- this.lastRenderTime = 0;
1594
+ if (this.playStartTime !== 0) {
1595
+ const oldPlayStartTime = this.playStartTime;
1596
+ this.playStartTime = now - this.accumulatedMediaTime;
1597
+ console.log("[renderLoop] No frames, adjusting playStartTime from", oldPlayStartTime, "to", this.playStartTime, "accumulated=", this.accumulatedMediaTime);
1598
+ }
1586
1599
  }
1587
1600
  this.frameTimer = requestAnimationFrame(this.renderLoop);
1588
1601
  };
@@ -1702,10 +1715,13 @@ class HLSPlayer extends BasePlayer {
1702
1715
  */
1703
1716
  async decodeLoop() {
1704
1717
  console.log("[DecodeLoop] START, isFMP4:", this.isFMP4);
1705
- console.log("[DecodeLoop] END");
1706
1718
  let batchCount = 0;
1707
1719
  while (this.isPlaying && !this.decodeLoopAbort) {
1708
1720
  this.prefetcher?.processQueue();
1721
+ if (!this.config.isLive && this.frameBuffer.length >= this.config.targetBufferSize) {
1722
+ await this.sleep(10);
1723
+ continue;
1724
+ }
1709
1725
  const batchSize = this.config.decodeBatchSize;
1710
1726
  let decodedInBatch = 0;
1711
1727
  if (this.isFMP4) {
@@ -1720,9 +1736,11 @@ class HLSPlayer extends BasePlayer {
1720
1736
  if (frame) {
1721
1737
  this.frameBuffer.push(frame);
1722
1738
  decodedInBatch++;
1723
- while (this.frameBuffer.length > this.config.targetBufferSize) {
1724
- this.frameBuffer.shift();
1725
- this.droppedFrames++;
1739
+ if (this.config.isLive) {
1740
+ while (this.frameBuffer.length > this.config.targetBufferSize) {
1741
+ this.frameBuffer.shift();
1742
+ this.droppedFrames++;
1743
+ }
1726
1744
  }
1727
1745
  }
1728
1746
  }
@@ -1738,9 +1756,11 @@ class HLSPlayer extends BasePlayer {
1738
1756
  if (frame) {
1739
1757
  this.frameBuffer.push(frame);
1740
1758
  decodedInBatch++;
1741
- while (this.frameBuffer.length > this.config.targetBufferSize) {
1742
- this.frameBuffer.shift();
1743
- this.droppedFrames++;
1759
+ if (this.config.isLive) {
1760
+ while (this.frameBuffer.length > this.config.targetBufferSize) {
1761
+ this.frameBuffer.shift();
1762
+ this.droppedFrames++;
1763
+ }
1744
1764
  }
1745
1765
  }
1746
1766
  }