From patchwork Thu Jan 3 17:38:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 145 Return-Path: Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8D4EA60B13 for ; Thu, 3 Jan 2019 18:39:02 +0100 (CET) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 265C9FF808; Thu, 3 Jan 2019 17:39:01 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 3 Jan 2019 18:38:55 +0100 Message-Id: <20190103173859.22624-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190103173859.22624-1-jacopo@jmondi.org> References: <20190103173859.22624-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/5] libcamera: Add pointer to MediaDevice to MediaObject 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, 03 Jan 2019 17:39:02 -0000 Add a MediaDevice member field to the MediaObject class hierarcy. Each media object now has a reference to the media device it belongs to, and which it has been created by. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/include/media_object.h | 10 ++++++---- src/libcamera/media_device.cpp | 8 ++++---- src/libcamera/media_object.cpp | 30 +++++++++++++++++++--------- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/libcamera/include/media_object.h b/src/libcamera/include/media_object.h index 950a332..0f0bb29 100644 --- a/src/libcamera/include/media_object.h +++ b/src/libcamera/include/media_object.h @@ -26,10 +26,12 @@ public: protected: friend class MediaDevice; - MediaObject(unsigned int id) : id_(id) { } + MediaObject(MediaDevice *media, unsigned int id) : + id_(id), media_(media) { } virtual ~MediaObject() { } unsigned int id_; + MediaDevice *media_; }; class MediaLink : public MediaObject @@ -42,7 +44,7 @@ public: private: friend class MediaDevice; - MediaLink(const struct media_v2_link *link, + MediaLink(MediaDevice *media, const struct media_v2_link *link, MediaPad *source, MediaPad *sink); MediaLink(const MediaLink &) = delete; ~MediaLink() { } @@ -65,7 +67,7 @@ public: private: friend class MediaDevice; - MediaPad(const struct media_v2_pad *pad, MediaEntity *entity); + MediaPad(MediaDevice *media, const struct media_v2_pad *pad, MediaEntity *entity); MediaPad(const MediaPad &) = delete; ~MediaPad(); @@ -93,7 +95,7 @@ public: private: friend class MediaDevice; - MediaEntity(const struct media_v2_entity *entity, + MediaEntity(MediaDevice *media, const struct media_v2_entity *entity, unsigned int major = 0, unsigned int minor = 0); MediaEntity(const MediaEntity &) = delete; ~MediaEntity(); diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index cf4ff90..2f9490c 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -430,11 +430,11 @@ bool MediaDevice::populateEntities(const struct media_v2_topology &topology) MediaEntity *entity; if (iface) - entity = new MediaEntity(&mediaEntities[i], + entity = new MediaEntity(this, &mediaEntities[i], iface->devnode.major, iface->devnode.minor); else - entity = new MediaEntity(&mediaEntities[i]); + entity = new MediaEntity(this, &mediaEntities[i]); if (!addObject(entity)) { delete entity; @@ -464,7 +464,7 @@ bool MediaDevice::populatePads(const struct media_v2_topology &topology) return false; } - MediaPad *pad = new MediaPad(&mediaPads[i], mediaEntity); + MediaPad *pad = new MediaPad(this, &mediaPads[i], mediaEntity); if (!addObject(pad)) { delete pad; return false; @@ -509,7 +509,7 @@ bool MediaDevice::populateLinks(const struct media_v2_topology &topology) return false; } - MediaLink *link = new MediaLink(&mediaLinks[i], source, sink); + MediaLink *link = new MediaLink(this, &mediaLinks[i], source, sink); if (!addObject(link)) { delete link; return false; diff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp index 581e1c0..f1535e6 100644 --- a/src/libcamera/media_object.cpp +++ b/src/libcamera/media_object.cpp @@ -44,14 +44,16 @@ namespace libcamera { * * MediaObject is an abstract base class for all media objects in the media * graph. Every media graph object is identified by an id unique in the media - * device context, and this base class provides that. + * device context, and this base class provides both of them. * * \sa MediaEntity, MediaPad, MediaLink */ /** * \fn MediaObject::MediaObject() - * \brief Construct a MediaObject with \a id + * \brief Construct a MediaObject with \a id, globally unique in the MediaDevice + * \a media + * \param media The media device this object belongs to * \param id The media object id * * The caller shall ensure unicity of the object id in the media device context. @@ -69,6 +71,11 @@ namespace libcamera { * \brief The media object id */ +/** + * \var MediaObject::media_ + * \brief The media device that constructed this object + */ + /** * \class MediaLink * \brief The MediaLink represents a link between two pads in the media graph. @@ -82,13 +89,14 @@ namespace libcamera { /** * \brief Construct a MediaLink + * \param media The media device this entity belongs to * \param link The media link kernel data * \param source The source pad at the origin of the link * \param sink The sink pad at the destination of the link */ -MediaLink::MediaLink(const struct media_v2_link *link, MediaPad *source, - MediaPad *sink) - : MediaObject(link->id), source_(source), +MediaLink::MediaLink(MediaDevice *media, const struct media_v2_link *link, + MediaPad *source, MediaPad *sink) + : MediaObject(media, link->id), source_(source), sink_(sink), flags_(link->flags) { } @@ -135,11 +143,13 @@ MediaLink::MediaLink(const struct media_v2_link *link, MediaPad *source, /** * \brief Construct a MediaPad + * \param media The media device this entity belongs to * \param pad The media pad kernel data * \param entity The entity the pad belongs to */ -MediaPad::MediaPad(const struct media_v2_pad *pad, MediaEntity *entity) - : MediaObject(pad->id), index_(pad->index), entity_(entity), +MediaPad::MediaPad(MediaDevice *media, const struct media_v2_pad *pad, + MediaEntity *entity) + : MediaObject(media, pad->id), index_(pad->index), entity_(entity), flags_(pad->flags) { } @@ -283,13 +293,15 @@ int MediaEntity::setDeviceNode(const std::string &devnode) /** * \brief Construct a MediaEntity + * \param media The media device this entity belongs to * \param entity The media entity kernel data * \param major The major number of the entity associated interface * \param minor The minor number of the entity associated interface */ -MediaEntity::MediaEntity(const struct media_v2_entity *entity, +MediaEntity::MediaEntity(MediaDevice *media, + const struct media_v2_entity *entity, unsigned int major, unsigned int minor) - : MediaObject(entity->id), name_(entity->name), + : MediaObject(media, entity->id), name_(entity->name), major_(major), minor_(minor) { }