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
88aa6f05
Commit
88aa6f05
authored
May 03, 2022
by
NzSN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
backup
parent
db721063
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
85 additions
and
12 deletions
+85
-12
encWW.js
resources/workers/encWW.js
+9
-4
muxWW.js
resources/workers/muxWW.js
+3
-0
WW.js
src/WW.js
+44
-2
encGrooupMsg.js
src/encGrooupMsg.js
+2
-2
encGroup.js
src/encGroup.js
+1
-1
WW.spec.js
tests/WW.spec.js
+26
-3
No files found.
resources/workers/encWW.js
View file @
88aa6f05
let
ident
=
undefined
;
let
encoder
=
null
;
let
encoder
=
null
;
let
isInited
=
false
;
let
isInited
=
false
;
let
isBridged
=
false
;
let
isBridged
=
false
;
...
@@ -28,11 +29,10 @@ createParaEncoder().then(m => {
...
@@ -28,11 +29,10 @@ createParaEncoder().then(m => {
// Init
// Init
onmessage
=
async
e
=>
{
onmessage
=
async
e
=>
{
await
main
(
e
.
data
);
await
eventloop
(
e
.
data
);
}
}
async
function
main
(
msg
)
{
async
function
eventloop
(
msg
)
{
if
(
!
isEncGrpMsg
(
msg
))
return
;
if
(
!
isEncGrpMsg
(
msg
))
return
;
switch
(
typeOfMsg
(
msg
))
{
switch
(
typeOfMsg
(
msg
))
{
...
@@ -48,7 +48,7 @@ async function main(msg) {
...
@@ -48,7 +48,7 @@ async function main(msg) {
if
(
isBridged
)
await
deBridging
();
if
(
isBridged
)
await
deBridging
();
break
;
break
;
case
MESSAGE_TYPE
.
DATA
:
case
MESSAGE_TYPE
.
DATA
:
if
(
is
Inited
&&
is
Bridged
)
{
if
(
isBridged
)
{
await
steps
();
await
steps
();
}
}
break
;
break
;
...
@@ -71,6 +71,7 @@ async function bridging(msg) {
...
@@ -71,6 +71,7 @@ async function bridging(msg) {
}
}
bridge
=
new
Channel
(
info
.
size
,
SharedArrayBuffer
,
info
.
shm
);
bridge
=
new
Channel
(
info
.
size
,
SharedArrayBuffer
,
info
.
shm
);
postMessage
(
makeMsg
(
MESSAGE_TYPE
.
BRIDGE
,
{}));
isBridged
=
true
;
isBridged
=
true
;
}
}
...
@@ -82,6 +83,7 @@ async function deBridging() {
...
@@ -82,6 +83,7 @@ async function deBridging() {
async
function
init
(
msg
)
{
async
function
init
(
msg
)
{
let
info
=
getInfoFromMsg
(
msg
),
ret
;
let
info
=
getInfoFromMsg
(
msg
),
ret
;
src
=
new
Channel
(
info
.
size
,
SharedArrayBuffer
,
info
.
shm
);
src
=
new
Channel
(
info
.
size
,
SharedArrayBuffer
,
info
.
shm
);
ident
=
info
.
ident
;
// Wait encoder init
// Wait encoder init
while
(
encoder
==
null
)
while
(
encoder
==
null
)
...
@@ -131,10 +133,13 @@ async function steps() {
...
@@ -131,10 +133,13 @@ async function steps() {
if
(
await
step
()
===
false
)
{
if
(
await
step
()
===
false
)
{
await
sleep
(
SLEEP_INTERVAL
);
await
sleep
(
SLEEP_INTERVAL
);
timeout
-=
SLEEP_INTERVAL
;
timeout
-=
SLEEP_INTERVAL
;
}
else
{
timeout
=
SPIN_TIMEOUT
;
}
}
}
}
src
.
unsetPriv
(
PRIV_FLAGS
.
EXECUTING
);
src
.
unsetPriv
(
PRIV_FLAGS
.
EXECUTING
);
postMessage
(
makeMsg
(
MESSAGE_TYPE
.
DATA_REQUIRE
,
{
ident
:
ident
}))
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
...
...
resources/workers/muxWW.js
View file @
88aa6f05
// Status
// Status
let
ident
=
undefined
;
let
isInited
=
false
;
let
isInited
=
false
;
let
isBridged
=
false
;
let
isBridged
=
false
;
let
bridge
=
null
;
let
bridge
=
null
;
...
@@ -118,4 +119,6 @@ async function steps() {
...
@@ -118,4 +119,6 @@ async function steps() {
}
}
src
.
unsetPriv
(
MSG
.
PRIV_FLAGS
.
EXECUTING
);
src
.
unsetPriv
(
MSG
.
PRIV_FLAGS
.
EXECUTING
);
postMessage
(
makeMsg
(
MESSAGE_TYPE
.
DATA_REQUIRE
,
{}))
}
}
src/WW.js
View file @
88aa6f05
import
{
MESSAGE_TYPE
,
typeOfMsg
}
from
'./encGrooupMsg'
;
import
{
Observable
,
filter
}
from
'./rxjs'
;
import
{
Observable
,
filter
}
from
'./rxjs'
;
...
@@ -9,6 +10,13 @@ export class WWInitError extends Error {
...
@@ -9,6 +10,13 @@ export class WWInitError extends Error {
}
}
export
const
WW_STATE
=
Object
.
freeze
({
UNINITIALIZED
:
0
,
READY
:
1
,
RUNNING
:
2
,
});
export
class
WW
extends
Observable
{
export
class
WW
extends
Observable
{
#
ident
=
undefined
;
#
ident
=
undefined
;
...
@@ -18,7 +26,19 @@ export class WW extends Observable {
...
@@ -18,7 +26,19 @@ export class WW extends Observable {
#
ww
=
undefined
;
#
ww
=
undefined
;
#
connected
=
{};
#
connected
=
{};
#
remoteInited
=
false
;
#
remoteBridged
=
false
;
#
state
=
WW_STATE
.
UNINITIALIZED
;
constructor
(
name
,
path
)
{
constructor
(
name
,
path
)
{
if
(
typeof
(
name
)
!=
"string"
||
typeof
(
path
)
!=
"string"
)
{
throw
new
TypeError
(
"Mismatch arguments"
,
"WW.js"
);
}
super
(
subscriber
=>
{
super
(
subscriber
=>
{
this
.
#
ww
.
onmessage
=
this
.
#
ww
.
onmessage
=
e
=>
{
subscriber
.
next
(
e
.
data
);
};
e
=>
{
subscriber
.
next
(
e
.
data
);
};
...
@@ -26,6 +46,8 @@ export class WW extends Observable {
...
@@ -26,6 +46,8 @@ export class WW extends Observable {
this
.
#
ident
=
name
;
this
.
#
ident
=
name
;
this
.
#
ww
=
new
Worker
(
path
);
this
.
#
ww
=
new
Worker
(
path
);
this
.
#
monitor
();
}
}
async
start
(
initWork
)
{
async
start
(
initWork
)
{
...
@@ -85,9 +107,29 @@ export class WW extends Observable {
...
@@ -85,9 +107,29 @@ export class WW extends Observable {
return
this
.
#
ww
.
terminate
();
return
this
.
#
ww
.
terminate
();
}
}
monitor
()
{
getState
()
{
this
.
subscribe
(
msg
=>
{
return
this
.
#
state
;
}
// Enable status tracking for WW,
// status of WW will map to local variables.
#
monitor
()
{
this
.
subscribe
(
msg
=>
{
switch
(
typeOfMsg
(
msg
))
{
case
MESSAGE_TYPE
.
INIT
:
this
.
#
remoteInited
=
true
;
break
;
case
MESSAGE_TYPE
.
BRIDGE
:
this
.
#
remoteBridged
=
true
;
break
;
}
// Update State
if
(
this
.
#
remoteInited
&&
this
.
#
remoteBridged
)
{
this
.
#
state
=
WW_STATE
.
READY
;
}
});
});
}
}
}
}
src/encGrooupMsg.js
View file @
88aa6f05
...
@@ -42,8 +42,8 @@ export function makeMsg(type, info_) {
...
@@ -42,8 +42,8 @@ export function makeMsg(type, info_) {
return
{
type
:
type
,
info
:
info_
};
return
{
type
:
type
,
info
:
info_
};
}
}
export
function
makeInitMsg
(
shm
,
size
)
{
export
function
makeInitMsg
(
shm
,
size
,
ident
)
{
return
makeMsg
(
MESSAGE_TYPE
.
INIT
,
{
shm
:
shm
,
size
:
size
})
return
makeMsg
(
MESSAGE_TYPE
.
INIT
,
{
shm
:
shm
,
size
:
size
,
ident
:
ident
})
}
}
export
function
typeOfMsg
(
msg
)
{
export
function
typeOfMsg
(
msg
)
{
...
...
src/encGroup.js
View file @
88aa6f05
...
@@ -182,7 +182,7 @@ async function muxInit(chnls, ww) {
...
@@ -182,7 +182,7 @@ async function muxInit(chnls, ww) {
let
channel
=
new
Channel
(
Math
.
pow
(
2
,
20
));
let
channel
=
new
Channel
(
Math
.
pow
(
2
,
20
));
ww
.
postMessage
(
ww
.
postMessage
(
makeInitMsg
(
channel
.
getShMem
(),
Math
.
pow
(
2
,
20
)));
makeInitMsg
(
channel
.
getShMem
(),
Math
.
pow
(
2
,
20
)
,
ww
.
ident
()
));
chnls
[
ww
.
ident
()]
=
channel
;
chnls
[
ww
.
ident
()]
=
channel
;
return
true
;
return
true
;
...
...
tests/WW.spec.js
View file @
88aa6f05
import
{
WW
}
from
'../src/WW.js'
;
import
{
WW
,
WW_STATE
}
from
'../src/WW.js'
;
import
{
Channel
}
from
'../src/channel.js'
;
import
{
Channel
}
from
'../src/channel.js'
;
import
{
makeMsg
,
MESSAGE_TYPE
}
from
'../src/encGrooupMsg.js'
;
import
{
makeMsg
,
MESSAGE_TYPE
}
from
'../src/encGrooupMsg.js'
;
import
{
sleep
,
assert
}
from
'../src/utils.js'
;
import
{
sleep
,
assert
}
from
'../src/utils.js'
;
...
@@ -162,9 +162,32 @@ describe("EncWW Specifications", () => {
...
@@ -162,9 +162,32 @@ describe("EncWW Specifications", () => {
},
1000
);
},
1000
);
});
});
expect
(
ch2
.
dataSize
()).
toBe
(
26597
);
expect
(
ch2
.
dataSize
()).
toBe
(
26597
);
expect
(
ch2_
.
dataSize
()).
toBe
(
26597
);
expect
(
ch2_
.
dataSize
()).
toBe
(
26597
);
},
100000
);
},
100000
);
})
it
(
"Enc WW Spec"
,
async
()
=>
{
let
enc
=
new
WW
(
"ENC"
,
"../resources/workers/encWW.js"
);
let
mem
=
new
SharedArrayBuffer
(
1024
);
enc
.
postMessage
(
makeMsg
(
MESSAGE_TYPE
.
INIT
,
{
shm
:
mem
,
size
:
1024
,
ident
:
"ENC"
}));
let
memB
=
new
SharedArrayBuffer
(
1024
);
enc
.
postMessage
(
makeMsg
(
MESSAGE_TYPE
.
BRIDGE
,
{
shm
:
memB
,
size
:
1024
}));
await
sleep
(
500
);
expect
(
enc
.
getState
()
==
WW_STATE
.
READY
).
toBe
(
true
);
await
sleep
(
1000
);
});
fit
(
"Mux WW Spec"
,
async
()
=>
{
let
mux
=
new
WW
(
"MUX"
,
"../resources/workers/muxWW.js"
);
let
mem
=
new
SharedArrayBuffer
(
1024
);
mux
.
postMessage
(
makeMsg
(
MESSAGE_TYPE
.
INIT
,
{
shm
:
mem
,
size
:
1024
}));
await
sleep
(
1000
);
});
});
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