Skip to content

Commit

Permalink
Merge pull request #169 from bilibili/fix/mp4clip-timeout
Browse files Browse the repository at this point in the history
Fix/mp4clip timeout
  • Loading branch information
hughfenghen authored Jul 8, 2024
2 parents de2ec63 + 0fe21e5 commit b9720e7
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .changeset/real-shoes-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@webav/av-canvas': patch
'@webav/av-cliper': patch
---

chore: add timeout error log
2 changes: 1 addition & 1 deletion packages/av-cliper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"dependencies": {
"@webav/mp4box.js": "0.5.3-fenghen",
"m3u8-parser": "^7.1.0",
"opfs-tools": "^0.5.6",
"opfs-tools": "^0.5.7",
"wave-resampler": "^1.0.0"
},
"devDependencies": {
Expand Down
54 changes: 44 additions & 10 deletions packages/av-cliper/src/clips/mp4-clip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,22 @@ export class MP4Clip implements IClip {
]),
new Promise<[]>((_, reject) => {
timeoutTimer = self.setTimeout(() => {
if (!audioReady) this.#audioFrameFinder?.reset();
if (!videoReady) this.#videoFrameFinder?.reset();
reject(
Error(
`MP4Clip.tick timeout, ${JSON.stringify({
videoReady,
audioReady,
})}, time: ${time}`,
),
);
let errMsg = `MP4Clip.tick timeout, ${JSON.stringify({
videoReady,
audioReady,
})}, `;

const aFinder = this.#audioFrameFinder;
if (!audioReady && aFinder != null) {
errMsg += JSON.stringify(aFinder.getState());
aFinder?.reset();
}
const vFinder = this.#videoFrameFinder;
if (!videoReady && vFinder != null) {
errMsg += JSON.stringify(vFinder.getState());
vFinder.reset();
}
reject(Error(errMsg));
}, 3000);
}),
])) as [Float32Array[], VideoFrame];
Expand Down Expand Up @@ -734,6 +740,18 @@ class VideoFrameFinder {
});
};

getState = () => ({
time: this.#ts,
decState: this.#dec?.state,
decQSize: this.#dec?.decodeQueueSize,
decCusorIdx: this.#videoDecCusorIdx,
sampleLen: this.samples.length,
inputCnt: this.#inputChunkCnt,
outputCnt: this.#outputFrameCnt,
cacheFrameLen: this.#videoFrames.length,
softDeocde: this.#downgradeSoftDecode,
});

destroy = () => {
if (this.#dec?.state !== 'closed') this.#dec?.close();
this.#dec = null;
Expand Down Expand Up @@ -868,6 +886,16 @@ class AudioFrameFinder {
);
};

getState = () => ({
time: this.#ts,
decState: this.#dec?.state,
decoding: this.#decoding,
decQSize: this.#dec?.decodeQueueSize,
decCusorIdx: this.#decCusorIdx,
sampleLen: this.samples.length,
pcmLen: this.#pcmData[0]?.length,
});

destroy = () => {
this.#dec = null;
this.#curAborter.abort = true;
Expand Down Expand Up @@ -948,6 +976,9 @@ function createAudioChunksDecoder(
get state() {
return adec.state;
},
get decodeQueueSize() {
return adec.decodeQueueSize;
},
};
}

Expand Down Expand Up @@ -989,8 +1020,10 @@ async function sample2Chunk<T extends EncodedAudioChunk | EncodedVideoChunk>(
clazz: Constructor<T>,
reader: Awaited<ReturnType<OPFSToolFile['createReader']>>,
): Promise<T> {
// todo: perf
const data = await reader.read(s.size, { at: s.offset });
return new clazz(
// todo: perf
sample2ChunkOpts({
...s,
data,
Expand Down Expand Up @@ -1089,6 +1122,7 @@ function decodeGoP(
) {
let i = 0;
try {
if (dec.state !== 'configured') return;
for (; i < chunks.length; i++) dec.decode(chunks[i]);
} catch (err) {
if (opts.idrFrameDowngrade || !(err instanceof Error)) throw err;
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b9720e7

Please sign in to comment.