blue-debug opened a new pull request, #21448: URL: https://github.com/apache/nuttx/pull/21448
*Note: Please adhere to [Contributing Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).* ## Summary This PR enhances the V4L2 capture and m2m drivers. It supersedes #18353, which was closed so that its changes come in again with the review comments addressed. The main changes: - v4l2_m2m: codec drivers can provide the MMAP buffers (`alloc_buf` / `free_buf`) and limit the queue size and the memory types; multi-planar formats, USERPTR buffers and DMA-BUF import; a `vaddr` member in `v4l2_buffer` / `v4l2_plane` for the address the driver uses. - v4l2_cap: `VIDIOC_EXPBUF` and `V4L2_MEMORY_DMABUF` import on top of the DMA-BUF framework (#21108), so frames reach a codec or a display without a copy. - v4l2_cap: JPEG and the new `V4L2_PIX_FMT_ENTROPY` streams take their buffer size from `sizeimage`; controls can be enumerated with `V4L2_CTRL_FLAG_NEXT_CTRL`. - v4l2_cap: drivers that set `IMGDATA_CAP_DROP_FRAME` keep capturing and drop frames while the application holds every buffer, instead of stopping and restarting the sensor. The sim camera sets it. - `<sys/videoio.h>`: the V4L2 structs take the Linux layout (32-bit control ids, reserved fields, packed structs; `buf_type` and `ctrl_class` removed as on Linux), plus the buffer flags, defines and lens shading control that libcamera and Linux applications use. - Documentation: testing V4L2 on sim with nxcamera and nxcodec. The review comments on #18353 are addressed: `sizeimage` is only used for JPEG and ENTROPY; m2m QBUF checks the index, memory type, MMAP heap and plane array before it takes a container; m2m DQBUF checks `buf` before its planes; `V4L2_CID_AUTOGAIN` / `V4L2_CID_GAIN` no longer share the ids of `V4L2_CID_HFLIP` / `V4L2_CID_VFLIP`. Depends-On: https://github.com/apache/nuttx-apps/pull/<apps PR> ## Impact Affects: V4L2 capture and m2m drivers, `<sys/videoio.h>`, sim camera and sim decoder/encoder. Behavior: the new driver interfaces are optional and the drop-frame behaviour needs `IMGDATA_CAP_DROP_FRAME`, so other drivers work as before. JPEG buffers without `sizeimage` are width * height bytes instead of width * height * 2. `V4L2_BUF_FLAG_ERROR` takes the Linux value 0x0040. Compatibility: code that uses the V4L2 structs has to be rebuilt. Code that sets `buf_type` of `v4l2_frmsizeenum` / `v4l2_frmivalenum` or `ctrl_class` of the query structs drops it, as on Linux, and keeps control ids in `uint32_t`. apache/nuttx-apps <apps PR> does this for examples/uvc_cam and system/nxcamera and goes in first. No in-tree driver uses the removed fields. ## Testing Simulator (sim:nxcamera, NSH). Every commit builds on its own, and checkpatch passes. Steps: - load v4l2loopback on the host and feed it with FFmpeg (smptebars, 640x480 YUV 4:2:0) - nxcamera captures 10 frames to a hostfs file - nxcodec decodes a 320x240 H.264 stream on the sim OpenH264 decoder Logs (excerpt): ``` nsh> uname -a NuttX 13.1.0 7fcceafa000 Nov 4 2026 20:37:29 sim sim nsh> mount -t hostfs -o fs=/tmp/upw/cap3/out5-main /host nsh> nxcamera nxcamera> input /dev/video0 nxcamera> output /host/frames.yuv 10 nxcamera> stream 640 480 30 YU12 nxcamera> q nsh> ls -l /host /host: -rw-r--r-- 4608000 2026-11-04 12:37 frames.yuv ... nsh> mount -t hostfs -o fs=/tmp/upw/cap3/nxc5-main /host nsh> cd /host nsh> nxcodec -d /dev/video1 -s 320x240 -f H264 -i t.h264 -f YU12 -o o.yuv nxcodec device name: /dev/video1 nxcodec size: 320x240 nxcodec is single-planar nxcodec init DONE. nxcodec started. ... ``` Result: PASS. Each of the 10 captured frames is byte-identical to FFmpeg's smptebars frame, and the 59 decoded frames are byte-identical to FFmpeg's decode of the same stream; master gives the same output. Additional platform coverage: - BES platform (Cortex-M55): camera preview and still capture with a USB UVC camera, capture into imported dma-bufs, MJPEG decoding on the hardware V4L2 m2m decoder with USERPTR input and DMA-BUF output, frame dropping on buffer underrun. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
