From patchwork Mon Jan 31 22:33:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 15308 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 9230EBF415 for ; Mon, 31 Jan 2022 22:33:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0BD19609DF; Mon, 31 Jan 2022 23:33:47 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="mn+YxDR9"; dkim-atps=neutral Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 953E6609C3 for ; Mon, 31 Jan 2022 23:33:44 +0100 (CET) Received: by mail-wr1-x434.google.com with SMTP id w11so28233005wra.4 for ; Mon, 31 Jan 2022 14:33:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MLw8XqYeW+4rASHT8E3MhoWoR6/A/q1gRfKWOUu+JEA=; b=mn+YxDR9kPorHx2ga/gPs4RxhA2jHMUOEEKrZkb5H6pts2Xk9p7ESo82lPk5qD6+th 75O86Pm8p6vmQsE0WTFsS2mXW4OGHKoA1IzwyGuHbDGK5wuJ/xPtVae2GjRBrbimcaVn aQmB8JvKkK/y/XgrxduYqDe7IZyZ1uVAOPmyjQLEhgYsP6JfqPaICeY65JQxq4xh/O7q JvWBr9vQ6wvZ+5ljbf5FphG3URzNeBxIrmb6cxv1HKS8iiFgYw5gvgsDJ+d5ao19UKo4 CwJPL2YLQE5hmeyW2sdvIBTCvBXVk3bsYQUXD+07N1shPx0xKgJEivN1q/MnqpZ9jtzp 4qCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MLw8XqYeW+4rASHT8E3MhoWoR6/A/q1gRfKWOUu+JEA=; b=1zggPbzYwAJttFVSYKwKNkebHasZC3833daT9sS6H+durikPE5RbbGeEj5m9qh/zuF fOR9XoOaQ55ggmgWPvb2/WFv13Tr22cR9kT/EGKRkCXLI0eyBibJzn3DH6rM5R8vJdpr BGsFvfnhIQS3VW4dmidsLFji8DH/DMcue9HAkFfEpC0CSVew80xucVZDWdhBSVPybgAZ r1Wr1q0ffFya3s1AKSrm77a14Vf4PvLwXhw97Mcg6QRE0IAWK90KEviphWvKxvVhTcGy kD+m654gJFzsjDCP5L6kJuZz78FGaHRWe3UNJmyRiQ02xGqv6uAzBZzrP+I6QtrxH6ip sC6w== X-Gm-Message-State: AOAM531aGoI7iwjAqbbMP89FHx6bVey8Q5giMeOe4BVfmWJEa6yGrDIx kphrtLgBgDeYaMXXGDynQIbhdq1YKAk= X-Google-Smtp-Source: ABdhPJzYUydD4H2mlGVBAHlxQ8pE5At1Bb9LWWPfCEzH293Fn1WjiGp/tJCsDItcyIltcr7Cm9eHag== X-Received: by 2002:a5d:64e5:: with SMTP id g5mr11419465wri.541.1643668424398; Mon, 31 Jan 2022 14:33:44 -0800 (PST) Received: from localhost.localdomain (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net. [86.13.91.161]) by smtp.gmail.com with ESMTPSA id q2sm6986740wrw.14.2022.01.31.14.33.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 14:33:43 -0800 (PST) From: Daniel Scally 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 Subject: [libcamera-devel] [PATCH v4 3/9] libcamera: media_device: Handle ancillary links in populateLinks() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The populateLinks() function can't currently handle ancillary links which causes an error to be thrown in process() when the MediaObject cannot be cast to a MediaPad. Add explicit handling for the different link types, creating either pad-2-pad links or else storing the pointer to the ancillary device MediaEntity in the ancillaryEntities_ member of the primary. Signed-off-by: Daniel Scally Reviewed-by: Laurent Pinchart --- Changes in v4: - Added some error checking to confirm that the casts to pad or entity return valid pointers (Laurent) Changes in v3: - Split out the new macro - Fixed some style errors and comments - Added a default case src/libcamera/media_device.cpp | 67 ++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index 941f86c2..a008383a 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -683,40 +683,75 @@ bool MediaDevice::populateLinks(const struct media_v2_topology &topology) (topology.ptr_links); for (unsigned int i = 0; i < topology.num_links; ++i) { - /* We only care about pad-2-pad links here. */ - if ((mediaLinks[i].flags & MEDIA_LNK_FL_LINK_TYPE) != - MEDIA_LNK_FL_DATA_LINK) + /* + * Skip links between entities and interfaces: interfaces are + * not created as MediaObjects at this time, so the source and + * sink pointers would never be found. + */ + 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. */ + /* Look up the source and sink objects. */ unsigned int source_id = mediaLinks[i].source_id; - MediaPad *source = dynamic_cast - (object(source_id)); + MediaObject *source = object(source_id); if (!source) { LOG(MediaDevice, Error) - << "Failed to find pad with id: " + << "Failed to find MediaObject with id: " << source_id; return false; } unsigned int sink_id = mediaLinks[i].sink_id; - MediaPad *sink = dynamic_cast - (object(sink_id)); + MediaObject *sink = object(sink_id); if (!sink) { LOG(MediaDevice, Error) - << "Failed to find pad with id: " + << "Failed to find MediaObject with id: " << sink_id; return false; } - MediaLink *link = new MediaLink(&mediaLinks[i], source, sink); - if (!addObject(link)) { - delete link; - return false; + switch (mediaLinks[i].flags & MEDIA_LNK_FL_LINK_TYPE) { + case MEDIA_LNK_FL_DATA_LINK: { + MediaPad *sourcePad = dynamic_cast(source); + MediaPad *sinkPad = dynamic_cast(sink); + if (!source || !sink) { + LOG(MediaDevice, Error) + << "Source or sink is not a pad"; + return false; + } + + MediaLink *link = new MediaLink(&mediaLinks[i], + sourcePad, sinkPad); + if (!addObject(link)) { + delete link; + return false; + } + + link->source()->addLink(link); + link->sink()->addLink(link); + + break; + } + case MEDIA_LNK_FL_ANCILLARY_LINK: { + MediaEntity *primary = dynamic_cast(source); + MediaEntity *ancillary = dynamic_cast(sink); + if (!primary || !ancillary) { + LOG(MediaDevice, Error) + << "Source or sink is not an entity"; + return false; + } + + primary->addAncillaryEntity(ancillary); + + break; } + default: + LOG(MediaDevice, Warning) + << "Unknown media link type"; - source->addLink(link); - sink->addLink(link); + break; + } } return true;