Перенос модуля NodeJS CPP v4l2.cc для работы с NodeJS v14

avatar
mat
8 августа 2021 в 18:19
52
0
0

Я пытаюсь собрать устаревший пакет NodeJS linuxcam на NodeJS v14.

Это было написано для NodeJS v4

Я получаю несколько ошибок компиляции. Некоторые из них я уже мог исправить. Вот исходный файл v4l2.cc:

#include <iostream>
#include <fstream>
using namespace std;

#include <node.h>
#include <node_object_wrap.h>
using namespace v8;

#include "webcam.h"

Webcam* webcam;

void start(const FunctionCallbackInfo<Value>& args) {
  Isolate* isolate = Isolate::GetCurrent();

  if (args.Length() < 3) {
    isolate->ThrowException(Exception::TypeError(
      String::NewFromUtf8(isolate, "start(string device, Uint32 width, Uint32 height)"))
    );
    return;
  }

  if (!args[0]->IsString() || !args[1]->IsUint32() || !args[2]->IsUint32()) {
    isolate->ThrowException(Exception::TypeError(
      String::NewFromUtf8(isolate, "start(string device, Uint32 width, Uint32 height)")));
    return;
  }

  String::Utf8Value devstr_arg(args[0]->ToString());
  string devstr = string(*devstr_arg);

  webcam = new Webcam(devstr, args[1]->Uint32Value(), args[2]->Uint32Value());
}

void frame(const FunctionCallbackInfo<Value>& args) {
  Isolate* isolate = Isolate::GetCurrent();
  auto frame = webcam->frame();

  Local<Array> array = Array::New(isolate, 3);
  array->Set(0, ArrayBuffer::New(isolate, frame->data, frame->size));
  array->Set(1, Integer::NewFromUnsigned(isolate, frame->width));
  array->Set(2, Integer::NewFromUnsigned(isolate, frame->height));


//  auto uint8_array = Uint8Array::New(array_buffer, 0, frame.size);

  args.GetReturnValue().Set(array);
}

void init(Handle<Object> exports) {
  NODE_SET_METHOD(exports, "start", start);
  NODE_SET_METHOD(exports, "frame", frame);
}

NODE_MODULE(v4l2, init)

Это моя текущая попытка:

#include <iostream>
#include <fstream>
using namespace std;

#include <node.h>
#include <node_object_wrap.h>
using namespace v8;

#include "webcam.h"

Webcam* webcam;

void start(const FunctionCallbackInfo<Value>& args) {
  v8::Isolate* isolate = v8::Isolate::GetCurrent();
  //v8::Isolate* isolate = v8::Isolate::New();

  if (args.Length() < 3) {
    isolate->ThrowException(Exception::TypeError(
      String::NewFromUtf8(isolate, "start(string device, Uint32 width, Uint32 height)").ToLocalChecked())
    );
    return;
  }

  if (!args[0]->IsString() || !args[1]->IsUint32() || !args[2]->IsUint32()) {
    isolate->ThrowException(Exception::TypeError(
      String::NewFromUtf8(isolate, "start(string device, Uint32 width, Uint32 height)").ToLocalChecked()));
    return;
  }

  /*String::Utf8Value devstr_arg(args[0]->ToString());
  string devstr = string(*devstr_arg);

  webcam = new Webcam(args[0]->StringValue(), args[1]->Uint32Value(), args[2]->Uint32Value());*/
  webcam = new Webcam(args[0], args[1], args[2]);
}

void frame(const FunctionCallbackInfo<Value>& args) {
  Isolate* isolate = Isolate::GetCurrent();
  auto frame = webcam->frame();

  Local<Array> array = Array::New(isolate, 3);
  array->Set(0, ArrayBuffer::New(isolate, frame->data, frame->size));
  array->Set(1, Integer::NewFromUnsigned(isolate, frame->width));
  array->Set(2, Integer::NewFromUnsigned(isolate, frame->height));


//  auto uint8_array = Uint8Array::New(array_buffer, 0, frame.size);

  args.GetReturnValue().Set(array);
}

