Patch Detail
Show a patch.
GET /api/patches/15276/?format=api
{ "id": 15276, "url": "https://patchwork.libcamera.org/api/patches/15276/?format=api", "web_url": "https://patchwork.libcamera.org/patch/15276/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20220113102529.3163441-2-naush@raspberrypi.com>", "date": "2022-01-13T10:25:28", "name": "[libcamera-devel,RFC,v1,1/2] libcamera: media_device: Add enumerateMediaWalks() helper", "commit_ref": null, "pull_url": null, "state": "rfc", "archived": false, "hash": "7f20bbfd0aa12a6cf971282ddd5516bf858caf4a", "submitter": { "id": 34, "url": "https://patchwork.libcamera.org/api/people/34/?format=api", "name": "Naushir Patuck", "email": "naush@raspberrypi.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/15276/mbox/", "series": [ { "id": 2892, "url": "https://patchwork.libcamera.org/api/series/2892/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2892", "date": "2022-01-13T10:25:27", "name": "MediaDevice enumeration helper", "version": 1, "mbox": "https://patchwork.libcamera.org/series/2892/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/15276/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/15276/checks/", "tags": {}, "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 2FC36C325A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 13 Jan 2022 10:25:39 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C372A6093D;\n\tThu, 13 Jan 2022 11:25:37 +0100 (CET)", "from mail-wr1-x435.google.com (mail-wr1-x435.google.com\n\t[IPv6:2a00:1450:4864:20::435])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F2CB16017E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Jan 2022 11:25:35 +0100 (CET)", "by mail-wr1-x435.google.com with SMTP id q8so9135171wra.12\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Jan 2022 02:25:35 -0800 (PST)", "from naush-laptop.pitowers.org\n\t([2a00:1098:3142:14:194e:c2b:3339:eb51])\n\tby smtp.gmail.com with ESMTPSA id\n\ts22sm6757855wmc.1.2022.01.13.02.25.34\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 13 Jan 2022 02:25:35 -0800 (PST)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"nf0c15no\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=5+boYhoE20g1aTmGiUb4iR1Pa8SbK9bEBGFwgPSNkLs=;\n\tb=nf0c15nobwcbHOFDywmBNY6ktZ1B7LuX266Yu/jewspDFtIJDvT+JqtRd0PqXS6VmI\n\taLy5I70K1+XdM/8CKAIsg1k2sz2S10nR62XdMhXZQp2KK0f7xFs72pxLDoziG9l4JfSD\n\trQ6DZPoQKoj6GkkxDzryRoivlPhMeIbS0WXrcQBvZbU0hSvtGSPqqAC5xgZcOvjJf6R0\n\t16dMYg+rsiwB4BuTExS8ST8G4spAXk7YvlOt5UJ3wrXzr1AHHMfU2rIr7QrowbN8sxYG\n\tTQn9LfwxRm+y3pt62TDeL+YxZWotagorlb+VrnARljxMkrpKEKXIEDIKHMY5bMpTZIWl\n\ttKow==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=5+boYhoE20g1aTmGiUb4iR1Pa8SbK9bEBGFwgPSNkLs=;\n\tb=CKWx6KiR0ofD8jwSha8FwV4nB8YkrVCcxOec6kK1LNd7m4kQE+Sdzew7HdUK7aJO7y\n\tGBD5DZRtLZEHbYyt8FLXmkeyL9VVItBxY+FaPbNr5uM0yeyhOtcLzevJRTvIkuHwg1BC\n\toEYDTtXMsWe64gQTdOpLdF67hEgie6YwRsNo8iu/sFSHMh9DMF4d5keeVXl1ZkD+iTFA\n\t8TEqxWr2zsWDHLqu0IfUar3lfqMz6jWxbXky2RpDIHWHG+KL1Fx2IJeZs6i+5K3Vwrqu\n\tYcav5u71t9EYSisX/TUDl93EfUleDJqhRa7izj/CtklRxQLvO395TXT+MMeqqe/+7Wrb\n\twlng==", "X-Gm-Message-State": "AOAM530PjFn9Xam8Q1+qbyevuVewS8JFnEJFhvOwTA1X1/NHXUuhkI87\n\t0MeRuXY2FQLO5ykbW30mYhtpLiMsKaIENjiF", "X-Google-Smtp-Source": "ABdhPJwy8gF1gQ0HnWSTgBGXtrhcKD0Jgu+wlplraaA/TV6Gq952MANEt6fNxGfBbcTfe09VzPbmTQ==", "X-Received": "by 2002:a5d:59ae:: with SMTP id\n\tp14mr3348845wrr.304.1642069535489; \n\tThu, 13 Jan 2022 02:25:35 -0800 (PST)", "From": "Naushir Patuck <naush@raspberrypi.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Thu, 13 Jan 2022 10:25:28 +0000", "Message-Id": "<20220113102529.3163441-2-naush@raspberrypi.com>", "X-Mailer": "git-send-email 2.25.1", "In-Reply-To": "<20220113102529.3163441-1-naush@raspberrypi.com>", "References": "<20220113102529.3163441-1-naush@raspberrypi.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [RFC v1 1/2] libcamera: media_device: Add\n\tenumerateMediaWalks() helper", "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>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Add a new helper function to the MediaDevice class which returns a vector of\nall possible media device topologies starting at the sensor entity and walking\nto an endpoint for the media device. Each of these topologies is called a\nMediaWalk. For each entity in a MediaWalk, we store a MediaEntity pointer\ntogether with the source and sink MediaLink pointers.\n\nAs an example, consider the media graph below:\n\n+----------+\n| CSI2 |\n +-----^----+\n |\n +---+---+\n | Mux1 <-------+\n +--^----+ |\n | |\n+-----+---+ +---+---+\n| Sensor1 | | Mux2 |<--+\n+---------+ +-^-----+ |\n | |\n +-------+-+ +---+-----+\n | Sensor2 | | Sensor3 |\n +---------+ +---------+\n\nThis would return three MediaDevice::MediaWalk structures looking like:\n\n1)\n+----------+\n| CSI2 |\n+-----^----+\n |\n+-----+----+\n| Mux1 |\n+-----^----+\n |\n+-----+----+\n| Sensor1 |\n+----------+\n\n2)\n+----------+\n| CSI2 |\n+-----^----+\n |\n+-----+----+\n| Mux1 |\n+-----^----+\n |\n+-----+----+\n| Mux2 |\n+-----^----+\n |\n+-----+----+\n| Sensor2 |\n+----------+\n\n3)\n+----------+\n| CSI2 |\n+-----^----+\n |\n+-----+----+\n| Mux1 |\n+-----^----+\n |\n+-----+----+\n| Mux2 |\n+-----^----+\n |\n+-----+----+\n| Sensor3 |\n+----------+\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\n include/libcamera/internal/media_device.h | 12 ++\n src/libcamera/media_device.cpp | 135 ++++++++++++++++++++++\n 2 files changed, 147 insertions(+)", "diff": "diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h\nindex 6e2a63f38229..63fcbe423eb9 100644\n--- a/include/libcamera/internal/media_device.h\n+++ b/include/libcamera/internal/media_device.h\n@@ -25,6 +25,13 @@ namespace libcamera {\n class MediaDevice : protected Loggable\n {\n public:\n+\tstruct EntityParams {\n+\t\tMediaEntity *entity;\n+\t\tMediaLink *sinkLink;\n+\t\tMediaLink *sourceLink;\n+\t};\n+\tusing MediaWalk = std::vector<EntityParams>;\n+\n \tMediaDevice(const std::string &deviceNode);\n \t~MediaDevice();\n \n@@ -47,6 +54,8 @@ public:\n \tconst std::vector<MediaEntity *> &entities() const { return entities_; }\n \tMediaEntity *getEntityByName(const std::string &name) const;\n \n+\tstd::vector<MediaWalk> enumerateMediaWalks() const;\n+\n \tMediaLink *link(const std::string &sourceName, unsigned int sourceIdx,\n \t\t\tconst std::string &sinkName, unsigned int sinkIdx);\n \tMediaLink *link(const MediaEntity *source, unsigned int sourceIdx,\n@@ -77,6 +86,9 @@ private:\n \tfriend int MediaLink::setEnabled(bool enable);\n \tint setupLink(const MediaLink *link, unsigned int flags);\n \n+\tvoid walkGraph(std::vector<MediaWalk> *mediaWalks, MediaWalk *walk,\n+\t\t MediaEntity *entity, MediaLink *sinkLink) const;\n+\n \tstd::string driver_;\n \tstd::string deviceNode_;\n \tstd::string model_;\ndiff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\nindex 941f86c25f66..60b397e205a2 100644\n--- a/src/libcamera/media_device.cpp\n+++ b/src/libcamera/media_device.cpp\n@@ -340,6 +340,105 @@ MediaEntity *MediaDevice::getEntityByName(const std::string &name) const\n \treturn nullptr;\n }\n \n+/**\n+ * \\fn MediaDevice::enumerateMediaWalks()\n+ * \\brief Retrieve the list of all possible MediaWalks available to this device\n+ *\n+ * Enumerate the media graph and return all possible permutations of unique\n+ * sub-graphs where the first entity is a sensor device. These sub-graphs are\n+ * stored as a \\a MediaDevice::MediaWalk structure, where each element gives the\n+ * device entity and associated sink pad link. The first entity in this structure\n+ * is asensor device, with the sink pad link set to a nullptr.\n+ *\n+ * As an example, consider the media graph below:\n+ *\n+ * +----------+\n+ * | CSI2 |\n+ * +-----^----+\n+ * |\n+ * +---+---+\n+ * | Mux1 <-------+\n+ * +--^----+ |\n+ * | |\n+ * +-----+---+ +---+---+\n+ * | Sensor1 | | Mux2 |<--+\n+ * +---------+ +-^-----+ |\n+ * | |\n+ * +-------+-+ +---+-----+\n+ * | Sensor2 | | Sensor3 |\n+ * +---------+ +---------+\n+ *\n+ * This would return three \\a MediaDevice::MediaWalk structures looking like:\n+ *\n+ * 1)\n+ * +----------+\n+ * | CSI2 |\n+ * +-----^----+\n+ * |\n+ * +-----+----+\n+ * | Mux1 |\n+ * +-----^----+\n+ * |\n+ * +-----+----+\n+ * | Sensor1 |\n+ * +----------+\n+ *\n+ * 2)\n+ * +----------+\n+ * | CSI2 |\n+ * +-----^----+\n+ * |\n+ * +-----+----+\n+ * | Mux1 |\n+ * +-----^----+\n+ * |\n+ * +-----+----+\n+ * | Mux2 |\n+ * +-----^----+\n+ * |\n+ * +-----+----+\n+ * | Sensor2 |\n+ * +----------+\n+ *\n+ * 3)\n+ * +----------+\n+ * | CSI2 |\n+ * +-----^----+\n+ * |\n+ * +-----+----+\n+ * | Mux1 |\n+ * +-----^----+\n+ * |\n+ * +-----+----+\n+ * | Mux2 |\n+ * +-----^----+\n+ * |\n+ * +-----+----+\n+ * | Sensor3 |\n+ * +----------+\n+ *\n+ * \\return A vector of MediaWalk structures available\n+ */\n+std::vector<MediaDevice::MediaWalk> MediaDevice::enumerateMediaWalks() const\n+{\n+\tstd::vector<MediaWalk> mediaWalks;\n+\n+\tfor (MediaEntity *entity : entities_) {\n+\t\t/* Only perform enumeration starting with sensor entities */\n+\t\tif (entity->function() != MEDIA_ENT_F_CAM_SENSOR)\n+\t\t\tcontinue;\n+\t\t/*\n+\t\t * Start with an empty MediaWalk structure, and walk the graph\n+\t\t * with the sensor entity at the top, and a nullptr as the sink\n+\t\t * pad link.\n+\t\t */\n+\t\tmediaWalks.push_back({});\n+\t\twalkGraph(&mediaWalks, &mediaWalks.back(), entity, nullptr);\n+\t}\n+\n+\treturn mediaWalks;\n+}\n+\n /**\n * \\brief Retrieve the MediaLink connecting two pads, identified by entity\n * names and pad indexes\n@@ -800,4 +899,40 @@ int MediaDevice::setupLink(const MediaLink *link, unsigned int flags)\n \treturn 0;\n }\n \n+void MediaDevice::walkGraph(std::vector<MediaWalk> *mediaWalks, MediaWalk *walk,\n+\t\t\t MediaEntity *entity, MediaLink *sinkLink) const\n+{\n+\tbool newWalk = false;\n+\n+\twalk->push_back({ entity, sinkLink, nullptr });\n+\n+\tfor (const MediaPad *pad : entity->pads()) {\n+\t\t/* We only walk down the graph, so ignore any sink pads */\n+\t\tif (pad->flags() & MEDIA_PAD_FL_SINK)\n+\t\t\tcontinue;\n+\n+\t\tfor (MediaLink *nextLink : pad->links()) {\n+\t\t\tMediaDevice::MediaWalk *nextWalk = walk;\n+\t\t\t/*\n+\t\t\t * If this is a new branch in the graph, create a new\n+\t\t\t * MediaWalk structure in our list, and populate it with\n+\t\t\t * a copy of the curret MediaWalk. Any subsequent recursion\n+\t\t\t * into this graph branch will cause it to diverge.\n+\t\t\t */\n+\t\t\tif (newWalk) {\n+\t\t\t\tmediaWalks->push_back(*walk);\n+\t\t\t\tnextWalk = &mediaWalks->back();\n+\t\t\t}\n+\n+\t\t\t/* Record the source pad link for the current entity */\n+\t\t\twalk->back().sourceLink = nextLink;\n+\n+\t\t\t/* Recurse into the next entity for this source pad link */\n+\t\t\tMediaEntity *nextEntity = nextLink->sink()->entity();\n+\t\t\twalkGraph(mediaWalks, nextWalk, nextEntity, nextLink);\n+\t\t\tnewWalk = true;\n+\t\t}\n+\t}\n+}\n+\n } /* namespace libcamera */\n", "prefixes": [ "libcamera-devel", "RFC", "v1", "1/2" ] }