diff options
author | Naushir Patuck <naush@raspberrypi.com> | 2023-09-21 18:55:45 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2023-09-27 14:42:12 +0300 |
commit | 0602cbc59665b3017ccc3fb9067d45840e6c1405 (patch) | |
tree | 7caa5279bedb4a361133ba7ad117ca7e2c1c8506 | |
parent | 2a5120f6744cfdab2aa6ec7b5e2195e38be70c60 (diff) |
libcamera: rpi: Cache rawStreams and outStreams
Currently, the stream configuration is stored in two vectors, rawStreams
and outStreams for convenience. However, these vectors are constructed
in both platformValidate() and platformConfigure().
This change caches these vectors in the RPiCameraConfiguration class to
construct them only once in platformValidate().
Pass a pointer to the current configuration to platformValidate() and
platformConfigure() so that they can access the streams vectors.
Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rw-r--r-- | src/libcamera/pipeline/rpi/common/pipeline_base.cpp | 50 | ||||
-rw-r--r-- | src/libcamera/pipeline/rpi/common/pipeline_base.h | 42 | ||||
-rw-r--r-- | src/libcamera/pipeline/rpi/vc4/vc4.cpp | 20 |
3 files changed, 48 insertions, 64 deletions
diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 471a13a9..a9495259 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -179,19 +179,21 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() if (transform != requestedTransform) status = Adjusted; - std::vector<CameraData::StreamParams> rawStreams, outStreams; + rawStreams_.clear(); + outStreams_.clear(); + for (const auto &[index, cfg] : utils::enumerate(config_)) { if (PipelineHandlerBase::isRaw(cfg.pixelFormat)) - rawStreams.emplace_back(index, &cfg); + rawStreams_.emplace_back(index, &cfg); else - outStreams.emplace_back(index, &cfg); + outStreams_.emplace_back(index, &cfg); } /* Sort the streams so the highest resolution is first. */ - std::sort(rawStreams.begin(), rawStreams.end(), + std::sort(rawStreams_.begin(), rawStreams_.end(), [](auto &l, auto &r) { return l.cfg->size > r.cfg->size; }); - std::sort(outStreams.begin(), outStreams.end(), + std::sort(outStreams_.begin(), outStreams_.end(), [](auto &l, auto &r) { return l.cfg->size > r.cfg->size; }); /* Compute the sensor's format then do any platform specific fixups. */ @@ -202,14 +204,14 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() /* Use the application provided sensor configuration. */ bitDepth = sensorConfig->bitDepth; sensorSize = sensorConfig->outputSize; - } else if (!rawStreams.empty()) { + } else if (!rawStreams_.empty()) { /* Use the RAW stream format and size. */ - BayerFormat bayerFormat = BayerFormat::fromPixelFormat(rawStreams[0].cfg->pixelFormat); + BayerFormat bayerFormat = BayerFormat::fromPixelFormat(rawStreams_[0].cfg->pixelFormat); bitDepth = bayerFormat.bitDepth; - sensorSize = rawStreams[0].cfg->size; + sensorSize = rawStreams_[0].cfg->size; } else { bitDepth = defaultRawBitDepth; - sensorSize = outStreams[0].cfg->size; + sensorSize = outStreams_[0].cfg->size; } sensorFormat_ = data_->findBestFormat(sensorSize, bitDepth); @@ -230,12 +232,12 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() } /* Do any platform specific fixups. */ - status = data_->platformValidate(this, rawStreams, outStreams); + status = data_->platformValidate(this); if (status == Invalid) return Invalid; /* Further fixups on the RAW streams. */ - for (auto &raw : rawStreams) { + for (auto &raw : rawStreams_) { StreamConfiguration &cfg = config_.at(raw.index); V4L2DeviceFormat rawFormat; @@ -273,7 +275,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() } /* Further fixups on the ISP output streams. */ - for (auto &out : outStreams) { + for (auto &out : outStreams_) { StreamConfiguration &cfg = config_.at(out.index); PixelFormat &cfgPixFmt = cfg.pixelFormat; V4L2VideoDevice::Formats fmts = out.dev->formats(); @@ -493,24 +495,6 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) for (auto const stream : data->streams_) stream->clearFlags(StreamFlag::External); - std::vector<CameraData::StreamParams> rawStreams, ispStreams; - - for (unsigned i = 0; i < config->size(); i++) { - StreamConfiguration *cfg = &config->at(i); - - if (isRaw(cfg->pixelFormat)) - rawStreams.emplace_back(i, cfg); - else - ispStreams.emplace_back(i, cfg); - } - - /* Sort the streams so the highest resolution is first. */ - std::sort(rawStreams.begin(), rawStreams.end(), - [](auto &l, auto &r) { return l.cfg->size > r.cfg->size; }); - - std::sort(ispStreams.begin(), ispStreams.end(), - [](auto &l, auto &r) { return l.cfg->size > r.cfg->size; }); - /* * Apply the format on the sensor with any cached transform. * @@ -535,9 +519,9 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) /* Use the user requested packing/bit-depth. */ std::optional<BayerFormat::Packing> packing; - if (!rawStreams.empty()) { + if (!rpiConfig->rawStreams_.empty()) { BayerFormat bayerFormat = - BayerFormat::fromPixelFormat(rawStreams[0].cfg->pixelFormat); + BayerFormat::fromPixelFormat(rpiConfig->rawStreams_[0].cfg->pixelFormat); packing = bayerFormat.packing; } @@ -545,7 +529,7 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) * Platform specific internal stream configuration. This also assigns * external streams which get configured below. */ - ret = data->platformConfigure(sensorFormat, packing, rawStreams, ispStreams); + ret = data->platformConfigure(sensorFormat, packing, rpiConfig); if (ret) return ret; diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index 135b7439..1a3a13db 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -57,29 +57,10 @@ public: { } - struct StreamParams { - StreamParams() - : index(0), cfg(nullptr), dev(nullptr) - { - } - - StreamParams(unsigned int index_, StreamConfiguration *cfg_) - : index(index_), cfg(cfg_), dev(nullptr) - { - } - - unsigned int index; - StreamConfiguration *cfg; - V4L2VideoDevice *dev; - }; - - virtual CameraConfiguration::Status platformValidate(RPiCameraConfiguration *rpiConfig, - std::vector<StreamParams> &rawStreams, - std::vector<StreamParams> &outStreams) const = 0; + virtual CameraConfiguration::Status platformValidate(RPiCameraConfiguration *rpiConfig) const = 0; virtual int platformConfigure(const V4L2SubdeviceFormat &sensorFormat, std::optional<BayerFormat::Packing> packing, - std::vector<StreamParams> &rawStreams, - std::vector<StreamParams> &outStreams) = 0; + const RPiCameraConfiguration *rpiConfig) = 0; virtual void platformStart() = 0; virtual void platformStop() = 0; @@ -270,6 +251,25 @@ public: /* The sensor format computed in validate() */ V4L2SubdeviceFormat sensorFormat_; + struct StreamParams { + StreamParams() + : index(0), cfg(nullptr), dev(nullptr) + { + } + + StreamParams(unsigned int index_, StreamConfiguration *cfg_) + : index(index_), cfg(cfg_), dev(nullptr) + { + } + + unsigned int index; + StreamConfiguration *cfg; + V4L2VideoDevice *dev; + }; + + std::vector<StreamParams> rawStreams_; + std::vector<StreamParams> outStreams_; + private: const CameraData *data_; diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp index 46504636..1c860d7f 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -25,6 +25,7 @@ namespace libcamera { LOG_DECLARE_CATEGORY(RPI) using StreamFlag = RPi::Stream::StreamFlag; +using StreamParams = RPi::RPiCameraConfiguration::StreamParams; namespace { @@ -65,9 +66,7 @@ public: { } - CameraConfiguration::Status platformValidate(RPi::RPiCameraConfiguration *rpiConfig, - std::vector<StreamParams> &rawStreams, - std::vector<StreamParams> &outStreams) const override; + CameraConfiguration::Status platformValidate(RPi::RPiCameraConfiguration *rpiConfig) const override; int platformPipelineConfigure(const std::unique_ptr<YamlObject> &root) override; @@ -118,8 +117,7 @@ private: int platformConfigure(const V4L2SubdeviceFormat &sensorFormat, std::optional<BayerFormat::Packing> packing, - std::vector<StreamParams> &rawStreams, - std::vector<StreamParams> &outStreams) override; + const RPi::RPiCameraConfiguration *rpiConfig) override; int platformConfigureIpa(ipa::RPi::ConfigParams ¶ms) override; int platformInitIpa([[maybe_unused]] ipa::RPi::InitParams ¶ms) override @@ -395,10 +393,11 @@ int PipelineHandlerVc4::platformRegister(std::unique_ptr<RPi::CameraData> &camer return 0; } -CameraConfiguration::Status Vc4CameraData::platformValidate(RPi::RPiCameraConfiguration *rpiConfig, - std::vector<StreamParams> &rawStreams, - std::vector<StreamParams> &outStreams) const +CameraConfiguration::Status Vc4CameraData::platformValidate(RPi::RPiCameraConfiguration *rpiConfig) const { + std::vector<StreamParams> &rawStreams = rpiConfig->rawStreams_; + std::vector<StreamParams> &outStreams = rpiConfig->outStreams_; + CameraConfiguration::Status status = CameraConfiguration::Status::Valid; /* Can only output 1 RAW stream, or 2 YUV/RGB streams. */ @@ -506,9 +505,10 @@ int Vc4CameraData::platformPipelineConfigure(const std::unique_ptr<YamlObject> & int Vc4CameraData::platformConfigure(const V4L2SubdeviceFormat &sensorFormat, std::optional<BayerFormat::Packing> packing, - std::vector<StreamParams> &rawStreams, - std::vector<StreamParams> &outStreams) + const RPi::RPiCameraConfiguration *rpiConfig) { + const std::vector<StreamParams> &rawStreams = rpiConfig->rawStreams_; + const std::vector<StreamParams> &outStreams = rpiConfig->outStreams_; int ret; if (!packing) |