From patchwork Sat Jul 13 17:23:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1696 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5B4706175B for ; Sat, 13 Jul 2019 19:24:50 +0200 (CEST) Received: from pendragon.ideasonboard.com (softbank126209254147.bbtec.net [126.209.254.147]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0A2642B2 for ; Sat, 13 Jul 2019 19:24:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1563038690; bh=VGHOiKNEy9gHqqvdAPRgaT+SmF7KogL50EqUPlP/Jk4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fS/P2qQiOb9V9Ov1sgMvWTodhGXS59VwUJDunyjGhkFanRtZ8nwrKzY5T2fvL7CMC mM6w7lkyoSt85wpn7aoTf7rQQSZTe0QvzCTJmImOZJEDE4RIUJIebsA1c4K1t4xqwZ 7E4LVgg5Cn8X4xPV3v59PCvULJP0rZPgm0dmkSyo= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 13 Jul 2019 20:23:50 +0300 Message-Id: <20190713172351.25452-16-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190713172351.25452-1-laurent.pinchart@ideasonboard.com> References: <20190713172351.25452-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 15/16] libcamera: pipeline: Support importing 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: Sat, 13 Jul 2019 17:24:50 -0000 From: Jacopo Mondi Add support for importing external buffers in all pipeline handlers. Use the stream memory type in the pipeline handlers during buffer allocation to import buffers to or export buffers from the video device. Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/pipeline/ipu3/ipu3.cpp | 49 ++++++++++++++++++------ src/libcamera/pipeline/rkisp1/rkisp1.cpp | 6 ++- src/libcamera/pipeline/uvcvideo.cpp | 5 ++- src/libcamera/pipeline/vimc.cpp | 5 ++- 4 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 488e89f25c5e..9ac5a5387dec 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -69,8 +69,9 @@ public: int configureOutput(ImgUOutput *output, const StreamConfiguration &cfg); - int importBuffers(BufferPool *pool); - int exportBuffers(ImgUOutput *output, BufferPool *pool); + int importInputBuffers(BufferPool *pool); + int importOutputBuffers(ImgUOutput *output, BufferPool *pool); + int exportOutputBuffers(ImgUOutput *output, BufferPool *pool); void freeBuffers(); int start(); @@ -605,7 +606,7 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera, if (!pool) return -ENOMEM; - ret = imgu->importBuffers(pool); + ret = imgu->importInputBuffers(pool); if (ret) goto error; @@ -616,7 +617,7 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera, */ bufferCount = pool->count(); imgu->stat_.pool->createBuffers(bufferCount); - ret = imgu->exportBuffers(&imgu->stat_, imgu->stat_.pool); + ret = imgu->exportOutputBuffers(&imgu->stat_, imgu->stat_.pool); if (ret) goto error; @@ -625,7 +626,10 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera, IPU3Stream *stream = static_cast(s); ImgUDevice::ImgUOutput *dev = stream->device_; - ret = imgu->exportBuffers(dev, &stream->bufferPool()); + if (stream->memoryType() == InternalMemory) + ret = imgu->exportOutputBuffers(dev, &stream->bufferPool()); + else + ret = imgu->importOutputBuffers(dev, &stream->bufferPool()); if (ret) goto error; } @@ -637,8 +641,8 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera, if (!outStream->active_) { bufferCount = vfStream->configuration().bufferCount; outStream->device_->pool->createBuffers(bufferCount); - ret = imgu->exportBuffers(outStream->device_, - outStream->device_->pool); + ret = imgu->exportOutputBuffers(outStream->device_, + outStream->device_->pool); if (ret) goto error; } @@ -646,8 +650,8 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera, if (!vfStream->active_) { bufferCount = outStream->configuration().bufferCount; vfStream->device_->pool->createBuffers(bufferCount); - ret = imgu->exportBuffers(vfStream->device_, - vfStream->device_->pool); + ret = imgu->exportOutputBuffers(vfStream->device_, + vfStream->device_->pool); if (ret) goto error; } @@ -1113,7 +1117,7 @@ int ImgUDevice::configureOutput(ImgUOutput *output, * \param[in] pool The buffer pool to import * \return 0 on success or a negative error code otherwise */ -int ImgUDevice::importBuffers(BufferPool *pool) +int ImgUDevice::importInputBuffers(BufferPool *pool) { int ret = input_->importBuffers(pool); if (ret) { @@ -1134,7 +1138,7 @@ int ImgUDevice::importBuffers(BufferPool *pool) * * \return 0 on success or a negative error code otherwise */ -int ImgUDevice::exportBuffers(ImgUOutput *output, BufferPool *pool) +int ImgUDevice::exportOutputBuffers(ImgUOutput *output, BufferPool *pool) { int ret = output->dev->exportBuffers(pool); if (ret) { @@ -1146,6 +1150,29 @@ int ImgUDevice::exportBuffers(ImgUOutput *output, BufferPool *pool) return 0; } +/** + * \brief Reserve buffers in \a output from the provided \a pool + * \param[in] output The ImgU output device + * \param[in] pool The buffer pool used to reserve buffers in \a output + * + * Reserve a number of buffers equal to the number of buffers in \a pool + * in the \a output device. + * + * \return 0 on success or a negative error code otherwise + */ +int ImgUDevice::importOutputBuffers(ImgUOutput *output, BufferPool *pool) +{ + int ret = output->dev->importBuffers(pool); + if (ret) { + LOG(IPU3, Error) + << "Failed to import buffer in " << output->name + << " ImgU device"; + return ret; + } + + return 0; +} + /** * \brief Release buffers for all the ImgU video devices */ diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index cc33a2cb2572..efa9604bc1e3 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -319,7 +319,11 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera, const std::set &streams) { Stream *stream = *streams.begin(); - return video_->exportBuffers(&stream->bufferPool()); + + if (stream->memoryType() == InternalMemory) + return video_->exportBuffers(&stream->bufferPool()); + else + return video_->importBuffers(&stream->bufferPool()); } int PipelineHandlerRkISP1::freeBuffers(Camera *camera, diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index b299c5da8471..8965210550d2 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -200,7 +200,10 @@ int PipelineHandlerUVC::allocateBuffers(Camera *camera, LOG(UVC, Debug) << "Requesting " << cfg.bufferCount << " buffers"; - return data->video_->exportBuffers(&stream->bufferPool()); + if (stream->memoryType() == InternalMemory) + return data->video_->exportBuffers(&stream->bufferPool()); + else + return data->video_->importBuffers(&stream->bufferPool()); } int PipelineHandlerUVC::freeBuffers(Camera *camera, diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp index 7d96c3645c06..61b68a32ea50 100644 --- a/src/libcamera/pipeline/vimc.cpp +++ b/src/libcamera/pipeline/vimc.cpp @@ -202,7 +202,10 @@ int PipelineHandlerVimc::allocateBuffers(Camera *camera, LOG(VIMC, Debug) << "Requesting " << cfg.bufferCount << " buffers"; - return data->video_->exportBuffers(&stream->bufferPool()); + if (stream->memoryType() == InternalMemory) + return data->video_->exportBuffers(&stream->bufferPool()); + else + return data->video_->importBuffers(&stream->bufferPool()); } int PipelineHandlerVimc::freeBuffers(Camera *camera,