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