Loading...
Searching...
No Matches
pipeline_handler.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2018, Google Inc.
*
* Pipeline handler infrastructure
*/
#pragma once
#include <memory>
#include <string>
#include <sys/types.h>
#include <vector>
#include <libcamera/base/object.h>
#include <libcamera/controls.h>
#include <libcamera/stream.h>
namespace libcamera {
class Camera;
class CameraConfiguration;
class CameraManager;
class DeviceEnumerator;
class DeviceMatch;
class FrameBuffer;
class MediaDevice;
class PipelineHandler;
class Request;
class PipelineHandler : public std::enable_shared_from_this<PipelineHandler>,
public Object
{
public:
PipelineHandler(CameraManager *manager,
unsigned int maxQueuedRequestsDevice = 32);
virtual ~PipelineHandler();
virtual bool match(DeviceEnumerator *enumerator) = 0;
std::shared_ptr<MediaDevice> acquireMediaDevice(DeviceEnumerator *enumerator,
const DeviceMatch &dm);
bool acquire(Camera *camera);
void release(Camera *camera);
virtual std::unique_ptr<CameraConfiguration> generateConfiguration(Camera *camera,
Span<const StreamRole> roles) = 0;
virtual int configure(Camera *camera, CameraConfiguration *config) = 0;
virtual int exportFrameBuffers(Camera *camera, Stream *stream,
std::vector<std::unique_ptr<FrameBuffer>> *buffers) = 0;
virtual int start(Camera *camera, const ControlList *controls) = 0;
void stop(Camera *camera);
bool hasPendingRequests(const Camera *camera) const;
void registerRequest(Request *request);
void queueRequest(Request *request);
bool completeBuffer(Request *request, FrameBuffer *buffer);
void completeRequest(Request *request);
void cancelRequest(Request *request);
std::string configurationFile(const std::string &subdir,
const std::string &name,
bool silent = false) const;
const char *name() const { return name_; }
CameraManager *cameraManager() const { return manager_; }
protected:
void registerCamera(std::shared_ptr<Camera> camera);
void hotplugMediaDevice(std::shared_ptr<MediaDevice> media);
unsigned int useCount() const { return useCount_; }
virtual int queueRequestDevice(Camera *camera, Request *request) = 0;
virtual void stopDevice(Camera *camera) = 0;
virtual bool acquireDevice(Camera *camera);
virtual void releaseDevice(Camera *camera);
CameraManager *manager_;
const unsigned int maxQueuedRequestsDevice_;
private:
void unlockMediaDevices();
void mediaDeviceDisconnected(std::shared_ptr<MediaDevice> media);
virtual void disconnect();
void doQueueRequest(Request *request);
void doQueueRequests(Camera *camera);
std::vector<std::shared_ptr<MediaDevice>> mediaDevices_;
std::vector<std::weak_ptr<Camera>> cameras_;
const char *name_;
unsigned int useCount_;
friend class PipelineHandlerFactoryBase;
};
class PipelineHandlerFactoryBase
{
public:
PipelineHandlerFactoryBase(const char *name);
virtual ~PipelineHandlerFactoryBase() = default;
std::shared_ptr<PipelineHandler> create(CameraManager *manager) const;
const std::string &name() const { return name_; }
static std::vector<PipelineHandlerFactoryBase *> &factories();
static const PipelineHandlerFactoryBase *getFactoryByName(const std::string &name);
private:
static void registerType(PipelineHandlerFactoryBase *factory);
virtual std::unique_ptr<PipelineHandler>
createInstance(CameraManager *manager) const = 0;
std::string name_;
};
template<typename _PipelineHandler>
class PipelineHandlerFactory final : public PipelineHandlerFactoryBase
{
public:
PipelineHandlerFactory(const char *name)
: PipelineHandlerFactoryBase(name)
{
}
std::unique_ptr<PipelineHandler>
createInstance(CameraManager *manager) const override
{
return std::make_unique<_PipelineHandler>(manager);
}
};
#define REGISTER_PIPELINE_HANDLER(handler, name) \
static PipelineHandlerFactory<handler> global_##handler##Factory(name);
} /* namespace libcamera */
libcamera::CameraConfiguration
Hold configuration for streams of the camera.
Definition camera.h:60
libcamera::CameraManager
Provide access and manage all cameras in the system.
Definition camera_manager.h:25
libcamera::Camera
Camera device.
Definition camera.h:115
libcamera::ControlList
Associate a list of ControlId with their values for an object.
Definition controls.h:409
libcamera::DeviceEnumerator
Enumerate, store and search media devices.
Definition device_enumerator.h:40
libcamera::DeviceMatch
Description of a media device search pattern.
Definition device_enumerator.h:22
libcamera::FrameBuffer
Frame buffer data and its associated dynamic metadata.
Definition framebuffer.h:50
libcamera::MediaDevice
The MediaDevice represents a Media Controller device with its full graph of connected objects.
Definition media_device.h:28
libcamera::Object::Object
Object(Object *parent=nullptr)
Construct an Object instance.
Definition object.cpp:69
libcamera::PipelineHandlerFactoryBase
Base class for pipeline handler factories.
Definition pipeline_handler.h:106
libcamera::PipelineHandlerFactoryBase::name
const std::string & name() const
Retrieve the factory name.
Definition pipeline_handler.h:113
libcamera::PipelineHandlerFactoryBase::getFactoryByName
static const PipelineHandlerFactoryBase * getFactoryByName(const std::string &name)
Return the factory for the pipeline handler with name name.
Definition pipeline_handler.cpp:918
libcamera::PipelineHandlerFactoryBase::PipelineHandlerFactoryBase
PipelineHandlerFactoryBase(const char *name)
Construct a pipeline handler factory base.
Definition pipeline_handler.cpp:857
libcamera::PipelineHandlerFactoryBase::factories
static std::vector< PipelineHandlerFactoryBase * > & factories()
Retrieve the list of all pipeline handler factories.
Definition pipeline_handler.cpp:902
libcamera::PipelineHandlerFactoryBase::create
std::shared_ptr< PipelineHandler > create(CameraManager *manager) const
Create an instance of the PipelineHandler corresponding to the factory.
Definition pipeline_handler.cpp:870
libcamera::PipelineHandlerFactory::PipelineHandlerFactory
PipelineHandlerFactory(const char *name)
Construct a pipeline handler factory.
Definition pipeline_handler.h:131
libcamera::PipelineHandlerFactory::createInstance
std::unique_ptr< PipelineHandler > createInstance(CameraManager *manager) const override
Create an instance of the PipelineHandler corresponding to the factory.
Definition pipeline_handler.h:137
libcamera::PipelineHandler
Create and manage cameras based on a set of media devices.
Definition pipeline_handler.h:34
libcamera::PipelineHandler::stopDevice
virtual void stopDevice(Camera *camera)=0
Stop capturing from all running streams.
libcamera::PipelineHandler::hotplugMediaDevice
void hotplugMediaDevice(std::shared_ptr< MediaDevice > media)
Enable hotplug handling for a media device.
Definition pipeline_handler.cpp:739
libcamera::PipelineHandler::cameraManager
CameraManager * cameraManager() const
Retrieve the CameraManager that this pipeline handler belongs to.
Definition pipeline_handler.h:71
libcamera::PipelineHandler::configurationFile
std::string configurationFile(const std::string &subdir, const std::string &name, bool silent=false) const
Retrieve the absolute path to a platform configuration file.
Definition pipeline_handler.cpp:638
libcamera::PipelineHandler::name
const char * name() const
Retrieve the pipeline handler name.
Definition pipeline_handler.h:69
libcamera::PipelineHandler::manager_
CameraManager * manager_
The Camera manager associated with the pipeline handler.
Definition pipeline_handler.h:84
libcamera::PipelineHandler::completeRequest
void completeRequest(Request *request)
Signal request completion.
Definition pipeline_handler.cpp:584
libcamera::PipelineHandler::releaseDevice
virtual void releaseDevice(Camera *camera)
Release resources associated with this camera.
Definition pipeline_handler.cpp:260
libcamera::PipelineHandler::queueRequestDevice
virtual int queueRequestDevice(Camera *camera, Request *request)=0
Queue a request to the device.
libcamera::PipelineHandler::acquire
bool acquire(Camera *camera)
Acquire exclusive access to the pipeline handler for the process.
Definition pipeline_handler.cpp:171
libcamera::PipelineHandler::useCount
unsigned int useCount() const
Retrieve the pipeline handler's used camera count.
Definition pipeline_handler.h:76
libcamera::PipelineHandler::acquireDevice
virtual bool acquireDevice(Camera *camera)
Acquire resources associated with this camera.
Definition pipeline_handler.cpp:239
libcamera::PipelineHandler::match
virtual bool match(DeviceEnumerator *enumerator)=0
Match media devices and create camera instances.
libcamera::PipelineHandler::registerCamera
void registerCamera(std::shared_ptr< Camera > camera)
Register a camera to the camera manager and pipeline handler.
Definition pipeline_handler.cpp:688
libcamera::PipelineHandler::registerRequest
void registerRequest(Request *request)
Register a request for use by the pipeline handler.
Definition pipeline_handler.cpp:435
libcamera::PipelineHandler::start
virtual int start(Camera *camera, const ControlList *controls)=0
Start capturing from a group of streams.
libcamera::PipelineHandler::cancelRequest
void cancelRequest(Request *request)
Cancel request and signal its completion.
Definition pipeline_handler.cpp:613
libcamera::PipelineHandler::PipelineHandler
PipelineHandler(CameraManager *manager, unsigned int maxQueuedRequestsDevice=32)
Construct a PipelineHandler instance.
Definition pipeline_handler.cpp:72
libcamera::PipelineHandler::queueRequest
void queueRequest(Request *request)
Queue a request.
Definition pipeline_handler.cpp:469
libcamera::PipelineHandler::hasPendingRequests
bool hasPendingRequests(const Camera *camera) const
Determine if the camera has any requests pending.
Definition pipeline_handler.cpp:422
libcamera::PipelineHandler::stop
void stop(Camera *camera)
Stop capturing from all running streams and cancel pending requests.
Definition pipeline_handler.cpp:367
libcamera::PipelineHandler::exportFrameBuffers
virtual int exportFrameBuffers(Camera *camera, Stream *stream, std::vector< std::unique_ptr< FrameBuffer > > *buffers)=0
Allocate and export buffers for stream.
libcamera::PipelineHandler::generateConfiguration
virtual std::unique_ptr< CameraConfiguration > generateConfiguration(Camera *camera, Span< const StreamRole > roles)=0
Generate a camera configuration for a specified camera.
libcamera::PipelineHandler::maxQueuedRequestsDevice_
const unsigned int maxQueuedRequestsDevice_
The maximum number of requests the pipeline handler shall queue to the device.
Definition pipeline_handler.h:85
libcamera::PipelineHandler::completeBuffer
bool completeBuffer(Request *request, FrameBuffer *buffer)
Complete a buffer for a request.
Definition pipeline_handler.cpp:563
libcamera::PipelineHandler::acquireMediaDevice
std::shared_ptr< MediaDevice > acquireMediaDevice(DeviceEnumerator *enumerator, const DeviceMatch &dm)
Search and acquire a MediaDevice matching a device pattern.
Definition pipeline_handler.cpp:136
libcamera::PipelineHandler::configure
virtual int configure(Camera *camera, CameraConfiguration *config)=0
Configure a group of streams for capture.
libcamera::PipelineHandler::release
void release(Camera *camera)
Release exclusive access to the pipeline handler.
Definition pipeline_handler.cpp:209
libcamera::Request
A frame capture request.
Definition request.h:30
libcamera::Stream
Video stream for a camera.
Definition stream.h:76
controls.h
Framework to manage controls related to an object.
libcamera::controls
Namespace for libcamera controls.
Definition control_ids.h:22
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
object.h
Base object to support automatic signal disconnection.
stream.h
Video stream for a Camera.