From patchwork Tue May 12 00:39:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3779 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3D954603DD for ; Tue, 12 May 2020 02:39:14 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="mpPmmiqd"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BEBBD33E; Tue, 12 May 2020 02:39:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589243954; bh=iZfjMmp2fdlaVYmISIIQlfXXTrwk0I742mhfeKJjBvE=; h=From:To:Cc:Subject:Date:From; b=mpPmmiqdugXjAt1IMYDT5FIKIqlQ1d/5WmstYGS1q9dlN1T8PtFcJZFT/7EkfLZcp NGw+LYnfPCdx614t3C4+aNURLvGsWIL28eABLOhhMGUIv5bGJ9L1hw+kCQ4YZzDsWN TQPnTzrGVamzPFG8vyXrEUw9ZYpox43iPdpKc3hQ= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:39:02 +0300 Message-Id: <20200512003903.20986-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] libcamera: pipeline: raspberrypi: Don't inline all of 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: , X-List-Received-Date: Tue, 12 May 2020 00:39:14 -0000 The StaggeredCtrl class has large functions, move them to a .cpp file instead of inlining them all to reduce the binary size. Signed-off-by: Laurent Pinchart Reviewed-by: Naushir Patuck --- .../pipeline/raspberrypi/meson.build | 3 +- .../pipeline/raspberrypi/staggered_ctrl.cpp | 173 ++++++++++++++++++ .../pipeline/raspberrypi/staggered_ctrl.h | 168 ++--------------- 3 files changed, 186 insertions(+), 158 deletions(-) create mode 100644 src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp diff --git a/src/libcamera/pipeline/raspberrypi/meson.build b/src/libcamera/pipeline/raspberrypi/meson.build index 737857977831..565a8902f1f4 100644 --- a/src/libcamera/pipeline/raspberrypi/meson.build +++ b/src/libcamera/pipeline/raspberrypi/meson.build @@ -1,3 +1,4 @@ libcamera_sources += files([ - 'raspberrypi.cpp' + 'raspberrypi.cpp', + 'staggered_ctrl.cpp', ]) diff --git a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp new file mode 100644 index 000000000000..fbd87d3e791e --- /dev/null +++ b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp @@ -0,0 +1,173 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * 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 "log.h" +#include "utils.h" + +/* For logging... */ +using libcamera::LogCategory; +using libcamera::LogDebug; +using libcamera::LogInfo; +using libcamera::utils::hex; + +LOG_DEFINE_CATEGORY(RPI_S_W); + +namespace RPi { + +void StaggeredCtrl::init(libcamera::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 " + << 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 = std::max(0, setCount_ - 1); + 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(libcamera::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 " + << hex(p.first) << " to " + << ctrl_[p.first][setCount_].value + << " at index " + << setCount_; + } + + return true; +} + +int StaggeredCtrl::write() +{ + std::lock_guard lock(lock_); + libcamera::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 " + << 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 " + << 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 */ diff --git a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h index 0403c087c686..c8f000a0b43c 100644 --- a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h +++ b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h @@ -6,24 +6,16 @@ */ #pragma once -#include +#include #include #include #include +#include #include -#include "log.h" -#include "utils.h" + #include "v4l2_videodevice.h" -/* For logging... */ -using libcamera::LogCategory; -using libcamera::LogDebug; -using libcamera::LogInfo; -using libcamera::utils::hex; - -LOG_DEFINE_CATEGORY(RPI_S_W); - namespace RPi { class StaggeredCtrl @@ -34,163 +26,25 @@ public: { } - ~StaggeredCtrl() - { - } - operator bool() const { return init_; } void init(libcamera::V4L2VideoDevice *dev, - std::initializer_list> delayList) - { - std::lock_guard lock(lock_); + std::initializer_list> delayList); + void reset(); - dev_ = dev; - delay_ = delayList; - ctrl_.clear(); + void get(std::unordered_map &ctrl, uint8_t offset = 0); - /* Find the largest delay across all controls. */ - maxDelay_ = 0; - for (auto const &p : delay_) { - LOG(RPI_S_W, Info) << "Init ctrl " - << hex(p.first) << " with delay " - << static_cast(p.second); - maxDelay_ = std::max(maxDelay_, p.second); - } + bool set(uint32_t ctrl, int32_t value); + bool set(std::initializer_list> ctrlList); + bool set(libcamera::ControlList &controls); - init_ = true; - } - - void reset() - { - std::lock_guard lock(lock_); - - int lastSetCount = std::max(0, setCount_ - 1); - 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 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 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 set(libcamera::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 " - << hex(p.first) << " to " - << ctrl_[p.first][setCount_].value - << " at index " - << setCount_; - } - - return true; - } - - int write() - { - std::lock_guard lock(lock_); - libcamera::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 " - << hex(p.first) << " to " - << p.second[index].value - << " at index " - << index; - } - } - - nextFrame(); - return dev_->setControls(&controls); - } - - void get(std::unordered_map &ctrl, uint8_t offset = 0) - { - 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 " - << hex(p.first) << " to " - << p.second[index].value - << " at index " - << index; - } - } + int write(); private: - void 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; - } - } + void nextFrame(); /* listSize must be a power of 2. */ static constexpr int listSize = (1 << 4); From patchwork Tue May 12 00:39:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3780 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 99AD5603DD for ; Tue, 12 May 2020 02:39:14 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="i3xZh06s"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2BB569CE; Tue, 12 May 2020 02:39:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589243954; bh=qHydbR6vh+V31zMOnQOvI6N015ShvrVHkSXpKbS38Jw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i3xZh06sSKMCFr1WgOJQOS6/7pj+s1ssaDwb+hG1ClQw+yyqMMItjvw1VVaOy0lD7 sIRWaqUDx63RGV0jgI+bkec8giIJAzoBVkFZWPvguiIHYo29deUFeZGkQlpzwNq6N+ xQE6ERdKxvzFolEhIc6eJ36L+USEaju2NckrF1ZM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:39:03 +0300 Message-Id: <20200512003903.20986-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200512003903.20986-1-laurent.pinchart@ideasonboard.com> References: <20200512003903.20986-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] libcamera: pipeline: raspberrypi: Move StaggeredCtrl to libcamera namespace 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: , X-List-Received-Date: Tue, 12 May 2020 00:39:14 -0000 The StaggeredCtrl class, part of the Raspberry Pi pipeline handler, is part of libcamera. Move it to the libcamera namespace to simplify usage of libcamera APIs. Signed-off-by: Laurent Pinchart Reviewed-by: Naushir Patuck --- .../pipeline/raspberrypi/raspberrypi.cpp | 2 +- .../pipeline/raspberrypi/staggered_ctrl.cpp | 25 ++++++++++--------- .../pipeline/raspberrypi/staggered_ctrl.h | 13 ++++++---- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 21a1d7f7cca3..41d1a522fa71 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -330,7 +330,7 @@ public: std::vector ipaBuffers_; /* VCSM allocation helper. */ - RPi::Vcsm vcsm_; + ::RPi::Vcsm vcsm_; void *lsTable_; RPi::StaggeredCtrl staggeredCtrl_; diff --git a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp index fbd87d3e791e..d431887ea137 100644 --- a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp +++ b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp @@ -9,20 +9,19 @@ #include +#include + #include "log.h" #include "utils.h" +#include "v4l2_videodevice.h" -/* For logging... */ -using libcamera::LogCategory; -using libcamera::LogDebug; -using libcamera::LogInfo; -using libcamera::utils::hex; +namespace libcamera { LOG_DEFINE_CATEGORY(RPI_S_W); namespace RPi { -void StaggeredCtrl::init(libcamera::V4L2VideoDevice *dev, +void StaggeredCtrl::init(V4L2VideoDevice *dev, std::initializer_list> delayList) { std::lock_guard lock(lock_); @@ -35,7 +34,7 @@ void StaggeredCtrl::init(libcamera::V4L2VideoDevice *dev, maxDelay_ = 0; for (auto const &p : delay_) { LOG(RPI_S_W, Info) << "Init ctrl " - << hex(p.first) << " with delay " + << utils::hex(p.first) << " with delay " << static_cast(p.second); maxDelay_ = std::max(maxDelay_, p.second); } @@ -92,7 +91,7 @@ bool StaggeredCtrl::set(std::initializer_list return true; } -bool StaggeredCtrl::set(libcamera::ControlList &controls) +bool StaggeredCtrl::set(ControlList &controls) { std::lock_guard lock(lock_); @@ -103,7 +102,7 @@ bool StaggeredCtrl::set(libcamera::ControlList &controls) ctrl_[p.first][setCount_] = CtrlInfo(p.second.get()); LOG(RPI_S_W, Debug) << "Setting ctrl " - << hex(p.first) << " to " + << utils::hex(p.first) << " to " << ctrl_[p.first][setCount_].value << " at index " << setCount_; @@ -115,7 +114,7 @@ bool StaggeredCtrl::set(libcamera::ControlList &controls) int StaggeredCtrl::write() { std::lock_guard lock(lock_); - libcamera::ControlList controls(dev_->controls()); + ControlList controls(dev_->controls()); for (auto &p : ctrl_) { int delayDiff = maxDelay_ - delay_[p.first]; @@ -126,7 +125,7 @@ int StaggeredCtrl::write() controls.set(p.first, p.second[index].value); p.second[index].updated = false; LOG(RPI_S_W, Debug) << "Writing ctrl " - << hex(p.first) << " to " + << utils::hex(p.first) << " to " << p.second[index].value << " at index " << index; @@ -149,7 +148,7 @@ void StaggeredCtrl::get(std::unordered_map &ctrl, uint8_t off int index = std::max(0, getCount_ - maxDelay_); ctrl[p.first] = p.second[index].value; LOG(RPI_S_W, Debug) << "Getting ctrl " - << hex(p.first) << " to " + << utils::hex(p.first) << " to " << p.second[index].value << " at index " << index; @@ -171,3 +170,5 @@ void StaggeredCtrl::nextFrame() } } /* namespace RPi */ + +} /* namespace libcamera */ diff --git a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h index c8f000a0b43c..eef16eaac235 100644 --- a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h +++ b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h @@ -12,9 +12,10 @@ #include #include -#include +namespace libcamera { -#include "v4l2_videodevice.h" +class ControlList; +class V4L2VideoDevice; namespace RPi { @@ -31,7 +32,7 @@ public: return init_; } - void init(libcamera::V4L2VideoDevice *dev, + void init(V4L2VideoDevice *dev, std::initializer_list> delayList); void reset(); @@ -39,7 +40,7 @@ public: bool set(uint32_t ctrl, int32_t value); bool set(std::initializer_list> ctrlList); - bool set(libcamera::ControlList &controls); + bool set(ControlList &controls); int write(); @@ -81,10 +82,12 @@ private: uint32_t setCount_; uint32_t getCount_; uint8_t maxDelay_; - libcamera::V4L2VideoDevice *dev_; + V4L2VideoDevice *dev_; std::unordered_map delay_; std::unordered_map ctrl_; std::mutex lock_; }; } /* namespace RPi */ + +} /* namespace libcamera */