//void init(Handle<Object> exports) {
void init(v8::Local<v8::Object> exports) {
  NODE_SET_METHOD(exports, "start", start);
  NODE_SET_METHOD(exports, "frame", frame);
}

NODE_MODULE(v4l2, init)

По-прежнему возникают следующие ошибки:

make: Verzeichnis „/home/m/www/camera-test/node_modules/linuxcam/build“ wird betreten
  CXX(target) Release/obj.target/v4l2/v4l2.o
../v4l2.cc: In function ‘void start(const v8::FunctionCallbackInfo<v8::Value>&)’:
../v4l2.cc:34:48: error: no matching function for call to ‘Webcam::Webcam(v8::Local<v8::Value>  v8::Local<v8::Value>  v8::Local<v8::Value>)’
   34 |   webcam = new Webcam(args[0], args[1], args[2]);
      |                                                ^
In file included from ../v4l2.cc:9:
../webcam.h:62:3: note: candidate: ‘Webcam::Webcam(const string&  int, int)’
   62 |   Webcam(const std::string& device = "/dev/video0",
      |   ^~~~~~
../webcam.h:62:29: note:   no known conversion for argument 1 from ‘v8::Local<v8::Value>’ to ‘const string&’ {aka ‘const std::__cxx11::basic_string<char>&’}
   62 |   Webcam(const std::string& device = "/dev/video0",
      |          ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
../webcam.h:59:7: note: candidate: ‘Webcam::Webcam(const Webcam&)’
   59 | class Webcam {
      |       ^~~~~~
../webcam.h:59:7: note:   candidate expects 1 argument, 3 provided
../v4l2.cc: In function ‘void frame(const v8::FunctionCallbackInfo<v8::Value>&)’:
../v4l2.cc:42:67: warning: ‘static v8::Local<v8::ArrayBuffer> v8::ArrayBuffer::New(v8::Isolate*, void*, size_t, v8::ArrayBufferCreationMode)’ is deprecated: Use the version that takes a BackingStore. See http://crbug.com/v8/9908. [-Wdeprecated-declarations]
   42 |   array->Set(0, ArrayBuffer::New(isolate, frame->data, frame->size));
      |                                                                   ^
In file included from /home/m/.cache/node-gyp/14.17.4/include/node/node.h:67,
                 from ../v4l2.cc:5:
/home/m/.cache/node-gyp/14.17.4/include/node/v8.h:5176:29: note: declared here
 5176 |   static Local<ArrayBuffer> New(
      |                             ^~~
../v4l2.cc:42:67: warning: ‘static v8::Local<v8::ArrayBuffer> v8::ArrayBuffer::New(v8::Isolate*, void*, size_t, v8::ArrayBufferCreationMode)’ is deprecated: Use the version that takes a BackingStore. See http://crbug.com/v8/9908. [-Wdeprecated-declarations]
   42 |   array->Set(0, ArrayBuffer::New(isolate, frame->data, frame->size));
      |                                                                   ^
In file included from /home/m/.cache/node-gyp/14.17.4/include/node/node.h:67,
                 from ../v4l2.cc:5:
/home/m/.cache/node-gyp/14.17.4/include/node/v8.h:5176:29: note: declared here
 5176 |   static Local<ArrayBuffer> New(
      |                             ^~~
../v4l2.cc:42:68: error: no matching function for call to ‘v8::Array::Set(int, v8::Local<v8::ArrayBuffer>)’
   42 |   array->Set(0, ArrayBuffer::New(isolate, frame->data, frame->size));
      |                                                                    ^
In file included from /home/m/.cache/node-gyp/14.17.4/include/node/node.h:67,
                 from ../v4l2.cc:5:
/home/m/.cache/node-gyp/14.17.4/include/node/v8.h:3670:37: note: candidate: ‘v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>  v8::Local<v8::Value>  v8::Local<v8::Value>)’
 3670 |   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
      |                                     ^~~
/home/m/.cache/node-gyp/14.17.4/include/node/v8.h:3670:37: note:   candidate expects 3 arguments, 2 provided
/home/m/.cache/node-gyp/14.17.4/include/node/v8.h:3673:37: note: candidate: ‘v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>  uint32_t, v8::Local<v8::Value>)’
 3673 |   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
      |                                     ^~~
/home/m/.cache/node-gyp/14.17.4/include/node/v8.h:3673:37: note:   candidate expects 3 arguments, 2 provided
../v4l2.cc:43:64: error: no matching function for call to ‘v8::Array::Set(int, v8::Local<v8::Integer>)’
   43 |   array->Set(1, Integer::NewFromUnsigned(isolate, frame->width));
      |                                                                ^
In file included from /home/m/.cache/node-gyp/14.17.4/include/node/node.h:67,
                 from ../v4l2.cc:5:
/home/m/.cache/node-gyp/14.17.4/include/node/v8.h:3670:37: note: candidate: ‘v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>  v8::Local<v8::Value>  v8::Local<v8::Value>)’
 3670 |   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
      |                                     ^~~
/home/m/.cache/node-gyp/14.17.4/include/node/v8.h:3670:37: note:   candidate expects 3 arguments, 2 provided
/home/m/.cache/node-gyp/14.17.4/include/node/v8.h:3673:37: note: candidate: ‘v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>  uint32_t, v8::Local<v8::Value>)’
 3673 |   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
      |                                     ^~~
/home/m/.cache/node-gyp/14.17.4/include/node/v8.h:3673:37: note:   candidate expects 3 arguments, 2 provided
../v4l2.cc:44:65: error: no matching function for call to ‘v8::Array::Set(int, v8::Local<v8::Integer>)’
   44 |   array->Set(2, Integer::NewFromUnsigned(isolate, frame->height));
      |                                                                 ^
In file included from /home/m/.cache/node-gyp/14.17.4/include/node/node.h:67,
                 from ../v4l2.cc:5:
/home/m/.cache/node-gyp/14.17.4/include/node/v8.h:3670:37: note: candidate: ‘v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>  v8::Local<v8::Value>  v8::Local<v8::Value>)’
 3670 |   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
      |                                     ^~~
