summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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