@@ -118,6 +118,7 @@ public:
const MediaPad *getPadById(unsigned int id) const;
int setDeviceNode(const std::string &deviceNode);
+ int disableLinks() const;
private:
LIBCAMERA_DISABLE_COPY_AND_MOVE(MediaEntity)
@@ -463,19 +463,9 @@ MediaLink *MediaDevice::link(const MediaPad *source, const MediaPad *sink)
int MediaDevice::disableLinks()
{
for (MediaEntity *entity : entities_) {
- for (MediaPad *pad : entity->pads()) {
- if (!(pad->flags() & MEDIA_PAD_FL_SOURCE))
- continue;
-
- for (MediaLink *link : pad->links()) {
- if (link->flags() & MEDIA_LNK_FL_IMMUTABLE)
- continue;
-
- int ret = link->setEnabled(false);
- if (ret)
- return ret;
- }
- }
+ int ret = entity->disableLinks();
+ if (ret)
+ return ret;
}
return 0;
@@ -428,6 +428,33 @@ int MediaEntity::setDeviceNode(const std::string &deviceNode)
return 0;
}
+/**
+ * \brief Disable all links on the media entity
+ *
+ * Disable all the media entity links, clearing the MEDIA_LNK_FL_ENABLED flag
+ * on links which are not flagged as IMMUTABLE.
+ *
+ * \return 0 on success or a negative error code otherwise
+ */
+int MediaEntity::disableLinks() const
+{
+ for (MediaPad *pad : pads_) {
+ if (!(pad->flags() & MEDIA_PAD_FL_SOURCE))
+ continue;
+
+ for (MediaLink *link : pad->links()) {
+ if (link->flags() & MEDIA_LNK_FL_IMMUTABLE)
+ continue;
+
+ int ret = link->setEnabled(false);
+ if (ret)
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
/**
* \brief Construct a MediaEntity
* \param[in] dev The media device this entity belongs to
Some pipeline-handlers may want finer-grained control over disabling links then MediaDevice::disableLinks() which simply disables all links on a media-device. Add a new MediaEntity::disableLinks() method which disables the links on a single MediaEntity and use that in MediaDevice::disableLinks() to avoid code duplication. Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com> --- include/libcamera/internal/media_object.h | 1 + src/libcamera/media_device.cpp | 16 +++----------- src/libcamera/media_object.cpp | 27 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 13 deletions(-)