[{"id":1083,"web_url":"https://patchwork.libcamera.org/comment/1083/","msgid":"<20190321085937.GG4615@pendragon.ideasonboard.com>","date":"2019-03-21T08:59:37","subject":"Re: [libcamera-devel] [PATCH v4 04/31] libcamera: ipu3: Set stream\n\tconfiguration from sensor","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Wed, Mar 20, 2019 at 05:30:28PM +0100, Jacopo Mondi wrote:\n> Inspect all image sizes provided by the sensor and select the\n> biggest of them, associated with an image format code supported by the\n> CIO2 unit.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/libcamera/pipeline/ipu3/ipu3.cpp | 47 +++++++++++++++++++---------\n>  1 file changed, 32 insertions(+), 15 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index 2602f89617a3..1df074553fd1 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 <iomanip>\n>  #include <memory>\n>  #include <vector>\n>  \n> @@ -74,6 +75,8 @@ private:\n>  \t\tStream stream_;\n>  \t};\n>  \n> +\tstatic constexpr unsigned int IPU3_BUFFER_COUNT = 4;\n> +\n>  \tIPU3CameraData *cameraData(const Camera *camera)\n>  \t{\n>  \t\treturn static_cast<IPU3CameraData *>(\n> @@ -106,26 +109,40 @@ std::map<Stream *, StreamConfiguration>\n>  PipelineHandlerIPU3::streamConfiguration(Camera *camera,\n>  \t\t\t\t\t std::set<Stream *> &streams)\n>  {\n> -\tIPU3CameraData *data = cameraData(camera);\n>  \tstd::map<Stream *, StreamConfiguration> configs;\n> -\tV4L2SubdeviceFormat format = {};\n> +\tIPU3CameraData *data = cameraData(camera);\n\nNitpicking, there's not need to reorder data and configs.\n\n> +\tV4L2Subdevice *sensor = data->sensor_;\n> +\tStreamConfiguration *config = &configs[&data->stream_];\n> +\tunsigned int bestSize = 0;\n>  \n> -\t/*\n> -\t * FIXME: As of now, return the image format reported by the sensor.\n> -\t * In future good defaults should be provided for each stream.\n> -\t */\n> -\tif (data->sensor_->getFormat(0, &format)) {\n> -\t\tLOG(IPU3, Error) << \"Failed to create stream configurations\";\n> -\t\treturn configs;\n> +\tconst FormatEnum formats = sensor->formats(0);\n\nThe const keyword isn't really needed.\n\n> +\tfor (auto it = formats.begin(); it != formats.end(); ++it) {\n\n\tfor (auto it : formats)\n\n> +\t\tint cio2Code = mediaBusToCIO2Format(it->first);\n> +\t\tif (cio2Code == -EINVAL)\n> +\t\t\tcontinue;\n> +\n> +\t\tfor (const SizeRange &range : it->second) {\n> +\t\t\tunsigned int frameSize = range.maxWidth\n> +\t\t\t\t\t       * range.maxHeight;\n> +\n> +\t\t\t/*  Use the largest image size the sensor provides. */\n> +\t\t\tif (frameSize < bestSize)\n> +\t\t\t\tcontinue;\n> +\n> +\t\t\tbestSize = frameSize;\n> +\n> +\t\t\tconfig->width = range.maxWidth;\n> +\t\t\tconfig->height = range.maxHeight;\n> +\t\t\tconfig->pixelFormat = cio2Code;\n> +\t\t}\n>  \t}\n\nThe formats enumerated by the sensor shouldn't vary, you can do this\nwhen creating the camera and cache the result.\n\n>  \n> -\tStreamConfiguration config = {};\n> -\tconfig.width = format.width;\n> -\tconfig.height = format.height;\n> -\tconfig.pixelFormat = V4L2_PIX_FMT_IPU3_SGRBG10;\n> -\tconfig.bufferCount = 4;\n> +\tconfig->bufferCount = IPU3_BUFFER_COUNT;\n>  \n> -\tconfigs[&data->stream_] = config;\n> +\tLOG(IPU3, Debug)\n> +\t\t<< \"Stream format set to: \" << config->width << \"x\"\n> +\t\t<< config->height << \"- 0x\" << std::hex << std::setfill('0')\n> +\t\t<< std::setw(4) << config->pixelFormat;\n\nShame we can't use the toString() helpers here.\n\n>  \n>  \treturn configs;\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 72DB2600F9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 21 Mar 2019 09:59:49 +0100 (CET)","from pendragon.ideasonboard.com (30.net042126252.t-com.ne.jp\n\t[42.126.252.30])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 26A3F23A;\n\tThu, 21 Mar 2019 09:59:47 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1553158789;\n\tbh=9pcgbxSRPqchcRByigxIvXv5g0zH7ubO2OFiwlLSSd0=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=qqDHz38BA3iBbJ+5gDx1puzD0oFohoLXpieHSvMP40LlKlDpXKhPu+kIRotI9is94\n\tYmbaBitm+jPlHOh0NrJTtzp2nt+F0dBufsK4RfFOFolyR3AxlbfZr61X5w3V6RzLIc\n\t/Y8XMCOfsLpuGmw8DfLwwCyWyGLP8SKT++18yFq4=","Date":"Thu, 21 Mar 2019 10:59:37 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190321085937.GG4615@pendragon.ideasonboard.com>","References":"<20190320163055.22056-1-jacopo@jmondi.org>\n\t<20190320163055.22056-5-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190320163055.22056-5-jacopo@jmondi.org>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v4 04/31] libcamera: ipu3: Set stream\n\tconfiguration from sensor","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":"Thu, 21 Mar 2019 08:59:49 -0000"}}]