diff options
author | Niklas Söderlund <niklas.soderlund@ragnatech.se> | 2019-02-26 02:46:33 +0100 |
---|---|---|
committer | Niklas Söderlund <niklas.soderlund@ragnatech.se> | 2019-02-28 18:41:52 +0100 |
commit | 132ce9c1cf6951d8cba8ff6ff5fbccadead385c1 (patch) | |
tree | d01cf52e2e68f468456907b335e24f8a6c85273d /src | |
parent | dc01a5bc43787ac8bf8f16683383f60265326f27 (diff) |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/cam/main.cpp | 10 | ||||
-rw-r--r-- | src/libcamera/camera.cpp | 8 | ||||
-rw-r--r-- | src/libcamera/include/pipeline_handler.h | 2 | ||||
-rw-r--r-- | src/libcamera/pipeline/ipu3/ipu3.cpp | 6 | ||||
-rw-r--r-- | src/libcamera/pipeline/uvcvideo.cpp | 6 | ||||
-rw-r--r-- | src/libcamera/pipeline/vimc.cpp | 6 |
6 files changed, 19 insertions, 19 deletions
diff --git a/src/cam/main.cpp b/src/cam/main.cpp index 8df8844c..13aa3596 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -75,10 +75,10 @@ static int parseOptions(int argc, char *argv[]) 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]; - Stream *id = streams.front(); + Stream *id = *streams.begin(); std::map<Stream *, StreamConfiguration> config = camera->streamConfiguration(streams); @@ -132,7 +132,7 @@ static int capture() { int ret; - std::vector<Stream *> streams = camera->streams(); + std::set<Stream *> streams = camera->streams(); std::vector<Request *> requests; ret = configureStreams(camera.get(), streams); @@ -141,7 +141,7 @@ static int capture() return ret; } - Stream *stream = streams.front(); + Stream *stream = *streams.begin(); ret = camera->allocateBuffers(); if (ret) { @@ -237,7 +237,7 @@ int main(int argc, char **argv) goto out; } - const std::vector<Stream *> &streams = camera->streams(); + const std::set<Stream *> &streams = camera->streams(); if (streams.size() != 1) { std::cout << "Camera has " << streams.size() << " streams, only 1 is supported" diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 3789732b..84b97b5c 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -66,7 +66,7 @@ LOG_DECLARE_CATEGORY(Camera) */ std::shared_ptr<Camera> Camera::create(PipelineHandler *pipe, const std::string &name, - const std::vector<Stream *> &streams) + const std::set<Stream *> &streams) { struct Allocator : std::allocator<Camera> { void construct(void *p, PipelineHandler *pipe, @@ -188,7 +188,7 @@ void Camera::release() * * \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_; } @@ -210,7 +210,7 @@ const std::vector<Stream *> &Camera::streams() const * empty list on error. */ std::map<Stream *, StreamConfiguration> -Camera::streamConfiguration(std::vector<Stream *> &streams) +Camera::streamConfiguration(std::set<Stream *> &streams) { if (disconnected_ || !streams.size()) return std::map<Stream *, StreamConfiguration>{}; @@ -264,7 +264,7 @@ int Camera::configureStreams(std::map<Stream *, StreamConfiguration> &config) const StreamConfiguration &cfg = iter.second; stream->configuration_ = cfg; - activeStreams_.push_back(stream); + activeStreams_.insert(stream); /* * Allocate buffer objects in the pool. diff --git a/src/libcamera/include/pipeline_handler.h b/src/libcamera/include/pipeline_handler.h index 4363dcd8..4cd9b90c 100644 --- a/src/libcamera/include/pipeline_handler.h +++ b/src/libcamera/include/pipeline_handler.h @@ -45,7 +45,7 @@ public: virtual bool match(DeviceEnumerator *enumerator) = 0; 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, std::map<Stream *, StreamConfiguration> &config) = 0; diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 9694d0ce..1066fbe3 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -32,7 +32,7 @@ public: std::map<Stream *, StreamConfiguration> streamConfiguration(Camera *camera, - std::vector<Stream *> &streams) override; + std::set<Stream *> &streams) override; int configureStreams(Camera *camera, std::map<Stream *, StreamConfiguration> &config) override; @@ -95,7 +95,7 @@ PipelineHandlerIPU3::~PipelineHandlerIPU3() std::map<Stream *, StreamConfiguration> PipelineHandlerIPU3::streamConfiguration(Camera *camera, - std::vector<Stream *> &streams) + std::set<Stream *> &streams) { IPU3CameraData *data = cameraData(camera); std::map<Stream *, StreamConfiguration> configs; @@ -374,7 +374,7 @@ void PipelineHandlerIPU3::registerCameras() std::unique_ptr<IPU3CameraData> data = utils::make_unique<IPU3CameraData>(); 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); /* diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index b7b8ff10..7b697c06 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -27,7 +27,7 @@ public: std::map<Stream *, StreamConfiguration> streamConfiguration(Camera *camera, - std::vector<Stream *> &streams) override; + std::set<Stream *> &streams) override; int configureStreams(Camera *camera, std::map<Stream *, StreamConfiguration> &config) override; @@ -63,7 +63,7 @@ PipelineHandlerUVC::~PipelineHandlerUVC() std::map<Stream *, StreamConfiguration> PipelineHandlerUVC::streamConfiguration(Camera *camera, - std::vector<Stream *> &streams) + std::set<Stream *> &streams) { std::map<Stream *, StreamConfiguration> configs; @@ -171,7 +171,7 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator) return false; } - std::vector<Stream *> streams{ &stream_ }; + std::set<Stream *> streams{ &stream_ }; std::shared_ptr<Camera> camera = Camera::create(this, media_->model(), streams); registerCamera(std::move(camera)); hotplugMediaDevice(media_.get()); diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp index 812777cf..9ba96323 100644 --- a/src/libcamera/pipeline/vimc.cpp +++ b/src/libcamera/pipeline/vimc.cpp @@ -27,7 +27,7 @@ public: std::map<Stream *, StreamConfiguration> streamConfiguration(Camera *camera, - std::vector<Stream *> &streams) override; + std::set<Stream *> &streams) override; int configureStreams(Camera *camera, std::map<Stream *, StreamConfiguration> &config) override; @@ -62,7 +62,7 @@ PipelineHandlerVimc::~PipelineHandlerVimc() std::map<Stream *, StreamConfiguration> PipelineHandlerVimc::streamConfiguration(Camera *camera, - std::vector<Stream *> &streams) + std::set<Stream *> &streams) { std::map<Stream *, StreamConfiguration> configs; @@ -171,7 +171,7 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator) return false; } - std::vector<Stream *> streams{ &stream_ }; + std::set<Stream *> streams{ &stream_ }; std::shared_ptr<Camera> camera = Camera::create(this, "VIMC Sensor B", streams); registerCamera(std::move(camera)); |