Monday, 4 July 2011

Multiple webcams on ZoneMinder (Part 4)

Some success!

The USB 3.0 route turns out to be a slight misunderstanding. The key factors involved are :
1) Bandwidth required by each camera, and :
2) Number of USB 2.0 controllers.

It appears that USB 1.1, 2.0, and 3.0 subsystems are basically independent of each other.
A USB 2.0 motherboard has a usb 1.1 and a usb 2.0 controller. The *total* bandwidth for the usb2.0 controller is 480M, and any 2.0 devices share this bandwidth (whichever USB port or hub they are on). USB 1.1 devices similarly share a single 1.1 controller (often labelled a legacy controller).

The usb 3 hub I have seems to have a usb 3.0 hub + a usb 2.0 hub (+ probably a usb 1.1 hub).
Connecting two 2.0 devices (direct, of through the hub) shares the bandwidth of a single 2.0 controller on the USB 3.0 card.

Using the uvcvideo bandwidth quirks mode, I can connect two YUUV webcams to a single usb 2.0 controller - any more fail. This is true whether the port is a standard USB 2.0 hub in a 2.0 motherboard socket, or a USB 3.0 hub in a USB card.

To connect more cameras, add more 2.0 controllers. These can be in a USB 3.0 PCI-e card, or a plain USB 2.0 PCI card, or anything else. Apparently the USB 2.0 controllers included on the usb 3 chips are slightly better as they don't have any other demands on them and only have to deal with the usb 2 traffic.


NOTE : the PS3eye camera has a special 'bayer' mode that uses bandwidth more efficiently - if the driver can handle it. This allows windows users to plug in multiple PS3 eye cameras (see Code Laboratories or iPisoft) I haven't found a similar linux driver yet.

So far, I have been able to display 6 cameras simultaneously -
4 x Cheap USB 2.0 webcams - 640x480 at 25fps - YUYV, PAL
2 x PS3 eye cams - 640x480 at 12fps - YUYV, PAL - some breakup.

I have two cams on a USB 3.0 hub, to a USB 3.0 PCI-E card.
Two cams direct to motherboard controller ports.
Two ps3 eyes on USB 2.0 hub to a USB2.0 PCI controller card.

lsusb -t
davidr@hgwells:~$ lsusb -t
6-1:1.0: No such file or directory
/:  Bus 06.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
    |__ Port 3: Dev 3, If 0, Class=hub, Driver=hub/4p, 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 4: Dev 5, If 0, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M
        |__ Port 4: Dev 5, If 1, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M
/:  Bus 05.Port 1: Dev 1, Class=root_hub, Driver=ohci_hcd/2p, 12M
/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=ohci_hcd/3p, 12M
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=ohci_hcd/8p, 12M
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/5p, 480M
    |__ Port 4: Dev 2, If 0, Class=vend., Driver=ov534, 480M
    |__ Port 4: Dev 2, If 1, Class=audio, Driver=snd-usb-audio, 480M
    |__ Port 4: Dev 2, If 2, Class=audio, Driver=snd-usb-audio, 480M
    |__ Port 5: Dev 3, If 0, Class=vend., Driver=ov534, 480M
    |__ Port 5: Dev 3, If 1, Class=audio, Driver=snd-usb-audio, 480M
    |__ Port 5: Dev 3, If 2, Class=audio, Driver=snd-usb-audio, 480M
/:  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 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 4: Dev 5, If 0, Class=hub, Driver=hub/4p, 12M
            |__ Port 1: Dev 6, If 0, Class=HID, Driver=usbhid, 12M
            |__ Port 1: Dev 6, If 1, Class=HID, Driver=usbhid, 12M
            |__ Port 4: Dev 7, If 0, Class=hub, Driver=hub/4p, 12M
                |__ Port 2: Dev 8, If 0, Class=HID, Driver=usbhid, 12M
                |__ Port 2: Dev 8, If 1, Class=HID, Driver=usbhid, 12M
                |__ Port 3: Dev 9, If 0, Class=HID, Driver=wacom, 1.5M
davidr@hgwells:~$ 

2 comments:

dedieko said...

Hello sir,
Let me say that I have read all the 4 parts of your journey, and I must say, it's very informative

I'm on the same boat as you, as I'm currently planning to utilize zoneminder + webcam(s) + usb extender

I've managed to overcome the voltage drop eaten by the cable due to the cable length, by adding external powered usb hub

The question is: If we reduce the frame rate to 15 or so, frame size 320 x 240, and use BW image, will that help to reduce bandwidth consumption of your webcam?

Renoir said...

I did try reducing the zonealarm FPS to 15, then 3, then 1 - but it didn't seem to make any difference to the bandwidth. Also changing size to 320x240. I didn't try BW.
I think you could try to change the v4l settings to try and reduce bandwidth - that might work (using v4lconf )?
Adding extra USB2 or USB3 controllers is the only real way to add bandwidth.