使用 Android NDK 和原始 USB 连接为内核不支持的相机实现 UVC 驱动程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10472330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:51:34  来源:igfitidea点击:

Implementing an UVC driver using the Android NDK and a raw usb connection for cameras that are not supported by the kernel

androidcameraandroid-ndkusbdevice-driver

提问by Nils

I'm looking for a way to get UVC compartible usb cameras working on other android devices that don't have a kernel driver for those UVC cameras by default.

我正在寻找一种方法让 UVC 兼容的 USB 相机在默认情况下没有用于这些 UVC 相机的内核驱动程序的其他 Android 设备上工作。

I don't want to root those devices nor change their image/kernel, because usual customers should be able to use the camera later on with every tablet and without special requirements (except an app).

我不想 root 那些设备,也不想更改它们的图像/内核,因为普通客户以后应该能够在每台平板电脑上使用相机并且没有特殊要求(应用程序除外)。

Do you think it might be possible to establish a raw connection to an unknown device using Android's USB class in Android 3.1 and higher (http://developer.android.com/guide/topics/usb/host.html) or can I only use it with devices that are supported and recognized by the kernel already?

您认为是否可以使用 Android 3.1 及更高版本 (http://developer.android.com/guide/topics/usb/host.html) 中的 Android USB 类与未知设备建立原始连接,或者我只能将它与内核已经支持和识别的设备一起使用?

If it would be possible, I would be interested in integrating the UVC driver using Java/NDK to get the video stream out of it. At least that's my rough idea.

如果可能的话,我会对使用 Java/NDK 集成 UVC 驱动程序感兴趣,以从中获取视频流。至少这是我的粗略想法。

Do you think that's possible?

你认为这可能吗?

采纳答案by mk..

It is definitely possible if you are compromising on that rooted part.. I did the same project and was finally successful. Inside uvc code, you shall be opening /dev/video1 or video0 node for which by default on most of the devices there are no user permissions.

如果你在那个根深蒂固的部分妥协,那绝对是可能的。我做了同样的项目,最后成功了。在 uvc 代码中,您应该打开 /dev/video1 或 video0 节点,默认情况下,在大多数设备上没有用户权限。

To state it simply,

简单地说,

It depends on 2 things :

这取决于两件事:

1) When you connect the USB Camera, if the camera node is getting created or not. It should be inside /dev directory with major number 81(signifies V4l2 device)

1) 当您连接 USB 摄像头时,是否正在创建摄像头节点。它应该在 /dev 目录中,主编号为 81(表示 V4l2 设备)

2) For that device node you are having user permissions or not.

2)对于该设备节点,您是否拥有用户权限。

These are the two hurdles you will be facing.

这是您将面临的两个障碍。

Solution to first is not there in our hands coz it depends from vendor to vendor. Ex, Acer tab it gets created but in Samsung Galaxy it doesnt.. The reason is missing support of V4L2 or UVC modules inside the kernel.

第一个的解决方案不在我们手中,因为它取决于供应商和供应商。例如,创建了 Acer 选项卡,但在三星 Galaxy 中却没有。原因是内核中缺少对 V4L2 或 UVC 模块的支持。

Solution to the second one is if you are a root user you can change the permissions of the node.

第二个的解决方案是,如果您是 root 用户,您可以更改节点的权限。

It is quite a big project and should take some time if you are starting from scratch.. All the best

这是一个相当大的项目,如果你从头开始,应该需要一些时间..一切顺利

回答by Chris Stratton

Yes, the purpose of the usb host support in more recent versions of Android userspace is to allow you to talk to USB devices which don't have kernel drivers. Conceptually it sounds a bit similar to the libusb idea, though it is not libusb.

是的,在最新版本的 Android 用户空间中支持 USB 主机的目的是让您可以与没有内核驱动程序的 USB 设备通信。从概念上讲,它听起来有点类似于 libusb 的想法,尽管它不是 libusb。

http://developer.android.com/guide/topics/usb/host.html

http://developer.android.com/guide/topics/usb/host.html

It occurs to me (as pure, unverified speculation) that there might perhaps be situations where partial driver-in-kernel support for a device could interfere with attempting to talk to it directly from userspace in this manner.

我突然想到(作为纯粹的、未经证实的推测),可能在某些情况下,对设备的部分驱动程序内核支持可能会干扰以这种方式直接从用户空间与它对话的尝试。

回答by t0mm13b

I'm looking for a way to get UVC compartible usb cameras working on other android devices that don't have a kernel driver for those UVC cameras by default.

我正在寻找一种方法让 UVC 兼容的 USB 相机在默认情况下没有用于这些 UVC 相机的内核驱动程序的其他 Android 设备上工作。

That is dependent on the kernel, and the drivers compiled in, also take into consideration in respect of the hardware if it can support it.

这取决于内核,并且编译的驱动程序也考虑了硬件是否可以支持它。

By the very sound of it - its resembling USB On-The-Go mechanism... now if you're saying you don't want the devices to be rooted, unfortunately for the USB OTG mechanism you do need root to avail of it and the scripts mechanism in the /etc directory within the ramdisk to handle the plugin event.

从它的声音来看 - 它类似于 USB On-The-Go 机制......现在如果你说你不希望设备被 root,不幸的是对于 USB OTG 机制,你确实需要 root 才能使用它以及 ramdisk 内 /etc 目录中的脚本机制来处理插件事件。