Commit a9090433 authored by Linshizhi's avatar Linshizhi

Add ENCODER.init

parent ce8c2cd9
...@@ -631,7 +631,7 @@ config("internal_config_base") { ...@@ -631,7 +631,7 @@ config("internal_config_base") {
config("internal_config") { config("internal_config") {
defines = [] defines = []
lib_dirs = [ "third_party/ffmpeg/lib" ] lib_dirs = [ "third_party/ffmpeg/lib" ]
libs = [ "avformat" ] libs = [ "avformat", "avutil" ]
# Only targets in this file and its subdirs can depend on this. # Only targets in this file and its subdirs can depend on this.
visibility = [ "./*" ] visibility = [ "./*" ]
......
...@@ -621,6 +621,7 @@ namespace internal { ...@@ -621,6 +621,7 @@ namespace internal {
CPP(JsonStringify) \ CPP(JsonStringify) \
\ \
/* ENCODER */ \ /* ENCODER */ \
CPP(InitEncodeContext) \
CPP(Encode) \ CPP(Encode) \
\ \
/* Web snapshots */ \ /* Web snapshots */ \
......
...@@ -5,18 +5,44 @@ ...@@ -5,18 +5,44 @@
extern "C" { extern "C" {
#include "libavformat/avformat.h" #include "libavformat/avformat.h"
#include "libavutil/avutil.h"
} }
namespace v8 { namespace v8 {
namespace internal { namespace internal {
bool inited = false;
AVFormatContext *format = NULL;
AVCodecContext *cc;
BUILTIN(InitEncodeContext) {
HandleScope scope(isolate);
Handle<Object> path = args.atOrUndefined(isolate, 1);
Handle<String> string;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, string,
Object::ToString(isolate, path));
if (inited) return *isolate->factory()->ToBoolean(false);
int ret = avformat_alloc_output_context2(
&format, NULL, NULL, "/home/linshizhi/aa.mp4");
if (ret < 0) {
printf("Failed to alloc output context: %s\n", av_err2str(ret));
return *isolate->factory()->ToBoolean(false);
}
inited = true;
return *isolate->factory()->ToBoolean(true);
}
BUILTIN(Encode) { BUILTIN(Encode) {
HandleScope scope(isolate); HandleScope scope(isolate);
printf("Encoding...\n"); printf("Encoding...\n");
AVFormatContext *format = avformat_alloc_context();
return *isolate->factory()->ToBoolean( return *isolate->factory()->ToBoolean(
format != NULL ? true : false); format != NULL ? true : false);
......
...@@ -2790,6 +2790,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -2790,6 +2790,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
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",
Builtin::kInitEncodeContext, 1, true);
SimpleInstallFunction(isolate_, encoder, "encode", SimpleInstallFunction(isolate_, encoder, "encode",
Builtin::kEncode, 0, true); Builtin::kEncode, 0, true);
InstallToStringTag(isolate_, encoder, "ENCODER"); InstallToStringTag(isolate_, encoder, "ENCODER");
......
libavformat.so.59.5.100
\ No newline at end of file
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