/home/m/.cache/node-gyp/14.17.4/include/node/v8.h:3670:37: note:   candidate expects 3 arguments, 2 provided
/home/m/.cache/node-gyp/14.17.4/include/node/v8.h:3673:37: note: candidate: ‘v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>  uint32_t, v8::Local<v8::Value>)’
 3673 |   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
      |                                     ^~~
/home/m/.cache/node-gyp/14.17.4/include/node/v8.h:3673:37: note:   candidate expects 3 arguments, 2 provided
In file included from ../v4l2.cc:5:
../v4l2.cc: At global scope:
/home/m/.cache/node-gyp/14.17.4/include/node/node.h:758:43: warning: cast between incompatible function types from ‘void (*)(v8::Local<v8::Object>)’ to ‘node::addon_register_func’ {aka ‘void (*)(v8::Local<v8::Object>  v8::Local<v8::Value>  void*)’} [-Wcast-function-type]
  758 |       (node::addon_register_func) (regfunc),                          \
      |                                           ^
/home/m/.cache/node-gyp/14.17.4/include/node/node.h:792:3: note: in expansion of macro ‘NODE_MODULE_X’
  792 |   NODE_MODULE_X(modname, regfunc, NULL, 0)  // NOLINT (readability/null_usage)
      |   ^~~~~~~~~~~~~
../v4l2.cc:58:1: note: in expansion of macro ‘NODE_MODULE’
   58 | NODE_MODULE(v4l2, init)
      | ^~~~~~~~~~~

Я действительно понятия не имею о cpp-интерфейсах для node js. Надеюсь, кто-нибудь сможет мне помочь.

Источник

Ответы (0)