[libcamera-devel] [PATCH 0/9] Simplify buffer management with V4L2 buffer orphaning

Laurent Pinchart laurent.pinchart at ideasonboard.com
Sun Mar 15 00:57:19 CET 2020


Hello,

This patch series reworks the buffer API (again :-)) to simplify the
interface between the Camera and PipelineHandler objects thanks to the
use of V4L2 buffer orphaning.

Since Linux v5.0, V4L2 support buffer orphaning. This feature allows
calling VIDIOC_REQBUFS(0) when dmabuf exported from MMAP buffers still
exist. While this simplifies handling of the V4L2 video device itself by
removing the need to track exported buffers before freeing buffers, the
feature has an interested side effect: It allows allocating and
exporting MMAP buffers before reconfiguring the device for DMABUF usage.
This effectively provides a cheap version of a generic buffer allocator
compatible with the V4L2 video device.

Patch 1/9 is a small initial cleanup of one test class, and is followed
by patches 2/9 to 5/9 that implements support for standalone buffer
export throught buffer orphaning. The V4L2VideoDevice then exposes three
functions, allocateBuffers() for regular MMAP buffer allocation,
exportBuffers() for export of orphaned buffers, and importBuffers() to
set the device to DMABUF mode.

Patch 6/9 is a small drive-by cleaned for the Camera class. Patch 7/9
starts the rework of the PipelineHandler API by decoupling buffer import
and export, and patch 8/9 finishes it by folding buffer management
(import and free) with the start() and stop() operations.

Patch 9/9 finally lifts some restrictions on the FrameBufferAllocator
class, made possible by the rework of the API.

Further enhancements are possible, such as switching to
VIDIOC_CREATE_BUFS to allocate buffers of user-specified sizes, removing
the limitation that the Camera needs to be configured before allocating
buffers.

Laurent Pinchart (9):
  test: libtest: buffer_source: Close video device right after
    allocation
  libcamera: v4l2_videodevice: Rename exportBuffers() to
    allocateBuffers()
  libcamera: v4l2_videodevice: Pass memory type to reqbufs()
  libcamera: v4l2_videodevice: Refactor allocateBuffers()
  libcamera: v4l2_videodevice: Add standalone buffer export support
  libcamera: camera: Propagate error value from importFrameBuffer
  libcamera: pipeline_handler: Decouple buffer import and export
  libcamera: pipeline_handler: Fold buffer management with start/stop
  libcamera: framebuffer_allocator: Lift camera restrictions on
    allocator

 include/libcamera/camera.h                |   3 -
 include/libcamera/framebuffer_allocator.h |   5 +-
 src/cam/capture.cpp                       |   2 +-
 src/gstreamer/gstlibcameraallocator.cpp   |   2 +-
 src/libcamera/camera.cpp                  |  46 +----
 src/libcamera/framebuffer_allocator.cpp   |  34 ----
 src/libcamera/include/pipeline_handler.h  |   2 -
 src/libcamera/include/v4l2_videodevice.h  |   8 +-
 src/libcamera/pipeline/ipu3/ipu3.cpp      | 150 +++++++--------
 src/libcamera/pipeline/rkisp1/rkisp1.cpp  |  24 +--
 src/libcamera/pipeline/uvcvideo.cpp       |  28 ++-
 src/libcamera/pipeline/vimc.cpp           |  28 ++-
 src/libcamera/pipeline_handler.cpp        |  58 +-----
 src/libcamera/v4l2_videodevice.cpp        | 221 ++++++++++++++++++----
 src/qcam/main_window.cpp                  |   2 +-
 src/v4l2/v4l2_camera.cpp                  |   2 +-
 test/camera/capture.cpp                   |   2 +-
 test/camera/statemachine.cpp              |   2 +-
 test/libtest/buffer_source.cpp            |  26 +--
 test/libtest/buffer_source.h              |   1 -
 test/v4l2_videodevice/buffer_sharing.cpp  |   2 +-
 test/v4l2_videodevice/capture_async.cpp   |   6 +-
 test/v4l2_videodevice/request_buffers.cpp |   2 +-
 test/v4l2_videodevice/stream_on_off.cpp   |   2 +-
 test/v4l2_videodevice/v4l2_m2mdevice.cpp  |   8 +-
 25 files changed, 322 insertions(+), 344 deletions(-)

-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list