Skip to content

Commit

Permalink
Merge pull request #167 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 4, 2024
2 parents 2135130 + 737cb31 commit 7034a45
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .changeset/light-boats-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@webav/av-canvas': patch
'@webav/av-cliper': patch
---

fix: cant stop decode audio when reset
2 changes: 1 addition & 1 deletion packages/av-canvas/demo/video-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const TimelineEditor = ({
<div>
<span className="ml-[10px]">缩放:</span>
<button
onClick={() => setScale(scale + 1)}
onClick={() => setScale(scale + 10)}
className="border rounded-full"
>
-
Expand Down
10 changes: 7 additions & 3 deletions packages/av-cliper/src/clips/mp4-clip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class MP4Clip implements IClip {
`MP4Clip.tick timeout, ${JSON.stringify({
videoReady,
audioReady,
})}`,
})}, time: ${time}`,
),
);
}, 3000);
Expand Down Expand Up @@ -792,7 +792,7 @@ class AudioFrameFinder {
dec: ReturnType<typeof createAudioChunksDecoder> | null = null,
aborter: { abort: boolean },
): Promise<Float32Array[]> => {
if (dec == null || aborter.abort) return [];
if (dec == null || aborter.abort || dec.state === 'closed') return [];

const frameCnt = Math.ceil(deltaTime * (this.#sampleRate / 1e6));
if (frameCnt === 0) return [];
Expand Down Expand Up @@ -861,6 +861,7 @@ class AudioFrameFinder {
new Float32Array(0), // right chan
];
this.#dec?.close();
this.#decoding = false;
this.#dec = createAudioChunksDecoder(
this.conf,
DEFAULT_AUDIO_CONF.sampleRate,
Expand Down Expand Up @@ -915,7 +916,7 @@ function createAudioChunksDecoder(

let tasks: Array<{ chunks: EncodedAudioChunk[]; cb: OutputHandle }> = [];
async function run() {
if (curCb != null) return;
if (curCb != null || adec.state !== 'configured') return;

const t = tasks.shift();
if (t == null) return;
Expand Down Expand Up @@ -944,6 +945,9 @@ function createAudioChunksDecoder(
curCb = null;
if (adec.state !== 'closed') adec.close();
},
get state() {
return adec.state;
},
};
}

Expand Down
27 changes: 15 additions & 12 deletions packages/av-cliper/src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ let THRESHOLD = 1;
const localFile = tmpfile();

let writer: Awaited<ReturnType<typeof localFile.createWriter>> | null = null;
const initPromise = (async function init() {
try {
writer = await localFile.createWriter();
} catch (err) {
if (!(err instanceof Error)) throw err;
if (err.message.includes('createSyncAccessHandle is not a function')) {
console.warn(err);
} else {
throw err;
}
}
})();

type LvName = 'debug' | 'info' | 'warn' | 'error';
const lvHandler = ['debug', 'info', 'warn', 'error'].reduce(
Expand Down Expand Up @@ -103,6 +91,21 @@ map.set(Log.info, 1);
map.set(Log.warn, 2);
map.set(Log.error, 3);

const initPromise = (async function init() {
try {
writer = await localFile.createWriter();
Log.info(navigator.userAgent);
Log.info('date: ' + new Date().toLocaleDateString());
} catch (err) {
if (!(err instanceof Error)) throw err;
if (err.message.includes('createSyncAccessHandle is not a function')) {
console.warn(err);
} else {
throw err;
}
}
})();

if (import.meta.env?.DEV) {
Log.setLogLevel(Log.debug);
}
Expand Down

0 comments on commit 7034a45

Please sign in to comment.