{"id":13178,"url":"https://patchwork.libcamera.org/api/1.1/patches/13178/?format=json","web_url":"https://patchwork.libcamera.org/patch/13178/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210803133205.6599-2-umang.jain@ideasonboard.com>","date":"2021-08-03T13:32:02","name":"[libcamera-devel,1/4] libcamera: camera_sensor: Transform CameraSensor::sizes()","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"4405da1e3660f112ae512acf222dfb542032f2e8","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/1.1/people/86/?format=json","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"delegate":{"id":12,"url":"https://patchwork.libcamera.org/api/1.1/users/12/?format=json","username":"uajain","first_name":"Umang","last_name":"Jain","email":"umang.jain@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/13178/mbox/","series":[{"id":2296,"url":"https://patchwork.libcamera.org/api/1.1/series/2296/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2296","date":"2021-08-03T13:32:01","name":"ipu3: Change sensor size selection policy","version":1,"mbox":"https://patchwork.libcamera.org/series/2296/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13178/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13178/checks/","tags":{},"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 C85ADC3235\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  3 Aug 2021 13:32:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 82BAE687CE;\n\tTue,  3 Aug 2021 15:32:27 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EB50E6026A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  3 Aug 2021 15:32:25 +0200 (CEST)","from perceval.ideasonboard.com (unknown [103.238.109.12])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D85DC3F0;\n\tTue,  3 Aug 2021 15:32:24 +0200 (CEST)"],"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=\"VTpiDiw4\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1627997545;\n\tbh=awfRVeK4EkuD9Hy2AouVGj9dsPxvxRCmHcnme0lmKRg=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=VTpiDiw49U+HT45GaiXpB8C121aCymzff60e86zo08QXGJMJM5TOQnb/5S0/M8LHg\n\titolYXeqohayGUDn/k1+3PBEABbxp9GPpExayVbv+Z7xlJwSpJhTPZFi44J/WmMy7x\n\tEGrW1LEa/3poSWfSb6Xx/s3UF9W1FgZhCcIjr2GU=","From":"Umang Jain <umang.jain@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  3 Aug 2021 19:02:02 +0530","Message-Id":"<20210803133205.6599-2-umang.jain@ideasonboard.com>","X-Mailer":"git-send-email 2.31.1","In-Reply-To":"<20210803133205.6599-1-umang.jain@ideasonboard.com>","References":"<20210803133205.6599-1-umang.jain@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 1/4] libcamera: camera_sensor: Transform\n\tCameraSensor::sizes()","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"In CameraSensor, the mbusCodes() and sizes() accessor functions\nretrieves all the supported media bus codes and the supported sizes\nrespectively. However, this is quite limiting since the caller\nprobably isn't in a position to match which range of sizes are\nsupported for a particular mbusCode.\n\nHence, the caller is most likely interested to know about the sizes\nsupported for a particular media bus code. This patch transforms the\nexisting CameraSensor::sizes() to CameraSensor::sizes(mbuscode) to\nachieve that goal.\n\nTo know all the frame sizes of the CameraSensor as required in IPU3\ncase Cio2Device::sizes(), one would now require to enumerate all the\nmedia bus codes (can be retrieved by CameraSensor::mbusCodes()) with\nCameraSensor::size(mbusCode). The result can be inserted in a\nstd::set<> to avoid duplicates.\n\nSigned-off-by: Umang Jain <umang.jain@ideasonboard.com>\n---\n include/libcamera/internal/camera_sensor.h |  2 +-\n src/libcamera/camera_sensor.cpp            | 36 ++++++++++++++++------\n src/libcamera/pipeline/ipu3/cio2.cpp       | 10 +++---\n test/camera-sensor.cpp                     |  2 +-\n 4 files changed, 34 insertions(+), 16 deletions(-)","diff":"diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h\nindex db12b07e..d25a1165 100644\n--- a/include/libcamera/internal/camera_sensor.h\n+++ b/include/libcamera/internal/camera_sensor.h\n@@ -38,7 +38,7 @@ public:\n \tconst std::string &id() const { return id_; }\n \tconst MediaEntity *entity() const { return entity_; }\n \tconst std::vector<unsigned int> &mbusCodes() const { return mbusCodes_; }\n-\tconst std::vector<Size> &sizes() const { return sizes_; }\n+\tconst std::vector<Size> sizes(unsigned int mbusCode) const;\n \tSize resolution() const;\n \tconst std::vector<int32_t> &testPatternModes() const\n \t{\ndiff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex cde431cc..3c3ceff3 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -471,16 +471,6 @@ int CameraSensor::initProperties()\n  * \\return The supported media bus codes sorted in increasing order\n  */\n \n-/**\n- * \\fn CameraSensor::sizes()\n- * \\brief Retrieve the frame sizes supported by the camera sensor\n- *\n- * The reported sizes span all media bus codes supported by the camera sensor.\n- * Not all sizes may be supported by all media bus codes.\n- *\n- * \\return The supported frame sizes sorted in increasing order\n- */\n-\n /**\n  * \\brief Retrieve the camera sensor resolution\n  *\n@@ -594,6 +584,32 @@ V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector<unsigned int> &mbu\n \treturn format;\n }\n \n+/**\n+ * \\brief Retrieve the supported frame sizes for a media bus code\n+ * \\param[in] mbusCode The media bus code for which sizes are requested\n+ *\n+ * The reported sizes for a particular \\a mbusCode are supported by the camera\n+ * sensor.\n+ *\n+ * \\return The supported frame sizes for \\a mbusCode sorted in increasing order\n+ */\n+const std::vector<Size> CameraSensor::sizes(unsigned int mbusCode) const\n+{\n+\tstd::vector<Size> sizes;\n+\n+\tconst auto format = formats_.find(mbusCode);\n+\tif (format == formats_.end())\n+\t\treturn sizes;\n+\n+\tconst std::vector<SizeRange> &ranges = format->second;\n+\tstd::transform(ranges.begin(), ranges.end(), std::back_inserter(sizes),\n+\t\t       [](const SizeRange &range) { return range.max; });\n+\n+\tstd::sort(sizes.begin(), sizes.end());\n+\n+\treturn sizes;\n+}\n+\n /**\n  * \\brief Set the sensor output format\n  * \\param[in] format The desired sensor output format\ndiff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp\nindex 1bcd580e..6f2ef321 100644\n--- a/src/libcamera/pipeline/ipu3/cio2.cpp\n+++ b/src/libcamera/pipeline/ipu3/cio2.cpp\n@@ -69,11 +69,13 @@ std::vector<SizeRange> CIO2Device::sizes() const\n \tif (!sensor_)\n \t\treturn {};\n \n-\tstd::vector<SizeRange> sizes;\n-\tfor (const Size &size : sensor_->sizes())\n-\t\tsizes.emplace_back(size, size);\n+\tstd::set<Size> allSizes;\n+\tfor (unsigned int code : sensor_->mbusCodes()) {\n+\t\tfor (Size sz : sensor_->sizes(code))\n+\t\t\tallSizes.insert(sz);\n+\t}\n \n-\treturn sizes;\n+\treturn std::vector<SizeRange>(allSizes.begin(), allSizes.end());\n }\n \n /**\ndiff --git a/test/camera-sensor.cpp b/test/camera-sensor.cpp\nindex a8dcad82..372ee4af 100644\n--- a/test/camera-sensor.cpp\n+++ b/test/camera-sensor.cpp\n@@ -76,7 +76,7 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tconst std::vector<Size> &sizes = sensor_->sizes();\n+\t\tconst std::vector<Size> &sizes = sensor_->sizes(*iter);\n \t\tauto iter2 = std::find(sizes.begin(), sizes.end(),\n \t\t\t\t       Size(4096, 2160));\n \t\tif (iter2 == sizes.end()) {\n","prefixes":["libcamera-devel","1/4"]}