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

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
  }
@@ -1730,8 +1785,8 @@ class HLSSegmentPrefetcher extends SegmentPrefetcher {
1730
1785
  async fetchSegment(segment, index) {
1731
1786
  if (segment.initSegmentUri && segment.initSegmentUri !== this.currentInitSegmentUri) {
1732
1787
  console.log("[HLSSegmentPrefetcher] Init segment changed:", segment.initSegmentUri);
1733
- await this.player.loadNewInitSegment(segment.initSegmentUri);
1734
1788
  this.currentInitSegmentUri = segment.initSegmentUri;
1789
+ await this.player.loadNewInitSegment(segment.initSegmentUri);
1735
1790
  }
1736
1791
  const baseUrl = this.baseUrl;
1737
1792
  const url = segment.uri.startsWith("http") ? segment.uri : baseUrl + segment.uri;
@@ -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
  /**
@@ -2464,8 +2520,12 @@ class HLSPlayer extends BasePlayer {
2464
2520
  */
2465
2521
  async loadNewInitSegment(uri) {
2466
2522
  console.log("[fMP4] Loading new init segment for discontinuity:", uri);
2467
- this._sampleQueue.length = 0;
2468
- this._nalQueue.length = 0;
2523
+ if (this._sampleQueue.length > 0) {
2524
+ this._sampleQueue.length = 0;
2525
+ }
2526
+ if (this._nalQueue.length > 0) {
2527
+ this._nalQueue.length = 0;
2528
+ }
2469
2529
  const url = uri.startsWith("http") ? uri : this.currentPlaylistUrl.substring(0, this.currentPlaylistUrl.lastIndexOf("/") + 1) + uri;
2470
2530
  const headers = {};
2471
2531
  if (this.initSegment?.uri === uri && this.initSegment.byteRange) {
@@ -2637,7 +2697,7 @@ class HLSPlayer extends BasePlayer {
2637
2697
  }
2638
2698
  content = text + decoder.decode();
2639
2699
  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"));
2700
+ logger$2.debug("parsePlaylist m3u8 streaming read completed, size:", content.length, "hasEndList:", text.includes("#EXT-X-ENDLIST"));
2641
2701
  }
2642
2702
  } else {
2643
2703
  content = await response.text();
@@ -2670,7 +2730,7 @@ class HLSPlayer extends BasePlayer {
2670
2730
  return { isMaster: true, isFMP4: false, segments: [], fmp4Segments: [], variants: variants.length };
2671
2731
  }
2672
2732
  const isFMP4 = lines.some((line) => line.includes("#EXT-X-MAP:"));
2673
- console.log("[parsePlaylist] isFMP4:", isFMP4, "url:", url);
2733
+ logger$2.debug("parsePlaylist isFMP4:", isFMP4, "url:", url);
2674
2734
  let currentInitSegment;
2675
2735
  for (let i = 0; i < lines.length; i++) {
2676
2736
  const line = lines[i].trim();
@@ -2812,7 +2872,7 @@ class HLSPlayer extends BasePlayer {
2812
2872
  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
2873
  return null;
2814
2874
  }
2815
- console.log("[fMP4] AVCC sample: nalCount=", nalCount, "annexBSize=", totalSize, "isSync=", sample.isSync, "lengthSize=", lengthSize);
2875
+ logger$2.debug("AVCC sample: nalCount=", nalCount, "annexBSize=", totalSize, "isSync=", sample.isSync, "lengthSize=", lengthSize);
2816
2876
  const annexBData = new Uint8Array(totalSize);
2817
2877
  let writeOffset = 0;
2818
2878
  offset = 0;
@@ -2864,6 +2924,7 @@ class HLSPlayer extends BasePlayer {
2864
2924
  return frame;
2865
2925
  }
2866
2926
  }
2927
+ const logger = createLogger("FLVDemuxer");
2867
2928
  const FLV_SIGNATURE = [70, 76, 86];
2868
2929
  const FLV_VERSION = 1;
2869
2930
  const TAG_TYPE_VIDEO = 9;
@@ -3037,14 +3098,14 @@ class FLVDemuxer {
3037
3098
  if (avcPacketType === AVC_PACKET_SEQUENCE_HEADER) {
3038
3099
  if (codecId === CODEC_ID_HEVC$1) {
3039
3100
  this.hevcConfig = this.parseHEVCSequenceHeader(avcData);
3040
- console.log("[FLVDemuxer] Parsed HEVC Sequence Header:", {
3101
+ logger.debug("Parsed HEVC Sequence Header:", {
3041
3102
  vpsCount: this.hevcConfig?.vpsList.length,
3042
3103
  spsCount: this.hevcConfig?.spsList.length,
3043
3104
  ppsCount: this.hevcConfig?.ppsList.length
3044
3105
  });
3045
3106
  } else {
3046
3107
  this.avcConfig = this.parseSequenceHeader(avcData);
3047
- console.log("[FLVDemuxer] Parsed AVC Sequence Header:", {
3108
+ logger.debug("Parsed AVC Sequence Header:", {
3048
3109
  profile: this.avcConfig?.avcProfileIndication,
3049
3110
  level: this.avcConfig?.avcLevelIndication,
3050
3111
  spsCount: this.avcConfig?.spsList.length,
@@ -3391,6 +3452,8 @@ class FLVPlayer extends BasePlayer {
3391
3452
  this.abortController = null;
3392
3453
  this.readyFired = false;
3393
3454
  this._currentDownloadSpeed = 0;
3455
+ this._logPrefetch = null;
3456
+ this._logDataReceived = null;
3394
3457
  this._decoderInitContext = null;
3395
3458
  this._totalFileSize = 0;
3396
3459
  this._downloadedBytes = 0;
@@ -3501,7 +3564,7 @@ class FLVPlayer extends BasePlayer {
3501
3564
  }
3502
3565
  }
3503
3566
  }
3504
- if (now - this.lastRenderLogTime > 5e3) {
3567
+ if (now - this.lastRenderLogTime > 1e4) {
3505
3568
  console.log("[FLVPlayer] RenderLoop stats:", {
3506
3569
  renderedFrames: this.renderedFrames,
3507
3570
  droppedFrames: this.droppedFrames,
@@ -3845,7 +3908,8 @@ class FLVPlayer extends BasePlayer {
3845
3908
  }
3846
3909
  }
3847
3910
  if (newCount > 0) {
3848
- console.log(`[FLVPlayer] Prefetch: +${newCount} new tags, queue: ${this._videoTagQueue.length}`);
3911
+ if (!this._logPrefetch) this._logPrefetch = throttleLog("[FLVPlayer]", 2e3);
3912
+ this._logPrefetch(`Prefetch: +${newCount} new tags, queue: ${this._videoTagQueue.length}`);
3849
3913
  }
3850
3914
  return { hasNewData: newCount > 0, processedBytes: data.length };
3851
3915
  }
@@ -3918,7 +3982,7 @@ class FLVPlayer extends BasePlayer {
3918
3982
  this.adjustBufferForResolution(frame.width, frame.height);
3919
3983
  }
3920
3984
  if (this._timedFrameBuffer.length <= 5) {
3921
- console.log("[FLVPlayer] Frame decoded, dts:", dts, "pts:", pts, "buffer size:", this._timedFrameBuffer.length);
3985
+ logger$2.debug("Frame decoded, dts:", dts, "pts:", pts, "buffer size:", this._timedFrameBuffer.length);
3922
3986
  }
3923
3987
  } else {
3924
3988
  this.decodeFailCount++;
@@ -4037,7 +4101,7 @@ class FLVPlayer extends BasePlayer {
4037
4101
  }
4038
4102
  this._videoTagQueue = [];
4039
4103
  this.parseAndQueueFLV(allData);
4040
- if (this._videoTagQueue.length - lastLoggedTags >= 50) {
4104
+ if (this._videoTagQueue.length - lastLoggedTags >= 200) {
4041
4105
  console.log("[FLVPlayer] Stream:", this._videoTagQueue.length, "tags,", totalLength, "bytes");
4042
4106
  lastLoggedTags = this._videoTagQueue.length;
4043
4107
  }
@@ -4092,7 +4156,8 @@ class FLVPlayer extends BasePlayer {
4092
4156
  this._currentDownloadSpeed = status.downloadSpeed;
4093
4157
  },
4094
4158
  onDataReceived: (totalBytes) => {
4095
- console.log(`[FLVPlayer] Data received: ${totalBytes} bytes`);
4159
+ if (!this._logDataReceived) this._logDataReceived = throttleLog("[FLVPlayer]", 2e3);
4160
+ this._logDataReceived(`Data received: ${totalBytes} bytes`);
4096
4161
  }
4097
4162
  },
4098
4163
  this
@@ -4992,16 +5057,6 @@ const _EnvDetector = class _EnvDetector {
4992
5057
  };
4993
5058
  _EnvDetector.cache = null;
4994
5059
  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
5060
  export {
5006
5061
  EcPlayerCore,
5007
5062
  EnvDetector,