{"id":10428,"url":"https://patchwork.libcamera.org/api/patches/10428/?format=json","web_url":"https://patchwork.libcamera.org/patch/10428/","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":"<20201116143757.155890-2-naush@raspberrypi.com>","date":"2020-11-16T14:37:57","name":"[libcamera-devel,v3,2/2] ipa: raspberrypi: Use MappedFrameBuffer for the IPA buffers","commit_ref":"6a2dfc26095f9564ecb7bed6506949ef18a8e9da","pull_url":null,"state":"accepted","archived":false,"hash":"76e865222efcdd734e6ab176011ad3888094c06f","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/10428/mbox/","series":[{"id":1463,"url":"https://patchwork.libcamera.org/api/series/1463/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1463","date":"2020-11-16T14:37:56","name":"[libcamera-devel,v3,1/2] pipeline: raspberrypi: Use MappedFrameBuffer for embedded data buffers","version":3,"mbox":"https://patchwork.libcamera.org/series/1463/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/10428/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/10428/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 89061BE082\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 16 Nov 2020 14:38:11 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 58DA2632C3;\n\tMon, 16 Nov 2020 15:38:11 +0100 (CET)","from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com\n\t[IPv6:2a00:1450:4864:20::32c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DCEE5632C1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Nov 2020 15:38:07 +0100 (CET)","by mail-wm1-x32c.google.com with SMTP id s13so23814618wmh.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Nov 2020 06:38:07 -0800 (PST)","from naushir-VirtualBox.patuck.local ([88.97.76.4])\n\tby smtp.gmail.com with ESMTPSA id\n\tj4sm22820810wrn.83.2020.11.16.06.38.06\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 16 Nov 2020 06:38:06 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"bA+QTwVO\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=8I6DT3x0SsFQNXMnrPiAb9GclErL8X7Bhpo4v3V43Qc=;\n\tb=bA+QTwVO5pmiBt3FKUG3/Vk0sqH4nHJxAQ4WyCRjzLyHX0yh7vvWEHCailJhgllRvP\n\tJLcSR7S0Jk0fhXdrRI6HksgDOvz7wtuklZ/+O1Sol1h/OoRKxn1A7yyRRJpGqFaB5SCp\n\tsqQvnM6jt252qOS9XAJmMkiYEWrWSMM7kl2GlAgW1qKA/krClQr/Wxoxn3g6ErqyMUmo\n\tYmPLOFUD4NLD5DsEzEegBrUsnFh81SfxrDe+kNCjgwCgc6YX1aGt2QyWg+MtOB6iJsgz\n\t5C/tH1dTxb30avZ6lmZLz0HjfXoVbVDu7ANG+tkKwp7yhM6PvBeE+bE7+/sWm8UIPrqP\n\tn4xQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=8I6DT3x0SsFQNXMnrPiAb9GclErL8X7Bhpo4v3V43Qc=;\n\tb=DSOZEKMQUYbF6wGcB2LsOow1/haG8tif7G5ZybyXiyQlYkwegNWAYM5JoC6U/97c2U\n\t12sxRTU7e7BNZlQ2LHNrcYUBQ10WPJdCgpo5Kfnc8lYeAqnFQmyZ6iUSR5J7xxiYAG5x\n\t8ZnBqoh/6OB9NQSKfM68EytdltAn0L9LYMMvuw00P3V+hJjcxErJ8IWU9auMzMN5Li0Z\n\tTM+kd1CqrrC16EU8Jl/NVPzv1r0TLKZ8BiQ0N3C4RwN5leZRQqoZ4NrQ2RdYl7qOu6tl\n\tpyv96KNJUBktpZ2ywdL2c3dWi/jY+QXUUNwCA8SToxTqYt5sjQS2rDqgoKow3xlNUiD3\n\tP50A==","X-Gm-Message-State":"AOAM533Iyop2UQKPe3shhKfNJglqaAb2QiCLdhLErM4BFyLMaaCMpKaV\n\t/EJjg9kM3bAp0gD12IUjeMiFFaqOtPQ2Hw==","X-Google-Smtp-Source":"ABdhPJyKjB2GKoOkzCwLm+7uSmUyWdlYN07RrqVMJBm74mMyXC1WoTOM7y/+xrVJF0FEHQYls23+0w==","X-Received":"by 2002:a1c:103:: with SMTP id 3mr15534747wmb.81.1605537487294; \n\tMon, 16 Nov 2020 06:38:07 -0800 (PST)","From":"Naushir Patuck <naush@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 16 Nov 2020 14:37:57 +0000","Message-Id":"<20201116143757.155890-2-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20201116143757.155890-1-naush@raspberrypi.com>","References":"<20201116143757.155890-1-naush@raspberrypi.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v3 2/2] ipa: raspberrypi: Use\n\tMappedFrameBuffer for the IPA buffers","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Instead of directly mmaping/unmapping buffers passed to the IPA, use\na MappedFrameBuffer. The latter is a cleaner interface, and avoid\ncode duplication.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/ipa/raspberrypi/raspberrypi.cpp | 42 +++++++++++------------------\n 1 file changed, 15 insertions(+), 27 deletions(-)","diff":"diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex 1c255aa2..ac24d5ef 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -24,6 +24,7 @@\n \n #include <libipa/ipa_interface_wrapper.h>\n \n+#include \"libcamera/internal/buffer.h\"\n #include \"libcamera/internal/camera_sensor.h\"\n #include \"libcamera/internal/log.h\"\n #include \"libcamera/internal/utils.h\"\n@@ -110,8 +111,7 @@ private:\n \tvoid applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls);\n \tvoid resampleTable(uint16_t dest[], double const src[12][16], int destW, int destH);\n \n-\tstd::map<unsigned int, FrameBuffer> buffers_;\n-\tstd::map<unsigned int, void *> buffersMemory_;\n+\tstd::map<unsigned int, MappedFrameBuffer> buffers_;\n \n \tControlInfoMap unicamCtrls_;\n \tControlInfoMap ispCtrls_;\n@@ -319,31 +319,18 @@ void IPARPi::configure(const CameraSensorInfo &sensorInfo,\n void IPARPi::mapBuffers(const std::vector<IPABuffer> &buffers)\n {\n \tfor (const IPABuffer &buffer : buffers) {\n-\t\tauto elem = buffers_.emplace(std::piecewise_construct,\n-\t\t\t\t\t     std::forward_as_tuple(buffer.id),\n-\t\t\t\t\t     std::forward_as_tuple(buffer.planes));\n-\t\tconst FrameBuffer &fb = elem.first->second;\n-\n-\t\tbuffersMemory_[buffer.id] = mmap(nullptr, fb.planes()[0].length,\n-\t\t\t\t\t\t PROT_READ | PROT_WRITE, MAP_SHARED,\n-\t\t\t\t\t\t fb.planes()[0].fd.fd(), 0);\n-\n-\t\tif (buffersMemory_[buffer.id] == MAP_FAILED) {\n-\t\t\tint ret = -errno;\n-\t\t\tLOG(IPARPI, Fatal) << \"Failed to mmap buffer: \" << strerror(-ret);\n-\t\t}\n+\t\tconst FrameBuffer fb(buffer.planes);\n+\t\tbuffers_.emplace(buffer.id, MappedFrameBuffer(&fb, PROT_READ | PROT_WRITE));\n \t}\n }\n \n void IPARPi::unmapBuffers(const std::vector<unsigned int> &ids)\n {\n \tfor (unsigned int id : ids) {\n-\t\tconst auto fb = buffers_.find(id);\n-\t\tif (fb == buffers_.end())\n+\t\tauto it = buffers_.find(id);\n+\t\tif (it == buffers_.end())\n \t\t\tcontinue;\n \n-\t\tmunmap(buffersMemory_[id], fb->second.planes()[0].length);\n-\t\tbuffersMemory_.erase(id);\n \t\tbuffers_.erase(id);\n \t}\n }\n@@ -785,15 +772,15 @@ void IPARPi::prepareISP(unsigned int bufferId)\n \n bool IPARPi::parseEmbeddedData(unsigned int bufferId, struct DeviceStatus &deviceStatus)\n {\n-\tauto it = buffersMemory_.find(bufferId);\n-\tif (it == buffersMemory_.end()) {\n+\tauto it = buffers_.find(bufferId);\n+\tif (it == buffers_.end()) {\n \t\tLOG(IPARPI, Error) << \"Could not find embedded buffer!\";\n \t\treturn false;\n \t}\n \n-\tint size = buffers_.find(bufferId)->second.planes()[0].length;\n-\thelper_->Parser().SetBufferSize(size);\n-\tRPiController::MdParser::Status status = helper_->Parser().Parse(it->second);\n+\tSpan<uint8_t> mem = it->second.maps()[0];\n+\thelper_->Parser().SetBufferSize(mem.size());\n+\tRPiController::MdParser::Status status = helper_->Parser().Parse(mem.data());\n \tif (status != RPiController::MdParser::Status::OK) {\n \t\tLOG(IPARPI, Error) << \"Embedded Buffer parsing failed, error \" << status;\n \t} else {\n@@ -820,13 +807,14 @@ bool IPARPi::parseEmbeddedData(unsigned int bufferId, struct DeviceStatus &devic\n \n void IPARPi::processStats(unsigned int bufferId)\n {\n-\tauto it = buffersMemory_.find(bufferId);\n-\tif (it == buffersMemory_.end()) {\n+\tauto it = buffers_.find(bufferId);\n+\tif (it == buffers_.end()) {\n \t\tLOG(IPARPI, Error) << \"Could not find stats buffer!\";\n \t\treturn;\n \t}\n \n-\tbcm2835_isp_stats *stats = static_cast<bcm2835_isp_stats *>(it->second);\n+\tSpan<uint8_t> mem = it->second.maps()[0];\n+\tbcm2835_isp_stats *stats = reinterpret_cast<bcm2835_isp_stats *>(mem.data());\n \tRPiController::StatisticsPtr statistics = std::make_shared<bcm2835_isp_stats>(*stats);\n \tcontroller_.Process(statistics, &rpiMetadata_);\n \n","prefixes":["libcamera-devel","v3","2/2"]}