[{"id":1712,"web_url":"https://patchwork.libcamera.org/comment/1712/","msgid":"<20190527190530.pnhjwmmlukmi2b6o@uno.localdomain>","date":"2019-05-27T19:05:30","subject":"Re: [libcamera-devel] [PATCH 07/17] libcamera: v4l2_subdevice:\n\tRework enumPadSizes()","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Niklas,\n\nOn Mon, May 27, 2019 at 02:15:33AM +0200, Niklas Söderlund wrote:\n> Align the enumPadSizes() interface and implementation with that of\n> enumPadCodes(). There is no functional change.\n>\n\nI'm afraid there are a few :)\n\n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/libcamera/include/v4l2_subdevice.h |  4 +--\n>  src/libcamera/v4l2_subdevice.cpp       | 36 ++++++++++++--------------\n>  2 files changed, 19 insertions(+), 21 deletions(-)\n>\n> diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h\n> index e714e2575022c04d..c6fdf417b43c0423 100644\n> --- a/src/libcamera/include/v4l2_subdevice.h\n> +++ b/src/libcamera/include/v4l2_subdevice.h\n> @@ -58,8 +58,8 @@ protected:\n>\n>  private:\n>  \tstd::vector<unsigned int> enumPadCodes(unsigned int pad);\n> -\tint enumPadSizes(unsigned int pad, unsigned int code,\n> -\t\t\t std::vector<SizeRange> *size);\n> +\tstd::vector<SizeRange> enumPadSizes(unsigned int pad,\n> +\t\t\t\t\t    unsigned int code);\n>\n>  \tint setSelection(unsigned int pad, unsigned int target,\n>  \t\t\t Rectangle *rect);\n> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> index 51b0ffaafb3e668e..8720013600ddb95f 100644\n> --- a/src/libcamera/v4l2_subdevice.cpp\n> +++ b/src/libcamera/v4l2_subdevice.cpp\n> @@ -210,8 +210,7 @@ FormatEnum V4L2Subdevice::formats(unsigned int pad)\n>  \t}\n>\n>  \tfor (unsigned int code : enumPadCodes(pad))\n> -\t\tif (enumPadSizes(pad, code, &formatMap[code]))\n> -\t\t\treturn {};\n> +\t\tformatMap[code] = enumPadSizes(pad, code);\n>\n>  \treturn formatMap;\n>  }\n> @@ -336,38 +335,37 @@ std::vector<unsigned int> V4L2Subdevice::enumPadCodes(unsigned int pad)\n>  \treturn codes;\n>  }\n>\n> -int V4L2Subdevice::enumPadSizes(unsigned int pad,unsigned int code,\n> -\t\t\t\tstd::vector<SizeRange> *sizes)\n> +std::vector<SizeRange> V4L2Subdevice::enumPadSizes(unsigned int pad,\n> +\t\t\t\t\t\t   unsigned int code)\n\nOne of the reason I returned an int and accepted the vector as\nparameter, was to be able to propagate up any error returned by\nENUM_FRAME_SIZES which is here ignored instead (not true, a message is\nprinted out) leaving the format map with an entry with an empty size\nlist.\n\nIf you're confortable with not propagating the error up, which I agree\nmight not be that -strictly- vital, at least you should check if the\nreturned vector is empty and not add the format code to the map. This\nmeans you should store the size list in a local variable first, then\ncopy it in the map, giving up  any return value optimization speed\nup. This was the reason this code returned an int.\n\nThanks\n   j\n\n>  {\n> -\tstruct v4l2_subdev_frame_size_enum sizeEnum = {};\n> +\tstd::vector<SizeRange> sizes;\n>  \tint ret;\n>\n> -\tsizeEnum.index = 0;\n> -\tsizeEnum.pad = pad;\n> -\tsizeEnum.code = code;\n> -\tsizeEnum.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n> -\twhile (true) {\n> +\tfor (unsigned int index = 0;; index++) {\n> +\t\tstruct v4l2_subdev_frame_size_enum sizeEnum = {\n> +\t\t\t.index = index,\n> +\t\t\t.pad = pad,\n> +\t\t\t.code = code,\n> +\t\t\t.which = V4L2_SUBDEV_FORMAT_ACTIVE,\n> +\t\t};\n> +\n>  \t\tret = ioctl(fd_, VIDIOC_SUBDEV_ENUM_FRAME_SIZE, &sizeEnum);\n>  \t\tif (ret)\n>  \t\t\tbreak;\n>\n> -\t\tsizes->emplace_back(sizeEnum.min_width, sizeEnum.min_height,\n> +\t\tsizes.emplace_back(sizeEnum.min_width, sizeEnum.min_height,\n>  \t\t\t\t    sizeEnum.max_width, sizeEnum.max_height);\n> -\n> -\t\tsizeEnum.index++;\n>  \t}\n>\n>  \tif (ret && (errno != EINVAL && errno != ENOTTY)) {\n> -\t\tret = -errno;\n> +\t\tret = errno;\n>  \t\tLOG(V4L2Subdev, Error)\n>  \t\t\t<< \"Unable to enumerate sizes on pad \" << pad\n> -\t\t\t<< \": \" << strerror(-ret);\n> -\t\tsizes->clear();\n> -\n> -\t\treturn ret;\n> +\t\t\t<< \": \" << strerror(ret);\n> +\t\treturn {};\n>  \t}\n>\n> -\treturn 0;\n> +\treturn sizes;\n>  }\n>\n>  int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,\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 relay7-d.mail.gandi.net (relay7-d.mail.gandi.net\n\t[217.70.183.200])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B924260E47\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 May 2019 21:04:24 +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 relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 4B53C20004;\n\tMon, 27 May 2019 19:04:22 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","Date":"Mon, 27 May 2019 21:05:30 +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":"<20190527190530.pnhjwmmlukmi2b6o@uno.localdomain>","References":"<20190527001543.13593-1-niklas.soderlund@ragnatech.se>\n\t<20190527001543.13593-8-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"3xx4ckkgnkbugeal\"","Content-Disposition":"inline","In-Reply-To":"<20190527001543.13593-8-niklas.soderlund@ragnatech.se>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH 07/17] libcamera: v4l2_subdevice:\n\tRework enumPadSizes()","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, 27 May 2019 19:04:24 -0000"}},{"id":1804,"web_url":"https://patchwork.libcamera.org/comment/1804/","msgid":"<20190609124311.GG4778@pendragon.ideasonboard.com>","date":"2019-06-09T12:43:11","subject":"Re: [libcamera-devel] [PATCH 07/17] libcamera: v4l2_subdevice:\n\tRework enumPadSizes()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nThank you for the patch.\n\nOn Mon, May 27, 2019 at 09:05:30PM +0200, Jacopo Mondi wrote:\n> On Mon, May 27, 2019 at 02:15:33AM +0200, Niklas Söderlund wrote:\n> > Align the enumPadSizes() interface and implementation with that of\n> > enumPadCodes(). There is no functional change.\n> \n> I'm afraid there are a few :)\n> \n> > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> > ---\n> >  src/libcamera/include/v4l2_subdevice.h |  4 +--\n> >  src/libcamera/v4l2_subdevice.cpp       | 36 ++++++++++++--------------\n> >  2 files changed, 19 insertions(+), 21 deletions(-)\n> >\n> > diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h\n> > index e714e2575022c04d..c6fdf417b43c0423 100644\n> > --- a/src/libcamera/include/v4l2_subdevice.h\n> > +++ b/src/libcamera/include/v4l2_subdevice.h\n> > @@ -58,8 +58,8 @@ protected:\n> >\n> >  private:\n> >  \tstd::vector<unsigned int> enumPadCodes(unsigned int pad);\n> > -\tint enumPadSizes(unsigned int pad, unsigned int code,\n> > -\t\t\t std::vector<SizeRange> *size);\n> > +\tstd::vector<SizeRange> enumPadSizes(unsigned int pad,\n> > +\t\t\t\t\t    unsigned int code);\n> >\n> >  \tint setSelection(unsigned int pad, unsigned int target,\n> >  \t\t\t Rectangle *rect);\n> > diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> > index 51b0ffaafb3e668e..8720013600ddb95f 100644\n> > --- a/src/libcamera/v4l2_subdevice.cpp\n> > +++ b/src/libcamera/v4l2_subdevice.cpp\n> > @@ -210,8 +210,7 @@ FormatEnum V4L2Subdevice::formats(unsigned int pad)\n> >  \t}\n> >\n> >  \tfor (unsigned int code : enumPadCodes(pad))\n> > -\t\tif (enumPadSizes(pad, code, &formatMap[code]))\n> > -\t\t\treturn {};\n> > +\t\tformatMap[code] = enumPadSizes(pad, code);\n> >\n> >  \treturn formatMap;\n> >  }\n> > @@ -336,38 +335,37 @@ std::vector<unsigned int> V4L2Subdevice::enumPadCodes(unsigned int pad)\n> >  \treturn codes;\n> >  }\n> >\n> > -int V4L2Subdevice::enumPadSizes(unsigned int pad,unsigned int code,\n> > -\t\t\t\tstd::vector<SizeRange> *sizes)\n> > +std::vector<SizeRange> V4L2Subdevice::enumPadSizes(unsigned int pad,\n> > +\t\t\t\t\t\t   unsigned int code)\n> \n> One of the reason I returned an int and accepted the vector as\n> parameter, was to be able to propagate up any error returned by\n> ENUM_FRAME_SIZES which is here ignored instead (not true, a message is\n> printed out) leaving the format map with an entry with an empty size\n> list.\n> \n> If you're confortable with not propagating the error up, which I agree\n> might not be that -strictly- vital, at least you should check if the\n> returned vector is empty and not add the format code to the map. This\n> means you should store the size list in a local variable first, then\n> copy it in the map, giving up  any return value optimization speed\n> up. This was the reason this code returned an int.\n\nI agree, I think we should fail if an enumeration error occurs. If we\nsilently continue we'll end up with inconsistent behaviours and possibly\nhard to reproduce and debug errors.\n\n> >  {\n> > -\tstruct v4l2_subdev_frame_size_enum sizeEnum = {};\n> > +\tstd::vector<SizeRange> sizes;\n> >  \tint ret;\n> >\n> > -\tsizeEnum.index = 0;\n> > -\tsizeEnum.pad = pad;\n> > -\tsizeEnum.code = code;\n> > -\tsizeEnum.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n> > -\twhile (true) {\n> > +\tfor (unsigned int index = 0;; index++) {\n> > +\t\tstruct v4l2_subdev_frame_size_enum sizeEnum = {\n> > +\t\t\t.index = index,\n> > +\t\t\t.pad = pad,\n> > +\t\t\t.code = code,\n> > +\t\t\t.which = V4L2_SUBDEV_FORMAT_ACTIVE,\n> > +\t\t};\n> > +\n> >  \t\tret = ioctl(fd_, VIDIOC_SUBDEV_ENUM_FRAME_SIZE, &sizeEnum);\n> >  \t\tif (ret)\n> >  \t\t\tbreak;\n> >\n> > -\t\tsizes->emplace_back(sizeEnum.min_width, sizeEnum.min_height,\n> > +\t\tsizes.emplace_back(sizeEnum.min_width, sizeEnum.min_height,\n> >  \t\t\t\t    sizeEnum.max_width, sizeEnum.max_height);\n> > -\n> > -\t\tsizeEnum.index++;\n> >  \t}\n> >\n> >  \tif (ret && (errno != EINVAL && errno != ENOTTY)) {\n> > -\t\tret = -errno;\n> > +\t\tret = errno;\n> >  \t\tLOG(V4L2Subdev, Error)\n> >  \t\t\t<< \"Unable to enumerate sizes on pad \" << pad\n> > -\t\t\t<< \": \" << strerror(-ret);\n> > -\t\tsizes->clear();\n> > -\n> > -\t\treturn ret;\n> > +\t\t\t<< \": \" << strerror(ret);\n> > +\t\treturn {};\n> >  \t}\n> >\n> > -\treturn 0;\n> > +\treturn sizes;\n> >  }\n> >\n> >  int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,","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 5574F61F4F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  9 Jun 2019 14:43:26 +0200 (CEST)","from pendragon.ideasonboard.com (unknown\n\t[IPv6:2a02:a03f:44f0:8500:ca05:8177:199c:fed4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C1F035D;\n\tSun,  9 Jun 2019 14:43:25 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1560084205;\n\tbh=kVW61vmtIzOE12kSdhUHdVeoVDMMlX13Hotffs6MMF0=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=O3urIPUdmctB6ya10vJf4Zz9TcRinRdLiwasnmHenTc3Gl5zGAcppBGEbkgHAhaC0\n\tBjPtMJTNbgfLSkx/P7SfDzkKbv9O6tY7FGlwBgIGaXHRpj6IKxWlF0O3PNJptHjbgL\n\tat17mhLSKU0KSJ/JPQDOHT8uFZCYjBccXd/8J4Kg=","Date":"Sun, 9 Jun 2019 15:43:11 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"Jacopo Mondi <jacopo@jmondi.org>, libcamera-devel@lists.libcamera.org","Message-ID":"<20190609124311.GG4778@pendragon.ideasonboard.com>","References":"<20190527001543.13593-1-niklas.soderlund@ragnatech.se>\n\t<20190527001543.13593-8-niklas.soderlund@ragnatech.se>\n\t<20190527190530.pnhjwmmlukmi2b6o@uno.localdomain>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190527190530.pnhjwmmlukmi2b6o@uno.localdomain>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 07/17] libcamera: v4l2_subdevice:\n\tRework enumPadSizes()","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":"Sun, 09 Jun 2019 12:43:26 -0000"}}]