Commit d0b1a151 authored by Linshizhi's avatar Linshizhi

Add libpath argument.

parent 585fc8af
...@@ -27,6 +27,8 @@ BUILTIN(InitEncodeContext) { ...@@ -27,6 +27,8 @@ BUILTIN(InitEncodeContext) {
Handle<Object> bitrate = args.atOrUndefined(isolate, 4); Handle<Object> bitrate = args.atOrUndefined(isolate, 4);
// Framerate // Framerate
Handle<Object> framerate = args.atOrUndefined(isolate, 5); Handle<Object> framerate = args.atOrUndefined(isolate, 5);
// Libav Path, Optional
Handle<Object> libpath = args.atOrUndefined(isolate, 6);
// Maybe an Encoder already exists. // Maybe an Encoder already exists.
if (inited) return *isolate->factory()->ToBoolean(true); if (inited) return *isolate->factory()->ToBoolean(true);
...@@ -39,8 +41,22 @@ BUILTIN(InitEncodeContext) { ...@@ -39,8 +41,22 @@ BUILTIN(InitEncodeContext) {
isolate, NewTypeError(MessageTemplate::kInvalidArgument)); isolate, NewTypeError(MessageTemplate::kInvalidArgument));
} }
// 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();
}
// Convert to C/C++ type // Convert to C/C++ type
std::string outpath { Object::ToString(isolate, path)->ToCString().get() }; Handle<String> path_str;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, path_str,
Object::ToString(isolate, path));
std::string outpath = { path_str->ToCString().get() };
uint32_t width_int, height_int, bitrate_int, framerate_int; uint32_t width_int, height_int, bitrate_int, framerate_int;
...@@ -50,7 +66,7 @@ BUILTIN(InitEncodeContext) { ...@@ -50,7 +66,7 @@ BUILTIN(InitEncodeContext) {
framerate->ToUint32(&framerate_int); framerate->ToUint32(&framerate_int);
enc = new LAIPIC_ENCODER::Encoder { enc = new LAIPIC_ENCODER::Encoder {
"", outpath, width_int, width_int, bitrate_int }; libpath_cppstr, outpath, width_int, height_int, bitrate_int };
if (!enc->isReady()) { if (!enc->isReady()) {
// Fail to initialize LAIPIC_ENCODER::Encoder. // Fail to initialize LAIPIC_ENCODER::Encoder.
...@@ -69,6 +85,12 @@ BUILTIN(Encode) { ...@@ -69,6 +85,12 @@ BUILTIN(Encode) {
if (!inited) return *isolate->factory()->ToBoolean(false); if (!inited) return *isolate->factory()->ToBoolean(false);
Handle<Object> frame = args.atOrUndefined(isolate, 1);
if (frame->IsNull()) {
enc->encodeRGB(nullptr, 0);
return *isolate->factory()->ToBoolean(true);
}
Handle<JSTypedArray> array; Handle<JSTypedArray> array;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, array, ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, array,
JSTypedArray::Validate(isolate, args.atOrUndefined(isolate, 1), "ENCODER.encode()")); JSTypedArray::Validate(isolate, args.atOrUndefined(isolate, 1), "ENCODER.encode()"));
......
...@@ -2786,12 +2786,12 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -2786,12 +2786,12 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
InstallToStringTag(isolate_, json_object, "JSON"); InstallToStringTag(isolate_, json_object, "JSON");
} }
{ { // -- E N C O D E R
Handle<JSObject> encoder = Handle<JSObject> encoder =
factory->NewJSObject(isolate_->object_function(), AllocationType::kOld); factory->NewJSObject(isolate_->object_function(), AllocationType::kOld);
JSObject::AddProperty(isolate_, global, "ENCODER", encoder, DONT_ENUM); JSObject::AddProperty(isolate_, global, "ENCODER", encoder, DONT_ENUM);
SimpleInstallFunction(isolate_, encoder, "init", SimpleInstallFunction(isolate_, encoder, "init",
Builtin::kInitEncodeContext, 5, true); Builtin::kInitEncodeContext, 6, true);
SimpleInstallFunction(isolate_, encoder, "encode", SimpleInstallFunction(isolate_, encoder, "encode",
Builtin::kEncode, 1, true); Builtin::kEncode, 1, true);
SimpleInstallFunction(isolate_, encoder, "close", SimpleInstallFunction(isolate_, encoder, "close",
......
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