Use gstreamer to open two USB cameras, Failed to allocate required memory

Open the first camera in the terminal, it can display normally.

$ gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw, width=640,height=480 ! xvimagesink
Setting pipeline to PAUSED …
Pipeline is live and does not need PREROLL …
Setting pipeline to PLAYING …
New clock: GstSystemClock

Open the second camera in the terminal and immediately exit abnormally
$ gst-launch-1.0 v4l2src device=/dev/video1 ! video/x-raw, width=640,height=480 ! xvimagesink
Setting pipeline to PAUSED …
Opening in BLOCKING MODE
Pipeline is live and does not need PREROLL …
Setting pipeline to PLAYING …
New clock: GstSystemClock
libv4l2: error turning on stream: No space left on device
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Failed to allocate required memory.
Additional debug info:
gstv4l2src.c(658): gst_v4l2src_decide_allocation (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
Buffer pool activation failed
Execution ended after 0:00:00.062916178
Setting pipeline to PAUSED …
Setting pipeline to READY …
Setting pipeline to NULL …
Freeing pipeline …

Hi @guo.chsh,

This problem is related to the max bandwidth that can be obtained through the USB2.0 ports. The UVC driver fails to calculate the bandwidth from several image formats. You may want to use the USB3.0 port. Please refer to the following thread

Also, as an alternative you can use a patch to modify the default UVC driver and ‘hack’ the calculation process. Please refer to the following guide:

Patch_to_support_4_USB_cameras

Regards,
Fabian
www.ridgerun.com

I use jetson nano, all four USB ports are usb3.0

If two USB3 cameras are using two separate USB3 root HUBs, then all should be good. If you have two USB3 cameras on a single root HUB (such as an external HUB with the cameras, and then the HUB using a single USB3 port on the Jetson), then the cameras must share the bandwidth (which some cameras do not like doing).

If you want to show what your USB layout is relative to HUBs, then use the command “lsusb -t”. Note that each device in the tree will list a “Class=”. Several devices may eventually converge on the same “root_hub”, in which case they are sharing bandwidth. Are your cameras sharing a single root HUB?

~$ lsusb -t
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=tegra-xusb/4p, 5000M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 5000M
|__ Port 1: Dev 11, If 0, Class=Video, Driver=uvcvideo, 5000M
|__ Port 1: Dev 11, If 1, Class=Video, Driver=uvcvideo, 5000M
|__ Port 3: Dev 10, If 0, Class=Hub, Driver=hub/4p, 5000M
|__ Port 4: Dev 7, If 1, Class=Video, Driver=uvcvideo, 5000M
|__ Port 4: Dev 7, If 0, Class=Video, Driver=uvcvideo, 5000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=tegra-xusb/5p, 480M
|__ Port 2: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 3: Dev 7, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 3: Dev 9, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
|__ Port 3: Dev 9, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M
|__ Port 2: Dev 8, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
|__ Port 3: Dev 3, If 0, Class=Wireless, Driver=btusb, 12M
|__ Port 3: Dev 3, If 1, Class=Wireless, Driver=btusb, 12M

Information obtained from desktop computers. The desktop computer can display two usb videos at the same time.
~$ lsusb -t
/: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 10000M
/: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/8p, 5000M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 5000M
|__ Port 4: Dev 4, If 3, Class=Video, Driver=uvcvideo, 5000M
|__ Port 4: Dev 4, If 1, Class=Video, Driver=uvcvideo, 5000M
|__ Port 4: Dev 4, If 4, Class=Vendor Specific Class, Driver=, 5000M
|__ Port 4: Dev 4, If 2, Class=Video, Driver=uvcvideo, 5000M
|__ Port 4: Dev 4, If 0, Class=Video, Driver=uvcvideo, 5000M
|__ Port 3: Dev 3, If 0, Class=Video, Driver=uvcvideo, 5000M
|__ Port 3: Dev 3, If 1, Class=Video, Driver=uvcvideo, 5000M
|__ Port 4: Dev 5, If 0, Class=Video, Driver=uvcvideo, 5000M
|__ Port 4: Dev 5, If 1, Class=Video, Driver=uvcvideo, 5000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/16p, 480M
|__ Port 3: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 2: Dev 5, If 0, Class=Human Interface Device, Driver=usbhid, 12M
|__ Port 2: Dev 5, If 1, Class=Human Interface Device, Driver=usbhid, 12M
|__ Port 1: Dev 4, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M
|__ Port 1: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
|__ Port 9: Dev 3, If 0, Class=Wireless, Driver=btusb, 12M
|__ Port 9: Dev 3, If 1, Class=Wireless, Driver=btusb, 12M

The PC probably has more ability to consume the data and more buffer space. Someone else may be able to tell you how to adjust USB buffer space, but having two cameras on a single USB3 gen. 1 HUB (the 5000M in tree view) will be insufficient in most cases on the Jetson.

Note that even though your desktop seems to be using the 5000M entry, it also has more root HUBs, and at least one of those is 10000M…double the bandwidth of the 5000M. That PC has to have a lot higher data throughput internally than what you will get from the Jetsons. I cannot give you a good answer, but perhaps someone who has worked with multiple cameras on a single root HUB can offer ways to tune the port, e.g., increased buffer size.