UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Explorer
Explorer
250 Views
Registered: ‎07-06-2016

v4l2 mem2mem pipeline error: VIDIOC_REQBUFS in failed: Invalid argument

Jump to solution

Hello,

I'm trying to implement the next video pipeline (tools version: 2018.3):

Untitled.jpg

The main idea is simple, to send video frames from PS to PL for processing it and get them back to PS.

I'm taking as a reference the TRD's 2014.4, 2015.4... where they also implement a v4l2 m2m video pipelines to process a sobel filter in the PL.

The device tree for the above hardware is:

 

&v_demosaic_0 {
    compatible = "xlnx,v-demosaic";
    clocks = <&clk 71>;
    reset-gpios = <&gpio 81 1>;

    ports {
        #address-cells = <1>;
        #size-cells = <0>;

        port@0 {
            reg = <0>;
            xlnx,video-width = <8>;

            bayer_in: endpoint {
                    remote-endpoint = <&rb_out>;
            };
        };

        port@1 {
            reg = <1>;
            xlnx,video-width = <8>;

            bayer_out: endpoint {
                remote-endpoint = <&csc_in>;
            };
        };
    };
};

&v_proc_ss_0 {
	 compatible ="xlnx,v-vpss-csc";
	 reg = <0x0 0xa0120000 0x0 0x10000>;
	 clocks = <&clk 71>;
	 reset-gpios = <&gpio 80 1>;
	 xlnx,max-width = <3840>;
	 xlnx,max-height = <2160>;
 ports {
         #address-cells = <1>;
         #size-cells = <0>;
         port@0 {
                 reg = <0>;
                 xlnx,video-format = <2>;
                 xlnx,video-width = <8>;

                 csc_in: endpoint {
                         remote-endpoint = <&bayer_out>;
                 };
         };
         port@1 {
                 reg = <1>;
                 xlnx,video-format = <2>;
                 xlnx,video-width = <8>;

                 csc_out: endpoint {
                         remote-endpoint = <&wb_in>;
                 };
         };
 };
};

&amba_pl {
    video_m2m {
        compatible = "xlnx,video";
        dmas =  <&v_frmbuf_wr_0 1> , <&v_frmbuf_rd_0 0>;
        dma-names = "port0","port1";

         ports {
                 #address-cells = <1>;
                 #size-cells = <0>;
                 port@0 {
                         
			 reg = <0>;
                         direction = "input";
 
                         wb_in: endpoint {
                                 remote-endpoint = <&csc_out>;
                         };
                         
                 };
 
                 port@1 {

                         reg = <1>;
                         direction = "output";
 
                         rb_out: endpoint {
                                 remote-endpoint = <&bayer_in>;
                         };

  
                 };
         };

    };
};

 

The printed media pipeline:

Media controller API version 4.14.0

Media device information
------------------------
driver          xilinx-video
model           Xilinx Video Composite Device
serial
bus info
hw revision     0x0
driver version  4.14.0

Device topology
- entity 1: video_m2m output 0 (1 pad, 1 link)
            type Node subtype V4L flags 0
            device node name /dev/video0
        pad0: Sink
                <- "a0120000.v_proc_ss":1 [ENABLED]

- entity 5: video_m2m input 1 (1 pad, 1 link)
            type Node subtype V4L flags 0
            device node name /dev/video1
        pad0: Source
                -> "a0130000.v_demosaic":0 [ENABLED]

- entity 9: a0130000.v_demosaic (2 pads, 2 links)
            type V4L2 subdev subtype Unknown flags 0
            device node name /dev/v4l-subdev0
        pad0: Sink
                [fmt:SRGGB8_1X8/1280x720 field:none]
                <- "video_m2m input 1":0 [ENABLED]
        pad1: Source
                [fmt:RBG888_1X24/1280x720 field:none]
                -> "a0120000.v_proc_ss":0 [ENABLED]

- entity 12: a0120000.v_proc_ss (2 pads, 2 links)
             type V4L2 subdev subtype Unknown flags 0
             device node name /dev/v4l-subdev1
        pad0: Sink
                [fmt:RBG888_1X24/1280x720 field:none]
                <- "a0130000.v_demosaic":1 [ENABLED]
        pad1: Source
                [fmt:RBG888_1X24/1280x720 field:none]
                -> "video_m2m output 0":0 [ENABLED]

 

 

