Page 1 of 1

v4l2-ctl buffer allocation error

Posted: 2024-07-18 9:13
by 14Og
Hello! I'm working with pico mini B (64MB) and currently my goal is to build video pipeline using v4l2 api (due to problems with ffmpeg). The problem is that i can not allocate memory buffers for resolution more than 640x480, when camera officially supports 2304x1296. I've reduced RK_BOOTARGS_CMA_SIZE to 1MB and with official buildroot image i have about 40MB free RAM:
Screenshot from 2024-07-18 11-53-03.png
Assuming that we use NV12 pixel format, which should take 2304 * 1296 * 1.5 = 4,478,976 bytes for one raw image buffer, which quite big amount of memory, but i have 40,000,000 bytes. The only problem, i suppose, may be that pico's memory is fragmented and kernel can't find continious memory buffer. According to v4l2-ctl output with default streaming command, we allocating 2 memory buffers, which doubles this size up to almost 10MB, but still sounds fairly possible:
Screenshot from 2024-07-18 12-02-10.png
I tried to allocate my own memory buffer in my own application:

Code: Select all

    
    uint8_t *pMemory = static_cast<uint8_t*>(malloc(2304 * 1296 * 3 * sizeof(uint8_t)));
    memset(pMemory, 0, 2304*1296*3);
And this actually works!
Screenshot from 2024-07-18 12-09-07.png
But trying to set up stream with 2304*1296 resolution causes allocation error:
Screenshot from 2024-07-18 12-10-10.png
Maybe kernel-space driver memory buffer allocation is not that simple as just calling malloc from user-space app, but i still do not understand why this is not working. Maybe someone else had this problem? Any information would be helpful!

Re: v4l2-ctl buffer allocation error

Posted: 2024-07-18 10:42
by 14Og
what i found out by now, is that v4l2 uses cma allocator, and according to /proc/meminfo it's size is 1024 kb, which is far less then 4,5 mb that i need. So how can i modify that CmaTotal size in buildroot?
Screenshot from 2024-07-18 13-42-20.png
UPD: Haha, now i understand that i've changed this value by myself as i thought that this CMA memory is needed for pico ISP sdk. Now everything should work properly.