Created
May 7, 2015 11:30
-
-
Save Ivshti/b54fee57c58746d882b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <node.h> | |
#include <v8.h> | |
using namespace v8; | |
char* buf; | |
const unsigned size = 400*400; | |
void GetVideoFrame(const v8::FunctionCallbackInfo<Value>& args) | |
{ | |
Isolate* isolate = Isolate::GetCurrent(); | |
HandleScope scope(isolate); | |
Local<Object> global = isolate->GetCurrentContext()->Global(); | |
Handle<Value> abv = global->Get(v8::String::NewFromUtf8(isolate, "Uint8Array", v8::String::kInternalizedString)); | |
Handle<Value> argv[] = { Integer::NewFromUnsigned(isolate, size) }; | |
Handle<Object> target = Handle<Function>::Cast(abv)->NewInstance(1, argv); | |
buf = static_cast<char*>(target->GetIndexedPropertiesExternalArrayData()); | |
for( unsigned i = 0; i < size / 2; ++i ) { | |
*(buf + i) = ( rand() % 256 ); | |
} | |
args.GetReturnValue().Set( target ); | |
} | |
void UpdateVideoFrame(const v8::FunctionCallbackInfo<Value>& args) | |
{ | |
for( unsigned i = 0; i < size / 2; ++i ) { | |
*(buf + i) = ( rand() % 256 ); | |
} | |
} | |
void Init(Handle<Object> exports) { | |
NODE_SET_METHOD(exports, "GetVideoFrame", GetVideoFrame); | |
NODE_SET_METHOD(exports, "UpdateVideoFrame", UpdateVideoFrame); | |
} | |
NODE_MODULE(WC, Init) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment