From patchwork Tue Nov 10 00:27:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 10405 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id DBF99BDB89 for ; Tue, 10 Nov 2020 00:28:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B5C01630C4; Tue, 10 Nov 2020 01:28:01 +0100 (CET) Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 16AD9630CA for ; Tue, 10 Nov 2020 01:28:00 +0100 (CET) X-Halon-ID: c56f7b00-22ea-11eb-bcc0-005056917f90 Authorized-sender: niklas.soderlund@fsdn.se Received: from bismarck.berto.se (p4fca2458.dip0.t-ipconnect.de [79.202.36.88]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id c56f7b00-22ea-11eb-bcc0-005056917f90; Tue, 10 Nov 2020 01:22:09 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org, naush@raspberrypi.com Date: Tue, 10 Nov 2020 01:27:06 +0100 Message-Id: <20201110002710.3233696-5-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201110002710.3233696-1-niklas.soderlund@ragnatech.se> References: <20201110002710.3233696-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/8] libcamera: raspberrypi: Remove StaggeredCtrl X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" There are no users left, remove it. Signed-off-by: Niklas Söderlund --- .../pipeline/raspberrypi/meson.build | 1 - .../pipeline/raspberrypi/staggered_ctrl.cpp | 174 ------------------ .../pipeline/raspberrypi/staggered_ctrl.h | 96 ---------- 3 files changed, 271 deletions(-) delete mode 100644 src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp delete mode 100644 src/libcamera/pipeline/raspberrypi/staggered_ctrl.h diff --git a/src/libcamera/pipeline/raspberrypi/meson.build b/src/libcamera/pipeline/raspberrypi/meson.build index 7c5b6ff73741c968..f1a2f5ee72c2a0dd 100644 --- a/src/libcamera/pipeline/raspberrypi/meson.build +++ b/src/libcamera/pipeline/raspberrypi/meson.build @@ -4,5 +4,4 @@ libcamera_sources += files([ 'dma_heaps.cpp', 'raspberrypi.cpp', 'rpi_stream.cpp', - 'staggered_ctrl.cpp', ]) diff --git a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp deleted file mode 100644 index 62605c0fceee7d11..0000000000000000 --- a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2020, Raspberry Pi (Trading) Ltd. - * - * staggered_ctrl.cpp - Helper for writing staggered ctrls to a V4L2 device. - */ - -#include "staggered_ctrl.h" - -#include - -#include - -#include "libcamera/internal/log.h" -#include "libcamera/internal/utils.h" -#include "libcamera/internal/v4l2_videodevice.h" - -namespace libcamera { - -LOG_DEFINE_CATEGORY(RPI_S_W) - -namespace RPi { - -void StaggeredCtrl::init(V4L2VideoDevice *dev, - std::initializer_list> delayList) -{ - std::lock_guard lock(lock_); - - dev_ = dev; - delay_ = delayList; - ctrl_.clear(); - - /* Find the largest delay across all controls. */ - maxDelay_ = 0; - for (auto const &p : delay_) { - LOG(RPI_S_W, Info) << "Init ctrl " - << utils::hex(p.first) << " with delay " - << static_cast(p.second); - maxDelay_ = std::max(maxDelay_, p.second); - } - - init_ = true; -} - -void StaggeredCtrl::reset() -{ - std::lock_guard lock(lock_); - - int lastSetCount = setCount_; - std::unordered_map lastVal; - - /* Reset the counters. */ - setCount_ = getCount_ = 0; - - /* Look for the last set values. */ - for (auto const &c : ctrl_) - lastVal[c.first] = c.second[lastSetCount].value; - - /* Apply the last set values as the next to be applied. */ - ctrl_.clear(); - for (auto &c : lastVal) - ctrl_[c.first][setCount_] = CtrlInfo(c.second); -} - -bool StaggeredCtrl::set(uint32_t ctrl, int32_t value) -{ - std::lock_guard lock(lock_); - - /* Can we find this ctrl as one that is registered? */ - if (delay_.find(ctrl) == delay_.end()) - return false; - - ctrl_[ctrl][setCount_].value = value; - ctrl_[ctrl][setCount_].updated = true; - - return true; -} - -bool StaggeredCtrl::set(std::initializer_list> ctrlList) -{ - std::lock_guard lock(lock_); - - for (auto const &p : ctrlList) { - /* Can we find this ctrl? */ - if (delay_.find(p.first) == delay_.end()) - return false; - - ctrl_[p.first][setCount_] = CtrlInfo(p.second); - } - - return true; -} - -bool StaggeredCtrl::set(const ControlList &controls) -{ - std::lock_guard lock(lock_); - - for (auto const &p : controls) { - /* Can we find this ctrl? */ - if (delay_.find(p.first) == delay_.end()) - return false; - - ctrl_[p.first][setCount_] = CtrlInfo(p.second.get()); - LOG(RPI_S_W, Debug) << "Setting ctrl " - << utils::hex(p.first) << " to " - << ctrl_[p.first][setCount_].value - << " at index " - << setCount_; - } - - return true; -} - -int StaggeredCtrl::write() -{ - std::lock_guard lock(lock_); - ControlList controls(dev_->controls()); - - for (auto &p : ctrl_) { - int delayDiff = maxDelay_ - delay_[p.first]; - int index = std::max(0, setCount_ - delayDiff); - - if (p.second[index].updated) { - /* We need to write this value out. */ - controls.set(p.first, p.second[index].value); - p.second[index].updated = false; - LOG(RPI_S_W, Debug) << "Writing ctrl " - << utils::hex(p.first) << " to " - << p.second[index].value - << " at index " - << index; - } - } - - nextFrame(); - return dev_->setControls(&controls); -} - -void StaggeredCtrl::get(std::unordered_map &ctrl, uint8_t offset) -{ - std::lock_guard lock(lock_); - - /* Account for the offset to reset the getCounter. */ - getCount_ += offset + 1; - - ctrl.clear(); - for (auto &p : ctrl_) { - int index = std::max(0, getCount_ - maxDelay_); - ctrl[p.first] = p.second[index].value; - LOG(RPI_S_W, Debug) << "Getting ctrl " - << utils::hex(p.first) << " to " - << p.second[index].value - << " at index " - << index; - } -} - -void StaggeredCtrl::nextFrame() -{ - /* Advance the control history to the next frame */ - int prevCount = setCount_; - setCount_++; - - LOG(RPI_S_W, Debug) << "Next frame, set index is " << setCount_; - - for (auto &p : ctrl_) { - p.second[setCount_].value = p.second[prevCount].value; - p.second[setCount_].updated = false; - } -} - -} /* namespace RPi */ - -} /* namespace libcamera */ diff --git a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h deleted file mode 100644 index 382fa31a685357f2..0000000000000000 --- a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h +++ /dev/null @@ -1,96 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2020, Raspberry Pi (Trading) Ltd. - * - * staggered_ctrl.h - Helper for writing staggered ctrls to a V4L2 device. - */ -#ifndef __LIBCAMERA_PIPELINE_RASPBERRYPI_STAGGERED_CTRL_H__ -#define __LIBCAMERA_PIPELINE_RASPBERRYPI_STAGGERED_CTRL_H__ - -#include -#include -#include -#include -#include - -namespace libcamera { - -class ControlList; -class V4L2VideoDevice; - -namespace RPi { - -class StaggeredCtrl -{ -public: - StaggeredCtrl() - : init_(false), setCount_(0), getCount_(0), maxDelay_(0) - { - } - - operator bool() const - { - return init_; - } - - void init(V4L2VideoDevice *dev, - std::initializer_list> delayList); - void reset(); - - void get(std::unordered_map &ctrl, uint8_t offset = 0); - - bool set(uint32_t ctrl, int32_t value); - bool set(std::initializer_list> ctrlList); - bool set(const ControlList &controls); - - int write(); - -private: - void nextFrame(); - - /* listSize must be a power of 2. */ - static constexpr int listSize = (1 << 4); - struct CtrlInfo { - CtrlInfo() - : value(0), updated(false) - { - } - - CtrlInfo(int32_t value_) - : value(value_), updated(true) - { - } - - int32_t value; - bool updated; - }; - - class CircularArray : public std::array - { - public: - CtrlInfo &operator[](int index) - { - return std::array::operator[](index & (listSize - 1)); - } - - const CtrlInfo &operator[](int index) const - { - return std::array::operator[](index & (listSize - 1)); - } - }; - - bool init_; - uint32_t setCount_; - uint32_t getCount_; - uint8_t maxDelay_; - V4L2VideoDevice *dev_; - std::unordered_map delay_; - std::unordered_map ctrl_; - std::mutex lock_; -}; - -} /* namespace RPi */ - -} /* namespace libcamera */ - -#endif /* __LIBCAMERA_PIPELINE_RASPBERRYPI_STAGGERED_CTRL_H__ */