[AGX Xavier] nvv4l2 encoder crashes on a particular case

Hi,

I have confirmed this issue on a xavier box running Jetson 4.2.1 + DeepStream 4.0.

Here’s a test case.

GST_DEBUG=2,v4l2*=7 ./test-launch "videotestsrc num-buffers=9000 is-live=true ! video/x-raw,width=(int)1920,height=(int)1080,framerate=30/1,format=NV12 ! nvvideoconvert ! video/x-raw(memory:NVMM),width=(int)1920,height=(int)1080,framerate=30/1,format=NV12 ! nvv4l2h264enc bufapi-version=True ! h264parse ! rtph264pay name=pay0"

This will crash when you access from a client. For example,

gst-launch-1.0 rtspsrc location=rtsp://127.0.0.1:8554/test ! rtph264depay ! queue ! h264parse ! nvv4l2decoder bufapi-version=True ! nvvideoconvert ! "video/x-raw(memory:NVMM),format=RGBA" ! nvegltransform ! nveglglessink sync=False

Here’s such a crash log.

stream ready at rtsp://127.0.0.1:8554/test
Opening in BLOCKING MODE 
0:00:02.964636578  2533   0x7f7800b630 WARN                    v4l2 gstv4l2object.c:2355:gst_v4l2_object_add_interlace_mode:0x7f780e4040 Failed to determine interlace mode
0:00:02.964782380  2533   0x7f7800b630 WARN                    v4l2 gstv4l2object.c:2355:gst_v4l2_object_add_interlace_mode:0x7f780e4040 Failed to determine interlace mode
0:00:02.964950456  2533   0x7f7800b630 WARN                    v4l2 gstv4l2object.c:4431:gst_v4l2_object_probe_caps:<nvv4l2h264enc0:src> Failed to probe pixel aspect ratio with VIDIOC_CROPCAP: Unknown error -1
in videoconvert caps = video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, framerate=(fraction)30/1, multiview-mode=(string)mono, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, format=(string)NV12

(test-launch:2533): GLib-GObject-WARNING **: 16:26:49.572: invalid cast from 'nvv4l2h264enc' to 'GstNvV4l2VideoDec'
NvMMLiteOpen : Block : BlockType = 4 
===== NVMEDIA: NVENC =====
NvMMLiteBlockCreate : Block : BlockType = 4 
0:00:03.092726665  2533   0x7f58005d90 WARN          v4l2bufferpool gstv4l2bufferpool.c:1066:gst_v4l2_buffer_pool_start:<nvv4l2h264enc0:pool:src> Uncertain or not enough buffers, enabling copy threshold
H264: Profile = 66, Level = 0 
0:00:03.267662450  2533   0x7f5c003370 WARN          v4l2bufferpool gstv4l2bufferpool.c:1655:gst_v4l2_buffer_pool_dqbuf:<nvv4l2h264enc0:pool:src> Driver should never set v4l2_buffer.field to ANY
0:00:03.283406269  2533   0x55801dbd90 WARN               rtspmedia rtsp-media.c:3861:gst_rtsp_media_suspend: media 0x7f7810c290 was not prepared

(test-launch:2533): GStreamer-CRITICAL **: 16:26:49.916: gst_structure_set: assertion 'IS_MUTABLE (structure) || field == NULL' failed

(test-launch:2533): GStreamer-CRITICAL **: 16:26:49.917: gst_structure_set: assertion 'IS_MUTABLE (structure) || field == NULL' failed

(test-launch:2533): GLib-GObject-WARNING **: 16:26:49.953: invalid cast from 'nvv4l2h264enc' to 'GstNvV4l2VideoDec'
0:00:03.355453918  2533   0x7f58005d90 WARN          v4l2bufferpool gstv4l2bufferpool.c:1600:gst_v4l2_buffer_pool_dqbuf:<nvv4l2h264enc0:pool:sink> V4L2 provided buffer has bytesused 0 which is too small to include data_offset 0
0:00:03.355569638  2533   0x7f58005d90 WARN          v4l2bufferpool gstv4l2bufferpool.c:1600:gst_v4l2_buffer_pool_dqbuf:<nvv4l2h264enc0:pool:sink> V4L2 provided buffer has bytesused 0 which is too small to include data_offset 0
0:00:03.388709453  2533   0x7f58005d90 WARN          v4l2bufferpool gstv4l2bufferpool.c:1600:gst_v4l2_buffer_pool_dqbuf:<nvv4l2h264enc0:pool:sink> V4L2 provided buffer has bytesused 0 which is too small to include data_offset 0
0:00:03.388890074  2533   0x7f58005d90 WARN          v4l2bufferpool gstv4l2bufferpool.c:1600:gst_v4l2_buffer_pool_dqbuf:<nvv4l2h264enc0:pool:sink> V4L2 provided buffer has bytesused 0 which is too small to include data_offset 0
Segmentation fault (core dumped)

After investigations, I found there was a bug filed as 796525 in GStreamer.

https://bugzilla.gnome.org/show_bug.cgi?id=796525

But this was fixed in 1.14.2, which is older than the one installed on Jetson 4.2.1.

I am wondering if nvv4l2 encoders came from older v4l2 encoders, and are not yet fixed?

Thanks.

Confirmed this on DeepStream 4.0 GA.

