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
e7062267
Commit
e7062267
authored
Dec 09, 2022
by
Linshizhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new api: addaudioBuffer and mergeMP4.
parent
a39b6827
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
82 additions
and
3 deletions
+82
-3
.gitmodules
.gitmodules
+6
-0
encoder
extensions/encoder
+1
-1
loadablemodule
extensions/loadablemodule
+1
-0
builtins-definitions.h
src/builtins/builtins-definitions.h
+2
-0
builtins-encoder.cc
src/builtins/builtins-encoder.cc
+68
-2
bootstrapper.cc
src/init/bootstrapper.cc
+4
-0
No files found.
.gitmodules
View file @
e7062267
...
...
@@ -2,3 +2,9 @@
path = extensions/loadablemodule
url = git@gitlab.laihua.com:linshizhi/loadablemodule.git
branch = main
[submodule "extensions/--force"]
path = extensions/--force
url = git@gitlab.laihua.com:linshizhi/encoder.git
[submodule "extensions/encoder"]
path = extensions/encoder
url = git@gitlab.laihua.com:linshizhi/encoder.git
encoder
@
d7cbcc5a
Subproject commit
acf7b7681996005565b9633d99ea9a69d248eb12
Subproject commit
d7cbcc5acfbb09311ca09ec74dd1bf40ad685fa5
loadablemodule
@
7123dbdb
Subproject commit 7123dbdba735a1b43bfd586e2110e25bcdaab9ed
src/builtins/builtins-definitions.h
View file @
e7062267
...
...
@@ -626,6 +626,8 @@ namespace internal {
CPP(Close) \
CPP(GetVideo) \
CPP(Save) \
CPP(AddAudioBuffer) \
CPP(MergeMP4) \
\
/* Web snapshots */
\
CPP(WebSnapshotSerialize) \
...
...
src/builtins/builtins-encoder.cc
View file @
e7062267
...
...
@@ -15,6 +15,7 @@ namespace internal {
namespace
{
bool
inited
=
false
;
LAIPIC_ENCODER
::
Encoder
*
enc
;
char
*
audioPath
;
}
BUILTIN
(
InitEncodeContext
)
{
...
...
@@ -140,6 +141,7 @@ BUILTIN(Close) {
return
*
isolate
->
factory
()
->
ToBoolean
(
true
);
}
std
::
remove
(
enc
->
getOutputPath
().
c_str
());
enc
->
close
();
enc
=
nullptr
;
inited
=
false
;
...
...
@@ -174,8 +176,6 @@ BUILTIN(GetVideo) {
videoFile
.
read
(
buffer
,
fileLength
);
videoFile
.
close
();
std
::
remove
(
enc
->
getOutputPath
().
c_str
());
return
*
videoContent
;
}
...
...
@@ -222,6 +222,72 @@ BUILTIN(Save) {
return
*
isolate
->
factory
()
->
ToBoolean
(
true
);
}
BUILTIN
(
AddAudioBuffer
)
{
HandleScope
scope
(
isolate
);
Handle
<
JSTypedArray
>
array
;
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
());
std
::
string
outpath
=
std
::
tmpnam
(
nullptr
);
outpath
+=
".aac"
;
audioPath
=
strdup
(
outpath
.
c_str
());
std
::
ofstream
audioFile
{
outpath
};
audioFile
.
write
(
reinterpret_cast
<
char
*>
(
buffer
),
bufferLen
);
audioFile
.
close
();
return
ReadOnlyRoots
(
isolate
).
undefined_value
();
}
BUILTIN
(
MergeMP4
)
{
HandleScope
scope
(
isolate
);
Handle
<
Object
>
libpath
=
args
.
atOrUndefined
(
isolate
,
1
);
// Libav path
std
::
string
libpath_cppstr
;
if
(
libpath
->
IsUndefined
())
{
libpath_cppstr
=
""
;
}
else
{
Handle
<
String
>
libpath_str
;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION
(
isolate
,
libpath_str
,
Object
::
ToString
(
isolate
,
libpath
));
libpath_cppstr
=
libpath_str
->
ToCString
().
get
();
}
Handle
<
Object
>
outpath
=
args
.
atOrUndefined
(
isolate
,
2
);
std
::
string
outpath_cppstr
;
if
(
outpath
->
IsUndefined
())
{
outpath_cppstr
=
std
::
tmpnam
(
nullptr
);
outpath_cppstr
+=
".mp4"
;
}
else
{
Handle
<
String
>
outpath_str
;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION
(
isolate
,
outpath_str
,
Object
::
ToString
(
isolate
,
outpath
));
outpath_cppstr
=
outpath_str
->
ToCString
().
get
();
}
LAIPIC_ENCODER
::
AVMerger
merger
(
libpath_cppstr
,
outpath_cppstr
,
enc
->
getOutputPath
(),
audioPath
);
merger
.
merge
();
std
::
remove
(
audioPath
);
Handle
<
String
>
mergepath
=
isolate
->
factory
()
->
NewStringFromAsciiChecked
(
outpath_cppstr
.
c_str
());
free
(
audioPath
);
audioPath
=
nullptr
;
return
*
mergepath
;
}
}
// internal
}
// v8
src/init/bootstrapper.cc
View file @
e7062267
...
...
@@ -2804,6 +2804,10 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Builtin
::
kGetVideo
,
0
,
true
);
SimpleInstallFunction
(
isolate_
,
mp4
,
"save"
,
Builtin
::
kSave
,
2
,
true
);
SimpleInstallFunction
(
isolate_
,
mp4
,
"addAudioBuffer"
,
Builtin
::
kAddAudioBuffer
,
1
,
true
);
SimpleInstallFunction
(
isolate_
,
mp4
,
"mergeMP4"
,
Builtin
::
kMergeMP4
,
2
,
true
);
InstallToStringTag
(
isolate_
,
media_codex
,
"MediaCodex"
);
}
...
...
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