From patchwork Tue Jan 15 15:18:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 233 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 19E2660C78 for ; Tue, 15 Jan 2019 16:18:53 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 84BDA55C for ; Tue, 15 Jan 2019 16:18:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1547565532; bh=kdznshboMzFNLLFQJ+OaNhbXtZBIq03ilNd5xxWeZUk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=AiX1vnmpEwKCvJthZ+TTHUC7/g8dQD0bzW2FHynqAAPDSXsROIkuSK58blox3hgul 1eYgBNSwcQJ/corHu6A4mJ1RkWX8vv+J1CP6SXiTCSbwh/zI3E54dzicHBF/xqshpY W3nyIkM6nhYP/Cpr+ZZQCmotFfO3C/6xtdz/0MJc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 15 Jan 2019 17:18:42 +0200 Message-Id: <20190115151849.1547-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190115151849.1547-1-laurent.pinchart@ideasonboard.com> References: <20190115151849.1547-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/8] libcamera: pipeline_handler: Don't index factories by name 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, 15 Jan 2019 15:18:53 -0000 Pipeline handler factories are register in a map indexed by their name, and the list of names is used to expose the factories and look them up. This is unnecessary cumbersome, we can instead store factories in a vector and expose it directly. The pipeline factory users will still have access to the factory names through the factory name() function. The PipelineHandlerFactory::create() method becomes so simple that it can be inlined in its single caller, removing the unneeded usage of the DeviceEnumerator in the factory. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- Changes since v1: - ASSERT() factory name uniqueness --- src/libcamera/camera_manager.cpp | 22 +++--- src/libcamera/include/pipeline_handler.h | 29 ++++---- src/libcamera/pipeline_handler.cpp | 95 ++++++++---------------- 3 files changed, 57 insertions(+), 89 deletions(-) diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index be327f5d5638..91ef6753f405 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -74,20 +74,24 @@ int CameraManager::start() * file and only fallback on all handlers if there is no * configuration file. */ - std::vector handlers = PipelineHandlerFactory::handlers(); - - for (std::string const &handler : handlers) { - PipelineHandler *pipe; + std::vector &handlers = PipelineHandlerFactory::handlers(); + for (PipelineHandlerFactory *factory : handlers) { /* * Try each pipeline handler until it exhaust * all pipelines it can provide. */ - do { - pipe = PipelineHandlerFactory::create(handler, enumerator_); - if (pipe) - pipes_.push_back(pipe); - } while (pipe); + while (1) { + PipelineHandler *pipe = factory->create(); + if (!pipe->match(enumerator_)) { + delete pipe; + break; + } + + LOG(Debug) << "Pipeline handler \"" << factory->name() + << "\" matched"; + pipes_.push_back(pipe); + } } /* TODO: register hot-plug callback here */ diff --git a/src/libcamera/include/pipeline_handler.h b/src/libcamera/include/pipeline_handler.h index fdf8b8db2e0a..764dde9ccc65 100644 --- a/src/libcamera/include/pipeline_handler.h +++ b/src/libcamera/include/pipeline_handler.h @@ -31,29 +31,28 @@ public: class PipelineHandlerFactory { public: + PipelineHandlerFactory(const char *name); virtual ~PipelineHandlerFactory() { }; virtual PipelineHandler *create() = 0; - static void registerType(const std::string &name, PipelineHandlerFactory *factory); - static PipelineHandler *create(const std::string &name, DeviceEnumerator *enumerator); - static std::vector handlers(); + const std::string &name() const { return name_; } + + static void registerType(PipelineHandlerFactory *factory); + static std::vector &handlers(); private: - static std::map ®istry(); + std::string name_; }; -#define REGISTER_PIPELINE_HANDLER(handler) \ -class handler##Factory : public PipelineHandlerFactory { \ -public: \ - handler##Factory() \ - { \ - PipelineHandlerFactory::registerType(#handler, this); \ - } \ - virtual PipelineHandler *create() { \ - return new handler(); \ - } \ -}; \ +#define REGISTER_PIPELINE_HANDLER(handler) \ +class handler##Factory : public PipelineHandlerFactory { \ +public: \ + handler##Factory() : PipelineHandlerFactory(#handler) { } \ + PipelineHandler *create() final { \ + return new handler(); \ + } \ +}; \ static handler##Factory global_##handler##Factory; } /* namespace libcamera */ diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 1daada8653e2..08e3291e741a 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -5,7 +5,6 @@ * pipeline_handler.cpp - Pipeline handler infrastructure */ -#include "device_enumerator.h" #include "log.h" #include "pipeline_handler.h" @@ -40,7 +39,7 @@ namespace libcamera { * system * * This function is the main entry point of the pipeline handler. It is called - * by the device enumerator with the \a enumerator passed as an argument. It + * by the camera manager with the \a enumerator passed as an argument. It * shall acquire from the \a enumerator all the media devices it needs for a * single pipeline and create one or multiple Camera instances. * @@ -88,6 +87,21 @@ namespace libcamera { * static list of factories. */ +/** + * \brief Construct a pipeline handler factory + * \param[in] name Name of the pipeline handler class + * + * Creating an instance of the factory registers is with the global list of + * factories, accessible through the handlers() function. + * + * The factory \a name is used for debug purpose and shall be unique. + */ +PipelineHandlerFactory::PipelineHandlerFactory(const char *name) + : name_(name) +{ + registerType(this); +} + /** * \fn PipelineHandlerFactory::create() * \brief Create an instance of the PipelineHandler corresponding to the factory @@ -98,78 +112,29 @@ namespace libcamera { * subclass corresponding to the factory */ +/** + * \fn PipelineHandlerFactory::name() + * \brief Retrieve the factory name + * \return The factory name + */ + /** * \brief Add a pipeline handler class to the registry - * \param[in] name Name of the pipeline handler class * \param[in] factory Factory to use to construct the pipeline handler * * The caller is responsible to guarantee the uniqueness of the pipeline handler * name. */ -void PipelineHandlerFactory::registerType(const std::string &name, - PipelineHandlerFactory *factory) -{ - std::map &factories = registry(); - - if (factories.count(name)) { - LOG(Error) << "Registering '" << name << "' pipeline twice"; - return; - } - - LOG(Debug) << "Registered pipeline handler \"" << name << "\""; - factories[name] = factory; -} - -/** - * \brief Create an instance of a pipeline handler if it matches media devices - * present in the system - * \param[in] name Name of the pipeline handler to instantiate - * \param[in] enumerator Device enumerator to search for a match for the handler - * - * This function matches the media devices required by pipeline \a name against - * the devices enumerated by \a enumerator. - * - * \return the newly created pipeline handler instance if a match was found, or - * nullptr otherwise - */ -PipelineHandler *PipelineHandlerFactory::create(const std::string &name, - DeviceEnumerator *enumerator) +void PipelineHandlerFactory::registerType(PipelineHandlerFactory *factory) { - std::map &factories = registry(); - - auto it = factories.find(name); - if (it == factories.end()) { - LOG(Error) << "Trying to create non-existing pipeline handler " - << name; - return nullptr; - } - - PipelineHandler *pipe = it->second->create(); + std::vector &factories = handlers(); - if (pipe->match(enumerator)) { - LOG(Debug) << "Pipeline handler \"" << name << "\" matched"; - return pipe; - } - - delete pipe; - return nullptr; -} - -/** - * \brief Retrieve the names of all pipeline handlers registered with the - * factory - * - * \return a list of all registered pipeline handler names - */ -std::vector PipelineHandlerFactory::handlers() -{ - std::map &factories = registry(); - std::vector handlers; + for (PipelineHandlerFactory *f : factories) + ASSERT(factory->name() != f->name()); - for (auto const &handler : factories) - handlers.push_back(handler.first); + factories.push_back(factory); - return handlers; + LOG(Debug) << "Registered pipeline handler \"" << factory->name() << "\""; } /** @@ -180,9 +145,9 @@ std::vector PipelineHandlerFactory::handlers() * * \return the list of pipeline handler factories */ -std::map &PipelineHandlerFactory::registry() +std::vector &PipelineHandlerFactory::handlers() { - static std::map factories; + static std::vector factories; return factories; } From patchwork Tue Jan 15 15:18:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 234 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9550C60C85 for ; Tue, 15 Jan 2019 16:18:53 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D63AC4F8 for ; Tue, 15 Jan 2019 16:18:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1547565533; bh=PvkPS50fI1Ol84OE9MuOboJ5l+cRC6A2bdw/QI26BS4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MGNdMV0NeYO/rUZ+CZrps+BjkFH5D6MskxrOedwvxN50pM5ZYaYedg+BSIRHWc6U1 u0tJQthuaKhsWXGfp4NwaulVaf2X0GEadfwst5S3AwlbbHWzpsdLcM3YVA0t1x5DfK NJUVs5OFRBqhpIRGmua/vPRDbwC4S3JkJQNfiu6c= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 15 Jan 2019 17:18:43 +0200 Message-Id: <20190115151849.1547-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190115151849.1547-1-laurent.pinchart@ideasonboard.com> References: <20190115151849.1547-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/8] libcamera: camera_manager: Improve class documentation 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, 15 Jan 2019 15:18:53 -0000 Move documentation from the \file directive to the CameraManager class, as it documents the class, not the file. Improve the documentation to provide a brief overview of how the camera manager operates, and fix a few typos and inconsistencies. The documentation mentions hotplug even though it isn't implement yet, as this is a planned feature. More improvements are needed for the documentation of the CameraManager member functions, and will be added as part of the API improvements in the near future. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/camera_manager.cpp | 56 +++++++++++++++++++------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 91ef6753f405..4313994e97c8 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -15,30 +15,42 @@ /** * \file camera_manager.h - * \brief Manage all cameras handled by libcamera - * - * The responsibility of the camera manager is to control the lifetime - * management of objects provided by libcamera. - * - * When a user wish to interact with libcamera it creates and starts a - * CameraManager object. Once confirmed the camera manager is running - * the application can list all cameras detected by the library, get - * one or more of the cameras and interact with them. - * - * When the user is done with the camera it should be returned to the - * camera manager. Once all cameras are returned to the camera manager - * the user is free to stop the manager. - * - * \todo Add ability to add and remove media devices based on - * hot-(un)plug events coming from the device enumerator. - * - * \todo Add interface to register a notification callback to the user - * to be able to inform it new cameras have been hot-plugged or - * cameras have been removed due to hot-unplug. + * \brief The camera manager */ namespace libcamera { +/** + * \class CameraManager + * \brief Provide access and manage all cameras in the system + * + * The camera manager is the entry point to libcamera. Ii enumerates devices, + * associates them with pipeline managers, and provides access to the cameras + * in the system to applications. The manager owns all Camera objects and + * handles hot-plugging and hot-unplugging to manage the lifetime of cameras. + * + * To interact with libcamera, an application retrieves the camera manager + * instance with CameraManager::instance(). The manager is initially stopped, + * and shall be configured before being started. In particular a custom event + * dispatcher shall be installed if needed with + * CameraManager::setEventDispatcher(). + * + * Once the camera manager is configured, it shall be started with start(). + * This will enumerate all the cameras present in the system, which can then be + * listed with list() and retrieved with get(). + * + * Cameras are reference-counted, and shall be returned to the camera manager + * with Camera::put() after being used. Once all cameras have been returned to + * the manager, it can be stopped with stop(). + * + * \todo Add ability to add and remove media devices based on hot-(un)plug + * events coming from the device enumerator. + * + * \todo Add interface to register a notification callback to the user to be + * able to inform it new cameras have been hot-plugged or cameras have been + * removed due to hot-unplug. + */ + CameraManager::CameraManager() : enumerator_(nullptr), dispatcher_(nullptr) { @@ -57,7 +69,7 @@ CameraManager::~CameraManager() * interact with cameras in the system until either the camera manager * is stopped or the camera is unplugged from the system. * - * \return true on successful start false otherwise + * \return 0 on successful start, or a negative error code otherwise */ int CameraManager::start() { @@ -102,7 +114,7 @@ int CameraManager::start() /** * \brief Stop the camera manager * - * Before stopping the camera manger the caller is responsible for making + * Before stopping the camera manager the caller is responsible for making * sure all cameras provided by the manager are returned to the manager. * * After the manager has been stopped no resource provided by the camera From patchwork Tue Jan 15 15:18:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 235 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E321D60C85 for ; Tue, 15 Jan 2019 16:18:53 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 833B255C for ; Tue, 15 Jan 2019 16:18:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1547565533; bh=ekM0Z/f9B5RgrZ0tUGeGD0I57RnbOD8gy7RoQTNGyHA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=V/y3WgZJMxkrHaW6c+qppMbycoyAO77WIL3s1XDcxIX9oODWcFq3CJ53K9FXIsBKr p2X36z7l0XWiIkc7siMdeIcqxD58fjwUyKNp7QH6AHLQDHcmSuiqgJwGLrmwW+dZcl fOWZlEkFc8PObeVlrUg+RXzyyDG22dFfttwgeWBw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 15 Jan 2019 17:18:44 +0200 Message-Id: <20190115151849.1547-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190115151849.1547-1-laurent.pinchart@ideasonboard.com> References: <20190115151849.1547-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/8] Documentation: Exclude pipeline handlers directory 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, 15 Jan 2019 15:18:54 -0000 The pipeline handlers don't define APIs, neither public not internal. There is thus no need to generate Doxygen documentation from thoses classes. Add them to the EXCLUDE files pattern. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- Documentation/Doxyfile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/Doxyfile.in b/Documentation/Doxyfile.in index 5c0d87baac9c..dd74b7295d50 100644 --- a/Documentation/Doxyfile.in +++ b/Documentation/Doxyfile.in @@ -833,7 +833,7 @@ RECURSIVE = YES # Note that relative paths are relative to the directory from which doxygen is # run. -EXCLUDE = +EXCLUDE = ../src/libcamera/pipeline/ # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded From patchwork Tue Jan 15 15:18:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 236 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 49D3A60C87 for ; Tue, 15 Jan 2019 16:18:54 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D06C24F8 for ; Tue, 15 Jan 2019 16:18:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1547565534; bh=rPg7O5lAfsSHYGN90ySpf8AE5T1imF3N1ZckaPWjuqg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ALSDMgx+WDKKdIgGFAM3cjPV/UYYJSOY9wCSqqSoWuxiNSIs6ZE9qy0pAei4Zj3c4 78qJyjMKgBJ/7J1Rc7btvnCemUtd8jcsesHBZ7jv+uPHP3otkcQ6m3/D1jghAsdFJM hYwctNaCKsUeux2Gy3pJi/FdtCMB3di6xdOaewu4= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 15 Jan 2019 17:18:45 +0200 Message-Id: <20190115151849.1547-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190115151849.1547-1-laurent.pinchart@ideasonboard.com> References: <20190115151849.1547-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/8] libcamera: pipeline_handler: Rename handlers() method to factories() 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, 15 Jan 2019 15:18:55 -0000 The PipelineHandlerFactory::handlers() static method returns a list of factories, not a list of handlers. Rename it accordingly. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/camera_manager.cpp | 4 ++-- src/libcamera/include/pipeline_handler.h | 2 +- src/libcamera/pipeline_handler.cpp | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 4313994e97c8..a17bf3d13a04 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -86,9 +86,9 @@ int CameraManager::start() * file and only fallback on all handlers if there is no * configuration file. */ - std::vector &handlers = PipelineHandlerFactory::handlers(); + std::vector &factories = PipelineHandlerFactory::factories(); - for (PipelineHandlerFactory *factory : handlers) { + for (PipelineHandlerFactory *factory : factories) { /* * Try each pipeline handler until it exhaust * all pipelines it can provide. diff --git a/src/libcamera/include/pipeline_handler.h b/src/libcamera/include/pipeline_handler.h index 764dde9ccc65..e976aaa13546 100644 --- a/src/libcamera/include/pipeline_handler.h +++ b/src/libcamera/include/pipeline_handler.h @@ -39,7 +39,7 @@ public: const std::string &name() const { return name_; } static void registerType(PipelineHandlerFactory *factory); - static std::vector &handlers(); + static std::vector &factories(); private: std::string name_; diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 08e3291e741a..4dfbc814a813 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -92,7 +92,7 @@ namespace libcamera { * \param[in] name Name of the pipeline handler class * * Creating an instance of the factory registers is with the global list of - * factories, accessible through the handlers() function. + * factories, accessible through the factories() function. * * The factory \a name is used for debug purpose and shall be unique. */ @@ -127,7 +127,7 @@ PipelineHandlerFactory::PipelineHandlerFactory(const char *name) */ void PipelineHandlerFactory::registerType(PipelineHandlerFactory *factory) { - std::vector &factories = handlers(); + std::vector &factories = PipelineHandlerFactory::factories(); for (PipelineHandlerFactory *f : factories) ASSERT(factory->name() != f->name()); @@ -145,7 +145,7 @@ void PipelineHandlerFactory::registerType(PipelineHandlerFactory *factory) * * \return the list of pipeline handler factories */ -std::vector &PipelineHandlerFactory::handlers() +std::vector &PipelineHandlerFactory::factories() { static std::vector factories; return factories; From patchwork Tue Jan 15 15:18:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 237 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B92CD60C8A for ; Tue, 15 Jan 2019 16:18:54 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3788F55C for ; Tue, 15 Jan 2019 16:18:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1547565534; bh=86w73yrQP8oVbkVs6Ize57x9ATcWJzgN7QUsWxdYHzg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=BV0ZTb0Dy8JswujkQ+nSoCic6cawwdr/mHn23pCEf3q9iv3d1TnbwCMX57HHpv6Ey NlFmlWoXhJ1mBMSSOxEx1FWElpLiqVLorlsZ6P8ISD3cJzcuYjBfhROcsI/ShyEuxW G3PD5m9UQzspJJdrKAhfM3CHFath2zlDuh6mkK+U= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 15 Jan 2019 17:18:46 +0200 Message-Id: <20190115151849.1547-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190115151849.1547-1-laurent.pinchart@ideasonboard.com> References: <20190115151849.1547-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 5/8] libcamera: event_dispatcher_poll: Constify argument to processNotifiers 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, 15 Jan 2019 15:18:55 -0000 The EventDispatcherPoll::processNotifiers() function doesn't modify the argument it receives, make it const. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/event_dispatcher_poll.cpp | 2 +- src/libcamera/include/event_dispatcher_poll.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcamera/event_dispatcher_poll.cpp b/src/libcamera/event_dispatcher_poll.cpp index a497a7fe9177..69edfcbf2725 100644 --- a/src/libcamera/event_dispatcher_poll.cpp +++ b/src/libcamera/event_dispatcher_poll.cpp @@ -173,7 +173,7 @@ short EventDispatcherPoll::EventNotifierSetPoll::events() const return events; } -void EventDispatcherPoll::processNotifiers(std::vector &pollfds) +void EventDispatcherPoll::processNotifiers(const std::vector &pollfds) { static const struct { EventNotifier::Type type; diff --git a/src/libcamera/include/event_dispatcher_poll.h b/src/libcamera/include/event_dispatcher_poll.h index 30fd58506d6b..a41926e11a11 100644 --- a/src/libcamera/include/event_dispatcher_poll.h +++ b/src/libcamera/include/event_dispatcher_poll.h @@ -41,7 +41,7 @@ private: std::map notifiers_; std::list timers_; - void processNotifiers(std::vector &pollfds); + void processNotifiers(const std::vector &pollfds); void processTimers(); }; From patchwork Tue Jan 15 15:18:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 238 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3CFDC60C8A for ; Tue, 15 Jan 2019 16:18:55 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CDC7B59B for ; Tue, 15 Jan 2019 16:18:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1547565534; bh=Cz7Czp6CfYmmIFFQEF9MrZkpYtp+3MczlcvN8f3bK2M=; h=From:To:Subject:Date:In-Reply-To:References:From; b=meaDl+JGkcAZcGOgsprs4u3aF3rVvGgyTuE+A7JFm/Bs3yQozi19h+DAFztQAnog0 A9U1x+5BogyDeLBg22k4cheVeIfT8dfMb8BD0GC52nO9gXdTGMLDqugGRwykZr8qqP vZQ9KbRh7di8F7A24msRTTIHbdp9Tp+/az0Hp97Q= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 15 Jan 2019 17:18:47 +0200 Message-Id: <20190115151849.1547-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190115151849.1547-1-laurent.pinchart@ideasonboard.com> References: <20190115151849.1547-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 6/8] libcamera: device_enumerator: Don't mark the search() function as const 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, 15 Jan 2019 15:18:55 -0000 While the DeviceEnumerator::search() function doesn't modify the instance directly, it returns a non-const pointer to a MediaEntity that is owned by the DeviceEnumerator instance. This breaks the const semantics. Don't mark the function as const. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/device_enumerator.cpp | 2 +- src/libcamera/include/device_enumerator.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp index 1653e4f4651a..18d7e86843e8 100644 --- a/src/libcamera/device_enumerator.cpp +++ b/src/libcamera/device_enumerator.cpp @@ -245,7 +245,7 @@ int DeviceEnumerator::addDevice(const std::string &devnode) * * \return pointer to the matching MediaDevice, or nullptr if no match is found */ -MediaDevice *DeviceEnumerator::search(const DeviceMatch &dm) const +MediaDevice *DeviceEnumerator::search(const DeviceMatch &dm) { for (MediaDevice *dev : devices_) { if (dev->busy()) diff --git a/src/libcamera/include/device_enumerator.h b/src/libcamera/include/device_enumerator.h index 29737da7a225..b68c815827dd 100644 --- a/src/libcamera/include/device_enumerator.h +++ b/src/libcamera/include/device_enumerator.h @@ -41,7 +41,7 @@ public: virtual int init() = 0; virtual int enumerate() = 0; - MediaDevice *search(const DeviceMatch &dm) const; + MediaDevice *search(const DeviceMatch &dm); protected: int addDevice(const std::string &devnode); From patchwork Tue Jan 15 15:18:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 239 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8F51F60C8A for ; Tue, 15 Jan 2019 16:18:55 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 29DA59DC for ; Tue, 15 Jan 2019 16:18:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1547565535; bh=EeHx7F4G3g+r7yLlZuozFoIBtaBP7srRW00d+LqYPTs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=evye7kJuD2rThzwK6qlpYRxI63CoO+bEGaYgbOw8sMgPMBx7oDdk5JMLAPNUdmAte ql1y5NSR8NgQeZ3sdmfCFoBE8Mmh8WMjNg0/mbEfcgWXxL1zjsgOFm9IDvzWk8djMr /rXIVWytlIxWIuD6qhmbKkp3w6IuOAKEE8cf6FqY= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 15 Jan 2019 17:18:48 +0200 Message-Id: <20190115151849.1547-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190115151849.1547-1-laurent.pinchart@ideasonboard.com> References: <20190115151849.1547-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 7/8] libcamera: utils: Implement C++14 make_unique<>() 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, 15 Jan 2019 15:18:55 -0000 C++14 introduces std::make_unique<>() that makes it easier to initialize unique_ptr<> instances. As libcamera is limited to C++11, implement our own version of the function in the libcamera::utils namespace. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/include/utils.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h index 3ffa6f4ea591..a2e450b35372 100644 --- a/src/libcamera/include/utils.h +++ b/src/libcamera/include/utils.h @@ -7,6 +7,19 @@ #ifndef __LIBCAMERA_UTILS_H__ #define __LIBCAMERA_UTILS_H__ +#include + #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) +namespace libcamera::utils { + +/* C++11 doesn't provide std::make_unique */ +template +std::unique_ptr make_unique(Args&&... args) +{ + return std::unique_ptr(new T(std::forward(args)...)); +} + +} /* namespace libcamera::utils */ + #endif /* __LIBCAMERA_UTILS_H__ */ From patchwork Tue Jan 15 15:18:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 240 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DF5F860C8A for ; Tue, 15 Jan 2019 16:18:55 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 77C2E4F8 for ; Tue, 15 Jan 2019 16:18:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1547565535; bh=wIyEthRVn+dkk80COo3O7gLrLmoXEdkapwc5+9KikkM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=M1cStOQC2WpS7oAOPF5zPQ/FZMis6Rx6DZV0mrl4b9txmGXlotDdkhdKMZkU3EqvN ojJhsaLJcQfGFEfwDjuiLHcSu9Z9tQB7VwTASuTP9XgEMayU9VBPHNRK9cI9PoRUd+ YVmigf9ARQyWF5VGcNEv7IPtc49qAWirQl0rhrjo= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 15 Jan 2019 17:18:49 +0200 Message-Id: <20190115151849.1547-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190115151849.1547-1-laurent.pinchart@ideasonboard.com> References: <20190115151849.1547-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 8/8] libcamera: camera_manager: Turn enumerator into a unique_ptr<> 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, 15 Jan 2019 15:18:56 -0000 Convey the fact that the CameraManager class owns the DeviceEnumerator instance it creates by using std::unique_ptr<> to store the pointer. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- include/libcamera/camera_manager.h | 3 ++- src/libcamera/camera_manager.cpp | 8 ++------ src/libcamera/device_enumerator.cpp | 9 ++++----- src/libcamera/include/device_enumerator.h | 3 ++- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h index 15e7c162032a..6cfcba3c3933 100644 --- a/include/libcamera/camera_manager.h +++ b/include/libcamera/camera_manager.h @@ -7,6 +7,7 @@ #ifndef __LIBCAMERA_CAMERA_MANAGER_H__ #define __LIBCAMERA_CAMERA_MANAGER_H__ +#include #include #include @@ -37,7 +38,7 @@ private: void operator=(const CameraManager &) = delete; ~CameraManager(); - DeviceEnumerator *enumerator_; + std::unique_ptr enumerator_; std::vector pipes_; EventDispatcher *dispatcher_; diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index a17bf3d13a04..ae5542bc332d 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -73,7 +73,6 @@ CameraManager::~CameraManager() */ int CameraManager::start() { - if (enumerator_) return -ENODEV; @@ -95,7 +94,7 @@ int CameraManager::start() */ while (1) { PipelineHandler *pipe = factory->create(); - if (!pipe->match(enumerator_)) { + if (!pipe->match(enumerator_.get())) { delete pipe; break; } @@ -130,10 +129,7 @@ void CameraManager::stop() pipes_.clear(); - if (enumerator_) - delete enumerator_; - - enumerator_ = nullptr; + enumerator_.reset(nullptr); } /** diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp index 18d7e86843e8..55c510e3b79a 100644 --- a/src/libcamera/device_enumerator.cpp +++ b/src/libcamera/device_enumerator.cpp @@ -14,6 +14,7 @@ #include "device_enumerator.h" #include "log.h" #include "media_device.h" +#include "utils.h" /** * \file device_enumerator.h @@ -128,20 +129,18 @@ bool DeviceMatch::match(const MediaDevice *device) const * \return A pointer to the newly created device enumerator on success, or * nullptr if an error occurs */ -DeviceEnumerator *DeviceEnumerator::create() +std::unique_ptr DeviceEnumerator::create() { - DeviceEnumerator *enumerator; + std::unique_ptr enumerator; /** * \todo Add compile time checks to only try udev enumerator if libudev * is available. */ - enumerator = new DeviceEnumeratorUdev(); + enumerator = utils::make_unique(); if (!enumerator->init()) return enumerator; - delete enumerator; - /* * Either udev is not available or udev initialization failed. Fall back * on the sysfs enumerator. diff --git a/src/libcamera/include/device_enumerator.h b/src/libcamera/include/device_enumerator.h index b68c815827dd..c5541c5f8d12 100644 --- a/src/libcamera/include/device_enumerator.h +++ b/src/libcamera/include/device_enumerator.h @@ -8,6 +8,7 @@ #define __LIBCAMERA_DEVICE_ENUMERATOR_H__ #include +#include #include #include @@ -34,7 +35,7 @@ private: class DeviceEnumerator { public: - static DeviceEnumerator *create(); + static std::unique_ptr create(); virtual ~DeviceEnumerator();