From patchwork Tue Mar 12 12:12:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 723 Return-Path: Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 62522611A2 for ; Tue, 12 Mar 2019 13:12:24 +0100 (CET) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id EEBE41C000A; Tue, 12 Mar 2019 12:12:23 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 12 Mar 2019 13:12:36 +0100 Message-Id: <20190312121242.2253-9-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190312121242.2253-1-jacopo@jmondi.org> References: <20190312121242.2253-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 08/14] libcamera: ipu3: Implement buffer allocation 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: Tue, 12 Mar 2019 12:12:25 -0000 Implement buffer allocation in IPU3 pipeline handlers. As the pipeline handler supports a single stream, preprare two buffer pools for 'viewfinder' and 'stat' video devices, and export the 'output' video device buffers to the Stream's pool. Share buffers between the CIO2 output and the ImgU input video devices, as the output of the former should immediately be provided to the latter for further processing. Signed-off-by: Jacopo Mondi --- src/libcamera/pipeline/ipu3/ipu3.cpp | 48 +++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 363b24ceead2..ad866346e13c 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -62,6 +62,9 @@ public: V4L2Device *viewfinder; V4L2Device *stat; /* \todo Add param video device for 3A tuning */ + + BufferPool vfPool; + BufferPool statPool; }; struct CIO2Device { @@ -80,6 +83,8 @@ struct CIO2Device { V4L2Device *output; V4L2Subdevice *csi2; V4L2Subdevice *sensor; + + BufferPool pool; }; class IPU3CameraData : public CameraData @@ -123,6 +128,8 @@ public: private: static constexpr unsigned int IPU3_IMGU_COUNT = 2; static constexpr unsigned int IPU3_BUFFER_COUNT = 4; + static constexpr unsigned int IPU3_CIO2_BUFFER_COUNT = 4; + static constexpr unsigned int IPU3_IMGU_BUFFER_COUNT = 4; IPU3CameraData *cameraData(const Camera *camera) { @@ -305,16 +312,47 @@ int PipelineHandlerIPU3::configureStreams(Camera *camera, int PipelineHandlerIPU3::allocateBuffers(Camera *camera, Stream *stream) { - const StreamConfiguration &cfg = stream->configuration(); IPU3CameraData *data = cameraData(camera); + V4L2Device *viewfinder = data->imgu->viewfinder; + V4L2Device *output = data->imgu->output; + V4L2Device *input = data->imgu->input; V4L2Device *cio2 = data->cio2.output; + V4L2Device *stat = data->imgu->stat; + int ret; - if (!cfg.bufferCount) - return -EINVAL; + /* Share buffers between CIO2 output and ImgU input. */ + data->cio2.pool.createBuffers(IPU3_CIO2_BUFFER_COUNT); + ret = cio2->exportBuffers(&data->cio2.pool); + if (ret) { + LOG(IPU3, Error) << "Failed to reserve CIO2 memory"; + return ret; + } + + ret = input->importBuffers(&data->cio2.pool); + if (ret) { + LOG(IPU3, Error) << "Failed to import ImgU memory"; + return ret; + } + + /* Prepare the buffer pools for viewfinder and stat. */ + data->imgu->vfPool.createBuffers(IPU3_IMGU_BUFFER_COUNT); + ret = viewfinder->exportBuffers(&data->imgu->vfPool); + if (ret) { + LOG(IPU3, Error) << "Failed to reserve ImgU viewfinder memory"; + return ret; + } + + data->imgu->statPool.createBuffers(IPU3_IMGU_BUFFER_COUNT); + ret = stat->exportBuffers(&data->imgu->statPool); + if (ret) { + LOG(IPU3, Error) << "Failed to reserve ImgU stat memory"; + return ret; + } - int ret = cio2->exportBuffers(&stream->bufferPool()); + /* Export ImgU output buffers to the stream's pool. */ + ret = output->exportBuffers(&stream->bufferPool()); if (ret) { - LOG(IPU3, Error) << "Failed to request memory"; + LOG(IPU3, Error) << "Failed to reserve ImgU output memory"; return ret; }