summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libcamera/pipeline/simple/converter.cpp15
-rw-r--r--src/libcamera/pipeline/simple/converter.h4
-rw-r--r--src/libcamera/pipeline/simple/simple.cpp26
3 files changed, 43 insertions, 2 deletions
diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp
index e5e2f0fd..dc7c0463 100644
--- a/src/libcamera/pipeline/simple/converter.cpp
+++ b/src/libcamera/pipeline/simple/converter.cpp
@@ -261,4 +261,19 @@ void SimpleConverter::outputBufferReady(FrameBuffer *buffer)
}
}
+std::tuple<unsigned int, unsigned int>
+SimpleConverter::strideAndFrameSize(const Size &size,
+ const PixelFormat &pixelFormat)
+{
+ V4L2DeviceFormat format = {};
+ format.fourcc = m2m_->capture()->toV4L2PixelFormat(pixelFormat);
+ format.size = size;
+
+ int ret = m2m_->capture()->tryFormat(&format);
+ if (ret < 0)
+ return { 0, 0 };
+
+ return { format.planes[0].bpl, format.planes[0].size };
+}
+
} /* namespace libcamera */
diff --git a/src/libcamera/pipeline/simple/converter.h b/src/libcamera/pipeline/simple/converter.h
index ef18cf73..8ca88912 100644
--- a/src/libcamera/pipeline/simple/converter.h
+++ b/src/libcamera/pipeline/simple/converter.h
@@ -10,6 +10,7 @@
#include <memory>
#include <queue>
+#include <tuple>
#include <vector>
#include <libcamera/pixel_format.h>
@@ -46,6 +47,9 @@ public:
int queueBuffers(FrameBuffer *input, FrameBuffer *output);
+ std::tuple<unsigned int, unsigned int>
+ strideAndFrameSize(const Size &size, const PixelFormat &pixelFormat);
+
Signal<FrameBuffer *, FrameBuffer *> bufferReady;
private:
diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
index 1ec8d0f7..28d36788 100644
--- a/src/libcamera/pipeline/simple/simple.cpp
+++ b/src/libcamera/pipeline/simple/simple.cpp
@@ -457,6 +457,30 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate()
cfg.bufferCount = 3;
+ /* Set the stride and frameSize. */
+ if (!needConversion_) {
+ V4L2DeviceFormat format = {};
+ format.fourcc = data_->video_->toV4L2PixelFormat(cfg.pixelFormat);
+ format.size = cfg.size;
+
+ int ret = data_->video_->tryFormat(&format);
+ if (ret < 0)
+ return Invalid;
+
+ cfg.stride = format.planes[0].bpl;
+ cfg.frameSize = format.planes[0].size;
+
+ return status;
+ }
+
+ SimplePipelineHandler *pipe = static_cast<SimplePipelineHandler *>(data_->pipe_);
+ SimpleConverter *converter = pipe->converter();
+
+ std::tie(cfg.stride, cfg.frameSize) =
+ converter->strideAndFrameSize(cfg.size, cfg.pixelFormat);
+ if (cfg.stride == 0)
+ return Invalid;
+
return status;
}
@@ -557,8 +581,6 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c)
return -EINVAL;
}
- cfg.stride = captureFormat.planes[0].bpl;
-
/* Configure the converter if required. */
useConverter_ = config->needConversion();