UvcLib constructor

UvcLib({
  1. String? libraryName,
  2. bool debugLogging = false,
  3. bool debugLoggingLibUsb = false,
})

Loads the library for controlling UVC compliant webcams.

Implementation

UvcLib({
  String? libraryName,
  this.debugLogging = false,
  this.debugLoggingLibUsb = false,
}) {
  if (_libusb == null) {
    final lib = _loadLibrary(libraryName: libraryName);
    _lib = lib;
    _libusb = Libusb(lib);

    final contextPtr = calloc<Pointer<libusb_context>>();
    final initResult = _libusb!.libusb_init(contextPtr);
    if (initResult < 0 || contextPtr.address == 0) {
      if (debugLogging) {
        print('uvc: libusb library not initialized successfully');
      }
      _libusb!.libusb_exit(contextPtr.value);
      calloc.free(contextPtr);
      _libusb = null;

      _lib?.close();
      _lib = null;
      return;
    }

    if (debugLogging) {
      print('uvc: libusb library initialized successfully');
    }

    _contextPtr = contextPtr;

    if (debugLoggingLibUsb) {
      libusb.libusb_set_debug(
          nullptr, libusb_log_level.LIBUSB_LOG_LEVEL_DEBUG);
    }
  }
}