Commit 1a70d8c1 authored by NzSN's avatar NzSN

Parameter check in ParaEncode.

parent 5e3cc2a9
......@@ -188,8 +188,14 @@ async function RGBProcessing(frame) {
// Encode RGB Frame into H264 Frame
encoder.HEAP8.set(frame, wasmMem);
let st, et;
st = new Date();
ret = encoder._encode(wasmMem, encBuf, ENC_BUF_SIZE, size);
size_ = encoder.getValue(size, 'i32');
et = new Date();
console.log("Encode with elapsed: " + (et - st));
if (size_ == 0)
return true;
......
......@@ -77,8 +77,6 @@ export class H264EncWWGroup extends WWGroup {
this.#numOfWorkers = numOfWW;
this.#numOfEncWorker = this.#numOfWorkers - 1;
console.log(this.#numOfEncWorker);
}
// H264EncWWGroup has two types of workers:
......
......@@ -13,13 +13,13 @@ export class ParaEncoder {
#numOfWW = 0;
#codec = undefined;
#mode = undefined
#grp = null;
#options
#options = null;
constructor(numOfWW, options) {
if (typeof(numOfWW) != 'number' ||
options == undefined ||
(!('codec' in options) || !(options['codec'] in ENC_GRPS)) ||
!('config' in options)) {
......@@ -27,13 +27,14 @@ export class ParaEncoder {
"Mismatch types parameter", "paraEncode.js");
}
this.#numOfWW = numOfWW;
this.#codec = options.codec;
this.#options = options;
}
async init() {
if (this.#options == undefined)
throw new TypeError("options can not be undefined");
this.#grp = new ENC_GRPS[this.#codec](
"ENCs", this.#numOfWW, this.#options.config);
await this.#grp.start();
......@@ -43,14 +44,6 @@ export class ParaEncoder {
return this.#numOfWW;
}
codec() {
return this.#codec;
}
mode() {
return this.#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
......
import { ParaEncoder, ENCODE_MODE } from "../src/paraEncode.js";
import { sleep } from "../src/utils.js";
import { sleep, waitCond } from "../src/utils.js";
let paraEnc;
const RGBAFrameSize = 1920*1080*4;
beforeEach(async () => {
paraEnc = new ParaEncoder(11, {
let trNum = navigator.hardwareConcurrency;
paraEnc = new ParaEncoder(trNum, {
codec: "H264",
config: {
encchnlsize: RGBAFrameSize * 10,
......@@ -13,19 +14,24 @@ beforeEach(async () => {
}
});
await paraEnc.init();
});
}, 20000);
describe("ParaEncoder", () => {
fit("Encode With ParaEncoder", async () => {
const data = new Uint8Array([...Array(RGBAFrameSize).keys()]);
for (let i = 0; i < 3000; ++i) {
let st = new Date();
for (let i = 0; i < 30000; ++i) {
await paraEnc.encode(data);
}
await paraEnc.encode(null);
await waitCond(() => paraEnc.isDone(), 3000000, 300);
let et = new Date();
let diff = (et - st) / 1000;
console.log("Total Elapsed time is " + diff);
await sleep(3000000);
}, 300000);
}, 3000000);
});
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