@swf2es/native 0.1.28 → 0.1.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/instance.d.ts.map +1 -1
- package/dist/instance.js +5 -1
- package/dist/instance.js.map +1 -1
- package/dist/memory.d.ts +12 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +41 -0
- package/dist/memory.js.map +1 -0
- package/dist/mp3/index.d.ts.map +1 -1
- package/dist/mp3/index.js +2 -0
- package/dist/mp3/index.js.map +1 -1
- package/dist/render/module.d.ts.map +1 -1
- package/dist/render/module.js +4 -1
- package/dist/render/module.js.map +1 -1
- package/package.json +5 -1
- package/src/instance.ts +6 -1
- package/src/memory.ts +47 -0
- package/src/mp3/index.ts +2 -0
- package/src/render/module.ts +4 -1
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@ swf2es's WebAssembly modules, built with the repository's pinned Zig:
|
|
|
15
15
|
- `@swf2es/native/atf`: Stage3D's ATF textures, read and decoded to what a
|
|
16
16
|
desktop GPU takes, their JPEG XR images by jxrlib; and JPEG XR files
|
|
17
17
|
written as Flash's `BitmapData.encode` writes them, by jxrlib's encoder.
|
|
18
|
+
- `@swf2es/native/memory`: `nativeMemory()`, the bytes the other modules'
|
|
19
|
+
live instances hold in their memories, for a host that shows them.
|
|
18
20
|
|
|
19
21
|
The package depends on no other package and uses no DOM or node APIs.
|
|
20
22
|
`compress`, `mp3`, `audio` and `atf` each compile their own module. What the renderer
|
package/dist/instance.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../src/instance.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../src/instance.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,eAAO,MAAM,WAAW,QAAU,CAAC;AAEnC,qBAAa,YAAY,CAAC,OAAO,SAAS;IAAE,MAAM,EAAE,WAAW,CAAC,MAAM,CAAA;CAAE;IACtE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAmC;IACnD,OAAO,CAAC,QAAQ,CAAwB;IAExC,YAAY,MAAM,EAAE,MAAM,EAEzB;IAED;;;;OAIG;IACH,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,CAAC,GAAG,CAAC,CAkB/B;IAED,mEAAmE;IACnE,IAAI,IAAI,IAAI,CAEX;IAED,qEAAqE;IACrE,IAAI,MAAM,IAAI,MAAM,CAEnB;CACF"}
|
package/dist/instance.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// instance made as needed, and let go after a call that threw, or whose
|
|
4
4
|
// memory grew past MEMORY_KEPT, since memory never shrinks.
|
|
5
5
|
import { decodeBase64 } from "./base64.js";
|
|
6
|
+
import { track } from "./memory.js";
|
|
6
7
|
/**
|
|
7
8
|
* Memory an instance may keep between calls: what a bitmap or a SWF of a
|
|
8
9
|
* few MB needs, less than an LZMA encoder's for a dictionary of 1 MB.
|
|
@@ -23,7 +24,10 @@ export class KeptInstance {
|
|
|
23
24
|
*/
|
|
24
25
|
call(f) {
|
|
25
26
|
this.compiled ??= new WebAssembly.Module(decodeBase64(this.binary));
|
|
26
|
-
|
|
27
|
+
if (!this.instance) {
|
|
28
|
+
this.instance = new WebAssembly.Instance(this.compiled).exports;
|
|
29
|
+
track(this.instance.memory);
|
|
30
|
+
}
|
|
27
31
|
const x = this.instance;
|
|
28
32
|
try {
|
|
29
33
|
return f(x);
|
package/dist/instance.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instance.js","sourceRoot":"","sources":["../src/instance.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,sEAAsE;AACtE,wEAAwE;AACxE,4DAA4D;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|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AAC;QACH,CAAC;IACH,CAAC;IAED,mEAAmE;IACnE,IAAI;QACF,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,qEAAqE;IACrE,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACpE,CAAC;CACF"}
|
package/dist/memory.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Count `memory` in nativeMemory while its instance lives. */
|
|
2
|
+
export declare function track(memory: WebAssembly.Memory): void;
|
|
3
|
+
/**
|
|
4
|
+
* The bytes the native modules' instances hold in their memories now:
|
|
5
|
+
* bitmap kernels, tessellators, lines, decoders, zlib and LZMA, every
|
|
6
|
+
* player's on the page together, but only this realm's: a worker's
|
|
7
|
+
* instances (a Flash Worker's thread) are counted in that worker alone. A
|
|
8
|
+
* memory grows and never shrinks; one whose instance was let go of counts
|
|
9
|
+
* until it is collected.
|
|
10
|
+
*/
|
|
11
|
+
export declare function nativeMemory(): number;
|
|
12
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AASA,+DAA+D;AAC/D,wBAAgB,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,GAAG,IAAI,CAQtD;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAOrC"}
|
package/dist/memory.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// The memories of the modules' live instances, for a host that shows what
|
|
2
|
+
// the page holds (the demo site's performance meter). Held weakly: an
|
|
3
|
+
// instance let go of, as KeptInstance lets one go whose memory grew, drops
|
|
4
|
+
// out once it is collected.
|
|
5
|
+
const memories = [];
|
|
6
|
+
/** The count at which `track` next sweeps out the collected, doubled each time it does. */
|
|
7
|
+
let sweepAt = 64;
|
|
8
|
+
/** Count `memory` in nativeMemory while its instance lives. */
|
|
9
|
+
export function track(memory) {
|
|
10
|
+
// An MP3 decoder is made for each sound played: the collected ones' refs go too, now and then.
|
|
11
|
+
if (memories.length >= sweepAt) {
|
|
12
|
+
sweep();
|
|
13
|
+
sweepAt = Math.max(64, memories.length * 2);
|
|
14
|
+
}
|
|
15
|
+
memories.push(new WeakRef(memory));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The bytes the native modules' instances hold in their memories now:
|
|
19
|
+
* bitmap kernels, tessellators, lines, decoders, zlib and LZMA, every
|
|
20
|
+
* player's on the page together, but only this realm's: a worker's
|
|
21
|
+
* instances (a Flash Worker's thread) are counted in that worker alone. A
|
|
22
|
+
* memory grows and never shrinks; one whose instance was let go of counts
|
|
23
|
+
* until it is collected.
|
|
24
|
+
*/
|
|
25
|
+
export function nativeMemory() {
|
|
26
|
+
let bytes = 0;
|
|
27
|
+
for (let i = 0; i < memories.length; i++) {
|
|
28
|
+
bytes += memories[i].deref()?.buffer.byteLength ?? 0;
|
|
29
|
+
}
|
|
30
|
+
return bytes;
|
|
31
|
+
}
|
|
32
|
+
function sweep() {
|
|
33
|
+
let kept = 0;
|
|
34
|
+
for (let i = 0; i < memories.length; i++) {
|
|
35
|
+
if (memories[i].deref()) {
|
|
36
|
+
memories[kept++] = memories[i];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
memories.length = kept;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,sEAAsE;AACtE,2EAA2E;AAC3E,4BAA4B;AAE5B,MAAM,QAAQ,GAAkC,EAAE,CAAC;AACnD,2FAA2F;AAC3F,IAAI,OAAO,GAAG,EAAE,CAAC;AAEjB,+DAA+D;AAC/D,MAAM,UAAU,KAAK,CAAC,MAA0B;IAC9C,+FAA+F;IAC/F,IAAI,QAAQ,CAAC,MAAM,IAAI,OAAO,EAAE,CAAC;QAC/B,KAAK,EAAE,CAAC;QACR,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED,QAAQ,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY;IAC1B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACzC,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,UAAU,IAAI,CAAC,CAAC;IACvD,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,KAAK;IACZ,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACzC,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;YACxB,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC;AACzB,CAAC"}
|
package/dist/mp3/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mp3/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mp3/index.ts"],"names":[],"mappings":"AAiBA;;;;GAIG;AACH,wBAAgB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAS1C;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,IAAI,OAAO,CAEtC;AAED,mGAAmG;AACnG,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAU;IAC/B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IACnC,QAAQ,CAAC,GAAG,EAAE,YAAY,CAAC;IAE3B,cASC;IAED,0FAA0F;IAC1F,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAO9B;IAED,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
|
package/dist/mp3/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// The compiled module is shared; each extraction has its own small decoder state.
|
|
2
2
|
import { decodeBase64 } from "../base64.js";
|
|
3
|
+
import { track } from "../memory.js";
|
|
3
4
|
import { binary } from "./binary.js";
|
|
4
5
|
let compiled = null;
|
|
5
6
|
let preparing = null;
|
|
@@ -28,6 +29,7 @@ export class Mp3Decoder {
|
|
|
28
29
|
throw new Error("prepareMp3 must finish before decoding");
|
|
29
30
|
}
|
|
30
31
|
this.wasm = new WebAssembly.Instance(compiled).exports;
|
|
32
|
+
track(this.wasm.memory);
|
|
31
33
|
this.input = new Uint8Array(this.wasm.memory.buffer, this.wasm.input(), 4096);
|
|
32
34
|
this.pcm = new Float32Array(this.wasm.memory.buffer, this.wasm.output(), 2304);
|
|
33
35
|
}
|
package/dist/mp3/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mp3/index.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,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AAQ,CAAC,QAAQ,CAAC,CAAC,OAA6B,CAAC;QAC7E,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;QAC9E,IAAI,CAAC,GAAG,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,CAAC;IACjF,CAAC;IAED,0FAA0F;IAC1F,IAAI,CAAC,KAAiB;QACpB,IAAI,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YACrC,OAAO,CAAC,CAAC;QACX,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACtB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC9B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/render/module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/render/module.ts"],"names":[],"mappings":"AAMA;;;;;;GAMG;AACH,wBAAgB,YAAY,IAAI,WAAW,CAAC,MAAM,CAGjD;AAWD,qDAAqD;AACrD,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAI5E"}
|
package/dist/render/module.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { decodeBase64 } from "../base64.js";
|
|
2
|
+
import { track } from "../memory.js";
|
|
2
3
|
import { binary } from "./binary.js";
|
|
3
4
|
let module = null;
|
|
4
5
|
/**
|
|
@@ -22,6 +23,8 @@ function renderImports(failure) {
|
|
|
22
23
|
}
|
|
23
24
|
/** An instance of the module, its memory its own. */
|
|
24
25
|
export function renderInstance(failure) {
|
|
25
|
-
|
|
26
|
+
const exports = new WebAssembly.Instance(renderModule(), renderImports(failure)).exports;
|
|
27
|
+
track(exports.memory);
|
|
28
|
+
return exports;
|
|
26
29
|
}
|
|
27
30
|
//# sourceMappingURL=module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/render/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,IAAI,MAAM,GAA8B,IAAI,CAAC;AAE7C;;;;;;GAMG;AACH,MAAM,UAAU,YAAY;IAC1B,MAAM,KAAK,IAAI,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;IACxD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,SAAS,aAAa,CAAC,OAAoB;IACzC,OAAO,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;AAChE,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,cAAc,CAAC,OAAoB;IACjD,OAAO,IAAI,WAAW,CAAC,QAAQ,CAAC,YAAY,EAAE,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/render/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,IAAI,MAAM,GAA8B,IAAI,CAAC;AAE7C;;;;;;GAMG;AACH,MAAM,UAAU,YAAY;IAC1B,MAAM,KAAK,IAAI,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;IACxD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,SAAS,aAAa,CAAC,OAAoB;IACzC,OAAO,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;AAChE,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,cAAc,CAAC,OAAoB;IACjD,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,QAAQ,CAAC,YAAY,EAAE,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;IACzF,KAAK,CAAC,OAAO,CAAC,MAA4B,CAAC,CAAC;IAC5C,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swf2es/native",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"description": "swf2es's WebAssembly modules: bitmap kernels, MP3, ADPCM and Nellymoser decoding, zlib and LZMA, fill and line tessellation, and ATF textures",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"swf",
|
|
@@ -33,6 +33,10 @@
|
|
|
33
33
|
"types": "./dist/compress/index.d.ts",
|
|
34
34
|
"default": "./dist/compress/index.js"
|
|
35
35
|
},
|
|
36
|
+
"./memory": {
|
|
37
|
+
"types": "./dist/memory.d.ts",
|
|
38
|
+
"default": "./dist/memory.js"
|
|
39
|
+
},
|
|
36
40
|
"./mp3": {
|
|
37
41
|
"types": "./dist/mp3/index.d.ts",
|
|
38
42
|
"default": "./dist/mp3/index.js"
|
package/src/instance.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// instance made as needed, and let go after a call that threw, or whose
|
|
4
4
|
// memory grew past MEMORY_KEPT, since memory never shrinks.
|
|
5
5
|
import { decodeBase64 } from "./base64.js";
|
|
6
|
+
import { track } from "./memory.js";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Memory an instance may keep between calls: what a bitmap or a SWF of a
|
|
@@ -27,7 +28,11 @@ export class KeptInstance<Exports extends { memory: WebAssembly.Memory }> {
|
|
|
27
28
|
*/
|
|
28
29
|
call<T>(f: (x: Exports) => T): T {
|
|
29
30
|
this.compiled ??= new WebAssembly.Module(decodeBase64(this.binary));
|
|
30
|
-
|
|
31
|
+
if (!this.instance) {
|
|
32
|
+
this.instance = new WebAssembly.Instance(this.compiled).exports as unknown as Exports;
|
|
33
|
+
track(this.instance.memory);
|
|
34
|
+
}
|
|
35
|
+
|
|
31
36
|
const x = this.instance;
|
|
32
37
|
try {
|
|
33
38
|
return f(x);
|
package/src/memory.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// The memories of the modules' live instances, for a host that shows what
|
|
2
|
+
// the page holds (the demo site's performance meter). Held weakly: an
|
|
3
|
+
// instance let go of, as KeptInstance lets one go whose memory grew, drops
|
|
4
|
+
// out once it is collected.
|
|
5
|
+
|
|
6
|
+
const memories: WeakRef<WebAssembly.Memory>[] = [];
|
|
7
|
+
/** The count at which `track` next sweeps out the collected, doubled each time it does. */
|
|
8
|
+
let sweepAt = 64;
|
|
9
|
+
|
|
10
|
+
/** Count `memory` in nativeMemory while its instance lives. */
|
|
11
|
+
export function track(memory: WebAssembly.Memory): void {
|
|
12
|
+
// An MP3 decoder is made for each sound played: the collected ones' refs go too, now and then.
|
|
13
|
+
if (memories.length >= sweepAt) {
|
|
14
|
+
sweep();
|
|
15
|
+
sweepAt = Math.max(64, memories.length * 2);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
memories.push(new WeakRef(memory));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The bytes the native modules' instances hold in their memories now:
|
|
23
|
+
* bitmap kernels, tessellators, lines, decoders, zlib and LZMA, every
|
|
24
|
+
* player's on the page together, but only this realm's: a worker's
|
|
25
|
+
* instances (a Flash Worker's thread) are counted in that worker alone. A
|
|
26
|
+
* memory grows and never shrinks; one whose instance was let go of counts
|
|
27
|
+
* until it is collected.
|
|
28
|
+
*/
|
|
29
|
+
export function nativeMemory(): number {
|
|
30
|
+
let bytes = 0;
|
|
31
|
+
for (let i = 0; i < memories.length; i++) {
|
|
32
|
+
bytes += memories[i].deref()?.buffer.byteLength ?? 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return bytes;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function sweep(): void {
|
|
39
|
+
let kept = 0;
|
|
40
|
+
for (let i = 0; i < memories.length; i++) {
|
|
41
|
+
if (memories[i].deref()) {
|
|
42
|
+
memories[kept++] = memories[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
memories.length = kept;
|
|
47
|
+
}
|
package/src/mp3/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// The compiled module is shared; each extraction has its own small decoder state.
|
|
2
2
|
import { decodeBase64 } from "../base64.js";
|
|
3
|
+
import { track } from "../memory.js";
|
|
3
4
|
import { binary } from "./binary.js";
|
|
4
5
|
|
|
5
6
|
interface Exports {
|
|
@@ -47,6 +48,7 @@ export class Mp3Decoder {
|
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
this.wasm = new WebAssembly.Instance(compiled).exports as unknown as Exports;
|
|
51
|
+
track(this.wasm.memory);
|
|
50
52
|
this.input = new Uint8Array(this.wasm.memory.buffer, this.wasm.input(), 4096);
|
|
51
53
|
this.pcm = new Float32Array(this.wasm.memory.buffer, this.wasm.output(), 2304);
|
|
52
54
|
}
|
package/src/render/module.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { decodeBase64 } from "../base64.js";
|
|
2
|
+
import { track } from "../memory.js";
|
|
2
3
|
import { binary } from "./binary.js";
|
|
3
4
|
|
|
4
5
|
let module: WebAssembly.Module | null = null;
|
|
@@ -26,5 +27,7 @@ function renderImports(failure: () => never): object {
|
|
|
26
27
|
|
|
27
28
|
/** An instance of the module, its memory its own. */
|
|
28
29
|
export function renderInstance(failure: () => never): Record<string, unknown> {
|
|
29
|
-
|
|
30
|
+
const exports = new WebAssembly.Instance(renderModule(), renderImports(failure)).exports;
|
|
31
|
+
track(exports.memory as WebAssembly.Memory);
|
|
32
|
+
return exports;
|
|
30
33
|
}
|