summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2022-07-29 12:37:29 +0200
committerJacopo Mondi <jacopo@jmondi.org>2022-08-03 15:07:20 +0200
commitb7ca378b65e8ba936bf3c5631e16534a3376aec9 (patch)
tree81d7112608ebb1eef8e05f61406c0617e0f30954
parent45736468c8395de02f004f6543dab91ff43dd71c (diff)
libcamera: v4l2_pixelformat: Return the list of V4L2 formats
Multiple V4L2 formats can be associated with a single PixelFormat. Now that users of V4L2PixelFormat::fromPixelFormat() have been converted to use V4L2VideoDevice::toV4L2PixelFormat(), return the full list of V4L2 formats in order to prepare to match them against the ones supported by the video device. The V4L2 compatibility layer, not having any video device to interact with, is converted to use the first returned format unconditionally. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Tested-by: Paul Elder <paul.elder@ideasonboard.com>
-rw-r--r--include/libcamera/internal/v4l2_pixelformat.h4
-rw-r--r--src/libcamera/v4l2_pixelformat.cpp14
-rw-r--r--src/libcamera/v4l2_videodevice.cpp2
-rw-r--r--src/v4l2/v4l2_camera_proxy.cpp6
4 files changed, 15 insertions, 11 deletions
diff --git a/include/libcamera/internal/v4l2_pixelformat.h b/include/libcamera/internal/v4l2_pixelformat.h
index ed94baf9..d5400f90 100644
--- a/include/libcamera/internal/v4l2_pixelformat.h
+++ b/include/libcamera/internal/v4l2_pixelformat.h
@@ -11,6 +11,7 @@
#include <ostream>
#include <stdint.h>
#include <string>
+#include <vector>
#include <linux/videodev2.h>
@@ -44,7 +45,8 @@ public:
const char *description() const;
PixelFormat toPixelFormat() const;
- static V4L2PixelFormat fromPixelFormat(const PixelFormat &pixelFormat);
+ static const std::vector<V4L2PixelFormat> &
+ fromPixelFormat(const PixelFormat &pixelFormat);
private:
uint32_t fourcc_;
diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp
index 9f74bd37..90c8fa8d 100644
--- a/src/libcamera/v4l2_pixelformat.cpp
+++ b/src/libcamera/v4l2_pixelformat.cpp
@@ -302,22 +302,24 @@ PixelFormat V4L2PixelFormat::toPixelFormat() const
}
/**
- * \brief Convert \a pixelFormat to its corresponding V4L2PixelFormat
+ * \brief Retrieve the list of V4L2PixelFormat associated with \a pixelFormat
* \param[in] pixelFormat The PixelFormat to convert
*
* Multiple V4L2 formats may exist for one PixelFormat as V4L2 defines separate
* 4CCs for contiguous and non-contiguous versions of the same image format.
- * When that is the case, this function returns the contiguous planes format.
*
- * \return The V4L2PixelFormat corresponding to \a pixelFormat
+ * \return The list of V4L2PixelFormat corresponding to \a pixelFormat
*/
-V4L2PixelFormat V4L2PixelFormat::fromPixelFormat(const PixelFormat &pixelFormat)
+const std::vector<V4L2PixelFormat> &
+V4L2PixelFormat::fromPixelFormat(const PixelFormat &pixelFormat)
{
+ static const std::vector<V4L2PixelFormat> empty;
+
const PixelFormatInfo &info = PixelFormatInfo::info(pixelFormat);
if (!info.isValid())
- return V4L2PixelFormat();
+ return empty;
- return info.v4l2Formats[0];
+ return info.v4l2Formats;
}
/**
diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index f41afa06..2ca22f48 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -2000,7 +2000,7 @@ V4L2VideoDevice::fromEntityName(const MediaDevice *media,
*/
V4L2PixelFormat V4L2VideoDevice::toV4L2PixelFormat(const PixelFormat &pixelFormat) const
{
- return V4L2PixelFormat::fromPixelFormat(pixelFormat);
+ return V4L2PixelFormat::fromPixelFormat(pixelFormat)[0];
}
/**
diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
index 26a227da..55ff62cd 100644
--- a/src/v4l2/v4l2_camera_proxy.cpp
+++ b/src/v4l2/v4l2_camera_proxy.cpp
@@ -182,7 +182,7 @@ void V4L2CameraProxy::setFmtFromConfig(const StreamConfiguration &streamConfig)
v4l2PixFormat_.width = size.width;
v4l2PixFormat_.height = size.height;
- v4l2PixFormat_.pixelformat = V4L2PixelFormat::fromPixelFormat(streamConfig.pixelFormat);
+ v4l2PixFormat_.pixelformat = V4L2PixelFormat::fromPixelFormat(streamConfig.pixelFormat)[0];
v4l2PixFormat_.field = V4L2_FIELD_NONE;
v4l2PixFormat_.bytesperline = streamConfig.stride;
v4l2PixFormat_.sizeimage = streamConfig.frameSize;
@@ -290,7 +290,7 @@ int V4L2CameraProxy::vidioc_enum_fmt(V4L2CameraFile *file, struct v4l2_fmtdesc *
return -EINVAL;
PixelFormat format = streamConfig_.formats().pixelformats()[arg->index];
- V4L2PixelFormat v4l2Format = V4L2PixelFormat::fromPixelFormat(format);
+ V4L2PixelFormat v4l2Format = V4L2PixelFormat::fromPixelFormat(format)[0];
arg->flags = format == formats::MJPEG ? V4L2_FMT_FLAG_COMPRESSED : 0;
utils::strlcpy(reinterpret_cast<char *>(arg->description),
@@ -333,7 +333,7 @@ int V4L2CameraProxy::tryFormat(struct v4l2_format *arg)
arg->fmt.pix.width = config.size.width;
arg->fmt.pix.height = config.size.height;
- arg->fmt.pix.pixelformat = V4L2PixelFormat::fromPixelFormat(config.pixelFormat);
+ arg->fmt.pix.pixelformat = V4L2PixelFormat::fromPixelFormat(config.pixelFormat)[0];
arg->fmt.pix.field = V4L2_FIELD_NONE;
arg->fmt.pix.bytesperline = config.stride;
arg->fmt.pix.sizeimage = config.frameSize;