[libcamera-devel] [PATCH v3 19/22] libcamera: simple: Fill stride and frameSize at config validation
Paul Elder
paul.elder at ideasonboard.com
Sat Jul 4 15:31:37 CEST 2020
Fill the stride and frameSize fields of the StreamConfiguration at
configuration validation time instead of at camera configuration time.
Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
---
New in v3
---
src/libcamera/pipeline/simple/converter.cpp | 14 +++++++++++
src/libcamera/pipeline/simple/converter.h | 5 ++++
src/libcamera/pipeline/simple/simple.cpp | 28 +++++++++++++++++++--
3 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp
index e5e2f0f..a015e8e 100644
--- a/src/libcamera/pipeline/simple/converter.cpp
+++ b/src/libcamera/pipeline/simple/converter.cpp
@@ -261,4 +261,18 @@ void SimpleConverter::outputBufferReady(FrameBuffer *buffer)
}
}
+unsigned int SimpleConverter::stride(const Size &size,
+ const PixelFormat &pixelFormat) const
+{
+ const PixelFormatInfo &info = PixelFormatInfo::info(pixelFormat);
+ return info.stride(size.width, 0);
+}
+
+unsigned int SimpleConverter::frameSize(const Size &size,
+ const PixelFormat &pixelFormat) const
+{
+ const PixelFormatInfo &info = PixelFormatInfo::info(pixelFormat);
+ return info.frameSize(size);
+}
+
} /* namespace libcamera */
diff --git a/src/libcamera/pipeline/simple/converter.h b/src/libcamera/pipeline/simple/converter.h
index ef18cf7..0696b8f 100644
--- a/src/libcamera/pipeline/simple/converter.h
+++ b/src/libcamera/pipeline/simple/converter.h
@@ -46,6 +46,11 @@ public:
int queueBuffers(FrameBuffer *input, FrameBuffer *output);
+ unsigned int stride(const Size &size,
+ const PixelFormat &pixelFormat) const;
+ unsigned int frameSize(const Size &size,
+ const PixelFormat &pixelFormat) const;
+
Signal<FrameBuffer *, FrameBuffer *> bufferReady;
private:
diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
index 1ec8d0f..39a29a7 100644
--- a/src/libcamera/pipeline/simple/simple.cpp
+++ b/src/libcamera/pipeline/simple/simple.cpp
@@ -457,6 +457,32 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate()
cfg.bufferCount = 3;
+ SimplePipelineHandler *pipe = static_cast<SimplePipelineHandler *>(data_->pipe_);
+ SimpleConverter *converter = pipe->converter();
+
+ /* Set the stride and frameSize. */
+ if (!converter) {
+ V4L2DeviceFormat format = {};
+ format.fourcc = data_->video_->toV4L2PixelFormat(cfg.pixelFormat);
+ format.size = cfg.size;
+
+ int ret = data_->video_->tryFormat(&format);
+ if (ret < 0) {
+ const PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat);
+ cfg.stride = info.stride(cfg.size.width, 0);
+ cfg.frameSize = info.frameSize(cfg.size);
+ return status;
+ }
+
+ cfg.stride = format.planes[0].bpl;
+ cfg.frameSize = format.planes[0].size;
+
+ return status;
+ }
+
+ cfg.stride = converter->stride(cfg.size, cfg.pixelFormat);
+ cfg.frameSize = converter->frameSize(cfg.size, cfg.pixelFormat);
+
return status;
}
@@ -557,8 +583,6 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c)
return -EINVAL;
}
- cfg.stride = captureFormat.planes[0].bpl;
-
/* Configure the converter if required. */
useConverter_ = config->needConversion();
--
2.27.0
More information about the libcamera-devel
mailing list