Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
V
V8
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
V8
Commits
f27efcaf
Commit
f27efcaf
authored
Oct 14, 2022
by
Linshizhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement global object ENCODER.
parent
b85121b5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
11 deletions
+93
-11
builtins-definitions.h
src/builtins/builtins-definitions.h
+1
-0
builtins-encoder.cc
src/builtins/builtins-encoder.cc
+88
-9
bootstrapper.cc
src/init/bootstrapper.cc
+4
-2
No files found.
src/builtins/builtins-definitions.h
View file @
f27efcaf
...
...
@@ -623,6 +623,7 @@ namespace internal {
/* ENCODER */
\
CPP(InitEncodeContext) \
CPP(Encode) \
CPP(Close) \
\
/* Web snapshots */
\
CPP(WebSnapshotSerialize) \
...
...
src/builtins/builtins-encoder.cc
View file @
f27efcaf
#include <stdio.h>
#include <iostream>
#include "src/execution/isolate.h"
#include "extensions/encoder/src/encoder.h"
#include "src/builtins/builtins.h"
#include "src/builtins/builtins-utils-inl.h"
...
...
@@ -8,23 +11,61 @@
namespace
v8
{
namespace
internal
{
namespace
{
bool
inited
=
false
;
LAIPIC_ENCODER
::
Encoder
*
enc
;
}
BUILTIN
(
InitEncodeContext
)
{
HandleScope
scope
(
isolate
);
// Output path
Handle
<
Object
>
path
=
args
.
atOrUndefined
(
isolate
,
1
);
Handle
<
String
>
string
;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION
(
isolate
,
string
,
// Width
Handle
<
Object
>
width
=
args
.
atOrUndefined
(
isolate
,
2
);
// Height
Handle
<
Object
>
height
=
args
.
atOrUndefined
(
isolate
,
3
);
// Bitrate
Handle
<
Object
>
bitrate
=
args
.
atOrUndefined
(
isolate
,
4
);
// Framerate
Handle
<
Object
>
framerate
=
args
.
atOrUndefined
(
isolate
,
5
);
// Maybe an Encoder already exists.
if
(
inited
)
return
*
isolate
->
factory
()
->
ToBoolean
(
true
);
// Argument check
if
(
!
path
->
IsString
()
||
!
width
->
IsNumber
()
||
!
height
->
IsNumber
()
||
!
bitrate
->
IsNumber
()
||
!
framerate
->
IsNumber
())
{
THROW_NEW_ERROR_RETURN_FAILURE
(
isolate
,
NewTypeError
(
MessageTemplate
::
kInvalidArgument
));
}
// Convert to C/C++ type
Handle
<
String
>
path_str
;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION
(
isolate
,
path_str
,
Object
::
ToString
(
isolate
,
path
));
LAIPIC_ENCODER
::
Encoder
enc
{
""
,
"/tmp/video.mp4"
,
1920
,
1080
,
60000
};
std
::
string
outpath
{
path_str
->
ToCString
().
get
()
};
uint32_t
width_int
,
height_int
,
bitrate_int
,
framerate_int
;
width
->
ToUint32
(
&
width_int
);
height
->
ToUint32
(
&
height_int
);
bitrate
->
ToUint32
(
&
bitrate_int
);
framerate
->
ToUint32
(
&
framerate_int
);
printf
(
"Encoder
\n
"
);
if
(
!
path
->
IsString
())
{
// Argument check
}
if
(
inited
)
return
*
isolate
->
factory
()
->
ToBoolean
(
true
);
enc
=
new
LAIPIC_ENCODER
::
Encoder
{
""
,
outpath
,
width_int
,
width_int
,
bitrate_int
,
};
if
(
!
enc
->
isReady
())
{
THROW_NEW_ERROR_RETURN_FAILURE
(
isolate
,
NewEvalError
(
MessageTemplate
::
kInvalidArgument
));
}
inited
=
true
;
...
...
@@ -33,10 +74,48 @@ BUILTIN(InitEncodeContext) {
BUILTIN
(
Encode
)
{
HandleScope
scope
(
isolate
);
//Handle<Object> frame = args.atOrUndefined(isolate, 1);
if
(
!
inited
)
return
*
isolate
->
factory
()
->
ToBoolean
(
false
);
Handle
<
JSTypedArray
>
array
;
// = Handle<JSTypedArray>::cast(frame);
ASSIGN_RETURN_FAILURE_ON_EXCEPTION
(
isolate
,
array
,
JSTypedArray
::
Validate
(
isolate
,
args
.
atOrUndefined
(
isolate
,
1
),
"ENCODER.encode()"
));
Handle
<
JSArrayBuffer
>
arrayBuffer
=
array
->
GetBuffer
();
std
::
shared_ptr
<
BackingStore
>
store
=
arrayBuffer
->
GetBackingStore
();
uint8_t
*
buffer
=
(
uint8_t
*
)
store
->
buffer_start
();
int
bufferLen
=
static_cast
<
int
>
(
store
->
byte_length
());
if
(
bufferLen
<=
0
)
{
// Operation of encodeing a zero length frame treat
// as a valid operation.
return
*
isolate
->
factory
()
->
ToBoolean
(
true
);
}
enc
->
encodeRGB
(
buffer
,
bufferLen
);
if
(
!
enc
->
isReady
())
{
// Encoder fall into unready stat which
// means there is something wrong happens during
// during encodeing.
THROW_NEW_ERROR_RETURN_FAILURE
(
isolate
,
NewEvalError
(
MessageTemplate
::
kInvalid
));
}
return
*
isolate
->
factory
()
->
ToBoolean
(
true
);
}
BUILTIN
(
Close
)
{
HandleScope
scope
(
isolate
);
printf
(
"Encoding...
\n
"
);
if
(
!
inited
)
{
return
*
isolate
->
factory
()
->
ToBoolean
(
true
);
}
enc
->
close
();
enc
=
nullptr
;
inited
=
false
;
return
*
isolate
->
factory
()
->
ToBoolean
(
true
);
}
...
...
src/init/bootstrapper.cc
View file @
f27efcaf
...
...
@@ -2791,9 +2791,11 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
factory
->
NewJSObject
(
isolate_
->
object_function
(),
AllocationType
::
kOld
);
JSObject
::
AddProperty
(
isolate_
,
global
,
"ENCODER"
,
encoder
,
DONT_ENUM
);
SimpleInstallFunction
(
isolate_
,
encoder
,
"init"
,
Builtin
::
kInitEncodeContext
,
1
,
true
);
Builtin
::
kInitEncodeContext
,
5
,
true
);
SimpleInstallFunction
(
isolate_
,
encoder
,
"encode"
,
Builtin
::
kEncode
,
0
,
true
);
Builtin
::
kEncode
,
1
,
true
);
SimpleInstallFunction
(
isolate_
,
encoder
,
"close"
,
Builtin
::
kClose
,
0
,
true
);
InstallToStringTag
(
isolate_
,
encoder
,
"ENCODER"
);
}
...
...
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