Sunday, 3 July 2011

Multiple webcams on ZoneMinder

Part 2:
Continuing the webcam saga (see part 1)

USB 1.1 and USB 2.0
I was incorrect in my earlier post. Modern motherboards usually have two usb controllers: a USB 2.0 controller and a 'legacy' USB 1.1 controller. Devices on each port are automatically switched to the right controller, so the problem of one usb 1 device slowing down the whole usb system does not occur.

I suspect something similar is implemented on most usb hubs - my USB 2.0 hub seems to cope fine with a mix of 1.1 and 2.0 devices.

Due to the wording of the USB 2.0 spec, some USB 1.1 webcams are labelled as USB 2.0 - despite the fact that they only connect at 12Mb (usb1.1). This is the case for two of my older webcams - a Targus and a Creative Live! cam both only connect at 1.1 speeds.

USB 3.0
Although Linux does have support for usb3 cards there is a bug in the current Ubuntu 'Natty Narwhal' kernel that means that USB 3.0 hubs may only be recognised as USB 2.0 hubs - you can see them using
lusub -t
connecting at 480M (usb 2.0).
This post suggested that a later version of the kernel would recognise the usb 3.0 hub properly.
I re-installed with the latest alpha version 11.10 (Oneiric Ocelot) which includes a later kernel. It now recognises the hub as 5000M.

Webcam USB Bandwidth
Some research on webcam USB bandwidth turned up a useful trick. Webcams request a whole load of bandwidth, usually more than they need.
Symptoms were fairly easy to spot: Opening one camera with
xawtv -v 1 -c /dev/video0
and at the same time opening /dev/video1 in another terminal led to
libv4l2: error turning on stream: No space left on device
VIDIOC_STREAMON - Unable to start capture: No space left on device
fps is set to 1/30
libv4l2: error turning on stream: Device or resource busy
VIDIOC_STREAMON - Unable to start capture: Device or resource busy

This post and this post gave me some useful pointers. The uvcvideo kernel module can be set to ignore the requested bandwidth, and to calculate the right bandwidth. Try:
sudo rmmod uvcvideo
sudo modprobe uvcvideo quirks=128
This will be reset every reboot. If this works, create the following file:
sudo vi /etc/modprobe.d/uvcvideo.conf 
containing the line:
options uvcvideo quirks=128

My Hardware setup
My new hardware - in case anyone wants to follow in my footsteps:
Transcend PCI Express Interface USB 3.0 Dual Expansion Card

Tsunami SSU34 100mm USB 3.0 4 Ports Hub

Webcam with Microphone for XP Vista PC Laptop MSN Skype

Output from lsusb :
davidr@hgwells:~$ lsusb -t
/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 5000M
    |__ Port 2: Dev 2, If 0, Class=hub, Driver=hub/4p, 5000M
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
    |__ Port 2: Dev 2, If 0, Class=hub, Driver=hub/4p, 480M
        |__ Port 1: Dev 3, If 0, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M
        |__ Port 1: Dev 3, If 1, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M
        |__ Port 2: Dev 4, If 0, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M
        |__ Port 2: Dev 4, If 1, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M
        |__ Port 3: Dev 5, If 0, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M
        |__ Port 3: Dev 5, If 1, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M
        |__ Port 4: Dev 6, If 0, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M
        |__ Port 4: Dev 6, If 1, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ohci_hcd/8p, 12M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/8p, 480M
    |__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/4p, 480M
        |__ Port 4: Dev 3, If 0, Class=hub, Driver=hub/4p, 12M
            |__ Port 1: Dev 4, If 0, Class=HID, Driver=usbhid, 12M
            |__ Port 1: Dev 4, If 1, Class=HID, Driver=usbhid, 12M
            |__ Port 4: Dev 5, If 0, Class=hub, Driver=hub/4p, 12M
                |__ Port 2: Dev 6, If 0, Class=HID, Driver=usbhid, 12M
                |__ Port 2: Dev 6, If 1, Class=HID, Driver=usbhid, 12M
                |__ Port 3: Dev 7, If 0, Class=HID, Driver=wacom, 1.5M
davidr@hgwells:~$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB
Bus 003 Device 002: ID 2109:3431  
Bus 004 Device 002: ID 2109:0810  
Bus 001 Device 003: ID 05e3:0604 Genesys Logic, Inc. USB 1.1 Hub
Bus 003 Device 003: ID 090c:937b Feiya Technology Corp. Silicon Motion Camera
Bus 003 Device 004: ID 090c:937b Feiya Technology Corp. Silicon Motion Camera
Bus 003 Device 005: ID 090c:937b Feiya Technology Corp. Silicon Motion Camera
Bus 003 Device 006: ID 090c:937b Feiya Technology Corp. Silicon Motion Camera
Bus 001 Device 004: ID 046d:c049 Logitech, Inc. G5 Laser Mouse
Bus 001 Device 005: ID 05f3:0081 PI Engineering, Inc. Kinesis Integrated Hub
Bus 001 Device 006: ID 05f3:0007 PI Engineering, Inc. Kinesis Advantage PRO MPC/USB Keyboard
Bus 001 Device 007: ID 056a:0013 Wacom Co., Ltd Graphire 3 4x5

7 comments:

Abacaxi said...

did you ever get your system to work?

Abacaxi said...

Did you ever get your set to work with zoneminder?

Unknown said...

More in part 3
and part 4

Unknown said...

mmm. does this method work if I want to connect 4 webcams to the same usb-hub?. Thanks!

Unknown said...

USB 2.0 just doesn't have the bandwidth needed for multiple cameras. One hub can support one or two cameras max. The PS3 eye camera has a compression chip that reduces bandwidth and allows up to 4 : however, drivers are only available for windows. Best solution is to buy some cheap USB cards - each card is a new usb subsystem that supports more cameras. I bought two USB3.0 cards for £10 each.

Unknown said...

On I proprietary portable device using a Ti OMAP3530, two on-board USB hubs, I have managed to get 4 cameras streaming simultaneously. Two of the cameras were paralleled using an external powered hub. All cameras connect via one of the on-board hubs to the OMAP3530's USB controller, the other hub is used by a USB Wifi modem. All the camera streams are sent to a network client via WLAN. Used quirk 128 on the v4L driver. Caveat - does not work with MS Lifecam Studio which hogs all bandwidth without the quirk, but won't work with it.

/Paul

Unknown said...

Nice work. I'm still waiting for usb3 cameras to come out - they'll be capable of much better frame rates and resolutions, since the sensors are so much better nowadays. e.g. my iphone has 8MP camera, but webcams struggle at 1280x1024!