Failed to allocate memory for four usb cameras

Hi,

I want to capture video (320x240) from 4 usb cameras simultaneously on TX2 system. Firstly, I am trying to use camera-viewer to open 4 usb cameras for a quick test. But it is failed to allocate memory when opening the third camera. The 4 cameras are USB2.0 and connected to the TX2 with a USB 3.0 hub. Any suggestions for using multiple usb camera on TX2? Thanks.

Below is the log from the camera-viewer app:
./camera-viewer --width=320 --height=240 --camera=/dev/video3
[gstreamer] initialized gstreamer, version 1.14.5.0
[gstreamer] gstCamera attempting to initialize with GST_SOURCE_NVARGUS, camera /dev/video3
[gstreamer] gstCamera pipeline string:
v4l2src device=/dev/video3 ! video/x-raw, width=(int)320, height=(int)240, format=YUY2 ! videoconvert ! video/x-raw, format=RGB ! videoconvert !appsink name=mysink
[gstreamer] gstCamera successfully initialized with GST_SOURCE_V4L2, camera /dev/video3
camera-viewer: successfully initialized camera device
width: 320
height: 240
depth: 24 (bpp)
[OpenGL] glDisplay – X screen 0 resolution: 1280x720
[OpenGL] glDisplay – display device initialized
[gstreamer] opening gstCamera for streaming, transitioning pipeline to GST_STATE_PLAYING
[gstreamer] gstreamer changed state from NULL to READY ==> mysink
[gstreamer] gstreamer changed state from NULL to READY ==> videoconvert1
[gstreamer] gstreamer changed state from NULL to READY ==> capsfilter1
[gstreamer] gstreamer changed state from NULL to READY ==> videoconvert0
[gstreamer] gstreamer changed state from NULL to READY ==> capsfilter0
[gstreamer] gstreamer changed state from NULL to READY ==> v4l2src0
[gstreamer] gstreamer changed state from NULL to READY ==> pipeline0
[gstreamer] gstreamer changed state from READY to PAUSED ==> videoconvert1
[gstreamer] gstreamer changed state from READY to PAUSED ==> capsfilter1
[gstreamer] gstreamer changed state from READY to PAUSED ==> videoconvert0
[gstreamer] gstreamer changed state from READY to PAUSED ==> capsfilter0
[gstreamer] gstreamer stream status CREATE ==> src
[gstreamer] gstreamer changed state from READY to PAUSED ==> v4l2src0
[gstreamer] gstreamer changed state from READY to PAUSED ==> pipeline0
[gstreamer] gstreamer msg new-clock ==> pipeline0
[gstreamer] gstreamer changed state from PAUSED to PLAYING ==> videoconvert1
[gstreamer] gstreamer changed state from PAUSED to PLAYING ==> capsfilter1
[gstreamer] gstreamer changed state from PAUSED to PLAYING ==> videoconvert0
[gstreamer] gstreamer changed state from PAUSED to PLAYING ==> capsfilter0
[gstreamer] gstreamer changed state from PAUSED to PLAYING ==> v4l2src0
[gstreamer] gstCamera onEOS
[gstreamer] gstreamer stream status ENTER ==> src
[gstreamer] gstreamer msg stream-start ==> pipeline0
[gstreamer] gstreamer v4l2src0 ERROR Failed to allocate required memory.
[gstreamer] gstreamer Debugging info: gstv4l2src.c(658): gst_v4l2src_decide_allocation (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
Buffer pool activation failed
[gstreamer] gstreamer v4l2src0 ERROR Internal data stream error.
[gstreamer] gstreamer Debugging info: gstbasesrc.c(3055): gst_base_src_loop (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
streaming stopped, reason not-negotiated (-4)
[gstreamer] gstreamer changed state from READY to PAUSED ==> mysink
camera-viewer: camera open for streaming
[gstreamer] gstCamera failed to capture frame
camera-viewer: failed to capture RGBA image

Hi,
You need to use USB3 cameras to get 5Gbps bancwidth.

Here is s similar post:

Hi @bryanmok,

If you need to use 4 usb cameras without changing to usb 3.0, you can use a workaround to “hack” the uvc-video driver. Find instructions in the following guide:

Installation_Guide#Patch_to_support_4_USB_cameras

Please notice probably the patch will not apply directly, but you can manually add the lines at the driver source file.

Regards,
Fabian

Hi @fabian.solano
Thanks for sharing the patch. Looks like the patch takes effect when we set MJPG format. If we set YUV422(UYVY, YUYV, …) format, it does not take effect. Is my understanding correct? Would like to get more information and please advise. Thanks.

Hi DaneLLL,

You are right! Actually this is a quick and ugly hack but it let you work with more than one UVC camera (actually you need to be careful on not setting the bandwidth too low for your camera). The main issue is that the UVC driver stack does not implement a logic to calculate the real bandwidth for encoded formats such as MJPEG and H264.

For YUY2 this is not a problem because the frames sizes are consistent and the bandwidth is fixed (actually there is a quirk parameter to overwrite it in case you camera reports the wrong value: UVC_QUIRK_FIX_BANDWIDTH, see more details at:

http://www.ideasonboard.org/uvc/faq/#faq7

I would like a more formal fix for this, unfortunately there is none yet due to the bandwidth calculation complexity. However, there have been lot of attempts to make this better such as the one described here:

https://patchwork.kernel.org/patch/9936791/

But AFAIK none has been pushed to mainstream.

Best Regards,
Marco
www.ridgerun.com

1 Like

Hi @DaneLLL,

Tried USB3.0 camera and works fine. Thanks!

1 Like

@bryanmok Would you mind to share what brand/type of cams you did use?