The userspace code snippet  I'm running is:

void v4l2_init()
{
	int ret = 0;
    int fdin=0,fdout=0;
	struct v4l2_capability caps1, caps2;
	struct v4l2_format fmt1,fmt2;


	//Open v4l2 file descriptors
    if((fdin = open("/dev/video1", O_RDWR)) < 0){
        perror("open in");
        exit(1);
    }

    if((fdout = open("/dev/video0", O_RDWR)) < 0){
        perror("open out");
        exit(1);
    }

    /*query v4l2 devices capabilities*/
	memset(&caps1, 0, sizeof caps1);
	ret=0;
	ret = ioctl(fdin, VIDIOC_QUERYCAP, &caps1);
	ASSERT(ret < 0, "VIDIOC_QUERYCAP video in failed: %s\n", ERRSTR);

	memset(&caps2, 0, sizeof caps2);
	ret=0;
	ret = ioctl(fdout, VIDIOC_QUERYCAP, &caps2);
	ASSERT(ret < 0, "VIDIOC_QUERYCAP video out failed: %s\n", ERRSTR);

	//Query v4l2 devices format
	memset(&fmt1, 0, sizeof fmt1);
	fmt1.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
	ret=0;
	ret = ioctl(fdin, VIDIOC_G_FMT, &fmt1);
	ASSERT(ret < 0, "VIDIOC_G_FMT in failed: %s\n", ERRSTR);

#ifdef DEBUG_MODE
	printf("G_FMT(start) in: width = %u, height = %u, 4cc = %.4s\n",
		fmt1.fmt.pix.width, fmt1.fmt.pix.height,
		(char*)&fmt1.fmt.pix.pixelformat);
#endif

	memset(&fmt2, 0, sizeof fmt2);
	fmt2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	ret=0;
	ret = ioctl(fdout , VIDIOC_G_FMT, &fmt2);
	ASSERT(ret < 0, "VIDIOC_G_FMT out failed: %s\n", ERRSTR);

#ifdef DEBUG_MODE
	printf("G_FMT(start) out: width = %u, height = %u, 4cc = %.4s\n",
		fmt2.fmt.pix.width, fmt2.fmt.pix.height,
		(char*)&fmt2.fmt.pix.pixelformat);
#endif
	ret=0;
	fmt1.fmt.pix = INPUT_PIX_FMT;
	ret = ioctl(fdin , VIDIOC_S_FMT, &fmt1);
	ASSERT(ret < 0, "VIDIOC_S_FMT failed: %s\n", ERRSTR);
	ret=0;
	ret = ioctl(fdin , VIDIOC_G_FMT, &fmt1);
	ASSERT(ret < 0, "VIDIOC_G_FMT in failed: %s\n", ERRSTR);

#ifdef DEBUG_MODE
	printf("G_FMT(final) in: width = %u, height = %u, 4cc = %.4s\n",
		fmt1.fmt.pix.width, fmt1.fmt.pix.height,
		(char*)&fmt1.fmt.pix.pixelformat);
#endif
	ret=0;
	fmt2.fmt.pix = OUTPUT_PIX_FMT;
	ret = ioctl(fdout , VIDIOC_S_FMT, &fmt2);
	ASSERT(ret < 0, "VIDIOC_S_FMT out failed: %s\n", ERRSTR);
	ret=0;
	ret = ioctl(fdout , VIDIOC_G_FMT, &fmt2);
	ASSERT(ret < 0, "VIDIOC_G_FMT out failed: %s\n", ERRSTR);

#ifdef DEBUG_MODE
	printf("G_FMT(final) out: width = %u, height = %u, 4cc = %.4s\n",
		fmt2.fmt.pix.width, fmt2.fmt.pix.height,
		(char*)&fmt2.fmt.pix.pixelformat);
#endif

	/*Request buffers*/
	struct v4l2_requestbuffers rqbufs;
	memset(&rqbufs, 0, sizeof(rqbufs));
	rqbufs.count = 1;
	rqbufs.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
	rqbufs.memory = V4L2_MEMORY_USERPTR;
	ret=0;

	ret = ioctl(fdin , VIDIOC_REQBUFS, &rqbufs);
	ASSERT(ret < 0, "VIDIOC_REQBUFS in failed: %s\n", ERRSTR);

	memset(&rqbufs, 0, sizeof(rqbufs));
	rqbufs.count = 1;
	rqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	rqbufs.memory = V4L2_MEMORY_USERPTR;
	ret=0;

	ret = ioctl(fdout, VIDIOC_REQBUFS, &rqbufs);
	ASSERT(ret < 0, "VIDIOC_REQBUFS out failed: %s\n", ERRSTR);
}