$ GST_DEBUG=2,v4l2*=7 ./test-launch "videotestsrc num-buffers=9000 is-live=true ! video/x-raw,width=(int)1920,height=(int)1080,framerate=30/1,format=NV12 ! nvvideoconvert ! video/x-raw(memory:NVMM),width=(int)1920,height=(int)1080,framerate=30/1,format=NV12 ! nvv4l2h264enc ! h264parse ! rtph264pay name=pay0"
stream ready at rtsp://127.0.0.1:8554/test
Opening in BLOCKING MODE 
0:00:14.917793140 32633   0x7f9c00ae30 WARN                    v4l2 gstv4l2object.c:2370:gst_v4l2_object_add_interlace_mode:0x7f9c0e40f0 Failed to determine interlace mode
0:00:14.918010175 32633   0x7f9c00ae30 WARN                    v4l2 gstv4l2object.c:2370:gst_v4l2_object_add_interlace_mode:0x7f9c0e40f0 Failed to determine interlace mode
0:00:14.918117573 32633   0x7f9c00ae30 WARN                    v4l2 gstv4l2object.c:2370:gst_v4l2_object_add_interlace_mode:0x7f9c0e40f0 Failed to determine interlace mode
0:00:14.918310928 32633   0x7f9c00ae30 WARN                    v4l2 gstv4l2object.c:4408:gst_v4l2_object_probe_caps:<nvv4l2h264enc0:src> Failed to probe pixel aspect ratio with VIDIOC_CROPCAP: Unknown error -1
NvMMLiteOpen : Block : BlockType = 4 
===== NVMEDIA: NVENC =====
NvMMLiteBlockCreate : Block : BlockType = 4 
0:00:14.932543734 32633   0x7f780075e0 WARN          v4l2bufferpool gstv4l2bufferpool.c:1054:gst_v4l2_buffer_pool_start:<nvv4l2h264enc0:pool:src> Uncertain or not enough buffers, enabling copy threshold
H264: Profile = 66, Level = 0 
0:00:15.071816203 32633   0x7f78033d90 WARN          v4l2bufferpool gstv4l2bufferpool.c:1518:gst_v4l2_buffer_pool_dqbuf:<nvv4l2h264enc0:pool:src> Driver should never set v4l2_buffer.field to ANY
0:00:15.088880139 32633   0x559c477190 WARN               rtspmedia rtsp-media.c:3861:gst_rtsp_media_suspend: media 0x7f9c10d2d0 was not prepared

(test-launch:32633): GStreamer-CRITICAL **: 11:32:00.997: gst_structure_set: assertion 'IS_MUTABLE (structure) || field == NULL' failed

(test-launch:32633): GStreamer-CRITICAL **: 11:32:00.997: gst_structure_set: assertion 'IS_MUTABLE (structure) || field == NULL' failed
0:00:15.146972034 32633   0x7f780075e0 WARN          v4l2bufferpool gstv4l2bufferpool.c:1463:gst_v4l2_buffer_pool_dqbuf:<nvv4l2h264enc0:pool:sink> V4L2 provided buffer has bytesused 0 which is too small to include data_offset 0
0:00:15.147066599 32633   0x7f780075e0 WARN          v4l2bufferpool gstv4l2bufferpool.c:1463:gst_v4l2_buffer_pool_dqbuf:<nvv4l2h264enc0:pool:sink> V4L2 provided buffer has bytesused 0 which is too small to include data_offset 0
0:00:15.162917733 32633   0x7f780075e0 WARN          v4l2bufferpool gstv4l2bufferpool.c:1463:gst_v4l2_buffer_pool_dqbuf:<nvv4l2h264enc0:pool:sink> V4L2 provided buffer has bytesused 0 which is too small to include data_offset 0
0:00:15.163028203 32633   0x7f780075e0 WARN          v4l2bufferpool gstv4l2bufferpool.c:1463:gst_v4l2_buffer_pool_dqbuf:<nvv4l2h264enc0:pool:sink> V4L2 provided buffer has bytesused 0 which is too small to include data_offset 0
Segmentation fault (core dumped)

Hello TakenoriSato,

Yes, nvv4l2 plugins in DS4.0 are based on 1.14.1

To download gst-v4l2 sources, you can follow below steps and try to add the fix from 1.14.2

  1. Go to : https://developer.nvidia.com/embedded/downloads
  2. In the “Search filter,” enter “L4T sources.”
  3. Select the appropriate “L4T Sources” for L4T 32.2 release.
  4. Download the file and untar it.
  5. Expand the file Gst-v4l2 sources are in gst-nvvideo4linux2_src.tbz2.

For the Quick check of crash in codec plugins I ran following commands on Tegra that worked,

gst-launch-1.0 udpsrc port=9000 ! h264parse ! nvv4l2decoder ! nvegltransform ! nveglglessink --gst-
debug=0

and

gst-launch-1.0 videotestsrc ! nvvideoconvert ! “video/x-raw(memory:NVMM), format=I420” ! nvv4l2h264enc ! h264parse ! udpsink host=127.0.0.1 port=9000 --gst-debug=0

Great, thanks! I will give it a try.

I have confirmed my test case worked fine now!

Here’s the change I made.

$ diff gstv4l2videoenc_org.c gst-nvvideo4linux2_src/gst-v4l2/gstv4l2videoenc.c 
867a868,871
>   /* Only renegotiate on upstream changes */
>   if (self->input_state)
>     return TRUE;
>

@DaneLLL

next version of DeepStream should fix this issue

Hi,
Thanks for sharing the solution. We will check the patch.