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>
This commit is contained in:
parent
99b926bd12
commit
89fb1efac2
3 changed files with 43 additions and 2 deletions
|
@ -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 */
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue