libcamera: Pass CameraManager around instead of GlobalConfiguration
The GlobalConfiguration is explicitly passed around through constructors of various objects that need access to the configuration. This ad-hoc solution works for the specific use cases it was meant to support, but isn't very generic. We have a top-level object in libcamera, the CameraManager, that also needs to be accessed from various locations and is passed to object constructors. Standardize on passing the CameraManager everywhere, and access the global configuration through it. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>
This commit is contained in:
@@ -93,7 +93,8 @@ void CameraManager::Private::run()
|
||||
|
||||
int CameraManager::Private::init()
|
||||
{
|
||||
ipaManager_ = std::make_unique<IPAManager>(configuration());
|
||||
CameraManager *const o = LIBCAMERA_O_PTR();
|
||||
ipaManager_ = std::make_unique<IPAManager>(*o);
|
||||
|
||||
enumerator_ = DeviceEnumerator::create();
|
||||
if (!enumerator_ || enumerator_->enumerate())
|
||||
|
||||
@@ -100,13 +100,16 @@ LOG_DEFINE_CATEGORY(IPAManager)
|
||||
|
||||
/**
|
||||
* \brief Construct an IPAManager instance
|
||||
* \param[in] cm The camera manager
|
||||
*
|
||||
* The IPAManager class is meant to only be instantiated once, by the
|
||||
* CameraManager.
|
||||
*/
|
||||
IPAManager::IPAManager(const GlobalConfiguration &configuration)
|
||||
: configuration_(configuration)
|
||||
IPAManager::IPAManager(const CameraManager &cm)
|
||||
: cm_(cm)
|
||||
{
|
||||
const GlobalConfiguration &configuration = cm._d()->configuration();
|
||||
|
||||
#if HAVE_IPA_PUBKEY
|
||||
if (!pubKey_.isValid())
|
||||
LOG(IPAManager, Warning) << "Public key not valid";
|
||||
|
||||
@@ -117,13 +117,19 @@ std::string ipaConfigurationFile(const std::string &ipaName, const std::string &
|
||||
/**
|
||||
* \brief Construct an IPAProxy instance
|
||||
* \param[in] ipam The IPA module
|
||||
* \param[in] configuration The global configuration
|
||||
* \param[in] cm The camera manager
|
||||
*/
|
||||
IPAProxy::IPAProxy(IPAModule *ipam, const GlobalConfiguration &configuration)
|
||||
: valid_(false), state_(ProxyStopped), ipam_(ipam),
|
||||
configPaths_(configuration.envListOption("LIBCAMERA_IPA_CONFIG_PATH", { "ipa", "config_paths" }).value_or(std::vector<std::string>())),
|
||||
execPaths_(configuration.envListOption("LIBCAMERA_IPA_PROXY_PATH", { "ipa", "proxy_paths" }).value_or(std::vector<std::string>()))
|
||||
IPAProxy::IPAProxy(IPAModule *ipam, const CameraManager &cm)
|
||||
: valid_(false), state_(ProxyStopped), ipam_(ipam)
|
||||
{
|
||||
const GlobalConfiguration &configuration = cm._d()->configuration();
|
||||
|
||||
configPaths_ = configuration.envListOption("LIBCAMERA_IPA_CONFIG_PATH",
|
||||
{ "ipa", "config_paths" })
|
||||
.value_or(std::vector<std::string>());
|
||||
execPaths_ = configuration.envListOption("LIBCAMERA_IPA_PROXY_PATH",
|
||||
{ "ipa", "proxy_paths" })
|
||||
.value_or(std::vector<std::string>());
|
||||
}
|
||||
|
||||
IPAProxy::~IPAProxy()
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
|
||||
#include <libcamera/base/log.h>
|
||||
|
||||
#include "libcamera/internal/camera_manager.h"
|
||||
#include "libcamera/internal/global_configuration.h"
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
LOG_DEFINE_CATEGORY(Benchmark)
|
||||
@@ -26,9 +29,11 @@ LOG_DEFINE_CATEGORY(Benchmark)
|
||||
/**
|
||||
* \brief Constructs a Benchmark object
|
||||
*/
|
||||
Benchmark::Benchmark(const GlobalConfiguration &configuration, const std::string &name)
|
||||
Benchmark::Benchmark(const CameraManager &cm, const std::string &name)
|
||||
: name_(name)
|
||||
{
|
||||
const GlobalConfiguration &configuration = cm._d()->configuration();
|
||||
|
||||
skipBeforeMeasure_ = configuration.option<unsigned int>(
|
||||
{ "software_isp", "measure", "skip" })
|
||||
.value_or(skipBeforeMeasure_);
|
||||
|
||||
@@ -18,12 +18,6 @@ namespace libcamera {
|
||||
* \brief Struct to hold the debayer parameters.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \fn Debayer::Debayer(const GlobalConfiguration &configuration)
|
||||
* \brief Construct a Debayer object
|
||||
* \param[in] configuration Global configuration reference
|
||||
*/
|
||||
|
||||
/**
|
||||
* \var DebayerParams::gains
|
||||
* \brief Colour channel gains
|
||||
@@ -58,8 +52,12 @@ namespace libcamera {
|
||||
|
||||
LOG_DEFINE_CATEGORY(Debayer)
|
||||
|
||||
Debayer::Debayer(const GlobalConfiguration &configuration)
|
||||
: bench_(configuration, "Debayer")
|
||||
/**
|
||||
* \brief Construct a Debayer object
|
||||
* \param[in] cm The camera manager
|
||||
*/
|
||||
Debayer::Debayer(const CameraManager &cm)
|
||||
: bench_(cm, "Debayer")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -22,12 +22,12 @@
|
||||
|
||||
#include "libcamera/internal/bayer_format.h"
|
||||
#include "libcamera/internal/dma_buf_allocator.h"
|
||||
#include "libcamera/internal/global_configuration.h"
|
||||
#include "libcamera/internal/software_isp/benchmark.h"
|
||||
#include "libcamera/internal/software_isp/debayer_params.h"
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class CameraManager;
|
||||
class FrameBuffer;
|
||||
|
||||
LOG_DECLARE_CATEGORY(Debayer)
|
||||
@@ -35,7 +35,7 @@ LOG_DECLARE_CATEGORY(Debayer)
|
||||
class Debayer : public Object
|
||||
{
|
||||
public:
|
||||
Debayer(const GlobalConfiguration &configuration);
|
||||
Debayer(const CameraManager &cm);
|
||||
virtual ~Debayer() = 0;
|
||||
|
||||
virtual int configure(const StreamConfiguration &inputCfg,
|
||||
|
||||
@@ -89,10 +89,10 @@ DebayerCpuThread::DebayerCpuThread(DebayerCpu *debayer, unsigned int threadIndex
|
||||
/**
|
||||
* \brief Constructs a DebayerCpu object
|
||||
* \param[in] stats Pointer to the stats object to use
|
||||
* \param[in] configuration The global configuration
|
||||
* \param[in] cm The camera manager
|
||||
*/
|
||||
DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats, const GlobalConfiguration &configuration)
|
||||
: Debayer(configuration), stats_(std::move(stats))
|
||||
DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats, const CameraManager &cm)
|
||||
: Debayer(cm), stats_(std::move(stats))
|
||||
{
|
||||
/*
|
||||
* Reading from uncached buffers may be very slow.
|
||||
@@ -105,6 +105,7 @@ DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats, const GlobalConfigurat
|
||||
* \todo Make memcpy automatic based on runtime detection of platform
|
||||
* capabilities.
|
||||
*/
|
||||
const GlobalConfiguration &configuration = cm._d()->configuration();
|
||||
bool enableInputMemcpy =
|
||||
configuration.option<bool>({ "software_isp", "copy_input_buffer" }).value_or(true);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <libcamera/base/object.h>
|
||||
|
||||
#include "libcamera/internal/bayer_format.h"
|
||||
#include "libcamera/internal/global_configuration.h"
|
||||
#include "libcamera/internal/camera_manager.h"
|
||||
#include "libcamera/internal/software_isp/debayer_params.h"
|
||||
#include "libcamera/internal/software_isp/swstats_cpu.h"
|
||||
|
||||
@@ -31,7 +31,7 @@ class DebayerCpuThread;
|
||||
class DebayerCpu : public Debayer
|
||||
{
|
||||
public:
|
||||
DebayerCpu(std::unique_ptr<SwStatsCpu> stats, const GlobalConfiguration &configuration);
|
||||
DebayerCpu(std::unique_ptr<SwStatsCpu> stats, const CameraManager &cm);
|
||||
~DebayerCpu();
|
||||
|
||||
int configure(const StreamConfiguration &inputCfg,
|
||||
|
||||
@@ -29,13 +29,12 @@ namespace libcamera {
|
||||
*/
|
||||
|
||||
/**
|
||||
* \fn DebayerEGL::DebayerEGL(std::unique_ptr<SwStatsCpu> stats, const GlobalConfiguration &configuration)
|
||||
* \brief Construct a DebayerEGL object
|
||||
* \param[in] stats Statistics processing object
|
||||
* \param[in] configuration Global configuration reference
|
||||
* \param[in] cm The camera manager
|
||||
*/
|
||||
DebayerEGL::DebayerEGL(std::unique_ptr<SwStatsCpu> stats, const GlobalConfiguration &configuration)
|
||||
: Debayer(configuration), stats_(std::move(stats))
|
||||
DebayerEGL::DebayerEGL(std::unique_ptr<SwStatsCpu> stats, const CameraManager &cm)
|
||||
: Debayer(cm), stats_(std::move(stats))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -35,10 +35,12 @@ namespace libcamera {
|
||||
#define DEBAYER_EGL_MIN_SIMPLE_RGB_GAIN_TEXTURE_UNITS 4
|
||||
#define DEBAYER_OPENGL_COORDS 4
|
||||
|
||||
class CameraManager;
|
||||
|
||||
class DebayerEGL : public Debayer
|
||||
{
|
||||
public:
|
||||
DebayerEGL(std::unique_ptr<SwStatsCpu> stats, const GlobalConfiguration &configuration);
|
||||
DebayerEGL(std::unique_ptr<SwStatsCpu> stats, const CameraManager &cm);
|
||||
~DebayerEGL();
|
||||
|
||||
int configure(const StreamConfiguration &inputCfg,
|
||||
|
||||
@@ -95,9 +95,9 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,
|
||||
return;
|
||||
}
|
||||
|
||||
const GlobalConfiguration &configuration = pipe->cameraManager()->_d()->configuration();
|
||||
const CameraManager &cm = *pipe->cameraManager();
|
||||
|
||||
auto stats = std::make_unique<SwStatsCpu>(configuration);
|
||||
auto stats = std::make_unique<SwStatsCpu>(cm);
|
||||
if (!stats->isValid()) {
|
||||
LOG(SoftwareIsp, Error) << "Failed to create SwStatsCpu object";
|
||||
return;
|
||||
@@ -105,6 +105,7 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,
|
||||
stats->statsReady.connect(this, &SoftwareIsp::statsReady);
|
||||
|
||||
#if HAVE_DEBAYER_EGL
|
||||
const GlobalConfiguration &configuration = cm._d()->configuration();
|
||||
std::optional<std::string> softISPMode = configuration.envOption("LIBCAMERA_SOFTISP_MODE", { "software_isp", "mode" });
|
||||
if (softISPMode) {
|
||||
if (softISPMode != "gpu" && softISPMode != "cpu") {
|
||||
@@ -117,11 +118,11 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,
|
||||
}
|
||||
|
||||
if (!softISPMode || softISPMode == "gpu")
|
||||
debayer_ = std::make_unique<DebayerEGL>(std::move(stats), configuration);
|
||||
debayer_ = std::make_unique<DebayerEGL>(std::move(stats), cm);
|
||||
|
||||
#endif
|
||||
if (!debayer_)
|
||||
debayer_ = std::make_unique<DebayerCpu>(std::move(stats), configuration);
|
||||
debayer_ = std::make_unique<DebayerCpu>(std::move(stats), cm);
|
||||
|
||||
debayer_->inputBufferReady.connect(this, &SoftwareIsp::inputReady);
|
||||
debayer_->outputBufferReady.connect(this, &SoftwareIsp::outputReady);
|
||||
|
||||
@@ -36,9 +36,9 @@ namespace libcamera {
|
||||
*/
|
||||
|
||||
/**
|
||||
* \fn SwStatsCpu::SwStatsCpu(const GlobalConfiguration &configuration)
|
||||
* \fn SwStatsCpu::SwStatsCpu(const CameraManager &cm)
|
||||
* \brief Construct a SwStatsCpu object
|
||||
* \param[in] configuration Global configuration reference
|
||||
* \param[in] cm The camera manager
|
||||
*
|
||||
* Creates a SwStatsCpu object and initialises shared memory for statistics
|
||||
* exchange.
|
||||
@@ -159,8 +159,8 @@ namespace libcamera {
|
||||
|
||||
LOG_DEFINE_CATEGORY(SwStatsCpu)
|
||||
|
||||
SwStatsCpu::SwStatsCpu(const GlobalConfiguration &configuration)
|
||||
: sharedStats_("softIsp_stats"), bench_(configuration, "CPU stats")
|
||||
SwStatsCpu::SwStatsCpu(const CameraManager &cm)
|
||||
: sharedStats_("softIsp_stats"), bench_(cm, "CPU stats")
|
||||
{
|
||||
if (!sharedStats_)
|
||||
LOG(SwStatsCpu, Error)
|
||||
|
||||
Reference in New Issue
Block a user