Commit 4bb7fec1 authored by NzSN's avatar NzSN

Endoer WW return message after initialization complete.

parent d2228340
......@@ -93,6 +93,7 @@ async function init(msg) {
ret = encoder._encodeInit(1920, 1080, 30);
isInited = true;
postMessage(makeMsg(MESSAGE_TYPE.INIT, {}));
}
async function destroy() {
......@@ -160,6 +161,8 @@ async function EOFProcessing() {
}
}
let i = 0;
async function RGBProcessing(frame) {
let ret = 0, size_;
......@@ -176,6 +179,8 @@ async function RGBProcessing(frame) {
throw new Error("Unknown error");
}
++i;
sendToMuxer(size_);
return true;
}
......
import { WW } from '../src/WW.js';
import { Channel } from '../src/channel.js';
import { makeMsg, MESSAGE_TYPE } from '../src/encGrooupMsg.js';
import { sleep } from '../src/utils.js';
import { sleep, assert } from '../src/utils.js';
// For Webpack 5
let url = '../resources/tests/worker.js';
......@@ -84,37 +84,68 @@ describe("WW Spec", () => {
});
describe("EncWW Specifications", () => {
it("Handle RGBA Frames", async () => {
let encoder = new WW('encoder', '../resources/workers/encWW.js');
let frameSize = 1920*1080*4;
let numOfFrames = 10;
async function initEncoder(encoder, frameSize, numOfFrames, shMem, bridgeMem) {
// Create a Shared memory which able to contain
// 8 RGBA Frames.
let size = frameSize * numOfFrames;
let shMem = new SharedArrayBuffer(size+12);
let ch1 = new Channel(size, SharedArrayBuffer, shMem);
// Init encoder
encoder.postMessage(
makeMsg(MESSAGE_TYPE.INIT, { size: size, shm: shMem }));
let bridgeMem = new SharedArrayBuffer(size+12);
let ch2 = new Channel(size, SharedArrayBuffer, bridgeMem);
await new Promise(r => {
let sub = encoder.subscribe(msg => {
assert(msg.type == MESSAGE_TYPE.INIT);
sub.unsubscribe();
r();
})
})
// Bridge to Main Thread
encoder.postMessage(
makeMsg(MESSAGE_TYPE.BRIDGE, { shm: bridgeMem, size: size }));
await sleep(1000);
}
describe("EncWW Specifications", () => {
fit("Handle RGBA Frames", async () => {
let encoder = new WW('encoder1', '../resources/workers/encWW.js');
let encoder_ = new WW('encoder2', '../resources/workers/encWW.js')
let frameSize = 1920*1080*4;
let numOfFrames = 30;
let size = frameSize * numOfFrames;
// Init Encoder 1
let shMem = new SharedArrayBuffer(size+12);
let ch1 = new Channel(size, SharedArrayBuffer, shMem);
let bridgeMem = new SharedArrayBuffer(size+12);
let ch2 = new Channel(size, SharedArrayBuffer, bridgeMem);
await initEncoder(encoder, frameSize, numOfFrames, shMem, bridgeMem);
// Init Encoder 2
let shMem_ = new SharedArrayBuffer(size+12);
let ch1_ = new Channel(size, SharedArrayBuffer, shMem_);
let bridgeMem_ = new SharedArrayBuffer(size+12);
let ch2_ = new Channel(size, SharedArrayBuffer, bridgeMem_);
await initEncoder(encoder_, frameSize, numOfFrames, shMem_, bridgeMem_);
// Send datas
for (let i = 0; i < 10; ++i) {
const data = new Uint8Array([...Array(frameSize).keys()]);
ch1.push(data);
encoder.postMessage(
makeMsg(MESSAGE_TYPE.DATA, {}));
encoder_.postMessage(
makeMsg(MESSAGE_TYPE.DATA, {}));
let chs = [ ch1, ch1_ ];
// Send datas
for (let i = 0; i < 30; ++i) {
chs[i%2].push(data);
}
// Send eof
......@@ -123,13 +154,17 @@ describe("EncWW Specifications", () => {
await new Promise(r => {
let intvl = setInterval(() => {
if (ch2.dataSize() >= 17167) {
if (ch2.dataSize() >= 26597 &&
ch2_.dataSize() >= 26597) {
clearInterval(intvl);
r();
}
}, 100);
}, 1000);
});
expect(ch2.dataSize()).toBe(17167);
expect(ch2.dataSize()).toBe(26597);
expect(ch2_.dataSize()).toBe(26597);
}, 100000);
})
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