VIDIOC_QBUF Buffer error when running Multimedia API sample 12_camera_v4l2_cuda

Hello. I’m trying to run example 12_camera_v4l2_cuda from the Multimedia API, with these platform:

  • Jetson Xavier NX L4T 32.4.3 and JetPack_4.4
  • e-CAM137A_CUMI1335_MOD - 13MP AR1335 Camera Module

When I run the example, I get these error/warnings:

/usr/src/tegra_multimedia_api/samples/12_camera_v4l2_cuda$ ./camera_v4l2_cuda -d /dev/video0 -s 1920x1080 -f UYVY -r 30 -v

INFO: camera_initialize(): (line:260) Camera ouput format: (1920 x 1080)  stride: 3840, imagesize: 4147200, frate: 75 / 1
[INFO] (NvEglRenderer.cpp:109) <renderer0> Setting Screen width 1920 height 1080
INFO: init_components(): (line:299) Initialize v4l2 components successfully
WARN: request_camera_buff(): (line:337) Camera v4l2 buf length is not expected
ERROR: request_camera_buff(): (line:343) Failed to enqueue buffers: Bad address (14)
ERROR: prepare_buffers(): (line:461) Failed to set up camera buff
*** stack smashing detected ***: <unknown> terminated
Aborted (core dumped)

The error is raised in this section of code:

line 343:
if (ioctl(ctx->cam_fd, VIDIOC_QBUF, &buf) < 0)
    ERROR_RETURN("Failed to enqueue buffers: %s (%d)",
            strerror(errno), errno);

The camera was checked and is running OK. This are the format supported:

v4l2-ctl -d0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
	Index       : 0
	Type        : Video Capture
	Pixel Format: 'UYVY'
	Name        : UYVY 4:2:2
		Size: Discrete 640x480
			Interval: Discrete 0.008s (120.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.013s (80.000 fps)
		Size: Discrete 1920x1080
			Interval: Discrete 0.013s (75.000 fps)
		Size: Discrete 3840x2160
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 4096x2160
			Interval: Discrete 0.036s (28.000 fps)
		Size: Discrete 4192x3120
			Interval: Discrete 0.053s (19.000 fps)

	Index       : 1
	Type        : Video Capture
	Pixel Format: 'NV16'
	Name        : Y/CbCr 4:2:2
		Size: Discrete 640x480
			Interval: Discrete 0.008s (120.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.013s (80.000 fps)
		Size: Discrete 1920x1080
			Interval: Discrete 0.013s (75.000 fps)
		Size: Discrete 3840x2160
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 4096x2160
			Interval: Discrete 0.036s (28.000 fps)
		Size: Discrete 4192x3120
			Interval: Discrete 0.053s (19.000 fps)

v4l2-ctl --set-fmt-video=width=1920,height=1080,pixelformat="UYVY" --device=/dev/video1 --stream-count=300 --stream-mmap
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 29.70 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 29.55 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 29.56 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 29.52 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 29.54 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 29.51 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 29.52 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 29.51 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 29.52 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 29.51 fps

The camera can be viewed without problems using GStreamer:

gst-launch-1.0 v4l2src device=/dev/video1 ! 'video/x-raw,format=UYVY,width=1920,height=1080' ! xvimagesink

Any help will be much appreciated.

Thanks!
Juan

Hi,
Probably the v4l2 source does not support V4L2_MEMORY_DMABUF. Please modify the code to force capture_dmabuf = false:

//        if (ctx->cam_pixfmt == V4L2_PIX_FMT_GREY &&
//            params.pitch[0] != params.width[0])
                ctx->capture_dmabuf = false;

And check if it works in V4L2_MEMORY_MMAP

Hello DaneLLL. Thanks for your reply.

Please note that the sample 12_camera_v4l2_cuda.cpp does not have that portion of code you pasted (at least my version!). I have attached the sample that I’m testing.

Anyway, I’ve modified the function request_camera_buff() and I’ve changed it to use V4L2_MEMORY_MMAP like below:

static bool
request_camera_buff(context_t *ctx)
{
    // Request camera v4l2 buffer
    struct v4l2_requestbuffers rb;
    memset(&rb, 0, sizeof(rb));
    rb.count = V4L2_BUFFERS_NUM;
    rb.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    rb.memory = V4L2_MEMORY_MMAP;
    if (ioctl(ctx->cam_fd, VIDIOC_REQBUFS, &rb) < 0)
        ERROR_RETURN("Failed to request v4l2 buffers: %s (%d)",
                strerror(errno), errno);
    if (rb.count != V4L2_BUFFERS_NUM)
        ERROR_RETURN("V4l2 buffer number is not as desired");

    for (unsigned int index = 0; index < V4L2_BUFFERS_NUM; index++)
    {
        struct v4l2_buffer buf;

        // Query camera v4l2 buf length
        memset(&buf, 0, sizeof buf);
        buf.index = index;
        buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

        buf.memory = V4L2_MEMORY_MMAP;
        if (ioctl(ctx->cam_fd, VIDIOC_QUERYBUF, &buf) < 0)
            ERROR_RETURN("Failed to query buff: %s (%d)",
                    strerror(errno), errno);

        ctx->g_buff[index].size = buf.length;
        ctx->g_buff[index].start = (unsigned char *)
            mmap (NULL /* start anywhere */,
                    buf.length,
                    PROT_READ | PROT_WRITE /* required */,
                    MAP_SHARED /* recommended */,
                    ctx->cam_fd, buf.m.offset);
        if (MAP_FAILED == ctx->g_buff[index].start)
            ERROR_RETURN("Failed to map buffers");

        if (ioctl(ctx->cam_fd, VIDIOC_QBUF, &buf) < 0)
            ERROR_RETURN("Failed to enqueue buffers: %s (%d)",
                    strerror(errno), errno);
    }

    return true;
}

Now the buffer error is gone, but I have new errors…

INFO: camera_initialize(): (line:260) Camera ouput format: (1920 x 1080)  stride: 3840, imagesize: 4147200, frate: 75 / 1
[INFO] (NvEglRenderer.cpp:109) <renderer0> Setting Screen width 1920 height 1080
INFO: init_components(): (line:299) Initialize v4l2 components successfully
INFO: prepare_buffers(): (line:464) Succeed in preparing stream buffers
*** stack smashing detected ***: <unknown> terminated
Aborted (core dumped)

I understand I have to adapt the rest of the sample, and I and don’t know how. Have you a complete sample using V4L2_MEMORY_MMAP buffer mode?.

Thanks!

Juan

Hi,
Do you install the samples through SDKManager? Not sure but it looks like the samples are old and do not fit the release version r32.4.3.

I’m using a Floyd carrier board with e-Con cameras, and it was flashed manually, without the NVIDIA SDK.

I was using the sample in this folder:

/usr/src/tegra_multimedia_api/samples/12_camera_v4l2_cuda/

That sample throws the errors reported before.

Now, I have downloaded and installed manually the multimedia-api_32.4.3 like this:

sudo dpkg -i nvidia-l4t-jetson-multimedia-api_32.4.3-20200625213407_arm64.deb tensorrt_7.1.3.0-1+cuda10.2_arm64.deb

Then, I’ve compiled this new sample in jetson_multimedia_api folder:

/usr/src/jetson_multimedia_api/samples/12_camera_v4l2_cuda/

Now the new sample, works perfectly without any modification!

Many thanks for your help!

Juan

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.