USB camera validation with HUB in imx8

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

USB camera validation with HUB in imx8

1,434 Views
redwanmohamed
Contributor III

We are trying to test dual USB camera with imx8qxp board where we could test successfully with gstreamer when we connect to 2 different usb ports whereas when we connect the cameras via external hub it fails even though one camera at a time still works but not both cameras at a time

We tried to externally power the HUB as well without any luck. Any pointers would be helpful to move forward

0 Kudos
8 Replies

1,155 Views
diwakar2599
Contributor II

hi, i'm can't able to open dual usb camera at same time but it is working well for single usb camera .i have connected these usb camera through usb hub 3.0

This is the code i run in terminal  

import cv2

cap1 = cv2.VideoCapture(0)
cap2 = cv2.VideoCapture(1)

while True:
    ret1, frame1 = cap1.read()
    ret2, frame2 = cap2.read()

    if ret1:
        cv2.imshow('Camera 1', frame1)
    else:
        print('Error reading frame from camera 1')
        break

    if ret2:
        cv2.imshow('Camera 2', frame2)
    else:
        print('Error reading frame from camera 2')
        break

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap1.release()
cap2.release()
cv2.destroyAllWindows()

-------------

it shows following error message that :

1. not enough bandwidth for new state

2. not enough bandwidth for altsetting 11.

3. gstreamer warning : embedded video playback halted  ; module v4l2src1  reported : Failed to allocate required memory.

4. gstreamer warning : unable to start pipeline 

and  i have attached pic for your reference . please guide me how to connect dual usb camera at same time in imx8pic.jpg

0 Kudos

1,412 Views
redwanmohamed
Contributor III

Thanks Edward for the feedback. Will check on this and get back

Tags (1)
0 Kudos

1,417 Views
kef2
Senior Contributor IV

Hi

Many if not the most of USB cameras on the market are broken like this. Analyzing USB descriptor, which can be read using MS USB Device Viewer from MS SDK (usbview.exe), usually cameras reserve much more bandwidth than is necessary to send their video stream. Everything works well with single camera, or two such cameras connected to different USB host controllers, but one of them fails when both are connected via hubs to the same USB host controller. Windows/Linux checks if there's available bandwidth to grant bandwidth request. It won't play if not enough bandwidth. 

Is it high speed camera? For isochronous transfer your pr_dwMaxPayloadTransferSize, see probe/commit stuff, for single camera can be as high as 3072. Thats 3 microframes, 1024 bytes each, 8kHz rate, which turns to (3072-12/*header*/) * 8000Hz ~24MB per second. 2nd camera with the same pr_dwMaxPayloadTransferSize=3072 won't fit. Reserved bandwidth + overhead and there's no space for two cameras with pr_dwMaxPayloadTransferSize = 3072. For two cameras your pr_dwMaxPayloadTransferSize should be no more than 2517. For 3 - 2048, 4- 1600. These are experimental numbers, perhaps with different OS they can be little lower or higher, but they worked for me. To use more cameras I was reducing frame rate and probe/committing to different frame interval and max payload size, for each there should be corresponding interface descriptor with right endpoint descriptor for max payload of 3072, 2517, and so on. That all was used with uncompressed video. Compressed should be simpler, just don't reserve more bandwidth than is really required, think about other devices user may need to connect to the same HUB tree. 

Regards,

Edward

 

 

0 Kudos

1,191 Views
diwakar2599
Contributor II

yeah, Bro please tell me how to connect two usb camera at a same time in imx8 .and how to

lower the bandwidth ??

0 Kudos

1,182 Views
kef2
Senior Contributor IV

Perhaps it was bit unclear, but if camera requests a lot of bandwidth, you can fix it either 1) fixing camera firmware or 2) look for camera, which doesn't request so lot bandwidth.

Windows 7 allowed to check used bandwidth. If you can plug you camera to Windows 7 PC, look in Device Manager, root hub properties if I recall, it should show bandwidth used. Of course you should check it while video is on.

