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
4bb7fec1
Commit
4bb7fec1
authored
Apr 30, 2022
by
NzSN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Endoer WW return message after initialization complete.
parent
d2228340
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
22 deletions
+62
-22
encWW.js
resources/workers/encWW.js
+5
-0
WW.spec.js
tests/WW.spec.js
+57
-22
No files found.
resources/workers/encWW.js
View file @
4bb7fec1
...
...
@@ -93,6 +93,7 @@ async function init(msg) {
ret
=
encoder
.
_encodeInit
(
1920
,
1080
,
30
);
isInited
=
true
;
postMessage
(
makeMsg
(
MESSAGE_TYPE
.
INIT
,
{}));
}
async
function
destroy
()
{
...
...
@@ -160,6 +161,8 @@ async function EOFProcessing() {
}
}
let
i
=
0
;
async
function
RGBProcessing
(
frame
)
{
let
ret
=
0
,
size_
;
...
...
@@ -176,6 +179,8 @@ async function RGBProcessing(frame) {
throw
new
Error
(
"Unknown error"
);
}
++
i
;
sendToMuxer
(
size_
);
return
true
;
}
...
...
tests/WW.spec.js
View file @
4bb7fec1
import
{
WW
}
from
'../src/WW.js'
;
import
{
Channel
}
from
'../src/channel.js'
;
import
{
makeMsg
,
MESSAGE_TYPE
}
from
'../src/encGrooupMsg.js'
;
import
{
sleep
}
from
'../src/utils.js'
;
import
{
sleep
,
assert
}
from
'../src/utils.js'
;
// For Webpack 5
let
url
=
'../resources/tests/worker.js'
;
...
...
@@ -84,37 +84,68 @@ describe("WW Spec", () => {
});
async
function
initEncoder
(
encoder
,
frameSize
,
numOfFrames
,
shMem
,
bridgeMem
)
{
// Create a Shared memory which able to contain
// 8 RGBA Frames.
let
size
=
frameSize
*
numOfFrames
;
// Init encoder
encoder
.
postMessage
(
makeMsg
(
MESSAGE_TYPE
.
INIT
,
{
size
:
size
,
shm
:
shMem
}));
await
new
Promise
(
r
=>
{
let
sub
=
encoder
.
subscribe
(
msg
=>
{
assert
(
msg
.
type
==
MESSAGE_TYPE
.
INIT
);
sub
.
unsubscribe
();
r
();
})
})
// Bridge to Main Thread
encoder
.
postMessage
(
makeMsg
(
MESSAGE_TYPE
.
BRIDGE
,
{
shm
:
bridgeMem
,
size
:
size
}));
}
describe
(
"EncWW Specifications"
,
()
=>
{
it
(
"Handle RGBA Frames"
,
async
()
=>
{
let
encoder
=
new
WW
(
'encoder'
,
'../resources/workers/encWW.js'
);
fit
(
"Handle RGBA Frames"
,
async
()
=>
{
let
encoder
=
new
WW
(
'encoder1'
,
'../resources/workers/encWW.js'
);
let
encoder_
=
new
WW
(
'encoder2'
,
'../resources/workers/encWW.js'
)
let
frameSize
=
1920
*
1080
*
4
;
let
numOfFrames
=
10
;
// Create a Shared memory which able to contain
// 8 RGBA Frames.
let
numOfFrames
=
30
;
let
size
=
frameSize
*
numOfFrames
;
// Init Encoder 1
let
shMem
=
new
SharedArrayBuffer
(
size
+
12
);
let
ch1
=
new
Channel
(
size
,
SharedArrayBuffer
,
shMem
);
// Init encoder
encoder
.
postMessage
(
makeMsg
(
MESSAGE_TYPE
.
INIT
,
{
size
:
size
,
shm
:
shMem
}));
let
bridgeMem
=
new
SharedArrayBuffer
(
size
+
12
);
let
ch2
=
new
Channel
(
size
,
SharedArrayBuffer
,
bridgeMem
);
// Bridge to Main Thread
await
initEncoder
(
encoder
,
frameSize
,
numOfFrames
,
shMem
,
bridgeMem
);
// Init Encoder 2
let
shMem_
=
new
SharedArrayBuffer
(
size
+
12
);
let
ch1_
=
new
Channel
(
size
,
SharedArrayBuffer
,
shMem_
);
let
bridgeMem_
=
new
SharedArrayBuffer
(
size
+
12
);
let
ch2_
=
new
Channel
(
size
,
SharedArrayBuffer
,
bridgeMem_
);
await
initEncoder
(
encoder_
,
frameSize
,
numOfFrames
,
shMem_
,
bridgeMem_
);
const
data
=
new
Uint8Array
([...
Array
(
frameSize
).
keys
()]);
encoder
.
postMessage
(
makeMsg
(
MESSAGE_TYPE
.
BRIDGE
,
{
shm
:
bridgeMem
,
size
:
size
}));
makeMsg
(
MESSAGE_TYPE
.
DATA
,
{}));
encoder_
.
postMessage
(
makeMsg
(
MESSAGE_TYPE
.
DATA
,
{}));
await
sleep
(
1000
)
;
let
chs
=
[
ch1
,
ch1_
]
;
// Send datas
for
(
let
i
=
0
;
i
<
10
;
++
i
)
{
const
data
=
new
Uint8Array
([...
Array
(
frameSize
).
keys
()]);
ch1
.
push
(
data
);
encoder
.
postMessage
(
makeMsg
(
MESSAGE_TYPE
.
DATA
,
{}));
for
(
let
i
=
0
;
i
<
30
;
++
i
)
{
chs
[
i
%
2
].
push
(
data
);
}
// Send eof
...
...
@@ -123,13 +154,17 @@ describe("EncWW Specifications", () => {
await
new
Promise
(
r
=>
{
let
intvl
=
setInterval
(()
=>
{
if
(
ch2
.
dataSize
()
>=
17167
)
{
if
(
ch2
.
dataSize
()
>=
26597
&&
ch2_
.
dataSize
()
>=
26597
)
{
clearInterval
(
intvl
);
r
();
}
},
100
);
},
100
0
);
});
expect
(
ch2
.
dataSize
()).
toBe
(
17167
);
expect
(
ch2
.
dataSize
()).
toBe
(
26597
);
expect
(
ch2_
.
dataSize
()).
toBe
(
26597
);
},
100000
);
})
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