From patchwork Tue Jan 1 21:23:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 119 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 58A3160B35 for ; Tue, 1 Jan 2019 22:22:34 +0100 (CET) Received: from avalon.bb.dnainternet.fi (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 447E41173 for ; Tue, 1 Jan 2019 22:22:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1546377753; bh=sa3t6/qnse81eA4bkgYTY1VKOtsQY67ejkpXV05OzMA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DBZSMR1hzBkxICjkjGDp+AclGn07+LB6C0T+Vknpo4mAX8ZICUfEJ12w1VpAkPUw7 P9Pk4mEt2PGsOj+q8eg/N/vkCptcqgzdwsHdETCRlOYyYX2vW9W/yiQYidSXLkjpAg BaHxCozXf7yu8fSiEPxfbuiOp7uO2CPsm1siXF0c= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 1 Jan 2019 23:23:27 +0200 Message-Id: <20190101212328.18361-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190101212328.18361-1-laurent.pinchart@ideasonboard.com> References: <20190101212328.18361-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/4] libcamera: mediadevice: Reorder functions in declaration order 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, 01 Jan 2019 21:22:34 -0000 In order to simplify navigation in the .cpp file, order functions in the declaration order in the .h file. Signed-off-by: Laurent Pinchart Acked-by: Kieran Bingham --- src/libcamera/media_device.cpp | 356 ++++++++++++++++----------------- 1 file changed, 178 insertions(+), 178 deletions(-) diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index fd5a31746075..4c77d3787391 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -70,38 +70,6 @@ MediaDevice::~MediaDevice() clear(); } -/** - * \fn MediaDevice::driver() - * \brief Retrieve the media device driver name - * \return The name of the kernel driver that handles the MediaDevice - */ - -/** - * \fn MediaDevice::devnode() - * \brief Retrieve the media device device node path - * \return The MediaDevice devnode path - */ - -/** - * \brief Delete all media objects in the MediaDevice. - * - * Delete all MediaEntities; entities will then delete their pads, - * and each source pad will delete links. - * - * After this function has been called, the media graph will be unpopulated - * and its media objects deleted. The media device has to be populated - * before it could be used again. - */ -void MediaDevice::clear() -{ - for (auto const &o : objects_) - delete o.second; - - objects_.clear(); - entities_.clear(); - valid_ = false; -} - /** * \brief Open a media device and retrieve informations from it * @@ -154,152 +122,6 @@ void MediaDevice::close() fd_ = -1; } -/** - * \fn MediaDevice::entities() - * \brief Retrieve the list of entities in the media graph - * \return The list of MediaEntities registered in the MediaDevice - */ - -/* - * Add a new object to the global objects pool and fail if the object - * has already been registered. - */ -bool MediaDevice::addObject(MediaObject *obj) -{ - - if (objects_.find(obj->id()) != objects_.end()) { - LOG(Error) << "Element with id " << obj->id() - << " already enumerated."; - return false; - } - - objects_[obj->id()] = obj; - - return true; -} - -/* - * MediaObject pool lookup by id. - */ -MediaObject *MediaDevice::object(unsigned int id) -{ - auto it = objects_.find(id); - return (it == objects_.end()) ? nullptr : it->second; -} - -/** - * \brief Return the MediaEntity with name \a name - * \param name The entity name - * \return The entity with \a name - * \return nullptr if no entity with \a name is found - */ -MediaEntity *MediaDevice::getEntityByName(const std::string &name) -{ - for (MediaEntity *e : entities_) - if (e->name() == name) - return e; - - return nullptr; -} - -bool MediaDevice::populateLinks(const struct media_v2_topology &topology) -{ - media_v2_link *mediaLinks = reinterpret_cast - (topology.ptr_links); - - for (unsigned int i = 0; i < topology.num_links; ++i) { - /* - * Skip links between entities and interfaces: we only care - * about pad-2-pad links here. - */ - if ((mediaLinks[i].flags & MEDIA_LNK_FL_LINK_TYPE) == - MEDIA_LNK_FL_INTERFACE_LINK) - continue; - - /* Store references to source and sink pads in the link. */ - unsigned int source_id = mediaLinks[i].source_id; - MediaPad *source = dynamic_cast - (object(source_id)); - if (!source) { - LOG(Error) << "Failed to find pad with id: " - << source_id; - return false; - } - - unsigned int sink_id = mediaLinks[i].sink_id; - MediaPad *sink = dynamic_cast - (object(sink_id)); - if (!sink) { - LOG(Error) << "Failed to find pad with id: " - << sink_id; - return false; - } - - MediaLink *link = new MediaLink(&mediaLinks[i], source, sink); - if (!addObject(link)) { - delete link; - return false; - } - - source->addLink(link); - sink->addLink(link); - } - - return true; -} - -bool MediaDevice::populatePads(const struct media_v2_topology &topology) -{ - media_v2_pad *mediaPads = reinterpret_cast - (topology.ptr_pads); - - for (unsigned int i = 0; i < topology.num_pads; ++i) { - unsigned int entity_id = mediaPads[i].entity_id; - - /* Store a reference to this MediaPad in entity. */ - MediaEntity *mediaEntity = dynamic_cast - (object(entity_id)); - if (!mediaEntity) { - LOG(Error) << "Failed to find entity with id: " - << entity_id; - return false; - } - - MediaPad *pad = new MediaPad(&mediaPads[i], mediaEntity); - if (!addObject(pad)) { - delete pad; - return false; - } - - mediaEntity->addPad(pad); - } - - return true; -} - -/* - * For each entity in the media graph create a MediaEntity and store a - * reference in the MediaObject global pool and in the global vector of - * entities. - */ -bool MediaDevice::populateEntities(const struct media_v2_topology &topology) -{ - media_v2_entity *mediaEntities = reinterpret_cast - (topology.ptr_entities); - - for (unsigned int i = 0; i < topology.num_entities; ++i) { - MediaEntity *entity = new MediaEntity(&mediaEntities[i]); - if (!addObject(entity)) { - delete entity; - return false; - } - - entities_.push_back(entity); - } - - return true; -} - /** * \brief Populate the media graph with media objects * @@ -380,15 +202,193 @@ int MediaDevice::populate() * \return true if the media graph is valid, false otherwise */ +/** + * \fn MediaDevice::driver() + * \brief Retrieve the media device driver name + * \return The name of the kernel driver that handles the MediaDevice + */ + +/** + * \fn MediaDevice::devnode() + * \brief Retrieve the media device device node path + * \return The MediaDevice devnode path + */ + +/** + * \fn MediaDevice::entities() + * \brief Retrieve the list of entities in the media graph + * \return The list of MediaEntities registered in the MediaDevice + */ + +/** + * \brief Return the MediaEntity with name \a name + * \param name The entity name + * \return The entity with \a name + * \return nullptr if no entity with \a name is found + */ +MediaEntity *MediaDevice::getEntityByName(const std::string &name) +{ + for (MediaEntity *e : entities_) + if (e->name() == name) + return e; + + return nullptr; +} + /** * \var MediaDevice::objects_ * \brief Global map of media objects (entities, pads, links) keyed by their * object id. */ +/* + * MediaObject pool lookup by id. + */ +MediaObject *MediaDevice::object(unsigned int id) +{ + auto it = objects_.find(id); + return (it == objects_.end()) ? nullptr : it->second; +} + +/* + * Add a new object to the global objects pool and fail if the object + * has already been registered. + */ +bool MediaDevice::addObject(MediaObject *obj) +{ + + if (objects_.find(obj->id()) != objects_.end()) { + LOG(Error) << "Element with id " << obj->id() + << " already enumerated."; + return false; + } + + objects_[obj->id()] = obj; + + return true; +} + +/** + * \brief Delete all media objects in the MediaDevice. + * + * Delete all MediaEntities; entities will then delete their pads, + * and each source pad will delete links. + * + * After this function has been called, the media graph will be unpopulated + * and its media objects deleted. The media device has to be populated + * before it could be used again. + */ +void MediaDevice::clear() +{ + for (auto const &o : objects_) + delete o.second; + + objects_.clear(); + entities_.clear(); + valid_ = false; +} + /** * \var MediaDevice::entities_ * \brief Global list of media entities in the media graph */ +/* + * For each entity in the media graph create a MediaEntity and store a + * reference in the MediaObject global pool and in the global vector of + * entities. + */ +bool MediaDevice::populateEntities(const struct media_v2_topology &topology) +{ + media_v2_entity *mediaEntities = reinterpret_cast + (topology.ptr_entities); + + for (unsigned int i = 0; i < topology.num_entities; ++i) { + MediaEntity *entity = new MediaEntity(&mediaEntities[i]); + if (!addObject(entity)) { + delete entity; + return false; + } + + entities_.push_back(entity); + } + + return true; +} + +bool MediaDevice::populatePads(const struct media_v2_topology &topology) +{ + media_v2_pad *mediaPads = reinterpret_cast + (topology.ptr_pads); + + for (unsigned int i = 0; i < topology.num_pads; ++i) { + unsigned int entity_id = mediaPads[i].entity_id; + + /* Store a reference to this MediaPad in entity. */ + MediaEntity *mediaEntity = dynamic_cast + (object(entity_id)); + if (!mediaEntity) { + LOG(Error) << "Failed to find entity with id: " + << entity_id; + return false; + } + + MediaPad *pad = new MediaPad(&mediaPads[i], mediaEntity); + if (!addObject(pad)) { + delete pad; + return false; + } + + mediaEntity->addPad(pad); + } + + return true; +} + +bool MediaDevice::populateLinks(const struct media_v2_topology &topology) +{ + media_v2_link *mediaLinks = reinterpret_cast + (topology.ptr_links); + + for (unsigned int i = 0; i < topology.num_links; ++i) { + /* + * Skip links between entities and interfaces: we only care + * about pad-2-pad links here. + */ + if ((mediaLinks[i].flags & MEDIA_LNK_FL_LINK_TYPE) == + MEDIA_LNK_FL_INTERFACE_LINK) + continue; + + /* Store references to source and sink pads in the link. */ + unsigned int source_id = mediaLinks[i].source_id; + MediaPad *source = dynamic_cast + (object(source_id)); + if (!source) { + LOG(Error) << "Failed to find pad with id: " + << source_id; + return false; + } + + unsigned int sink_id = mediaLinks[i].sink_id; + MediaPad *sink = dynamic_cast + (object(sink_id)); + if (!sink) { + LOG(Error) << "Failed to find pad with id: " + << sink_id; + return false; + } + + MediaLink *link = new MediaLink(&mediaLinks[i], source, sink); + if (!addObject(link)) { + delete link; + return false; + } + + source->addLink(link); + sink->addLink(link); + } + + return true; +} + } /* namespace libcamera */