[mmapi] libv4l2_nvvidconv: set mapping failed

In my code, when I destroy and then create a converter, it will print:

libv4l2_nvvidconv: set mapping failed

And then a seg fault occurs when the output_plane.qBuffer is executed

Segmentation Fault!
info.si_signo = 11
info.si_errno = 0
info.si_code  = 1 (SEGV_MAPERR)
info.si_addr  = 0x8

Excuse me, what kind of error will lead to this happening?

Hi li lin, please share a sample to reproduce the issue. Are you on r28.1?

hi li lin,
Except setting mmap in converter, you can use below APIs on r28.1 to get mapped buffers:

int NvBufferMemMap (int dmabuf_fd, unsigned int plane, NvBufferMemFlags memflag, void **pVirtAddr);
int NvBufferMemSyncForCpu (int dmabuf_fd, unsigned int plane, void **pVirtAddr);
int NvBufferMemUnMap (int dmabuf_fd, unsigned int plane, void **pVirtAddr);

hi DaneLLL:

Thank you for your reply, sorry for such a long time to update.
I am using L4T 28.1
Then I changed the mmapi ‘backend’ sample, you can reproduce the problem.

Use the following command to run:

./backend 1 ../../data/Video/sample_outdoor_car_1080p_10fps.h264 H264

Please help me analyze, where my code is not correct, this problem has plagued me for a long time, very grateful!
stitch_demo.tar.gz (13.6 KB)

Hi DaneLLL:

The way I will reproduce the problem becomes simpler.
I modified sample 00_video_decode

After conv created , I added a small piece of code, enough to reproduce the problem.

Please check the code in the attachment, thank you!

video_decode_main.cpp (34.7 KB)

./video_decode …/…/data/Video/sample_outdoor_car_1080p_10fps.h264 H264 --input-nalu
Set governor to performance before enabling profiler
Failed to query video capabilities: Inappropriate ioctl for device
NvMMLiteOpen : Block : BlockType = 261
TVMR: NvMMLiteTVMRDecBlockOpen: 7907: NvMMLiteBlockOpen
NvMMLiteBlockCreate : Block : BlockType = 261
Failed to query video capabilities: Inappropriate ioctl for device
+++ after create conv0
Failed to query video capabilities: Inappropriate ioctl for device
DEBUG @ render_thread_for_test, 775, we created it
DEBUG @ render_thread_for_test, 779
DEBUG @ render_thread_for_test, 781, we destroy it
Failed to query video capabilities: Inappropriate ioctl for device
libv4l2_nvvidconv: set mapping failed
DEBUG @ render_thread_for_test, 775, we created it
DEBUG @ render_thread_for_test, 779
*** Error in `./video_decode’: free(): invalid pointer: 0x0000007f780013c0 ***
Aborted

Hi li lin,
Can you try the APIs in #3 to avoid the error in video converter?

Hi DaneLLL,

Thank you for your reply.
But this error does not matter with mmap, I do not need the dma_buf mmap operation.
The error occurs when creating a converter

I suspect that the converter module is not thread-safe

Please check the code in #5, compared with the original code of the sample, the change is very small, I just created and destroyed one more converter in the sample.

like:

In the second time to create vic0, there will be set mapping failed error

int
main(int argc, char *argv[])
{
	NvVideoConverter *vic0;
	NvVideoConverter *vic1;
	log_level = LOG_LEVEL_DEBUG;

	vic1 = NvVideoConverter::createVideoConverter("vic1");
        
        //If it is open, no error occurs
        //delete vic1;

	while(1)
	{
		vic0 = NvVideoConverter::createVideoConverter("vic0");

		delete vic0;
	}

}

Hi li lin,
What is a valid usecase you iteratively create/delete a video converter?

Hi DaneLLL:

For example, a mmapi pipeline for multi-channel encoding or decoding.
Among them, one channel of encoding or decoding resolution changes, we need to delete and create the converter.
This should be a very common operation.

This question should be very similar to the one we had previously solved in

https://devtalk.nvidia.com/default/topic/1006857/-mmapi-under-what-conditions-lsquo-conv-gt-capture_plane-qbuffer-rsquo-will-block/

The same is the problems occurred in the conv delete/create.

I do not know if you are care about the process of module destruction in the software.
Please help me solve, useing vic is very important part in my project(for encode/decode/stitch), thank you!

Hello everyone:

I found a way to avoid this problem.
Do not destroy the converter, only destroy the two planes of the converter, and then re-configure them (similar to the decoding sample).
I’ll share the way to reconfigure one of the converters when creating multiple converters:

Destroy plane:
1, send EOS to conv’s output_plane, let DQ thread exit
2, conv-> waitForIdle (2000);
3, conv-> output_plane.stopDQThread ();
   conv-> capture_plane.stopDQThread ();
4, conv-> capture_plane.setStreamStatus (false);
conv-> output_plane.setStreamStatus (false);
5, conv-> output_plane.deinitPlane ();
conv-> capture_plane.deinitPlane ();

Reconfigure plane:
1, conv-> setOutputPlaneFormat
conv-> setCapturePlaneFormat
2, conv-> output_plane.setupPlane
conv-> capture_plane.setupPlane
3, prepared buffers for the two planes, such as get the NvBuffer from the output_plane, or put v4l2_buffer into capture_plane
4, conv-> output_plane.setStreamStatus (true)
conv-> capture_plane.setStreamStatus (true)
5, conv-> output_plane.startDQThread
conv-> capture_plane.startDQThread

Hope that nvidia can solve this ‘mapping failed’ error in the next L4T version

Thank you for sharing information. We will check and update.

This shall be fixed on r28.2. Please give it a try.