[libcamera-devel] [PATCH v2 07/16] libcamera: v4l2_subdevice: Rework enumPadSizes()
Jacopo Mondi
jacopo at jmondi.org
Thu Jun 13 17:41:40 CEST 2019
Hi Niklas!
nice!
Reviewed-by: Jacopo Mondi <jacopo at jmondi.org>
Thanks
j
On Wed, Jun 12, 2019 at 02:43:50AM +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>
> ---
> 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);
> +
> + 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);
> -
> - 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,
> --
> 2.21.0
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel at lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20190613/cd3de031/attachment.sig>
More information about the libcamera-devel
mailing list