Global configuration is accessed via a GlobalConfiguration instance. The instance is conceptually a singleton, but singletons are not welcome in libcamera so we must store the (preferably single) instance somewhere. This patch creates a GlobalConfiguration instance in CameraManager and defines the corresponding access method. CameraManager is typically instantiated only once or a few times, it is accessible in many places in libcamera and the configuration can be retrieved from it and passed to other places if needed (it's read-only once created). Using CameraManager for the purpose is still suboptimal and we use it only due to lack of better options. An alternative could be Logger, which is still a singleton and it's accessible from everywhere. But with Logger, we have a chicken and egg problem -- GlobalConfiguration should log contingent problems with the configuration when it's loaded but if it is created in the logger then there are mutual infinite recursive calls. One possible way to deal with this is to look at the environment variables only during logging initialisation and apply the logging configuration when a CameraManager is constructed. Considering there are intentions to remove the Logger singleton, let's omit logging configuration for now. If there are multiple CameraManager instances, there are also multiple GlobalConfiguration instances, each CameraManager instance is meant to be fully independent, including configuration. They may or may not contain the same data, depending on whether the global configuration file in the file system was changed in the meantime. The configuration is stored in the private CameraManager. It's accessible within libcamera (via CameraManager) but it's not meant to be accessed by applications. Signed-off-by: Milan Zamazal <mzamazal@redhat.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
79 lines
1.8 KiB
C++
79 lines
1.8 KiB
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2023, Ideas on Board Oy.
|
|
*
|
|
* Camera manager private data
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <libcamera/camera_manager.h>
|
|
|
|
#include <memory>
|
|
#include <sys/types.h>
|
|
#include <vector>
|
|
|
|
#include <libcamera/base/class.h>
|
|
#include <libcamera/base/mutex.h>
|
|
#include <libcamera/base/thread.h>
|
|
#include <libcamera/base/thread_annotations.h>
|
|
|
|
#include "libcamera/internal/global_configuration.h"
|
|
#include "libcamera/internal/process.h"
|
|
|
|
namespace libcamera {
|
|
|
|
class Camera;
|
|
class DeviceEnumerator;
|
|
class IPAManager;
|
|
class PipelineHandlerFactoryBase;
|
|
|
|
class CameraManager::Private : public Extensible::Private, public Thread
|
|
{
|
|
LIBCAMERA_DECLARE_PUBLIC(CameraManager)
|
|
|
|
public:
|
|
Private();
|
|
|
|
int start();
|
|
void addCamera(std::shared_ptr<Camera> camera) LIBCAMERA_TSA_EXCLUDES(mutex_);
|
|
void removeCamera(std::shared_ptr<Camera> camera) LIBCAMERA_TSA_EXCLUDES(mutex_);
|
|
|
|
const GlobalConfiguration &configuration() const
|
|
{
|
|
return configuration_;
|
|
}
|
|
|
|
IPAManager *ipaManager() const { return ipaManager_.get(); }
|
|
|
|
protected:
|
|
void run() override;
|
|
|
|
private:
|
|
int init();
|
|
void createPipelineHandlers();
|
|
void pipelineFactoryMatch(const PipelineHandlerFactoryBase *factory);
|
|
void cleanup() LIBCAMERA_TSA_EXCLUDES(mutex_);
|
|
|
|
/*
|
|
* This mutex protects
|
|
*
|
|
* - initialized_ and status_ during initialization
|
|
* - cameras_ after initialization
|
|
*/
|
|
mutable Mutex mutex_;
|
|
std::vector<std::shared_ptr<Camera>> cameras_ LIBCAMERA_TSA_GUARDED_BY(mutex_);
|
|
|
|
ConditionVariable cv_;
|
|
bool initialized_ LIBCAMERA_TSA_GUARDED_BY(mutex_);
|
|
int status_ LIBCAMERA_TSA_GUARDED_BY(mutex_);
|
|
|
|
std::unique_ptr<DeviceEnumerator> enumerator_;
|
|
|
|
std::unique_ptr<IPAManager> ipaManager_;
|
|
|
|
const GlobalConfiguration configuration_;
|
|
};
|
|
|
|
} /* namespace libcamera */
|