{"id":3357,"url":"https://patchwork.libcamera.org/api/1.1/patches/3357/?format=json","web_url":"https://patchwork.libcamera.org/patch/3357/","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":"<20200327113152.348570-3-jacopo@jmondi.org>","date":"2020-03-27T11:31:52","name":"[libcamera-devel,RFCv2,2/2] libcamera: camera_sensor: Add method to get sensor info","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"768077c509ae7c58ad81bc06cae3310cebf928c6","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3357/mbox/","series":[{"id":787,"url":"https://patchwork.libcamera.org/api/1.1/series/787/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=787","date":"2020-03-27T11:31:50","name":"Define CameraSensorInfo","version":1,"mbox":"https://patchwork.libcamera.org/series/787/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3357/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3357/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net\n\t[217.70.183.196])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A58CF6040E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 Mar 2020 12:29:00 +0100 (CET)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 64B80E0008\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 Mar 2020 11:29:00 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 27 Mar 2020 12:31:52 +0100","Message-Id":"<20200327113152.348570-3-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20200327113152.348570-1-jacopo@jmondi.org>","References":"<20200327113152.348570-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [RFCv2 2/2] libcamera: camera_sensor: Add method\n\tto get sensor info","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>","X-List-Received-Date":"Fri, 27 Mar 2020 11:29:00 -0000"},"content":"Add method to retrieve the CameraSensorInfo to the CameraSensor class.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/camera_sensor.cpp       | 127 ++++++++++++++++++++++++++\n src/libcamera/include/camera_sensor.h |   1 +\n 2 files changed, 128 insertions(+)","diff":"diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex df1d82d29f74..23204b05d062 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -11,10 +11,13 @@\n #include <float.h>\n #include <iomanip>\n #include <limits.h>\n+#include <map>\n #include <math.h>\n #include <memory>\n #include <string.h>\n \n+#include <linux/v4l2-mediabus.h>\n+\n #include <libcamera/property_ids.h>\n \n #include \"formats.h\"\n@@ -30,6 +33,101 @@ namespace libcamera {\n \n LOG_DEFINE_CATEGORY(CameraSensor);\n \n+namespace {\n+\n+const std::map<uint32_t, uint8_t> mbusToBppMap = {\n+\t{ V4L2_MBUS_FMT_RGB444_2X8_PADHI_BE, 16 },\n+\t{ V4L2_MBUS_FMT_RGB444_2X8_PADHI_LE, 16 },\n+\t{ V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE, 16 },\n+\t{ V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE, 16 },\n+\t{ V4L2_MBUS_FMT_BGR565_2X8_BE, 16 },\n+\t{ V4L2_MBUS_FMT_BGR565_2X8_LE, 16 },\n+\t{ V4L2_MBUS_FMT_RGB565_2X8_BE, 16 },\n+\t{ V4L2_MBUS_FMT_RGB565_2X8_LE, 16 },\n+\t{ V4L2_MBUS_FMT_RGB666_1X18, 18 },\n+\t{ V4L2_MBUS_FMT_RGB888_1X24, 24 },\n+\t{ V4L2_MBUS_FMT_RGB888_2X12_BE, 24 },\n+\t{ V4L2_MBUS_FMT_RGB888_2X12_LE, 24 },\n+\t{ V4L2_MBUS_FMT_ARGB8888_1X32, 32 },\n+\t{ V4L2_MBUS_FMT_Y8_1X8, 8 },\n+\t{ V4L2_MBUS_FMT_UV8_1X8, 8 },\n+\t{ V4L2_MBUS_FMT_UYVY8_1_5X8, 40 },\n+\t{ V4L2_MBUS_FMT_VYUY8_1_5X8, 40 },\n+\t{ V4L2_MBUS_FMT_YUYV8_1_5X8, 40 },\n+\t{ V4L2_MBUS_FMT_YVYU8_1_5X8, 40 },\n+\t{ V4L2_MBUS_FMT_UYVY8_2X8, 16 },\n+\t{ V4L2_MBUS_FMT_VYUY8_2X8, 16 },\n+\t{ V4L2_MBUS_FMT_YUYV8_2X8, 16 },\n+\t{ V4L2_MBUS_FMT_YVYU8_2X8, 16 },\n+\t{ V4L2_MBUS_FMT_Y10_1X10, 10 },\n+\t{ V4L2_MBUS_FMT_UYVY10_2X10, 20 },\n+\t{ V4L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\n+\t{ V4L2_MBUS_FMT_SGRBG10_ALAW8_1X8, 8 },\n+\t{ V4L2_MBUS_FMT_SRGGB10_ALAW8_1X8, 8 },\n+\t{ V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8, 8 },\n+\t{ V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8, 8 },\n+\t{ V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8, 8 },\n+\t{ V4L2_MBUS_FMT_SRGGB10_DPCM8_1X8, 8 },\n+\t{ V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_BE, 16 },\n+\t{ V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE, 16 },\n+\t{ V4L2_MBUS_FMT_SBGGR10_2X8_PADLO_BE, 16 },\n+\t{ V4L2_MBUS_FMT_SBGGR10_2X8_PADLO_LE, 16 },\n+\t{ V4L2_MBUS_FMT_SBGGR10_1X10, 10 },\n+\t{ V4L2_MBUS_FMT_SGBRG10_1X10, 10 },\n+\t{ V4L2_MBUS_FMT_SGRBG10_1X10, 10 },\n+\t{ V4L2_MBUS_FMT_SRGGB10_1X10, 10 },\n+\t{ V4L2_MBUS_FMT_SBGGR12_1X12, 24 },\n+\t{ V4L2_MBUS_FMT_SGBRG12_1X12, 24 },\n+\t{ V4L2_MBUS_FMT_SGRBG12_1X12, 24 },\n+\t{ V4L2_MBUS_FMT_SRGGB12_1X12, 24 },\n+\t{ V4L2_MBUS_FMT_JPEG_1X8, 8 },\n+\t{ V4L2_MBUS_FMT_S5C_UYVY_JPEG_1X8, 8 },\n+\t{ V4L2_MBUS_FMT_AHSV8888_1X32, 32 },\n+};\n+\n+uint8_t mbusToBpp(uint32_t mbus_code)\n+{\n+\tconst auto it = mbusToBppMap.find(mbus_code);\n+\tif (it == mbusToBppMap.end()) {\n+\t\tLOG(CameraSensor, Error) << \"Unsupported media bus format: \"\n+\t\t\t\t\t << mbus_code;\n+\t\t/* Return 8 to avoid divisions by 0. */\n+\t\treturn 8;\n+\t}\n+\n+\treturn it->second;\n+}\n+\n+}; /* namespace */\n+\n /**\n  * \\struct CameraSensorInfo\n  * \\brief Report the image sensor characteristics\n@@ -482,6 +580,35 @@ int CameraSensor::setControls(ControlList *ctrls)\n  * \\return The list of camera sensor properties\n  */\n \n+/**\n+ * \\brief Assemble and return the camera sensor info\n+ *\n+ * This method is meant to be overridden by CameraSensor specialized sub-classes\n+ * to report more detailed information about the camera sensor configuration.\n+ *\n+ * The base class implementation provides a stub implementation to support\n+ * camera sensor without an associated sub-class specialization.\n+ *\n+ * \\return An instance of CameraSensorInfo describing the sensor configuration\n+ */\n+CameraSensorInfo CameraSensor::sensorInfo() const\n+{\n+\tCameraSensorInfo info{};\n+\n+\t/* Get format on pad #0 by default for generic camera sensor. */\n+\tV4L2SubdeviceFormat format{};\n+\tint ret = subdev_->getFormat(0, &format);\n+\tif (ret)\n+\t\treturn {};\n+\n+\tinfo.name = \"generic_sensor\";\n+\tinfo.bitsPerPixel = mbusToBpp(format.mbus_code);\n+\tinfo.outputSize.width = format.size.width;\n+\tinfo.outputSize.height = format.size.height;\n+\n+\treturn info;\n+}\n+\n std::string CameraSensor::logPrefix() const\n {\n \treturn \"'\" + subdev_->entity()->name() + \"'\";\ndiff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h\nindex acc6022cf0e8..94374a4d01dd 100644\n--- a/src/libcamera/include/camera_sensor.h\n+++ b/src/libcamera/include/camera_sensor.h\n@@ -69,6 +69,7 @@ public:\n \tint setControls(ControlList *ctrls);\n \n \tconst ControlList &properties() const { return properties_; }\n+\tvirtual CameraSensorInfo sensorInfo() const;\n \n protected:\n \tstd::string logPrefix() const;\n","prefixes":["libcamera-devel","RFCv2","2/2"]}