@give-tech/ec-player 0.0.1-beta.12 → 0.0.1-beta.14
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":"fMP4Demuxer.d.ts","sourceRoot":"","sources":["../../src/demuxer/fMP4Demuxer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA8CH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAC/B;AAED,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,sBAAsB,CAAC,EAAE,MAAM,CAAA;IAC/B,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED,MAAM,WAAW,OAAO;IACtB,mBAAmB,EAAE,MAAM,CAAA;CAC5B;AAED,MAAM,WAAW,OAAO;IACtB,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,OAAO,EAAE,UAAU,EAAE,CAAA;CACtB;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,KAAK,EAAE,OAAO,EAAE,CAAA;CACjB;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,CAAC,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE,CAAA;IACjC,KAAK,EAAE,OAAO,EAAE,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MA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H,OAAO,CAAC,SAAS;IAkBjB;;OAEG;IACH,OAAO,CAAC,SAAS;IAoCjB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IA2B9B;;OAEG;IACH,OAAO,CAAC,SAAS;IASjB;;OAEG;IACH,OAAO,CAAC,SAAS;IAkBjB;;OAEG;IACH,OAAO,CAAC,SAAS;IAkBjB;;OAEG;IACH,OAAO,CAAC,SAAS;IA0BjB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAmB3B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAoB5B;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO;IAiCxD;;OAEG;IACH,OAAO,CAAC,SAAS;IA8BjB;;OAEG;IACH,OAAO,CAAC,SAAS;IA+BjB;;OAEG;IACH,OAAO,CAAC,SAAS;IASjB;;OAEG;IACH,OAAO,CAAC,SAAS;IAiEjB;;;OAGG;IACH,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,WAAW,EAAE;IA0D1G;;OAEG;IACH,YAAY,IAAI,MAAM;IAItB;;OAEG;IACH,OAAO,IAAI,UAAU,GAAG,IAAI;IAI5B;;OAEG;IACH,OAAO,IAAI,UAAU,GAAG,IAAI;IAI5B;;OAEG;IACH,YAAY,IAAI,OAAO;CAGxB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAuBzD"}
|
package/dist/index.js
CHANGED
|
@@ -464,7 +464,6 @@ class fMP4Demuxer {
|
|
|
464
464
|
const endOffset = trakOffset + trakSize;
|
|
465
465
|
let currentTrackId = null;
|
|
466
466
|
let isVideoTrack = false;
|
|
467
|
-
console.log("[fMP4Demuxer] parseTrak called, size:", trakSize);
|
|
468
467
|
while (offset < endOffset - 8) {
|
|
469
468
|
const boxSize = readUint32$1(data, offset);
|
|
470
469
|
const boxType = readFourCC(data, offset + 4);
|
|
@@ -477,12 +476,10 @@ class fMP4Demuxer {
|
|
|
477
476
|
} else {
|
|
478
477
|
currentTrackId = readUint32$1(data, boxDataStart + 1 + 3 + 4 + 4);
|
|
479
478
|
}
|
|
480
|
-
console.log("[fMP4Demuxer] tkhd: version=", version, "trackId=", currentTrackId);
|
|
481
479
|
} else if (boxType === "mdia") {
|
|
482
480
|
isVideoTrack = this.parseMdiaAndCheckVideo(data, offset, boxSize);
|
|
483
481
|
if (isVideoTrack && currentTrackId !== null) {
|
|
484
482
|
this.trackId = currentTrackId;
|
|
485
|
-
console.log("[fMP4Demuxer] Found video track, trackId:", currentTrackId);
|
|
486
483
|
}
|
|
487
484
|
}
|
|
488
485
|
offset += boxSize;
|
|
@@ -606,7 +603,6 @@ class fMP4Demuxer {
|
|
|
606
603
|
if (boxSize < 8) break;
|
|
607
604
|
if (boxType === "hvcC") {
|
|
608
605
|
this.hvcC = data.slice(offset, offset + boxSize);
|
|
609
|
-
console.log("[fMP4Demuxer] Found hvcC, size:", boxSize);
|
|
610
606
|
return;
|
|
611
607
|
}
|
|
612
608
|
offset += boxSize;
|
|
@@ -768,9 +764,7 @@ class fMP4Demuxer {
|
|
|
768
764
|
const samples = [];
|
|
769
765
|
for (const traf of moof.trafs) {
|
|
770
766
|
if (!traf.tfhd || !traf.tfdt) continue;
|
|
771
|
-
console.log(`[fMP4Demuxer] extractSamples: traf.trackId=${traf.tfhd.trackId}, videoTrackId=${this.trackId}`);
|
|
772
767
|
if (traf.tfhd.trackId !== this.trackId) {
|
|
773
|
-
console.log(`[fMP4Demuxer] Skipping track ${traf.tfhd.trackId}`);
|
|
774
768
|
continue;
|
|
775
769
|
}
|
|
776
770
|
let baseDts = traf.tfdt.baseMediaDecodeTime;
|
|
@@ -1553,9 +1547,15 @@ class HLSPlayer extends BasePlayer {
|
|
|
1553
1547
|
this.prefetcher = null;
|
|
1554
1548
|
this.lastRenderTime = 0;
|
|
1555
1549
|
this.playStartTime = 0;
|
|
1556
|
-
this.
|
|
1550
|
+
this.accumulatedMediaTime = 0;
|
|
1551
|
+
this._lastLogTime = 0;
|
|
1557
1552
|
this.renderLoop = (timestamp = 0) => {
|
|
1558
1553
|
if (!this.isPlaying) return;
|
|
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
|
+
}
|
|
1559
1559
|
const downloaded = this.isFMP4 ? this.sampleQueue.length : this.nalQueue.length;
|
|
1560
1560
|
const segments = this.isFMP4 ? this.fmp4Segments : this.segments;
|
|
1561
1561
|
const totalSegments = segments.length;
|
|
@@ -1568,25 +1568,32 @@ class HLSPlayer extends BasePlayer {
|
|
|
1568
1568
|
});
|
|
1569
1569
|
if (this.frameBuffer.length > 0 && this.renderer) {
|
|
1570
1570
|
const frame = this.frameBuffer[0];
|
|
1571
|
-
if (this.playStartTime === 0 || this.firstFramePts === null) {
|
|
1572
|
-
this.playStartTime = performance.now();
|
|
1573
|
-
this.firstFramePts = frame.pts ?? 0;
|
|
1574
|
-
}
|
|
1575
|
-
const elapsedMs = performance.now() - this.playStartTime;
|
|
1576
1571
|
const timescale = this.fmp4Demuxer.getTimescale();
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1572
|
+
if (this.playStartTime === 0) {
|
|
1573
|
+
this.playStartTime = now;
|
|
1574
|
+
this.accumulatedMediaTime = 0;
|
|
1575
|
+
console.log("[renderLoop] Init: timescale=", timescale);
|
|
1576
|
+
}
|
|
1577
|
+
const elapsedWallTime = now - this.playStartTime;
|
|
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
|
+
}
|
|
1582
|
+
const bufferMs = 50;
|
|
1583
|
+
if (elapsedWallTime >= this.accumulatedMediaTime - bufferMs) {
|
|
1580
1584
|
this.frameBuffer.shift();
|
|
1581
1585
|
this.renderer.render(frame);
|
|
1582
|
-
this.
|
|
1586
|
+
this.accumulatedMediaTime += frameDurationMs;
|
|
1587
|
+
this.setCurrentTime(this.accumulatedMediaTime / 1e3);
|
|
1583
1588
|
this.updateState({ resolution: `${frame.width}x${frame.height}` });
|
|
1584
1589
|
const fps = this.renderer.updateFps();
|
|
1585
1590
|
this.updateState({ fps });
|
|
1586
1591
|
this.callbacks.onFrameRender?.(frame);
|
|
1587
1592
|
}
|
|
1588
1593
|
} else {
|
|
1589
|
-
this.
|
|
1594
|
+
if (this.playStartTime !== 0) {
|
|
1595
|
+
this.playStartTime = now - this.accumulatedMediaTime;
|
|
1596
|
+
}
|
|
1590
1597
|
}
|
|
1591
1598
|
this.frameTimer = requestAnimationFrame(this.renderLoop);
|
|
1592
1599
|
};
|
|
@@ -1665,7 +1672,7 @@ class HLSPlayer extends BasePlayer {
|
|
|
1665
1672
|
this.decodeLoopAbort = false;
|
|
1666
1673
|
this.lastRenderTime = 0;
|
|
1667
1674
|
this.playStartTime = 0;
|
|
1668
|
-
this.
|
|
1675
|
+
this.accumulatedMediaTime = 0;
|
|
1669
1676
|
this.updateState({ isPlaying: true });
|
|
1670
1677
|
if (!this.prefetcher) {
|
|
1671
1678
|
this.initPrefetcher();
|
|
@@ -1712,6 +1719,10 @@ class HLSPlayer extends BasePlayer {
|
|
|
1712
1719
|
const batchSize = this.config.decodeBatchSize;
|
|
1713
1720
|
let decodedInBatch = 0;
|
|
1714
1721
|
if (this.isFMP4) {
|
|
1722
|
+
const queueSize = this.sampleQueue.length;
|
|
1723
|
+
if (queueSize > 0 || batchCount % 50 === 0) {
|
|
1724
|
+
console.log("[DecodeLoop] fMP4: sampleQueue=", queueSize, "frameBuffer=", this.frameBuffer.length, "batch=", batchCount);
|
|
1725
|
+
}
|
|
1715
1726
|
while (this.sampleQueue.length > 0 && decodedInBatch < batchSize) {
|
|
1716
1727
|
const queuedSample = this.sampleQueue.shift();
|
|
1717
1728
|
const sample = queuedSample.sample;
|
|
@@ -1837,7 +1848,9 @@ class HLSPlayer extends BasePlayer {
|
|
|
1837
1848
|
this._sampleQueue.push({ sample });
|
|
1838
1849
|
}
|
|
1839
1850
|
totalSampleCount += samples.length;
|
|
1851
|
+
console.log("[parseFMP4Data] Pushed", samples.length, "samples, totalQueue=", this._sampleQueue.length);
|
|
1840
1852
|
}
|
|
1853
|
+
console.log("[parseFMP4Data] Total samples parsed:", totalSampleCount);
|
|
1841
1854
|
return totalSampleCount;
|
|
1842
1855
|
}
|
|
1843
1856
|
/**
|
|
@@ -2214,6 +2227,7 @@ class HLSPlayer extends BasePlayer {
|
|
|
2214
2227
|
if (frame) {
|
|
2215
2228
|
frame.pts = sample.pts;
|
|
2216
2229
|
frame.dts = sample.dts;
|
|
2230
|
+
frame.duration = sample.duration;
|
|
2217
2231
|
}
|
|
2218
2232
|
return frame;
|
|
2219
2233
|
}
|