Commit d0df74ad authored by Linshizhi's avatar Linshizhi

update

parent 48f27d3b
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
"name": "paraencode", "name": "paraencode",
"version": "1.0.0", "version": "1.0.0",
"license": "ISC", "license": "ISC",
"dependencies": {
"rxjs": "^7.5.5"
},
"devDependencies": { "devDependencies": {
"@babel/core": "^7.17.9", "@babel/core": "^7.17.9",
"@babel/preset-env": "^7.16.11", "@babel/preset-env": "^7.16.11",
...@@ -4774,6 +4777,14 @@ ...@@ -4774,6 +4777,14 @@
"url": "https://github.com/sponsors/isaacs" "url": "https://github.com/sponsors/isaacs"
} }
}, },
"node_modules/rxjs": {
"version": "7.5.5",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.5.5.tgz",
"integrity": "sha512-sy+H0pQofO95VDmFLzyaw9xNJU4KTRSwQIGM6+iG3SypAtCiLDzpeG8sJrNCWn2Up9km+KhkvTdbkrdy+yzZdw==",
"dependencies": {
"tslib": "^2.1.0"
}
},
"node_modules/safe-buffer": { "node_modules/safe-buffer": {
"version": "5.1.2", "version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
...@@ -5087,6 +5098,11 @@ ...@@ -5087,6 +5098,11 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/tslib": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz",
"integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw=="
},
"node_modules/type-check": { "node_modules/type-check": {
"version": "0.3.2", "version": "0.3.2",
"resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz",
...@@ -8962,6 +8978,14 @@ ...@@ -8962,6 +8978,14 @@
"glob": "^7.1.3" "glob": "^7.1.3"
} }
}, },
"rxjs": {
"version": "7.5.5",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.5.5.tgz",
"integrity": "sha512-sy+H0pQofO95VDmFLzyaw9xNJU4KTRSwQIGM6+iG3SypAtCiLDzpeG8sJrNCWn2Up9km+KhkvTdbkrdy+yzZdw==",
"requires": {
"tslib": "^2.1.0"
}
},
"safe-buffer": { "safe-buffer": {
"version": "5.1.2", "version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
...@@ -9200,6 +9224,11 @@ ...@@ -9200,6 +9224,11 @@
"punycode": "^2.1.1" "punycode": "^2.1.1"
} }
}, },
"tslib": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz",
"integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw=="
},
"type-check": { "type-check": {
"version": "0.3.2", "version": "0.3.2",
"resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz",
......
...@@ -23,5 +23,8 @@ ...@@ -23,5 +23,8 @@
"FFMPEG" "FFMPEG"
], ],
"author": "Linshizhi", "author": "Linshizhi",
"license": "ISC" "license": "ISC",
"dependencies": {
"rxjs": "^7.5.5"
}
} }
...@@ -5,19 +5,51 @@ export let SUPPORT_CODECS = { ...@@ -5,19 +5,51 @@ export let SUPPORT_CODECS = {
"h264": 0 "h264": 0
}; };
export const ENCODE_MODE = Object.freeze({
URGENT: Symbol("URGENT"),
SAVE_MEMORY: Symbol("SAVEMEM"),
});
/* ParaEncoder use number of threads specified by
* caller to encode RGB pictures into a video */
export class ParaEncoder { export class ParaEncoder {
/* */ constructor(numOfTR, codec, mode) {
constructor(numOfTR, codec) {
assert(typeof(numOfTR) == 'number', assert(typeof(numOfTR) == 'number',
"typeof(numOfTR) == 'number' failed"); "typeof(n umOfTR) == 'number' failed");
assert(typeof(codec) == 'string', assert(typeof(codec) == 'string',
"typeof(codec) == 'number' failed"); "typeof(codec) == 'number' failed");
for (let encodeMode in ENCODE_MODE) {
assert(mode != encodeMode, "INVALID ENCODE MODE");
}
this.numOfTR = numOfTR; this.numOfTR = numOfTR;
this.codec = codec; this.codec = codec;
this.mode = mode;
} }
/* Encode pixels into a video frame, pixels can be generated from
* WebGLRenderingContext.readPixels()
* details: https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/readPixels
*
* Pixels should be passed to worker thread */
encode(pixels) {
switch (this.mode) {
case ENCODE_MODE.URGENT:
return this.#encodeUrgent(pixels);
break;
case ENCODE_MODE.SAVE_MEMORY:
return
break;
}
}
#encodeUrgent(pixels) {
}
#encodeSaveMem(pixels) {
}
} }
import { ParaEncoder } from "../src/paraEncode"; import { ParaEncoder, ENCODE_MODE } from "../src/paraEncode";
let dut = new ParaEncoder(1, "h264", ENCODE_MODE.SAVE_MEMORY);
test('ParaEncoder Normal Init', () => { test('ParaEncoder Normal Init', () => {
let dut = new ParaEncoder(1, "h264");
expect(dut.numOfTR).toBe(1); expect(dut.numOfTR).toBe(1);
expect(dut.codec).toBe("h264"); expect(dut.codec).toBe("h264");
}); });
test("ParaEncoder Invalid Init", () => { test("ParaEncoder Invalid Init", () => {
try { try {
new ParaEncoder(1, 1); new ParaEncoder(1, 1, ENCODE_MODE.SAVE_MEMORY);
} catch (err) { } catch (err) {
expect(err.message) expect(err.message)
.toBe("typeof(codec) == 'number' failed"); .toBe("typeof(codec) == 'number' failed");
} }
}) })
test("ParaEncoder Invalid encode mode", () => {
try {
new ParaEncoder(1, "h264", Symbol("URGENT"));
} catch (err) {
expect(err.message)
.toBe("INVALID ENCODE MODE");
}
})
test("Encode with ParaEncoder", () => {
let pixels = new Uint8Array(1920*1080*4);
dut.encode(pixels);
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment