@give-tech/ec-player 0.0.1-beta.57 → 0.0.1-beta.58

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.
@@ -1 +1 @@
1
- {"version":3,"file":"FLVDemuxer.d.ts","sourceRoot":"","sources":["../../src/demuxer/FLVDemuxer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,cAAc,EACd,aAAa,EACd,MAAM,UAAU,CAAA;AAoDjB,qBAAa,UAAU;IACrB,OAAO,CAAC,SAAS,CAA4B;IAC7C,OAAO,CAAC,UAAU,CAA6B;IAC/C,OAAO,CAAC,OAAO,CAAuB;IAGtC,OAAO,CAAC,WAAW,CAAI;IACvB,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,UAAU,CAAI;IAEtB;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO;IAkBvC;;OAEG;IACH,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,cAAc;IAgEvC;;;;;OAKG;IACH,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,cAAc;IA2DlD;;OAEG;IACH,gBAAgB,IAAI,IAAI;IAOxB;;;OAGG;IACH,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAKrC;;;;;;;;OAQG;IACH,OAAO,CAAC,aAAa;IA0DrB;;;;;;;;;;;;;;;;;OAiBG;IACH,mBAAmB,CAAC,IAAI,EAAE,UAAU,GAAG,YAAY,GAAG,IAAI;IAqE1D;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,uBAAuB,CAAC,IAAI,EAAE,UAAU,GAAG,aAAa,GAAG,IAAI;IAyH/D;;OAEG;IACH,YAAY,IAAI,YAAY,GAAG,IAAI;IAInC;;OAEG;IACH,aAAa,IAAI,aAAa,GAAG,IAAI;IAIrC;;OAEG;IACH,UAAU,IAAI,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;OAEG;IACH,YAAY,IAAI,YAAY,GAAG,IAAI;IAInC;;OAEG;IACH,aAAa,IAAI,aAAa,GAAG,IAAI;IAIrC;;OAEG;IACH,UAAU,IAAI,MAAM;IAIpB;;;;;;;;;OASG;IACH,gBAAgB,CAAC,GAAG,EAAE,WAAW,EAAE,UAAU,GAAE,MAAU,GAAG,UAAU,GAAG,IAAI;IA+D7E;;OAEG;IACH,UAAU,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO;CAGtC;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAE/C"}
package/dist/index.js CHANGED
@@ -1155,6 +1155,60 @@ class HEVCDecoder {
1155
1155
  return rgba;
1156
1156
  }
1157
1157
  }
