Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
P
ParaEncode
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ParaEncode
Commits
fc687dec
Commit
fc687dec
authored
May 09, 2022
by
NzSN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
69150b38
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
65 additions
and
71 deletions
+65
-71
karma.conf.js
karma.conf.js
+2
-0
muxWW.js
resources/workers/muxWW.js
+9
-2
encGroup.js
src/encGroup.js
+2
-2
interfaces.cc
src/wasms/interfaces.cc
+40
-56
ENCH264Group.spec.js
tests/ENCH264Group.spec.js
+3
-2
wasm-build.sh
wasm-build.sh
+9
-9
No files found.
karma.conf.js
View file @
fc687dec
...
...
@@ -22,6 +22,7 @@ module.exports = function(config) {
// list of files / patterns to load in the browser
files
:
[
{
pattern
:
'./temp.debug.wasm'
,
included
:
false
,
served
:
true
},
{
pattern
:
'src/**/*.js'
,
included
:
false
,
served
:
true
},
{
pattern
:
'tests/**/*.js'
,
included
:
true
},
{
pattern
:
'resources/**/*.js'
,
included
:
false
,
served
:
true
},
...
...
@@ -35,6 +36,7 @@ module.exports = function(config) {
'/src'
:
'/base/src/'
,
'/resources'
:
'/base/resources/'
,
'/workers'
:
'/base/tests/workers/'
,
'/temp.debug.wasm'
:
'/base/temp.debug.wasm'
},
// preprocess matching files before serving them to the browser
...
...
resources/workers/muxWW.js
View file @
fc687dec
...
...
@@ -13,6 +13,8 @@ let eof = [];
let
eofCount
=
0
;
let
done
=
false
;
let
inExec
=
false
;
// Constants
const
SLEEP_INTERVAL
=
100
;
const
SPIN_TIMEOUT
=
100000
;
...
...
@@ -51,7 +53,7 @@ async function main(msg) {
if
(
isBridged
)
await
deBridging
();
break
;
case
MESSAGE_TYPE
.
DATA
:
await
steps
();
if
(
!
inExec
)
await
steps
();
break
;
case
MESSAGE_TYPE
.
DESTROY
:
if
(
isInited
)
await
destroy
();
...
...
@@ -136,7 +138,7 @@ async function step() {
continue
;
}
console
.
log
(
"MUXWW Push to "
+
i
);
console
.
log
(
"MUXWW Push to "
+
i
+
" with length "
+
data
.
byteLength
);
/* Write data into wasm */
muxBuffer
=
muxer
.
_malloc
(
data
.
byteLength
);
...
...
@@ -152,6 +154,9 @@ async function step() {
}
async
function
steps
()
{
inExec
=
true
;
while
(
await
step
())
{
console
.
log
(
"Done: "
+
done
);
if
(
done
)
...
...
@@ -162,4 +167,6 @@ async function steps() {
// Notify to main thread that all frames
// has been written into format.
postMessage
(
makeMsg
(
MESSAGE_TYPE
.
DONE
,
{}));
inExec
=
false
;
}
src/encGroup.js
View file @
fc687dec
...
...
@@ -160,9 +160,9 @@ export class H264EncWWGroup extends WWGroup {
console
.
log
(
"Proc WW is "
+
this
.
#
encWorkers
[
this
.
#
curProcWW
].
ident
());
// Null is treated as terminated
// frame.
// Null is treated as terminated frame.
if
(
rgbFrame
==
null
)
{
console
.
log
(
"EOF"
);
for
(
let
i
=
0
;
i
<
this
.
#
numOfEncWorker
;
++
i
)
{
this
.
#
channels
[
i
].
setPriv
(
PRIV_FLAGS
.
EOF
);
}
...
...
src/wasms/interfaces.cc
View file @
fc687dec
...
...
@@ -250,6 +250,8 @@ using IOEndpoint = IOProto::MovMemProto::MovMemProto;
namespace
MuxEnv
{
size_t
numOfPackets_
;
class
PacketBuffer
{
public
:
using
PacketChain
=
std
::
queue
<
AVPacket
*>
;
...
...
@@ -264,7 +266,7 @@ public:
void
push
(
int
idx
,
AVPacket
*
packet
)
{
printf
(
"PacketBuffer: Push
\n
"
);
packets
[
idx
].
push
(
packet
);
printf
(
"size of packet in %d is %lu
\n
"
,
idx
,
packets
[
idx
].
size
())
;
++
numOfPackets_
;
}
AVPacket
*
pop
(
int
idx
)
{
...
...
@@ -276,6 +278,7 @@ public:
auto
pkt
=
chain
.
front
();
chain
.
pop
();
numOfPackets_
--
;
return
pkt
;
}
...
...
@@ -283,18 +286,23 @@ public:
return
packets
[
idx
].
size
();
}
int
numOfPkts
()
{
return
numOfPackets_
;
}
private
:
std
::
vector
<
PacketChain
>
packets
;
};
bool
ioCtxInited
=
false
;
int
numOfStreams
=
0
;
int
numOfStreams1
=
0
;
PacketBuffer
pktBuffer
;
int
finishedCount
=
0
;
int
initedCount
=
0
;
std
::
shared_ptr
<
bool
[]
>
finished
;
std
::
shared_ptr
<
bool
[]
>
inited
;
std
::
shared_ptr
<
bool
[]
>
failed
;
bool
*
finished
;
bool
*
inited
;
bool
*
failed
;
bool
oCtxInited
=
false
;
std
::
vector
<
IOEndpoint
>
protos
;
IOCtx
::
InCtx
**
ctxs
=
nullptr
;
...
...
@@ -317,13 +325,15 @@ EM_PORT_API(int) muxInit(int numOfStreams) {
// Setup MuxEnv Status
MuxEnv
::
numOfStreams
=
numOfStreams
;
MuxEnv
::
pktBuffer
=
MuxEnv
::
PacketBuffer
(
numOfStreams
);
MuxEnv
::
finished
=
std
::
shared_ptr
<
bool
[]
>
(
new
bool
[
numOfStreams
]{
false
});
MuxEnv
::
inited
=
std
::
shared_ptr
<
bool
[]
>
(
new
bool
[
numOfStreams
]{
false
});
MuxEnv
::
failed
=
std
::
shared_ptr
<
bool
[]
>
(
new
bool
[
numOfStreams
]{
false
});
MuxEnv
::
numOfStreams1
=
numOfStreams
;
printf
(
"Numb of Streams %d
\n
"
,
MuxEnv
::
numOfStreams
);
MuxEnv
::
pktBuffer
=
MuxEnv
::
PacketBuffer
(
MuxEnv
::
numOfStreams
);
MuxEnv
::
finished
=
new
bool
[
MuxEnv
::
numOfStreams
]{
false
};
MuxEnv
::
inited
=
new
bool
[
MuxEnv
::
numOfStreams
]{
false
};
MuxEnv
::
failed
=
new
bool
[
MuxEnv
::
numOfStreams
]{
false
};
MuxEnv
::
ctxs
=
(
IOCtx
::
InCtx
**
)
malloc
(
sizeof
(
IOCtx
::
InCtx
*
));
printf
(
"Numb of Streams %d
\n
"
,
numOfStreams
);
for
(
int
i
=
0
;
i
<
numOfStreams
;
++
i
)
{
...
...
@@ -335,8 +345,8 @@ EM_PORT_API(int) muxInit(int numOfStreams) {
}
EM_PORT_API
(
int
)
muxPush
(
int
sIdx
,
uint8_t
*
data
,
size_t
size
)
{
printf
(
"
Push to %d in wasm
\n
"
,
sIdx
);
MuxEnv
::
protos
[
sIdx
].
push
(
data
,
size
);
printf
(
"
MUX WASM: Push to proto %d: %p,%ld
\n
"
,
sIdx
,
data
,
size
);
MuxEnv
::
protos
[
sIdx
%
MuxEnv
::
numOfStreams1
].
push
(
data
,
size
);
return
0
;
}
...
...
@@ -352,18 +362,14 @@ int bufferPackets() {
for
(
int
i
=
0
;
i
<
MuxEnv
::
numOfStreams
;
++
i
)
{
if
(
MuxEnv
::
failed
[
i
]
||
MuxEnv
::
finished
[
i
]
||
!
MuxEnv
::
inited
[
i
])
{
printf
(
"SKIP %d
\n
"
,
i
);
printf
(
"
WASM:
SKIP %d
\n
"
,
i
);
continue
;
}
printf
(
"IOCTX %d in processing...
\n
"
,
i
);
IOCtx
::
InCtx
*
c
=
MuxEnv
::
ctxs
[
i
];
pkt
=
pkt
==
nullptr
?
av_packet_alloc
()
:
pkt
;
printf
(
"Read Frame...
\n
"
);
ret
=
c
->
readFrame_
(
pkt
);
printf
(
"Read Frame...Done
\n
"
);
if
(
ret
<
0
)
{
if
(
ret
==
AVERROR_EOF
)
{
MuxEnv
::
finishedCount
++
;
...
...
@@ -372,31 +378,25 @@ int bufferPackets() {
printf
(
"WASM: EOF %d
\n
"
,
i
);
if
(
MuxEnv
::
finishedCount
==
MuxEnv
::
numOfStreams
)
{
printf
(
"ALL STREAM EOF DONE
\n
"
);
AVPacket
*
nullpkt
=
av_packet_alloc
();
nullpkt
->
data
=
nullptr
;
nullpkt
->
size
=
0
;
MuxEnv
::
finished
[
i
]
=
false
;
MuxEnv
::
pktBuffer
.
push
(
i
,
nullpkt
);
//
MuxEnv::pktBuffer.push(i, nullpkt);
}
goto
END_LOOP
;
}
else
if
(
ret
==
AVERROR
(
EAGAIN
))
{
printf
(
"READ AGAIN
\n
"
);
}
else
{
}
else
if
(
ret
!=
AVERROR
(
EAGAIN
))
{
MuxEnv
::
failed
[
i
]
=
true
;
printf
(
"Failed
\n
"
);
}
continue
;
}
printf
(
"PKT SIZE %d
\n
"
,
pkt
->
size
);
printf
(
"Buffer into buffer %d
\n
"
,
i
);
printf
(
"BUFFER PACKET
\n
"
);
MuxEnv
::
pktBuffer
.
push
(
i
,
pkt
);
printf
(
"Buffer into buffer %d Done
\n
"
,
i
);
pkt
=
nullptr
;
++
readed
;
...
...
@@ -424,7 +424,6 @@ void ioCtxInitialize() {
for
(
int
i
=
0
;
i
<
MuxEnv
::
numOfStreams
;
++
i
)
{
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
()
>
25000
)
{
...
...
@@ -432,27 +431,15 @@ void ioCtxInitialize() {
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
);
printf
(
"INIT %d
\n
"
,
i
);
++
MuxEnv
::
initedCount
;
}
}
...
...
@@ -488,12 +475,16 @@ int writeToOutput() {
while
(
true
)
{
AVPacket
*
p
=
MuxEnv
::
pktBuffer
.
pop
(
i
);
return
0
;
printf
(
"WriteToOutput(): Index %d
\n
"
,
i
);
if
(
p
==
nullptr
)
if
(
MuxEnv
::
finished
[
i
])
{
printf
(
"
SKIP Cause of FIN %d
\n
"
,
i
);
printf
(
"
WriteToOutput(): Fin
\n
"
);
goto
NEXT
;
}
else
{
printf
(
"
P is nullptr in %d
\n
"
,
i
);
printf
(
"
WriteToOutput(): END LOOP
\n
"
);
goto
END_LOOP
;
}
else
if
(
p
->
data
==
nullptr
&&
p
->
size
==
0
)
{
...
...
@@ -504,8 +495,8 @@ int writeToOutput() {
timestampSetup
(
p
);
// Write to output context
MuxEnv
::
oCtx
.
writeFrame
(
p
);
printf
(
"Write
Done %d
\n
"
,
i
);
//
MuxEnv::oCtx.writeFrame(p);
printf
(
"Write
ToOutput(): Index %d...Done
\n
"
,
i
);
// Cleaning
av_packet_free
(
&
p
);
...
...
@@ -515,16 +506,10 @@ int writeToOutput() {
}
END_LOOP
:
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 %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
();
...
...
@@ -533,22 +518,21 @@ int writeToOutput() {
EM_PORT_API
(
int
)
muxStep
()
{
printf
(
"Step Buffer
\n
"
);
// Buffer Encoded frames from
// Encoder into 'MuxEnv::pktBuffer'
bufferPackets
();
printf
(
"
Init
\n
"
);
printf
(
"
%d packets are buffered
\n
"
,
MuxEnv
::
pktBuffer
.
numOfPkts
()
);
// Initialize IOCtx
if
(
MuxEnv
::
initedCount
<
MuxEnv
::
numOfStreams
)
ioCtxInitialize
();
printf
(
"WriteOut
\n
"
);
if
(
MuxEnv
::
initedCount
==
MuxEnv
::
numOfStreams
)
// Try to write to output file
return
writeToOutput
();
else
return
0
;
}
EM_PORT_API
(
int
)
isDone
()
{
...
...
tests/ENCH264Group.spec.js
View file @
fc687dec
...
...
@@ -9,14 +9,13 @@ describe("H264EncWWGroup Spec", () => {
await
sleep
(
1000
);
expect
(
wg
.
numOfWorker
()).
toBe
(
2
);
});
fit
(
"Encode by H264EncWWGroup Spec"
,
async
()
=>
{
const
RGBAFrameSize
=
1920
*
1080
*
4
;
let
grp
=
new
H264EncWWGroup
(
"h264enc"
,
{
numOfWW
:
2
,
numOfWW
:
8
,
encchnlsize
:
RGBAFrameSize
*
10
,
bridgechnlsize
:
Math
.
pow
(
2
,
25
)
});
...
...
@@ -29,6 +28,8 @@ describe("H264EncWWGroup Spec", () => {
await
grp
.
dispatch
(
data
);
}
console
.
log
(
"Main Done"
);
// Terminated
await
grp
.
dispatch
(
null
);
...
...
wasm-build.sh
View file @
fc687dec
...
...
@@ -17,8 +17,8 @@ THIRD_DIR=${WORKPATH}/lib/third/build
FFMPEG_PROTO
=
${
WORKPATH
}
/src/protos/src
WASM_DIR
=
${
WORKPATH
}
/src/wasms
DEBUG
=
"-O2"
#DEBUG="-O1 -g -fno-inline -gseparate-dwarf=./temp.debug.wasm -s SEPARATE_DWARF_URL=http://localhost:9678
/temp.debug.wasm"
#
DEBUG="-O2"
DEBUG
=
"-g2 -gseparate-dwarf=./temp.debug.wasm -s SEPARATE_DWARF_URL=http://localhost:9876
/temp.debug.wasm"
BUILD_DIR
=
${
WORKPATH
}
/Build
...
...
@@ -81,12 +81,15 @@ else
fi
FLAGS
=(
-I
$BUILD_DIR
/include
-L
$BUILD_DIR
/lib
-I
$LIB_DIR
/ffmpeg.wasm-core
-
Wno-deprecated-declarations
-Wno-pointer-sign
-Wno-implicit-int-float-conversion
-Wno-switch
-Wno-parentheses
-Qunused-arguments
-I
$BUILD_DIR
/include
-L
$BUILD_DIR
/lib
-I
$LIB_DIR
/ffmpeg.wasm-core
-
I
$LIB_DIR
/ffmpeg.protos/src
-Wno-
deprecated-declarations
-Wno-
pointer-sign
-Wno-implicit-int-float-conversion
-Wno-switch
-Wno-parentheses
-Qunused-arguments
-lavdevice
-lavfilter
-lavformat
-lavcodec
-lswresample
-lswscale
-lavutil
-lpostproc
-lm
-lx264
-lz
-lshmproto
$WASM_DIR
/interfaces.cc
$LIB_DIR
/ffmpeg.protos/src/ioctx.cc
$LIB_DIR
/ffmpeg.protos/src/utils.cc
$LIB_DIR
/ffmpeg.protos/src/proto/movMemProto.cc
$LIB_DIR
/ffmpeg.protos/src/proto/proto.cc
-std
=
c++2a
-s
FORCE_FILESYSTEM
=
1
...
...
@@ -98,10 +101,7 @@ FLAGS=(
-s
EXPORT_NAME
=
"createParaEncoder"
# assign export name for browser
-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
=
2
-s
DEMANGLE_SUPPORT
=
1
-s
WARN_UNALIGNED
=
1
-s
INITIAL_MEMORY
=
536870912
# 64 KB * 1024 * 16 * 2047 = 2146435072 bytes ~= 2 GB, 268435456 =256M, 134,217,728 =128M
-s
SAFE_HEAP
=
1
--pre-js
$WORKPATH
/pre.js
--post-js
$WORKPATH
/post.js
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment