[libcamera-devel] Support for hotplugging UVC devices

Umang Jain email at uajain.com
Wed May 6 12:32:39 CEST 2020


Hi Laurent

On Thu, Apr 30, 2020 at 00:27, Laurent Pinchart 
<laurent.pinchart at ideasonboard.com> wrote:
> 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://u15657259.ct.sendgrid.net/ls/click?upn=8H1KCc2bev8KdIveckpOEF8NFg9rbIgRS-2FA55EvKtHykb8IS-2Bk-2FOjvY70Cmox2SkeZGYPYqHL-2F3Ad3KLfA5jWg-3D-3DqraL_C3wFy2Q4UgRsRLDAYieRZ5Z3EhAWyy0-2FkOzyYc6FPc1dn6ROcAJqKXb9hjP566uP5oG9z5GCp2cwpQcv6TdhSxNWLALzPNZP6nkCWRRNBMcKvEjWyGHiecURFlqctOpg6ob6yToOhGl1Emp46ixZf2SpVHeADm4gmmKeK-2BPJUeO22ShiPCS3jlgqImbS-2FckWAxlAr20NGbV7yTvE9Xw9ZORX3Dk9Ix8d5-2FoQcRe6ZVnQALh5YugRLwRHBVANDlQbUhwXj4U7a1xCyVWFcddOmg-3D-3D>
>>  hotplug
> 
> Nice work !

Thanks. Means a lot coming from you.
> 
>>  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://u15657259.ct.sendgrid.net/ls/click?upn=8H1KCc2bev8KdIveckpOENWIe8wLJf27r55W-2FCbo39NIgkUTQYfWmAgVXccH3QLaoZ5x_C3wFy2Q4UgRsRLDAYieRZ5Z3EhAWyy0-2FkOzyYc6FPc1dn6ROcAJqKXb9hjP566uP5oG9z5GCp2cwpQcv6TdhSwFyIWFHyVXDwa-2BH-2FJWIR6RwDXZUDNXvIZxnr9OOktrT0eEDZe3gbzT2v1DImlCd8CtoQlOW6NrR9vSA4VJQpi9jdJff3GmvfpEMf0oGD2NceHsX2UAfN14JEozKbDFG5JUY8VwKnXhvZes7pfOnAtzduObbCbgvcXsdO9rxKeEm7Mg1wj2phD69ZmwDWiIJJA-3D-3D>
>>  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 see. Thanks for the audit for this. I actually had no idea about the 
internals but
I mentioned it here, as that was the goal I was looking for, until....

> 
> 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

I learnt about this. I actually got a automated test case now, around 
this.
However I uncovered a bug in libcamera which created a problem while
rebinding the device itself. I have put a small workaround for that for 
now and will
explain in the patchset itself.

> 
> 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://u15657259.ct.sendgrid.net/ls/click?upn=8H1KCc2bev8KdIveckpOENWIe8wLJf27r55W-2FCbo39NPgHn5U3BwXeiNNqvgoaQbohYe7mkL4Q8KETGwINprZZ4J3Ijx-2FAUinHJu5B7AiRC7yXTDTfFehSYm0rsxvnDsziGe_C3wFy2Q4UgRsRLDAYieRZ5Z3EhAWyy0-2FkOzyYc6FPc1dn6ROcAJqKXb9hjP566uP5oG9z5GCp2cwpQcv6TdhS47ZB0Ts6r0VYO4VwAoUcQYrDhCkRnrsBhAj0UghwZLcjSACzSiLjLlWoH4lOXsPGAwzp6Wi-2FdvoG9PHBjxIma1u5gOBFlmR0BYIvA17QmJa1MIaAN4nRVIGKWI5pX7lawmf604A4hpDSh23gHtGxmZk75LMezTOVrdK1JYnR86-2BpVodEy4timpgL2kC3Xxaaw-3D-3D>
> 
> --
> Regards,
> 
> Laurent Pinchart

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20200506/8baedef6/attachment.htm>


More information about the libcamera-devel mailing list