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