From patchwork Tue Jun 23 02:09:21 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: 4128 Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9962E603BF for ; Tue, 23 Jun 2020 04:09:43 +0200 (CEST) X-Halon-ID: 99e4d2a0-b4f6-11ea-933e-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id 99e4d2a0-b4f6-11ea-933e-005056917a89; Tue, 23 Jun 2020 04:09:42 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 23 Jun 2020 04:09:21 +0200 Message-Id: <20200623020930.1781469-2-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623020930.1781469-1-niklas.soderlund@ragnatech.se> References: <20200623020930.1781469-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 01/10] libcamera: camera_sensor: Make mbusCodes() return a set 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, 23 Jun 2020 02:09:44 -0000 It makes little sens for a CameraSensor to support the same media bus format multiple times, change the container from a vector<> to a set<>. This was discovered while working with the IPU3 pipeline handler that Unnecessarily had to carry code to sort vectors in order to find intersections. As this change requires switching the container to set<> in that pipeline handler as well fix this while we are at it. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- include/libcamera/internal/camera_sensor.h | 4 ++-- include/libcamera/internal/formats.h | 2 +- src/libcamera/camera_sensor.cpp | 1 - src/libcamera/formats.cpp | 7 +++---- src/libcamera/pipeline/ipu3/ipu3.cpp | 13 +++++-------- test/camera-sensor.cpp | 2 +- 6 files changed, 12 insertions(+), 17 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 7f07413f95602881..6d92818f16e4b752 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -50,7 +50,7 @@ public: const std::string &model() const { return model_; } const MediaEntity *entity() const { return entity_; } - const std::vector &mbusCodes() const { return mbusCodes_; } + const std::set &mbusCodes() const { return mbusCodes_; } const std::vector &sizes() const { return sizes_; } const Size &resolution() const { return resolution_; } @@ -77,7 +77,7 @@ private: ImageFormats formats_; Size resolution_; - std::vector mbusCodes_; + std::set mbusCodes_; std::vector sizes_; ControlList properties_; diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h index 4b172efc6588d374..e8aa555dcbe99350 100644 --- a/include/libcamera/internal/formats.h +++ b/include/libcamera/internal/formats.h @@ -24,7 +24,7 @@ public: int addFormat(unsigned int format, const std::vector &sizes); bool isEmpty() const; - std::vector formats() const; + std::set formats() const; const std::vector &sizes(unsigned int format) const; const std::map> &data() const; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index b14b4051dca606b9..5ab50de660534f3f 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -251,7 +251,6 @@ int CameraSensor::init() } mbusCodes_ = formats_.formats(); - std::sort(mbusCodes_.begin(), mbusCodes_.end()); for (const auto &format : formats_.data()) { const std::vector &ranges = format.second; diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index 1272de29c802c539..6234fd98f3e2002c 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -68,14 +68,13 @@ bool ImageFormats::isEmpty() const * \brief Retrieve a list of all supported image formats * \return List of pixel formats or media bus codes */ -std::vector ImageFormats::formats() const +std::set ImageFormats::formats() const { - std::vector formats; - formats.reserve(data_.size()); + std::set formats; /* \todo: Should this be cached instead of computed each time? */ for (auto const &it : data_) - formats.push_back(it.first); + formats.insert(it.first); return formats; } diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 5544288b14f739c0..1a59de0c58975b3c 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -1441,15 +1441,12 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index) /* * Make sure the sensor produces at least one format compatible with * the CIO2 requirements. - * - * utils::set_overlap requires the ranges to be sorted, keep the - * cio2Codes vector sorted in ascending order. */ - const std::vector cio2Codes{ MEDIA_BUS_FMT_SBGGR10_1X10, - MEDIA_BUS_FMT_SGRBG10_1X10, - MEDIA_BUS_FMT_SGBRG10_1X10, - MEDIA_BUS_FMT_SRGGB10_1X10 }; - const std::vector &sensorCodes = sensor_->mbusCodes(); + const std::set cio2Codes{ MEDIA_BUS_FMT_SBGGR10_1X10, + MEDIA_BUS_FMT_SGRBG10_1X10, + MEDIA_BUS_FMT_SGBRG10_1X10, + MEDIA_BUS_FMT_SRGGB10_1X10 }; + const std::set &sensorCodes = sensor_->mbusCodes(); if (!utils::set_overlap(sensorCodes.begin(), sensorCodes.end(), cio2Codes.begin(), cio2Codes.end())) { LOG(IPU3, Error) diff --git a/test/camera-sensor.cpp b/test/camera-sensor.cpp index 8c7fd1d2d4445db3..146b1b7d6c294fdb 100644 --- a/test/camera-sensor.cpp +++ b/test/camera-sensor.cpp @@ -67,7 +67,7 @@ protected: return TestFail; } - const std::vector &codes = sensor_->mbusCodes(); + const std::set &codes = sensor_->mbusCodes(); auto iter = std::find(codes.begin(), codes.end(), MEDIA_BUS_FMT_ARGB8888_1X32); if (iter == codes.end()) {