{"id":10425,"url":"https://patchwork.libcamera.org/api/patches/10425/?format=json","web_url":"https://patchwork.libcamera.org/patch/10425/","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":"<20201116112458.148477-2-naush@raspberrypi.com>","date":"2020-11-16T11:24:58","name":"[libcamera-devel,v2,2/2] ipa: raspberrypi: Use MappedFrameBuffer for the IPA buffers","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"253d7e76cc1e415b25b321eeb3615cf12f774cbd","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/10425/mbox/","series":[{"id":1461,"url":"https://patchwork.libcamera.org/api/series/1461/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1461","date":"2020-11-16T11:24:57","name":"[libcamera-devel,v2,1/2] pipeline: raspberrypi: Use MappedFrameBuffer for embedded data buffers","version":2,"mbox":"https://patchwork.libcamera.org/series/1461/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/10425/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/10425/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 E37DFBE081\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 16 Nov 2020 11:25:07 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A44F5632C2;\n\tMon, 16 Nov 2020 12:25:07 +0100 (CET)","from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com\n\t[IPv6:2a00:1450:4864:20::42d])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B7DD2632C1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Nov 2020 12:25:05 +0100 (CET)","by mail-wr1-x42d.google.com with SMTP id r17so18312921wrw.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Nov 2020 03:25:05 -0800 (PST)","from naushir-VirtualBox.patuck.local ([88.97.76.4])\n\tby smtp.gmail.com with ESMTPSA id\n\td8sm18828152wmb.11.2020.11.16.03.25.04\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 16 Nov 2020 03:25:04 -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=\"qrt/7Ahe\"; 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=MFxOD1RHH9DUpvo3uH9tZAAzL14TCR0C3W6cmDAUVGs=;\n\tb=qrt/7AheKGFipt9uBWzxfatoUHYzht2arTdqFqakCsOy47U7bzqygbx15aRf7AFeFE\n\t6Wr2pVsEnk8PjSZpG0qliHYcT3UpQGnFiBL+YmqjJXV8C2ECjn10LyP+9Is16VZn37Rw\n\tOIskDjwT5S+q0zVklIh7afqDl7ziZ9vYrKdr088ZkdW/1GUqWeFrk9fqOTbFf6U5IZCH\n\tdfupd2pxOVUGEMXD09jIYgK8GGvA9NHQtK8ou30DmaA01rAi5fqzfcCr7iuYMiSDwCBl\n\tLLufikPheXnbMuoU+RLJuQrMHMbZLu2Ahii8RjBxxIAeoQ5543upwX1jp9B6025iCf6O\n\tWrmw==","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=MFxOD1RHH9DUpvo3uH9tZAAzL14TCR0C3W6cmDAUVGs=;\n\tb=A3QsqV/l0qVALmqvoJ05LYeY5gNOTuwjsQiH70visfDsdF+CZXJRWI2TomqRsAptAB\n\tK4AxQPWg0bV0U9EuyLwBo1R5GR/qvKPHOI3gkuAGeBjihdgB390cvHSF3ceSn9d422vv\n\tPsycBaBZ57ueK8k9l4lJuwjol1D5nkzHTgN0AZvooLcDSuay5ixo/2wyp/5Jkf1veZWj\n\t0IsAs6mpnJlUTcCQFZI9L7PXc0Fwh2bpKaYNBAe/P2IZojbVt9SOVMu8ppizjnFpwSkR\n\tqh4jinfNkKfam4QUtiIg0t/8qvlytn4OYFCD/vWTexG/QRsSo/1NIEfE46/KQJ40iVcA\n\tFaqA==","X-Gm-Message-State":"AOAM531Ackhg9NgPyw8qYcLLfr0XaWCcJxsOfgrdNeE5FRPAz303kRF8\n\tcfRtaeM7jJotjvyfkpPDfZN6uKjO/6ANmA==","X-Google-Smtp-Source":"ABdhPJxqO7MTYuxyRWNRSYNoGg0HH6/k5ELbkPBIwoPEDdXfWh+bOcOZYaWVo0OZYFrCLvPtpehFFA==","X-Received":"by 2002:adf:f146:: with SMTP id\n\ty6mr18829515wro.298.1605525905058; \n\tMon, 16 Nov 2020 03:25:05 -0800 (PST)","From":"Naushir Patuck <naush@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 16 Nov 2020 11:24:58 +0000","Message-Id":"<20201116112458.148477-2-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20201116112458.148477-1-naush@raspberrypi.com>","References":"<20201116112458.148477-1-naush@raspberrypi.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v2 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>\n---\n src/ipa/raspberrypi/raspberrypi.cpp | 41 +++++++++++------------------\n 1 file changed, 15 insertions(+), 26 deletions(-)","diff":"diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex 1c255aa2..6bb45b75 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 = FrameBuffer(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,16 @@ 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+\tint size = buffers_.find(bufferId)->second.maps()[0].size();\n+\tvoid *ptr = buffers_.find(bufferId)->second.maps()[0].data();\n \thelper_->Parser().SetBufferSize(size);\n-\tRPiController::MdParser::Status status = helper_->Parser().Parse(it->second);\n+\tRPiController::MdParser::Status status = helper_->Parser().Parse(ptr);\n \tif (status != RPiController::MdParser::Status::OK) {\n \t\tLOG(IPARPI, Error) << \"Embedded Buffer parsing failed, error \" << status;\n \t} else {\n@@ -820,13 +808,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+\tvoid *ptr = buffers_.find(bufferId)->second.maps()[0].data();\n+\tbcm2835_isp_stats *stats = static_cast<bcm2835_isp_stats *>(ptr);\n \tRPiController::StatisticsPtr statistics = std::make_shared<bcm2835_isp_stats>(*stats);\n \tcontroller_.Process(statistics, &rpiMetadata_);\n \n","prefixes":["libcamera-devel","v2","2/2"]}