summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libcamera/include/v4l2_device.h7
-rw-r--r--src/libcamera/v4l2_device.cpp109
2 files changed, 90 insertions, 26 deletions
diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h
index cecafa15..bdecc087 100644
--- a/src/libcamera/include/v4l2_device.h
+++ b/src/libcamera/include/v4l2_device.h
@@ -150,12 +150,15 @@ protected:
std::string logPrefix() const;
private:
- int getFormatSingleplane(V4L2DeviceFormat *format);
- int setFormatSingleplane(V4L2DeviceFormat *format);
+ int getFormatMeta(V4L2DeviceFormat *format);
+ int setFormatMeta(V4L2DeviceFormat *format);
int getFormatMultiplane(V4L2DeviceFormat *format);
int setFormatMultiplane(V4L2DeviceFormat *format);
+ int getFormatSingleplane(V4L2DeviceFormat *format);
+ int setFormatSingleplane(V4L2DeviceFormat *format);
+
int requestBuffers(unsigned int count);
int createPlane(Buffer *buffer, unsigned int plane,
unsigned int length);
diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index e42f6ef0..0821bd75 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -428,8 +428,12 @@ std::string V4L2Device::logPrefix() const
*/
int V4L2Device::getFormat(V4L2DeviceFormat *format)
{
- return caps_.isMultiplanar() ? getFormatMultiplane(format) :
- getFormatSingleplane(format);
+ if (caps_.isMeta())
+ return getFormatMeta(format);
+ else if (caps_.isMultiplanar())
+ return getFormatMultiplane(format);
+ else
+ return getFormatSingleplane(format);
}
/**
@@ -443,14 +447,18 @@ int V4L2Device::getFormat(V4L2DeviceFormat *format)
*/
int V4L2Device::setFormat(V4L2DeviceFormat *format)
{
- return caps_.isMultiplanar() ? setFormatMultiplane(format) :
- setFormatSingleplane(format);
+ if (caps_.isMeta())
+ return setFormatMeta(format);
+ else if (caps_.isMultiplanar())
+ return setFormatMultiplane(format);
+ else
+ return setFormatSingleplane(format);
}
-int V4L2Device::getFormatSingleplane(V4L2DeviceFormat *format)
+int V4L2Device::getFormatMeta(V4L2DeviceFormat *format)
{
struct v4l2_format v4l2Format = {};
- struct v4l2_pix_format *pix = &v4l2Format.fmt.pix;
+ struct v4l2_meta_format *pix = &v4l2Format.fmt.meta;
int ret;
v4l2Format.type = bufferType_;
@@ -461,29 +469,25 @@ int V4L2Device::getFormatSingleplane(V4L2DeviceFormat *format)
return ret;
}
- format->size.width = pix->width;
- format->size.height = pix->height;
- format->fourcc = pix->pixelformat;
+ format->size.width = 0;
+ format->size.height = 0;
+ format->fourcc = pix->dataformat;
format->planesCount = 1;
- format->planes[0].bpl = pix->bytesperline;
- format->planes[0].size = pix->sizeimage;
+ format->planes[0].bpl = pix->buffersize;
+ format->planes[0].size = pix->buffersize;
return 0;
}
-int V4L2Device::setFormatSingleplane(V4L2DeviceFormat *format)
+int V4L2Device::setFormatMeta(V4L2DeviceFormat *format)
{
struct v4l2_format v4l2Format = {};
- struct v4l2_pix_format *pix = &v4l2Format.fmt.pix;
+ struct v4l2_meta_format *pix = &v4l2Format.fmt.meta;
int ret;
v4l2Format.type = bufferType_;
- pix->width = format->size.width;
- pix->height = format->size.height;
- pix->pixelformat = format->fourcc;
- pix->bytesperline = format->planes[0].bpl;
- pix->field = V4L2_FIELD_NONE;
-
+ pix->dataformat = format->fourcc;
+ pix->buffersize = format->planes[0].size;
ret = ioctl(fd_, VIDIOC_S_FMT, &v4l2Format);
if (ret) {
ret = -errno;
@@ -495,12 +499,12 @@ int V4L2Device::setFormatSingleplane(V4L2DeviceFormat *format)
* Return to caller the format actually applied on the device,
* which might differ from the requested one.
*/
- format->size.width = pix->width;
- format->size.height = pix->height;
- format->fourcc = pix->pixelformat;
+ format->size.width = 0;
+ format->size.height = 0;
+ format->fourcc = format->fourcc;
format->planesCount = 1;
- format->planes[0].bpl = pix->bytesperline;
- format->planes[0].size = pix->sizeimage;
+ format->planes[0].bpl = pix->buffersize;
+ format->planes[0].size = pix->buffersize;
return 0;
}
@@ -573,6 +577,63 @@ int V4L2Device::setFormatMultiplane(V4L2DeviceFormat *format)
return 0;
}
+int V4L2Device::getFormatSingleplane(V4L2DeviceFormat *format)
+{
+ struct v4l2_format v4l2Format = {};
+ struct v4l2_pix_format *pix = &v4l2Format.fmt.pix;
+ int ret;
+
+ v4l2Format.type = bufferType_;
+ ret = ioctl(fd_, VIDIOC_G_FMT, &v4l2Format);
+ if (ret) {
+ ret = -errno;
+ LOG(V4L2, Error) << "Unable to get format: " << strerror(-ret);
+ return ret;
+ }
+
+ format->size.width = pix->width;
+ format->size.height = pix->height;
+ format->fourcc = pix->pixelformat;
+ format->planesCount = 1;
+ format->planes[0].bpl = pix->bytesperline;
+ format->planes[0].size = pix->sizeimage;
+
+ return 0;
+}
+
+int V4L2Device::setFormatSingleplane(V4L2DeviceFormat *format)
+{
+ struct v4l2_format v4l2Format = {};
+ struct v4l2_pix_format *pix = &v4l2Format.fmt.pix;
+ int ret;
+
+ v4l2Format.type = bufferType_;
+ pix->width = format->size.width;
+ pix->height = format->size.height;
+ pix->pixelformat = format->fourcc;
+ pix->bytesperline = format->planes[0].bpl;
+ pix->field = V4L2_FIELD_NONE;
+ ret = ioctl(fd_, VIDIOC_S_FMT, &v4l2Format);
+ if (ret) {
+ ret = -errno;
+ LOG(V4L2, Error) << "Unable to set format: " << strerror(-ret);
+ return ret;
+ }
+
+ /*
+ * Return to caller the format actually applied on the device,
+ * which might differ from the requested one.
+ */
+ format->size.width = pix->width;
+ format->size.height = pix->height;
+ format->fourcc = pix->pixelformat;
+ format->planesCount = 1;
+ format->planes[0].bpl = pix->bytesperline;
+ format->planes[0].size = pix->sizeimage;
+
+ return 0;
+}
+
int V4L2Device::requestBuffers(unsigned int count)
{
struct v4l2_requestbuffers rb = {};