{"id":9878,"url":"https://patchwork.libcamera.org/api/patches/9878/?format=json","web_url":"https://patchwork.libcamera.org/patch/9878/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200930132707.19367-7-jacopo@jmondi.org>","date":"2020-09-30T13:27:04","name":"[libcamera-devel,v4,6/9] android: camera_device: Allocate buffer pools","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"53b8ee6397487ffc26b08588950e63d8428d38d6","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/9878/mbox/","series":[{"id":1340,"url":"https://patchwork.libcamera.org/api/series/1340/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1340","date":"2020-09-30T13:26:58","name":"android: camera_device: Add support for internal buffers","version":4,"mbox":"https://patchwork.libcamera.org/series/1340/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9878/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9878/checks/","tags":{},"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 00A30C3B5E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 30 Sep 2020 13:23:28 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C8D61623BA;\n\tWed, 30 Sep 2020 15:23:27 +0200 (CEST)","from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net\n\t[217.70.183.198])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EE60560364\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 30 Sep 2020 15:23:25 +0200 (CEST)","from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay6-d.mail.gandi.net (Postfix) with ESMTPSA id D6C5FC0010;\n\tWed, 30 Sep 2020 13:23:24 +0000 (UTC)"],"X-Originating-IP":"93.34.118.233","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 30 Sep 2020 15:27:04 +0200","Message-Id":"<20200930132707.19367-7-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.28.0","In-Reply-To":"<20200930132707.19367-1-jacopo@jmondi.org>","References":"<20200930132707.19367-1-jacopo@jmondi.org>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v4 6/9] android: camera_device: Allocate\n\tbuffer 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","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>"},"content":"After the Camera has been configured, walk the list of collected\nCameraStream instances and allocate memory for the ones that needs\nintermediate buffers reserved by the libcamera FrameBufferAllocator.\n\nMaintain a map between each Stream and a vector of pointers to the\nassociated buffers.\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nSigned-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(+)","diff":"diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex 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+\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) {\ndiff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex 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+\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 \n \tCameraMetadata *staticMetadata_;\n \tstd::map<unsigned int, const CameraMetadata *> requestTemplates_;\n","prefixes":["libcamera-devel","v4","6/9"]}