[{"id":14067,"web_url":"https://patchwork.libcamera.org/comment/14067/","msgid":"<20201205012613.GP4109@pendragon.ideasonboard.com>","date":"2020-12-05T01:26:13","subject":"Re: [libcamera-devel] [PATCH v3 4/8] libcamera: raspberrypi: Remove\n\tStaggeredCtrl","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nThank you for the patch.\n\nOn Mon, Nov 23, 2020 at 11:12:30PM +0100, Niklas Söderlund wrote:\n> There are no users left, remove it.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  .../pipeline/raspberrypi/meson.build          |   1 -\n>  .../pipeline/raspberrypi/staggered_ctrl.cpp   | 174 ------------------\n>  .../pipeline/raspberrypi/staggered_ctrl.h     |  96 ----------\n>  3 files changed, 271 deletions(-)\n>  delete mode 100644 src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp\n>  delete mode 100644 src/libcamera/pipeline/raspberrypi/staggered_ctrl.h\n> \n> diff --git a/src/libcamera/pipeline/raspberrypi/meson.build b/src/libcamera/pipeline/raspberrypi/meson.build\n> index 7c5b6ff73741c968..f1a2f5ee72c2a0dd 100644\n> --- a/src/libcamera/pipeline/raspberrypi/meson.build\n> +++ b/src/libcamera/pipeline/raspberrypi/meson.build\n> @@ -4,5 +4,4 @@ libcamera_sources += files([\n>      'dma_heaps.cpp',\n>      'raspberrypi.cpp',\n>      'rpi_stream.cpp',\n> -    'staggered_ctrl.cpp',\n>  ])\n> diff --git a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp\n> deleted file mode 100644\n> index 62605c0fceee7d11..0000000000000000\n> --- a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp\n> +++ /dev/null\n> @@ -1,174 +0,0 @@\n> -/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> -/*\n> - * Copyright (C) 2020, Raspberry Pi (Trading) Ltd.\n> - *\n> - * staggered_ctrl.cpp - Helper for writing staggered ctrls to a V4L2 device.\n> - */\n> -\n> -#include \"staggered_ctrl.h\"\n> -\n> -#include <algorithm>\n> -\n> -#include <libcamera/controls.h>\n> -\n> -#include \"libcamera/internal/log.h\"\n> -#include \"libcamera/internal/utils.h\"\n> -#include \"libcamera/internal/v4l2_videodevice.h\"\n> -\n> -namespace libcamera {\n> -\n> -LOG_DEFINE_CATEGORY(RPI_S_W)\n> -\n> -namespace RPi {\n> -\n> -void StaggeredCtrl::init(V4L2VideoDevice *dev,\n> -\t  std::initializer_list<std::pair<const uint32_t, uint8_t>> delayList)\n> -{\n> -\tstd::lock_guard<std::mutex> lock(lock_);\n> -\n> -\tdev_ = dev;\n> -\tdelay_ = delayList;\n> -\tctrl_.clear();\n> -\n> -\t/* Find the largest delay across all controls. */\n> -\tmaxDelay_ = 0;\n> -\tfor (auto const &p : delay_) {\n> -\t\tLOG(RPI_S_W, Info) << \"Init ctrl \"\n> -\t\t\t\t   << utils::hex(p.first) << \" with delay \"\n> -\t\t\t\t   << static_cast<int>(p.second);\n> -\t\tmaxDelay_ = std::max(maxDelay_, p.second);\n> -\t}\n> -\n> -\tinit_ = true;\n> -}\n> -\n> -void StaggeredCtrl::reset()\n> -{\n> -\tstd::lock_guard<std::mutex> lock(lock_);\n> -\n> -\tint lastSetCount = setCount_;\n> -\tstd::unordered_map<uint32_t, int32_t> lastVal;\n> -\n> -\t/* Reset the counters. */\n> -\tsetCount_ = getCount_ = 0;\n> -\n> -\t/* Look for the last set values. */\n> -\tfor (auto const &c : ctrl_)\n> -\t\tlastVal[c.first] = c.second[lastSetCount].value;\n> -\n> -\t/* Apply the last set values as the next to be applied. */\n> -\tctrl_.clear();\n> -\tfor (auto &c : lastVal)\n> -\t\tctrl_[c.first][setCount_] = CtrlInfo(c.second);\n> -}\n> -\n> -bool StaggeredCtrl::set(uint32_t ctrl, int32_t value)\n> -{\n> -\tstd::lock_guard<std::mutex> lock(lock_);\n> -\n> -\t/* Can we find this ctrl as one that is registered? */\n> -\tif (delay_.find(ctrl) == delay_.end())\n> -\t\treturn false;\n> -\n> -\tctrl_[ctrl][setCount_].value = value;\n> -\tctrl_[ctrl][setCount_].updated = true;\n> -\n> -\treturn true;\n> -}\n> -\n> -bool StaggeredCtrl::set(std::initializer_list<std::pair<const uint32_t, int32_t>> ctrlList)\n> -{\n> -\tstd::lock_guard<std::mutex> lock(lock_);\n> -\n> -\tfor (auto const &p : ctrlList) {\n> -\t\t/* Can we find this ctrl? */\n> -\t\tif (delay_.find(p.first) == delay_.end())\n> -\t\t\treturn false;\n> -\n> -\t\tctrl_[p.first][setCount_] = CtrlInfo(p.second);\n> -\t}\n> -\n> -\treturn true;\n> -}\n> -\n> -bool StaggeredCtrl::set(const ControlList &controls)\n> -{\n> -\tstd::lock_guard<std::mutex> lock(lock_);\n> -\n> -\tfor (auto const &p : controls) {\n> -\t\t/* Can we find this ctrl? */\n> -\t\tif (delay_.find(p.first) == delay_.end())\n> -\t\t\treturn false;\n> -\n> -\t\tctrl_[p.first][setCount_] = CtrlInfo(p.second.get<int32_t>());\n> -\t\tLOG(RPI_S_W, Debug) << \"Setting ctrl \"\n> -\t\t\t\t    << utils::hex(p.first) << \" to \"\n> -\t\t\t\t    << ctrl_[p.first][setCount_].value\n> -\t\t\t\t    << \" at index \"\n> -\t\t\t\t    << setCount_;\n> -\t}\n> -\n> -\treturn true;\n> -}\n> -\n> -int StaggeredCtrl::write()\n> -{\n> -\tstd::lock_guard<std::mutex> lock(lock_);\n> -\tControlList controls(dev_->controls());\n> -\n> -\tfor (auto &p : ctrl_) {\n> -\t\tint delayDiff = maxDelay_ - delay_[p.first];\n> -\t\tint index = std::max<int>(0, setCount_ - delayDiff);\n> -\n> -\t\tif (p.second[index].updated) {\n> -\t\t\t/* We need to write this value out. */\n> -\t\t\tcontrols.set(p.first, p.second[index].value);\n> -\t\t\tp.second[index].updated = false;\n> -\t\t\tLOG(RPI_S_W, Debug) << \"Writing ctrl \"\n> -\t\t\t\t\t    << utils::hex(p.first) << \" to \"\n> -\t\t\t\t\t    << p.second[index].value\n> -\t\t\t\t\t    << \" at index \"\n> -\t\t\t\t\t    << index;\n> -\t\t}\n> -\t}\n> -\n> -\tnextFrame();\n> -\treturn dev_->setControls(&controls);\n> -}\n> -\n> -void StaggeredCtrl::get(std::unordered_map<uint32_t, int32_t> &ctrl, uint8_t offset)\n> -{\n> -\tstd::lock_guard<std::mutex> lock(lock_);\n> -\n> -\t/* Account for the offset to reset the getCounter. */\n> -\tgetCount_ += offset + 1;\n> -\n> -\tctrl.clear();\n> -\tfor (auto &p : ctrl_) {\n> -\t\tint index = std::max<int>(0, getCount_ - maxDelay_);\n> -\t\tctrl[p.first] = p.second[index].value;\n> -\t\tLOG(RPI_S_W, Debug) << \"Getting ctrl \"\n> -\t\t\t\t    << utils::hex(p.first) << \" to \"\n> -\t\t\t\t    << p.second[index].value\n> -\t\t\t\t    << \" at index \"\n> -\t\t\t\t    << index;\n> -\t}\n> -}\n> -\n> -void StaggeredCtrl::nextFrame()\n> -{\n> -\t/* Advance the control history to the next frame */\n> -\tint prevCount = setCount_;\n> -\tsetCount_++;\n> -\n> -\tLOG(RPI_S_W, Debug) << \"Next frame, set index is \" << setCount_;\n> -\n> -\tfor (auto &p : ctrl_) {\n> -\t\tp.second[setCount_].value = p.second[prevCount].value;\n> -\t\tp.second[setCount_].updated = false;\n> -\t}\n> -}\n> -\n> -} /* namespace RPi */\n> -\n> -} /* namespace libcamera */\n> diff --git a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h\n> deleted file mode 100644\n> index 382fa31a685357f2..0000000000000000\n> --- a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h\n> +++ /dev/null\n> @@ -1,96 +0,0 @@\n> -/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> -/*\n> - * Copyright (C) 2020, Raspberry Pi (Trading) Ltd.\n> - *\n> - * staggered_ctrl.h - Helper for writing staggered ctrls to a V4L2 device.\n> - */\n> -#ifndef __LIBCAMERA_PIPELINE_RASPBERRYPI_STAGGERED_CTRL_H__\n> -#define __LIBCAMERA_PIPELINE_RASPBERRYPI_STAGGERED_CTRL_H__\n> -\n> -#include <array>\n> -#include <initializer_list>\n> -#include <mutex>\n> -#include <unordered_map>\n> -#include <utility>\n> -\n> -namespace libcamera {\n> -\n> -class ControlList;\n> -class V4L2VideoDevice;\n> -\n> -namespace RPi {\n> -\n> -class StaggeredCtrl\n> -{\n> -public:\n> -\tStaggeredCtrl()\n> -\t\t: init_(false), setCount_(0), getCount_(0), maxDelay_(0)\n> -\t{\n> -\t}\n> -\n> -\toperator bool() const\n> -\t{\n> -\t\treturn init_;\n> -\t}\n> -\n> -\tvoid init(V4L2VideoDevice *dev,\n> -\t\t  std::initializer_list<std::pair<const uint32_t, uint8_t>> delayList);\n> -\tvoid reset();\n> -\n> -\tvoid get(std::unordered_map<uint32_t, int32_t> &ctrl, uint8_t offset = 0);\n> -\n> -\tbool set(uint32_t ctrl, int32_t value);\n> -\tbool set(std::initializer_list<std::pair<const uint32_t, int32_t>> ctrlList);\n> -\tbool set(const ControlList &controls);\n> -\n> -\tint write();\n> -\n> -private:\n> -\tvoid nextFrame();\n> -\n> -\t/* listSize must be a power of 2. */\n> -\tstatic constexpr int listSize = (1 << 4);\n> -\tstruct CtrlInfo {\n> -\t\tCtrlInfo()\n> -\t\t\t: value(0), updated(false)\n> -\t\t{\n> -\t\t}\n> -\n> -\t\tCtrlInfo(int32_t value_)\n> -\t\t\t: value(value_), updated(true)\n> -\t\t{\n> -\t\t}\n> -\n> -\t\tint32_t value;\n> -\t\tbool updated;\n> -\t};\n> -\n> -\tclass CircularArray : public std::array<CtrlInfo, listSize>\n> -\t{\n> -\tpublic:\n> -\t\tCtrlInfo &operator[](int index)\n> -\t\t{\n> -\t\t\treturn std::array<CtrlInfo, listSize>::operator[](index & (listSize - 1));\n> -\t\t}\n> -\n> -\t\tconst CtrlInfo &operator[](int index) const\n> -\t\t{\n> -\t\t\treturn std::array<CtrlInfo, listSize>::operator[](index & (listSize - 1));\n> -\t\t}\n> -\t};\n> -\n> -\tbool init_;\n> -\tuint32_t setCount_;\n> -\tuint32_t getCount_;\n> -\tuint8_t maxDelay_;\n> -\tV4L2VideoDevice *dev_;\n> -\tstd::unordered_map<uint32_t, uint8_t> delay_;\n> -\tstd::unordered_map<uint32_t, CircularArray> ctrl_;\n> -\tstd::mutex lock_;\n> -};\n> -\n> -} /* namespace RPi */\n> -\n> -} /* namespace libcamera */\n> -\n> -#endif /* __LIBCAMERA_PIPELINE_RASPBERRYPI_STAGGERED_CTRL_H__ */","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 C73FEBE176\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat,  5 Dec 2020 01:26:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5CF9D635DE;\n\tSat,  5 Dec 2020 02:26:16 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1AB4260325\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  5 Dec 2020 02:26:15 +0100 (CET)","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 8D2C52A4;\n\tSat,  5 Dec 2020 02:26:14 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"I0dyAhWx\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1607131574;\n\tbh=XJg+iF9O8AsZUN5s1e3LURThvLJwi697/LPR8aY8oes=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=I0dyAhWxxgQ/vMgtWN+E3Pc/a5OwTyEHTBk36JuoY4vVzc3vfSZcFZeNiYPci9Rwu\n\tldElhFTg06VadrswOJCERRqM18IhX+1mtl2GRDcJVwGW+PrjzXO7exa56Ph2Y2RhFE\n\tlWL6mLoqdNxQ6QxE7fLVcGcPe3sZy/BaPFMfJh7Y=","Date":"Sat, 5 Dec 2020 03:26:13 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Message-ID":"<20201205012613.GP4109@pendragon.ideasonboard.com>","References":"<20201123221234.485933-1-niklas.soderlund@ragnatech.se>\n\t<20201123221234.485933-5-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20201123221234.485933-5-niklas.soderlund@ragnatech.se>","Subject":"Re: [libcamera-devel] [PATCH v3 4/8] libcamera: raspberrypi: Remove\n\tStaggeredCtrl","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","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>"}}]