{"id":1021,"url":"https://patchwork.libcamera.org/api/1.1/patches/1021/?format=json","web_url":"https://patchwork.libcamera.org/patch/1021/","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":"<20190416220839.1577-13-laurent.pinchart@ideasonboard.com>","date":"2019-04-16T22:08:38","name":"[libcamera-devel,v2,12/13] libcamera: pipeline: ipu3: Use the new CameraSensor class","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"720997566e548877a32550e2a1307fd246257cd9","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1021/mbox/","series":[{"id":253,"url":"https://patchwork.libcamera.org/api/1.1/series/253/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=253","date":"2019-04-16T22:08:26","name":"Rockchip ISP pipeline handler","version":2,"mbox":"https://patchwork.libcamera.org/series/253/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1021/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1021/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 88FAE60DCE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 17 Apr 2019 00:08:55 +0200 (CEST)","from pendragon.bb.dnainternet.fi\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2B9832BA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 17 Apr 2019 00:08:55 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1555452535;\n\tbh=9ceZmuZ/MTu5Mhpo/nBsm3sTOyjsUmxf8y++Mtlj+Mk=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=eCcD8mgsrbTOKoRuSjALuE3ikw4F4Z98m0Qkj1Z8Un6aigiIM2gwZK7iP1c/A2gDf\n\t+P9sbd+tO0q9xoaGfoQxm0tBcWmTQGOJqwARDg0SifJP00+sesrOQPhDz6k9cqfsVM\n\tYtQIlAGuPZU03XnakH9fU6UozjgcnLFu6qzO0BIA=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 17 Apr 2019 01:08:38 +0300","Message-Id":"<20190416220839.1577-13-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190416220839.1577-1-laurent.pinchart@ideasonboard.com>","References":"<20190416220839.1577-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 12/13] libcamera: pipeline: ipu3: Use\n\tthe new CameraSensor class","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, 16 Apr 2019 22:08:56 -0000"},"content":"Replace the manual handling of sensor formats with usage of the new\nCameraSensor class.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\nChanges since v1:\n\n- Move sensor entity function check to CameraSensor class\n- Verify sensor media bus codes at init time\n---\n src/libcamera/pipeline/ipu3/ipu3.cpp | 107 +++++++++------------------\n 1 file changed, 36 insertions(+), 71 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex e3c79f93963e..861c0da7550a 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -5,6 +5,7 @@\n  * ipu3.cpp - Pipeline handler for Intel IPU3\n  */\n \n+#include <algorithm>\n #include <iomanip>\n #include <memory>\n #include <vector>\n@@ -15,6 +16,7 @@\n #include <libcamera/request.h>\n #include <libcamera/stream.h>\n \n+#include \"camera_sensor.h\"\n #include \"device_enumerator.h\"\n #include \"log.h\"\n #include \"media_device.h\"\n@@ -124,11 +126,7 @@ public:\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+\tCameraSensor *sensor_;\n \n \tBufferPool pool_;\n };\n@@ -255,8 +253,9 @@ int PipelineHandlerIPU3::configureStreams(Camera *camera,\n \t\treturn -EINVAL;\n \t}\n \n-\tif (cfg.width > cio2->maxSize_.width ||\n-\t    cfg.height > cio2->maxSize_.height) {\n+\tconst Size &resolution = cio2->sensor_->resolution();\n+\tif (cfg.width > resolution.width ||\n+\t    cfg.height > resolution.height) {\n \t\tLOG(IPU3, Error)\n \t\t\t<< \"Invalid stream size: larger than sensor resolution\";\n \t\treturn -EINVAL;\n@@ -1021,45 +1020,39 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index)\n \n \tMediaLink *link = links[0];\n \tMediaEntity *sensorEntity = link->source()->entity();\n-\tif (sensorEntity->function() != MEDIA_ENT_F_CAM_SENSOR)\n-\t\treturn -ENODEV;\n+\tsensor_ = new CameraSensor(sensorEntity);\n+\tret = sensor_->init();\n+\tif (ret)\n+\t\treturn ret;\n \n \tret = link->setEnabled(true);\n \tif (ret)\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 * Make sure the sensor produces at least one format compatible with\n+\t * the CIO2 requirements.\n \t *\n+\t * utils::set_overlap requires the ranges to be sorted, keep the\n+\t * cio2Codes vector sorted in ascending order.\n+\t */\n+\tconst std::vector<unsigned int> cio2Codes{ MEDIA_BUS_FMT_SBGGR10_1X10,\n+\t\t\t\t\t\t   MEDIA_BUS_FMT_SGBRG10_1X10,\n+\t\t\t\t\t\t   MEDIA_BUS_FMT_SGRBG10_1X10,\n+\t\t\t\t\t\t   MEDIA_BUS_FMT_SRGGB10_1X10 };\n+\tconst std::vector<unsigned int> &sensorCodes = sensor_->mbusCodes();\n+\tif (!utils::set_overlap(sensorCodes.begin(), sensorCodes.end(),\n+\t\t\t\tcio2Codes.begin(), cio2Codes.end())) {\n+\t\tLOG(IPU3, Error)\n+\t\t\t<< \"Sensor \" << sensor_->entity()->name()\n+\t\t\t<< \" has not format compatible with the IPU3\";\n+\t\treturn -EINVAL;\n+\t}\n+\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-\tsensor_ = new V4L2Subdevice(sensorEntity);\n-\tret = sensor_->open();\n-\tif (ret)\n-\t\treturn ret;\n-\n-\tfor (auto it : sensor_->formats(0)) {\n-\t\tint mbusCode = 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.max.width &&\n-\t\t\t    maxSize_.height < size.max.height) {\n-\t\t\t\tmaxSize_ = size.max;\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_->entity()->name()\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@@ -1085,47 +1078,19 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index)\n int CIO2Device::configure(const StreamConfiguration &config,\n \t\t\t  V4L2DeviceFormat *outputFormat)\n {\n-\tunsigned int imageSize = config.width * config.height;\n-\tV4L2SubdeviceFormat sensorFormat = {};\n-\tunsigned int best = ~0;\n+\tV4L2SubdeviceFormat sensorFormat;\n \tint ret;\n \n-\tfor (auto it : sensor_->formats(0)) {\n-\t\t/* Only consider formats consumable by the CIO2 unit. */\n-\t\tif (mediaBusToFormat(it.first) < 0)\n-\t\t\tcontinue;\n-\n-\t\tfor (const SizeRange &size : it.second) {\n-\t\t\t/*\n-\t\t\t * Only select formats bigger than the requested sizes\n-\t\t\t * as the IPU3 cannot up-scale.\n-\t\t\t *\n-\t\t\t * \\todo: Unconditionally scale on the sensor as much\n-\t\t\t * as possible. This will need to be revisited when\n-\t\t\t * implementing the scaling policy.\n-\t\t\t */\n-\t\t\tif (size.max.width < config.width ||\n-\t\t\t    size.max.height < config.height)\n-\t\t\t\tcontinue;\n-\n-\t\t\tunsigned int diff = size.max.width * size.max.height\n-\t\t\t\t\t  - imageSize;\n-\t\t\tif (diff >= best)\n-\t\t\t\tcontinue;\n-\n-\t\t\tbest = diff;\n-\n-\t\t\tsensorFormat.width = size.max.width;\n-\t\t\tsensorFormat.height = size.max.height;\n-\t\t\tsensorFormat.mbus_code = it.first;\n-\t\t}\n-\t}\n-\n \t/*\n \t * Apply the selected format to the sensor, the CSI-2 receiver and\n \t * the CIO2 output device.\n \t */\n-\tret = sensor_->setFormat(0, &sensorFormat);\n+\tsensorFormat = sensor_->getFormat({ MEDIA_BUS_FMT_SBGGR10_1X10,\n+\t\t\t\t\t    MEDIA_BUS_FMT_SGBRG10_1X10,\n+\t\t\t\t\t    MEDIA_BUS_FMT_SGRBG10_1X10,\n+\t\t\t\t\t    MEDIA_BUS_FMT_SRGGB10_1X10 },\n+\t\t\t\t\t  Size(config.width, config.height));\n+\tret = sensor_->setFormat(&sensorFormat);\n \tif (ret)\n \t\treturn ret;\n \n","prefixes":["libcamera-devel","v2","12/13"]}