From patchwork Thu Mar 3 23:49:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 15410 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 E0D0BBE08A for ; Thu, 3 Mar 2022 23:50:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CE4F361176; Fri, 4 Mar 2022 00:50:17 +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="pdagp9Qx"; 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 7F37B61166 for ; Fri, 4 Mar 2022 00:50:14 +0100 (CET) Received: by mail-wr1-x434.google.com with SMTP id u10so8512640wra.9 for ; Thu, 03 Mar 2022 15:50:14 -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=bytZg0LZdg13NuH+aLz5Hfv65SKmuD+2gMC0l8UtcCI=; b=pdagp9QxbQdh4oZbOEcMRi148KelyNBhJRvFDQFWXzkoedUVRJp14SrqYa1UyL1jA0 RctAyNuChhKZF0XHfc/qK3UJa/2rb6fVVpBkSXmJWYdK36L/kz9ANCuifO/BpNabUajb kOddIaUB6QNlv7pbK5P8iNWzpDxcEKkazBLZhj4TIzumcfewul7btXh2a2WV/iNUK84K MvTjqTAXii7bmMErmp5/EylX+TW7c6z4xBFpCovUisoSF5JDm8JhKJYZrue8EJxuyJpi KKO4JkpXamKoaD4QZnsCtLaQZ2LTOIk9uLFe8hPm/JrVq7/A/UhtqzGMIbvkg5ZnuX5j 9Weg== 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=bytZg0LZdg13NuH+aLz5Hfv65SKmuD+2gMC0l8UtcCI=; b=hTAD2VUB4uTDOJPgUBcjukoqGIQNp4jXTG46WVYNQ67iGH8NgrTFSQnabr+g5Qxid7 PF66vY3gNtRvTXaZvYZ3QO3boa1AZ0s5Vl6B851yS2nPGEpe+Usettmj9Y9UmNY75LwS ZmGZgv1XvPyfuhh+j+4yxG1X+jr3lSi+Zll5a6+L5ms/P9pXk+s8ECcbEOw/IoCvrT7S seGZrGOOL2J5QiNINfO5PlXtB6jWQYtxUo96NWrmSonblJVKtcw0zEewVIx+N79sfqdE kofyjuleBOwNpciUawR1quHdf8ciGi/EOYBP8zcXnQ5uKXKKog72kOl6BSpos67lnJ8c Eugw== X-Gm-Message-State: AOAM531rTHLDmxYIoVfrTVVEFqKCM/Majv/Bd0quCqollJZ5K1J1myd7 jBMEsN/6GE6pLL4T951D6MvmRcffdkS/1A== X-Google-Smtp-Source: ABdhPJxc3Mk24QXDC2PfJPGzY7H/AiRGAjAWU03fT0L+D5sPXyVLaPMRcGob+tOji8a2YpxDwXc+gw== X-Received: by 2002:a5d:6d88:0:b0:1e3:37c1:3633 with SMTP id l8-20020a5d6d88000000b001e337c13633mr29122338wrs.484.1646351413966; Thu, 03 Mar 2022 15:50:13 -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 y4-20020adff144000000b001f022290737sm3079779wro.6.2022.03.03.15.50.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Mar 2022 15:50:13 -0800 (PST) From: Daniel Scally To: libcamera-devel@lists.libcamera.org Date: Thu, 3 Mar 2022 23:49:50 +0000 Message-Id: <20220303234956.1463551-4-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220303234956.1463551-1-djrscally@gmail.com> References: <20220303234956.1463551-1-djrscally@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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. Reviewed-by: Laurent Pinchart Signed-off-by: Daniel Scally Reviewed-by: Jean-Michel Hautbois --- Changes in v5: - Fix some formatting and comments (Laurent) 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 | 64 +++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index 941f86c2..7c94da9e 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -683,40 +683,72 @@ 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) + 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; } - source->addLink(link); - sink->addLink(link); + 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"; + + break; + } } return true;