From patchwork Tue Dec 7 22:45:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 15069 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 6EF8EBDB13 for ; Tue, 7 Dec 2021 22:45:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2505860890; Tue, 7 Dec 2021 23:45:36 +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="ILc8EsU0"; dkim-atps=neutral Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A70EB60868 for ; Tue, 7 Dec 2021 23:45:30 +0100 (CET) Received: by mail-wr1-x435.google.com with SMTP id c4so715640wrd.9 for ; Tue, 07 Dec 2021 14:45:30 -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=ntCMpvdJQK9Bdi2smBtYSqjYv78X3g5csArMHbVTPCg=; b=ILc8EsU0ZVMVxPxkBFRJQmg3mzzjedvMdyO5P/7Cb3hEF9eVThi+vBzpyzQc05W9qR FijHX6t7GMI8ovfeqWifZQLUYC9KfOAjXHlXy3uw9np6KCEXJkQb/CgPO9LWHTcrQc75 p1/AKIqze0OKM3OVALTYRAtOjTmCC5K+6ySSNhWe6hm8W7b9hNKaKF+lF9FkbXPfmRa8 0Ai2a1P0P9l4KDt7JFJT6YnuPDwFjXs0Uh1qRrWGQSFQCfutpBocZNCRJ6jObmi94/MW D0D4+pJvk1P0b6WmjLcy4U2AII5E8AAXQ0+l2EPx02YwvoGgAjb15fTDnWY4guF4b4W6 nQ9g== 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=ntCMpvdJQK9Bdi2smBtYSqjYv78X3g5csArMHbVTPCg=; b=e/5IqKDNGqEdVEvAamVdHnVg1SX00n+FS6B9YywQPYvfIz3q5Z2G9fWdEt9DT6wfRV b47PgT42eCrOeJpa7A3MbLAhx6kSkPpMhcyFpF9VVHXQwoRJ2AdZG+pwThSEObowUAZA WTwZkMno8WPihxlDbOLrF6ltY3aN9d2RmCRA5cZB2ZWJ0PDfPgmuD+epacLaqpS7S9dI hUYxYDMmIYGCEgHScbO8FNm4htdTngVUbdKbqCmbDhsNB84H2nP2UZxm3MprcNPUS7AT h7k9CRdWHkkFKeq/5znm8ejAQl2qPcfGA6JKUtXUcX3lSk/t68ColW5SKM+GlC5wsggd IZ9g== X-Gm-Message-State: AOAM533x1fsmVmn6T5Kk9vzEMWYnd1fPm/cvAGeRp6K0U27WugbgtsG9 JAs4YXFbqKSdRttKO67/XgRFzoQaf9Y= X-Google-Smtp-Source: ABdhPJzdXmv9i1n72fJcSi8tSoyo084TQceBOu+xODVdAxgirW5oDdpeE0GKm1NmZrN1Uef35qCdxQ== X-Received: by 2002:adf:e484:: with SMTP id i4mr56152368wrm.49.1638917130465; Tue, 07 Dec 2021 14:45:30 -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 y12sm980332wrn.73.2021.12.07.14.45.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 14:45:30 -0800 (PST) From: Daniel Scally To: libcamera-devel@lists.libcamera.org Date: Tue, 7 Dec 2021 22:45:06 +0000 Message-Id: <20211207224512.753979-4-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211207224512.753979-1-djrscally@gmail.com> References: <20211207224512.753979-1-djrscally@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 --- Changes in v3: - Split out the new macro - Fixed some style errors and comments - Added a default case src/libcamera/media_device.cpp | 55 ++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index 4df0a27f..fb332445 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -693,45 +693,68 @@ bool MediaDevice::populateLinks(const struct media_v2_topology &topology) { struct media_v2_link *mediaLinks = reinterpret_cast (topology.ptr_links); + MediaEntity *ancillary; + MediaEntity *primary; + MediaLink *link; for (unsigned int i = 0; i < topology.num_links; ++i) { /* - * Skip links between entities and interfaces: we only care - * about pad-2-pad links here. + * 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: + link = new MediaLink(&mediaLinks[i], + dynamic_cast(source), + dynamic_cast(sink)); + if (!addObject(link)) { + delete link; + return false; + } + + link->source()->addLink(link); + link->sink()->addLink(link); + + break; + + case MEDIA_LNK_FL_ANCILLARY_LINK: + primary = dynamic_cast(source); + ancillary = dynamic_cast(sink); - source->addLink(link); - sink->addLink(link); + primary->addAncillaryEntity(ancillary); + + break; + + default: + LOG(MediaDevice, Warning) + << "Unknown media link type"; + + break; + } } return true;