@give-tech/ec-player 0.0.1-beta.56 → 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
  /**
@@ -2617,7 +2673,31 @@ class HLSPlayer extends BasePlayer {
2617
2673
  }
2618
2674
  let content;
2619
2675
  try {
2620
- content = await response.text();
2676
+ const M3U8_READ_TIMEOUT = 15e3;
2677
+ const body = response.body;
2678
+ if (body) {
2679
+ const reader = body.getReader();
2680
+ const decoder = new TextDecoder();
2681
+ let text = "";
2682
+ const startTime = Date.now();
2683
+ while (true) {
2684
+ if (this.abortController?.signal.aborted) {
2685
+ reader.cancel();
2686
+ throw new DOMException("Aborted", "AbortError");
2687
+ }
2688
+ const { done, value } = await reader.read();
2689
+ if (done) break;
2690
+ text += decoder.decode(value, { stream: true });
2691
+ if (text.includes("#EXT-X-ENDLIST")) break;
2692
+ if (Date.now() - startTime > M3U8_READ_TIMEOUT || text.length > 5e4) break;
2693
+ }
2694
+ content = text + decoder.decode();
2695
+ if (Date.now() - startTime > M3U8_READ_TIMEOUT || !text.includes("#EXT-X-ENDLIST")) {
2696
+ logger$2.debug("parsePlaylist m3u8 streaming read completed, size:", content.length, "hasEndList:", text.includes("#EXT-X-ENDLIST"));
2697
+ }
2698
+ } else {
2699
+ content = await response.text();
2700
+ }
2621
2701
  } catch (error) {
2622
2702
  throw error;
2623
2703
  }
@@ -2646,7 +2726,7 @@ class HLSPlayer extends BasePlayer {
2646
2726
  return { isMaster: true, isFMP4: false, segments: [], fmp4Segments: [], variants: variants.length };
2647
2727
  }
2648
2728
  const isFMP4 = lines.some((line) => line.includes("#EXT-X-MAP:"));
2649
- console.log("[parsePlaylist] isFMP4:", isFMP4, "url:", url);
2729
+ logger$2.debug("parsePlaylist isFMP4:", isFMP4, "url:", url);
2650
2730
  let currentInitSegment;
2651
2731
  for (let i = 0; i < lines.length; i++) {
2652
2732
  const line = lines[i].trim();
@@ -2788,7 +2868,7 @@ class HLSPlayer extends BasePlayer {
2788
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(" "));
2789
2869
  return null;
2790
2870
  }
2791
- 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);
2792
2872
  const annexBData = new Uint8Array(totalSize);
2793
2873
  let writeOffset = 0;
2794
2874
  offset = 0;
@@ -2840,6 +2920,7 @@ class HLSPlayer extends BasePlayer {
2840
2920
  return frame;
2841
2921
  }
2842
2922
  }
2923
+ const logger = createLogger("FLVDemuxer");
2843
2924
  const FLV_SIGNATURE = [70, 76, 86];
2844
2925
  const FLV_VERSION = 1;
2845
2926
  const TAG_TYPE_VIDEO = 9;
@@ -3013,14 +3094,14 @@ class FLVDemuxer {
3013
3094
  if (avcPacketType === AVC_PACKET_SEQUENCE_HEADER) {
3014
3095
  if (codecId === CODEC_ID_HEVC$1) {
3015
3096
  this.hevcConfig = this.parseHEVCSequenceHeader(avcData);
3016
- console.log("[FLVDemuxer] Parsed HEVC Sequence Header:", {
3097
+ logger.debug("Parsed HEVC Sequence Header:", {
3017
3098
  vpsCount: this.hevcConfig?.vpsList.length,
3018
3099
  spsCount: this.hevcConfig?.spsList.length,
3019
3100
  ppsCount: this.hevcConfig?.ppsList.length
3020
3101
  });
3021
3102
  } else {
3022
3103
  this.avcConfig = this.parseSequenceHeader(avcData);
3023
- console.log("[FLVDemuxer] Parsed AVC Sequence Header:", {
3104
+ logger.debug("Parsed AVC Sequence Header:", {
3024
3105
  profile: this.avcConfig?.avcProfileIndication,
3025
3106
  level: this.avcConfig?.avcLevelIndication,
3026
3107
  spsCount: this.avcConfig?.spsList.length,
@@ -3367,6 +3448,8 @@ class FLVPlayer extends BasePlayer {
3367
3448
  this.abortController = null;
3368
3449
  this.readyFired = false;
3369
3450
  this._currentDownloadSpeed = 0;
3451
+ this._logPrefetch = null;
3452
+ this._logDataReceived = null;
3370
3453
  this._decoderInitContext = null;
3371
3454
  this._totalFileSize = 0;
3372
3455
  this._downloadedBytes = 0;
@@ -3477,7 +3560,7 @@ class FLVPlayer extends BasePlayer {
3477
3560
  }
3478
3561
  }
3479
3562
  }
3480
- if (now - this.lastRenderLogTime > 5e3) {
3563
+ if (now - this.lastRenderLogTime > 1e4) {
3481
3564
  console.log("[FLVPlayer] RenderLoop stats:", {
3482
3565
  renderedFrames: this.renderedFrames,
3483
3566
  droppedFrames: this.droppedFrames,
@@ -3821,7 +3904,8 @@ class FLVPlayer extends BasePlayer {
3821
3904
  }
3822
3905
  }
3823
3906
  if (newCount > 0) {
3824
- 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}`);
3825
3909
  }
3826
3910
  return { hasNewData: newCount > 0, processedBytes: data.length };
3827
3911
  }
@@ -3894,7 +3978,7 @@ class FLVPlayer extends BasePlayer {
3894
3978
  this.adjustBufferForResolution(frame.width, frame.height);
3895
3979
  }
3896
3980
  if (this._timedFrameBuffer.length <= 5) {
3897
- 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);
3898
3982
  }
3899
3983
  } else {
3900
3984
  this.decodeFailCount++;
@@ -4013,7 +4097,7 @@ class FLVPlayer extends BasePlayer {
4013
4097
  }
4014
4098
  this._videoTagQueue = [];
4015
4099
  this.parseAndQueueFLV(allData);
4016
- if (this._videoTagQueue.length - lastLoggedTags >= 50) {
4100
+ if (this._videoTagQueue.length - lastLoggedTags >= 200) {
4017
4101
  console.log("[FLVPlayer] Stream:", this._videoTagQueue.length, "tags,", totalLength, "bytes");
4018
4102
  lastLoggedTags = this._videoTagQueue.length;
4019
4103
  }
@@ -4068,7 +4152,8 @@ class FLVPlayer extends BasePlayer {
4068
4152
  this._currentDownloadSpeed = status.downloadSpeed;
4069
4153
  },
4070
4154
  onDataReceived: (totalBytes) => {
4071
- console.log(`[FLVPlayer] Data received: ${totalBytes} bytes`);
4155
+ if (!this._logDataReceived) this._logDataReceived = throttleLog("[FLVPlayer]", 2e3);
4156
+ this._logDataReceived(`Data received: ${totalBytes} bytes`);
4072
4157
  }
4073
4158
  },
4074
4159
  this
@@ -4968,16 +5053,6 @@ const _EnvDetector = class _EnvDetector {
4968
5053
  };
4969
5054
  _EnvDetector.cache = null;
4970
5055
  let EnvDetector = _EnvDetector;
4971
- var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
4972
- LogLevel2[LogLevel2["NONE"] = 0] = "NONE";
4973
- LogLevel2[LogLevel2["ERROR"] = 1] = "ERROR";
4974
- LogLevel2[LogLevel2["WARN"] = 2] = "WARN";
4975
- LogLevel2[LogLevel2["INFO"] = 3] = "INFO";
4976
- LogLevel2[LogLevel2["DEBUG"] = 4] = "DEBUG";
4977
- return LogLevel2;
4978
- })(LogLevel || {});
4979
- function setLogLevel(level) {
4980
- }
4981
5056
  export {
4982
5057
  EcPlayerCore,
4983
5058
  EnvDetector,