ffi: update cbindgen version to 0.20
2 files changed
tree: e222ea287b56476abbdc47da0504f55917def741
  1. ffi/
  2. lib/
  3. utils/
  4. .gitignore
  5. .travis.yml
  6. Android.bp
  7. Cargo.lock
  8. Cargo.toml
  9. LICENSE
  10. README.md
README.md

Rust bindings for V4L2 Build Status

This is a work-in-progress library to implement safe Rust bindings and high-level interfaces for V4L2.

Currently the following is implemented:

  • Safe low-level abstractions to manage OUTPUT and CAPTURE queues, as well as buffers allocation/queueing/dequeuing for MMAP, USERPTR and DMABUF memory types,
  • High-level abstraction of the stateful video decoder interface,
  • High-level abstraction of the stateful video encoder interface,
  • C FFI for using the video decoder interface from C programs.

The library provides several levels of abstraction over V4L2:

  • At the lowest level is a very thin layer over the V4L2 ioctls, that stays as close as possible to the actual kernel API while adding extra safety and removing some of the historical baggage like the difference in format for single-planar and multi-planar queues.

  • A higher-level abstraction exposes devices, queues, and other V4L2 concepts as strongly typed objects. The goal here is to provide an nice-to-use interface that remains generic enough to be used for any kind of V4L2 device.

  • Finally, more specialized abstractions can be used by applications for performing specific tasks, like decoding a video using hardware acceleration. For these abstractions, a C FFI is usually provided so their use is not limited to Rust.

Dependencies shall be kept to a minimum: this library talks directly to the kernel using ioctls, and only depends on a few small, well-established crates.

Project Layout

lib contains the Rust library (v4l2r), including the thin ioctl abstraction, the more usable device abstraction, and task-specific modules for e.g. video decoding and encoding.

ffi contains the C FFI (v4l2r-ffi) which is currently exposed as a static library other projects can link against. A v4l2r.h header file with the public API is generated upon build.

How to use

Check lib/examples/vicodec_test/device_api.rs for a short example of how to use the device-level interface, or lib/examples/vicodec_test/ioctl_api.rs for the same example using the lower-level ioctl API. Both examples encode generated frames into the FWHT format using the vicodec kernel driver (which must be inserted beforehand, using e.g. modprobe vicodec multiplanar=1).

You can try these examples with

cargo run --example vicodec_test -- /dev/video0

for running the device API example, or

cargo run --example vicodec_test -- /dev/video0 --use_ioctl

for the ioctl example, assuming /dev/video0 is the path to the vicodec encoder.

lib/examples/fwht_encoder contains another example program implementing a higher-level vicodec encoder running in its own thread. It can be run as follows:

cargo run --example fwht_encoder -- /dev/video0

Pass --help to the program for further options.

lib/examples/fwht_decoder is a decoder example able to decode the streams produced by the fwht_encoder example above.

Finally, ffi/examples/c_fwht_decode/ contains a C program demonstrating how to use the C FFI to decode a FWHT stream. See the Makefile for build and use instructions.