camera.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2018, Google Inc.
*
* camera.h - Camera object interface
*/
#ifndef __LIBCAMERA_CAMERA_H__
#define __LIBCAMERA_CAMERA_H__
#include <memory>
#include <set>
#include <stdint.h>
#include <string>
#include <libcamera/controls.h>
#include <libcamera/request.h>
#include <libcamera/signal.h>
#include <libcamera/stream.h>
namespace libcamera {
class FrameBuffer;
class FrameBufferAllocator;
class PipelineHandler;
class Request;
class CameraConfiguration
{
public:
enum Status {
Valid,
Adjusted,
Invalid,
};
using iterator = std::vector<StreamConfiguration>::iterator;
using const_iterator = std::vector<StreamConfiguration>::const_iterator;
virtual ~CameraConfiguration();
void addConfiguration(const StreamConfiguration &cfg);
virtual Status validate() = 0;
StreamConfiguration &at(unsigned int index);
const StreamConfiguration &at(unsigned int index) const;
StreamConfiguration &operator[](unsigned int index)
{
return at(index);
}
const StreamConfiguration &operator[](unsigned int index) const
{
return at(index);
}
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
bool empty() const;
std::size_t size() const;
protected:
CameraConfiguration();
std::vector<StreamConfiguration> config_;
};
class Camera final : public std::enable_shared_from_this<Camera>
{
public:
static std::shared_ptr<Camera> create(PipelineHandler *pipe,
const std::string &name,
const std::set<Stream *> &streams);
Camera(const Camera &) = delete;
Camera &operator=(const Camera &) = delete;
const std::string &name() const;
Signal<Request *, FrameBuffer *> bufferCompleted;
Signal<Request *> requestCompleted;
Signal<Camera *> disconnected;
int acquire();
int release();
const ControlInfoMap &controls();
const ControlList &properties();
const std::set<Stream *> &streams() const;
std::unique_ptr<CameraConfiguration> generateConfiguration(const StreamRoles &roles);
int configure(CameraConfiguration *config);
Request *createRequest(uint64_t cookie = 0);
int queueRequest(Request *request);
int start();
int stop();
private:
Camera(PipelineHandler *pipe, const std::string &name,
const std::set<Stream *> &streams);
~Camera();
class Private;
std::unique_ptr<Private> p_;
friend class PipelineHandler;
void disconnect();
void requestComplete(Request *request);
friend class FrameBufferAllocator;
int exportFrameBuffers(Stream *stream,
std::vector<std::unique_ptr<FrameBuffer>> *buffers);
};
} /* namespace libcamera */
#endif /* __LIBCAMERA_CAMERA_H__ */
libcamera::CameraConfiguration
Hold configuration for streams of the camera.
Definition: camera.h:28
libcamera::CameraConfiguration::iterator
std::vector< StreamConfiguration >::iterator iterator
Iterator for the stream configurations in the camera configuration.
Definition: camera.h:36
libcamera::CameraConfiguration::config_
std::vector< StreamConfiguration > config_
The vector of stream configurations.
Definition: camera.h:66
libcamera::CameraConfiguration::validate
virtual Status validate()=0
Validate and possibly adjust the camera configuration.
libcamera::CameraConfiguration::at
StreamConfiguration & at(unsigned int index)
Retrieve a reference to a stream configuration.
Definition: camera.cpp:150
libcamera::CameraConfiguration::Status
Status
Validity of a camera configuration.
Definition: camera.h:30
libcamera::CameraConfiguration::Valid
@ Valid
Definition: camera.h:31
libcamera::CameraConfiguration::Adjusted
@ Adjusted
Definition: camera.h:32
libcamera::CameraConfiguration::Invalid
@ Invalid
Definition: camera.h:33
libcamera::CameraConfiguration::operator[]
const StreamConfiguration & operator[](unsigned int index) const
Retrieve a const reference to a stream configuration.
Definition: camera.h:50
libcamera::CameraConfiguration::empty
bool empty() const
Check if the camera configuration is empty.
Definition: camera.cpp:239
libcamera::CameraConfiguration::CameraConfiguration
CameraConfiguration()
Create an empty camera configuration.
Definition: camera.cpp:95
libcamera::CameraConfiguration::size
std::size_t size() const
Retrieve the number of stream configurations.
Definition: camera.cpp:248
libcamera::CameraConfiguration::addConfiguration
void addConfiguration(const StreamConfiguration &cfg)
Add a stream configuration to the camera configuration.
Definition: camera.cpp:108
libcamera::CameraConfiguration::begin
iterator begin()
Retrieve an iterator to the first stream configuration in the sequence.
Definition: camera.cpp:199
libcamera::CameraConfiguration::end
iterator end()
Retrieve an iterator pointing to the past-the-end stream configuration in the sequence.
Definition: camera.cpp:219
libcamera::CameraConfiguration::const_iterator
std::vector< StreamConfiguration >::const_iterator const_iterator
Const iterator for the stream configuration in the camera configuration.
Definition: camera.h:37
libcamera::CameraConfiguration::operator[]
StreamConfiguration & operator[](unsigned int index)
Retrieve a reference to a stream configuration.
Definition: camera.h:46
libcamera::Camera
Camera device.
Definition: camera.h:70
libcamera::Camera::streams
const std::set< Stream * > & streams() const
Retrieve all the camera's stream information.
Definition: camera.cpp:669
libcamera::Camera::create
static std::shared_ptr< Camera > create(PipelineHandler *pipe, const std::string &name, const std::set< Stream * > &streams)
Create a camera instance.
Definition: camera.cpp:460
libcamera::Camera::configure
int configure(CameraConfiguration *config)
Configure the camera prior to capture.
Definition: camera.cpp:749
libcamera::Camera::controls
const ControlInfoMap & controls()
Retrieve the list of controls supported by the camera.
Definition: camera.cpp:640
libcamera::Camera::stop
int stop()
Stop capture from camera.
Definition: camera.cpp:929
libcamera::Camera::acquire
int acquire()
Acquire the camera device for exclusive access.
Definition: camera.cpp:581
libcamera::Camera::properties
const ControlList & properties()
Retrieve the list of properties of the camera.
Definition: camera.cpp:653
libcamera::Camera::release
int release()
Release exclusive access to the camera device.
Definition: camera.cpp:616
libcamera::Camera::requestCompleted
Signal< Request * > requestCompleted
Signal emitted when a request queued to the camera has completed.
Definition: camera.h:82
libcamera::Camera::start
int start()
Start capture from camera.
Definition: camera.cpp:897
libcamera::Camera::queueRequest
int queueRequest(Request *request)
Queue a request to the camera.
Definition: camera.cpp:851
libcamera::Camera::createRequest
Request * createRequest(uint64_t cookie=0)
Create a request object for the camera.
Definition: camera.cpp:816
libcamera::Camera::disconnected
Signal< Camera * > disconnected
Signal emitted when the camera is disconnected from the system.
Definition: camera.h:83
libcamera::Camera::generateConfiguration
std::unique_ptr< CameraConfiguration > generateConfiguration(const StreamRoles &roles)
Generate a default camera configuration according to stream roles.
Definition: camera.cpp:690
libcamera::Camera::name
const std::string & name() const
Retrieve the name of the camera.
Definition: camera.cpp:481
libcamera::Camera::bufferCompleted
Signal< Request *, FrameBuffer * > bufferCompleted
Signal emitted when a buffer for a request queued to the camera has completed.
Definition: camera.h:81
libcamera::ControlInfoMap
A map of ControlId to ControlInfo.
Definition: controls.h:297
libcamera::ControlList
Associate a list of ControlId with their values for an object.
Definition: controls.h:342
libcamera::FrameBufferAllocator
FrameBuffer allocator for applications.
Definition: framebuffer_allocator.h:21
libcamera::PipelineHandler
Create and manage cameras based on a set of media devices.
Definition: pipeline_handler.h:59
libcamera::Request
A frame capture request.
Definition: request.h:26
libcamera::Signal
Generic signal and slot communication mechanism.
Definition: signal.h:39
libcamera::Stream
Video stream for a camera.
Definition: stream.h:70
controls.h
Framework to manage controls related to an object.
request.h
Describes a frame capture request to be processed by a camera.
signal.h
Signal & slot implementation.
stream.h
Video stream for a Camera.
libcamera::StreamRoles
std::vector< StreamRole > StreamRoles
A vector of StreamRole.
Definition: stream.h:67
libcamera::StreamConfiguration
Configuration parameters for a stream.
Definition: stream.h:39