[{"id":1888,"web_url":"https://patchwork.libcamera.org/comment/1888/","msgid":"<20190613151533.h5z46sg5hqx4aexv@uno.localdomain>","date":"2019-06-13T15:15:33","subject":"Re: [libcamera-devel] [PATCH v2 05/16] libcamera: formats: Add\n\tImageFormats","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Niklas,\n\nOn Wed, Jun 12, 2019 at 02:43:48AM +0200, Niklas Söderlund wrote:\n> Add a new class to hold format information for v4l2 devices and\n> subdevices. The object describes the relationship between either pixel\n> formats (v4l2 devices) or media bus codes (v4l2 subdevice) and a list of\n> image sizes which can be produced with that format.\n>\n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/libcamera/formats.cpp       | 83 +++++++++++++++++++++++++++++++++\n>  src/libcamera/include/formats.h | 17 +++++++\n>  2 files changed, 100 insertions(+)\n>\n> diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp\n> index 56f4ddb51ffad4d3..ab4bae0a5928d9ba 100644\n> --- a/src/libcamera/formats.cpp\n> +++ b/src/libcamera/formats.cpp\n> @@ -24,4 +24,87 @@ namespace libcamera {\n>   * resolutions represented by SizeRange items.\n>   */\n>\n> +/**\n> + * \\class ImageFormats\n\nI'm a bit undecided here... This represents a V4L2 device or subdevice\nformat, and I would keep the \"ImageFormats\" name for the application\nfacing image format, which might end up being different than the V4L2\ndefined one.\n\nNow that we have a V4L2Device I think V4L2Format might be considered\nas an alternative name..\n\n> + * \\brief Describe V4L2Device and V4L2SubDevice image formats\n> + *\n> + * The class describes information about image formats and supported sizes. If\n> + * the ImageFormat describe a V4L2Device the formats described are pixel formats\n> + * while if it describes a V4L2SubDevice the formats are media bus codes.\n\nI would:\n The class describes information about image formats and supported sizes. If\n the ImageFormat describe a V4L2Device the image formats are described\n with a fourcc pixel format code, while if it describes a V4L2SubDevice\n the formats are described with media bus codes, both defined by the\n V4L2 specification.\n\nIs fine if you keep yours...\n\n> + */\n> +\n> +ImageFormats::ImageFormats()\n> +{\n> +}\n\nDo you need this? The compiler generates a default contructor for\nyou..\n\n> +\n> +/**\n> + * \\brief Add a format and sizes to the description\n> + * \\param[in] format Pixel format or media bus code to describe\n> + * \\param[in] sizes List of supported sizes for the format\n> + *\n> + * \\return 0 on success or a negative error code otherwise\n> + * \\retval -EBUSY The format is already described\n> + */\n> +int ImageFormats::addFormat(unsigned int format, const std::vector<SizeRange> &sizes)\n> +{\n> +\tif (data_.find(format) != data_.end())\n> +\t\treturn -EBUSY;\n> +\n> +\tdata_[format] = sizes;\n> +\n> +\treturn 0;\n> +}\n> +\n> +/**\n> + * \\brief Retrieve a list of all supported image formats\n> + * \\return List of pixel formats or media bus codes\n> + */\n> +std::vector<unsigned int> ImageFormats::formats() const\n> +{\n> +\tstd::vector<unsigned int> formats;\n> +\tformats.reserve(data_.size());\n> +\n> +\tfor (auto const &it : data_)\n> +\t\tformats.push_back(it.first);\n> +\n> +\treturn formats;\n> +}\n> +\n> +/**\n> + * \\brief Retrieve all sizes for a specific format\n> + * \\param[in] format A pixelformat or mbus code\n> + *\n> + * Retrieve all SizeRanges for a specific format. For V4L2Device \\a format is a\n> + * pixel format while for a V4L2Subdevice \\a format is a media bus code.\n> + *\n> + * \\return he list of image sizes produced using \\a format, or an empty list if\n> + * format is not supported\n> + */\n> +std::vector<SizeRange> ImageFormats::sizes(unsigned int format) const\n> +{\n> +\tauto const &it = data_.find(format);\n> +\tif (it == data_.end())\n> +\t\treturn {};\n> +\n> +\treturn it->second;\n> +}\n> +\n> +/**\n> + * \\brief Check if the list of devices supported formats is empty\n> + * \\return True if the list of supported formats is empty\n> + */\n> +bool ImageFormats::isEmpty() const\n> +{\n> +\treturn data_.empty();\n> +}\n> +\n> +/**\n> + * \\brief Retrieve the map that associates formats to image sizes\n> + * \\return Map that associates formats to image sizes\n> + */\n> +const std::map<unsigned int, std::vector<SizeRange>> &ImageFormats::data() const\n> +{\n> +\treturn data_;\n> +}\n> +\n>  } /* namespace libcamera */\n> diff --git a/src/libcamera/include/formats.h b/src/libcamera/include/formats.h\n> index a73772b1eda068b4..a31aa42bcb4742ac 100644\n> --- a/src/libcamera/include/formats.h\n> +++ b/src/libcamera/include/formats.h\n> @@ -17,6 +17,23 @@ namespace libcamera {\n>\n>  typedef std::map<unsigned int, std::vector<SizeRange>> FormatEnum;\n\nDo we want to use this in this class?\n\n>\n> +class ImageFormats\n> +{\n> +public:\n> +\tImageFormats();\n> +\n> +\tint addFormat(unsigned int format, const std::vector<SizeRange> &sizes);\n> +\n> +\tstd::vector<unsigned int> formats() const;\n> +\tstd::vector<SizeRange> sizes(unsigned int format) const;\n\nI would return a const & here\n\n> +\n> +\tbool isEmpty() const;\n> +\tconst std::map<unsigned int, std::vector<SizeRange>> &data() const;\n\nand group the three data accessors together. Maybe you can move\nisEmpty() up as the first method?\n\nThanks\n   j\n\n> +\n> +private:\n> +\tstd::map<unsigned int, std::vector<SizeRange>> data_;\n> +};\n> +\n>  } /* namespace libcamera */\n>\n>  #endif /* __LIBCAMERA_FORMATS_H__ */\n> --\n> 2.21.0\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 relay9-d.mail.gandi.net (relay9-d.mail.gandi.net\n\t[217.70.183.199])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1CF6E61EC4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Jun 2019 17:14:21 +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 relay9-d.mail.gandi.net (Postfix) with ESMTPSA id A0008FF810;\n\tThu, 13 Jun 2019 15:14:20 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","Date":"Thu, 13 Jun 2019 17:15:33 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190613151533.h5z46sg5hqx4aexv@uno.localdomain>","References":"<20190612004359.15772-1-niklas.soderlund@ragnatech.se>\n\t<20190612004359.15772-6-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"z7hyx226fie3elri\"","Content-Disposition":"inline","In-Reply-To":"<20190612004359.15772-6-niklas.soderlund@ragnatech.se>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH v2 05/16] libcamera: formats: Add\n\tImageFormats","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, 13 Jun 2019 15:14:21 -0000"}},{"id":1890,"web_url":"https://patchwork.libcamera.org/comment/1890/","msgid":"<20190613152201.GC20196@bigcity.dyn.berto.se>","date":"2019-06-13T15:22:01","subject":"Re: [libcamera-devel] [PATCH v2 05/16] libcamera: formats: Add\n\tImageFormats","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Jacopo,\n\nThanks for your feedback.\n\nOn 2019-06-13 17:15:33 +0200, Jacopo Mondi wrote:\n> Hi Niklas,\n> \n> On Wed, Jun 12, 2019 at 02:43:48AM +0200, Niklas Söderlund wrote:\n> > Add a new class to hold format information for v4l2 devices and\n> > subdevices. The object describes the relationship between either pixel\n> > formats (v4l2 devices) or media bus codes (v4l2 subdevice) and a list of\n> > image sizes which can be produced with that format.\n> >\n> > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> > ---\n> >  src/libcamera/formats.cpp       | 83 +++++++++++++++++++++++++++++++++\n> >  src/libcamera/include/formats.h | 17 +++++++\n> >  2 files changed, 100 insertions(+)\n> >\n> > diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp\n> > index 56f4ddb51ffad4d3..ab4bae0a5928d9ba 100644\n> > --- a/src/libcamera/formats.cpp\n> > +++ b/src/libcamera/formats.cpp\n> > @@ -24,4 +24,87 @@ namespace libcamera {\n> >   * resolutions represented by SizeRange items.\n> >   */\n> >\n> > +/**\n> > + * \\class ImageFormats\n> \n> I'm a bit undecided here... This represents a V4L2 device or subdevice\n> format, and I would keep the \"ImageFormats\" name for the application\n> facing image format, which might end up being different than the V4L2\n> defined one.\n\nI'm open to renaming it, I'm bad at naming so I picked ImageFormats as \nyou suggested it in your last review ;-P I wait for what others think \nand do the popular thing.\n\n> \n> Now that we have a V4L2Device I think V4L2Format might be considered\n> as an alternative name..\n> \n> > + * \\brief Describe V4L2Device and V4L2SubDevice image formats\n> > + *\n> > + * The class describes information about image formats and supported sizes. If\n> > + * the ImageFormat describe a V4L2Device the formats described are pixel formats\n> > + * while if it describes a V4L2SubDevice the formats are media bus codes.\n> \n> I would:\n>  The class describes information about image formats and supported sizes. If\n>  the ImageFormat describe a V4L2Device the image formats are described\n>  with a fourcc pixel format code, while if it describes a V4L2SubDevice\n>  the formats are described with media bus codes, both defined by the\n>  V4L2 specification.\n> \n> Is fine if you keep yours...\n> \n> > + */\n> > +\n> > +ImageFormats::ImageFormats()\n> > +{\n> > +}\n> \n> Do you need this? The compiler generates a default contructor for\n> you..\n> \n> > +\n> > +/**\n> > + * \\brief Add a format and sizes to the description\n> > + * \\param[in] format Pixel format or media bus code to describe\n> > + * \\param[in] sizes List of supported sizes for the format\n> > + *\n> > + * \\return 0 on success or a negative error code otherwise\n> > + * \\retval -EBUSY The format is already described\n> > + */\n> > +int ImageFormats::addFormat(unsigned int format, const std::vector<SizeRange> &sizes)\n> > +{\n> > +\tif (data_.find(format) != data_.end())\n> > +\t\treturn -EBUSY;\n> > +\n> > +\tdata_[format] = sizes;\n> > +\n> > +\treturn 0;\n> > +}\n> > +\n> > +/**\n> > + * \\brief Retrieve a list of all supported image formats\n> > + * \\return List of pixel formats or media bus codes\n> > + */\n> > +std::vector<unsigned int> ImageFormats::formats() const\n> > +{\n> > +\tstd::vector<unsigned int> formats;\n> > +\tformats.reserve(data_.size());\n> > +\n> > +\tfor (auto const &it : data_)\n> > +\t\tformats.push_back(it.first);\n> > +\n> > +\treturn formats;\n> > +}\n> > +\n> > +/**\n> > + * \\brief Retrieve all sizes for a specific format\n> > + * \\param[in] format A pixelformat or mbus code\n> > + *\n> > + * Retrieve all SizeRanges for a specific format. For V4L2Device \\a format is a\n> > + * pixel format while for a V4L2Subdevice \\a format is a media bus code.\n> > + *\n> > + * \\return he list of image sizes produced using \\a format, or an empty list if\n> > + * format is not supported\n> > + */\n> > +std::vector<SizeRange> ImageFormats::sizes(unsigned int format) const\n> > +{\n> > +\tauto const &it = data_.find(format);\n> > +\tif (it == data_.end())\n> > +\t\treturn {};\n> > +\n> > +\treturn it->second;\n> > +}\n> > +\n> > +/**\n> > + * \\brief Check if the list of devices supported formats is empty\n> > + * \\return True if the list of supported formats is empty\n> > + */\n> > +bool ImageFormats::isEmpty() const\n> > +{\n> > +\treturn data_.empty();\n> > +}\n> > +\n> > +/**\n> > + * \\brief Retrieve the map that associates formats to image sizes\n> > + * \\return Map that associates formats to image sizes\n> > + */\n> > +const std::map<unsigned int, std::vector<SizeRange>> &ImageFormats::data() const\n> > +{\n> > +\treturn data_;\n> > +}\n> > +\n> >  } /* namespace libcamera */\n> > diff --git a/src/libcamera/include/formats.h b/src/libcamera/include/formats.h\n> > index a73772b1eda068b4..a31aa42bcb4742ac 100644\n> > --- a/src/libcamera/include/formats.h\n> > +++ b/src/libcamera/include/formats.h\n> > @@ -17,6 +17,23 @@ namespace libcamera {\n> >\n> >  typedef std::map<unsigned int, std::vector<SizeRange>> FormatEnum;\n> \n> Do we want to use this in this class?\n\nI don't want to use it and it's removed in a later patch in this series.\n\n> \n> >\n> > +class ImageFormats\n> > +{\n> > +public:\n> > +\tImageFormats();\n> > +\n> > +\tint addFormat(unsigned int format, const std::vector<SizeRange> &sizes);\n> > +\n> > +\tstd::vector<unsigned int> formats() const;\n> > +\tstd::vector<SizeRange> sizes(unsigned int format) const;\n> \n> I would return a const & here\n\nI would to if it where possible, as we need to generate the vector from \nthe map we can't return a reference. Laurent suggested to compute and \ncache the vectors which would allow this. I'm not against doing that but \nit could be done at a later time as we optimize.\n\n> \n> > +\n> > +\tbool isEmpty() const;\n> > +\tconst std::map<unsigned int, std::vector<SizeRange>> &data() const;\n> \n> and group the three data accessors together. Maybe you can move\n> isEmpty() up as the first method?\n\nSure, I have no preference.\n\n> \n> Thanks\n>    j\n> \n> > +\n> > +private:\n> > +\tstd::map<unsigned int, std::vector<SizeRange>> data_;\n> > +};\n> > +\n> >  } /* namespace libcamera */\n> >\n> >  #endif /* __LIBCAMERA_FORMATS_H__ */\n> > --\n> > 2.21.0\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-lj1-x242.google.com (mail-lj1-x242.google.com\n\t[IPv6:2a00:1450:4864:20::242])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D94E36369A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Jun 2019 17:22:03 +0200 (CEST)","by mail-lj1-x242.google.com with SMTP id a21so18940630ljh.7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Jun 2019 08:22:03 -0700 (PDT)","from localhost (89-233-230-99.cust.bredband2.com. [89.233.230.99])\n\tby smtp.gmail.com with ESMTPSA id\n\tp15sm43019lji.80.2019.06.13.08.22.02\n\t(version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256);\n\tThu, 13 Jun 2019 08:22:02 -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=O6OQRe6HrudhyLKFCIfyaIJ6fSwIoAolGyaatefZvbc=;\n\tb=PcHU0dcrnp3BVCrwIohVYHQBvZOk8Emt1MKaDu7wjUaQAjRIz210CueUHN4A38zj+4\n\t+7nKv4H2sReUvAOdb18QRmsuRuhwLE94yrPt6EeWdHXat7igK9t7FvpWAFaRmqKiPCsC\n\txU/98GURdodQpLB7Rnh7Wy4FqI9iygxL9yOyFUEj7ZckU0YzX65FNkMuTXvfqbv7B/XA\n\tzZYpuOuQ0Rnk613Sxza0axSdTYOZjus5UY6I11bOBFU92FK+qwiBDkXoAts10JfLJFHQ\n\tNr7Yjfc4EyT1Kzc3tH2SQ0tac2CSBps589fGz2QnPGKBxL5+0VntZQj42ZdtJykljDrM\n\tG7+w==","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=O6OQRe6HrudhyLKFCIfyaIJ6fSwIoAolGyaatefZvbc=;\n\tb=UEUeqJ8MYZ++RbSYLx0l+OKWW/hQx0QvSvWAQ7l3TLXGP5ZoWw44qwWiFKhF65CZD3\n\t5jMMbIzyNOCR0IYRVkTBoymE+2/KdPieIvpNIxdk6Cl3axOv7j3xGj+JPxhfwwwj/gzw\n\t/7HIFKRTwVOoP2MX/ZhNP6DUu/TZaXKCS6f3E2B6D/0V6xqoYtHqBZewwLjSqq3KbP0b\n\t7CjOCTUl+Ga/tbgKs340Y45DItOwA5HZIWAnPBl7ig6w5Dr+MegmjwIMD5HjmIVjQaBo\n\tGHGv5/XW9UNVT3RhJJOhPG7AoHKXbYmANO3EezpY9SAd5WM9GUc48AYaDkBdGdLKYAkE\n\t1ZmQ==","X-Gm-Message-State":"APjAAAXqNnf0zbgygBBp57AyVZ8aR3pvgxxFHvTgij0PX0P9qr9ABFmV\n\txaWn9RLZTBiz/fkxf8DXLqhqAKBhtEA=","X-Google-Smtp-Source":"APXvYqzV3YhJjTL7sdPNSmafFieP8NihDP6yvknRDUnHZ8SMOVzwx6qytfpNItH98Q33CWRcYVi2Og==","X-Received":"by 2002:a2e:730d:: with SMTP id o13mr4742007ljc.81.1560439322866;\n\tThu, 13 Jun 2019 08:22:02 -0700 (PDT)","Date":"Thu, 13 Jun 2019 17:22:01 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190613152201.GC20196@bigcity.dyn.berto.se>","References":"<20190612004359.15772-1-niklas.soderlund@ragnatech.se>\n\t<20190612004359.15772-6-niklas.soderlund@ragnatech.se>\n\t<20190613151533.h5z46sg5hqx4aexv@uno.localdomain>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190613151533.h5z46sg5hqx4aexv@uno.localdomain>","User-Agent":"Mutt/1.12.0 (2019-05-25)","Subject":"Re: [libcamera-devel] [PATCH v2 05/16] libcamera: formats: Add\n\tImageFormats","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, 13 Jun 2019 15:22:04 -0000"}}]