[{"id":12922,"web_url":"https://patchwork.libcamera.org/comment/12922/","msgid":"<20201002002240.GM3722@pendragon.ideasonboard.com>","date":"2020-10-02T00:22:40","subject":"Re: [libcamera-devel] [PATCH v4 6/9] android: camera_device:\n\tAllocate buffer pools","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Wed, Sep 30, 2020 at 03:27:04PM +0200, Jacopo Mondi wrote:\n> After the Camera has been configured, walk the list of collected\n> CameraStream instances and allocate memory for the ones that needs\n> intermediate buffers reserved by the libcamera FrameBufferAllocator.\n> \n> Maintain a map between each Stream and a vector of pointers to the\n> associated buffers.\n> \n> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/android/camera_device.cpp | 36 +++++++++++++++++++++++++++++++++++\n>  src/android/camera_device.h   |  6 ++++++\n>  2 files changed, 42 insertions(+)\n> \n> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n> index 8692771a4538..07041dd916d5 100644\n> --- a/src/android/camera_device.cpp\n> +++ b/src/android/camera_device.cpp\n> @@ -1191,6 +1191,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)\n>  \tstreams_.clear();\n>  \tstreams_.reserve(stream_list->num_streams);\n>  \tallocator_.freeAll();\n> +\tbufferPool_.clear();\n>  \n>  \t/* First handle all non-MJPEG streams. */\n>  \tcamera3_stream_t *jpegStream = nullptr;\n> @@ -1338,6 +1339,25 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)\n>  \t\treturn ret;\n>  \t}\n>  \n> +\t/*\n> +\t * Now that the camera has been configured allocate buffers for\n> +\t * the streams that need memory reserved by libcamera.\n\nI would write \"that are internal and will thus not received buffers from\nthe camera service.\".\n\n> +\t */\n> +\tfor (const CameraStream &cameraStream : streams_) {\n> +\t\tconst StreamConfiguration &cfg = config_->at(cameraStream.index());\n> +\t\tStream *stream = cfg.stream();\n> +\n> +\t\tif (cameraStream.type() != CameraStream::Type::Internal)\n> +\t\t\tcontinue;\n> +\n> +\t\tret = allocateBufferPool(stream);\n> +\t\tif (ret) {\n> +\t\t\tLOG(HAL, Error) << \"Failed to allocate buffers for stream \"\n> +\t\t\t\t\t<< cameraStream.index();\n> +\t\t\treturn ret;\n> +\t\t}\n> +\t}\n> +\n>  \treturn 0;\n>  }\n>  \n> @@ -1371,6 +1391,22 @@ FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer\n>  \treturn new FrameBuffer(std::move(planes));\n>  }\n>  \n> +int CameraDevice::allocateBufferPool(Stream *stream)\n> +{\n> +\tint ret = allocator_.allocate(stream);\n> +\tif (ret < 0)\n> +\t\treturn ret;\n> +\n> +\t/*\n> +\t * Save a pointer to the reserved frame buffer for usage in\n> +\t * the HAL.\n> +\t */\n> +\tfor (const auto &frameBuffer : allocator_.buffers(stream))\n> +\t\tbufferPool_[stream].push_back(frameBuffer.get());\n> +\n> +\treturn 0;\n> +}\n> +\n>  int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request)\n>  {\n>  \tif (!camera3Request->num_output_buffers) {\n> diff --git a/src/android/camera_device.h b/src/android/camera_device.h\n> index 75e3305089d9..c46610725e12 100644\n> --- a/src/android/camera_device.h\n> +++ b/src/android/camera_device.h\n> @@ -166,6 +166,9 @@ protected:\n>  \tstd::string logPrefix() const override;\n>  \n>  private:\n> +\tusing FrameBufferPool = std::map<libcamera::Stream *,\n> +\t\t\t\t\t std::vector<libcamera::FrameBuffer *>>;\n\nDo we need this type ? I agree that the right-hand side is long and not\nnice to write, but the type is only used once, below. Having an alias\nrequires looking it up when reading the code. Up to you.\n\n> +\n>  \tCameraDevice(unsigned int id, const std::shared_ptr<libcamera::Camera> &camera);\n>  \n>  \tstruct Camera3RequestDescriptor {\n> @@ -194,6 +197,8 @@ private:\n>  \n>  \tstd::tuple<uint32_t, uint32_t> calculateStaticMetadataSize();\n>  \tlibcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer);\n> +\tint allocateBufferPool(libcamera::Stream *stream);\n> +\n>  \tvoid notifyShutter(uint32_t frameNumber, uint64_t timestamp);\n>  \tvoid notifyError(uint32_t frameNumber, camera3_stream_t *stream);\n>  \tCameraMetadata *requestTemplatePreview();\n> @@ -208,6 +213,7 @@ private:\n>  \tstd::shared_ptr<libcamera::Camera> camera_;\n>  \tstd::unique_ptr<libcamera::CameraConfiguration> config_;\n>  \tlibcamera::FrameBufferAllocator allocator_;\n> +\tFrameBufferPool bufferPool_;\n\nMaybe bufferPools_ as there's more than one pool ?\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  \n>  \tCameraMetadata *staticMetadata_;\n>  \tstd::map<unsigned int, const CameraMetadata *> requestTemplates_;","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 9E58CC3B5C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  2 Oct 2020 00:23:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2A65260BCD;\n\tFri,  2 Oct 2020 02:23:20 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6685F60576\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  2 Oct 2020 02:23:18 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C282560;\n\tFri,  2 Oct 2020 02:23:17 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"e2lR44Dl\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1601598198;\n\tbh=1H4n6vCf1/fFkpJ6Kxu3E+WvjGdEHlMOS+ZbGa63jBQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=e2lR44DlEEdWfnDwi1KlCVm6UWSso1ngxDvVWCdEpbQG8GwMz8NDigKW+/REsv3Y0\n\ti4meTfBQiu/mpNQ16LlWELhE9x3saI/LQSYIz1rg/pWSDyExk9k7Xgl6SiZZSHeb9O\n\tkCbyq/fawQkCyeNcTEGwDtJH64XfhyPvdJl8XKKw=","Date":"Fri, 2 Oct 2020 03:22:40 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<20201002002240.GM3722@pendragon.ideasonboard.com>","References":"<20200930132707.19367-1-jacopo@jmondi.org>\n\t<20200930132707.19367-7-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200930132707.19367-7-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH v4 6/9] android: camera_device:\n\tAllocate buffer pools","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"hanlinchen@chromium.org, libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]