[mmapi] libv4l2: error attempting to open more then 16 video devices

I did the following tests in TX1, L4T28.1:

int
main(int argc, char *argv[])
{
	NvVideoConverter *conv[64] = {0};
	NvVideoDecoder *dec[64] = {0};

	for (int i = 0; i < 64; i++)
	{

		conv[i] = NvVideoConverter::createVideoConverter("vic");
		if(!conv[i])
		{
			printf("Could not create video converter%d\n", i);
			return -1;
		}

		dec[i] = NvVideoDecoder::createVideoDecoder("dec");
		if(!dec[i])
		{
			printf("Could not create video decoder%d\n", i);
			return -1;
		}
	}
}

When creating the 17th device, an error is reported:
libv4l2: error attempting to open more then 16 video devices

In our needs, this amount is too small.
We need 9 decoding, and then take 9 vic stitch into a composite picture, and then encode to H265 es stream. 16 is not enough.

Is there any way to raise this restriction?

1, can I modify libv4l2.so source code?

I checked out source code from GitHub - pboettch/v4l-utils

After compiling, replace /usr/lib/aarch64-linux-gnu/libv4l2.so.0.0.0, run mmapi sample will be an error:
[ERROR] (NvV4l2Element.cpp:63) Could not open device ‘/dev/nvhost-nvdec’: Inappropriate ioctl for device

2, I found that each process can create 16 v4l2 elements, can I create multiple processes to complete my work, the processes passed video data by dma_buf fd ?

Lilin,
Yes, you can download source code there, and modify 16 to 64.
Then make and make install.

Another point you need to care is:
You need modify lib’s destanation to /usr/lib/aarch64-linux-gnu/libv4l/(default is /usr/local/…) when confiure.

or
copy /usr/lib/aarch64-linux-gnu/libv4l/plugin/*so to /usr/local…

Hi, WayneZhu:

Thank you for your reply, I’ll try it right away.

How to enable 32 video devices?

  1. git clone GitHub - pboettch/v4l-utils
  2. cd v4l-utils
    git apply open_32_video_devices.patch
  3. autoreconf -vfi
  4. sudo ./configure --prefix=/usr --libdir=/usr/lib/aarch64-linux-gnu/ --libexecdir=/usr/lib/aarch64-linux-gnu --without-jpeg
  5. sudo make
  6. sudo make install
$ cat open_32_video_devices.patch
diff --git a/lib/libv4l2/libv4l2-priv.h b/lib/libv4l2/libv4l2-priv.h
index 343db5e1..8f03ae75 100644
--- a/lib/libv4l2/libv4l2-priv.h
+++ b/lib/libv4l2/libv4l2-priv.h
@@ -25,7 +25,7 @@

 #include "../libv4lconvert/libv4lsyscall-priv.h"

-#define V4L2_MAX_DEVICES 16
+#define V4L2_MAX_DEVICES 32
 /* Warning when making this larger the frame_queued and frame_mapped members of
    the v4l2_dev_info struct can no longer be a bitfield, so the code needs to
    be adjusted! */
diff --git a/lib/libv4l2/libv4l2.c b/lib/libv4l2/libv4l2.c
index 966a000c..921c7e32 100644
--- a/lib/libv4l2/libv4l2.c
+++ b/lib/libv4l2/libv4l2.c
@@ -90,6 +90,10 @@ static void v4l2_set_src_and_dest_format(int index,
 static pthread_mutex_t v4l2_open_mutex = PTHREAD_MUTEX_INITIALIZER;
 static struct v4l2_dev_info devices[V4L2_MAX_DEVICES] = {
        { .fd = -1 },
+       { .fd = -1 },
+       { .fd = -1 }, { .fd = -1 }, { .fd = -1 }, { .fd = -1 }, { .fd = -1 },
+       { .fd = -1 }, { .fd = -1 }, { .fd = -1 }, { .fd = -1 }, { .fd = -1 },
+       { .fd = -1 }, { .fd = -1 }, { .fd = -1 }, { .fd = -1 }, { .fd = -1 },
        { .fd = -1 }, { .fd = -1 }, { .fd = -1 }, { .fd = -1 }, { .fd = -1 },
        { .fd = -1 }, { .fd = -1 }, { .fd = -1 }, { .fd = -1 }, { .fd = -1 },
        { .fd = -1 }, { .fd = -1 }, { .fd = -1 }, { .fd = -1 }, { .fd = -1 }

I got it !