[{"id":18794,"web_url":"https://patchwork.libcamera.org/comment/18794/","msgid":"<20210814053741.GC1513067@pyrite.rasen.tech>","date":"2021-08-14T05:37:41","subject":"Re: [libcamera-devel] [PATCH v3 3/4] ipa: vimc: Map and unmap\n\tbuffers","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Hi Umang,\n\nOn Sat, Aug 14, 2021 at 10:39:11AM +0530, Umang Jain wrote:\n> VIMC pipeline handler have dmabuf-backed mock FrameBuffers which are\n> specifically targetted mimicking IPA buffers (parameter and statistics).\n> Map these mock buffers to the VIMC IPA that would enable exercising IPA\n> IPC code paths. This will provide leverage to our test suite to test\n> IPA IPC code paths, which are common to various platforms.\n> \n> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  include/libcamera/ipa/vimc.mojom     |  3 +++\n>  src/ipa/vimc/vimc.cpp                | 27 +++++++++++++++++++++++++++\n>  src/libcamera/pipeline/vimc/vimc.cpp | 15 +++++++++++++++\n>  3 files changed, 45 insertions(+)\n> \n> diff --git a/include/libcamera/ipa/vimc.mojom b/include/libcamera/ipa/vimc.mojom\n> index ee66353d..8cb240d3 100644\n> --- a/include/libcamera/ipa/vimc.mojom\n> +++ b/include/libcamera/ipa/vimc.mojom\n> @@ -26,6 +26,9 @@ interface IPAVimcInterface {\n>  \n>  \tstart() => (int32 ret);\n>  \tstop();\n> +\n> +\tmapBuffers(array<libcamera.IPABuffer> buffers);\n> +\tunmapBuffers(array<uint32> ids);\n>  };\n>  \n>  interface IPAVimcEventInterface {\n> diff --git a/src/ipa/vimc/vimc.cpp b/src/ipa/vimc/vimc.cpp\n> index fb134084..7d9d22d0 100644\n> --- a/src/ipa/vimc/vimc.cpp\n> +++ b/src/ipa/vimc/vimc.cpp\n> @@ -19,6 +19,8 @@\n>  #include <libcamera/ipa/ipa_interface.h>\n>  #include <libcamera/ipa/ipa_module_info.h>\n>  \n> +#include \"libcamera/internal/mapped_framebuffer.h\"\n> +\n>  namespace libcamera {\n>  \n>  LOG_DEFINE_CATEGORY(IPAVimc)\n> @@ -38,11 +40,15 @@ public:\n>  \t\t      const std::map<unsigned int, IPAStream> &streamConfig,\n>  \t\t      const std::map<unsigned int, ControlInfoMap> &entityControls) override;\n>  \n> +\tvoid mapBuffers(const std::vector<IPABuffer> &buffers) override;\n> +\tvoid unmapBuffers(const std::vector<unsigned int> &ids) override;\n> +\n>  private:\n>  \tvoid initTrace();\n>  \tvoid trace(enum ipa::vimc::IPAOperationCode operation);\n>  \n>  \tint fd_;\n> +\tstd::map<unsigned int, MappedFrameBuffer> buffers_;\n>  };\n>  \n>  IPAVimc::IPAVimc()\n> @@ -99,6 +105,27 @@ int IPAVimc::configure([[maybe_unused]] const IPACameraSensorInfo &sensorInfo,\n>  \treturn 0;\n>  }\n>  \n> +void IPAVimc::mapBuffers(const std::vector<IPABuffer> &buffers)\n> +{\n> +\tfor (const IPABuffer &buffer : buffers) {\n> +\t\tconst FrameBuffer fb(buffer.planes);\n> +\t\tbuffers_.emplace(std::piecewise_construct,\n> +\t\t\t\t std::forward_as_tuple(buffer.id),\n> +\t\t\t\t std::forward_as_tuple(&fb, MappedFrameBuffer::MapFlag::Read));\n> +\t}\n> +}\n> +\n> +void IPAVimc::unmapBuffers(const std::vector<unsigned int> &ids)\n> +{\n> +\tfor (unsigned int id : ids) {\n> +\t\tauto it = buffers_.find(id);\n> +\t\tif (it == buffers_.end())\n> +\t\t\tcontinue;\n> +\n> +\t\tbuffers_.erase(it);\n> +\t}\n> +}\n> +\n>  void IPAVimc::initTrace()\n>  {\n>  \tstruct stat fifoStat;\n> diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp\n> index 2dfa1418..b08325c2 100644\n> --- a/src/libcamera/pipeline/vimc/vimc.cpp\n> +++ b/src/libcamera/pipeline/vimc/vimc.cpp\n> @@ -334,6 +334,15 @@ int PipelineHandlerVimc::start(Camera *camera, [[maybe_unused]] const ControlLis\n>  \tif (ret < 0)\n>  \t\treturn ret;\n>  \n> +\t/* Map the mock IPA buffers to VIMC IPA to exercise IPC code paths */\n> +\tunsigned int ipaBufferId = 1;\n> +\tstd::vector<IPABuffer> ipaBuffers;\n> +\tfor (auto [i, buffer] : utils::enumerate(data->mockIPABufs_)) {\n> +\t\tbuffer->setCookie(ipaBufferId++);\n> +\t\tipaBuffers.emplace_back(buffer->cookie(), buffer->planes());\n> +\t}\n> +\tdata->ipa_->mapBuffers(ipaBuffers);\n> +\n>  \tret = data->ipa_->start();\n>  \tif (ret) {\n>  \t\tdata->video_->releaseBuffers();\n> @@ -354,7 +363,13 @@ void PipelineHandlerVimc::stop(Camera *camera)\n>  {\n>  \tVimcCameraData *data = cameraData(camera);\n>  \tdata->video_->streamOff();\n> +\n> +\tstd::vector<unsigned int> ids;\n> +\tfor (const std::unique_ptr<FrameBuffer> &buffer : data->mockIPABufs_)\n> +\t\tids.push_back(buffer->cookie());\n> +\tdata->ipa_->unmapBuffers(ids);\n>  \tdata->ipa_->stop();\n> +\n>  \tdata->video_->releaseBuffers();\n>  }\n>  \n> -- \n> 2.31.1\n>","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 61FFBBD87D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 14 Aug 2021 05:37:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1B0B268890;\n\tSat, 14 Aug 2021 07:37:50 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0592C6888D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 14 Aug 2021 07:37:49 +0200 (CEST)","from pyrite.rasen.tech (unknown\n\t[IPv6:2400:4051:61:600:2c71:1b79:d06d:5032])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9753F3E5;\n\tSat, 14 Aug 2021 07:37:47 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"A+aLe/PE\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1628919468;\n\tbh=lWCH5AdArGYzH/iriXv25RbIgEWlnBYlvbOS2PZrEAU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=A+aLe/PEqCGMewBm30yE/tNn1n0nSyw7kxYuw6cOxos3X5IoIMS0+Mu5j468OLOFT\n\tK58tZffsn0YAg5VO+rABKI3YYuCJAlDkXOtez3umlnKnOb9rFp5WedLfqaG/Ajdytd\n\tdjB9zQv+7eiFtx0umL4us9Nkxeivpb8jxapbUITM=","Date":"Sat, 14 Aug 2021 14:37:41 +0900","From":"paul.elder@ideasonboard.com","To":"Umang Jain <umang.jain@ideasonboard.com>","Message-ID":"<20210814053741.GC1513067@pyrite.rasen.tech>","References":"<20210814050912.15113-1-umang.jain@ideasonboard.com>\n\t<20210814050912.15113-4-umang.jain@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20210814050912.15113-4-umang.jain@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v3 3/4] ipa: vimc: Map and unmap\n\tbuffers","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":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":18798,"web_url":"https://patchwork.libcamera.org/comment/18798/","msgid":"<YRgW6szvnD6OJL2k@pendragon.ideasonboard.com>","date":"2021-08-14T19:18:02","subject":"Re: [libcamera-devel] [PATCH v3 3/4] ipa: vimc: Map and unmap\n\tbuffers","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Umang,\n\nThank you for the patch.\n\nOn Sat, Aug 14, 2021 at 10:39:11AM +0530, Umang Jain wrote:\n> VIMC pipeline handler have dmabuf-backed mock FrameBuffers which are\n\ns/have/has/\n\n> specifically targetted mimicking IPA buffers (parameter and statistics).\n> Map these mock buffers to the VIMC IPA that would enable exercising IPA\n> IPC code paths. This will provide leverage to our test suite to test\n> IPA IPC code paths, which are common to various platforms.\n> \n> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n> ---\n>  include/libcamera/ipa/vimc.mojom     |  3 +++\n>  src/ipa/vimc/vimc.cpp                | 27 +++++++++++++++++++++++++++\n>  src/libcamera/pipeline/vimc/vimc.cpp | 15 +++++++++++++++\n>  3 files changed, 45 insertions(+)\n> \n> diff --git a/include/libcamera/ipa/vimc.mojom b/include/libcamera/ipa/vimc.mojom\n> index ee66353d..8cb240d3 100644\n> --- a/include/libcamera/ipa/vimc.mojom\n> +++ b/include/libcamera/ipa/vimc.mojom\n> @@ -26,6 +26,9 @@ interface IPAVimcInterface {\n>  \n>  \tstart() => (int32 ret);\n>  \tstop();\n> +\n> +\tmapBuffers(array<libcamera.IPABuffer> buffers);\n> +\tunmapBuffers(array<uint32> ids);\n>  };\n>  \n>  interface IPAVimcEventInterface {\n> diff --git a/src/ipa/vimc/vimc.cpp b/src/ipa/vimc/vimc.cpp\n> index fb134084..7d9d22d0 100644\n> --- a/src/ipa/vimc/vimc.cpp\n> +++ b/src/ipa/vimc/vimc.cpp\n> @@ -19,6 +19,8 @@\n>  #include <libcamera/ipa/ipa_interface.h>\n>  #include <libcamera/ipa/ipa_module_info.h>\n>  \n> +#include \"libcamera/internal/mapped_framebuffer.h\"\n> +\n>  namespace libcamera {\n>  \n>  LOG_DEFINE_CATEGORY(IPAVimc)\n> @@ -38,11 +40,15 @@ public:\n>  \t\t      const std::map<unsigned int, IPAStream> &streamConfig,\n>  \t\t      const std::map<unsigned int, ControlInfoMap> &entityControls) override;\n>  \n> +\tvoid mapBuffers(const std::vector<IPABuffer> &buffers) override;\n> +\tvoid unmapBuffers(const std::vector<unsigned int> &ids) override;\n> +\n>  private:\n>  \tvoid initTrace();\n>  \tvoid trace(enum ipa::vimc::IPAOperationCode operation);\n>  \n>  \tint fd_;\n> +\tstd::map<unsigned int, MappedFrameBuffer> buffers_;\n>  };\n>  \n>  IPAVimc::IPAVimc()\n> @@ -99,6 +105,27 @@ int IPAVimc::configure([[maybe_unused]] const IPACameraSensorInfo &sensorInfo,\n>  \treturn 0;\n>  }\n>  \n> +void IPAVimc::mapBuffers(const std::vector<IPABuffer> &buffers)\n> +{\n> +\tfor (const IPABuffer &buffer : buffers) {\n> +\t\tconst FrameBuffer fb(buffer.planes);\n> +\t\tbuffers_.emplace(std::piecewise_construct,\n> +\t\t\t\t std::forward_as_tuple(buffer.id),\n> +\t\t\t\t std::forward_as_tuple(&fb, MappedFrameBuffer::MapFlag::Read));\n> +\t}\n> +}\n> +\n> +void IPAVimc::unmapBuffers(const std::vector<unsigned int> &ids)\n> +{\n> +\tfor (unsigned int id : ids) {\n> +\t\tauto it = buffers_.find(id);\n> +\t\tif (it == buffers_.end())\n> +\t\t\tcontinue;\n> +\n> +\t\tbuffers_.erase(it);\n> +\t}\n> +}\n> +\n>  void IPAVimc::initTrace()\n>  {\n>  \tstruct stat fifoStat;\n> diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp\n> index 2dfa1418..b08325c2 100644\n> --- a/src/libcamera/pipeline/vimc/vimc.cpp\n> +++ b/src/libcamera/pipeline/vimc/vimc.cpp\n> @@ -334,6 +334,15 @@ int PipelineHandlerVimc::start(Camera *camera, [[maybe_unused]] const ControlLis\n>  \tif (ret < 0)\n>  \t\treturn ret;\n>  \n> +\t/* Map the mock IPA buffers to VIMC IPA to exercise IPC code paths */\n\ns/paths/paths./\n\n> +\tunsigned int ipaBufferId = 1;\n> +\tstd::vector<IPABuffer> ipaBuffers;\n> +\tfor (auto [i, buffer] : utils::enumerate(data->mockIPABufs_)) {\n> +\t\tbuffer->setCookie(ipaBufferId++);\n\nYou can use\n\n\t\tbuffer->setCookie(i + 1);\n\nand drop the ipaBufferId variable.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\t\tipaBuffers.emplace_back(buffer->cookie(), buffer->planes());\n> +\t}\n> +\tdata->ipa_->mapBuffers(ipaBuffers);\n> +\n>  \tret = data->ipa_->start();\n>  \tif (ret) {\n>  \t\tdata->video_->releaseBuffers();\n> @@ -354,7 +363,13 @@ void PipelineHandlerVimc::stop(Camera *camera)\n>  {\n>  \tVimcCameraData *data = cameraData(camera);\n>  \tdata->video_->streamOff();\n> +\n> +\tstd::vector<unsigned int> ids;\n> +\tfor (const std::unique_ptr<FrameBuffer> &buffer : data->mockIPABufs_)\n> +\t\tids.push_back(buffer->cookie());\n> +\tdata->ipa_->unmapBuffers(ids);\n>  \tdata->ipa_->stop();\n> +\n>  \tdata->video_->releaseBuffers();\n>  }\n>","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 DBD5EBD87D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 14 Aug 2021 19:18:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 61F3368891;\n\tSat, 14 Aug 2021 21:18:08 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C587360261\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 14 Aug 2021 21:18:07 +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 456533F0;\n\tSat, 14 Aug 2021 21:18:07 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Gxy0JULp\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1628968687;\n\tbh=yWpTzqeQU2v3g2G504S0paOdtAVFGyA6OOPSmdXsv6U=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Gxy0JULp9Is9cUD+XVrrB56CbDRh7BFm3Ll3PAoS+iEdoZ+C3Y/DlTq2OUDMxAeLA\n\t7ULMG21W0267Le16cw0scfZ//e/YnzKyBGBcDpz4h54fe93ee+UmUf3LoMGDY88czw\n\tVSxp88l5xvv0OYKfLFE0PLjaGUFj7Mt3h4iQ3588=","Date":"Sat, 14 Aug 2021 22:18:02 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Umang Jain <umang.jain@ideasonboard.com>","Message-ID":"<YRgW6szvnD6OJL2k@pendragon.ideasonboard.com>","References":"<20210814050912.15113-1-umang.jain@ideasonboard.com>\n\t<20210814050912.15113-4-umang.jain@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20210814050912.15113-4-umang.jain@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v3 3/4] ipa: vimc: Map and unmap\n\tbuffers","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":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]