Safe binding to interact with [v4l2loopback].
[v4l2loopback] allows your to manage virtual video devices on linux. Application are able to pass video content to those devices, and this video feed will be available as a camera.
⚠️ Warning:
This crate is based on an unreleased version of [v4l2loopback]. To use this crate you will need to build and install [v4l2loopback] from source. (If you are on archlinux, you can install [v4l2loopback-dkms-git] from the aur)
Keep in mind that you need the permission to open /dev/v4l2loopback
.
So when when using this crate in your application, be sure that it is running as root
before calling functions in this crate.
To avoid having to run cargo as root during developpement, you can change the permissions of the control device, (See Building and Testing)
```rust use std::path::Path; use v4l2loopbackrs::{adddevice, deletedevice, querydevice, DeviceConfig};
// Device configuration // Here you declare informations about the camera device that will be created. // It should be matching the content that you will want to pass through let deviceconfig = DeviceConfig { label: "Test Device".tostring(), minwidth: 100, maxwidth: 4000, minheight: 100, maxheight: 4000, maxbuffers: 9, maxopeners: 3, }; // Create a device let devicenum = adddevice(None, device_config.clone()).expect("Error when creating the device");
// Querying informations about a device // This returns the matchin device's configuration let cfg = querydevice(devicenum).expect("Error when querying the device");
// When you are done with you processing, don't forget to delete the device, otherwise the
// device /dev/videoN
will not be removed.
deletedevice(devicenum).expect("Error when removing device");
assert!(!Path::new(&format!("/dev/video{}", device_num)).exists());
```
To be able to test this crate, you will need to clone this repository and it's submodules,
since for generating bindings it needs v4l2loopback/v4l2loopback.h
.
For executing tests, you need to ensure you can open /dev/v4l2loopback
.
To do so, you can change the permissions of /dev/v4l2loopback
:
```bash
sudo chmod o+r /dev/v4l2loopback ```