From patchwork Thu Feb 28 18:51:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 666 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 82583610BB for ; Thu, 28 Feb 2019 19:51:39 +0100 (CET) X-Halon-ID: df50643b-3b89-11e9-8144-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id df50643b-3b89-11e9-8144-0050569116f7; Thu, 28 Feb 2019 19:51:35 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Feb 2019 19:51:25 +0100 Message-Id: <20190228185126.32475-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190228185126.32475-1-niklas.soderlund@ragnatech.se> References: <20190228185126.32475-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/3] libcamera: store stream pointers in sets instead of a vectors X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Feb 2019 18:51:40 -0000 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 Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- include/libcamera/camera.h | 11 ++++++----- src/cam/main.cpp | 10 +++++----- src/libcamera/camera.cpp | 8 ++++---- src/libcamera/include/pipeline_handler.h | 2 +- src/libcamera/pipeline/ipu3/ipu3.cpp | 6 +++--- src/libcamera/pipeline/uvcvideo.cpp | 6 +++--- src/libcamera/pipeline/vimc.cpp | 6 +++--- 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index bf70255a6a5ea364..9c8ae01ed5c607f1 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -27,7 +28,7 @@ class Camera final public: static std::shared_ptr create(PipelineHandler *pipe, const std::string &name, - const std::vector &streams); + const std::set &streams); Camera(const Camera &) = delete; Camera &operator=(const Camera &) = delete; @@ -40,9 +41,9 @@ public: int acquire(); void release(); - const std::vector &streams() const; + const std::set &streams() const; std::map - streamConfiguration(std::vector &streams); + streamConfiguration(std::set &streams); int configureStreams(std::map &config); int allocateBuffers(); @@ -64,8 +65,8 @@ private: std::shared_ptr pipe_; std::string name_; - std::vector streams_; - std::vector activeStreams_; + std::set streams_; + std::set activeStreams_; bool acquired_; bool disconnected_; diff --git a/src/cam/main.cpp b/src/cam/main.cpp index 8df8844c33a2d052..13aa35968f38964d 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 &streams) +static int configureStreams(Camera *camera, std::set &streams) { KeyValueParser::Options format = options[OptFormat]; - Stream *id = streams.front(); + Stream *id = *streams.begin(); std::map config = camera->streamConfiguration(streams); @@ -132,7 +132,7 @@ static int capture() { int ret; - std::vector streams = camera->streams(); + std::set streams = camera->streams(); std::vector 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 &streams = camera->streams(); + const std::set &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 3789732b95d1ae38..84b97b5c2ce94ecf 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -66,7 +66,7 @@ LOG_DECLARE_CATEGORY(Camera) */ std::shared_ptr Camera::create(PipelineHandler *pipe, const std::string &name, - const std::vector &streams) + const std::set &streams) { struct Allocator : std::allocator { 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 &Camera::streams() const +const std::set &Camera::streams() const { return streams_; } @@ -210,7 +210,7 @@ const std::vector &Camera::streams() const * empty list on error. */ std::map -Camera::streamConfiguration(std::vector &streams) +Camera::streamConfiguration(std::set &streams) { if (disconnected_ || !streams.size()) return std::map{}; @@ -264,7 +264,7 @@ int Camera::configureStreams(std::map &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 4363dcd8ed8ead97..4cd9b90c609c067e 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 - streamConfiguration(Camera *camera, std::vector &streams) = 0; + streamConfiguration(Camera *camera, std::set &streams) = 0; virtual int configureStreams(Camera *camera, std::map &config) = 0; diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 9694d0ce51abda41..1066fbe350d934a0 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -32,7 +32,7 @@ public: std::map streamConfiguration(Camera *camera, - std::vector &streams) override; + std::set &streams) override; int configureStreams(Camera *camera, std::map &config) override; @@ -95,7 +95,7 @@ PipelineHandlerIPU3::~PipelineHandlerIPU3() std::map PipelineHandlerIPU3::streamConfiguration(Camera *camera, - std::vector &streams) + std::set &streams) { IPU3CameraData *data = cameraData(camera); std::map configs; @@ -374,7 +374,7 @@ void PipelineHandlerIPU3::registerCameras() std::unique_ptr data = utils::make_unique(); std::string cameraName = sensor->name() + " " + std::to_string(id); - std::vector streams{ &data->stream_ }; + std::set streams{ &data->stream_ }; std::shared_ptr camera = Camera::create(this, cameraName, streams); /* diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index b7b8ff109109e9c5..7b697c0685630d92 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -27,7 +27,7 @@ public: std::map streamConfiguration(Camera *camera, - std::vector &streams) override; + std::set &streams) override; int configureStreams(Camera *camera, std::map &config) override; @@ -63,7 +63,7 @@ PipelineHandlerUVC::~PipelineHandlerUVC() std::map PipelineHandlerUVC::streamConfiguration(Camera *camera, - std::vector &streams) + std::set &streams) { std::map configs; @@ -171,7 +171,7 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator) return false; } - std::vector streams{ &stream_ }; + std::set streams{ &stream_ }; std::shared_ptr 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 812777cffbb3e618..9ba96323d335e010 100644 --- a/src/libcamera/pipeline/vimc.cpp +++ b/src/libcamera/pipeline/vimc.cpp @@ -27,7 +27,7 @@ public: std::map streamConfiguration(Camera *camera, - std::vector &streams) override; + std::set &streams) override; int configureStreams(Camera *camera, std::map &config) override; @@ -62,7 +62,7 @@ PipelineHandlerVimc::~PipelineHandlerVimc() std::map PipelineHandlerVimc::streamConfiguration(Camera *camera, - std::vector &streams) + std::set &streams) { std::map configs; @@ -171,7 +171,7 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator) return false; } - std::vector streams{ &stream_ }; + std::set streams{ &stream_ }; std::shared_ptr camera = Camera::create(this, "VIMC Sensor B", streams); registerCamera(std::move(camera));