Skip to content

Commit

Permalink
chore: more log
Browse files Browse the repository at this point in the history
  • Loading branch information
hughfenghen committed Dec 23, 2024
1 parent 708858a commit ef1cc97
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-jars-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@webav/av-cliper': patch
---

chore: more log info
34 changes: 32 additions & 2 deletions packages/av-cliper/src/clips/mp4-clip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,9 @@ class VideoFrameFinder {
this.#ts = time;

this.#curAborter = { abort: false, st: performance.now() };
return await this.#parseFrame(time, this.#dec, this.#curAborter);
const vf = await this.#parseFrame(time, this.#dec, this.#curAborter);
this.#sleepCnt = 0;
return vf;
};

// fix VideoFrame duration is null
Expand All @@ -619,6 +621,7 @@ class VideoFrameFinder {
#videoFrames: VideoFrame[] = [];
#outputFrameCnt = 0;
#inputChunkCnt = 0;
#sleepCnt = 0;
#parseFrame = async (
time: number,
dec: VideoDecoder | null,
Expand Down Expand Up @@ -659,6 +662,7 @@ class VideoFrameFinder {
);
}
// 解码中,等待,然后重试
this.#sleepCnt += 1;
await sleep(15);
} else if (this.#videoDecCusorIdx >= this.samples.length) {
// decode completed
Expand Down Expand Up @@ -781,6 +785,9 @@ class VideoFrameFinder {
outputCnt: this.#outputFrameCnt,
cacheFrameLen: this.#videoFrames.length,
softDeocde: this.#downgradeSoftDecode,
clipIdCnt: CLIP_ID,
sleepCnt: this.#sleepCnt,
memInfo: memoryUsageInfo(),
});

destroy = () => {
Expand Down Expand Up @@ -836,11 +843,13 @@ class AudioFrameFinder {

this.#curAborter = { abort: false, st: performance.now() };

return await this.#parseFrame(
const pcmData = await this.#parseFrame(
Math.ceil(deltaTime * (this.#sampleRate / 1e6)),
this.#dec,
this.#curAborter,
);
this.#sleepCnt = 0;
return pcmData;
};

#ts = 0;
Expand All @@ -852,6 +861,7 @@ class AudioFrameFinder {
frameCnt: 0,
data: [],
};
#sleepCnt = 0;
#parseFrame = async (
emitFrameCnt: number,
dec: ReturnType<typeof createAudioChunksDecoder> | null = null,
Expand Down Expand Up @@ -884,6 +894,7 @@ class AudioFrameFinder {
);
}
// 解码中,等待
this.#sleepCnt += 1;
await sleep(15);
} else if (this.#decCusorIdx >= this.samples.length - 1) {
// 最后片段,返回剩余数据
Expand Down Expand Up @@ -950,6 +961,9 @@ class AudioFrameFinder {
decCusorIdx: this.#decCusorIdx,
sampleLen: this.samples.length,
pcmLen: this.#pcmData.frameCnt,
clipIdCnt: CLIP_ID,
sleepCnt: this.#sleepCnt,
memInfo: memoryUsageInfo(),
});

destroy = () => {
Expand Down Expand Up @@ -1386,3 +1400,19 @@ function fixFirstBlackFrame(samples: ExtMP4Sample[]) {
minCtsSample.cts = 0;
}
}

function memoryUsageInfo() {
try {
// @ts-ignore
const mem = performance.memory;
return {
jsHeapSizeLimit: mem.jsHeapSizeLimit,
totalJSHeapSize: mem.totalJSHeapSize,
usedJSHeapSize: mem.usedJSHeapSize,
percentUsed: (mem.usedJSHeapSize / mem.jsHeapSizeLimit).toFixed(3),
percentTotal: (mem.totalJSHeapSize / mem.jsHeapSizeLimit).toFixed(3),
};
} catch (err) {
return {};
}
}

0 comments on commit ef1cc97

Please sign in to comment.