All runs ok till the buffer request stage, which the driver returns: "VIDIOC_REQBUFS in failed: Invalid argument"

Any idea what am I missing or what's wrong?

Thanks in advance.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
Explorer
Explorer
95 Views
Registered: ‎07-06-2016

Re: v4l2 mem2mem pipeline error: VIDIOC_REQBUFS in failed: Invalid argument

Jump to solution

Hi, 

I was not able to get this working, so I used instead the mem2mem framework to send data to the PS, the solution here:

https://forums.xilinx.com/t5/Video/Gstreamer-and-sending-data-from-PS-to-PL/m-p/1025738#M27850

 

6 Replies
Explorer
Explorer
204 Views
Registered: ‎07-06-2016

Re: v4l2 mem2mem pipeline error: VIDIOC_REQBUFS in failed: Invalid argument

Jump to solution

I managed to make some progress on this,

I did test the media pipeline using yavta and it seems to be working and creating the buffers:

yavta -n 3 -c10 -f YUYV -s 1920x1080 --skip 7 -F /dev/video1
Device /dev/video1 opened.
Device `video_m2m input 1' on `platform:video_m2m:1' is a video output (without mplanes) device.
Video format set: YUYV (56595559) 1920x1080 field none, 1 planes:
 * Stride 3840, buffer size 4147200
Video format: YUYV (56595559) 1920x1080 field none, 1 planes:
 * Stride 3840, buffer size 4147200
3 buffers requested.
length: 1 offset: 4079339472 timestamp type/source: mono/EoF
Buffer 0/0 mapped at address 0x7fba7e6000.
length: 1 offset: 4079339472 timestamp type/source: mono/EoF
Buffer 1/0 mapped at address 0x7fba3f1000.
length: 1 offset: 4079339472 timestamp type/source: mono/EoF
Buffer 2/0 mapped at address 0x7fb9ffc000.
yavta -n 3 -c10 -f YUYV -s 1920x1080 --skip 7 -F /dev/video0
Device /dev/video0 opened.
Device `video_m2m output 0' on `platform:video_m2m:0' is a video output (without mplanes) device.
Video format set: YUYV (56595559) 1920x1080 field none, 1 planes:
 * Stride 3840, buffer size 4147200
Video format: YUYV (56595559) 1920x1080 field none, 1 planes:
 * Stride 3840, buffer size 4147200
3 buffers requested.
length: 1 offset: 3337198112 timestamp type/source: mono/EoF
Buffer 0/0 mapped at address 0x7f8bdec000.
length: 1 offset: 3337198112 timestamp type/source: mono/EoF
Buffer 1/0 mapped at address 0x7f8b9f7000.
length: 1 offset: 3337198112 timestamp type/source: mono/EoF
Buffer 2/0 mapped at address 0x7f8b602000.

So I decided to create a simple app and use the yavta source code only to open and check capcabilities of the video1 device:

#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>
#include <stdlib.h>
#include <errno.h>
#include <getopt.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/select.h>
#include <sys/time.h>

#include <linux/videodev2.h>


struct device
{
	int fd;

	enum v4l2_buf_type type;
	enum v4l2_memory memtype;
	unsigned int nbufs;
	struct buffer *buffers;

	unsigned int width;
	unsigned int height;
	unsigned int bytesperline;
	unsigned int imagesize;

	void *pattern;
};

