Saturday, January 16, 2010

linux - cheapo usb camera/webcam

links
Video: use and settings (not good for compile instructions)
Blog: making it work with Flash


getting started (FAIL)

# udevmonitor

the program '/bin/bash' called 'udevmonitor', it should use 'udevadm monitor ', this will stop working in a future release monitor will print the received events for:
UDEV the event which udev sends out after rule processing
UEVENT the kernel uevent
UEVENT[1263672227.910603] add /class/usb_device/usbdev1.2 (usb_device)
UEVENT[1263672227.910786] add /class/usb_endpoint/usbdev1.2_ep00 (usb_endpoint)


# lsusb

Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 093a:010e Pixart Imaging, Inc. Digital camera, CD302N/Elta Medi@ digi-cam/HE-501A
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub


So the kernel sees the camera. We have a $2 Pixart CD302N/HE-501A (ID 093a:010e) camera. How do we capture from this piece of junk?

Software
A simple command line interface for the camera will be spcagui ,once the camera is initialized, if the camera uses the gspca module to drive the camera. How do I determine the right module for my CD302N/HE-501A (ID 093a:010e) camera?

Navigated to Linux Kernel driver database and found that the 093a:010e camera uses gspca module. Checking the kernel to see if it's activated:
# modprobe gspca
FATAL: Module gspca not found.

So, it's not installed. Would the Kernel allow it, if we had it?
# cd /etc
# grep -rn "CONFIG_USB" *
udev/rules.d/30-scanners.rules:25:# For Linux >= 2.6.22 without CONFIG_USB_DEVICE_CLASS=y

So, it appears I won't have to modify the kernel, but I will have to build a module (in Windowspeak, a "driver") to load into the kernel. If I'd had to change the kernel from "n" to "y", I would go here and accomplish all this. But I don't have to change the kernel.

The documentation above noted the GSPCA module relies on libv4l, so it must also be checked:
# netpkg libv4l
[I][l] Found installed libv4l-0.5.8-i486-60.1.tgz on the repository
what should I do ?
1) reinstall
2) download
3) skip
There and installed. So only the source and patch for the GSPCA module needs to be found somewhere.
  • At this site appears gspcav1-20071224.tar.gz is the most recent version.

  • At this site appears gspcapatch.gz is a 2009 version.

Unzip them both into the same folder, then patch
$ patch<.gspcapatch
Following the patch, root-up and run their excellent compilation script
# ./gspca_build
The module will be created. Then just modprobe it and check to see if it loaded
# modprobe gspca
# lsmod
gspca          601572  0
videodev       23680   1   gspca
v4l1_compat   9732   1   videodev

So, all are loaded. I plugged-in the camera, and checked in /dev, and found that there was no /dev/video0, and so there was no way to find the camera. This is a well known bug, but the standard fixes, such as reloading the module, haven't worked.

A HA!
# modinfo gspca
filename: /lib/modules/2.6.28.7/kernel/drivers/usb/media/gspca.ko
license: GPL
description: GSPCA/SPCA5XX USB Camera Driver
author: Michel Xhaard
--HUGE OUTPUT--

# modinfo gspca |grep 93A
alias: usb:v093Ap2463d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap2472d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap260Fd*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap260Ed*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap2608d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap2603d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap2601d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap2600d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap2470d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap2460d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap2471d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap2468d*dc*dsc*dp*ic*isc*ip*
alias: usb:v093Ap050Fd*dc*dsc*dp*ic*isc*ip*
Notice that there is no 093a:010e in the list of these Pixart cameras. So, we are definitely going to need to add another module or patch the current one further. The OS needs to create the node/dev/video0 or else software that shows images can't interact with the camera.

mr97310a.c
Mr97310a.c, may be the patch. It's described at the Linux Database. Scrolling down, the site seems to indicate that the 093a:010e Pixart Imaging, Inc. Digital camera, CD302N/Elta Medi@ digi-cam/HE-501A requires this "C" module to be patched into the gspca module when compiling it, however this patch cannot be downloaded or copied and pasted. Alternatively, perhaps it will be a module named gspca_mr97310a. I can't figure out how to build this from the documentation.

Since I don't want, or don't have the information, to go to that trouble, I'm going to handcode what the module source will need to find the hardware, and then recompile the module:

In gspa.mod.c, added:
MODULE_ALIAS("usb:v093Ap010Ed*dc*dsc*dp*ic*isc*ip*");

In gspa_core.c, added line 413:
{PAC7310},
added Line 613:
{PAC7310, "Pixart Kaibo 7310"},
added Line 628:
{USB_DEVICE(0x093a, 0x010e)}, /* Pixart Kaibo 7310 */
added Lines @ 4120:
case 0x010e:
spca50x->desc = PAC7310;
spca50x->bridge = BRIDGE_PAC7311;
spca50x->sensor = SENSOR_PAC7311;
break;

Then, took out the old module and recompiled and installed:
# modprobe -r gspca videodev v4l1_compat
# rm /lib/modules/2.6.28.7/kernel/drivers/usb/media/gspca.ko
# cd /home/foo/Download/gspcav1-20071224
# ./gspca_build

So, after these steps, and a # modprobe gspca and plugging in the camera, we get:
[dev]# find . -name "video*"
./video0
./v4l/video0
./.udev/names/video0

Great! The system is seeing the camera, and creating the /dev/video0 and associated nodes. Let's see if we can get a picture. No. It may be that the 7311 bridge is not going to work properly with a 7310 camera:
$ spcagui
SpcaGui version: 0.3.5 date: 18 September 2005
video device /dev/video0
ERROR opening V4L interface
: Input/output error

Reinstalling the driver, with modprobe yields the same result. It appears I'm very close, but that the bridge for the 7311 is not going to work with the 7310. Not sure what to do without that 7310 bridge, but at least the process is confirmed for compiling the driver and recognizing the camera. More to come.

No comments: