我是一个节点& C ++ newbie所以要小心。
我正在编写一个本机节点插件。
我的插件启动网络摄像头流媒体(使用UVC lib),我希望每个帧都可用于节点。
我的CC插件有点像
uvc_start_streaming(devh, &ctrl, frameProcess, (void *) &args, 0)
其中:
每个新帧都会调用c ++回调,我想简单地打印“收到新帧”这样的东西,所以我的C ++就像:
void frameProcess(uvc_frame_t *frame, void *ptr) {
const FunctionCallbackInfo<Value> args = *((const FunctionCallbackInfo<Value>*)(ptr));
Isolate* isolate = args.GetIsolate();
Local<Function> cb = Local<Function>::Cast(args[0]);
const unsigned argc = 1;
Local<Value> argv[argc] = { String::NewFromUtf8(isolate, "new frame received") };
cb->Call(Null(isolate), argc, argv);
}
void testStreaming (const FunctionCallbackInfo<Value>& args) {
...
res = uvc_start_streaming(devh, &ctrl, frameProcess, (void *) &args, 0);
puts("Streaming...");
Sleep(10000); /* stream for 10 seconds */
uvc_stop_streaming(devh);
puts("Done streaming.");
...
}
...
NODE_SET_METHOD(exports, "testStreaming", testDevice);
我的js就像:
'use strict';
var uvc = require('../build/Release/binding')
uvc.testStreaming(
function (x) {
console.log(x)
}
)
问题是当程序到达cb-&gt; Call。
时,节点退出而没有任何消息或错误如果我评论cb-&gt;调用行程序运行10秒(连续调用)编程,然后退出。
但如果我取消注释cb-&gt;立即调用程序退出。