mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-25 01:25:08 +03:00
The CameraConfiguration class implements a simple storage of StreamConfiguration with internal validation limited to verifying that the stream configurations are not empty. Extend this mechanism by implementing a smart validate() method backed by pipeline handlers. This new mechanism changes the semantic of the camera configuration. The Camera::generateConfiguration() operation still generates a default configuration based on roles, but now also supports generating empty configurations to be filled by applications. Applications can inspect the configuration, optionally modify it, and validate it. The validation implements "try" semantics and adjusts invalid configurations instead of rejecting them completely. Applications then decide whether to accept the modified configuration, or try again with a different set of parameters. Once the configuration is valid, it is passed to Camera::configure(), and pipeline handlers are guaranteed that the configuration they receive is valid. A reference to the Camera may need to be stored in the CameraConfiguration derived classes in order to access it from their validate() implementation. This must be stored as a std::shared_ptr<> as the CameraConfiguration instances belong to applications. In order to make this possible, make the Camera class inherit from std::shared_from_this<>. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
130 lines
2.7 KiB
C++
130 lines
2.7 KiB
C++
/* 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 <map>
|
|
#include <memory>
|
|
#include <set>
|
|
#include <string>
|
|
|
|
#include <libcamera/request.h>
|
|
#include <libcamera/signal.h>
|
|
#include <libcamera/stream.h>
|
|
|
|
namespace libcamera {
|
|
|
|
class Buffer;
|
|
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 *, Buffer *> bufferCompleted;
|
|
Signal<Request *, const std::map<Stream *, Buffer *> &> requestCompleted;
|
|
Signal<Camera *> disconnected;
|
|
|
|
int acquire();
|
|
int release();
|
|
|
|
const std::set<Stream *> &streams() const;
|
|
std::unique_ptr<CameraConfiguration> generateConfiguration(const StreamRoles &roles);
|
|
int configure(CameraConfiguration *config);
|
|
|
|
int allocateBuffers();
|
|
int freeBuffers();
|
|
|
|
Request *createRequest();
|
|
int queueRequest(Request *request);
|
|
|
|
int start();
|
|
int stop();
|
|
|
|
private:
|
|
enum State {
|
|
CameraAvailable,
|
|
CameraAcquired,
|
|
CameraConfigured,
|
|
CameraPrepared,
|
|
CameraRunning,
|
|
};
|
|
|
|
Camera(PipelineHandler *pipe, const std::string &name);
|
|
~Camera();
|
|
|
|
bool stateBetween(State low, State high) const;
|
|
bool stateIs(State state) const;
|
|
|
|
friend class PipelineHandler;
|
|
void disconnect();
|
|
|
|
void requestComplete(Request *request);
|
|
|
|
std::shared_ptr<PipelineHandler> pipe_;
|
|
std::string name_;
|
|
std::set<Stream *> streams_;
|
|
std::set<Stream *> activeStreams_;
|
|
|
|
bool disconnected_;
|
|
State state_;
|
|
};
|
|
|
|
} /* namespace libcamera */
|
|
|
|
#endif /* __LIBCAMERA_CAMERA_H__ */
|