1158
+ var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
1159
+ LogLevel2[LogLevel2["NONE"] = 0] = "NONE";
1160
+ LogLevel2[LogLevel2["ERROR"] = 1] = "ERROR";
1161
+ LogLevel2[LogLevel2["WARN"] = 2] = "WARN";
1162
+ LogLevel2[LogLevel2["INFO"] = 3] = "INFO";
1163
+ LogLevel2[LogLevel2["DEBUG"] = 4] = "DEBUG";
1164
+ return LogLevel2;
1165
+ })(LogLevel || {});
1166
+ let currentLogLevel = 3;
1167
+ function setLogLevel(level) {
1168
+ currentLogLevel = level;
1169
+ }
1170
+ function createLogger(moduleName) {
1171
+ const prefix = `[${moduleName}]`;
1172
+ return {
1173
+ error: (...args) => {
1174
+ if (currentLogLevel >= 1) {
1175
+ console.error(prefix, ...args);
1176
+ }
1177
+ },
1178
+ warn: (...args) => {
1179
+ if (currentLogLevel >= 2) {
1180
+ console.warn(prefix, ...args);
1181
+ }
1182
+ },
1183
+ info: (...args) => {
1184
+ if (currentLogLevel >= 3) {
1185
+ console.log(prefix, ...args);
1186
+ }
1187
+ },
1188
+ debug: (...args) => {
1189
+ if (currentLogLevel >= 4) {
1190
+ console.log(prefix, ...args);
1191
+ }
1192
+ },
1193
+ log: (...args) => {
1194
+ if (currentLogLevel >= 3) {
1195
+ console.log(prefix, ...args);
1196
+ }
1197
+ }
1198
+ };
1199
+ }
1200
+ function throttleLog(prefix, intervalMs = 1e3) {
1201
+ let lastTime = 0;
1202
+ return (...args) => {
1203
+ if (currentLogLevel < 3) return;
1204
+ const now = performance.now();
1205
+ if (now - lastTime >= intervalMs) {
1206
+ lastTime = now;
1207
+ console.log(prefix, ...args);
1208
+ }
1209
+ };
1210
+ }
1211
+ const logger$2 = createLogger("EcPlayer");
1158
1212
  class BasePrefetcher {
1159
1213
  constructor(config, callbacks = {}) {
1160
1214
  this.isRunning = false;
@@ -1320,6 +1374,7 @@ class BasePrefetcher {
1320
1374
  console.log("[BasePrefetcher] Reset complete");
1321
1375
  }
1322
1376
  }
1377
+ const logger$1 = createLogger("SegmentPrefetcher");
1323
1378
  class SegmentPrefetcher extends BasePrefetcher {
1324
1379
  constructor(config, callbacks = {}) {
1325
1380
  super(config, callbacks);
@@ -1429,7 +1484,7 @@ class SegmentPrefetcher extends BasePrefetcher {
1429
1484
  });
1430
1485
  const callbacks = this.callbacks;
1431
1486
  callbacks.onSegmentFetched?.(nextIndex, data);
1432
- console.log(`[SegmentPrefetcher] Fetched segment #${nextIndex}: ${data.length} bytes, ${fetchTime.toFixed(0)}ms`);
1487
+ logger$1.debug(`Fetched segment #${nextIndex}: ${data.length} bytes, ${fetchTime.toFixed(0)}ms`);
1433
1488
  } catch (error) {
1434
1489
  if (error.name === "AbortError") {
1435
1490
  console.log(`[SegmentPrefetcher] Fetch aborted`);
@@ -1470,7 +1525,7 @@ class SegmentPrefetcher extends BasePrefetcher {
1470
1525
  this.updateStatus({ currentSegmentIndex: this.currentSegmentIndex });
1471
1526
  const callbacks = this.callbacks;
1472
1527
  callbacks.onSegmentParsed?.(item.segmentIndex, itemCount);
1473
- console.log(`[SegmentPrefetcher] Parsed segment #${item.segmentIndex}: ${itemCount} items, ${parseTime.toFixed(0)}ms`);
1528
+ logger$1.debug(`Parsed segment #${item.segmentIndex}: ${itemCount} items, ${parseTime.toFixed(0)}ms`);
1474
1529
  processed = true;
1475
1530
  processedCount++;
1476
1531
  }
@@ -1871,7 +1926,7 @@ class HLSPlayer extends BasePlayer {
1871
1926
  }
1872
1927
  }
1873
1928
  this._lastRafTime = now;
1874
- if (!this._lastLogTime || now - this._lastLogTime > 1e3) {
1929
+ if (!this._lastLogTime || now - this._lastLogTime > 3e3) {
1875
1930
  this._lastLogTime = now;
1876
1931
  console.log("[renderLoop] frameBuffer=", this.frameBuffer.length, "renderer=", !!this.renderer);
1877
1932
  }
@@ -1902,7 +1957,7 @@ class HLSPlayer extends BasePlayer {
1902
1957
  console.log("[renderLoop] Buffer recovered, reset playStartTime to continue from", Math.floor(this.accumulatedMediaTime), "ms");
1903
1958
  }
1904
1959
  const elapsedWallTime = (now - this.playStartTime) * this._playbackRate;
1905
- if (Math.floor(elapsedWallTime / 1e3) !== Math.floor((elapsedWallTime - 20 * this._playbackRate) / 1e3)) {
1960
+ if (Math.floor(elapsedWallTime / 3e3) !== Math.floor((elapsedWallTime - 60 * this._playbackRate) / 3e3)) {
1906
1961
  console.log("[renderLoop] elapsed=", Math.floor(elapsedWallTime), "accumulated=", Math.floor(this.accumulatedMediaTime), "rate=", this._playbackRate, "frameBuffer=", this.frameBuffer.length);
1907
1962
  }
1908
1963
  const getFrameDurationMs = (frame2) => {
@@ -2150,6 +2205,7 @@ class HLSPlayer extends BasePlayer {
2150
2205
  */
2151
2206
  async decodeLoop() {
2152
2207
  console.log("[DecodeLoop] START, isFMP4:", this.isFMP4);
2208
+ const _logDecodeStatus = throttleLog("[DecodeLoop]", 2e3);
2153
2209
  let batchCount = 0;
2154
2210
  const CHECK_INTERVAL_MS = 5e3;
2155
2211
  let checkCount = 0;
@@ -2190,7 +2246,7 @@ class HLSPlayer extends BasePlayer {
2190
2246
  if (this.isFMP4) {
2191
2247
  const queueSize = this.sampleQueue.length;
2192
2248
  if (queueSize > 0 || batchCount % 50 === 0) {
2193
- console.log("[DecodeLoop] fMP4: sampleQueue=", queueSize, "frameBuffer=", this.frameBuffer.length, "batch=", batchCount, "decoderInit=", this.decoderInitialized, "rate=", this._playbackRate);
2249
+ _logDecodeStatus("fMP4: sampleQueue=", queueSize, "frameBuffer=", this.frameBuffer.length, "batch=", batchCount, "decoderInit=", this.decoderInitialized, "rate=", this._playbackRate);
2194
2250
  }
2195
2251
  if (this._playbackRate > 1) {
2196
2252
  const skipInterval = this._playbackRate;
@@ -2220,7 +2276,7 @@ class HLSPlayer extends BasePlayer {
2220
2276
  }
2221
2277
  }
2222
2278
  if (samplesProcessed > 10 && this.droppedFrames > 0) {
2223
- console.log("[DecodeLoop] High rate", this._playbackRate, "x: processed", samplesProcessed, "samples, decoded", decodedInBatch, "dropped", this.droppedFrames);
2279
+ _logDecodeStatus("High rate", this._playbackRate, "x: processed", samplesProcessed, "samples, decoded", decodedInBatch, "dropped", this.droppedFrames);
2224
2280
  }
2225
2281
  } else {
2226
2282
  while (this.sampleQueue.length > 0 && decodedInBatch < batchSize) {
@@ -2374,9 +2430,9 @@ class HLSPlayer extends BasePlayer {
2374
2430
  this._sampleQueue.push({ sample });
2375
2431
  }
2376
2432
  totalSampleCount += samples.length;
2377
- console.log("[parseFMP4Data] Pushed", samples.length, "samples, totalQueue=", this._sampleQueue.length);
2433
+ logger$2.debug("parseFMP4Data Pushed", samples.length, "samples, totalQueue=", this._sampleQueue.length);
2378
2434
  }
2379
- console.log("[parseFMP4Data] Total samples parsed:", totalSampleCount);
2435
+ logger$2.debug("parseFMP4Data Total samples parsed:", totalSampleCount);
2380
2436
  return totalSampleCount;
2381
2437
  }
2382
2438
  /**
@@ -2637,7 +2693,7 @@ class HLSPlayer extends BasePlayer {
2637
2693
  }
2638
2694
  content = text + decoder.decode();
2639
2695
  if (Date.now() - startTime > M3U8_READ_TIMEOUT || !text.includes("#EXT-X-ENDLIST")) {
2640
- console.log("[parsePlaylist] m3u8 streaming read completed, size:", content.length, "hasEndList:", text.includes("#EXT-X-ENDLIST"));
2696
+ logger$2.debug("parsePlaylist m3u8 streaming read completed, size:", content.length, "hasEndList:", text.includes("#EXT-X-ENDLIST"));
2641
2697
  }
2642
2698
  } else {
2643
2699
  content = await response.text();
@@ -2670,7 +2726,7 @@ class HLSPlayer extends BasePlayer {
2670
2726
  return { isMaster: true, isFMP4: false, segments: [], fmp4Segments: [], variants: variants.length };
2671
2727
  }
2672
2728
  const isFMP4 = lines.some((line) => line.includes("#EXT-X-MAP:"));
2673
- console.log("[parsePlaylist] isFMP4:", isFMP4, "url:", url);
2729
+ logger$2.debug("parsePlaylist isFMP4:", isFMP4, "url:", url);
2674
2730
  let currentInitSegment;
2675
2731
  for (let i = 0; i < lines.length; i++) {
2676
2732
  const line = lines[i].trim();
@@ -2812,7 +2868,7 @@ class HLSPlayer extends BasePlayer {
2812
2868
  console.warn("[fMP4] No valid NAL units found in sample, data.length=", data.length, "lengthSize=", lengthSize, "firstBytes=", Array.from(data.slice(0, 8)).map((b) => b.toString(16).padStart(2, "0")).join(" "));
2813
2869
  return null;
2814
2870
  }
2815
- console.log("[fMP4] AVCC sample: nalCount=", nalCount, "annexBSize=", totalSize, "isSync=", sample.isSync, "lengthSize=", lengthSize);
2871
+ logger$2.debug("AVCC sample: nalCount=", nalCount, "annexBSize=", totalSize, "isSync=", sample.isSync, "lengthSize=", lengthSize);
2816
2872
  const annexBData = new Uint8Array(totalSize);
2817
2873
  let writeOffset = 0;
2818
2874
  offset = 0;
@@ -2864,6 +2920,7 @@ class HLSPlayer extends BasePlayer {
2864
2920
  return frame;
2865
2921
  }
2866
2922
  }
2923
+ const logger = createLogger("FLVDemuxer");
2867
2924
  const FLV_SIGNATURE = [70, 76, 86];
2868
2925
  const FLV_VERSION = 1;
2869
2926
  const TAG_TYPE_VIDEO = 9;
@@ -3037,14 +3094,14 @@ class FLVDemuxer {
3037
3094
  if (avcPacketType === AVC_PACKET_SEQUENCE_HEADER) {
3038
3095
  if (codecId === CODEC_ID_HEVC$1) {
3039
3096
  this.hevcConfig = this.parseHEVCSequenceHeader(avcData);
3040
- console.log("[FLVDemuxer] Parsed HEVC Sequence Header:", {
3097
+ logger.debug("Parsed HEVC Sequence Header:", {
3041
3098
  vpsCount: this.hevcConfig?.vpsList.length,
3042
3099
  spsCount: this.hevcConfig?.spsList.length,
3043
3100
  ppsCount: this.hevcConfig?.ppsList.length
3044
3101
  });
3045
3102
  } else {
3046
3103
  this.avcConfig = this.parseSequenceHeader(avcData);
3047
- console.log("[FLVDemuxer] Parsed AVC Sequence Header:", {
3104
+ logger.debug("Parsed AVC Sequence Header:", {
3048
3105
  profile: this.avcConfig?.avcProfileIndication,
3049
3106
  level: this.avcConfig?.avcLevelIndication,
3050
3107
  spsCount: this.avcConfig?.spsList.length,
@@ -3391,6 +3448,8 @@ class FLVPlayer extends BasePlayer {
3391
3448
  this.abortController = null;
3392
3449
  this.readyFired = false;
3393
3450
  this._currentDownloadSpeed = 0;
3451
+ this._logPrefetch = null;
3452
+ this._logDataReceived = null;
3394
3453
  this._decoderInitContext = null;
3395
3454
  this._totalFileSize = 0;
3396
3455
  this._downloadedBytes = 0;
@@ -3501,7 +3560,7 @@ class FLVPlayer extends BasePlayer {
3501
3560
  }
3502
3561
  }
3503
3562
  }
3504
- if (now - this.lastRenderLogTime > 5e3) {
3563
+ if (now - this.lastRenderLogTime > 1e4) {
3505
3564
  console.log("[FLVPlayer] RenderLoop stats:", {
3506
3565
  renderedFrames: this.renderedFrames,
3507
3566
  droppedFrames: this.droppedFrames,
@@ -3845,7 +3904,8 @@ class FLVPlayer extends BasePlayer {
3845
3904
  }
3846
3905
  }
3847
3906
  if (newCount > 0) {
3848
- console.log(`[FLVPlayer] Prefetch: +${newCount} new tags, queue: ${this._videoTagQueue.length}`);
3907
+ if (!this._logPrefetch) this._logPrefetch = throttleLog("[FLVPlayer]", 2e3);
3908
+ this._logPrefetch(`Prefetch: +${newCount} new tags, queue: ${this._videoTagQueue.length}`);
3849
3909
  }
3850
3910
  return { hasNewData: newCount > 0, processedBytes: data.length };
3851
3911
  }
@@ -3918,7 +3978,7 @@ class FLVPlayer extends BasePlayer {
3918
3978
  this.adjustBufferForResolution(frame.width, frame.height);
3919
3979
  }
3920
3980
  if (this._timedFrameBuffer.length <= 5) {
3921
- console.log("[FLVPlayer] Frame decoded, dts:", dts, "pts:", pts, "buffer size:", this._timedFrameBuffer.length);
3981
+ logger$2.debug("Frame decoded, dts:", dts, "pts:", pts, "buffer size:", this._timedFrameBuffer.length);
3922
3982
  }
3923
3983
  } else {
3924
3984
  this.decodeFailCount++;
@@ -4037,7 +4097,7 @@ class FLVPlayer extends BasePlayer {
4037
4097
  }
4038
4098
  this._videoTagQueue = [];
4039
4099
  this.parseAndQueueFLV(allData);
4040
- if (this._videoTagQueue.length - lastLoggedTags >= 50) {
4100
+ if (this._videoTagQueue.length - lastLoggedTags >= 200) {
4041
4101
  console.log("[FLVPlayer] Stream:", this._videoTagQueue.length, "tags,", totalLength, "bytes");
4042
4102
  lastLoggedTags = this._videoTagQueue.length;
4043
4103
  }
@@ -4092,7 +4152,8 @@ class FLVPlayer extends BasePlayer {
4092
4152
  this._currentDownloadSpeed = status.downloadSpeed;
4093
4153
  },
4094
4154
  onDataReceived: (totalBytes) => {
4095
- console.log(`[FLVPlayer] Data received: ${totalBytes} bytes`);
4155
+ if (!this._logDataReceived) this._logDataReceived = throttleLog("[FLVPlayer]", 2e3);
4156
+ this._logDataReceived(`Data received: ${totalBytes} bytes`);
4096
4157
  }
4097
4158
  },
4098
4159
  this
@@ -4992,16 +5053,6 @@ const _EnvDetector = class _EnvDetector {
4992
5053
  };
4993
5054
  _EnvDetector.cache = null;
4994
5055
  let EnvDetector = _EnvDetector;
4995
- var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
4996
- LogLevel2[LogLevel2["NONE"] = 0] = "NONE";
4997
- LogLevel2[LogLevel2["ERROR"] = 1] = "ERROR";
4998
- LogLevel2[LogLevel2["WARN"] = 2] = "WARN";
4999
- LogLevel2[LogLevel2["INFO"] = 3] = "INFO";
5000
- LogLevel2[LogLevel2["DEBUG"] = 4] = "DEBUG";
5001
- return LogLevel2;
5002
- })(LogLevel || {});
5003
- function setLogLevel(level) {
5004
- }
5005
5056
  export {
5006
5057
  EcPlayerCore,
5007
5058
  EnvDetector,