Issues with jpegenc

We experience issues with the hardware jpeg encoding in our application (virtual memory keeps increasing).

There seems to be a related post here: Libjpeg encode leak - Jetson & Embedded Systems / Jetson Xavier NX - NVIDIA Developer Forums Which was reported solved.

Just to test this I ran the sample:

./jpeg_encode /usr/src/jetson_multimedia_api/data/Picture/nvidia-logo.yuv 1920 1080 encode_test.jpg -quality 90 -f 1 -s 10000000 --dbg-level 3

Which at some point in time seems to crash:


[DEBUG] (NvJpegEncoder.cpp:117) :Succesfully encoded Buffer fd=967
[DEBUG] (NvJpegEncoder.cpp:65) jpenenc (0xaaaLb065475e0) destroyed
[DEBUG] (NvJpegEncoder.cpp:117) :Succesfully encoded Buffer fd=969
[DEBUG] (NvJpegEncoder.cpp:65) jpenenc (0xaaab065475e0) destroyed
[DEBUG] (NvJpegEncoder.cpp:117) :Succesfully encoded Buffer fd=971
[DEBUG] (NvJpegEncoder.cpp:65) jpenenc (0xaaab065475e0) destroyed
[DEBUG] (NvJpegEncoder.cpp:117) :Succesfully encoded Buffer fd=973
[DEBUG] (NvJpegEncoder.cpp:65) jpenenc (0xaaab065475e0) destroyed
[DEBUG] (NvJpegEncoder.cpp:117) :Succesfully encoded Buffer fd=975
[DEBUG] (NvJpegEncoder.cpp:65) jpenenc (0xaaab065475e0) destroyed
NVMAP_IOC_GET_FD failed: Bad address
NvRmStream: Channel submission failed (err=196623)
NvRmStream: Flush failed (err=196623)
JPEGEncFeedFrame 1796: Stream flush failed with error = 196623
Segmentation fault (core dumped)

This is on a Xavier NX with Jetpack 5.1.1 L4T: 35.3.1
Im not sure this example is related to my application crash, but I suppose it shouldnt crash.

[edit: the input image can be created using the encode sample:

sudo ./jpeg_decode num_files 1 …/…/data/Picture/nvidia-logo.jpg …/…/data/Picture/nvidia-logo.yuv

]

Hi,
Thanks for reporting it. We will set up and try to replicate the issue.

Thanks!

I also succeeded in reproducing the same issue that I see in my application code. If in line 204 in jpeg_encode_main.cpp the iteration around encodeFromFd is increased to a large amount, the virtual memory will (very) slowly fill until the application crashes.

for (int i = 0; i < 10000000000; ++i)
{
    ret = ctx.jpegenc->encodeFromFd(dst_dma_fd, JCS_YCbCr, &out_buf,
          out_buf_size, ctx.quality);
    if (ret < 0)
    {
        cerr << "Error while encoding from fd" << endl;
        ctx.got_error = true;
        break;
    }
}

I assume its allowed to use the encoder this way: that I dont need to create a jpeg encoder context for each image that I want to compress.
Also I assume that encodeFromFd does not / should not allocate output memory.

[edit: just to be clear: this is probably not the same issue as reported in the above post]
[edit: the above code, after a long while, crashes with:

PosixMemMap:84 mmap failed : Cannot allocate memory

the virtual memory increase can be monitored with htop
]