USB Camera在android车机上应用前景及初试小结
USB Camera在我们的生活中已经有一些年头了,USB接口的普通摄像头由于使用方便,价格低廉,性能较好,应用在了工作生活的各个方面,比如可视电话、视频聊天和普通的视频监控。但是,目前在车载行业,使用USB Camera的还是非常非常少的。在车机行业,由于摄像头安装的位置跟主控的距离一般都很远,走数字信号很有难度,目前大多都是走的模拟信号,比如把camera输出的信号转化成cvbs信号,再输入给主控,这条路当然可行,但是也很有局限性,一个是就是清晰度,头像质量的衰减等,可想而知这个整体效果就上不了一个台阶。随着科技的进步,消费者市场需求的越来越强烈,得更进一步啊!目前笔者在预研一下USB Camera在android车机上的开发工作。USB Camera可以采集高清信号,通过usb传输给主控,当然usb的走线一般也能比较长,在硬件上稍加一下放大,走的线应该可以满足车载的需求,至少做后视镜一点问题都没有,做车机理论上应该能解决好,笔者抛砖引玉带领大家看看如何去应用USB Camera。
大家都知道android的底层操作系统内核是基于linux的,linux里面有支持UVC(USB video class),首先得到内核里去把配置打开,已经加载驱动。在内核里UVC可以配置成buildin的模式,但是为了调试方便还是配置成模块的形式比较好,配置成模块。配置如下:
[python]
@@ -1561,6 +1561,9 @@ CONFIG_MEDIA_TUNER_MC44S803=y
CONFIG_VIDEO_V4L2=y
CONFIG_VIDEOBUF_GEN=m
CONFIG_VIDEOBUF_DMA_CONTIG=m
+CONFIG_VIDEOBUF2_CORE=m
+CONFIG_VIDEOBUF2_MEMOPS=m
+CONFIG_VIDEOBUF2_VMALLOC=m
CONFIG_VIDEO_CAPTURE_DRIVERS=y
# CONFIG_VIDEO_ADV_DEBUG is not set
# CONFIG_VIDEO_FIXED_MINOR_RANGES is not set
@@ -1606,7 +1609,7 @@
CONFIG_VIDEO_HELPER_CHIPS_AUTO=y
# Miscelaneous helper chips
#
CONFIG_V4L_USB_DRIVERS=y
-# CONFIG_USB_VIDEO_CLASS is not set
+CONFIG_USB_VIDEO_CLASS=m
CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV=y
CONFIG_USB_GSPCA=m
# CONFIG_USB_M5602 is not set
@@ -1561,6 +1561,9 @@ CONFIG_MEDIA_TUNER_MC44S803=y
CONFIG_VIDEO_V4L2=y
CONFIG_VIDEOBUF_GEN=m
CONFIG_VIDEOBUF_DMA_CONTIG=m
+CONFIG_VIDEOBUF2_CORE=m
+CONFIG_VIDEOBUF2_MEMOPS=m
+CONFIG_VIDEOBUF2_VMALLOC=m
CONFIG_VIDEO_CAPTURE_DRIVERS=y
# CONFIG_VIDEO_ADV_DEBUG is not set
# CONFIG_VIDEO_FIXED_MINOR_RANGES is not set
@@ -1606,7 +1609,7 @@
CONFIG_VIDEO_HELPER_CHIPS_AUTO=y
# Miscelaneous helper chips
#
CONFIG_V4L_USB_DRIVERS=y
-# CONFIG_USB_VIDEO_CLASS is not set
+CONFIG_USB_VIDEO_CLASS=m
CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV=y
CONFIG_USB_GSPCA=m
# CONFIG_USB_M5602 is not set 加载驱动有一点顺序要求,如下:
[plain] view plaincopyprint?insmod /system/vendor/modules/videobuf2-core.ko
insmod /system/vendor/modules/videobuf2-memops.ko
insmod /system/vendor/modules/videobuf2-vmalloc.ko
insmod /system/vendor/modules/uvcvideo.ko
insmod /system/vendor/modules/videobuf2-core.ko
insmod /system/vendor/modules/videobuf2-memops.ko
insmod /system/vendor/modules/videobuf2-vmalloc.ko
insmod /system/vendor/modules/uvcvideo.ko
加载了驱动以后,插入USB Camera,看看/dev下面产生video的设备文件,如果没有产生,说明不成功,需要去查一下这个USB Camera是不是支持uvc,当然如果要条件一些参数,还得写一点具体设备的驱动控制。插入USB Camera打印及设备文件查看:
打印:
[plain]
root@android:/ # ls /dev/video*
/dev/video0
/dev/video1
root@android:/ #
root@android:/ #
root@android:/ # [ 75.718597] [fantasy] wrn dbs_check_cpu, 1227 : try to switch cpu freq to 336000
[ 80.103781] Line:520:check_reset_complete
[ 80.163617] usb 2-1: new high-speed USB device number 2 using sw-ehci
[ 80.223609] Line:520:check_reset_complete
[ 80.441143] uvcvideo: Found UVC 1.00 device USB 2.0 Camera (0c45:6341)
[ 80.472928] input: USB 2.0 Camera as /devices/platform/sw-ehci.1/usb2/2-1/2-1:1.0/input/input3
[ 81.118867] [fantasy] wrn dbs_check_cpu, 1227 : try to switch cpu freq to 240000
[ 82.477074] init: waitpid returned pid 2776, status = 00000000
[ 82.483021] init: untracked pid 2776 exited
root@android:/ #
root@android:/ #
root@android:/ # ls /dev/video*
[ 87.418713] [fantasy] wrn dbs_check_cpu, 1227 : try to switch cpu freq to 144000
/dev/video0
/dev/video1
/dev/video2
root@android:/ #
root@android:/ # ls /dev/video*
/dev/video0
/dev/video1
root@android:/ #
root@android:/ #
root@android:/ # [ 75.718597] [fantasy] wrn dbs_check_cpu, 1227 : try to switch cpu freq to 336000
[ 80.103781] Line:520:check_reset_complete
[ 80.163617] usb 2-1: new high-speed USB device number 2 using sw-ehci
[ 80.223609] Line:520:check_reset_complete
[ 80.441143] uvcvideo: Found UVC 1.00 device USB 2.0 Camera (0c45:6341)
[ 80.472928] input: USB 2.0 Camera as /devices/platform/sw-ehci.1/usb2/2-1/2-1:1.0/input/input3
[ 81.118867] [fantasy] wrn dbs_check_cpu, 1227 : try to switch cpu freq to 240000
[ 82.477074] init: waitpid returned pid 2776, status = 00000000
[ 82.483021] init: untracked pid 2776 exited
root@android:/ #
root@android:/ #
root@android:/ # ls /dev/video*
[ 87.418713] [fantasy] wrn dbs_check_cpu, 1227 : try to switch cpu freq to 144000
/dev/video0
/dev/video1
/dev/video2
root@android:/ #
接下来,我们修改一下android的camera hal层的控制,强制把设备文件指向video2,也就是这个USB Camera的设备文件,然后替换好这个库文件,运行camera apk,看看下面的效果截图吧!
<
补充:移动开发 , Android ,