Commit baaeb9f7 authored by Linshizhi's avatar Linshizhi

Implement Encoder.

parent 0bf24f43
......@@ -4,6 +4,7 @@ let isInited = false;
let isBridged = false;
let src = null;
let bridge = null;
let size = null;
// Number of bytes for each read
// from channel
......@@ -34,6 +35,9 @@ async function main(msg) {
if (!isInited)
await init(msg);
break;
case MESSAGE_TYPE.BRIDGE:
if (!isBridged)
await bridging(msg);
case MESSAGE_TYPE.DATA:
await steps();
break;
......@@ -44,6 +48,13 @@ async function main(msg) {
}
}
async function bridging(msg) {
let info = getInfoFromMsg(msg);
bridge = new Channel(info.size, SharedArrayBuffer, info.shm);
isBridged = true;
}
async function init(msg) {
let info = getInfoFromMsg(msg);
src = new Channel(info.size, SharedArrayBuffer, info.shm);
......@@ -53,8 +64,7 @@ async function init(msg) {
await sleep(100);
let size = encoder._malloc(4);
let mem = encoder._encode(size);
console.log(encoder.getValue(size, 'i32'));
let ret = encoder._encodeInit(1920, 1080, 30);
isInited = true;
}
......@@ -65,9 +75,14 @@ async function init(msg) {
async function step() {
// Read RGB Frame from Channel.
let data = src.readData(READ_SIZE);
if (data.byteLength == 0) {
return false;
}
/* RGB Frame Processing */
return await RGBProcessing(data);
await RGBProcessing(data);
return true;
}
async function steps() {
......@@ -98,9 +113,24 @@ async function steps() {
async function RGBProcessing(frame) {
// Encode RGB Frame into H264 Frame
let h264frame = encoder.encode(frame, size);
let frameSize = encoder.getValue(size, 'i32');
let h264frame_ = encoder.HEAP8.subarray(h264frame, h264frame+frameSize);
return false;
// Push to Muxer
bridge.push(h264frame_);
// To Check that is Muxer in executing
let flag = bridge.readPriv()
if (flag & PRIV_FLAGS.EXECUTING == 0) {
// Muxer is idle, send a Data message to
// Muxer to wake it up.
postMessage(makeMsg(Data, {}));
}
return true;
}
......@@ -396,6 +426,7 @@ const MESSAGE_TYPE = Object.freeze({
/* Notify to oppsite that there is datas
* within shared memory */
DATA : 4,
BRIDGE : 5,
MSG_MAX : 5,
});
......
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