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
6f9e2c8e
Commit
6f9e2c8e
authored
Apr 29, 2022
by
NzSN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new spec and Channel update.
parent
c04fa8c0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
11 deletions
+58
-11
karma.conf.js
karma.conf.js
+0
-4
encWW.js
resources/workers/encWW.js
+1
-3
channel.js
src/channel.js
+4
-4
WW.spec.js
tests/WW.spec.js
+53
-0
No files found.
karma.conf.js
View file @
6f9e2c8e
// Karma configuration
// Karma configuration
// Generated on Tue Apr 19 2022 21:54:47 GMT+0800 (China Standard Time)
// Generated on Tue Apr 19 2022 21:54:47 GMT+0800 (China Standard Time)
let
webpackConfig
=
require
(
'./webpack.tdd.conf.js'
);
const
path
=
require
(
'path'
);
function
CrossOriginIsolationMiddlewareFactory
(
config
)
{
function
CrossOriginIsolationMiddlewareFactory
(
config
)
{
return
function
crossOriginIsolation
(
req
,
res
,
next
)
{
return
function
crossOriginIsolation
(
req
,
res
,
next
)
{
res
.
setHeader
(
'Cross-Origin-Opener-Policy'
,
'same-origin'
);
res
.
setHeader
(
'Cross-Origin-Opener-Policy'
,
'same-origin'
);
...
...
resources/workers/encWW.js
View file @
6f9e2c8e
...
@@ -17,13 +17,11 @@ const SPIN_TIMEOUT = 500;
...
@@ -17,13 +17,11 @@ const SPIN_TIMEOUT = 500;
const
ENC_BUF_SIZE
=
RGBFrameSize
*
10
const
ENC_BUF_SIZE
=
RGBFrameSize
*
10
let
encBuf
=
null
;
let
encBuf
=
null
;
// Read H264 Encode Group definitions
// Read H264 Encode Group definitions
self
.
importScripts
(
'defs.js'
);
self
.
importScripts
(
'defs.js'
);
// Load wasm encoder
// Load wasm encoder
self
.
importScripts
(
'
./
mp4encoder.js'
);
self
.
importScripts
(
'mp4encoder.js'
);
createMP4Encoder
().
then
(
m
=>
{
createMP4Encoder
().
then
(
m
=>
{
encoder
=
m
;
encoder
=
m
;
});
});
...
...
src/channel.js
View file @
6f9e2c8e
...
@@ -186,7 +186,7 @@ export class Channel {
...
@@ -186,7 +186,7 @@ export class Channel {
return
new
Uint8Array
(
0
);
return
new
Uint8Array
(
0
);
}
else
if
(
this
.
#
readPointerCache
<
writePos
)
{
}
else
if
(
this
.
#
readPointerCache
<
writePos
)
{
readTo
=
this
.
#
readPointerCache
+
Math
.
min
(
size
,
writePos
-
this
.
#
readPointerCache
);
readTo
=
this
.
#
readPointerCache
+
Math
.
min
(
size
,
writePos
-
this
.
#
readPointerCache
);
readBuffer
=
this
.
#
buffer
.
s
lice
(
this
.
#
readPointerCache
,
readTo
);
readBuffer
=
this
.
#
buffer
.
s
ubarray
(
this
.
#
readPointerCache
,
readTo
);
this
.
#
readPointerUpdate
(
readTo
);
this
.
#
readPointerUpdate
(
readTo
);
}
else
{
}
else
{
// To make sure
// To make sure
...
@@ -197,13 +197,13 @@ export class Channel {
...
@@ -197,13 +197,13 @@ export class Channel {
readBuffer
=
new
Uint8Array
(
firstRSize
+
secondRSize
);
readBuffer
=
new
Uint8Array
(
firstRSize
+
secondRSize
);
// First read
// First read
readBuffer
.
set
(
this
.
#
buffer
.
s
lice
(
readBuffer
.
set
(
this
.
#
buffer
.
s
ubarray
(
this
.
#
readPointerCache
,
this
.
#
readPointerCache
+
firstRSize
),
0
);
this
.
#
readPointerCache
,
this
.
#
readPointerCache
+
firstRSize
),
0
);
// Second Read
// Second Read
if
(
secondRSize
>
0
)
{
if
(
secondRSize
>
0
)
{
readBuffer
.
set
(
readBuffer
.
set
(
this
.
#
buffer
.
s
lice
(
this
.
#
metaSize
,
this
.
#
metaSize
+
secondRSize
),
this
.
#
buffer
.
s
ubarray
(
this
.
#
metaSize
,
this
.
#
metaSize
+
secondRSize
),
firstRSize
);
firstRSize
);
this
.
#
readPointerUpdate
(
this
.
#
metaSize
+
secondRSize
);
this
.
#
readPointerUpdate
(
this
.
#
metaSize
+
secondRSize
);
}
else
{
}
else
{
...
@@ -239,7 +239,7 @@ export class Channel {
...
@@ -239,7 +239,7 @@ export class Channel {
if
(
plan
.
size
==
0
)
if
(
plan
.
size
==
0
)
continue
;
continue
;
let
d_
=
data
.
s
lice
(
srcPos
,
srcPos
+
plan
.
size
);
let
d_
=
data
.
s
ubarray
(
srcPos
,
srcPos
+
plan
.
size
);
this
.
#
buffer
.
set
(
d_
,
plan
.
pos
);
this
.
#
buffer
.
set
(
d_
,
plan
.
pos
);
srcPos
+=
plan
.
size
;
srcPos
+=
plan
.
size
;
writePos
=
plan
.
pos
+
plan
.
size
;
writePos
=
plan
.
pos
+
plan
.
size
;
...
...
tests/WW.spec.js
View file @
6f9e2c8e
import
{
WW
}
from
'../src/WW.js'
;
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'
;
// For Webpack 5
// For Webpack 5
let
url
=
'../resources/tests/worker.js'
;
let
url
=
'../resources/tests/worker.js'
;
...
@@ -80,3 +83,53 @@ describe("WW Spec", () => {
...
@@ -80,3 +83,53 @@ describe("WW Spec", () => {
});
});
});
});
describe
(
"EncWW Specifications"
,
()
=>
{
it
(
"Handle RGBA Frames"
,
async
()
=>
{
let
encoder
=
new
WW
(
'encoder'
,
'../resources/workers/encWW.js'
);
let
frameSize
=
1920
*
1080
*
4
;
let
numOfFrames
=
10
;
// Create a Shared memory which able to contain
// 8 RGBA Frames.
let
size
=
frameSize
*
numOfFrames
;
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
encoder
.
postMessage
(
makeMsg
(
MESSAGE_TYPE
.
BRIDGE
,
{
shm
:
bridgeMem
,
size
:
size
}));
await
sleep
(
1000
);
// 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
,
{}));
}
// Send eof
encoder
.
postMessage
(
makeMsg
(
MESSAGE_TYPE
.
EOF
,
{}));
await
new
Promise
(
r
=>
{
let
intvl
=
setInterval
(()
=>
{
if
(
ch2
.
dataSize
()
>=
17167
)
{
clearInterval
(
intvl
);
r
();
}
},
100
);
});
expect
(
ch2
.
dataSize
()).
toBe
(
17167
);
},
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