mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-22 08:05:06 +03:00
libcamera: pipeline: simple: Cache pipeline config in SimpleCameraConfiguration
As the pipeline configuration is selected in SimpleCameraConfiguration::validate() already, cache it in the SimpleCameraConfiguration instead of looking it up in SimplePipelineHandler::configure(). This makes little difference at the moment, but will save duplication of more complex logic between validate() and configure() when adding support for multiple streams. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Tested-by: Phi-Bang Nguyen <pnguyen@baylibre.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
parent
7b29587840
commit
23c60fcdff
1 changed files with 21 additions and 17 deletions
|
@ -177,6 +177,11 @@ public:
|
|||
|
||||
Status validate() override;
|
||||
|
||||
const SimpleCameraData::Configuration *pipeConfig() const
|
||||
{
|
||||
return pipeConfig_;
|
||||
}
|
||||
|
||||
bool needConversion() const { return needConversion_; }
|
||||
|
||||
private:
|
||||
|
@ -188,6 +193,7 @@ private:
|
|||
std::shared_ptr<Camera> camera_;
|
||||
const SimpleCameraData *data_;
|
||||
|
||||
const SimpleCameraData::Configuration *pipeConfig_;
|
||||
bool needConversion_;
|
||||
};
|
||||
|
||||
|
@ -506,7 +512,7 @@ int SimpleCameraData::setupFormats(V4L2SubdeviceFormat *format,
|
|||
SimpleCameraConfiguration::SimpleCameraConfiguration(Camera *camera,
|
||||
SimpleCameraData *data)
|
||||
: CameraConfiguration(), camera_(camera->shared_from_this()),
|
||||
data_(data)
|
||||
data_(data), pipeConfig_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -542,18 +548,18 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate()
|
|||
status = Adjusted;
|
||||
}
|
||||
|
||||
const SimpleCameraData::Configuration &pipeConfig = it->second;
|
||||
if (!pipeConfig.outputSizes.contains(cfg.size)) {
|
||||
pipeConfig_ = &it->second;
|
||||
if (!pipeConfig_->outputSizes.contains(cfg.size)) {
|
||||
LOG(SimplePipeline, Debug)
|
||||
<< "Adjusting size from " << cfg.size.toString()
|
||||
<< " to " << pipeConfig.captureSize.toString();
|
||||
cfg.size = pipeConfig.captureSize;
|
||||
<< " to " << pipeConfig_->captureSize.toString();
|
||||
cfg.size = pipeConfig_->captureSize;
|
||||
status = Adjusted;
|
||||
}
|
||||
|
||||
/* \todo Create a libcamera core class to group format and size */
|
||||
needConversion_ = cfg.pixelFormat != pipeConfig.captureFormat
|
||||
|| cfg.size != pipeConfig.captureSize;
|
||||
needConversion_ = cfg.pixelFormat != pipeConfig_->captureFormat
|
||||
|| cfg.size != pipeConfig_->captureSize;
|
||||
|
||||
cfg.bufferCount = 3;
|
||||
|
||||
|
@ -647,21 +653,19 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c)
|
|||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
const SimpleCameraData::Configuration &pipeConfig =
|
||||
data->formats_[cfg.pixelFormat];
|
||||
|
||||
V4L2SubdeviceFormat format{ pipeConfig.code, data->sensor_->resolution() };
|
||||
const SimpleCameraData::Configuration *pipeConfig = config->pipeConfig();
|
||||
V4L2SubdeviceFormat format{ pipeConfig->code, data->sensor_->resolution() };
|
||||
|
||||
ret = data->setupFormats(&format, V4L2Subdevice::ActiveFormat);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* Configure the video node. */
|
||||
V4L2PixelFormat videoFormat = video->toV4L2PixelFormat(pipeConfig.captureFormat);
|
||||
V4L2PixelFormat videoFormat = video->toV4L2PixelFormat(pipeConfig->captureFormat);
|
||||
|
||||
V4L2DeviceFormat captureFormat;
|
||||
captureFormat.fourcc = videoFormat;
|
||||
captureFormat.size = pipeConfig.captureSize;
|
||||
captureFormat.size = pipeConfig->captureSize;
|
||||
|
||||
ret = video->setFormat(&captureFormat);
|
||||
if (ret)
|
||||
|
@ -674,10 +678,10 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c)
|
|||
}
|
||||
|
||||
if (captureFormat.fourcc != videoFormat ||
|
||||
captureFormat.size != pipeConfig.captureSize) {
|
||||
captureFormat.size != pipeConfig->captureSize) {
|
||||
LOG(SimplePipeline, Error)
|
||||
<< "Unable to configure capture in "
|
||||
<< pipeConfig.captureSize.toString() << "-"
|
||||
<< pipeConfig->captureSize.toString() << "-"
|
||||
<< videoFormat.toString();
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -687,8 +691,8 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c)
|
|||
|
||||
if (useConverter_) {
|
||||
StreamConfiguration inputCfg;
|
||||
inputCfg.pixelFormat = pipeConfig.captureFormat;
|
||||
inputCfg.size = pipeConfig.captureSize;
|
||||
inputCfg.pixelFormat = pipeConfig->captureFormat;
|
||||
inputCfg.size = pipeConfig->captureSize;
|
||||
inputCfg.stride = captureFormat.planes[0].bpl;
|
||||
inputCfg.bufferCount = cfg.bufferCount;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue