@give-tech/ec-player 0.0.1-beta.16 → 0.0.1-beta.17

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
@@ -1226,11 +1226,16 @@ class SegmentPrefetcher extends BasePrefetcher {
1226
1226
  /**
1227
1227
  * 处理预取队列中的数据
1228
1228
  *
1229
+ * @param maxSegments 最多处理的分片数量(默认处理所有)
1229
1230
  * @returns 是否有数据被处理
1230
1231
  */
1231
- processQueue() {
1232
+ processQueue(maxSegments) {
1232
1233
  let processed = false;
1234
+ let processedCount = 0;
1233
1235
  while (this.prefetchQueue.length > 0) {
1236
+ if (maxSegments !== void 0 && processedCount >= maxSegments) {
1237
+ break;
1238
+ }
1234
1239
  const item = this.prefetchQueue[0];
1235
1240
  if (item.segmentIndex !== this.currentSegmentIndex) {
1236
1241
  break;
@@ -1246,6 +1251,7 @@ class SegmentPrefetcher extends BasePrefetcher {
1246
1251
  callbacks.onSegmentParsed?.(item.segmentIndex, itemCount);
1247
1252
  console.log(`[SegmentPrefetcher] Parsed segment #${item.segmentIndex}: ${itemCount} items, ${parseTime.toFixed(0)}ms`);
1248
1253
  processed = true;
1254
+ processedCount++;
1249
1255
  }
1250
1256
  return processed;
1251
1257
  }
@@ -1717,7 +1723,11 @@ class HLSPlayer extends BasePlayer {
1717
1723
  console.log("[DecodeLoop] START, isFMP4:", this.isFMP4);
1718
1724
  let batchCount = 0;
1719
1725
  while (this.isPlaying && !this.decodeLoopAbort) {
1720
- this.prefetcher?.processQueue();
1726
+ const sampleQueueSize = this.sampleQueue.length;
1727
+ const maxSamplesBeforePause = this.config.maxQueueSize * 3;
1728
+ if (sampleQueueSize < maxSamplesBeforePause && this.prefetcher) {
1729
+ this.prefetcher.processQueue(1);
1730
+ }
1721
1731
  if (!this.config.isLive && this.frameBuffer.length >= this.config.targetBufferSize) {
1722
1732
  await this.sleep(10);
1723
1733
  continue;