{"id":803,"url":"https://patchwork.libcamera.org/api/patches/803/?format=json","web_url":"https://patchwork.libcamera.org/patch/803/","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":"<20190326083902.26121-9-jacopo@jmondi.org>","date":"2019-03-26T08:38:51","name":"[libcamera-devel,v5,08/19] libcamera: ipu3: Cache the camera sizes","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"2eb653e4a4a1a6e657fcaa179a66370941c545d2","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/803/mbox/","series":[{"id":219,"url":"https://patchwork.libcamera.org/api/series/219/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=219","date":"2019-03-26T08:38:43","name":"libcamera: ipu3: Add ImgU support","version":5,"mbox":"https://patchwork.libcamera.org/series/219/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/803/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/803/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay10.mail.gandi.net (relay10.mail.gandi.net\n\t[217.70.178.230])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6ECBA61243\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 26 Mar 2019 09:38:35 +0100 (CET)","from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay10.mail.gandi.net (Postfix) with ESMTPSA id EC9EF240005;\n\tTue, 26 Mar 2019 08:38:34 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 26 Mar 2019 09:38:51 +0100","Message-Id":"<20190326083902.26121-9-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190326083902.26121-1-jacopo@jmondi.org>","References":"<20190326083902.26121-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 08/19] libcamera: ipu3: Cache the\n\tcamera sizes","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":"Tue, 26 Mar 2019 08:38:36 -0000"},"content":"When creating a camera, make sure a the image sensor provides images in\na format compatible with IPU3 CIO2 unit requirements and cache the\nminimum and maximum camera sizes.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/pipeline/ipu3/ipu3.cpp | 56 +++++++++++++++++++++++++++-\n 1 file changed, 54 insertions(+), 2 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 55489c31df2d..d42c81273cc6 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -8,11 +8,14 @@\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 \n #include \"device_enumerator.h\"\n+#include \"geometry.h\"\n #include \"log.h\"\n #include \"media_device.h\"\n #include \"pipeline_handler.h\"\n@@ -24,6 +27,22 @@ namespace libcamera {\n \n LOG_DEFINE_CATEGORY(IPU3)\n \n+static int mediaBusToCIO2Format(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 class PipelineHandlerIPU3 : public PipelineHandler\n {\n public:\n@@ -70,6 +89,9 @@ private:\n \t\tV4L2Subdevice *sensor_;\n \n \t\tStream stream_;\n+\n+\t\t/* Maximum sizes and the mbus code used to produce them. */\n+\t\tstd::pair<unsigned int, SizeRange> maxSizes_;\n \t};\n \n \tIPU3CameraData *cameraData(const Camera *camera)\n@@ -404,18 +426,48 @@ void PipelineHandlerIPU3::registerCameras()\n \t\tif (ret)\n \t\t\tcontinue;\n \n-\t\tdata->cio2_->bufferReady.connect(data.get(), &IPU3CameraData::bufferReady);\n-\n+\t\t/*\n+\t\t * Make sure the sensor produces at least one image format\n+\t\t * compatible with IPU3 CIO2 requirements and cache the camera\n+\t\t * maximum sizes.\n+\t\t */\n \t\tdata->sensor_ = new V4L2Subdevice(sensor);\n \t\tret = data->sensor_->open();\n \t\tif (ret)\n \t\t\tcontinue;\n \n+\t\tfor (auto it : data->sensor_->formats(0)) {\n+\t\t\tint mbusCode = mediaBusToCIO2Format(it.first);\n+\t\t\tif (mbusCode < 0)\n+\t\t\t\tcontinue;\n+\n+\t\t\tfor (const SizeRange &size : it.second) {\n+\t\t\t\tSizeRange &maxSize = data->maxSizes_.second;\n+\n+\t\t\t\tif (maxSize.maxWidth < size.maxWidth &&\n+\t\t\t\t    maxSize.maxHeight < size.maxHeight) {\n+\t\t\t\t\tmaxSize.maxWidth = size.maxWidth;\n+\t\t\t\t\tmaxSize.maxHeight = size.maxHeight;\n+\t\t\t\t\tdata->maxSizes_.first = mbusCode;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\t\tif (data->maxSizes_.second.maxWidth == 0) {\n+\t\t\tLOG(IPU3, Info)\n+\t\t\t\t<< \"Sensor '\" << data->sensor_->entityName()\n+\t\t\t\t<< \"' detected, but no supported image format \"\n+\t\t\t\t<< \" found: skip camera creation\";\n+\t\t\tcontinue;\n+\t\t}\n+\n \t\tdata->csi2_ = new V4L2Subdevice(csi2);\n \t\tret = data->csi2_->open();\n \t\tif (ret)\n \t\t\tcontinue;\n \n+\t\tdata->cio2_->bufferReady.connect(data.get(),\n+\t\t\t\t\t\t &IPU3CameraData::bufferReady);\n+\n \t\tregisterCamera(std::move(camera), std::move(data));\n \n \t\tLOG(IPU3, Info)\n","prefixes":["libcamera-devel","v5","08/19"]}