[libcamera-devel] [PATCH] src/libcamera/media_device.cpp: Make MediaDevice::setupLink account for existing link flags

Dan Scally djrscally at protonmail.com
Mon Aug 24 22:01:59 CEST 2020


The setupLink function fails (ioctl returns EINVAL) when it passes the MEDIA_LNK_FL_ENABLE flag
to a link that is already flagged with MEDIA_LNK_FL_ENABLE and MEDIA_LNK_FL_IMMUTABLE. Contrast
to media-ctl's equivalent media_setup_link() which ORs the new flags with the existing values.
This patch modifies the behaviour of setupLink() to behave the same as media_setup_link() in
media-ctl.

ref https://git.linuxtv.org/v4l-utils.git/tree/utils/media-ctl/libmediactl.c#n210

Signed-off-by: Daniel Scally <djrscally at protonmail.com>
---
 src/libcamera/media_device.cpp | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp
index de18d57..cd44902 100644
--- a/src/libcamera/media_device.cpp
+++ b/src/libcamera/media_device.cpp
@@ -780,11 +780,20 @@ void MediaDevice::fixupEntityFlags(struct media_v2_entity *entity)
  *
  * \return 0 on success or a negative error code otherwise
  */
-int MediaDevice::setupLink(const MediaLink *link, unsigned int flags)
+int MediaDevice::setupLink(const MediaLink *nlink, unsigned int flags)
 {
 	struct media_link_desc linkDesc = {};
-	MediaPad *source = link->source();
-	MediaPad *sink = link->sink();
+	MediaPad *source = nlink->source();
+	MediaPad *sink = nlink->sink();
+	MediaLink *elink;	// existing link
+
+	elink = link(source, sink);
+
+	if (elink == NULL) {
+		LOG(MediaDevice, Error)
+			<< __func__ << ": Link not found\n";
+		return -ENOENT;
+	}
 

 	linkDesc.source.entity = source->entity()->id();
 	linkDesc.source.index = source->index();
@@ -794,7 +803,7 @@ int MediaDevice::setupLink(const MediaLink *link, unsigned int flags)
 	linkDesc.sink.index = sink->index();
 	linkDesc.sink.flags = MEDIA_PAD_FL_SINK;
 

-	linkDesc.flags = flags;
+	linkDesc.flags = flags | (elink->flags() & MEDIA_LNK_FL_IMMUTABLE);
 

 	int ret = ioctl(fd_, MEDIA_IOC_SETUP_LINK, &linkDesc);
 	if (ret) {
-- 

2.17.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 509 bytes
Desc: OpenPGP digital signature
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20200824/538cab35/attachment.sig>


More information about the libcamera-devel mailing list