Comparing version 0.1.0 to 0.1.1
40
dav1d.js
@@ -48,7 +48,21 @@ // Must be in sync with emcc settings! | ||
function fetchAndInstantiate(data, url, imports) { | ||
if (data) return WebAssembly.instantiate(data, imports); | ||
const req = fetch(url, {credentials: "same-origin"}); | ||
if (WebAssembly.instantiateStreaming) { | ||
return WebAssembly.instantiateStreaming(req, imports); | ||
} else { | ||
return req | ||
.then(res => res.arrayBuffer()) | ||
.then(data => WebAssembly.instantiate(data, imports)); | ||
} | ||
} | ||
export function create(opts = {}) { | ||
const data = opts.wasmData; | ||
if (!opts.wasmURL && !opts.wasmData) { | ||
return Promise.reject(new Error("Either wasmURL or wasmData shall be provided")); | ||
} | ||
const runtime = getRuntime(); | ||
const imports = {env: runtime}; | ||
return WebAssembly.instantiate(data, imports).then(wasm => { | ||
return fetchAndInstantiate(opts.wasmData, opts.wasmURL, imports).then(wasm => { | ||
const d = new Dav1d({wasm, runtime}); | ||
@@ -64,2 +78,4 @@ d._init(); | ||
class Dav1d { | ||
/* Private methods, shall not be used */ | ||
constructor({wasm, runtime}) { | ||
@@ -70,2 +86,3 @@ this.FFI = wasm.instance.exports; | ||
this.ref = null; | ||
this.lastFrameRef = null; | ||
} | ||
@@ -92,3 +109,3 @@ _init() { | ||
if (unsafe) { | ||
this.FFI.djs_free_frame(frameRef); | ||
this.lastFrameRef = frameRef; | ||
return srcData; | ||
@@ -101,2 +118,5 @@ } | ||
} | ||
/* Public API methods */ | ||
/** | ||
@@ -111,6 +131,8 @@ * Frame decoding, copy of frame data is returned. | ||
} | ||
/** | ||
* Unsafe decoding with minimal overhead. We return pointer to WASM | ||
* memory, so you can't call any dav1d.js methods while keeping | ||
* reference to it. | ||
* Unsafe decoding with minimal overhead, pointer to WebAssembly | ||
* memory is returned. User can't call any dav1d.js methods while | ||
* keeping reference to it and shall call `unsafeCleanup` when | ||
* finished using the data. | ||
*/ | ||
@@ -123,4 +145,10 @@ unsafeDecodeFrameAsYUV(obu) { | ||
} | ||
unsafeCleanup() { | ||
if (this.lastFrameRef) { | ||
this.FFI.djs_free_frame(this.lastFrameRef); | ||
this.lastFrameRef = null; | ||
} | ||
} | ||
} | ||
export default {create}; |
{ | ||
"name": "dav1d.js", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "WebAssembly AV1 decoder", | ||
"main": "dav1d.js", | ||
"scripts": { | ||
"prepublishOnly": "make dav1d.wasm" | ||
}, | ||
"repository": { | ||
@@ -7,0 +10,0 @@ "type": "git", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
137
388733
2