Skip to content

Instantly share code, notes, and snippets.

@Ivshti
Created May 7, 2015 11:30
Show Gist options
  • Save Ivshti/b54fee57c58746d882b1 to your computer and use it in GitHub Desktop.
Save Ivshti/b54fee57c58746d882b1 to your computer and use it in GitHub Desktop.
#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