Commit baaeb9f7 authored by Linshizhi's avatar Linshizhi

Implement Encoder.

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