{"id":890,"url":"https://patchwork.libcamera.org/api/patches/890/?format=json","web_url":"https://patchwork.libcamera.org/patch/890/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20190403080148.11479-5-jacopo@jmondi.org>","date":"2019-04-03T08:01:39","name":"[libcamera-devel,v8,04/13] libcamera: ipu3: Cache the sensor size and format","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"41f965de34253c760852448e27059e113cf5eb34","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/890/mbox/","series":[{"id":235,"url":"https://patchwork.libcamera.org/api/series/235/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=235","date":"2019-04-03T08:01:35","name":"libcamera: ipu3: Add ImgU support","version":8,"mbox":"https://patchwork.libcamera.org/series/235/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/890/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/890/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net\n\t[217.70.183.195])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BEC146110D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Apr 2019 10:01:12 +0200 (CEST)","from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 049396000F;\n\tWed,  3 Apr 2019 08:01:11 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed,  3 Apr 2019 10:01:39 +0200","Message-Id":"<20190403080148.11479-5-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190403080148.11479-1-jacopo@jmondi.org>","References":"<20190403080148.11479-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v8 04/13] libcamera: ipu3: Cache the\n\tsensor size and format","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Wed, 03 Apr 2019 08:01:13 -0000"},"content":"Cache the sensor maximum size and the media bus code used to produce\nit.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/pipeline/ipu3/ipu3.cpp | 51 +++++++++++++++++++++++++++-\n 1 file changed, 50 insertions(+), 1 deletion(-)","diff":"diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 993954777694..1a1517268145 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -8,6 +8,8 @@\n #include <memory>\n #include <vector>\n \n+#include <linux/media-bus-format.h>\n+\n #include <libcamera/camera.h>\n #include <libcamera/request.h>\n #include <libcamera/stream.h>\n@@ -41,9 +43,15 @@ public:\n \n \tint init(const MediaDevice *media, unsigned int index);\n \n+\tstatic int mediaBusToFormat(unsigned int code);\n+\n \tV4L2Device *output_;\n \tV4L2Subdevice *csi2_;\n \tV4L2Subdevice *sensor_;\n+\n+\t/* Maximum sizes and the mbus code used to produce them. */\n+\tunsigned int mbusCode_;\n+\tSize maxSize_;\n };\n \n class PipelineHandlerIPU3 : public PipelineHandler\n@@ -407,7 +415,7 @@ void PipelineHandlerIPU3::IPU3CameraData::bufferReady(Buffer *buffer)\n  * Create and open the video device and subdevices in the CIO2 instance at \\a\n  * index, if a supported image sensor is connected to the CSI-2 receiver of\n  * this CIO2 instance.  Enable the media links connecting the CIO2 components\n- * to prepare for capture operations.\n+ * to prepare for capture operations and cached the sensor maximum size.\n  *\n  * \\return 0 on success or a negative error code otherwise\n  * \\retval -ENODEV No supported image sensor is connected to this CIO2 instance\n@@ -442,6 +450,10 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index)\n \t\treturn ret;\n \n \t/*\n+\t * Now that we're sure a sensor subdevice is connected, make sure it\n+\t * produces at least one image format compatible with CIO2 requirements\n+\t * and cache the camera maximum size.\n+\t *\n \t * \\todo Define when to open and close video device nodes, as they\n \t * might impact on power consumption.\n \t */\n@@ -450,6 +462,27 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index)\n \tif (ret)\n \t\treturn ret;\n \n+\tfor (auto it : sensor_->formats(0)) {\n+\t\tint mbusCode = CIO2Device::mediaBusToFormat(it.first);\n+\t\tif (mbusCode < 0)\n+\t\t\tcontinue;\n+\n+\t\tfor (const SizeRange &size : it.second) {\n+\t\t\tif (maxSize_.width < size.maxWidth &&\n+\t\t\t    maxSize_.height < size.maxHeight) {\n+\t\t\t\tmaxSize_.width = size.maxWidth;\n+\t\t\t\tmaxSize_.height = size.maxHeight;\n+\t\t\t\tmbusCode_ = mbusCode;\n+\t\t\t}\n+\t\t}\n+\t}\n+\tif (maxSize_.width == 0) {\n+\t\tLOG(IPU3, Info) << \"Sensor '\" << sensor_->entityName()\n+\t\t\t\t<< \"' detected, but no supported image format \"\n+\t\t\t\t<< \" found: skip camera creation\";\n+\t\treturn -ENODEV;\n+\t}\n+\n \tcsi2_ = new V4L2Subdevice(csi2Entity);\n \tret = csi2_->open();\n \tif (ret)\n@@ -464,6 +497,22 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index)\n \treturn 0;\n }\n \n+int CIO2Device::mediaBusToFormat(unsigned int code)\n+{\n+\tswitch (code) {\n+\tcase MEDIA_BUS_FMT_SBGGR10_1X10:\n+\t\treturn V4L2_PIX_FMT_IPU3_SBGGR10;\n+\tcase MEDIA_BUS_FMT_SGBRG10_1X10:\n+\t\treturn V4L2_PIX_FMT_IPU3_SGBRG10;\n+\tcase MEDIA_BUS_FMT_SGRBG10_1X10:\n+\t\treturn V4L2_PIX_FMT_IPU3_SGRBG10;\n+\tcase MEDIA_BUS_FMT_SRGGB10_1X10:\n+\t\treturn V4L2_PIX_FMT_IPU3_SRGGB10;\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\n+}\n+\n REGISTER_PIPELINE_HANDLER(PipelineHandlerIPU3);\n \n } /* namespace libcamera */\n","prefixes":["libcamera-devel","v8","04/13"]}