From patchwork Sun Jun 30 18:10:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1533 Return-Path: Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C822360BC0 for ; Sun, 30 Jun 2019 20:09:37 +0200 (CEST) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 53503200007; Sun, 30 Jun 2019 18:09:37 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sun, 30 Jun 2019 20:10:41 +0200 Message-Id: <20190630181049.9548-1-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 0/8] libcamera: Add support for importing external memory buffers X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Jun 2019 18:09:37 -0000 The libcamera APIs need to be augmented to allow application to use buffers whose memory has been allocated outside of the library. This feature is particularly essential to support the Android camera HAL, which uses buffers allocated by mean of gralloc and exported by using DMABUF file descriptor. Each Stream has a buffer pool which contains buffers which are used to interact with the underlying video devices and whose memory is directly accessed by applications in case a Stream uses its internal memory, but could also be mapped on buffers whose memory is allocated elsewhere by exchanging the dmabuf file descriptors associated to each buffer's plane. Extend the StreamConfiguration class with a flag that defines the memory type a Stream uses (internal or external) and use said flag in pipeline handler to either allocate memory for the buffer, or prepare to use externally allocated buffers. As a consequence, rename PipelineHandler::allocateBuffers() to PipelineHandler::setupBuffers(). On top of this perform buffer mapping for streams using external memory at request queueing time, hiding the mapping from pipeline handler that will always only interact with streams from the Stream's internal pool. Add a map of buffers to each request to perform back-and-forth translation of application provided buffers to stream internal buffer at request complete time. Finally, add a test application that use buffers allocated in the vivid output device to stream a Camera. The test is not meant to be considered for merge, but more a proof a concept (it has my camera name hardcoded...) and fails for buffer #0 (but works for all others). Comments are missing, rough edges here and there, I'm sending as RFC as this touches several part of the core APIs and I would like to have feedbacks sooner than later. Thanks j Jacopo Mondi (8): libcamera: v4l2_videodevice: Re-group operations libcamera: stream: Provide accessors to buffers libcamera: stream: Add Stream memory type libcamera: Rename PipelineHandler::allocateBuffers libcamera: request: Rename the Stream to Buffer map libcamera: stream: Add operation to map buffers libcamera: request: Support buffer mapping test: v4l2_videodevice: Add buffer import test include/libcamera/buffer.h | 1 + include/libcamera/request.h | 8 +- include/libcamera/stream.h | 25 +++ src/cam/capture.cpp | 4 +- src/libcamera/camera.cpp | 11 +- src/libcamera/include/pipeline_handler.h | 4 +- src/libcamera/include/v4l2_videodevice.h | 6 +- src/libcamera/pipeline/ipu3/ipu3.cpp | 12 +- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 6 +- src/libcamera/pipeline/uvcvideo.cpp | 16 +- src/libcamera/pipeline/vimc.cpp | 16 +- src/libcamera/pipeline_handler.cpp | 12 +- src/libcamera/request.cpp | 43 ++++- src/libcamera/stream.cpp | 115 ++++++++++- src/libcamera/v4l2_videodevice.cpp | 170 ++++++++-------- src/qcam/main_window.cpp | 4 +- test/camera/capture.cpp | 3 +- test/camera/statemachine.cpp | 3 +- test/v4l2_videodevice/buffer_import.cpp | 234 +++++++++++++++++++++++ test/v4l2_videodevice/meson.build | 1 + 20 files changed, 547 insertions(+), 147 deletions(-) create mode 100644 test/v4l2_videodevice/buffer_import.cpp --- 2.21.0