[libcamera-devel] Support for hotplugging UVC devices

Laurent Pinchart laurent.pinchart at ideasonboard.com
Wed Apr 29 23:27:51 CEST 2020


Hi Umang,

On Wed, Apr 29, 2020 at 02:50:42AM +0000, Umang Jain wrote:
> Hi all,
> 
> Thanks for your comments on the approach, Laurent. 
> I have pushed a branch here : https://github.com/uajain/libcamera/tree/uajain/
> hotplug

Nice work !

> I have tested with UVC devices (primarily a external webcam) and I had
> satisfactory results.
> I am now exploring ways to write unit tests around this. I, ideally, needs to
> run CameraManager and have a mock UDev
> device-connected event fired so that CameraManager can run/test the code path
> above. I came across https://github.com/martinpitt/umockdev
> which seems relevant for this. Not sure how far can I get with this.

That's an interesting project, I wasn't aware of it. If I understand the
documentation correctly, it emulates devices in userspace, with options
to record ioctls issues on a real device and then replaying them. The
emulation uses the LD_PRELOAD technique to intercept libc calls, and is
implemented in [1].

It seems that support for mmap() and ppoll(), which are pretty
fundamental operation for V4L2 devices, is missing. It wouldn't be
straightforward to add them, so I'm not sure if using umockdev will be a
feasible approach.

I'm wondering if we shouldn't start simpler. Devices can be unbound from
drivers programmatically through sysfs. For instance running

echo 1-5:1.0 > /sys/module/uvcvideo/drivers/usb\:uvcvideo/unbind

unbinds my integrated webcam from the uvcvideo driver. This has the same
effect, from a userspace point of view, as unplugging the device. You
can also simulate hotplug by re-binding the device to the driver if you
write the same string to the 'bind' file.

Maybe the test could be based on this ? Writing to these files requires
root , so the test should be skipped if it doesn't have the right
permissions, but it would be a good step forward in my opinion. It would
however require a UVC device being plugged into the system, but we could
in a second step port it to vimc (and I wouldn't be surprised if it then
could crash the kernel, requiring fixes in vimc :-)).

[1] https://github.com/martinpitt/umockdev/blob/master/src/libumockdev-preload.c

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list