近期在rk3399 Android9.0的项目上,有个客户外接了两个usb的摄像头A和B,现在的情况是,两个usb摄像头都是前置的,客户想要固定摄像头A为前摄,摄像头B为后摄。
芯片 | rk3399 |
---|---|
Android版本 | Android9.0 |
– | – |
内核版本 | 4.4 |
思路是:根据usb摄像头插入usb口的节点,固定usb摄像头的video节点,然后hal层通过读取对应的video节点,赋予对应的前后摄属性。
例如:插入usb摄像头A后,将其固定为dev/video7 ; usb摄像头B, 固定为 dev/video8 ,然后hal层通过读取到对应的值后,赋予对应的属性。
话不多说直接上修改记录。
kernel修改如下:
diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
index 435b2ee7a0f4..464f93e14a2f 100644
--- a/drivers/media/usb/uvc/uvc_driver.c
+++ b/drivers/media/usb/uvc/uvc_driver.c
@@ -1909,6 +1909,9 @@ int uvc_register_video_device(struct uvc_device *dev,
*/
video_set_drvdata(vdev, stream);
+ vdev->hw_portnum = dev->udev->hw_portnum;
+ printk("vdev->hw_portnum=%d\n",vdev->hw_portnum);
+
ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
if (ret < 0) {
uvc_printk(KERN_ERR, "Failed to register %s device (%d).\n",
diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
index 72a8b8047bd0..e1a28ea90e37 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -849,6 +849,16 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
/* Pick a device node number */
mutex_lock(&videodev_lock);
+
+ printk("dxq portnum=%d\n",vdev->hw_portnum);
+ if(vdev->vfl_type == VFL_TYPE_GRABBER) {
+ if(7 == vdev->hw_portnum) {
+ nr = 7;
+ }else if(8 == vdev->hw_portnum) {
+ nr = 8;
+ }
+ }
+
nr = devnode_find(vdev, nr == -1 ? 0 : nr, minor_cnt);
if (nr == minor_cnt)
nr = devnode_find(vdev, 0, minor_cnt);
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 1e5f55118d42..02d85ea9488d 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -2167,6 +2167,15 @@ static void show_string(struct usb_device *udev, char *id, char *string)
static void announce_device(struct usb_device *udev)
{
+ udev->hw_portnum=0;
+ //printk("kobject_name(&udev->dev->kobj)=%s\n",kobject_name(&(udev->dev.kobj)));
+ if(!strcmp("2-1.1.1",kobject_name(&(udev->dev.kobj)))){
+ udev->hw_portnum=7;
+ }else if(!strcmp("2-1.1.2",kobject_name(&(udev->dev.kobj)))){
+ udev->hw_portnum=8;
+ }
+ //printk("udev->hw_portnum=%d\n",udev->hw_portnum);
+
dev_info(&udev->dev, "New USB device found, idVendor=%04x, idProduct=%04x\n",
le16_to_cpu(udev->descriptor.idVendor),
le16_to_cpu(udev->descriptor.idProduct));
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 5c03ebc6dfa0..05896dae09c5 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -572,6 +572,7 @@ struct usb_device {
unsigned short bus_mA;
u8 portnum;
+ u8 hw_portnum;
u8 level;
unsigned can_submit:1;
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index 5a562ad58bb9..f74fbcaf0ba2 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -128,6 +128,7 @@ struct video_device
/* Internal device debug flags, not for use by drivers */
int dev_debug;
+ int hw_portnum; /*usb hw port*/
/* Video standard vars */
v4l2_std_id tvnorms; /* Supported tv norms */
以上修改参考链接:
https://blog.csdn.net/ldinvicible/article/details/104511306
接下来是HAL层的修改:
diff --git a/hardware/interfaces//camera/device/3.4/default/ExternalCameraDevice.cpp b/hardware/interfaces//camera/device/3.4/default/ExternalCameraDevice.cpp
index 9382c511b..9d246c36a 100644
--- a/hardware/interfaces/camera/device/3.4/default/ExternalCameraDevice.cpp
+++ b/hardware/interfaces/camera/device/3.4/default/ExternalCameraDevice.cpp
@@ -21,6 +21,7 @@
#include <algorithm>
#include <array>
#include <linux/videodev2.h>
+#include <string.h>
#include "android-base/macros.h"
#include "CameraMetadata.h"
#include "../../3.2/default/include/convert.h"
@@ -309,7 +310,15 @@ status_t ExternalCameraDevice::initDefaultCharsKeys(
UPDATE(ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION,
&opticalStabilizationMode, 1);
- const uint8_t facing = ANDROID_LENS_FACING_BACK;
+ const char* dev = mCameraId.c_str();
+ bool face_flage = false;
+ if(strcmp(dev,"/dev/video7") == 0){
+ face_flage = true;
+ } else {
+ face_flage = false;
+ }
+ const uint8_t facing = face_flage ? ANDROID_LENS_FACING_BACK : ANDROID_LENS_FACING_FRONT;
+ ALOGE("%s: dxq mCameraId.c_str()=%s ", __FUNCTION__, mCameraId.c_str());
UPDATE(ANDROID_LENS_FACING, &facing, 1);
// android.noiseReduction
以上是我自己项目上的修改记录,可以根据读者自身项目进行修改。
版权声明:本文为it_rensheng原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。