From patchwork Sat Mar 14 23:57:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3093 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1809360420 for ; Sun, 15 Mar 2020 00:57:40 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8F53410CA for ; Sun, 15 Mar 2020 00:57:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1584230259; bh=9N1+EvM+pGTfD9PTsUoG0Hk62UCS7gUhyYtnLv2UvJw=; h=From:To:Subject:Date:From; b=V39AYj43reosmSF/woreqKJK00cZKAuJCHbP9CxxEIsw8Y8zRcb2M0b6MtpcHSxKc mH2xm0a2pb0A99fZs54rkZElKXf248UYJR84nRcafBVC7/8tgbW+Xoagu+SJYmFlM+ Nm6jsL0mX3qJCVpJdRRPZZZdJas4+a4urpes8xcM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 15 Mar 2020 01:57:19 +0200 Message-Id: <20200314235728.15495-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 0/9] Simplify buffer management with V4L2 buffer orphaning X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Mar 2020 23:57:40 -0000 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(-)