vcam test === 環境 === ubuntu 16.04.3 lenove x220 有一個前鏡頭 核心版本 4.15.0-58-generic 測試輸出 === ```bash= schwarm@schwarm:~/sysprog21/vcam$ make cc -O2 -Wall -Wextra -pedantic -std=c99 -o vcam-util vcam-util.c make -C /lib/modules/4.15.0-58-generic/build M=/home/schwarm/sysprog21/vcam modules make[1]: Entering directory '/usr/src/linux-headers-4.15.0-58-generic' CC [M] /home/schwarm/sysprog21/vcam/module.o CC [M] /home/schwarm/sysprog21/vcam/control.o CC [M] /home/schwarm/sysprog21/vcam/device.o CC [M] /home/schwarm/sysprog21/vcam/videobuf.o CC [M] /home/schwarm/sysprog21/vcam/fb.o LD [M] /home/schwarm/sysprog21/vcam/vcam.o Building modules, stage 2. MODPOST 1 modules CC /home/schwarm/sysprog21/vcam/vcam.mod.o LD [M] /home/schwarm/sysprog21/vcam/vcam.ko make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-58-generic' schwarm@schwarm:~/sysprog21/vcam$ ls control.c device.o Makefile README.md vcam.mod.o videobuf.h control.h fb.c module.c udev vcam.o videobuf.o control.o fb.h module.o vcam.h vcam-util device.c fb.o modules.order vcam.ko vcam-util.c device.h LICENSE Module.symvers vcam.mod.c videobuf.c schwarm@schwarm:~/sysprog21/vcam$ sudo insmod vcam.ko [sudo] password for schwarm: schwarm@schwarm:~/sysprog21/vcam$ ls | grep /proc/fb schwarm@schwarm:~/sysprog21/vcam$ ls | grep /proc schwarm@schwarm:~/sysprog21/vcam$ ls /proc/ | grep fb. vcamfb1 schwarm@schwarm:~/sysprog21/vcam$ ls control.c device.o Makefile README.md vcam.mod.o videobuf.h control.h fb.c module.c udev vcam.o videobuf.o control.o fb.h module.o vcam.h vcam-util device.c fb.o modules.order vcam.ko vcam-util.c device.h LICENSE Module.symvers vcam.mod.c videobuf.c schwarm@schwarm:~/sysprog21/vcam$ sudo ./vcam-util -l Available virtual V4L2 compatible devices: 1. vcamfb1(640,480,rgb24) -> /dev/video1 schwarm@schwarm:~/sysprog21/vcam$ sudo apt install v4l-utils Reading package lists... Done Building dependency tree Reading state information... Done v4l-utils is already the newest version (1.10.0-1). 0 upgraded, 0 newly installed, 0 to remove and 527 not upgraded. schwarm@schwarm:~/sysprog21/vcam$ sudo v4l2-compliance -d /dev/video1 -f Driver Info: Driver name : vcam Card type : vcam Bus info : platform: virtual Driver version: 4.15.18 Capabilities : 0x85200001 Video Capture Read/Write Streaming Extended Pix Format Device Capabilities Device Caps : 0x05200001 Video Capture Read/Write Streaming Extended Pix Format Compliance test for device /dev/video1 (not using libv4l2): Required ioctls: test VIDIOC_QUERYCAP: OK Allow for multiple opens: test second video open: OK test VIDIOC_QUERYCAP: OK test VIDIOC_G/S_PRIORITY: OK Debug ioctls: test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported) Input ioctls: test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported) test VIDIOC_G/S/ENUMINPUT: OK test VIDIOC_G/S_AUDIO: OK (Not Supported) Inputs: 1 Audio Inputs: 0 Tuners: 0 Output ioctls: test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported) Outputs: 0 Audio Outputs: 0 Modulators: 0 Input/Output configuration ioctls: test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported) Test input 0: Control ioctls: test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported) test VIDIOC_QUERYCTRL: OK (Not Supported) test VIDIOC_G/S_CTRL: OK (Not Supported) test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported) test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported) test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 0 Private Controls: 0 Format ioctls: test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK test VIDIOC_G_FBUF: OK (Not Supported) test VIDIOC_G_FMT: OK test VIDIOC_TRY_FMT: OK test VIDIOC_S_FMT: OK test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported) test Composing: OK (Not Supported) test Scaling: OK (Not Supported) Codec ioctls: test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported) Buffer ioctls: test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK Test input 0: Stream using all formats: test MMAP for Format RGB3, Frame Size 640x480@59.94 Hz: Stride 1920, Field None: OK test MMAP for Format RGB3, Frame Size 640x480@0.00 Hz: Stride 1920, Field None: OK Total: 44, Succeeded: 44, Failed: 0, Warnings: 0 schwarm@schwarm:~/sysprog21/vcam$ sudo v4l2-ctl -d /dev/videoX --all Failed to open /dev/videoX: No such file or directory schwarm@schwarm:~/sysprog21/vcam$ sudo v4l2-ctl -d /dev/video1 --all Driver Info (not using libv4l2): Driver name : vcam Card type : vcam Bus info : platform: virtual Driver version: 4.15.18 Capabilities : 0x85200001 Video Capture Read/Write Streaming Extended Pix Format Device Capabilities Device Caps : 0x05200001 Video Capture Read/Write Streaming Extended Pix Format Priority: 2 Video input : 0 (vcam_in 0: ok) Format Video Capture: Width/Height : 640/480 Pixel Format : 'RGB3' Field : None Bytes per Line : 1920 Size Image : 921600 Colorspace : sRGB Transfer Function : Default YCbCr Encoding : Default Quantization : Default Flags : Streaming Parameters Video Capture: Frames per second: 29.970 (30000/1001) Read buffers : 1 schwarm@schwarm:~/sysprog21/vcam$ una unalias unattended-upgrade uname unattended-upgrades schwarm@schwarm:~/sysprog21/vcam$ uname -r 4.15.0-58-generic schwarm@schwarm:~/sysprog21/vcam$ ``` 截圖輸出 === ![](https://i.imgur.com/v1PpiuS.png) ![](https://i.imgur.com/Qab99jr.png) ![](https://i.imgur.com/j0tJXp6.png) ![](https://i.imgur.com/0lPDEZi.png) ![](https://i.imgur.com/Xk5vZKb.png) https://github.com/jserv/vcam?fbclid=IwAR2cci6fKfPx0M-wWvUYvK0QEP2hrBix3csEDMCKhu-bukT-2aL2_x8eJlM 徵求測試: vcam 是個針對 Linux 核心開發的虛擬攝影機裝置,全部程式碼僅 1 千 5 百行,從而可理解 V4L2 (video fro Linux APIs, version 2) 的使用和 Linux 多媒體架構。開發一個虛擬的攝影機裝置除了理解 Linux 核心設計外,也有資訊安全的幫助,例如你可以安插相關程式碼,紀錄有哪些應用程式偷偷啟動攝影機,但過程中又不會揭露真正的隱私。 測試方法: 依據下方取得原始程式碼並依據 READMD.md 指示編譯,注意不能在 User-mode Linux 中測試; 承上,確認核心模組能夠載入到 Linux 核心中,並留意到 /dev 目錄應該要出現 video? 和 vcamctl 這兩個裝置節點,其中 "?" 表示數字; 執行 vcam-util 並確認虛擬攝影機裝置出現在列表中; 執行 v4l2-compliance 和 v4l2-ctl 確保本裝置得以被 V4L2 識別並回傳註冊資訊; 檢查 /dev 下是否有 framebuffer 裝置; 用 xawtv 或 VLC 開啟上述建立的 /dev/video? 裝置; 請在下方留言,告知測試結果和相關的核心版本一類的資訊,謝謝! 檢查 dmesg 的輸出是否有 vcamfb 裝置被建立的訊息 (記得確認 printk 的 log level) 參照 https://medium.com/@petehouston/play-webcam-using-mplayer-fb4b8729ff88的說明,用 MPlayer 開啟這個建立的 /dev/video? 裝置 http://zylix666.blogspot.com/2008/07/kernel-message-level.html 互動問題 === 1. 請告知 V4L 工具的資訊: dpkg -l | grep v4l-utils dpkg -l | grep v4l-utils 1.10.0-1 ![](https://i.imgur.com/7R7rdR0.jpg) 2. 有沒有看到 /dev/fb? 被建立? 有 /dev/fb0 ![](https://i.imgur.com/Rb9sBkE.jpg) 3. 檢查 dmesg 的輸出是否有 vcamfb 裝置被建立的訊息 (記得確認 printk 的 log level) vcam有訊息沒被正確建立 ![](https://i.imgur.com/EhDOYAl.png) ```txt= [ 802.946610] vcam: loading out-of-tree module taints kernel. [ 802.946710] vcam: module verification failed: signature and/or required key missing - tainting kernel [ 986.045816] usb 1-1.4: new full-speed USB device number 52 using ehci-pci ``` 4. 試著 cat /dev/urandom > /dev/vcamfb1 (不要立刻關閉,放著觀察) 之後再用 VLC 一類的播放器開啟 /dev/video? (新建立的裝置節點) cat /dev/urandom是亂碼 ![](https://i.imgur.com/ZV7876n.jpg) 沒有/dev/vcamfb1 5. 參照 https://medium.com/@petehouston/play-webcam-using-mplayer-fb4b8729ff88的說明,用 MPlayer 開啟這個建立的 /dev/video? 裝置 學習點 === kernel訊息印在dmesg 用log level控制不同重要程度的printk顯示 ![](https://i.imgur.com/TzgULhD.png) cat /proc/sys/kernel/printk log_level設定顯示dsmeg不同重要程度訊息 To change your current console_loglevel simply write to this file, so in order to get all messages printed to the console do a simple **echo 8 > /proc/sys/kernel/printk** #### set console_loglevel to print KERN_WARNING (4) or more severe messages **dmesg -n 5** ![](https://i.imgur.com/oCwuonU.png) https://elinux.org/Debugging_by_printing#Log_Levels ![](https://i.imgur.com/EhDOYAl.png) vcam未被正確建立 我想寫 linux下PS3 eye camera multiple driver (windows有在賣多攝影機版本的) ![](https://i.imgur.com/yai5pFi.png) 延伸 === Dynamic Kernel Module Support out of tree build 工作原理 ovc https://github.com/osrf/ovc PS3 eye multiple driver https://alexpopovich.wordpress.com/ https://hackmd.io/CEmoCLFkRHOYGZiw513fSw