From patchwork Fri Dec 3 22:42:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 15032 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 32EB6BF415 for ; Fri, 3 Dec 2021 22:42:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E8FB06086C; Fri, 3 Dec 2021 23:42:40 +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="Tb9x/VUQ"; dkim-atps=neutral Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5D7F8607DE for ; Fri, 3 Dec 2021 23:42:38 +0100 (CET) Received: by mail-wr1-x429.google.com with SMTP id d24so8825999wra.0 for ; Fri, 03 Dec 2021 14:42:38 -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=wP5Mk610fVyffoaymXg9kkRA0t99CmQnxwVpbCNOf7Y=; b=Tb9x/VUQBtlaNVLKp5EJLibqmDco3vTZeYCyS4mE6YEcX6+BXbahLzAw1RnV7E96DD gpJGLQbyn/kGE8itT+R7D1B2qB9PgudoObhmv4X7LeChpr5IRG5xqU/JKc8UwJtA/36W YHdH2EXbPPnPoadV1IxY44fW4s0nxI8kq9KUj7d6giDftnaK9voK4ClUCk3jcAdQ7L2W YCrUzPrNkSA7p4NLDeNYV8TCn03CTBsmXxMJNpaUjm9CsnMk6Ix3Ren1uYEkX/6NF4QU 3QOgtrlqC6fxQpE2/N3bzdKimbx4PUllrQv9HEg3hwjcZhPLNT3Te4iw7XbBX3iIg5TF VRjg== 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=wP5Mk610fVyffoaymXg9kkRA0t99CmQnxwVpbCNOf7Y=; b=jHXz3Zey1xX/IUqHq6+N4N6OHJ090kZoXa8C5bnYe1CvVJ9MBfE3AiaAqfIixoIQTr lI5gYhOF3eK9iGavteL49+1Xy79KN7cGsuNKp2l4/b58tgSR/yHpUI+popnkOHay5DCv GUxb7/oWb6FrAWiEAMMP1iAUvewt7uQ1E0PKOG1u7AFnj7+ebwB4QBtdNsF6dZpqVI5A pi5zaxnPMwkVBg0/Wql7jYcDXoNE6kseHSTTP0JORLu5iKTjuAWa8KsMWAAYpRrfaEpM XDTtSFHG63nAg4TaBQEyuo9Ces7pbQCM/q7jwmiAQC+Ga5UgzOvFddpZPQypfotbeHhW opMw== X-Gm-Message-State: AOAM531kh42as7ZXScRaVKuD7HE4bj2zolMQxa1AkolF0zf4CcxANy/v RhGixINpdaHh0eKQwmb5i1N98DCUXDQ= X-Google-Smtp-Source: ABdhPJx6ndwDfg6t88v4bUhLdjH8MtofNAIN2rdWuT5sXOHGC/rfY/aaUgdARio4tbFD2vcTa+TV6Q== X-Received: by 2002:a5d:522e:: with SMTP id i14mr24166634wra.43.1638571358133; Fri, 03 Dec 2021 14:42:38 -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 o25sm3939919wms.17.2021.12.03.14.42.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:42:37 -0800 (PST) From: Daniel Scally To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Dec 2021 22:42:25 +0000 Message-Id: <20211203224230.38700-3-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211203224230.38700-1-djrscally@gmail.com> References: <20211203224230.38700-1-djrscally@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/7] 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 v2: - Storing pointer to the sink entity in the new ancillaryEntities_ vector of the source entity where in case MEDIA_LNK_FL_ANCILLARY_LINK rather than creating a MediaLink (Laurent) include/linux/media.h | 1 + src/libcamera/media_device.cpp | 46 +++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/include/linux/media.h b/include/linux/media.h index 17432318..e3123d1a 100644 --- a/include/linux/media.h +++ b/include/linux/media.h @@ -222,6 +222,7 @@ struct media_pad_desc { #define MEDIA_LNK_FL_LINK_TYPE (0xf << 28) # define MEDIA_LNK_FL_DATA_LINK (0 << 28) # define MEDIA_LNK_FL_INTERFACE_LINK (1 << 28) +# define MEDIA_LNK_FL_ANCILLARY_LINK (2 << 28) struct media_link_desc { struct media_pad_desc source; diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index aa93da75..6eddb5a0 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -699,45 +699,61 @@ bool MediaDevice::populateLinks(const struct media_v2_topology &topology) { struct media_v2_link *mediaLinks = reinterpret_cast (topology.ptr_links); + unsigned int link_type; + 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. + * about pad-2-pad and entity-2-entity links here. */ 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. */ + /* Store references to source and sink objects in the link. */ 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; - } + link_type = mediaLinks[i].flags & MEDIA_LNK_FL_LINK_TYPE; + + switch (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); - source->addLink(link); - sink->addLink(link); + break; + case MEDIA_LNK_FL_ANCILLARY_LINK: + MediaEntity *primary = dynamic_cast(source); + MediaEntity *ancillary = dynamic_cast(sink); + + primary->addAncillaryEntity(ancillary); + + break; + } } return true;