[{"id":1369,"web_url":"https://patchwork.libcamera.org/comment/1369/","msgid":"<20190415215039.GA1980@bigcity.dyn.berto.se>","date":"2019-04-15T21:50:39","subject":"Re: [libcamera-devel] [PATCH 10/11] libcamera: pipeline: ipu3: Use\n\tthe new CameraSensor class","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for your work.\n\nOn 2019-04-15 19:56:59 +0300, Laurent Pinchart wrote:\n> Replace the manual handling of sensor formats with usage of the new\n> CameraSensor class.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  src/libcamera/pipeline/ipu3/ipu3.cpp | 78 +++++-----------------------\n>  1 file changed, 14 insertions(+), 64 deletions(-)\n\nI just love to see code melt away from pipeline handler implementations \nto helpers.\n\n> \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index e3c79f93963e..1326a1be105f 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -15,6 +15,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 +125,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 +252,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> @@ -1036,31 +1034,11 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index)\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> +\tsensor_ = new CameraSensor(sensorEntity);\n> +\tret = sensor_->init();\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>  \tif (ret)\n> @@ -1085,47 +1063,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> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lf1-x141.google.com (mail-lf1-x141.google.com\n\t[IPv6:2a00:1450:4864:20::141])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 09AB560B2E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 15 Apr 2019 23:50:41 +0200 (CEST)","by mail-lf1-x141.google.com with SMTP id j11so14301372lfm.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 15 Apr 2019 14:50:40 -0700 (PDT)","from localhost (89-233-230-99.cust.bredband2.com. [89.233.230.99])\n\tby smtp.gmail.com with ESMTPSA id\n\tb14sm10277743ljf.53.2019.04.15.14.50.39\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tMon, 15 Apr 2019 14:50:39 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=6VemNAamvJPf5EQAgYsGawk0SaNIHlcGtJsN+N3+JEw=;\n\tb=ag4igDTFqJw8OL6iyOVY9kX5z7S64GINLvjVUUFtUp5aEsmi9XW0RwEIFgYzUtYP5E\n\tjjSjmdGNiQd5rtR/3/OlL3miy6yHRszD6DDgFAcsyA0iYe5QO8IVuIV4CF+hyi5KhscB\n\tQuMQcZBKGucfVZ/oy58SnLQFVlXiJSuexabwp9YwKTM1eEX9VsC12O/jFV7Ct7ofYTRl\n\t0bDhdqOzSL2gfCpkpzlFC/OCHhhj8a1G4HkafXZzGlMZu9ZamMe29/woi1UwGQ7YFk++\n\tQzKXqpzSpYVwFf0q7gnZOJdnqwvWorNSbPOdE41gHtXfJ9vSy30sAwuPhqWTCgqLEd55\n\tPsBg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=6VemNAamvJPf5EQAgYsGawk0SaNIHlcGtJsN+N3+JEw=;\n\tb=sqD4yDLBYGUfqleaxJdPW+ZrVjkyhD2wv9h01D3SXvVm1C0yuMUAFb0T42ZMZkzD0P\n\tifpkyfiAAXU2xAOwVIMxgS2MKr2r2CudCw0xxWmCDtCzXbXwlA1YFPdabQof4V7EzEZz\n\tool/vnzV207LICPaI2RrZsqRlx6DpFQxVMFpAOPGaZPBcXEa86DyvHnnkLvGeioqS34X\n\t62ZiQWNPRM4DfKwM+cs3gs2REVhN+oPSix+mGziJglkTTM0SoqHynqTICQYwcj+sppky\n\trOS+gnrBSJY0+qFjRkjsjROZROae/f0z4CaXIJGQ7p/NWStRwAzGkcn4ljyiLpDxm55x\n\tFhNA==","X-Gm-Message-State":"APjAAAXx+FZ8jdg5j6gGHpRtdBMReKRNV/2rag93MlD+Zwvdmmo3Uxjn\n\t95aY1eAVgPr4FcGf+yPYovWDOAu/Vc4=","X-Google-Smtp-Source":"APXvYqzxuTihl2p4xtgD4jtMlyd+X6iXcxxRQY/pdp8Vi2nAdOTq0KHJUw3P2rKA6Y+KxTr9pj/1vQ==","X-Received":"by 2002:a19:4b84:: with SMTP id y126mr189698lfa.15.1555365040313;\n\tMon, 15 Apr 2019 14:50:40 -0700 (PDT)","Date":"Mon, 15 Apr 2019 23:50:39 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190415215039.GA1980@bigcity.dyn.berto.se>","References":"<20190415165700.22970-1-laurent.pinchart@ideasonboard.com>\n\t<20190415165700.22970-11-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190415165700.22970-11-laurent.pinchart@ideasonboard.com>","User-Agent":"Mutt/1.11.3 (2019-02-01)","Subject":"Re: [libcamera-devel] [PATCH 10/11] 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":"Mon, 15 Apr 2019 21:50:41 -0000"}},{"id":1396,"web_url":"https://patchwork.libcamera.org/comment/1396/","msgid":"<20190416164021.i4dub2mpudek74k5@uno.localdomain>","date":"2019-04-16T16:40:21","subject":"Re: [libcamera-devel] [PATCH 10/11] libcamera: pipeline: ipu3: Use\n\tthe new CameraSensor class","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Mon, Apr 15, 2019 at 07:56:59PM +0300, Laurent Pinchart wrote:\n> Replace the manual handling of sensor formats with usage of the new\n> CameraSensor class.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/libcamera/pipeline/ipu3/ipu3.cpp | 78 +++++-----------------------\n>  1 file changed, 14 insertions(+), 64 deletions(-)\n>\n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index e3c79f93963e..1326a1be105f 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -15,6 +15,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 +125,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 +252,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> @@ -1036,31 +1034,11 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index)\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> +\tsensor_ = new CameraSensor(sensorEntity);\n> +\tret = sensor_->init();\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>  \tif (ret)\n> @@ -1085,47 +1063,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\nover-paranoid me wonders if this has to be checked...\n\nVery nice removing code from pipeline handlers\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n  j\n\n\n> +\tret = sensor_->setFormat(&sensorFormat);\n>  \tif (ret)\n>  \t\treturn ret;\n>\n> --\n> Regards,\n>\n> Laurent Pinchart\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net\n\t[217.70.183.201])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D693A60DB4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 16 Apr 2019 18:39:29 +0200 (CEST)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 5282B1BF213;\n\tTue, 16 Apr 2019 16:39:29 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","Date":"Tue, 16 Apr 2019 18:40:21 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190416164021.i4dub2mpudek74k5@uno.localdomain>","References":"<20190415165700.22970-1-laurent.pinchart@ideasonboard.com>\n\t<20190415165700.22970-11-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"fy3d6talptwz2itt\"","Content-Disposition":"inline","In-Reply-To":"<20190415165700.22970-11-laurent.pinchart@ideasonboard.com>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH 10/11] 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 16:39:30 -0000"}},{"id":1408,"web_url":"https://patchwork.libcamera.org/comment/1408/","msgid":"<20190416214103.GE4822@pendragon.ideasonboard.com>","date":"2019-04-16T21:41:03","subject":"Re: [libcamera-devel] [PATCH 10/11] libcamera: pipeline: ipu3: Use\n\tthe new CameraSensor class","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn Tue, Apr 16, 2019 at 06:40:21PM +0200, Jacopo Mondi wrote:\n> On Mon, Apr 15, 2019 at 07:56:59PM +0300, Laurent Pinchart wrote:\n> > Replace the manual handling of sensor formats with usage of the new\n> > CameraSensor class.\n> >\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  src/libcamera/pipeline/ipu3/ipu3.cpp | 78 +++++-----------------------\n> >  1 file changed, 14 insertions(+), 64 deletions(-)\n> >\n> > diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> > index e3c79f93963e..1326a1be105f 100644\n> > --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> > +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> > @@ -15,6 +15,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 +125,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 +252,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> > @@ -1036,31 +1034,11 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index)\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> > +\tsensor_ = new CameraSensor(sensorEntity);\n> > +\tret = sensor_->init();\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> >  \tif (ret)\n> > @@ -1085,47 +1063,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> \n> over-paranoid me wonders if this has to be checked...\n\nIn practice it would be very weird to find a system with a sensor\nconnected to the IPU3 where the two would have no common format. I\nhowever think it would make sense to check this, not here, but after\ncalling CameraSensor::init(). I'll do so.\n\n> Very nice removing code from pipeline handlers\n> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n> \n> > +\tret = sensor_->setFormat(&sensorFormat);\n> >  \tif (ret)\n> >  \t\treturn ret;\n> >","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3808E60004\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 16 Apr 2019 23:41:13 +0200 (CEST)","from pendragon.ideasonboard.com\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 94A8BE2;\n\tTue, 16 Apr 2019 23:41:12 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1555450872;\n\tbh=A8DTwEOuPzaEvLNGvu4kz26zFaCQR5x3Ke+7gLI4uyg=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=IgOxvqTMcb+8t+slvpZgOwqpvtfAkiz4NThxY1v3CdYlYp1tulX+U6XUixKyIwNsp\n\tH1y/Q5eP8gi4aggsulQCpCgUOjTclj2jVF4iXw5EsqVfRHhhbPRccKPOnlXxnqyhQG\n\t+PJXAjGgaM4rWVZP1bTzXwc9OIPZJHEJZWHjPPBo=","Date":"Wed, 17 Apr 2019 00:41:03 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190416214103.GE4822@pendragon.ideasonboard.com>","References":"<20190415165700.22970-1-laurent.pinchart@ideasonboard.com>\n\t<20190415165700.22970-11-laurent.pinchart@ideasonboard.com>\n\t<20190416164021.i4dub2mpudek74k5@uno.localdomain>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190416164021.i4dub2mpudek74k5@uno.localdomain>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 10/11] 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 21:41:13 -0000"}}]