Commit 4aa5018c authored by Linshizhi's avatar Linshizhi

Stage

parent 1ab8cca1
...@@ -629,6 +629,7 @@ namespace internal { ...@@ -629,6 +629,7 @@ namespace internal {
CPP(AddAudioBuffer) \ CPP(AddAudioBuffer) \
CPP(MergeMP4) \ CPP(MergeMP4) \
CPP(ApplyAudioEffects) \ CPP(ApplyAudioEffects) \
CPP(AddAudioURL) \
\ \
/* Web snapshots */ \ /* Web snapshots */ \
CPP(WebSnapshotSerialize) \ CPP(WebSnapshotSerialize) \
......
...@@ -18,6 +18,7 @@ char *audioPath; ...@@ -18,6 +18,7 @@ char *audioPath;
void *loadedSyms; void *loadedSyms;
void *encoder; void *encoder;
void *audioEffecter; void *audioEffecter;
void *resourcer;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Dynamic load procedures // // Dynamic load procedures //
...@@ -48,6 +49,10 @@ void (*removeInputsAE)(void *effecter); ...@@ -48,6 +49,10 @@ void (*removeInputsAE)(void *effecter);
void* (*spawnMerger)(const char *output, const char *videoPath, const char *audioPath); void* (*spawnMerger)(const char *output, const char *videoPath, const char *audioPath);
void (*merging)(void *merger_); void (*merging)(void *merger_);
// Resourcer
void* (*getResourcer)();
int (*fetchRe)(void *resourcer, const char *url, const char *fsPath);
} }
BUILTIN(InitEncodeContext) { BUILTIN(InitEncodeContext) {
...@@ -138,6 +143,20 @@ BUILTIN(InitEncodeContext) { ...@@ -138,6 +143,20 @@ BUILTIN(InitEncodeContext) {
THROW_NEW_ERROR_RETURN_FAILURE( THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewEvalError(MessageTemplate::kInvalidArgument)); isolate, NewEvalError(MessageTemplate::kInvalidArgument));
} }
getResourcer = reinterpret_cast<decltype(getResourcer)>(
dlsym(loadedSyms, "getResourcer"));
if (getResourcer == NULL) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewEvalError(MessageTemplate::kInvalidArgument));
}
fetchRe = reinterpret_cast<decltype(fetchRe)>(
dlsym(loadedSyms, "fetchRe"));
if (fetchRe == NULL) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewEvalError(MessageTemplate::kInvalidArgument));
}
} }
// Width // Width
...@@ -342,6 +361,75 @@ BUILTIN(Save) { ...@@ -342,6 +361,75 @@ BUILTIN(Save) {
return *isolate->factory()->ToBoolean(true); return *isolate->factory()->ToBoolean(true);
} }
BUILTIN(AddAudioURL) {
HandleScope scope(isolate);
Handle<Object> url = args.atOrUndefined(isolate, 1);
Handle<String> url_str;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, url_str, Object::ToString(isolate, url));
std::string url_cppstr = url_str->ToCString().get();
std::string outpath = std::tmpnam(nullptr);
outpath += ".aac";
// 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;
addInputFileAE(audioEffecter, outpath.c_str(), volume_, strong_end_time_, start_time_,
end_time_, delay_, duration_, fade_out_duration_, isLoop_bool);
if (resourcer == NULL) {
resourcer = getResourcer();
}
int errorCode = fetchRe(resourcer, url_cppstr.c_str(), outpath.c_str());
return *isolate->factory()->NewNumberFromInt(errorCode);
}
BUILTIN(AddAudioBuffer) { BUILTIN(AddAudioBuffer) {
HandleScope scope(isolate); HandleScope scope(isolate);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment