Commit 8bd31b04 authored by Linshizhi's avatar Linshizhi

update

parent 522461ca
......@@ -188,6 +188,7 @@ EM_PORT_API(int) getPackets(uint8_t *buffer, uint32_t size, uint32_t *osize) {
if (lastPkt != NULL && lastPkt->size > remainSize) {
memcpy(pos, lastPkt->data, lastPkt->size);
pos += lastPkt->size;
remainSize -= lastPkt->size;
av_packet_unref(lastPkt);
lastPkt = NULL;
......@@ -198,15 +199,19 @@ EM_PORT_API(int) getPackets(uint8_t *buffer, uint32_t size, uint32_t *osize) {
while (true) {
ret = avcodec_receive_packet(cc, packet);
if (ret < 0) {
ret = 1;
goto DONE;
}
printf("WASM Encode: Packet Size %d\n", packet->size);
// For video frame avcodec_receive_packet should return
// only once.
if (remainSize > packet->size) {
memcpy(pos, packet->data, packet->size);
pos += packet->size;
remainSize -= packet->size;
} else {
lastPkt = packet;
......@@ -217,12 +222,19 @@ EM_PORT_API(int) getPackets(uint8_t *buffer, uint32_t size, uint32_t *osize) {
}
DONE:
*osize = size - remainSize;
return ret;
}
EM_PORT_API(int) flushEncoder() {
if (avcodec_send_frame(cc, NULL) < 0) {
return 1;
}
return 0;
}
///////////////////////////////////////////////////////////////////////////////
// Muxing Parts //
///////////////////////////////////////////////////////////////////////////////
......@@ -252,7 +264,7 @@ public:
void push(int idx, AVPacket *packet) {
printf("PacketBuffer: Push\n");
packets[idx].push(packet);
printf("size of packet in %d is %d\n", idx, packets[idx].size());
printf("size of packet in %d is %lu\n", idx, packets[idx].size());
}
AVPacket* pop(int idx) {
......@@ -329,7 +341,7 @@ EM_PORT_API(int) muxPush(int sIdx, uint8_t *data, size_t size) {
}
int bufferPackets() {
int ret = 0, total = 0;
int ret = 0, total = 0;
AVPacket *pkt = nullptr;
while (true) {
......@@ -415,17 +427,29 @@ void ioCtxInitialize() {
printf("Size of Buffer %d: %ld\n", i, MuxEnv::protos[i].size());
// IOProto require 20KB to probe stream informations.
if (!MuxEnv::inited[i] && MuxEnv::protos[i].size() > 65000) {
if (!MuxEnv::inited[i] && MuxEnv::protos[i].size() > 25000) {
MuxEnv::ctxs[i] = new IOCtx::InCtx{"", &MuxEnv::protos[i]};
MuxEnv::inited[i] = true;
if (!MuxEnv::oCtxInited) {
printf("Inited Output\n");
AVStream *s = MuxEnv::ctxs[i]->getStream([](AVStream *s) {
return s->codecpar->codec_type == AVMEDIA_TYPE_VIDEO;
});
if (s == nullptr) {
printf("Failed to got stream\n");
}
printf("Stream got\n");
printf("New Stream...\n");
MuxEnv::oCtx.newStream(s->codecpar);
printf("New Stream...Done\n");
printf("Write Header....\n");
MuxEnv::oCtx.writeHeader();
printf("Write Header....Done\n");
}
printf("INIT DONE: %d\n", i);
......@@ -473,6 +497,7 @@ int writeToOutput() {
goto END_LOOP;
}
else if (p->data == nullptr && p->size == 0) {
MuxEnv::finished[i] = true;
goto MUX_DONE;
}
......@@ -490,15 +515,15 @@ int writeToOutput() {
}
END_LOOP:
printf("SKIP %d", i);
printf("SKIP %d\n", i);
MuxEnv::currentChannel = i;
return 0;
MUX_DONE:
printf("WASM MUXER DONE\n");
for (int i = 0; i < MuxEnv::numOfStreams; ++i) {
printf("Remain in Proto %d is %d\n", i, MuxEnv::protos[i].size());
printf("Remain in packet buffer %d is %d\n\n", MuxEnv::pktBuffer.size(i));
printf("Remain in Proto %d is %zu\n", i, MuxEnv::protos[i].size());
printf("Remain in packet buffer %d is %d\n\n", i, MuxEnv::pktBuffer.size(i));
}
MuxEnv::done = true;
MuxEnv::oCtx.writeTrailer();
......
......@@ -16,7 +16,7 @@ describe("H264EncWWGroup Spec", () => {
const RGBAFrameSize = 1920*1080*4;
let grp = new H264EncWWGroup("h264enc", {
numOfWW: 3,
numOfWW: 2,
encchnlsize: RGBAFrameSize * 10,
bridgechnlsize: Math.pow(2, 25)
});
......
......@@ -3,7 +3,6 @@
set -euxo pipefail
WORKPATH=$(cd $(dirname $0); pwd)
DEMO_PATH=$WORKPATH
rm -rf ${DEMO_PATH}/resources/workers/paraencoder.js ${DEMO_PATH}/resources/workers/paraencoder.wasm
......@@ -101,9 +100,10 @@ FLAGS=(
-s EXPORTED_FUNCTIONS="[_main,_malloc,_free]" # export main and proxy_main funcs
-s EXPORTED_RUNTIME_METHODS="[FS, cwrap, ccall, setValue, writeAsciiToMemory, getValue]" # export preamble funcs
-s INITIAL_MEMORY=268435456 # 64 KB * 1024 * 16 * 2047 = 2146435072 bytes ~= 2 GB, 268435456 =256M, 134,217,728 =128M
-s ASSERTIONS=1
-s SAFE_HEAP=1
-s ASSERTIONS=2
-s DEMANGLE_SUPPORT=1
-s WARN_UNALIGNED=1
-s SAFE_HEAP=1
--pre-js $WORKPATH/pre.js
--post-js $WORKPATH/post.js
$OPTIM_FLAGS
......
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