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
d0df74ad
Commit
d0df74ad
authored
Apr 18, 2022
by
Linshizhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
48f27d3b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
7 deletions
+86
-7
package-lock.json
package-lock.json
+29
-0
package.json
package.json
+4
-1
paraEncode.js
src/paraEncode.js
+35
-3
paraEncodeSpec.test.js
tests/paraEncodeSpec.test.js
+18
-3
No files found.
package-lock.json
View file @
d0df74ad
...
...
@@ -8,6 +8,9 @@
"name"
:
"paraencode"
,
"version"
:
"1.0.0"
,
"license"
:
"ISC"
,
"dependencies"
:
{
"rxjs"
:
"^7.5.5"
},
"devDependencies"
:
{
"@babel/core"
:
"^7.17.9"
,
"@babel/preset-env"
:
"^7.16.11"
,
...
...
@@ -4774,6 +4777,14 @@
"url"
:
"https://github.com/sponsors/isaacs"
}
},
"node_modules/rxjs"
:
{
"version"
:
"7.5.5"
,
"resolved"
:
"https://registry.npmjs.org/rxjs/-/rxjs-7.5.5.tgz"
,
"integrity"
:
"sha512-sy+H0pQofO95VDmFLzyaw9xNJU4KTRSwQIGM6+iG3SypAtCiLDzpeG8sJrNCWn2Up9km+KhkvTdbkrdy+yzZdw=="
,
"dependencies"
:
{
"tslib"
:
"^2.1.0"
}
},
"node_modules/safe-buffer"
:
{
"version"
:
"5.1.2"
,
"resolved"
:
"https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz"
,
...
...
@@ -5087,6 +5098,11 @@
"node"
:
">=8"
}
},
"node_modules/tslib"
:
{
"version"
:
"2.3.1"
,
"resolved"
:
"https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz"
,
"integrity"
:
"sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw=="
},
"node_modules/type-check"
:
{
"version"
:
"0.3.2"
,
"resolved"
:
"https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz"
,
...
...
@@ -8962,6 +8978,14 @@
"glob"
:
"^7.1.3"
}
},
"rxjs"
:
{
"version"
:
"7.5.5"
,
"resolved"
:
"https://registry.npmjs.org/rxjs/-/rxjs-7.5.5.tgz"
,
"integrity"
:
"sha512-sy+H0pQofO95VDmFLzyaw9xNJU4KTRSwQIGM6+iG3SypAtCiLDzpeG8sJrNCWn2Up9km+KhkvTdbkrdy+yzZdw=="
,
"requires"
:
{
"tslib"
:
"^2.1.0"
}
},
"safe-buffer"
:
{
"version"
:
"5.1.2"
,
"resolved"
:
"https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz"
,
...
...
@@ -9200,6 +9224,11 @@
"punycode"
:
"^2.1.1"
}
},
"tslib"
:
{
"version"
:
"2.3.1"
,
"resolved"
:
"https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz"
,
"integrity"
:
"sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw=="
},
"type-check"
:
{
"version"
:
"0.3.2"
,
"resolved"
:
"https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz"
,
...
...
package.json
View file @
d0df74ad
...
...
@@ -23,5 +23,8 @@
"FFMPEG"
],
"author"
:
"Linshizhi"
,
"license"
:
"
ISC
"
"license"
:
"
ISC
"
,
"dependencies"
:
{
"
rxjs
"
:
"^7.5.5"
}
}
src/paraEncode.js
View file @
d0df74ad
...
...
@@ -5,19 +5,51 @@ export let SUPPORT_CODECS = {
"h264"
:
0
};
export
const
ENCODE_MODE
=
Object
.
freeze
({
URGENT
:
Symbol
(
"URGENT"
),
SAVE_MEMORY
:
Symbol
(
"SAVEMEM"
),
});
/* ParaEncoder use number of threads specified by
* caller to encode RGB pictures into a video */
export
class
ParaEncoder
{
/* */
constructor
(
numOfTR
,
codec
)
{
constructor
(
numOfTR
,
codec
,
mode
)
{
assert
(
typeof
(
numOfTR
)
==
'number'
,
"typeof(numOfTR) == 'number' failed"
);
"typeof(n
umOfTR) == 'number' failed"
);
assert
(
typeof
(
codec
)
==
'string'
,
"typeof(codec) == 'number' failed"
);
for
(
let
encodeMode
in
ENCODE_MODE
)
{
assert
(
mode
!=
encodeMode
,
"INVALID ENCODE MODE"
);
}
this
.
numOfTR
=
numOfTR
;
this
.
codec
=
codec
;
this
.
mode
=
mode
;
}
/* Encode pixels into a video frame, pixels can be generated from
* WebGLRenderingContext.readPixels()
* details: https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/readPixels
*
* Pixels should be passed to worker thread */
encode
(
pixels
)
{
switch
(
this
.
mode
)
{
case
ENCODE_MODE
.
URGENT
:
return
this
.
#
encodeUrgent
(
pixels
);
break
;
case
ENCODE_MODE
.
SAVE_MEMORY
:
return
break
;
}
}
#
encodeUrgent
(
pixels
)
{
}
#
encodeSaveMem
(
pixels
)
{
}
}
tests/paraEncodeSpec.test.js
View file @
d0df74ad
import
{
ParaEncoder
}
from
"../src/paraEncode"
;
import
{
ParaEncoder
,
ENCODE_MODE
}
from
"../src/paraEncode"
;
let
dut
=
new
ParaEncoder
(
1
,
"h264"
,
ENCODE_MODE
.
SAVE_MEMORY
);
test
(
'ParaEncoder Normal Init'
,
()
=>
{
let
dut
=
new
ParaEncoder
(
1
,
"h264"
);
expect
(
dut
.
numOfTR
).
toBe
(
1
);
expect
(
dut
.
codec
).
toBe
(
"h264"
);
});
test
(
"ParaEncoder Invalid Init"
,
()
=>
{
try
{
new
ParaEncoder
(
1
,
1
);
new
ParaEncoder
(
1
,
1
,
ENCODE_MODE
.
SAVE_MEMORY
);
}
catch
(
err
)
{
expect
(
err
.
message
)
.
toBe
(
"typeof(codec) == 'number' failed"
);
}
})
test
(
"ParaEncoder Invalid encode mode"
,
()
=>
{
try
{
new
ParaEncoder
(
1
,
"h264"
,
Symbol
(
"URGENT"
));
}
catch
(
err
)
{
expect
(
err
.
message
)
.
toBe
(
"INVALID ENCODE MODE"
);
}
})
test
(
"Encode with ParaEncoder"
,
()
=>
{
let
pixels
=
new
Uint8Array
(
1920
*
1080
*
4
);
dut
.
encode
(
pixels
);
})
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