diff options
author | Paul Elder <paul.elder@ideasonboard.com> | 2020-07-04 17:56:25 +0900 |
---|---|---|
committer | Paul Elder <paul.elder@ideasonboard.com> | 2020-07-10 16:11:32 +0900 |
commit | 89fb1efac240451a2e463a405f4676910fc062b1 (patch) | |
tree | 6d1cc8254ab2b2ef21df64c2bdc75d12b369b80c | |
parent | 99b926bd124565aa98d7d47a40d8830813b7209e (diff) |
libcamera: simple: Fill stride and frameSize at config validation
Fill the stride and frameSize fields of the StreamConfiguration at
configuration validation time instead of at camera configuration time.
This allows applications to get the stride when trying a configuration
without modifying the active configuration of the camera.
Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
-rw-r--r-- | src/libcamera/pipeline/simple/converter.cpp | 15 | ||||
-rw-r--r-- | src/libcamera/pipeline/simple/converter.h | 4 | ||||
-rw-r--r-- | src/libcamera/pipeline/simple/simple.cpp | 26 |
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(); |