[libcamera-devel] [PATCH v3 07/16] libcamera: v4l2_subdevice: Rework enumPadSizes()
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Wed Jun 19 00:53:37 CEST 2019
Hi Niklas,
Thank you for the patch.
On Sun, Jun 16, 2019 at 03:33:53PM +0200, Niklas Söderlund wrote:
> Align the enumPadSizes() interface and implementation with that of
> enumPadCodes(). There is no functional change.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
> Reviewed-by: Jacopo Mondi <jacopo at jmondi.org>
> ---
> src/libcamera/include/v4l2_subdevice.h | 4 +--
> src/libcamera/v4l2_subdevice.cpp | 37 ++++++++++++++------------
> 2 files changed, 22 insertions(+), 19 deletions(-)
>
> diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h
> index e714e2575022c04d..c6fdf417b43c0423 100644
> --- a/src/libcamera/include/v4l2_subdevice.h
> +++ b/src/libcamera/include/v4l2_subdevice.h
> @@ -58,8 +58,8 @@ protected:
>
> private:
> std::vector<unsigned int> enumPadCodes(unsigned int pad);
> - int enumPadSizes(unsigned int pad, unsigned int code,
> - std::vector<SizeRange> *size);
> + std::vector<SizeRange> enumPadSizes(unsigned int pad,
> + unsigned int code);
>
> int setSelection(unsigned int pad, unsigned int target,
> Rectangle *rect);
> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
> index 99e202fa264af5a6..35052b4aa45d3e42 100644
> --- a/src/libcamera/v4l2_subdevice.cpp
> +++ b/src/libcamera/v4l2_subdevice.cpp
> @@ -209,10 +209,15 @@ FormatEnum V4L2Subdevice::formats(unsigned int pad)
> return {};
> }
>
> - for (unsigned int code : enumPadCodes(pad))
> - if (enumPadSizes(pad, code, &formatMap[code]))
> + for (unsigned int code : enumPadCodes(pad)) {
> + std::vector<SizeRange> sizes = enumPadSizes(pad, code);
> +
You can remove this blank line.
> + if (sizes.empty())
> return {};
>
> + formatMap[code] = sizes;
> + }
> +
> return formatMap;
> }
>
> @@ -335,25 +340,25 @@ std::vector<unsigned int> V4L2Subdevice::enumPadCodes(unsigned int pad)
> return codes;
> }
>
> -int V4L2Subdevice::enumPadSizes(unsigned int pad,unsigned int code,
> - std::vector<SizeRange> *sizes)
> +std::vector<SizeRange> V4L2Subdevice::enumPadSizes(unsigned int pad,
> + unsigned int code)
> {
> - struct v4l2_subdev_frame_size_enum sizeEnum = {};
> + std::vector<SizeRange> sizes;
> int ret;
>
> - sizeEnum.index = 0;
> - sizeEnum.pad = pad;
> - sizeEnum.code = code;
> - sizeEnum.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> - while (true) {
> + for (unsigned int index = 0;; index++) {
> + struct v4l2_subdev_frame_size_enum sizeEnum = {};
> + sizeEnum.index = index;
> + sizeEnum.pad = pad;
> + sizeEnum.code = code;
> + sizeEnum.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> +
> ret = ioctl(fd_, VIDIOC_SUBDEV_ENUM_FRAME_SIZE, &sizeEnum);
> if (ret)
> break;
>
> - sizes->emplace_back(sizeEnum.min_width, sizeEnum.min_height,
> + sizes.emplace_back(sizeEnum.min_width, sizeEnum.min_height,
> sizeEnum.max_width, sizeEnum.max_height);
Wrong indentation.
With these small issues address,
Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> -
> - sizeEnum.index++;
> }
>
> if (ret && (errno != EINVAL && errno != ENOTTY)) {
> @@ -361,12 +366,10 @@ int V4L2Subdevice::enumPadSizes(unsigned int pad,unsigned int code,
> LOG(V4L2Subdev, Error)
> << "Unable to enumerate sizes on pad " << pad
> << ": " << strerror(-ret);
> - sizes->clear();
> -
> - return ret;
> + return {};
> }
>
> - return 0;
> + return sizes;
> }
>
> int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list