[{"id":24947,"web_url":"https://patchwork.libcamera.org/comment/24947/","msgid":"<166245659081.4009730.14213354798415071376@Monstersaurus>","date":"2022-09-06T09:29:50","subject":"Re: [libcamera-devel] [PATCH 2/3] pipeline: uvcvideo: Cache\n\tsupported formats in UVCCameraData","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Laurent Pinchart via libcamera-devel (2022-09-03 19:10:36)\n> Populate and cache the list of supported formats in\n> UVCCameraData::init(), to avoid repeating the operation every time\n> generateConfiguration() is called.\n> \n\nFurthermore, optimize the search for the largest supported size reported\nby the device by determining this while processing the supported formats\nto prevent searching the list twice.\n\n(Or otherwise...)\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 44 ++++++++++----------\n>  1 file changed, 22 insertions(+), 22 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n> index 22b67faf309e..be0fbaea508a 100644\n> --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n> +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n> @@ -50,6 +50,7 @@ public:\n>  \n>         std::unique_ptr<V4L2VideoDevice> video_;\n>         Stream stream_;\n> +       std::map<PixelFormat, std::vector<SizeRange>> formats_;\n>  \n>  private:\n>         bool generateId();\n> @@ -186,15 +187,7 @@ CameraConfiguration *PipelineHandlerUVC::generateConfiguration(Camera *camera,\n>         if (roles.empty())\n>                 return config;\n>  \n> -       V4L2VideoDevice::Formats v4l2Formats = data->video_->formats();\n> -       std::map<PixelFormat, std::vector<SizeRange>> deviceFormats;\n> -       for (const auto &format : v4l2Formats) {\n> -               PixelFormat pixelFormat = format.first.toPixelFormat();\n> -               if (pixelFormat.isValid())\n> -                       deviceFormats[pixelFormat] = format.second;\n> -       }\n> -\n> -       StreamFormats formats(deviceFormats);\n> +       StreamFormats formats(data->formats_);\n>         StreamConfiguration cfg(formats);\n>  \n>         cfg.pixelFormat = formats.pixelformats().front();\n> @@ -445,6 +438,26 @@ int UVCCameraData::init(MediaDevice *media)\n>                 return -EINVAL;\n>         }\n>  \n> +       /*\n> +        * Populate the map of supported formats, and infer the camera sensor\n> +        * resolution from the largest size it advertises.\n> +        */\n> +       Size resolution;\n> +       for (const auto &format : video_->formats()) {\n> +               PixelFormat pixelFormat = format.first.toPixelFormat();\n> +               if (!pixelFormat.isValid())\n> +                       continue;\n> +\n> +               formats_[pixelFormat] = format.second;\n> +\n> +               const std::vector<SizeRange> &sizeRanges = format.second;\n> +               for (const SizeRange &sizeRange : sizeRanges) {\n> +                       if (sizeRange.max > resolution)\n> +                               resolution = sizeRange.max;\n> +               }\n> +       }\n> +\n> +       /* Populate the camera properties. */\n>         properties_.set(properties::Model, utils::toAscii(media->model()));\n>  \n>         /*\n> @@ -475,19 +488,6 @@ int UVCCameraData::init(MediaDevice *media)\n>  \n>         properties_.set(properties::Location, location);\n>  \n> -       /*\n> -        * Get the current format in order to initialize the sensor array\n> -        * properties.\n> -        */\n> -       Size resolution;\n> -       for (const auto &it : video_->formats()) {\n> -               const std::vector<SizeRange> &sizeRanges = it.second;\n> -               for (const SizeRange &sizeRange : sizeRanges) {\n> -                       if (sizeRange.max > resolution)\n> -                               resolution = sizeRange.max;\n> -               }\n> -       }\n> -\n>         properties_.set(properties::PixelArraySize, resolution);\n>         properties_.set(properties::PixelArrayActiveAreas, { Rectangle(resolution) });\n>  \n> -- \n> Regards,\n> \n> Laurent Pinchart\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 9B369C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  6 Sep 2022 09:29:56 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E65566207C;\n\tTue,  6 Sep 2022 11:29:55 +0200 (CEST)","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 627216203B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  6 Sep 2022 11:29:54 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C9F9425B;\n\tTue,  6 Sep 2022 11:29:53 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1662456595;\n\tbh=zfg9EVR+NIuhMAVKuKb+wCcSj7t0Pbu5wg/15/vhLto=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=1TdXL+vLGzNLMWFCdYfOI2z2BKEQ+7peeMYTYR+DIiSZziYFUgq6NFS6nCZqKYgJk\n\tyT/EaToFENWzTSz+So9k/zjtIHyGkESEX6mfE5N3VPvOzjP8X22uTkYi50tRrO9CVj\n\tyXbX4iRw6tNzqzIdhpi+AuqRtH28V0y5euM1lZYAnQMfkYvg+/FhdWvR1tMb33+yNW\n\tC/leKO2Xqy/5O71GElRcz8qZT3hG8RuDUDzy8LF+WmN2ZPqfoFe2pzeDdeKK00t6Gf\n\tOMix43drYWPDQCnNw0AI/kBCTzjycN7ccmPbysQs5IFylc6DCurvvXEAXLhV/gyaCJ\n\to8O0V5+Y50jgQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1662456593;\n\tbh=zfg9EVR+NIuhMAVKuKb+wCcSj7t0Pbu5wg/15/vhLto=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=RT62otItz8WXR5mXoyUxQQtu07dFIoU6470SnOOlhUgI8Y3t/iUuNYgI6il9x9h3J\n\t8j5ZCJCL9OLVyKNrG6ME65+aj+7evAOraS4/qZgITeTqWjcJ9LuN3hXbCmfRdMBqJd\n\t3Wyx3xXYaDh8bZP3PlGLmrHknucMkPDUU7QS2QbY="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"RT62otIt\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20220903181037.1406-3-laurent.pinchart@ideasonboard.com>","References":"<20220903181037.1406-1-laurent.pinchart@ideasonboard.com>\n\t<20220903181037.1406-3-laurent.pinchart@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Tue, 06 Sep 2022 10:29:50 +0100","Message-ID":"<166245659081.4009730.14213354798415071376@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH 2/3] pipeline: uvcvideo: Cache\n\tsupported formats in UVCCameraData","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]