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,看看下面的效果吧!
基本的通路是跑下來了,但是還是存在一些問題,比如要錄影以及拍照,筆者的USB Camera控制器是用的SN9C259,用的sensor是NT99140,這可能就是導致一些設定無法進行,造成失敗的原因,後面得繼續跟進一下這些問題,路途是艱難的,但是筆者相信前景是光明的,繼續加油!