{"id":10424,"url":"https://patchwork.libcamera.org/api/patches/10424/?format=json","web_url":"https://patchwork.libcamera.org/patch/10424/","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-1-naush@raspberrypi.com>","date":"2020-11-16T11:24:57","name":"[libcamera-devel,v2,1/2] pipeline: raspberrypi: Use MappedFrameBuffer for embedded data buffers","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"f8c0d6f69abdd545ee65e6e7bcbcba5162dcea14","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/10424/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/10424/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/10424/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 BE2B7BE081\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 16 Nov 2020 11:25:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4D9C4632C1;\n\tMon, 16 Nov 2020 12:25:06 +0100 (CET)","from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com\n\t[IPv6:2a00:1450:4864:20::42a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A9545631B5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Nov 2020 12:25:04 +0100 (CET)","by mail-wr1-x42a.google.com with SMTP id k2so18323375wrx.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Nov 2020 03:25:04 -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.02\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 16 Nov 2020 03:25:02 -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=\"XWz70blK\"; 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:mime-version\n\t:content-transfer-encoding;\n\tbh=UJdolys+WSJVKPXmuVms/SsEXhD62UGdUH3Pqy0i8ag=;\n\tb=XWz70blKISlj0SLcfMBw3pEcIYxSUbyUcqhZ7Cch3pPQj2OyGVAAkFKx6yT3daYW9d\n\t09744Z4vhEJNjiqhwzbaIJqJQ+nBCYWdZrKjXrzaJsI1wBI+VVfrJ3gr1+7nEX2/PZsO\n\t9Xf7EkhPp6TwOXOGfG/oZeG+1ChLxzAW8J7jcGdH8MknU/a+kUAEHaiub8gwMcj2BqdG\n\tHeFCSufL4tR8/d1ZEnX9stNrbap5041YW2a0g2mF7uDvmN8ZbgXVK7YjWx9RLYIHo4fW\n\teLs/eIF4hBCyQfkmviBbDzBT9pqjNyoyOS7TY1Pxm6gBO9B6j1F6Yikwd5IMlR0N5hQU\n\tKghA==","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:mime-version\n\t:content-transfer-encoding;\n\tbh=UJdolys+WSJVKPXmuVms/SsEXhD62UGdUH3Pqy0i8ag=;\n\tb=tKjKispq+8bWfbruWOYMVixthz9qpLLnn260bORKIs9zkq71WzD/OUQ8yex9Zou5/B\n\tjokfMa+hcXIj/Nv+UlbaVfoA88n3edIRi0Mpmjvb873wHy/lwVKuNUdSo/+YmUJcT++t\n\t7nggpfr1j262drXPqlQQqJEcPkGamfYbcDoShcE6yJpUFwXOXyiY0nSWOC3mS/ggTMqy\n\t7Y247Iukj7bpwY7Bkm9dxeDdnGU1iyMOvbQP6Q8+tyUsSLIkHZFqbyn3YjOFGT8PL4oF\n\toaNs90zzfLwet+7CUCohpmnfArrrhFTWcKfgQmt8BvIGLijp4fCOwBFw+nR7K/1vYBv/\n\tIP0w==","X-Gm-Message-State":"AOAM533CDEQE/hugZnHrM7TX/ZWdCm5a8CIJhKHZyJSw7G4p08ZGPyRl\n\tUtGqyYP/Enqzkk6cUBTsVqwk0w1YAnBX1g==","X-Google-Smtp-Source":"ABdhPJwog2QVd061mTPiNTVNqZh3UoGMQL0OFM8ie11ye6Mzda6Ww6q8KRHgHbAZOZbiWhOBe7xUaQ==","X-Received":"by 2002:a5d:5308:: with SMTP id\n\te8mr18625209wrv.299.1605525904010; \n\tMon, 16 Nov 2020 03:25:04 -0800 (PST)","From":"Naushir Patuck <naush@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 16 Nov 2020 11:24:57 +0000","Message-Id":"<20201116112458.148477-1-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v2 1/2] pipeline: raspberrypi: Use\n\tMappedFrameBuffer for embedded data 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":"Use a MappedFrameBuffer to mmap embedded data buffers for the pipeline\nhandler to use in the cases where the sensor does not fill it in. This\navoids the need to mmap and unmap on every frame.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n .../pipeline/raspberrypi/raspberrypi.cpp      | 33 ++++++++++++++-----\n 1 file changed, 25 insertions(+), 8 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex dd62dfc7..faa06c00 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -24,6 +24,7 @@\n #include <linux/videodev2.h>\n \n #include \"libcamera/internal/bayer_format.h\"\n+#include \"libcamera/internal/buffer.h\"\n #include \"libcamera/internal/camera_sensor.h\"\n #include \"libcamera/internal/device_enumerator.h\"\n #include \"libcamera/internal/ipa_manager.h\"\n@@ -165,6 +166,12 @@ public:\n \t/* Stores the ids of the buffers mapped in the IPA. */\n \tstd::unordered_set<unsigned int> ipaBuffers_;\n \n+\t/*\n+\t * Map of (internal) mmaped embedded data buffers, to avoid having to\n+\t * map/unmap on every frame.\n+\t */\n+\tstd::map<unsigned int, MappedFrameBuffer> mappedEmbeddedBuffers_;\n+\n \t/* DMAHEAP allocation helper. */\n \tRPi::DmaHeap dmaHeap_;\n \tFileDescriptor lsTable_;\n@@ -1040,6 +1047,13 @@ int PipelineHandlerRPi::prepareBuffers(Camera *camera)\n \t\t\treturn ret;\n \t}\n \n+\tif (!data->sensorMetadata_) {\n+\t\tfor (auto const &it : data->unicam_[Unicam::Embedded].getBuffers()) {\n+\t\t\tdata->mappedEmbeddedBuffers_.emplace(it.first,\n+\t\t\t\t\t\t\t     MappedFrameBuffer(it.second, PROT_READ | PROT_WRITE));\n+\t\t}\n+\t}\n+\n \t/*\n \t * Pass the stats and embedded data buffers to the IPA. No other\n \t * buffers need to be passed.\n@@ -1078,6 +1092,7 @@ void PipelineHandlerRPi::freeBuffers(Camera *camera)\n \tstd::vector<unsigned int> ipaBuffers(data->ipaBuffers_.begin(), data->ipaBuffers_.end());\n \tdata->ipa_->unmapBuffers(ipaBuffers);\n \tdata->ipaBuffers_.clear();\n+\tdata->mappedEmbeddedBuffers_.clear();\n \n \tfor (auto const stream : data->streams_)\n \t\tstream->releaseBuffers();\n@@ -1310,14 +1325,16 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer)\n \t\t * metadata buffer.\n \t\t */\n \t\tif (!sensorMetadata_) {\n-\t\t\tconst FrameBuffer &fb = buffer->planes();\n-\t\t\tuint32_t *mem = static_cast<uint32_t *>(::mmap(nullptr, fb.planes()[0].length,\n-\t\t\t\t\t\t\t\t       PROT_READ | PROT_WRITE,\n-\t\t\t\t\t\t\t\t       MAP_SHARED,\n-\t\t\t\t\t\t\t\t       fb.planes()[0].fd.fd(), 0));\n-\t\t\tmem[0] = ctrl[V4L2_CID_EXPOSURE];\n-\t\t\tmem[1] = ctrl[V4L2_CID_ANALOGUE_GAIN];\n-\t\t\tmunmap(mem, fb.planes()[0].length);\n+\t\t\tunsigned int bufferId = unicam_[Unicam::Embedded].getBufferId(buffer);\n+\t\t\tauto it = mappedEmbeddedBuffers_.find(bufferId);\n+\t\t\tif (it != mappedEmbeddedBuffers_.end()) {\n+\t\t\t\tuint32_t *mem = reinterpret_cast<uint32_t *>(it->second.maps()[0].data());\n+\t\t\t\tmem[0] = ctrl[V4L2_CID_EXPOSURE];\n+\t\t\t\tmem[1] = ctrl[V4L2_CID_ANALOGUE_GAIN];\n+\t\t\t} else {\n+\t\t\t\tLOG(RPI, Warning) << \"Failed to find embedded buffer \"\n+\t\t\t\t\t\t  << bufferId;\n+\t\t\t}\n \t\t}\n \t}\n \n","prefixes":["libcamera-devel","v2","1/2"]}