[{"id":22237,"web_url":"https://patchwork.libcamera.org/comment/22237/","msgid":"<3391bfca-0770-1b04-869e-4b4ac2779276@ideasonboard.com>","date":"2022-03-09T15:12:39","subject":"Re: [libcamera-devel] [PATCH v5 3/9] libcamera: media_device:\n\tHandle ancillary links in populateLinks()","submitter":{"id":97,"url":"https://patchwork.libcamera.org/api/people/97/","name":"Nicolas Dufresne via libcamera-devel","email":"libcamera-devel@lists.libcamera.org"},"content":"Hi !\n\nThanks for the patch !\n\nOn 04/03/2022 00:49, Daniel Scally wrote:\n> The populateLinks() function can't currently handle ancillary links\n> which causes an error to be thrown in process() when the MediaObject\n> cannot be cast to a MediaPad.\n> \n> Add explicit handling for the different link types, creating either\n> pad-2-pad links or else storing the pointer to the ancillary device\n> MediaEntity in the ancillaryEntities_ member of the primary.\n> \n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Signed-off-by: Daniel Scally <djrscally@gmail.com>\n\nReviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n\n> ---\n> Changes in v5:\n> \t- Fix some formatting and comments (Laurent)\n> \n> Changes in v4:\n> \n> \t- Added some error checking to confirm that the casts to pad or entity\n> \treturn valid pointers (Laurent)\n> \n> Changes 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 | 64 +++++++++++++++++++++++++---------\n>   1 file changed, 48 insertions(+), 16 deletions(-)\n> \n> diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\n> index 941f86c2..7c94da9e 100644\n> --- a/src/libcamera/media_device.cpp\n> +++ b/src/libcamera/media_device.cpp\n> @@ -683,40 +683,72 @@ 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\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>   \n> -\t\tsource->addLink(link);\n> -\t\tsink->addLink(link);\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> +\n> +\t\tdefault:\n> +\t\t\tLOG(MediaDevice, Warning)\n> +\t\t\t\t<< \"Unknown media link type\";\n> +\n> +\t\t\tbreak;\n> +\t\t}\n>   \t}\n>   \n>   \treturn true;","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 C14DCBE08A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  9 Mar 2022 15:12:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6D25961189;\n\tWed,  9 Mar 2022 16:12:43 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 222DC60475\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  9 Mar 2022 16:12:42 +0100 (CET)","from [IPV6:2a01:e0a:169:7140:3734:287e:1a7f:9772] (unknown\n\t[IPv6:2a01:e0a:169:7140:3734:287e:1a7f:9772])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DF99A8C4;\n\tWed,  9 Mar 2022 16:12:41 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1646838763;\n\tbh=uZnu4P7mInfRiybkV5SyqoKIVPOvb9JfvpgcRWPRQV0=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=Os9evZ8ZJZhM7HYWgafkvrggIqsHD5a/v40ALrX2lC8g5j+UZRRx9l/r7LYYmZbwK\n\tp6964bY3uFOKBYyzPw/Napl4V88Q1JCzK9oQkPzKoiFfw7eAnUCn0ZIzZMkW7bXVUB\n\t4CZXskHWgaeAqL28uUJL+J28nTk1NjJEZAf+6uLVMvcI2ECMiXsvaeUmxyQaF9TQg6\n\tT6s4/7pHcFAjY3KyPCjcD56/crCoGrZRYiQhcSoA/GiK9DSccudtKGd/ehb2myI+jx\n\tUQjfqber0x1aOudOBDDYxZ6zv/iFKGzj9RLTdEm+QxBFjiMdK1bdxvFLobPnCMvfEK\n\tKTXm18KJJSGgQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1646838761;\n\tbh=uZnu4P7mInfRiybkV5SyqoKIVPOvb9JfvpgcRWPRQV0=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=NJsLCPf60b51gY7Z4CyuFIciBoHBmImSap7AuJpHQMx+jrIR1/d32GFETK/f2S3eK\n\tTZPTS6sFXUPKts0u6J51iV95PiGWCyAWWUbRPKz5yrtknMS+hPdFkWG4xRExkGy+L4\n\tDaezbWh1QW/DRT+zoxd4MBcQ46qS74/bcWiwrX3A="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"NJsLCPf6\"; dkim-atps=neutral","Message-ID":"<3391bfca-0770-1b04-869e-4b4ac2779276@ideasonboard.com>","Date":"Wed, 9 Mar 2022 16:12:39 +0100","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101\n\tThunderbird/91.5.0","Content-Language":"en-US","To":"Daniel Scally <djrscally@gmail.com>, libcamera-devel@lists.libcamera.org","References":"<20220303234956.1463551-1-djrscally@gmail.com>\n\t<20220303234956.1463551-4-djrscally@gmail.com>","In-Reply-To":"<20220303234956.1463551-4-djrscally@gmail.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH v5 3/9] libcamera: media_device:\n\tHandle ancillary 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>","From":"Jean-Michel Hautbois via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]