Commit 8b1268bf authored by Linshizhi's avatar Linshizhi

Add encode parameters to encgroup.

parent 7ae6479d
...@@ -8,12 +8,16 @@ let bridge = null; ...@@ -8,12 +8,16 @@ let bridge = null;
let wasmMem = null; let wasmMem = null;
let size = null; let size = null;
let eof = false; let eof = false;
let elapsed = 0; let elapsed = 0;
/* Video parameter */
let width_ = 1920;
let height_ = 1080;
let frameRate_ = 30;
// Number of bytes for each read // Number of bytes for each read
// from channel // from channel
const RGBFrameSize = 1920*1080*4; let RGBFrameSize = width_ * height_ * 4;
let READ_SIZE = RGBFrameSize; let READ_SIZE = RGBFrameSize;
const SLEEP_INTERVAL = 30; const SLEEP_INTERVAL = 30;
const SPIN_TIMEOUT = 90000; const SPIN_TIMEOUT = 90000;
...@@ -91,6 +95,15 @@ async function init(msg) { ...@@ -91,6 +95,15 @@ async function init(msg) {
src.enableBlockMode(info.blocksize); src.enableBlockMode(info.blocksize);
} }
if ('width' in info && 'height' in info && 'fps' in info) {
width_ = info.width;
height_ = info.height;
frameRate_ = info.fps;
RGBFrameSize = width_ * height_ * 4;
console.log(width_, height_, frameRate_);
}
// Wait encoder init // Wait encoder init
while (encoder == null) while (encoder == null)
await sleep(100); await sleep(100);
...@@ -98,7 +111,7 @@ async function init(msg) { ...@@ -98,7 +111,7 @@ async function init(msg) {
size = encoder._malloc(4); size = encoder._malloc(4);
wasmMem = encoder._malloc(RGBFrameSize); wasmMem = encoder._malloc(RGBFrameSize);
encodedFrames = encoder._malloc(ENC_BUF_SIZE); encodedFrames = encoder._malloc(ENC_BUF_SIZE);
ret = encoder._encodeInit(1920, 1080, 30); ret = encoder._encodeInit(width_, height_, frameRate_);
isInited = true; isInited = true;
postMessage(makeMsg(MESSAGE_TYPE.INIT, {})); postMessage(makeMsg(MESSAGE_TYPE.INIT, {}));
......
...@@ -54,6 +54,10 @@ export class H264EncWWGroup extends WWGroup { ...@@ -54,6 +54,10 @@ export class H264EncWWGroup extends WWGroup {
#blockSize = 0; #blockSize = 0;
#width = 1920;
#height = 1080;
#fps = 30;
/* Precondition: 2 <= options.numOfWW */ /* Precondition: 2 <= options.numOfWW */
constructor(name, numOfWW, options = {}) { constructor(name, numOfWW, options = {}) {
...@@ -65,7 +69,6 @@ export class H264EncWWGroup extends WWGroup { ...@@ -65,7 +69,6 @@ export class H264EncWWGroup extends WWGroup {
// Setting options // Setting options
if (options != undefined) { if (options != undefined) {
if ('max' in options) if ('max' in options)
this.#maxPayload = options.max; this.#maxPayload = options.max;
...@@ -81,6 +84,12 @@ export class H264EncWWGroup extends WWGroup { ...@@ -81,6 +84,12 @@ export class H264EncWWGroup extends WWGroup {
if ('blocksize' in options) if ('blocksize' in options)
this.#blockSize = options.blocksize; this.#blockSize = options.blocksize;
if ('width' in options && 'height' in options && 'fps' in options) {
this.#width = options.width;
this.#height = options.height;
this.#fps = options.fps;
}
this.#numOfWorkers = numOfWW; this.#numOfWorkers = numOfWW;
this.#numOfEncWorker = this.#numOfWorkers - 1; this.#numOfEncWorker = this.#numOfWorkers - 1;
} }
...@@ -117,7 +126,8 @@ export class H264EncWWGroup extends WWGroup { ...@@ -117,7 +126,8 @@ export class H264EncWWGroup extends WWGroup {
await this.#encWorkers[i].start(async ww => { await this.#encWorkers[i].start(async ww => {
return await initStrategies(encInit, INIT_FLAGS.NONE, ww, return await initStrategies(encInit, INIT_FLAGS.NONE, ww,
// encInit parameters // encInit parameters
this.#channels, this.#encChannelSize, ww, this.#blockSize); this.#channels, this.#encChannelSize, ww, this.#blockSize,
this.#width, this.#height, this.#fps)
}); });
} }
} catch (e) { } catch (e) {
...@@ -278,7 +288,7 @@ function syncInitStrategy(init, ww) { ...@@ -278,7 +288,7 @@ function syncInitStrategy(init, ww) {
return strategy; return strategy;
} }
async function encInit(chnls, size, ww, blockSize) { async function encInit(chnls, size, ww, blockSize, width, height, fps) {
let channel = new Channel(size); let channel = new Channel(size);
if (blockSize > 0) { if (blockSize > 0) {
...@@ -291,6 +301,9 @@ async function encInit(chnls, size, ww, blockSize) { ...@@ -291,6 +301,9 @@ async function encInit(chnls, size, ww, blockSize) {
size: size, size: size,
ident: ww.ident(), ident: ww.ident(),
blocksize: blockSize, blocksize: blockSize,
width: width,
height: height,
fps: fps
})); }));
chnls.push(channel); chnls.push(channel);
......
...@@ -35,7 +35,7 @@ describe("ParaEncoder", () => { ...@@ -35,7 +35,7 @@ describe("ParaEncoder", () => {
}, 3000000); }, 3000000);
}); });
describe("ParaEncoder Blockbased", () => { fdescribe("ParaEncoder Blockbased", () => {
beforeEach(async () => { beforeEach(async () => {
let trNum = navigator.hardwareConcurrency; let trNum = navigator.hardwareConcurrency;
paraEnc = new ParaEncoder(trNum, { paraEnc = new ParaEncoder(trNum, {
...@@ -44,6 +44,9 @@ describe("ParaEncoder Blockbased", () => { ...@@ -44,6 +44,9 @@ describe("ParaEncoder Blockbased", () => {
encchnlsize: RGBAFrameSize * 10, encchnlsize: RGBAFrameSize * 10,
bridgechnlsize: Math.pow(2, 25), bridgechnlsize: Math.pow(2, 25),
blocksize: RGBAFrameSize, blocksize: RGBAFrameSize,
width: 1920,
height: 1080,
fps: 25
} }
}); });
await paraEnc.init(); await paraEnc.init();
......
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