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
1ab8cca1
Commit
1ab8cca1
authored
Jan 10, 2023
by
Linshizhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add AudioEffecter as Builtins.
parent
8065f496
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
133 additions
and
16 deletions
+133
-16
builtins-definitions.h
src/builtins/builtins-definitions.h
+1
-0
builtins-encoder.cc
src/builtins/builtins-encoder.cc
+129
-15
bootstrapper.cc
src/init/bootstrapper.cc
+3
-1
No files found.
src/builtins/builtins-definitions.h
View file @
1ab8cca1
...
...
@@ -628,6 +628,7 @@ namespace internal {
CPP(Save) \
CPP(AddAudioBuffer) \
CPP(MergeMP4) \
CPP(ApplyAudioEffects) \
\
/* Web snapshots */
\
CPP(WebSnapshotSerialize) \
...
...
src/builtins/builtins-encoder.cc
View file @
1ab8cca1
...
...
@@ -17,16 +17,37 @@ char *audioPath;
void
*
loadedSyms
;
void
*
encoder
;
void
*
audioEffecter
;
///////////////////////////////////////////////////////////////////////////////
// Dynamic load procedures //
///////////////////////////////////////////////////////////////////////////////
// Video Encoder
void
*
(
*
spawnEncoder
)(
const
char
*
output
,
uint32_t
width
,
uint32_t
height
,
uint32_t
bitrate
,
int
fmt
,
int32_t
framerate
,
std
::
string
encoderName
);
const
char
*
encoderName
);
void
(
*
encoding
)(
void
*
encoder_
,
const
uint8_t
*
buff
,
int
length
);
bool
(
*
encoderFailed
)(
void
*
encoder_
);
void
(
*
closeEncoder
)(
void
*
encoder_
);
const
char
*
(
*
outputOfEncoder
)(
void
*
encoder_
);
// Audio Effecter
void
*
(
*
getAudioEffecter
)();
int
(
*
addInputFileAE
)(
void
*
effecter
,
const
char
*
filename
,
const
double
volume
,
const
double
strong_end_time
,
const
double
start_time
,
const
double
end_time
,
const
double
delay
,
const
double
duration
,
const
double
fade_out_duration
,
bool
isLoop
);
int
(
*
doTranscodingAE
)(
void
*
effecter
,
const
char
*
output
,
const
double
duration
);
int
(
*
isWeakAE
)(
void
*
effecter
);
void
(
*
removeInputsAE
)(
void
*
effecter
);
// AV Merger
void
*
(
*
spawnMerger
)(
const
char
*
output
,
const
char
*
videoPath
,
const
char
*
audioPath
);
void
(
*
merging
)(
void
*
merger_
);
}
BUILTIN
(
InitEncodeContext
)
{
...
...
@@ -39,8 +60,6 @@ BUILTIN(InitEncodeContext) {
printf
(
"Failed to load libencoder.so"
);
THROW_NEW_ERROR_RETURN_FAILURE
(
isolate
,
NewEvalError
(
MessageTemplate
::
kInvalidArgument
));
}
else
{
printf
(
"libencoder.so loaded
\n
"
);
}
spawnEncoder
=
reinterpret_cast
<
decltype
(
spawnEncoder
)
>
(
dlsym
(
loadedSyms
,
"spawnEncoder"
));
...
...
@@ -48,49 +67,77 @@ BUILTIN(InitEncodeContext) {
THROW_NEW_ERROR_RETURN_FAILURE
(
isolate
,
NewEvalError
(
MessageTemplate
::
kInvalidArgument
));
}
printf
(
"spawnEncoder loaded
\n
"
);
encoding
=
reinterpret_cast
<
decltype
(
encoding
)
>
(
dlsym
(
loadedSyms
,
"encoding"
));
if
(
encoding
==
NULL
)
{
THROW_NEW_ERROR_RETURN_FAILURE
(
isolate
,
NewEvalError
(
MessageTemplate
::
kInvalidArgument
));
}
printf
(
"encoding loaded
\n
"
);
encoderFailed
=
reinterpret_cast
<
decltype
(
encoderFailed
)
>
(
dlsym
(
loadedSyms
,
"encoderFailed"
));
if
(
encoderFailed
==
NULL
)
{
THROW_NEW_ERROR_RETURN_FAILURE
(
isolate
,
NewEvalError
(
MessageTemplate
::
kInvalidArgument
));
}
printf
(
"encoderFailed loaded
\n
"
);
closeEncoder
=
reinterpret_cast
<
decltype
(
closeEncoder
)
>
(
dlsym
(
loadedSyms
,
"closeEncoder"
));
if
(
closeEncoder
==
NULL
)
{
THROW_NEW_ERROR_RETURN_FAILURE
(
isolate
,
NewEvalError
(
MessageTemplate
::
kInvalidArgument
));
}
printf
(
"closeEncoder loaded
\n
"
);
outputOfEncoder
=
reinterpret_cast
<
decltype
(
outputOfEncoder
)
>
(
dlsym
(
loadedSyms
,
"outputOfEncoder"
));
if
(
outputOfEncoder
==
NULL
)
{
THROW_NEW_ERROR_RETURN_FAILURE
(
isolate
,
NewEvalError
(
MessageTemplate
::
kInvalidArgument
));
}
printf
(
"outputOfEncoder loaded
\n
"
);
spawnMerger
=
reinterpret_cast
<
decltype
(
spawnMerger
)
>
(
dlsym
(
loadedSyms
,
"spawnMerger"
));
if
(
spawnMerger
==
NULL
)
{
THROW_NEW_ERROR_RETURN_FAILURE
(
isolate
,
NewEvalError
(
MessageTemplate
::
kInvalidArgument
));
}
printf
(
"spawnMerger loaded
\n
"
);
merging
=
reinterpret_cast
<
decltype
(
merging
)
>
(
dlsym
(
loadedSyms
,
"merging"
));
if
(
merging
==
NULL
)
{
THROW_NEW_ERROR_RETURN_FAILURE
(
isolate
,
NewEvalError
(
MessageTemplate
::
kInvalidArgument
));
}
printf
(
"merging loaded
\n
"
);
getAudioEffecter
=
reinterpret_cast
<
decltype
(
getAudioEffecter
)
>
(
dlsym
(
loadedSyms
,
"getAudioEffecter"
));
if
(
getAudioEffecter
==
NULL
)
{
THROW_NEW_ERROR_RETURN_FAILURE
(
isolate
,
NewEvalError
(
MessageTemplate
::
kInvalidArgument
));
}
addInputFileAE
=
reinterpret_cast
<
decltype
(
addInputFileAE
)
>
(
dlsym
(
loadedSyms
,
"addInputFileAE"
));
if
(
addInputFileAE
==
NULL
)
{
THROW_NEW_ERROR_RETURN_FAILURE
(
isolate
,
NewEvalError
(
MessageTemplate
::
kInvalidArgument
));
}
doTranscodingAE
=
reinterpret_cast
<
decltype
(
doTranscodingAE
)
>
(
dlsym
(
loadedSyms
,
"doTranscodingAE"
));
if
(
doTranscodingAE
==
NULL
)
{
THROW_NEW_ERROR_RETURN_FAILURE
(
isolate
,
NewEvalError
(
MessageTemplate
::
kInvalidArgument
));
}
isWeakAE
=
reinterpret_cast
<
decltype
(
isWeakAE
)
>
(
dlsym
(
loadedSyms
,
"isWeakAE"
));
if
(
isWeakAE
==
NULL
)
{
THROW_NEW_ERROR_RETURN_FAILURE
(
isolate
,
NewEvalError
(
MessageTemplate
::
kInvalidArgument
));
}
removeInputsAE
=
reinterpret_cast
<
decltype
(
removeInputsAE
)
>
(
dlsym
(
loadedSyms
,
"removeInputsAE"
));
if
(
removeInputsAE
==
NULL
)
{
THROW_NEW_ERROR_RETURN_FAILURE
(
isolate
,
NewEvalError
(
MessageTemplate
::
kInvalidArgument
));
}
}
// Width
...
...
@@ -217,6 +264,8 @@ BUILTIN(Close) {
encoder
=
nullptr
;
inited
=
false
;
removeInputsAE
(
audioEffecter
);
return
*
isolate
->
factory
()
->
ToBoolean
(
true
);
}
...
...
@@ -296,7 +345,6 @@ BUILTIN(Save) {
BUILTIN
(
AddAudioBuffer
)
{
HandleScope
scope
(
isolate
);
Handle
<
Object
>
audioBuffer
=
args
.
atOrUndefined
(
isolate
,
1
);
if
(
audioBuffer
->
IsUndefined
()
||
audioBuffer
->
IsNull
())
{
return
ReadOnlyRoots
(
isolate
).
undefined_value
();
...
...
@@ -306,6 +354,7 @@ BUILTIN(AddAudioBuffer) {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION
(
isolate
,
array
,
JSTypedArray
::
Validate
(
isolate
,
args
.
atOrUndefined
(
isolate
,
1
),
"ENCODER.encode()"
));
// Write Buffer into file system
Handle
<
JSArrayBuffer
>
arrayBuffer
=
array
->
GetBuffer
();
std
::
shared_ptr
<
BackingStore
>
store
=
arrayBuffer
->
GetBackingStore
();
...
...
@@ -315,15 +364,80 @@ BUILTIN(AddAudioBuffer) {
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
();
// Add audio file into AudioEffecter
Handle
<
Object
>
volume
=
args
.
atOrUndefined
(
isolate
,
2
);
Handle
<
Object
>
strong_end_time
=
args
.
atOrUndefined
(
isolate
,
3
);
Handle
<
Object
>
start_time
=
args
.
atOrUndefined
(
isolate
,
4
);
Handle
<
Object
>
end_time
=
args
.
atOrUndefined
(
isolate
,
5
);
Handle
<
Object
>
delay
=
args
.
atOrUndefined
(
isolate
,
6
);
Handle
<
Object
>
duration
=
args
.
atOrUndefined
(
isolate
,
7
);
Handle
<
Object
>
fade_out_duration
=
args
.
atOrUndefined
(
isolate
,
8
);
Handle
<
Object
>
isLoop
=
args
.
atOrUndefined
(
isolate
,
9
);
if
(
!
volume
->
IsNumber
()
||
!
strong_end_time
->
IsNumber
()
||
!
start_time
->
IsNumber
()
||
!
end_time
->
IsNumber
()
||
!
delay
->
IsNumber
()
||
!
duration
->
IsNumber
()
||
!
fade_out_duration
->
IsNumber
()
||
!
isLoop
->
IsNumber
())
{
THROW_NEW_ERROR_RETURN_FAILURE
(
isolate
,
NewTypeError
(
MessageTemplate
::
kInvalidArgument
));
}
double
volume_
,
strong_end_time_
,
start_time_
,
end_time_
,
delay_
,
duration_
,
fade_out_duration_
,
isLoop_
;
volume_
=
volume
->
Number
();
strong_end_time_
=
strong_end_time
->
Number
();
start_time_
=
start_time
->
Number
();
end_time_
=
end_time
->
Number
();
delay_
=
delay
->
Number
();
duration_
=
duration
->
Number
();
fade_out_duration_
=
fade_out_duration
->
Number
();
isLoop_
=
isLoop
->
Number
();
if
(
audioEffecter
==
NULL
)
{
audioEffecter
=
getAudioEffecter
();
if
(
audioEffecter
==
NULL
)
{
THROW_NEW_ERROR_RETURN_FAILURE
(
isolate
,
NewEvalError
(
MessageTemplate
::
kInvalidArgument
));
}
}
bool
isLoop_bool
=
isLoop_
==
1
;
int
ret
=
addInputFileAE
(
audioEffecter
,
outpath
.
c_str
(),
volume_
,
strong_end_time_
,
start_time_
,
end_time_
,
delay_
,
duration_
,
fade_out_duration_
,
isLoop_bool
);
return
*
isolate
->
factory
()
->
ToBoolean
(
ret
==
0
);
}
BUILTIN
(
ApplyAudioEffects
)
{
HandleScope
scope
(
isolate
);
Handle
<
Object
>
duration
=
args
.
atOrUndefined
(
isolate
,
1
);
if
(
!
duration
->
IsNumber
())
{
THROW_NEW_ERROR_RETURN_FAILURE
(
isolate
,
NewTypeError
(
MessageTemplate
::
kInvalidArgument
));
}
uint32_t
duration_
;
duration
->
ToUint32
(
&
duration_
);
std
::
string
outpath
=
std
::
tmpnam
(
nullptr
);
outpath
+=
".aac"
;
printf
(
"Outputpath is %s, Duration is %d
\n
"
,
outpath
.
c_str
(),
duration_
);
int
ret
=
doTranscodingAE
(
audioEffecter
,
outpath
.
c_str
(),
duration_
);
if
(
ret
==
0
)
{
audioPath
=
strdup
(
outpath
.
c_str
());
}
return
*
isolate
->
factory
()
->
ToBoolean
(
ret
==
0
);
}
BUILTIN
(
MergeMP4
)
{
...
...
src/init/bootstrapper.cc
View file @
1ab8cca1
...
...
@@ -2805,9 +2805,11 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
SimpleInstallFunction
(
isolate_
,
mp4
,
"save"
,
Builtin
::
kSave
,
2
,
true
);
SimpleInstallFunction
(
isolate_
,
mp4
,
"addAudioBuffer"
,
Builtin
::
kAddAudioBuffer
,
1
,
true
);
Builtin
::
kAddAudioBuffer
,
9
,
true
);
SimpleInstallFunction
(
isolate_
,
mp4
,
"mergeMP4"
,
Builtin
::
kMergeMP4
,
2
,
true
);
SimpleInstallFunction
(
isolate_
,
mp4
,
"applyAudioEffects"
,
Builtin
::
kApplyAudioEffects
,
1
,
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