[{"id":22836,"web_url":"https://patchwork.libcamera.org/comment/22836/","msgid":"<165165495690.4076486.16092857294729431734@Monstersaurus>","date":"2022-05-04T09:02:36","subject":"Re: [libcamera-devel] [PATCH 4/5] libcamera: Add operator<<() for\n\tV4L2 format classes","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-04-29 22:23:47)\n> Implement the stream output operator<<() for the V4L2DeviceFormat and\n> V4L2SubdeviceFormat classes to simplify printing them.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  include/libcamera/internal/v4l2_subdevice.h   |  3 ++\n>  include/libcamera/internal/v4l2_videodevice.h |  3 ++\n>  src/libcamera/v4l2_subdevice.cpp              | 34 +++++++++++++------\n>  src/libcamera/v4l2_videodevice.cpp            | 16 ++++++++-\n>  4 files changed, 45 insertions(+), 11 deletions(-)\n> \n> diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h\n> index 58d1e5114e7b..6fda52ada41b 100644\n> --- a/include/libcamera/internal/v4l2_subdevice.h\n> +++ b/include/libcamera/internal/v4l2_subdevice.h\n> @@ -9,6 +9,7 @@\n>  \n>  #include <memory>\n>  #include <optional>\n> +#include <ostream>\n>  #include <string>\n>  #include <vector>\n>  \n> @@ -35,6 +36,8 @@ struct V4L2SubdeviceFormat {\n>         uint8_t bitsPerPixel() const;\n>  };\n>  \n> +std::ostream &operator<<(std::ostream &out, const V4L2SubdeviceFormat &f);\n> +\n>  class V4L2Subdevice : public V4L2Device\n>  {\n>  public:\n> diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\n> index 9c9493cc16ed..23f37f83f8e2 100644\n> --- a/include/libcamera/internal/v4l2_videodevice.h\n> +++ b/include/libcamera/internal/v4l2_videodevice.h\n> @@ -11,6 +11,7 @@\n>  #include <atomic>\n>  #include <memory>\n>  #include <optional>\n> +#include <ostream>\n>  #include <stdint.h>\n>  #include <string>\n>  #include <vector>\n> @@ -180,6 +181,8 @@ public:\n>         const std::string toString() const;\n>  };\n>  \n> +std::ostream &operator<<(std::ostream &out, const V4L2DeviceFormat &f);\n> +\n>  class V4L2VideoDevice : public V4L2Device\n>  {\n>  public:\n> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> index d5ae460571d8..b3d0ddad83db 100644\n> --- a/src/libcamera/v4l2_subdevice.cpp\n> +++ b/src/libcamera/v4l2_subdevice.cpp\n> @@ -190,17 +190,10 @@ const std::map<uint32_t, V4L2SubdeviceFormatInfo> formatInfoMap = {\n>   */\n>  const std::string V4L2SubdeviceFormat::toString() const\n>  {\n> -       std::stringstream mbus;\n> -       mbus << size << \"-\";\n> +       std::stringstream ss;\n> +       ss << *this;\n>  \n> -       const auto it = formatInfoMap.find(mbus_code);\n> -\n> -       if (it == formatInfoMap.end())\n> -               mbus << utils::hex(mbus_code, 4);\n> -       else\n> -               mbus << it->second.name;\n> -\n> -       return mbus.str();\n> +       return ss.str();\n>  }\n>  \n>  /**\n> @@ -220,6 +213,27 @@ uint8_t V4L2SubdeviceFormat::bitsPerPixel() const\n>         return it->second.bitsPerPixel;\n>  }\n>  \n> +/**\n> + * \\brief Insert a text representation of a V4L2SubdeviceFormat into an output\n> + * stream\n> + * \\param[in] out The output stream\n> + * \\param[in] f The V4L2SubdeviceFormat\n> + * \\return The output stream \\a out\n> + */\n> +std::ostream &operator<<(std::ostream &out, const V4L2SubdeviceFormat &f)\n> +{\n> +       out << f.size << \"-\";\n> +\n> +       const auto it = formatInfoMap.find(f.mbus_code);\n> +\n> +       if (it == formatInfoMap.end())\n> +               out << utils::hex(f.mbus_code, 4);\n> +       else\n> +               out << it->second.name;\n> +\n> +       return out;\n> +}\n> +\n>  /**\n>   * \\class V4L2Subdevice\n>   * \\brief A V4L2 subdevice as exposed by the Linux kernel\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 5ba866ad71bb..5b4637b1a39e 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -433,10 +433,24 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const\n>  const std::string V4L2DeviceFormat::toString() const\n>  {\n>         std::stringstream ss;\n> -       ss << size << \"-\" << fourcc.toString();\n> +       ss << *this;\n> +\n>         return ss.str();\n>  }\n>  \n> +/**\n> + * \\brief Insert a text representation of a V4L2DeviceFormat into an output\n> + * stream\n> + * \\param[in] out The output stream\n> + * \\param[in] f The V4L2DeviceFormat\n> + * \\return The output stream \\a out\n> + */\n> +std::ostream &operator<<(std::ostream &out, const V4L2DeviceFormat &f)\n> +{\n> +       out << f.size << \"-\" << f.fourcc;\n> +       return out;\n> +}\n> +\n>  /**\n>   * \\class V4L2VideoDevice\n>   * \\brief V4L2VideoDevice object and API\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 18C4AC0F2A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  4 May 2022 09:02:42 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 71B2E65642;\n\tWed,  4 May 2022 11:02:41 +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 5174A65641\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  4 May 2022 11:02:39 +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 DD8BFE5;\n\tWed,  4 May 2022 11:02:38 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1651654961;\n\tbh=oXKBzykd6HBQpSrTznn0sI/ZQdkgtfdsxcgs/VlvSPA=;\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=NMepzZaQMtcxM2iftZSr8x28jQzO4Dan78CAYoX+rFDAMcOdNQaqF+eAwq6aKOElK\n\t+LjllEinPgru+H/2Trz3AXlEX8eT5PpsWBe3c6eET6iswrCQyJQrKxHQdeUB255eE/\n\t0MBMDs4BTAxQEuGfvxCznE9j0d8vesM6zKqAL38N80qHLIUW5wy1ELsHSPDWh+r1vx\n\tXJDfEJtYEtPk0x0btJf23Sv1X8KYsVJ9udwYC+EW5GuuUX1/ycR+AaKFa7V0k8juaS\n\t82RloKiWJT0WNbtMxx1e28Cvfs1UsroeedZhP9YF1r3qg7voPdUIivubGjgCFTyIrP\n\t9oAdi7jsEKG0A==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1651654958;\n\tbh=oXKBzykd6HBQpSrTznn0sI/ZQdkgtfdsxcgs/VlvSPA=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=kBwlVnXtaBC1stVVkRHnYsFQJ/LT3oZYLBwv6Amdkvm8aqpX9q5oWG6YDj+jQ8NAN\n\tM6U8A6Ey4PdgIU35OggSke04ri23HzJdpSO4Oc8JoNh9oHWTZB96TmRDDAgcrLd0i/\n\tRjBcTczLi+SAdHQv0GTsGZvfjMF+2ndfQaT1ZcmA="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"kBwlVnXt\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20220429212348.18063-5-laurent.pinchart@ideasonboard.com>","References":"<20220429212348.18063-1-laurent.pinchart@ideasonboard.com>\n\t<20220429212348.18063-5-laurent.pinchart@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 04 May 2022 10:02:36 +0100","Message-ID":"<165165495690.4076486.16092857294729431734@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH 4/5] libcamera: Add operator<<() for\n\tV4L2 format classes","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>"}}]