libcamera: store stream pointers in sets instead of a vectors
The arrays that store Stream pointers shall always contain unique values. Storing them in vectors opens up for the same stream pointer appearing twice. Remove this possibility by storing them in a set which guarantees each element is unique. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
dc01a5bc43
commit
132ce9c1cf
7 changed files with 25 additions and 24 deletions
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <libcamera/request.h>
|
#include <libcamera/request.h>
|
||||||
|
@ -27,7 +28,7 @@ class Camera final
|
||||||
public:
|
public:
|
||||||
static std::shared_ptr<Camera> create(PipelineHandler *pipe,
|
static std::shared_ptr<Camera> create(PipelineHandler *pipe,
|
||||||
const std::string &name,
|
const std::string &name,
|
||||||
const std::vector<Stream *> &streams);
|
const std::set<Stream *> &streams);
|
||||||
|
|
||||||
Camera(const Camera &) = delete;
|
Camera(const Camera &) = delete;
|
||||||
Camera &operator=(const Camera &) = delete;
|
Camera &operator=(const Camera &) = delete;
|
||||||
|
@ -40,9 +41,9 @@ public:
|
||||||
int acquire();
|
int acquire();
|
||||||
void release();
|
void release();
|
||||||
|
|
||||||
const std::vector<Stream *> &streams() const;
|
const std::set<Stream *> &streams() const;
|
||||||
std::map<Stream *, StreamConfiguration>
|
std::map<Stream *, StreamConfiguration>
|
||||||
streamConfiguration(std::vector<Stream *> &streams);
|
streamConfiguration(std::set<Stream *> &streams);
|
||||||
int configureStreams(std::map<Stream *, StreamConfiguration> &config);
|
int configureStreams(std::map<Stream *, StreamConfiguration> &config);
|
||||||
|
|
||||||
int allocateBuffers();
|
int allocateBuffers();
|
||||||
|
@ -64,8 +65,8 @@ private:
|
||||||
|
|
||||||
std::shared_ptr<PipelineHandler> pipe_;
|
std::shared_ptr<PipelineHandler> pipe_;
|
||||||
std::string name_;
|
std::string name_;
|
||||||
std::vector<Stream *> streams_;
|
std::set<Stream *> streams_;
|
||||||
std::vector<Stream *> activeStreams_;
|
std::set<Stream *> activeStreams_;
|
||||||
|
|
||||||
bool acquired_;
|
bool acquired_;
|
||||||
bool disconnected_;
|
bool disconnected_;
|
||||||
|
|
|
@ -75,10 +75,10 @@ static int parseOptions(int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int configureStreams(Camera *camera, std::vector<Stream *> &streams)
|
static int configureStreams(Camera *camera, std::set<Stream *> &streams)
|
||||||
{
|
{
|
||||||
KeyValueParser::Options format = options[OptFormat];
|
KeyValueParser::Options format = options[OptFormat];
|
||||||
Stream *id = streams.front();
|
Stream *id = *streams.begin();
|
||||||
|
|
||||||
std::map<Stream *, StreamConfiguration> config =
|
std::map<Stream *, StreamConfiguration> config =
|
||||||
camera->streamConfiguration(streams);
|
camera->streamConfiguration(streams);
|
||||||
|
@ -132,7 +132,7 @@ static int capture()
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
std::vector<Stream *> streams = camera->streams();
|
std::set<Stream *> streams = camera->streams();
|
||||||
std::vector<Request *> requests;
|
std::vector<Request *> requests;
|
||||||
|
|
||||||
ret = configureStreams(camera.get(), streams);
|
ret = configureStreams(camera.get(), streams);
|
||||||
|
@ -141,7 +141,7 @@ static int capture()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream *stream = streams.front();
|
Stream *stream = *streams.begin();
|
||||||
|
|
||||||
ret = camera->allocateBuffers();
|
ret = camera->allocateBuffers();
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
@ -237,7 +237,7 @@ int main(int argc, char **argv)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<Stream *> &streams = camera->streams();
|
const std::set<Stream *> &streams = camera->streams();
|
||||||
if (streams.size() != 1) {
|
if (streams.size() != 1) {
|
||||||
std::cout << "Camera has " << streams.size()
|
std::cout << "Camera has " << streams.size()
|
||||||
<< " streams, only 1 is supported"
|
<< " streams, only 1 is supported"
|
||||||
|
|
|
@ -66,7 +66,7 @@ LOG_DECLARE_CATEGORY(Camera)
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<Camera> Camera::create(PipelineHandler *pipe,
|
std::shared_ptr<Camera> Camera::create(PipelineHandler *pipe,
|
||||||
const std::string &name,
|
const std::string &name,
|
||||||
const std::vector<Stream *> &streams)
|
const std::set<Stream *> &streams)
|
||||||
{
|
{
|
||||||
struct Allocator : std::allocator<Camera> {
|
struct Allocator : std::allocator<Camera> {
|
||||||
void construct(void *p, PipelineHandler *pipe,
|
void construct(void *p, PipelineHandler *pipe,
|
||||||
|
@ -188,7 +188,7 @@ void Camera::release()
|
||||||
*
|
*
|
||||||
* \return An array of all the camera's streams.
|
* \return An array of all the camera's streams.
|
||||||
*/
|
*/
|
||||||
const std::vector<Stream *> &Camera::streams() const
|
const std::set<Stream *> &Camera::streams() const
|
||||||
{
|
{
|
||||||
return streams_;
|
return streams_;
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ const std::vector<Stream *> &Camera::streams() const
|
||||||
* empty list on error.
|
* empty list on error.
|
||||||
*/
|
*/
|
||||||
std::map<Stream *, StreamConfiguration>
|
std::map<Stream *, StreamConfiguration>
|
||||||
Camera::streamConfiguration(std::vector<Stream *> &streams)
|
Camera::streamConfiguration(std::set<Stream *> &streams)
|
||||||
{
|
{
|
||||||
if (disconnected_ || !streams.size())
|
if (disconnected_ || !streams.size())
|
||||||
return std::map<Stream *, StreamConfiguration>{};
|
return std::map<Stream *, StreamConfiguration>{};
|
||||||
|
@ -264,7 +264,7 @@ int Camera::configureStreams(std::map<Stream *, StreamConfiguration> &config)
|
||||||
const StreamConfiguration &cfg = iter.second;
|
const StreamConfiguration &cfg = iter.second;
|
||||||
|
|
||||||
stream->configuration_ = cfg;
|
stream->configuration_ = cfg;
|
||||||
activeStreams_.push_back(stream);
|
activeStreams_.insert(stream);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate buffer objects in the pool.
|
* Allocate buffer objects in the pool.
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
virtual bool match(DeviceEnumerator *enumerator) = 0;
|
virtual bool match(DeviceEnumerator *enumerator) = 0;
|
||||||
|
|
||||||
virtual std::map<Stream *, StreamConfiguration>
|
virtual std::map<Stream *, StreamConfiguration>
|
||||||
streamConfiguration(Camera *camera, std::vector<Stream *> &streams) = 0;
|
streamConfiguration(Camera *camera, std::set<Stream *> &streams) = 0;
|
||||||
virtual int configureStreams(Camera *camera,
|
virtual int configureStreams(Camera *camera,
|
||||||
std::map<Stream *, StreamConfiguration> &config) = 0;
|
std::map<Stream *, StreamConfiguration> &config) = 0;
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ public:
|
||||||
|
|
||||||
std::map<Stream *, StreamConfiguration>
|
std::map<Stream *, StreamConfiguration>
|
||||||
streamConfiguration(Camera *camera,
|
streamConfiguration(Camera *camera,
|
||||||
std::vector<Stream *> &streams) override;
|
std::set<Stream *> &streams) override;
|
||||||
int configureStreams(Camera *camera,
|
int configureStreams(Camera *camera,
|
||||||
std::map<Stream *, StreamConfiguration> &config) override;
|
std::map<Stream *, StreamConfiguration> &config) override;
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ PipelineHandlerIPU3::~PipelineHandlerIPU3()
|
||||||
|
|
||||||
std::map<Stream *, StreamConfiguration>
|
std::map<Stream *, StreamConfiguration>
|
||||||
PipelineHandlerIPU3::streamConfiguration(Camera *camera,
|
PipelineHandlerIPU3::streamConfiguration(Camera *camera,
|
||||||
std::vector<Stream *> &streams)
|
std::set<Stream *> &streams)
|
||||||
{
|
{
|
||||||
IPU3CameraData *data = cameraData(camera);
|
IPU3CameraData *data = cameraData(camera);
|
||||||
std::map<Stream *, StreamConfiguration> configs;
|
std::map<Stream *, StreamConfiguration> configs;
|
||||||
|
@ -374,7 +374,7 @@ void PipelineHandlerIPU3::registerCameras()
|
||||||
std::unique_ptr<IPU3CameraData> data = utils::make_unique<IPU3CameraData>();
|
std::unique_ptr<IPU3CameraData> data = utils::make_unique<IPU3CameraData>();
|
||||||
|
|
||||||
std::string cameraName = sensor->name() + " " + std::to_string(id);
|
std::string cameraName = sensor->name() + " " + std::to_string(id);
|
||||||
std::vector<Stream *> streams{ &data->stream_ };
|
std::set<Stream *> streams{ &data->stream_ };
|
||||||
std::shared_ptr<Camera> camera = Camera::create(this, cameraName, streams);
|
std::shared_ptr<Camera> camera = Camera::create(this, cameraName, streams);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -27,7 +27,7 @@ public:
|
||||||
|
|
||||||
std::map<Stream *, StreamConfiguration>
|
std::map<Stream *, StreamConfiguration>
|
||||||
streamConfiguration(Camera *camera,
|
streamConfiguration(Camera *camera,
|
||||||
std::vector<Stream *> &streams) override;
|
std::set<Stream *> &streams) override;
|
||||||
int configureStreams(Camera *camera,
|
int configureStreams(Camera *camera,
|
||||||
std::map<Stream *, StreamConfiguration> &config) override;
|
std::map<Stream *, StreamConfiguration> &config) override;
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ PipelineHandlerUVC::~PipelineHandlerUVC()
|
||||||
|
|
||||||
std::map<Stream *, StreamConfiguration>
|
std::map<Stream *, StreamConfiguration>
|
||||||
PipelineHandlerUVC::streamConfiguration(Camera *camera,
|
PipelineHandlerUVC::streamConfiguration(Camera *camera,
|
||||||
std::vector<Stream *> &streams)
|
std::set<Stream *> &streams)
|
||||||
{
|
{
|
||||||
std::map<Stream *, StreamConfiguration> configs;
|
std::map<Stream *, StreamConfiguration> configs;
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Stream *> streams{ &stream_ };
|
std::set<Stream *> streams{ &stream_ };
|
||||||
std::shared_ptr<Camera> camera = Camera::create(this, media_->model(), streams);
|
std::shared_ptr<Camera> camera = Camera::create(this, media_->model(), streams);
|
||||||
registerCamera(std::move(camera));
|
registerCamera(std::move(camera));
|
||||||
hotplugMediaDevice(media_.get());
|
hotplugMediaDevice(media_.get());
|
||||||
|
|
|
@ -27,7 +27,7 @@ public:
|
||||||
|
|
||||||
std::map<Stream *, StreamConfiguration>
|
std::map<Stream *, StreamConfiguration>
|
||||||
streamConfiguration(Camera *camera,
|
streamConfiguration(Camera *camera,
|
||||||
std::vector<Stream *> &streams) override;
|
std::set<Stream *> &streams) override;
|
||||||
int configureStreams(Camera *camera,
|
int configureStreams(Camera *camera,
|
||||||
std::map<Stream *, StreamConfiguration> &config) override;
|
std::map<Stream *, StreamConfiguration> &config) override;
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ PipelineHandlerVimc::~PipelineHandlerVimc()
|
||||||
|
|
||||||
std::map<Stream *, StreamConfiguration>
|
std::map<Stream *, StreamConfiguration>
|
||||||
PipelineHandlerVimc::streamConfiguration(Camera *camera,
|
PipelineHandlerVimc::streamConfiguration(Camera *camera,
|
||||||
std::vector<Stream *> &streams)
|
std::set<Stream *> &streams)
|
||||||
{
|
{
|
||||||
std::map<Stream *, StreamConfiguration> configs;
|
std::map<Stream *, StreamConfiguration> configs;
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Stream *> streams{ &stream_ };
|
std::set<Stream *> streams{ &stream_ };
|
||||||
std::shared_ptr<Camera> camera = Camera::create(this, "VIMC Sensor B",
|
std::shared_ptr<Camera> camera = Camera::create(this, "VIMC Sensor B",
|
||||||
streams);
|
streams);
|
||||||
registerCamera(std::move(camera));
|
registerCamera(std::move(camera));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue