Commit 6f9e2c8e authored by NzSN's avatar NzSN

Add new spec and Channel update.

parent c04fa8c0
// Karma configuration // Karma configuration
// Generated on Tue Apr 19 2022 21:54:47 GMT+0800 (China Standard Time) // 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) { function CrossOriginIsolationMiddlewareFactory(config) {
return function crossOriginIsolation(req, res, next) { return function crossOriginIsolation(req, res, next) {
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin'); res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
......
...@@ -17,13 +17,11 @@ const SPIN_TIMEOUT = 500; ...@@ -17,13 +17,11 @@ const SPIN_TIMEOUT = 500;
const ENC_BUF_SIZE = RGBFrameSize * 10 const ENC_BUF_SIZE = RGBFrameSize * 10
let encBuf = null; let encBuf = null;
// Read H264 Encode Group definitions // Read H264 Encode Group definitions
self.importScripts('defs.js'); self.importScripts('defs.js');
// Load wasm encoder // Load wasm encoder
self.importScripts('./mp4encoder.js'); self.importScripts('mp4encoder.js');
createMP4Encoder().then(m => { createMP4Encoder().then(m => {
encoder = m; encoder = m;
}); });
......
...@@ -186,7 +186,7 @@ export class Channel { ...@@ -186,7 +186,7 @@ export class Channel {
return new Uint8Array(0); return new Uint8Array(0);
} else if (this.#readPointerCache < writePos) { } else if (this.#readPointerCache < writePos) {
readTo = this.#readPointerCache + Math.min(size, writePos - this.#readPointerCache); 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); this.#readPointerUpdate(readTo);
} else { } else {
// To make sure // To make sure
...@@ -197,13 +197,13 @@ export class Channel { ...@@ -197,13 +197,13 @@ export class Channel {
readBuffer = new Uint8Array(firstRSize+secondRSize); readBuffer = new Uint8Array(firstRSize+secondRSize);
// First read // First read
readBuffer.set(this.#buffer.slice( readBuffer.set(this.#buffer.subarray(
this.#readPointerCache, this.#readPointerCache+firstRSize), 0); this.#readPointerCache, this.#readPointerCache+firstRSize), 0);
// Second Read // Second Read
if (secondRSize > 0) { if (secondRSize > 0) {
readBuffer.set( readBuffer.set(
this.#buffer.slice(this.#metaSize, this.#metaSize+secondRSize), this.#buffer.subarray(this.#metaSize, this.#metaSize+secondRSize),
firstRSize); firstRSize);
this.#readPointerUpdate(this.#metaSize+secondRSize); this.#readPointerUpdate(this.#metaSize+secondRSize);
} else { } else {
...@@ -239,7 +239,7 @@ export class Channel { ...@@ -239,7 +239,7 @@ export class Channel {
if (plan.size == 0) if (plan.size == 0)
continue; continue;
let d_ = data.slice(srcPos, srcPos+plan.size); let d_ = data.subarray(srcPos, srcPos+plan.size);
this.#buffer.set(d_, plan.pos); this.#buffer.set(d_, plan.pos);
srcPos += plan.size; srcPos += plan.size;
writePos = plan.pos+plan.size; writePos = plan.pos+plan.size;
......
import { WW } from '../src/WW.js'; 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 // For Webpack 5
let url = '../resources/tests/worker.js'; let url = '../resources/tests/worker.js';
...@@ -80,3 +83,53 @@ describe("WW Spec", () => { ...@@ -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