narragansett
Posts: 49
Joined: Tue Aug 07, 2018 12:34 am

Clean up after encoder (video11)

Thu Apr 15, 2021 1:17 pm

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 :)

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11211
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Clean up after encoder (video11)

Thu Apr 15, 2021 1:36 pm

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
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

narragansett
Posts: 49
Joined: Tue Aug 07, 2018 12:34 am

Re: Clean up after encoder (video11)

Thu Apr 15, 2021 2:41 pm

That's what I was missing! (calls to munmap)

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

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11211
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Clean up after encoder (video11)

Thu Apr 15, 2021 3:21 pm

Yup, until you've released all of your allocations they'll be kept around. Reference counting is a great thing (until it goes wrong!).
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Camera board”