To properly support both multiple streams and stream usages the library must provide a method to map the stream usages to the returned streams configurations. Add a camera configuration object to handle this mapping. Applications can iterate over the returned camera configuration to retrieve the streams selected by the library in the same order as the usages it provided to the library. Applications can use the operator[] to retrieve the stream pointer and the stream configuration. Using a numerical index retrieves the stream pointer, the numerical indexes corresponds to the insertion order of usages in the CameraConfiguration, using the stream pointer retrieves the stream's configuration. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
121 lines
2.5 KiB
C++
121 lines
2.5 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>
|
|
|
|
namespace libcamera {
|
|
|
|
class Buffer;
|
|
class PipelineHandler;
|
|
class Request;
|
|
class Stream;
|
|
class StreamConfiguration;
|
|
class StreamUsage;
|
|
|
|
class CameraConfiguration
|
|
{
|
|
public:
|
|
using iterator = std::vector<Stream *>::iterator;
|
|
using const_iterator = std::vector<Stream *>::const_iterator;
|
|
|
|
CameraConfiguration();
|
|
|
|
iterator begin();
|
|
iterator end();
|
|
const_iterator begin() const;
|
|
const_iterator end() const;
|
|
|
|
bool isValid() const;
|
|
bool isEmpty() const;
|
|
std::size_t size() const;
|
|
|
|
Stream *front();
|
|
const Stream *front() const;
|
|
|
|
Stream *operator[](unsigned int index) const;
|
|
StreamConfiguration &operator[](Stream *stream);
|
|
const StreamConfiguration &operator[](Stream *stream) const;
|
|
|
|
private:
|
|
std::vector<Stream *> order_;
|
|
std::map<Stream *, StreamConfiguration> config_;
|
|
};
|
|
|
|
class Camera final
|
|
{
|
|
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::map<Stream *, StreamConfiguration>
|
|
streamConfiguration(const std::vector<StreamUsage> &usage);
|
|
int configureStreams(std::map<Stream *, StreamConfiguration> &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__ */
|