Page 1 of 1

Clean up after encoder (video11)

Posted: Thu Apr 15, 2021 1:17 pm
by narragansett
Hello,
I'm working with the newer V4L2 encoder, using the libcamera source as a guide (h264_encoder.xxx) It works well, but I'm having issues when I destroy the encoder and rebuild it without exiting the process. I can destroy and rebuild about 6 times before I get a "Got 2 output buffers" message and it throws a runtime_error "request for capture buffers failed".

To clean things up, I perform VIDIOC_STREAMOFF on both the output and capture buffer types, and I close the fd. What am I missing?

thanks :)

Re: Clean up after encoder (video11)

Posted: Thu Apr 15, 2021 1:36 pm
by 6by9
What mode are you running encoder in? VB2_MEMORY_MMAP or VB2_MEMORY_DMABUF? They change who is allocating the buffers (MMAP is /dev/video11, whilst DMABUF is something else). If DMABUF then you need to release the externally allocated buffers.

You should be able to use "sudo cat /sys/kernel/debug/dma_buf/bufinfo" to see the state of any currently allocated buffers.
There was a bug in vcsm-cma that wasn't releasing all buffers. Fixed on 5.10 earlier this week with https://github.com/raspberrypi/linux/pull/4277

Re: Clean up after encoder (video11)

Posted: Thu Apr 15, 2021 2:41 pm
by narragansett
That's what I was missing! (calls to munmap)

Thanks much for the quick reply and sharp insight! :)

Re: Clean up after encoder (video11)

Posted: Thu Apr 15, 2021 3:21 pm
by 6by9
Yup, until you've released all of your allocations they'll be kept around. Reference counting is a great thing (until it goes wrong!).