@give-tech/ec-player 0.0.1-beta.11 → 0.0.1-beta.13
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;
|
|
@@ -1552,8 +1546,11 @@ class HLSPlayer extends BasePlayer {
|
|
|
1552
1546
|
this._sampleQueue = [];
|
|
1553
1547
|
this.prefetcher = null;
|
|
1554
1548
|
this.lastRenderTime = 0;
|
|
1549
|
+
this.playStartTime = 0;
|
|
1550
|
+
this.accumulatedMediaTime = 0;
|
|
1555
1551
|
this.renderLoop = (timestamp = 0) => {
|
|
1556
1552
|
if (!this.isPlaying) return;
|
|
1553
|
+
const now = performance.now();
|
|
1557
1554
|
const downloaded = this.isFMP4 ? this.sampleQueue.length : this.nalQueue.length;
|
|
1558
1555
|
const segments = this.isFMP4 ? this.fmp4Segments : this.segments;
|
|
1559
1556
|
const totalSegments = segments.length;
|
|
@@ -1565,17 +1562,25 @@ class HLSPlayer extends BasePlayer {
|
|
|
1565
1562
|
totalSegments
|
|
1566
1563
|
});
|
|
1567
1564
|
if (this.frameBuffer.length > 0 && this.renderer) {
|
|
1568
|
-
const frame = this.frameBuffer
|
|
1569
|
-
this.
|
|
1570
|
-
if (this.
|
|
1571
|
-
|
|
1572
|
-
this.
|
|
1565
|
+
const frame = this.frameBuffer[0];
|
|
1566
|
+
const timescale = this.fmp4Demuxer.getTimescale();
|
|
1567
|
+
if (this.playStartTime === 0) {
|
|
1568
|
+
this.playStartTime = now;
|
|
1569
|
+
this.accumulatedMediaTime = 0;
|
|
1570
|
+
}
|
|
1571
|
+
const elapsedWallTime = now - this.playStartTime;
|
|
1572
|
+
const frameDurationMs = frame.duration ? frame.duration * 1e3 / timescale : 33.33;
|
|
1573
|
+
const bufferMs = 50;
|
|
1574
|
+
if (elapsedWallTime >= this.accumulatedMediaTime - bufferMs) {
|
|
1575
|
+
this.frameBuffer.shift();
|
|
1576
|
+
this.renderer.render(frame);
|
|
1577
|
+
this.accumulatedMediaTime += frameDurationMs;
|
|
1578
|
+
this.setCurrentTime(this.accumulatedMediaTime / 1e3);
|
|
1579
|
+
this.updateState({ resolution: `${frame.width}x${frame.height}` });
|
|
1580
|
+
const fps = this.renderer.updateFps();
|
|
1581
|
+
this.updateState({ fps });
|
|
1582
|
+
this.callbacks.onFrameRender?.(frame);
|
|
1573
1583
|
}
|
|
1574
|
-
this.lastRenderTime = timestamp;
|
|
1575
|
-
this.updateState({ resolution: `${frame.width}x${frame.height}` });
|
|
1576
|
-
const fps = this.renderer.updateFps();
|
|
1577
|
-
this.updateState({ fps });
|
|
1578
|
-
this.callbacks.onFrameRender?.(frame);
|
|
1579
1584
|
} else {
|
|
1580
1585
|
this.lastRenderTime = 0;
|
|
1581
1586
|
}
|
|
@@ -1655,6 +1660,8 @@ class HLSPlayer extends BasePlayer {
|
|
|
1655
1660
|
this.isPlaying = true;
|
|
1656
1661
|
this.decodeLoopAbort = false;
|
|
1657
1662
|
this.lastRenderTime = 0;
|
|
1663
|
+
this.playStartTime = 0;
|
|
1664
|
+
this.accumulatedMediaTime = 0;
|
|
1658
1665
|
this.updateState({ isPlaying: true });
|
|
1659
1666
|
if (!this.prefetcher) {
|
|
1660
1667
|
this.initPrefetcher();
|
|
@@ -1695,12 +1702,17 @@ class HLSPlayer extends BasePlayer {
|
|
|
1695
1702
|
*/
|
|
1696
1703
|
async decodeLoop() {
|
|
1697
1704
|
console.log("[DecodeLoop] START, isFMP4:", this.isFMP4);
|
|
1705
|
+
console.log("[DecodeLoop] END");
|
|
1698
1706
|
let batchCount = 0;
|
|
1699
1707
|
while (this.isPlaying && !this.decodeLoopAbort) {
|
|
1700
1708
|
this.prefetcher?.processQueue();
|
|
1701
1709
|
const batchSize = this.config.decodeBatchSize;
|
|
1702
1710
|
let decodedInBatch = 0;
|
|
1703
1711
|
if (this.isFMP4) {
|
|
1712
|
+
const queueSize = this.sampleQueue.length;
|
|
1713
|
+
if (queueSize > 0 || batchCount % 50 === 0) {
|
|
1714
|
+
console.log("[DecodeLoop] fMP4: sampleQueue=", queueSize, "frameBuffer=", this.frameBuffer.length, "batch=", batchCount);
|
|
1715
|
+
}
|
|
1704
1716
|
while (this.sampleQueue.length > 0 && decodedInBatch < batchSize) {
|
|
1705
1717
|
const queuedSample = this.sampleQueue.shift();
|
|
1706
1718
|
const sample = queuedSample.sample;
|
|
@@ -1826,7 +1838,9 @@ class HLSPlayer extends BasePlayer {
|
|
|
1826
1838
|
this._sampleQueue.push({ sample });
|
|
1827
1839
|
}
|
|
1828
1840
|
totalSampleCount += samples.length;
|
|
1841
|
+
console.log("[parseFMP4Data] Pushed", samples.length, "samples, totalQueue=", this._sampleQueue.length);
|
|
1829
1842
|
}
|
|
1843
|
+
console.log("[parseFMP4Data] Total samples parsed:", totalSampleCount);
|
|
1830
1844
|
return totalSampleCount;
|
|
1831
1845
|
}
|
|
1832
1846
|
/**
|
|
@@ -2200,6 +2214,11 @@ class HLSPlayer extends BasePlayer {
|
|
|
2200
2214
|
data: annexBData,
|
|
2201
2215
|
size: annexBData.length
|
|
2202
2216
|
});
|
|
2217
|
+
if (frame) {
|
|
2218
|
+
frame.pts = sample.pts;
|
|
2219
|
+
frame.dts = sample.dts;
|
|
2220
|
+
frame.duration = sample.duration;
|
|
2221
|
+
}
|
|
2203
2222
|
return frame;
|
|
2204
2223
|
}
|
|
2205
2224
|
/**
|