summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2019-05-25 00:54:17 +0200
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2019-06-19 02:47:06 +0200
commitbe78ffbe9abbd0fa6aab7a76c4a56d655d7b7548 (patch)
tree2436290d046b696f532a684e0681189b6dab4fdf
parent3e51cc30bf9d71e06b0fdc252c5aed70047429cb (diff)
libcamera: v4l2_subdevice: Rework enumPadSizes()
Align the enumPadSizes() interface and implementation with that of enumPadCodes(). There is no functional change. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rw-r--r--src/libcamera/include/v4l2_subdevice.h4
-rw-r--r--src/libcamera/v4l2_subdevice.cpp38
2 files changed, 22 insertions, 20 deletions
diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h
index e714e257..c6fdf417 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 99e202fa..3296bc01 100644
--- a/src/libcamera/v4l2_subdevice.cpp
+++ b/src/libcamera/v4l2_subdevice.cpp
@@ -209,10 +209,14 @@ 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 +339,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,
- sizeEnum.max_width, sizeEnum.max_height);
-
- sizeEnum.index++;
+ sizes.emplace_back(sizeEnum.min_width, sizeEnum.min_height,
+ sizeEnum.max_width, sizeEnum.max_height);
}
if (ret && (errno != EINVAL && errno != ENOTTY)) {
@@ -361,12 +365,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,