Joel Purra: Developer and more


Node.js library for USB Video Class (UVC) devices (node-libuvc)

Low-level Node.js library for USB Video Class (UVC) devices, wrapping the cross-platform libuvc C library. Used to write software for webcams, camcorders, etcetera.

UVC-compliant devices include webcams, digital camcorders, transcoders, analog video converters and still-image cameras.

This is a experimental, proof-of-concept combining several technologies.

This proof-of-concept lead to the development of node-ffi-packager.

Features

  • All functionality of libuvc available in Node.js.
  • Strictly follows the libuvc.h C header file.
  • Enables C-style programming.
    • This style is different from the usual conveniences of modern Javascript.
    • This low-level library was primarily created to enable building other libraries, where developer convenience can be a goal.

Requirements

Installation

Use a package.json reference to your preferred semantic version node-libuvc git tag.

npm install --save github:joelpurra/node-libuvc#semver:^v1.0.0

Usage

See ./examples/ for ready-to-run code.

const libuvc = require("libuvc");
const ref = require("ref-napi");

// NOTE: C types in comments for reference.
const /* uvc_context_t * */ ctx = ref.alloc(libuvc.types.uvc_context_tPointer);
const /* uvc_device_t * */ dev = ref.alloc(libuvc.types.uvc_device_tPointer);
const /* uvc_device_handle_t * */ devh = ref.alloc(
    libuvc.types.uvc_device_handle_tPointer
  );
const /* uvc_stream_ctrl_t */ ctrl = ref.alloc(libuvc.types.uvc_stream_ctrl_t);
let /* uvc_error_t */ res;

res = libuvc.functions.uvc_init(/* & */ ctx, null);
res = libuvc.functions.uvc_find_device(ctx.deref(), /* & */ dev, 0, 0, null);
res = libuvc.functions.uvc_open(dev.deref(), /* & */ devh);

// NOTE: use the UVC device here, for example setting controls and streaming image frames.

libuvc.functions.uvc_close(devh.deref());
libuvc.functions.uvc_unref_device(dev.deref());
libuvc.functions.uvc_exit(ctx.deref());

Building

The package should be automatically built by npm install. You can also manually (re)build the package dependencies.

npm run --silent build

Development

# Make sure git-flow is initialized.
git flow init -d

npm run --silent rebuild

npm run --silent test

See also

Acknowledgements


node-libuvc Copyright © 2020, 2021 Joel Purra. Released under GNU Lesser General Public License version 3.0 (LGPL-3.0). Your donations are appreciated!

Live programming stream