From patchwork Thu Aug 5 22:24:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13236 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id C2DACC323A for ; Thu, 5 Aug 2021 22:25:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 66E1968895; Fri, 6 Aug 2021 00:25:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="VHxV8Dfp"; dkim-atps=neutral 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 655BD68822 for ; Fri, 6 Aug 2021 00:24:57 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0E5A54FB for ; Fri, 6 Aug 2021 00:24:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1628202297; bh=tA70Jm1PhQtLiTq4CyO7ypsCxUHXhDkeVN832Xlpx54=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VHxV8DfpUKQ6zhWRGxjaX/SH1w1ZmPXvH0qIQjfr3RHFlI2m/4ALhFii92P/GVt3p KT4V0FOEvtYL4ogk1fKwGvlIrIAN32Kr3CuCJpADazfX9Qt+DpVOKcqP+vDe7lWxma OtyrR5qTpyKNMzglnOXNCsqnsbOkJ1Iq5dqKPErI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Aug 2021 01:24:31 +0300 Message-Id: <20210805222436.6263-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210805222436.6263-1-laurent.pinchart@ideasonboard.com> References: <20210805222436.6263-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 05/10] libcamera: pipeline: simple: Store all entity devices in common map X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Merge the SimplePipelineHandler videos_ and subdevs_ maps, which respectively store V4L2 video devices and subdevices associated with entities, into a single entities_ map that contains an EntityData structure. This gathers all data about entities in a single place, allowing for easy extension of entity data in the future. Signed-off-by: Laurent Pinchart --- src/libcamera/pipeline/simple/simple.cpp | 63 +++++++++++++----------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 99ecd640349c..6b808bfbe6fa 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -265,6 +265,11 @@ protected: private: static constexpr unsigned int kNumInternalBuffers = 3; + struct EntityData { + std::unique_ptr video; + std::unique_ptr subdev; + }; + SimpleCameraData *cameraData(const Camera *camera) { return static_cast( @@ -278,8 +283,7 @@ private: void converterOutputDone(FrameBuffer *buffer); MediaDevice *media_; - std::map> videos_; - std::map subdevs_; + std::map entities_; std::unique_ptr converter_; @@ -1064,24 +1068,25 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator) return false; /* - * Create and open V4L2Subdevice instances for all entities - * corresponding to a V4L2 subdevice. + * Insert all entities in the global entities list. Create and open + * V4L2Subdevice instances for each entity corresponding to a V4L2 + * subdevice. */ for (MediaEntity *entity : entities) { - if (entity->type() != MediaEntity::Type::V4L2Subdevice) - continue; + std::unique_ptr subdev; - auto elem = subdevs_.emplace(std::piecewise_construct, - std::forward_as_tuple(entity), - std::forward_as_tuple(entity)); - V4L2Subdevice *subdev = &elem.first->second; - int ret = subdev->open(); - if (ret < 0) { - LOG(SimplePipeline, Error) - << "Failed to open " << subdev->deviceNode() - << ": " << strerror(-ret); - return false; + if (entity->type() == MediaEntity::Type::V4L2Subdevice) { + subdev = std::make_unique(entity); + int ret = subdev->open(); + if (ret < 0) { + LOG(SimplePipeline, Error) + << "Failed to open " << subdev->deviceNode() + << ": " << strerror(-ret); + return false; + } } + + entities_[entity] = { nullptr, std::move(subdev) }; } /* Initialize each pipeline and register a corresponding camera. */ @@ -1114,28 +1119,30 @@ V4L2VideoDevice *SimplePipelineHandler::video(const MediaEntity *entity) * by constructing a new one. */ - auto iter = videos_.find(entity); - if (iter != videos_.end()) - return iter->second.get(); + auto iter = entities_.find(entity); + if (iter == entities_.end()) + return nullptr; + + EntityData &data = iter->second; + if (data.video) + return data.video.get(); - std::unique_ptr video = - std::make_unique(entity); - if (video->open() < 0) + data.video = std::make_unique(entity); + if (data.video->open() < 0) return nullptr; - video->bufferReady.connect(this, &SimplePipelineHandler::bufferReady); + data.video->bufferReady.connect(this, &SimplePipelineHandler::bufferReady); - auto element = videos_.emplace(entity, std::move(video)); - return element.first->second.get(); + return data.video.get(); } V4L2Subdevice *SimplePipelineHandler::subdev(const MediaEntity *entity) { - auto iter = subdevs_.find(entity); - if (iter == subdevs_.end()) + auto iter = entities_.find(entity); + if (iter == entities_.end()) return nullptr; - return &iter->second; + return iter->second.subdev.get(); } /* -----------------------------------------------------------------------------