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
9d20a86f
Commit
9d20a86f
authored
May 12, 2022
by
Linshizhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
5b72bcf8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
63 additions
and
71 deletions
+63
-71
muxWW.js
resources/workers/muxWW.js
+0
-1
WW.js
src/WW.js
+10
-6
channel.js
src/channel.js
+1
-1
encGroup.js
src/encGroup.js
+16
-28
muxer.c
src/wasms/muxer.c
+1
-0
ENCH264Group.spec.js
tests/ENCH264Group.spec.js
+13
-9
paraEncodeSpec.spec.js
tests/paraEncodeSpec.spec.js
+20
-26
wasm-build.sh
wasm-build.sh
+2
-0
No files found.
resources/workers/muxWW.js
View file @
9d20a86f
...
@@ -134,7 +134,6 @@ async function step() {
...
@@ -134,7 +134,6 @@ async function step() {
continue
;
continue
;
}
}
/* Write data into wasm */
/* Write data into wasm */
muxBuffer
=
muxer
.
_malloc
(
data
.
byteLength
);
muxBuffer
=
muxer
.
_malloc
(
data
.
byteLength
);
muxer
.
HEAP8
.
set
(
data
,
muxBuffer
);
muxer
.
HEAP8
.
set
(
data
,
muxBuffer
);
...
...
src/WW.js
View file @
9d20a86f
import
{
MESSAGE_TYPE
,
typeOfMsg
}
from
'./encGrooupMsg'
;
import
{
makeMsg
,
MESSAGE_TYPE
,
typeOfMsg
}
from
'./encGrooupMsg'
;
import
{
Observable
,
filter
}
from
'./rxjs'
;
import
{
Observable
,
filter
}
from
'./rxjs'
;
...
@@ -12,8 +12,10 @@ export class WWInitError extends Error {
...
@@ -12,8 +12,10 @@ export class WWInitError extends Error {
export
const
WW_STATE
=
Object
.
freeze
({
export
const
WW_STATE
=
Object
.
freeze
({
UNINITIALIZED
:
0
,
UNINITIALIZED
:
0
,
INITED
:
4
,
READY
:
1
,
READY
:
1
,
RUNNING
:
2
,
RUNNING
:
2
,
FIN
:
3
,
});
});
...
@@ -29,6 +31,7 @@ export class WW extends Observable {
...
@@ -29,6 +31,7 @@ export class WW extends Observable {
#
remoteInited
=
false
;
#
remoteInited
=
false
;
#
remoteBridged
=
false
;
#
remoteBridged
=
false
;
#
done
=
false
;
#
done
=
false
;
#
monitorSub
=
null
;
#
state
=
WW_STATE
.
UNINITIALIZED
;
#
state
=
WW_STATE
.
UNINITIALIZED
;
...
@@ -87,10 +90,10 @@ export class WW extends Observable {
...
@@ -87,10 +90,10 @@ export class WW extends Observable {
await
preconnect
(
this
,
targetWW
);
await
preconnect
(
this
,
targetWW
);
let
sub
=
this
.
pipe
(
filter
(
data
=>
msgPredicate
(
data
)
))
//let sub = this.pipe(filter(data => { msgPredicate(data);}
))
.
subscribe
(
data
=>
{
targetWW
.
postMessage
(
data
);
});
//
.subscribe(data => { targetWW.postMessage(data); });
this
.
#
connected
[
targetWW
.
ident
]
=
sub
;
//
this.#connected[targetWW.ident] = sub;
}
}
async
disconnect
(
targetWW
,
uninstall
)
{
async
disconnect
(
targetWW
,
uninstall
)
{
...
@@ -98,7 +101,7 @@ export class WW extends Observable {
...
@@ -98,7 +101,7 @@ export class WW extends Observable {
await
uninstall
(
targetWW
);
await
uninstall
(
targetWW
);
if
(
targetWW
.
ident
in
this
.
#
connected
)
{
if
(
targetWW
.
ident
in
this
.
#
connected
)
{
this
.
#
connected
[
targetWW
.
ident
].
unsubscribe
();
//
this.#connected[targetWW.ident].unsubscribe();
delete
this
.
#
connected
[
targetWW
.
ident
];
delete
this
.
#
connected
[
targetWW
.
ident
];
}
}
}
}
...
@@ -123,12 +126,14 @@ export class WW extends Observable {
...
@@ -123,12 +126,14 @@ export class WW extends Observable {
switch
(
typeOfMsg
(
msg
))
{
switch
(
typeOfMsg
(
msg
))
{
case
MESSAGE_TYPE
.
INIT
:
case
MESSAGE_TYPE
.
INIT
:
this
.
#
remoteInited
=
true
;
this
.
#
remoteInited
=
true
;
this
.
#
state
=
WW_STATE
.
INITED
;
break
;
break
;
case
MESSAGE_TYPE
.
BRIDGE
:
case
MESSAGE_TYPE
.
BRIDGE
:
this
.
#
remoteBridged
=
true
;
this
.
#
remoteBridged
=
true
;
break
;
break
;
case
MESSAGE_TYPE
.
DONE
:
case
MESSAGE_TYPE
.
DONE
:
this
.
#
done
=
true
;
this
.
#
done
=
true
;
this
.
#
state
==
WW_STATE
.
FIN
;
break
;
break
;
}
}
...
@@ -139,5 +144,4 @@ export class WW extends Observable {
...
@@ -139,5 +144,4 @@ export class WW extends Observable {
});
});
}
}
}
}
src/channel.js
View file @
9d20a86f
...
@@ -32,7 +32,7 @@ export class Channel {
...
@@ -32,7 +32,7 @@ export class Channel {
#
rFieldPosLen
=
4
;
#
rFieldPosLen
=
4
;
#
wFieldPosLen
=
4
;
#
wFieldPosLen
=
4
;
#
priFieldLen
=
4
;
#
priFieldLen
=
4
;
#
numOfMetaField
=
3
#
numOfMetaField
=
3
;
#
fieldSize
=
0
;
#
fieldSize
=
0
;
#
metaSize
=
0
;
#
metaSize
=
0
;
...
...
src/encGroup.js
View file @
9d20a86f
...
@@ -52,7 +52,7 @@ export class H264EncWWGroup extends WWGroup {
...
@@ -52,7 +52,7 @@ export class H264EncWWGroup extends WWGroup {
#
terminated
=
false
;
#
terminated
=
false
;
/* Precondition: 2 <= options.numOfWW */
/* Precondition: 2 <= options.numOfWW */
constructor
(
name
,
options
)
{
constructor
(
name
,
numOfWW
,
options
=
{}
)
{
super
();
super
();
...
@@ -75,17 +75,8 @@ export class H264EncWWGroup extends WWGroup {
...
@@ -75,17 +75,8 @@ export class H264EncWWGroup extends WWGroup {
if
(
'bridgechnlsize'
in
options
)
if
(
'bridgechnlsize'
in
options
)
this
.
#
bridgeChannelSize
=
options
.
bridgechnlsize
;
this
.
#
bridgeChannelSize
=
options
.
bridgechnlsize
;
if
(
'numOfWW'
in
options
)
{
this
.
#
numOfWorkers
=
numOfWW
;
// Precondition not meet:
this
.
#
numOfEncWorker
=
this
.
#
numOfWorkers
-
1
;
// At least two web workers is required, one encode worker
// and one mux worker.
if
(
options
.
numOfWW
<
2
)
{
throw
new
Error
(
"Number of worker is too small (<2)"
);
}
this
.
#
numOfWorkers
=
options
.
numOfWW
;
this
.
#
numOfEncWorker
=
options
.
numOfWW
-
1
;
}
}
}
// H264EncWWGroup has two types of workers:
// H264EncWWGroup has two types of workers:
...
@@ -158,11 +149,8 @@ export class H264EncWWGroup extends WWGroup {
...
@@ -158,11 +149,8 @@ export class H264EncWWGroup extends WWGroup {
}
}
if
(
this
.
#
terminated
)
return
;
if
(
this
.
#
terminated
)
return
;
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
)
{
if
(
rgbFrame
==
null
)
{
console
.
log
(
"EOF"
);
for
(
let
i
=
0
;
i
<
this
.
#
numOfEncWorker
;
++
i
)
{
for
(
let
i
=
0
;
i
<
this
.
#
numOfEncWorker
;
++
i
)
{
this
.
#
channels
[
i
].
setPriv
(
PRIV_FLAGS
.
EOF
);
this
.
#
channels
[
i
].
setPriv
(
PRIV_FLAGS
.
EOF
);
}
}
...
@@ -171,21 +159,22 @@ export class H264EncWWGroup extends WWGroup {
...
@@ -171,21 +159,22 @@ export class H264EncWWGroup extends WWGroup {
return
;
return
;
}
}
console
.
log
(
"Ready to push..."
);
while
(
this
.
#
channels
[
this
.
#
curProcWW
].
push
(
rgbFrame
)
==
false
)
{
while
(
this
.
#
channels
[
this
.
#
curProcWW
].
push
(
rgbFrame
)
==
false
)
{
console
.
log
(
"Pushing..."
);
await
sleep
(
300
);
await
sleep
(
300
);
}
}
if
(
!
this
.
#
channels
[
this
.
#
curProcWW
].
isSetPriv
(
PRIV_FLAGS
.
EXECUTING
))
{
if
(
!
this
.
#
channels
[
this
.
#
curProcWW
].
isSetPriv
(
PRIV_FLAGS
.
EXECUTING
))
{
this
.
#
encWorkers
[
this
.
#
curProcWW
].
postMessage
(
this
.
#
encWorkers
[
this
.
#
curProcWW
].
postMessage
(
makeMsg
(
MESSAGE_TYPE
.
DATA
,
{}))
makeMsg
(
MESSAGE_TYPE
.
DATA
,
{}))
}
}
this
.
#
curProcWW
=
(
this
.
#
curProcWW
+
1
)
%
this
.
#
numOfEncWorker
;
this
.
#
curProcWW
=
(
this
.
#
curProcWW
+
1
)
%
this
.
#
numOfEncWorker
;
}
}
isDone
()
{
return
this
.
#
muxWorker
.
isDone
();
}
async
getResult
()
{
async
getResult
()
{
// Muxer is not done the job.
// Muxer is not done the job.
...
@@ -201,11 +190,17 @@ export class H264EncWWGroup extends WWGroup {
...
@@ -201,11 +190,17 @@ export class H264EncWWGroup extends WWGroup {
makeMsg
(
MESSAGE_TYPE
.
DATA_REQUIRE
,
{}));
makeMsg
(
MESSAGE_TYPE
.
DATA_REQUIRE
,
{}));
await
waitCond
(()
=>
result
!=
null
,
500
);
await
waitCond
(()
=>
result
!=
null
,
500
);
sub
.
unsu
s
bscribe
();
sub
.
unsubscribe
();
return
result
;
return
result
;
}
}
terminate
()
{
this
.
#
muxWorker
.
terminate
();
for
(
let
i
=
0
;
i
<
this
.
#
numOfEncWorker
;
++
i
)
this
.
#
encWorkers
[
i
].
terminate
();
}
}
}
...
@@ -241,18 +236,11 @@ function syncInitStrategy(init, ww) {
...
@@ -241,18 +236,11 @@ function syncInitStrategy(init, ww) {
let
inited
=
undefined
;
let
inited
=
undefined
;
let
strategy
=
async
()
=>
{
let
strategy
=
async
()
=>
{
let
sub
=
ww
.
subscribe
(
msg
=>
{
inited
=
typeOfMsg
(
msg
)
==
MESSAGE_TYPE
.
INIT
;
console
.
log
(
"INITED: "
+
ww
.
ident
());
sub
.
unsubscribe
();
});
if
(
await
init
()
===
false
)
{
if
(
await
init
()
===
false
)
{
return
false
;
return
false
;
}
}
// Waiting 1 Second for Encoder/Muxer
// Waiting 1 Second for Encoder/Muxer
let
ret
=
await
waitCond
(()
=>
inited
===
true
,
5000
);
let
ret
=
await
waitCond
(()
=>
ww
.
getState
()
==
WW_STATE
.
INITED
,
5000
);
return
ret
;
return
ret
;
};
};
...
...
src/wasms/muxer.c
View file @
9d20a86f
...
@@ -197,6 +197,7 @@ int writeToOFormat() {
...
@@ -197,6 +197,7 @@ int writeToOFormat() {
}
}
streamWriteFrame
(
octx
,
pkt
);
streamWriteFrame
(
octx
,
pkt
);
printf
(
"Writed
\n
"
);
av_packet_free
(
&
pkt
);
av_packet_free
(
&
pkt
);
...
...
tests/ENCH264Group.spec.js
View file @
9d20a86f
import
{
sleep
}
from
'../src/utils.js'
;
import
{
sleep
,
waitCond
}
from
'../src/utils.js'
;
import
{
H264EncWWGroup
,
H264GRP_OPTIONS
}
from
'../src/encGroup.js'
;
import
{
H264EncWWGroup
,
H264GRP_OPTIONS
}
from
'../src/encGroup.js'
;
describe
(
"H264EncWWGroup Spec"
,
()
=>
{
describe
(
"H264EncWWGroup Spec"
,
()
=>
{
it
(
"Instantiation"
,
async
()
=>
{
it
(
"Instantiation"
,
async
()
=>
{
let
wg
=
new
H264EncWWGroup
(
"h264enc"
,
{
numOfWW
:
2
}
);
let
wg
=
new
H264EncWWGroup
(
"h264enc"
,
2
);
await
wg
.
start
();
await
wg
.
start
();
await
sleep
(
1000
);
await
sleep
(
1000
);
...
@@ -11,11 +11,10 @@ describe("H264EncWWGroup Spec", () => {
...
@@ -11,11 +11,10 @@ describe("H264EncWWGroup Spec", () => {
expect
(
wg
.
numOfWorker
()).
toBe
(
2
);
expect
(
wg
.
numOfWorker
()).
toBe
(
2
);
});
});
f
it
(
"Encode by H264EncWWGroup Spec"
,
async
()
=>
{
it
(
"Encode by H264EncWWGroup Spec"
,
async
()
=>
{
const
RGBAFrameSize
=
1920
*
1080
*
4
;
const
RGBAFrameSize
=
1920
*
1080
*
4
;
let
grp
=
new
H264EncWWGroup
(
"h264enc"
,
{
let
grp
=
new
H264EncWWGroup
(
"h264enc"
,
7
,
{
numOfWW
:
11
,
encchnlsize
:
RGBAFrameSize
*
10
,
encchnlsize
:
RGBAFrameSize
*
10
,
bridgechnlsize
:
Math
.
pow
(
2
,
25
)
bridgechnlsize
:
Math
.
pow
(
2
,
25
)
});
});
...
@@ -28,11 +27,16 @@ describe("H264EncWWGroup Spec", () => {
...
@@ -28,11 +27,16 @@ describe("H264EncWWGroup Spec", () => {
await
grp
.
dispatch
(
data
);
await
grp
.
dispatch
(
data
);
}
}
console
.
log
(
"Main Done"
);
// Terminated
// Terminated
await
grp
.
dispatch
(
null
);
await
grp
.
dispatch
(
null
);
await
sleep
(
100000
);
// Waiting for EncGroup
},
300000
)
await
waitCond
(()
=>
grp
.
isDone
());
let
result
=
await
grp
.
getResult
();
console
.
log
(
result
);
grp
.
terminate
();
},
3000000
)
})
})
tests/paraEncodeSpec.spec.js
View file @
9d20a86f
import
{
ParaEncoder
,
ENCODE_MODE
}
from
"../src/paraEncode.js"
;
import
{
ParaEncoder
,
ENCODE_MODE
}
from
"../src/paraEncode.js"
;
import
{
sleep
}
from
"../src/utils.js"
;
let
paraEnc
;
let
paraEnc
;
const
RGBAFrameSize
=
1920
*
1080
*
4
;
beforeEach
(()
=>
{
beforeEach
(
async
()
=>
{
paraEnc
=
new
ParaEncoder
(
2
,
"H264"
,
ENCODE_MODE
.
SAVE_MEMORY
);
paraEnc
=
new
ParaEncoder
(
11
,
{
codec
:
"H264"
,
grpcfg
:
{
encchnlsize
:
RGBAFrameSize
*
10
,
bridgechnlsize
:
Math
.
pow
(
2
,
25
),
}
});
await
paraEnc
.
init
();
});
});
describe
(
"ParaEncoder"
,
()
=>
{
describe
(
"ParaEncoder"
,
()
=>
{
it
(
"ParaEncoder Normal Init"
,
()
=>
{
fit
(
"Encode With ParaEncoder"
,
async
()
=>
{
expect
(
paraEnc
.
numOfWW
()).
toBe
(
2
);
const
data
=
new
Uint8Array
([...
Array
(
RGBAFrameSize
).
keys
()]);
expect
(
paraEnc
.
codec
()).
toBe
(
"H264"
);
expect
(
paraEnc
.
mode
()).
toBe
(
ENCODE_MODE
.
SAVE_MEMORY
);
});
it
(
"ParaEncoder Invalid Init"
,
()
=>
{
for
(
let
i
=
0
;
i
<
3000
;
++
i
)
{
try
{
await
paraEnc
.
encode
(
data
);
new
ParaEncoder
(
2
,
1
,
ENCODE_MODE
.
SAVE_MEMORY
);
}
}
catch
(
err
)
{}
});
it
(
"ParaEncoder Invalid encode mode"
,
()
=>
{
await
paraEnc
.
encode
(
null
);
let
WRONG_MODE
=
0
;
await
sleep
(
3000000
);
},
300000
);
try
{
new
ParaEncoder
(
1
,
"h264"
,
WRONG_MODE
);
}
catch
(
err
)
{}
});
it
(
"Encode With ParaEncoder"
,
()
=>
{
});
});
});
wasm-build.sh
View file @
9d20a86f
...
@@ -114,6 +114,7 @@ FLAGS_ENCODER=(
...
@@ -114,6 +114,7 @@ FLAGS_ENCODER=(
-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
--pre-js
$WORKPATH
/pre.js
--pre-js
$WORKPATH
/pre.js
--post-js
$WORKPATH
/post.js
--post-js
$WORKPATH
/post.js
$ENCODER_OPTIM_FLAGS
$ENCODER_OPTIM_FLAGS
...
@@ -138,6 +139,7 @@ FLAGS_MUXER=(
...
@@ -138,6 +139,7 @@ FLAGS_MUXER=(
-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
=
536870912
# 64 KB * 1024 * 16 * 2047 = 2146435072 bytes ~= 2 GB, 268435456 =256M, 134,217,728 =128M
-s
INITIAL_MEMORY
=
536870912
# 64 KB * 1024 * 16 * 2047 = 2146435072 bytes ~= 2 GB, 268435456 =256M, 134,217,728 =128M
-s
ASSERTIONS
=
1
--pre-js
$WORKPATH
/pre.js
--pre-js
$WORKPATH
/pre.js
--post-js
$WORKPATH
/post.js
--post-js
$WORKPATH
/post.js
$MUXER_OPTIM_FLAGS
$MUXER_OPTIM_FLAGS
...
...
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