Using usbview.exe on Windows you may look deeper for what to expect from you camera. Perhaps Linux lsusb -vvv can help as well, I just haven't tried it myself. Look for Endpoint descriptors. There could be one or more isochronous transfer descriptors like this

 

          ===>Endpoint Descriptor<===
bLength:                           0x07
bDescriptorType:                   0x05
bEndpointAddress:                  0x81  -> Direction: IN - EndpointID: 1
bmAttributes:                      0x05  -> Isochronous Transfer Type, Synchronization Type = Asynchronous, Usage Type = Data Endpoint
wMaxPacketSize:                  0x1400 = 3 transactions per microframe, 0x400 max bytes
bInterval:                         0x01

^^ this one is for top isochronous USB HS bandwidth of 3 * 0x400 * 8000 = 24576000 bytes per second. If your camera doesn't have less thick EP descriptors, you can't use more than one of such camera on the same USB HS bus.  

Uncompressed VGA @30fps needs 640*480 * 2 * 30 = 18432000 B/s, clearly one such camera will fit. Obviously you can't have 2 such VGA cams at 30 fps on the same bus. 2xVGA @15fps should fit, but not 2xVGA @ 20fps. For more cameras you need less pixels, less fps or compressed stream. Of course there has to be right EP descriptor with wMaxPacketSize of 0x1347 , so that at least two cameras will fit, and those right descriptors should be selected to operate with.

0 Kudos

1,137 Views
diwakar2599
Contributor II

hi, i'm can't able to open dual usb camera at same time but it is working well for single usb camera .i have connected these usb camera through usb hub 3.0

This is the code i run in terminal  

import cv2

cap1 = cv2.VideoCapture(0)
cap2 = cv2.VideoCapture(1)

while True:
    ret1, frame1 = cap1.read()
    ret2, frame2 = cap2.read()

    if ret1:
        cv2.imshow('Camera 1', frame1)
    else:
        print('Error reading frame from camera 1')
        break

    if ret2:
        cv2.imshow('Camera 2', frame2)
    else:
        print('Error reading frame from camera 2')
        break

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap1.release()
cap2.release()
cv2.destroyAllWindows()

-------------

it shows following error message that :

1. not enough bandwidth for new state

2. not enough bandwidth for altsetting 11.

3. gstreamer warning : embedded video playback halted  ; module v4l2src1  reported : Failed to allocate required memory.

4. gstreamer warning : unable to start pipeline 

and  i have attached pic for your reference . please guide me how to connect dual usb camera at same time in imx8pic.jpg

0 Kudos

1,129 Views
kef2
Senior Contributor IV
  • 1. not enough bandwidth for new state
  • 2. not enough bandwidth for altsetting 11.

This should exactly mean that video frame size and frame rate lead to choosing endpoint descriptor, which leaves no spare bandwidth for another camera. If you are using USB SS camera and USB 3.0 HUB, then you should have no problems, provided host and device operate in SS mode instead of HS mode.

In HS mode you easily can reach bandiwth limitation, especially if camera doesn't care about other USB devices on the same USB bus and takes maximum available BW via wMaxPacketSize of 3x 1024 bytes. Can you show `lsusb -v` output? No picture please, text. Doesn't you camera provide lower frame size or frame rate format? If available, try choosing lower resolution and or frame rate.

0 Kudos

1,113 Views
diwakar2599
Contributor II

Thanks a lot  bro !.. as you said i have reduced my frame and tried with that its successfully working by python code. 

but if i run with the following command i get syntax error .could you please check these command what was the error in the following commad and help me solve this  issue.

 gst-launch-1.0 -v imxcompositor_g2d name=comp \ sink_0::xpos=0 sink_0::ypos=0 sink_0::width=320 sink_0::height=240 \ sink_1::xpos=0 sink_1::ypos=240 sink_1::width=320 sink_1::height=240 \ ! video/x-raw,format=RGB16 ! waylandsink \ v4l2src device=/dev/video5 ! video/x-raw,width=320,height=240 ! comp.sink_0 \ v4l2src device=/dev/video7 ! video/x-raw,width=320,height=240 ! comp.sink_1 

here, my usb camera are connected in video7, video5.

0 Kudos