{"id":15308,"url":"https://patchwork.libcamera.org/api/1.1/patches/15308/?format=json","web_url":"https://patchwork.libcamera.org/patch/15308/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220131223330.61563-4-djrscally@gmail.com>","date":"2022-01-31T22:33:24","name":"[libcamera-devel,v4,3/9] libcamera: media_device: Handle ancillary links in populateLinks()","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"f7ccbec810f387b1100446d7e3d7c40b88b28b9f","submitter":{"id":90,"url":"https://patchwork.libcamera.org/api/1.1/people/90/?format=json","name":"Daniel Scally","email":"djrscally@gmail.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/15308/mbox/","series":[{"id":2906,"url":"https://patchwork.libcamera.org/api/1.1/series/2906/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2906","date":"2022-01-31T22:33:21","name":"Enumerate CameraLens by following sensor's ancillary links","version":4,"mbox":"https://patchwork.libcamera.org/series/2906/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15308/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15308/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 9230EBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 31 Jan 2022 22:33:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0BD19609DF;\n\tMon, 31 Jan 2022 23:33:47 +0100 (CET)","from mail-wr1-x434.google.com (mail-wr1-x434.google.com\n\t[IPv6:2a00:1450:4864:20::434])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 953E6609C3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 31 Jan 2022 23:33:44 +0100 (CET)","by mail-wr1-x434.google.com with SMTP id w11so28233005wra.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 31 Jan 2022 14:33:44 -0800 (PST)","from localhost.localdomain\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net. [86.13.91.161])\n\tby smtp.gmail.com with ESMTPSA id\n\tq2sm6986740wrw.14.2022.01.31.14.33.43\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 31 Jan 2022 14:33:43 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"mn+YxDR9\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=MLw8XqYeW+4rASHT8E3MhoWoR6/A/q1gRfKWOUu+JEA=;\n\tb=mn+YxDR9kPorHx2ga/gPs4RxhA2jHMUOEEKrZkb5H6pts2Xk9p7ESo82lPk5qD6+th\n\t75O86Pm8p6vmQsE0WTFsS2mXW4OGHKoA1IzwyGuHbDGK5wuJ/xPtVae2GjRBrbimcaVn\n\taQmB8JvKkK/y/XgrxduYqDe7IZyZ1uVAOPmyjQLEhgYsP6JfqPaICeY65JQxq4xh/O7q\n\tJvWBr9vQ6wvZ+5ljbf5FphG3URzNeBxIrmb6cxv1HKS8iiFgYw5gvgsDJ+d5ao19UKo4\n\tCwJPL2YLQE5hmeyW2sdvIBTCvBXVk3bsYQUXD+07N1shPx0xKgJEivN1q/MnqpZ9jtzp\n\t4qCg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=MLw8XqYeW+4rASHT8E3MhoWoR6/A/q1gRfKWOUu+JEA=;\n\tb=1zggPbzYwAJttFVSYKwKNkebHasZC3833daT9sS6H+durikPE5RbbGeEj5m9qh/zuF\n\tfOR9XoOaQ55ggmgWPvb2/WFv13Tr22cR9kT/EGKRkCXLI0eyBibJzn3DH6rM5R8vJdpr\n\tBGsFvfnhIQS3VW4dmidsLFji8DH/DMcue9HAkFfEpC0CSVew80xucVZDWdhBSVPybgAZ\n\tr1Wr1q0ffFya3s1AKSrm77a14Vf4PvLwXhw97Mcg6QRE0IAWK90KEviphWvKxvVhTcGy\n\tkD+m654gJFzsjDCP5L6kJuZz78FGaHRWe3UNJmyRiQ02xGqv6uAzBZzrP+I6QtrxH6ip\n\tsC6w==","X-Gm-Message-State":"AOAM531aGoI7iwjAqbbMP89FHx6bVey8Q5giMeOe4BVfmWJEa6yGrDIx\n\tkphrtLgBgDeYaMXXGDynQIbhdq1YKAk=","X-Google-Smtp-Source":"ABdhPJzYUydD4H2mlGVBAHlxQ8pE5At1Bb9LWWPfCEzH293Fn1WjiGp/tJCsDItcyIltcr7Cm9eHag==","X-Received":"by 2002:a5d:64e5:: with SMTP id\n\tg5mr11419465wri.541.1643668424398; \n\tMon, 31 Jan 2022 14:33:44 -0800 (PST)","From":"Daniel Scally <djrscally@gmail.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 31 Jan 2022 22:33:24 +0000","Message-Id":"<20220131223330.61563-4-djrscally@gmail.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20220131223330.61563-1-djrscally@gmail.com>","References":"<20220131223330.61563-1-djrscally@gmail.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 3/9] libcamera: media_device: Handle\n\tancillary links in populateLinks()","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The populateLinks() function can't currently handle ancillary links\nwhich causes an error to be thrown in process() when the MediaObject\ncannot be cast to a MediaPad.\n\nAdd explicit handling for the different link types, creating either\npad-2-pad links or else storing the pointer to the ancillary device\nMediaEntity in the ancillaryEntities_ member of the primary.\n\nSigned-off-by: Daniel Scally <djrscally@gmail.com>\n---\n\nChanges in v4:\n\n\t- Added some error checking to confirm that the casts to pad or entity\n\treturn valid pointers (Laurent)\n\nChanges in v3:\n\n\t- Split out the new macro\n\t- Fixed some style errors and comments\n\t- Added a default case\n\n src/libcamera/media_device.cpp | 67 ++++++++++++++++++++++++++--------\n 1 file changed, 51 insertions(+), 16 deletions(-)","diff":"diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\nindex 941f86c2..a008383a 100644\n--- a/src/libcamera/media_device.cpp\n+++ b/src/libcamera/media_device.cpp\n@@ -683,40 +683,75 @@ bool MediaDevice::populateLinks(const struct media_v2_topology &topology)\n \t\t\t\t\t   (topology.ptr_links);\n \n \tfor (unsigned int i = 0; i < topology.num_links; ++i) {\n-\t\t/* We only care about pad-2-pad links here. */\n-\t\tif ((mediaLinks[i].flags & MEDIA_LNK_FL_LINK_TYPE) !=\n-\t\t    MEDIA_LNK_FL_DATA_LINK)\n+\t\t/*\n+\t\t * Skip links between entities and interfaces: interfaces are\n+\t\t * not created as MediaObjects at this time, so the source and\n+\t\t * sink pointers would never be found.\n+\t\t */\n+\t\tif ((mediaLinks[i].flags & MEDIA_LNK_FL_LINK_TYPE) ==\n+\t\t    MEDIA_LNK_FL_INTERFACE_LINK)\n \t\t\tcontinue;\n \n-\t\t/* Store references to source and sink pads in the link. */\n+\t\t/* Look up the source and sink objects. */\n \t\tunsigned int source_id = mediaLinks[i].source_id;\n-\t\tMediaPad *source = dynamic_cast<MediaPad *>\n-\t\t\t\t   (object(source_id));\n+\t\tMediaObject *source = object(source_id);\n \t\tif (!source) {\n \t\t\tLOG(MediaDevice, Error)\n-\t\t\t\t<< \"Failed to find pad with id: \"\n+\t\t\t\t<< \"Failed to find MediaObject with id: \"\n \t\t\t\t<< source_id;\n \t\t\treturn false;\n \t\t}\n \n \t\tunsigned int sink_id = mediaLinks[i].sink_id;\n-\t\tMediaPad *sink = dynamic_cast<MediaPad *>\n-\t\t\t\t (object(sink_id));\n+\t\tMediaObject *sink = object(sink_id);\n \t\tif (!sink) {\n \t\t\tLOG(MediaDevice, Error)\n-\t\t\t\t<< \"Failed to find pad with id: \"\n+\t\t\t\t<< \"Failed to find MediaObject with id: \"\n \t\t\t\t<< sink_id;\n \t\t\treturn false;\n \t\t}\n \n-\t\tMediaLink *link = new MediaLink(&mediaLinks[i], source, sink);\n-\t\tif (!addObject(link)) {\n-\t\t\tdelete link;\n-\t\t\treturn false;\n+\t\tswitch (mediaLinks[i].flags & MEDIA_LNK_FL_LINK_TYPE) {\n+\t\tcase MEDIA_LNK_FL_DATA_LINK: {\n+\t\t\tMediaPad *sourcePad = dynamic_cast<MediaPad *>(source);\n+\t\t\tMediaPad *sinkPad = dynamic_cast<MediaPad *>(sink);\n+\t\t\tif (!source || !sink) {\n+\t\t\t\tLOG(MediaDevice, Error)\n+\t\t\t\t\t<< \"Source or sink is not a pad\";\n+\t\t\t\treturn false;\n+\t\t\t}\n+\n+\t\t\tMediaLink *link = new MediaLink(&mediaLinks[i],\n+\t\t\t\t\t\t\tsourcePad, sinkPad);\n+\t\t\tif (!addObject(link)) {\n+\t\t\t\tdelete link;\n+\t\t\t\treturn false;\n+\t\t\t}\n+\n+\t\t\tlink->source()->addLink(link);\n+\t\t\tlink->sink()->addLink(link);\n+\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase MEDIA_LNK_FL_ANCILLARY_LINK: {\n+\t\t\tMediaEntity *primary = dynamic_cast<MediaEntity *>(source);\n+\t\t\tMediaEntity *ancillary = dynamic_cast<MediaEntity *>(sink);\n+\t\t\tif (!primary || !ancillary) {\n+\t\t\t\tLOG(MediaDevice, Error)\n+\t\t\t\t\t<< \"Source or sink is not an entity\";\n+\t\t\t\treturn false;\n+\t\t\t}\n+\n+\t\t\tprimary->addAncillaryEntity(ancillary);\n+\n+\t\t\tbreak;\n \t\t}\n+\t\tdefault:\n+\t\t\tLOG(MediaDevice, Warning)\n+\t\t\t\t<< \"Unknown media link type\";\n \n-\t\tsource->addLink(link);\n-\t\tsink->addLink(link);\n+\t\t\tbreak;\n+\t\t}\n \t}\n \n \treturn true;\n","prefixes":["libcamera-devel","v4","3/9"]}