int main(int argc, char **argv)
{
	struct device dev;
	 int ret;
	/* Open the video device. */
	ret = video_open(&dev, "/dev/video1", 0);
	if (ret < 0)
		return 1;

	return 0;
}





 int video_open(struct device *dev, const char *devname, int no_query)
{
	struct v4l2_capability cap;
	int ret;

	memset(dev, 0, sizeof *dev);
	dev->fd = -1;
	dev->memtype = V4L2_MEMORY_MMAP;
	dev->buffers = NULL;

	dev->fd = open(devname, O_RDWR);
	if (dev->fd < 0) {
		printf("Error opening device %s: %d.\n", devname, errno);
		return dev->fd;
	}

	if (!no_query) {
		memset(&cap, 0, sizeof cap);
		ret = ioctl(dev->fd, VIDIOC_QUERYCAP, &cap);
		if (ret < 0) {
			printf("Error opening device %s: unable to query "
				"device.\n", devname);
			close(dev->fd);
			return ret;
		}

		if (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)
			dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
		else if (cap.capabilities & V4L2_CAP_VIDEO_OUTPUT)
			dev->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
		else {
			printf("Error opening device %s: neither video capture "
				"nor video output supported.\n", devname);
			close(dev->fd);
			return -EINVAL;
		}

		printf("Device %s opened: %s (%s).\n", devname, cap.card, cap.bus_info);
	} else {
		dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
		printf("Device %s opened.\n", devname);
	}

	return 0;
}



I'm running the code in debug mode in xsdk and I've got the next error: "Error opening device /dev/video1: neither video capture nor video output supported."

Does anyone have an idea why running same yavta code form xsdk gives the above error when querying the capabilities?  

 

Moderator
Moderator
198 Views
Registered: ‎11-09-2015

Re: v4l2 mem2mem pipeline error: VIDIOC_REQBUFS in failed: Invalid argument

Jump to solution

HI @joseer 

Again, I am not familiar with this flow so this is just a guess. According to the wiki page for the demosaic IP:

This driver is a V4L2 sub-device driver, which means it is designed to operate with a video device in it's graph

So you might not be able to use the demosaic as a capture or output device. This might be the reason why you are getting this error. Not sure if that would work but what if you add the TPG IP as pass-through?

I know this is king of a uggly patching but I do not think what you are trying to do is supported by the driver.

Anyway, hope this was still a bit helpful,

Regards


Florent
Product Application Engineer - Xilinx Technical Support EMEA
**~ Don't forget to reply, give kudos, and accept as solution.~**
0 Kudos
Explorer
Explorer
193 Views
Registered: ‎07-06-2016

Re: v4l2 mem2mem pipeline error: VIDIOC_REQBUFS in failed: Invalid argument

Jump to solution

Hi @florentw , thanks for your reply,

Yes, I read that in the demosaic IP wiki page, but when I run yavta utility in petalinux (see above code), it works and checks video capabilities without problem, also it maps the buffers...if a driver incompatibility (demosaic) was the case it shouldn't be working with yavta either but it does work, and this is the part that confuse me more.....

Thanks for the suggestion, agreed it is not a great fix but I'll try the tpg as pass-through and see how it goes...

0 Kudos
Explorer
Explorer
170 Views
Registered: ‎07-06-2016

Re: v4l2 mem2mem pipeline error: VIDIOC_REQBUFS in failed: Invalid argument

Jump to solution

Hi,

I tried to add the vtpg but unfortunately still same issue, I've also tried to use only the VPSS IP in color conversion mode with same results....

The problem  is that running the yavta plugin everything seems to work fine but when I'm running same yavta functions (see above code) from user space to query the device capabilities it does return:  "neither video capture nor video output supported".

The "cap.capabilities" variable returned value is: 0x84203000 which it doesn't make sense as the expected values are : 0x00000001 (capture) or 0x00000002(output)

any idea what could it be the problem?

0 Kudos
Moderator
Moderator
100 Views
Registered: ‎11-09-2015

Re: v4l2 mem2mem pipeline error: VIDIOC_REQBUFS in failed: Invalid argument

Jump to solution

HI @joseer 

As per the topic below, I assume you got this issue fixed?

https://forums.xilinx.com/t5/Embedded-Linux/VPSS-IP-config-from-user-space/m-p/1025750/highlight/false#M36851

Could you kindly share your solution with the community and mark the reply as accepted solution?

Thanks


Florent
Product Application Engineer - Xilinx Technical Support EMEA
**~ Don't forget to reply, give kudos, and accept as solution.~**
0 Kudos
Explorer
Explorer
96 Views
Registered: ‎07-06-2016

Re: v4l2 mem2mem pipeline error: VIDIOC_REQBUFS in failed: Invalid argument

Jump to solution

Hi, 

I was not able to get this working, so I used instead the mem2mem framework to send data to the PS, the solution here:

https://forums.xilinx.com/t5/Video/Gstreamer-and-sending-data-from-PS-to-PL/m-p/1025738#M27850