summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2019-06-28 10:45:55 +0200
committerJacopo Mondi <jacopo@jmondi.org>2019-07-04 11:17:29 +0200
commit79e03cdf40f9ef97751b9a9aa1bcb6d3df6234f2 (patch)
treebf20fdb5f4455ed8dfbbce6e06af818215ba373a /src
parent851bf31df898b1569571244ce2094b59a9efcb7f (diff)
libcamera: v4l2_videodevice: Re-group operations
Group together operations to enumerate formats and operations to handle memory handling, alternating public and private operations but respecting the ordering within each group. Cosmetic change only. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/include/v4l2_videodevice.h6
-rw-r--r--src/libcamera/v4l2_videodevice.cpp170
2 files changed, 88 insertions, 88 deletions
diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h
index 734b34f1..b92df882 100644
--- a/src/libcamera/include/v4l2_videodevice.h
+++ b/src/libcamera/include/v4l2_videodevice.h
@@ -160,13 +160,13 @@ private:
int getFormatSingleplane(V4L2DeviceFormat *format);
int setFormatSingleplane(V4L2DeviceFormat *format);
+ std::vector<unsigned int> enumPixelformats();
+ std::vector<SizeRange> enumSizes(unsigned int pixelFormat);
+
int requestBuffers(unsigned int count);
int createPlane(Buffer *buffer, unsigned int plane,
unsigned int length);
- std::vector<unsigned int> enumPixelformats();
- std::vector<SizeRange> enumSizes(unsigned int pixelFormat);
-
Buffer *dequeueBuffer();
void bufferAvailable(EventNotifier *notifier);
diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index 12af3bd0..2d1e87a7 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -627,6 +627,91 @@ ImageFormats V4L2VideoDevice::formats()
return formats;
}
+std::vector<unsigned int> V4L2VideoDevice::enumPixelformats()
+{
+ std::vector<unsigned int> formats;
+ int ret;
+
+ for (unsigned int index = 0; ; index++) {
+ struct v4l2_fmtdesc pixelformatEnum = {};
+ pixelformatEnum.index = index;
+ pixelformatEnum.type = bufferType_;
+
+ ret = ioctl(VIDIOC_ENUM_FMT, &pixelformatEnum);
+ if (ret)
+ break;
+
+ formats.push_back(pixelformatEnum.pixelformat);
+ }
+
+ if (ret && ret != -EINVAL) {
+ LOG(V4L2, Error)
+ << "Unable to enumerate pixel formats: "
+ << strerror(-ret);
+ return {};
+ }
+
+ return formats;
+}
+
+std::vector<SizeRange> V4L2VideoDevice::enumSizes(unsigned int pixelFormat)
+{
+ std::vector<SizeRange> sizes;
+ int ret;
+
+ for (unsigned int index = 0;; index++) {
+ struct v4l2_frmsizeenum frameSize = {};
+ frameSize.index = index;
+ frameSize.pixel_format = pixelFormat;
+
+ ret = ioctl(VIDIOC_ENUM_FRAMESIZES, &frameSize);
+ if (ret)
+ break;
+
+ if (index != 0 &&
+ frameSize.type != V4L2_FRMSIZE_TYPE_DISCRETE) {
+ LOG(V4L2, Error)
+ << "Non-zero index for non discrete type";
+ return {};
+ }
+
+ switch (frameSize.type) {
+ case V4L2_FRMSIZE_TYPE_DISCRETE:
+ sizes.emplace_back(frameSize.discrete.width,
+ frameSize.discrete.height);
+ break;
+ case V4L2_FRMSIZE_TYPE_CONTINUOUS:
+ sizes.emplace_back(frameSize.stepwise.min_width,
+ frameSize.stepwise.min_height,
+ frameSize.stepwise.max_width,
+ frameSize.stepwise.max_height);
+ break;
+ case V4L2_FRMSIZE_TYPE_STEPWISE:
+ sizes.emplace_back(frameSize.stepwise.min_width,
+ frameSize.stepwise.min_height,
+ frameSize.stepwise.max_width,
+ frameSize.stepwise.max_height,
+ frameSize.stepwise.step_width,
+ frameSize.stepwise.step_height);
+ break;
+ default:
+ LOG(V4L2, Error)
+ << "Unknown VIDIOC_ENUM_FRAMESIZES type "
+ << frameSize.type;
+ return {};
+ }
+ }
+
+ if (ret && ret != -EINVAL) {
+ LOG(V4L2, Error)
+ << "Unable to enumerate frame sizes: "
+ << strerror(-ret);
+ return {};
+ }
+
+ return sizes;
+}
+
int V4L2VideoDevice::requestBuffers(unsigned int count)
{
struct v4l2_requestbuffers rb = {};
@@ -754,91 +839,6 @@ int V4L2VideoDevice::createPlane(Buffer *buffer, unsigned int planeIndex,
return 0;
}
-std::vector<unsigned int> V4L2VideoDevice::enumPixelformats()
-{
- std::vector<unsigned int> formats;
- int ret;
-
- for (unsigned int index = 0; ; index++) {
- struct v4l2_fmtdesc pixelformatEnum = {};
- pixelformatEnum.index = index;
- pixelformatEnum.type = bufferType_;
-
- ret = ioctl(VIDIOC_ENUM_FMT, &pixelformatEnum);
- if (ret)
- break;
-
- formats.push_back(pixelformatEnum.pixelformat);
- }
-
- if (ret && ret != -EINVAL) {
- LOG(V4L2, Error)
- << "Unable to enumerate pixel formats: "
- << strerror(-ret);
- return {};
- }
-
- return formats;
-}
-
-std::vector<SizeRange> V4L2VideoDevice::enumSizes(unsigned int pixelFormat)
-{
- std::vector<SizeRange> sizes;
- int ret;
-
- for (unsigned int index = 0;; index++) {
- struct v4l2_frmsizeenum frameSize = {};
- frameSize.index = index;
- frameSize.pixel_format = pixelFormat;
-
- ret = ioctl(VIDIOC_ENUM_FRAMESIZES, &frameSize);
- if (ret)
- break;
-
- if (index != 0 &&
- frameSize.type != V4L2_FRMSIZE_TYPE_DISCRETE) {
- LOG(V4L2, Error)
- << "Non-zero index for non discrete type";
- return {};
- }
-
- switch (frameSize.type) {
- case V4L2_FRMSIZE_TYPE_DISCRETE:
- sizes.emplace_back(frameSize.discrete.width,
- frameSize.discrete.height);
- break;
- case V4L2_FRMSIZE_TYPE_CONTINUOUS:
- sizes.emplace_back(frameSize.stepwise.min_width,
- frameSize.stepwise.min_height,
- frameSize.stepwise.max_width,
- frameSize.stepwise.max_height);
- break;
- case V4L2_FRMSIZE_TYPE_STEPWISE:
- sizes.emplace_back(frameSize.stepwise.min_width,
- frameSize.stepwise.min_height,
- frameSize.stepwise.max_width,
- frameSize.stepwise.max_height,
- frameSize.stepwise.step_width,
- frameSize.stepwise.step_height);
- break;
- default:
- LOG(V4L2, Error)
- << "Unknown VIDIOC_ENUM_FRAMESIZES type "
- << frameSize.type;
- return {};
- }
- }
-
- if (ret && ret != -EINVAL) {
- LOG(V4L2, Error)
- << "Unable to enumerate frame sizes: "
- << strerror(-ret);
- return {};
- }
-
- return sizes;
-}
-
/**
* \brief Import the externally allocated \a pool of buffers
* \param[in] pool BufferPool of buffers to import