From patchwork Tue Feb 26 02:18:55 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: 627 Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7DB67601E2 for ; Tue, 26 Feb 2019 03:19:25 +0100 (CET) X-Halon-ID: ef0531c2-396c-11e9-985a-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id ef0531c2-396c-11e9-985a-005056917f90; Tue, 26 Feb 2019 03:19:24 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Feb 2019 03:18:55 +0100 Message-Id: <20190226021857.28255-7-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190226021857.28255-1-niklas.soderlund@ragnatech.se> References: <20190226021857.28255-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 6/8] 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: Tue, 26 Feb 2019 02:19:25 -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 grantees 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 | 10 +++++----- 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, 26 insertions(+), 25 deletions(-) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 8c8545b074e8ae13..1e75a6dafa4e7c5f 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(); @@ -73,8 +74,8 @@ private: std::shared_ptr pipe_; std::string name_; - std::vector streams_; - std::vector activeStreams_; + std::set streams_; + std::set activeStreams_; State state_; }; 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 c50b14bbd904fc1c..938f21fe80ef8ceb 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, @@ -223,10 +223,10 @@ void Camera::release() * * \return An array of all the camera's streams. */ -const std::vector &Camera::streams() const +const std::set &Camera::streams() const { if (!stateIsAtleast(Free)) - std::vector{}; + std::set{}; return streams_; } @@ -248,7 +248,7 @@ const std::vector &Camera::streams() const * empty list on error. */ std::map -Camera::streamConfiguration(std::vector &streams) +Camera::streamConfiguration(std::set &streams) { if (!stateIsAtleast(Free) || !streams.size()) return std::map{}; @@ -300,7 +300,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));