From bce8e0deaca1205df542059a4287d942ba4dee57 Mon Sep 17 00:00:00 2001 From: mengxiaoxuan Date: Tue, 11 Jun 2024 10:54:06 +0800 Subject: [PATCH] fix: compatibility --- demo/index.html | 81 +++++++++++++++++++++++-------------------- package.json | 2 +- src/capture.worker.ts | 26 -------------- src/index.ts | 6 ++-- 4 files changed, 47 insertions(+), 68 deletions(-) diff --git a/demo/index.html b/demo/index.html index d1cce88..a54c7b6 100644 --- a/demo/index.html +++ b/demo/index.html @@ -9,18 +9,16 @@ - + - + -
- diff --git a/package.json b/package.json index 3910f49..8163624 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cheetah-capture", - "version": "0.2.0-beta.3", + "version": "0.2.1", "description": "cheetah-capture是基于ffmpeg的wasm截取视频帧工具", "keywords": [ "ffmpeg", diff --git a/src/capture.worker.ts b/src/capture.worker.ts index 9282756..47855b4 100644 --- a/src/capture.worker.ts +++ b/src/capture.worker.ts @@ -191,43 +191,17 @@ class ImageCapture { } getMetadata(key: string, id: number) { - // getMetadata(key, path, id) if (!this.name) { throw new Error('Please mount file first!'); } const cGetMetadata = Module.cwrap('getMetaDataByKey', 'string', ['string', 'string', 'number']); const metadataValue = cGetMetadata(key, `${this.path}/${this.name}`, id); - // cGetMetadata(); self.postMessage({ type: Events.getMetadataOnSuccess, meta: metadataValue, id, }); - // // cGetMetadata(); - // const ptr = Module.ccall('getMetaDataByKey', 'number', ['string', 'string', 'number'], [key, `${this.path}/${this.name}`, id]); - // if (!ptr) { - // console.error('Invalid pointer received'); - // } else { - // console.log('===>ptr', ptr); - // const length = Module.ccall('get_string_length', 'number', ['number'], [ptr]); - // console.log('===>length', length); - // if (length > 0) { - // const data = new Uint8Array(Module.HEAPU8.buffer, ptr, length); - // const decoder = new TextDecoder('utf-8'); - // const metadataValue = decoder.decode(data); - // console.log('==>from worker', metadataValue); - // self.postMessage({ - // type: Events.getMetadataOnSuccess, - // meta: metadataValue, - // id, - // }); - // } else { - // console.error('Received empty or invalid length'); - // } - // } - - } } diff --git a/src/index.ts b/src/index.ts index 42adc80..a39eddb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -231,7 +231,7 @@ export async function initCapture({ } case Events.receiveImageOnSuccess: { const {id, meta} = e.data || {}; - const cbk = pool.getCbk(id); + const cbk = pool.getCbk(id) || {}; const {onSuccess} = cbk; const {cache} = pool.getCbk(id); onSuccess && onSuccess({ @@ -242,14 +242,14 @@ export async function initCapture({ } case Events.receiveError: { const {errmsg, id} = e.data || {}; - const cbk = pool.getCbk(id); + const cbk = pool.getCbk(id) || {}; const {onError} = cbk; onError && onError(errmsg); break; } case Events.getMetadataOnSuccess: { const {id, meta} = e.data || {}; - const cbk = pool.getCbk(id); + const cbk = pool.getCbk(id) || {}; const {onSuccess} = cbk; onSuccess && onSuccess({meta: meta as string}); break;