Commit 6f9e2c8e authored by NzSN's avatar NzSN

Add new spec and Channel update.

parent c04fa8c0
// Karma configuration
// Generated on Tue Apr 19 2022 21:54:47 GMT+0800 (China Standard Time)
let webpackConfig = require('./webpack.tdd.conf.js');
const path = require('path');
function CrossOriginIsolationMiddlewareFactory(config) {
return function crossOriginIsolation(req, res, next) {
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
......
......@@ -17,13 +17,11 @@ const SPIN_TIMEOUT = 500;
const ENC_BUF_SIZE = RGBFrameSize * 10
let encBuf = null;
// Read H264 Encode Group definitions
self.importScripts('defs.js');
// Load wasm encoder
self.importScripts('./mp4encoder.js');
self.importScripts('mp4encoder.js');
createMP4Encoder().then(m => {
encoder = m;
});
......
......@@ -186,7 +186,7 @@ export class Channel {
return new Uint8Array(0);
} else if (this.#readPointerCache < writePos) {
readTo = this.#readPointerCache + Math.min(size, writePos - this.#readPointerCache);
readBuffer = this.#buffer.slice(this.#readPointerCache, readTo);
readBuffer = this.#buffer.subarray(this.#readPointerCache, readTo);
this.#readPointerUpdate(readTo);
} else {
// To make sure
......@@ -197,13 +197,13 @@ export class Channel {
readBuffer = new Uint8Array(firstRSize+secondRSize);
// First read
readBuffer.set(this.#buffer.slice(
readBuffer.set(this.#buffer.subarray(
this.#readPointerCache, this.#readPointerCache+firstRSize), 0);
// Second Read
if (secondRSize > 0) {
readBuffer.set(
this.#buffer.slice(this.#metaSize, this.#metaSize+secondRSize),
this.#buffer.subarray(this.#metaSize, this.#metaSize+secondRSize),
firstRSize);
this.#readPointerUpdate(this.#metaSize+secondRSize);
} else {
......@@ -239,7 +239,7 @@ export class Channel {
if (plan.size == 0)
continue;
let d_ = data.slice(srcPos, srcPos+plan.size);
let d_ = data.subarray(srcPos, srcPos+plan.size);
this.#buffer.set(d_, plan.pos);
srcPos += plan.size;
writePos = plan.pos+plan.size;
......
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';
// For Webpack 5
let url = '../resources/tests/worker.js';
......@@ -80,3 +83,53 @@ 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;
// 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);
// Bridge to Main Thread
encoder.postMessage(
makeMsg(MESSAGE_TYPE.BRIDGE, { shm: bridgeMem, size: size }));
await sleep(1000);
// 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, {}));
}
// Send eof
encoder.postMessage(
makeMsg(MESSAGE_TYPE.EOF, {}));
await new Promise(r => {
let intvl = setInterval(() => {
if (ch2.dataSize() >= 17167) {
clearInterval(intvl);
r();
}
}, 100);
});
expect(ch2.dataSize()).toBe(17167);
}, 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