Show a patch.

GET /api/patches/15163/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 15163,
    "url": "https://patchwork.libcamera.org/api/patches/15163/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/15163/",
    "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": "<20211214140002.3552445-3-naush@raspberrypi.com>",
    "date": "2021-12-14T14:00:02",
    "name": "[libcamera-devel,v4,2/2] pipeline: raspberrypi: Add support for Video Mux and Bridge devices",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "67c2dea37068c89b0354e00ce3521e1050663cc5",
    "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/15163/mbox/",
    "series": [
        {
            "id": 2844,
            "url": "https://patchwork.libcamera.org/api/series/2844/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2844",
            "date": "2021-12-14T14:00:00",
            "name": "Raspberry Pi: Add video mux and bridge support",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/2844/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/15163/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/15163/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 C2384BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 14 Dec 2021 14:00:10 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D3ED9608F8;\n\tTue, 14 Dec 2021 15:00:08 +0100 (CET)",
            "from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com\n\t[IPv6:2a00:1450:4864:20::42d])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 015FC605A7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Dec 2021 15:00:07 +0100 (CET)",
            "by mail-wr1-x42d.google.com with SMTP id a9so32518303wrr.8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Dec 2021 06:00:06 -0800 (PST)",
            "from naush-laptop.pitowers.org\n\t([2a00:1098:3142:14:8958:60a:582a:396])\n\tby smtp.gmail.com with ESMTPSA id\n\tm7sm2160999wml.38.2021.12.14.06.00.05\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 14 Dec 2021 06:00:05 -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=\"cYiVzQlb\"; 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=ZCKX3n4FlvxqPd70WacoWyzyIEYvZ2ike0riBFRMQlU=;\n\tb=cYiVzQlbMTTgjd7FF2B2Mf2czFj/SUm6/wCeUNeL6wQVGnIb2WF+5IoCL2xmYY386T\n\tPnl+mFv3Bvb6KI2ba53c+17BtzfQj7KcjUtbt0tPupvsL8jZBknokL8n2tembdQI+Ps4\n\tCHKsF3vpRROgbYLN6ur4UKD71A6uCE7KYCXeiZQSb/rTaOtNkuL2RHSAdR6gqZuU/sxI\n\t2nlshgDhbizO5cN/HwlkUs4+iX+mmGRAJMNw6RL4zfOT9PXITeycJeWf5yMcEtmgn+ec\n\tAHBDqZokd5V4T/vMe+SFzrCLvlpbJo8hM5n8sEFQm+ysywKxDpee4GJrPBjNEUMU2NsY\n\tNTeQ==",
        "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=ZCKX3n4FlvxqPd70WacoWyzyIEYvZ2ike0riBFRMQlU=;\n\tb=h3qJggS/radrAB1kikAh5raP4TnoF3xUOFblbUN9UJm/d78uA5fRZij7Vqm/0epx+K\n\t+Vm1U+GCDOHqfKbNyTjmt1yJh4r50neQgRtKBLOl/++X4CC7ZnJU1XEg3uCRpB9ZtoXF\n\t5+f8DaJNnd78KVBgenA9LHTfUkCyjrBVFcIfsJSlAn39bTXal9rLJ1MrHw98ps/INeq8\n\t3SN1iZRrbPN95xfOKbnOTw6qoppOqr7O0e9+BEdCHOGjXCT6dnM4tEZW2wO2pltbc73l\n\tVGur89cmAJrTCH+EP6GDtzIzCrNkcA4EnTf5KOHqgmdvqc8oCSwfAPmFIivXqim79oNM\n\t87ag==",
        "X-Gm-Message-State": "AOAM533MrS3cKO0jGH5oW5Qr/6wqf4BpekmdqksxK+gOrZKMPw6LbT79\n\tttUFHMFPThVq6boukPs1JrX80nu2jDAx9Q==",
        "X-Google-Smtp-Source": "ABdhPJzswO0rU8hFYsT9uYGOqdEWMqd9PmLrYJJGTpvBV42aIFbsEicvxnwZhA6vpZOJs7FS5FA3uA==",
        "X-Received": "by 2002:a5d:6c63:: with SMTP id r3mr6212790wrz.213.1639490406310;\n\tTue, 14 Dec 2021 06:00:06 -0800 (PST)",
        "From": "Naushir Patuck <naush@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue, 14 Dec 2021 14:00:02 +0000",
        "Message-Id": "<20211214140002.3552445-3-naush@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20211214140002.3552445-1-naush@raspberrypi.com>",
        "References": "<20211214140002.3552445-1-naush@raspberrypi.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v4 2/2] pipeline: raspberrypi: Add support\n\tfor Video Mux and Bridge devices",
        "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": "This change will allow the pipeline handler to enumerate and control Video\nMux or Bridge devices that may be attached between sensors and a particular\nUnicam instance. Cascaded mux or bridge devices are also handled.\n\nA new member function RPiCameraData::enumerateVideoDevices(), called from\nPipelineHandlerRPi::registerCamera(), is used to identify and open all mux and\nbridge subdevices present in the sensor -> Unicam link.\n\nRelevent links are enabled/disabled and pad formats correctly set in\nPipelineHandlerRPi::configure() before the camera is started.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n .../pipeline/raspberrypi/raspberrypi.cpp      | 139 ++++++++++++++++++\n 1 file changed, 139 insertions(+)",
    "diff": "diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 2a2fb5273eb8..4ec646d3c7a3 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -12,6 +12,7 @@\n #include <mutex>\n #include <queue>\n #include <unordered_set>\n+#include <utility>\n \n #include <libcamera/base/shared_fd.h>\n #include <libcamera/base/utils.h>\n@@ -191,6 +192,8 @@ public:\n \tint loadIPA(ipa::RPi::SensorConfig *sensorConfig);\n \tint configureIPA(const CameraConfiguration *config);\n \n+\tvoid enumerateVideoDevices(MediaLink *link);\n+\n \tvoid statsMetadataComplete(uint32_t bufferId, const ControlList &controls);\n \tvoid runIsp(uint32_t bufferId);\n \tvoid embeddedComplete(uint32_t bufferId);\n@@ -220,6 +223,11 @@ public:\n \tstd::vector<RPi::Stream *> streams_;\n \t/* Stores the ids of the buffers mapped in the IPA. */\n \tstd::unordered_set<unsigned int> ipaBuffers_;\n+\t/*\n+\t * Stores a cascade of Video Mux or Bridge devices between the sensor and\n+\t * Unicam together with media link across the entities.\n+\t */\n+\tstd::vector<std::pair<std::unique_ptr<V4L2Subdevice>, MediaLink *>> bridgeDevices_;\n \n \t/* DMAHEAP allocation helper. */\n \tRPi::DmaHeap dmaHeap_;\n@@ -868,6 +876,38 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n \t */\n \tdata->properties_.set(properties::ScalerCropMaximum, data->sensorInfo_.analogCrop);\n \n+\t/* Setup the Video Mux/Bridge entities. */\n+\tfor (auto &[device, link] : data->bridgeDevices_) {\n+\t\t/*\n+\t\t * Start by disabling all the sink pad links on the devices in the\n+\t\t * cascade, with the exception of the link connecting the device.\n+\t\t */\n+\t\tfor (const MediaPad *p : device->entity()->pads()) {\n+\t\t\tif (!(p->flags() & MEDIA_PAD_FL_SINK))\n+\t\t\t\tcontinue;\n+\n+\t\t\tfor (MediaLink *l : p->links()) {\n+\t\t\t\tif (l != link)\n+\t\t\t\t\tl->setEnabled(false);\n+\t\t\t}\n+\t\t}\n+\n+\t\t/* Next, enable the entity -> entity links, and setup the pad format. */\n+\t\tlink->setEnabled(true);\n+\t\tconst MediaPad *srcPad = link->sink();\n+\t\tret = device->setFormat(srcPad->index(), &sensorFormat);\n+\t\tif (ret) {\n+\t\t\tLOG(RPI, Error) << \"Failed to set format on \" << device->entity()->name()\n+\t\t\t\t\t<< \" pad \" << srcPad->index()\n+\t\t\t\t\t<< \" with format  \" << format.toString()\n+\t\t\t\t\t<< \": \" << ret;\n+\t\t\treturn ret;\n+\t\t}\n+\n+\t\tLOG(RPI, Info) << \"Configured media link on device \" << device->entity()->name()\n+\t\t\t       << \" on pad \" << srcPad->index();\n+\t}\n+\n \treturn ret;\n }\n \n@@ -1098,6 +1138,13 @@ int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp, Me\n \tif (data->sensor_->init())\n \t\treturn -EINVAL;\n \n+\t/*\n+\t * Enumerate all the Video Mux/Bridge devices across the sensor -> unicam\n+\t * link. There may be a cascade of devices in this link!\n+\t */\n+\tMediaLink *link = sensorEntity->getPadByIndex(0)->links()[0];\n+\tdata->enumerateVideoDevices(link);\n+\n \tdata->sensorFormats_ = populateSensorFormats(data->sensor_);\n \n \tipa::RPi::SensorConfig sensorConfig;\n@@ -1447,6 +1494,98 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config)\n \treturn 0;\n }\n \n+/*\n+ * enumerateVideoDevices() iterates over the Media Controller topology, starting\n+ * at the sensor and finishing at Unicam. For each sensor, RPiCameraData stores\n+ * a unique list of any intermediate video mux or bridge devices connected in a\n+ * cascade, together with the entity to entity link.\n+ *\n+ * Entity pad configuration and link enabling happens at the end of configure().\n+ * We first disables all pad links on each entity device in the chain, and then\n+ * selectively enabling the specific links to link sensor to Unicam across all\n+ * intermediate muxes and bridges.\n+ *\n+ * In the cascaded topology below, if Sensor1 is used, the Mux2 -> Mux1 link\n+ * will be disabled, and Sensor1 -> Mux1 -> Unicam links enabled. Alternatively,\n+ * if Sensor3 is used, the Sensor2 -> Mux2 and Sensor1 -> Mux1 links are disabled,\n+ * and Sensor3 -> Mux2 -> Mux1 -> Unicam links are enabled. All other links will\n+ * remain unchanged.\n+ *\n+ *  +----------+\n+ *  |  Unicam  |\n+ *  +-----^----+\n+ *        |\n+ *    +---+---+\n+ *    |  Mux1 <-------+\n+ *    +--^----+       |\n+ *       |            |\n+ * +-----+---+    +---+---+\n+ * | Sensor1 |    |  Mux2 |<--+\n+ * +---------+    +-^-----+   |\n+ *                  |         |\n+ *          +-------+-+   +---+-----+\n+ *          | Sensor2 |   | Sensor3 |\n+ *          +---------+   +---------+\n+ */\n+void RPiCameraData::enumerateVideoDevices(MediaLink *link)\n+{\n+\tconst MediaPad *sinkPad = link->sink();\n+\tconst MediaEntity *entity = sinkPad->entity();\n+\tbool unicamFound = false;\n+\n+\t/* We only deal with Video Mux and Bridge devices in cascade. */\n+\tif (entity->function() != MEDIA_ENT_F_VID_MUX &&\n+\t    entity->function() != MEDIA_ENT_F_VID_IF_BRIDGE)\n+\t\treturn;\n+\n+\t/* Find the source pad for this Video Mux or Bridge device. */\n+\tconst MediaPad *entitySourcePad = nullptr;\n+\tfor (const MediaPad *pad : entity->pads()) {\n+\t\tif (pad->flags() & MEDIA_PAD_FL_SOURCE) {\n+\t\t\t/*\n+\t\t\t * We can only deal with devices that have a single source\n+\t\t\t * pad. If this device has multple source pads, ignore it\n+\t\t\t * and this branch in the cascade.\n+\t\t\t */\n+\t\t\tif (entitySourcePad)\n+\t\t\t\treturn;\n+\n+\t\t\tentitySourcePad = pad;\n+\t\t}\n+\t}\n+\n+\tLOG(RPI, Info) << \"Found video mux device \" << entity->name()\n+\t\t       << \" linked to sink pad \" << sinkPad->index();\n+\n+\tbridgeDevices_.emplace_back(std::make_unique<V4L2Subdevice>(entity), link);\n+\tbridgeDevices_.back().first->open();\n+\n+\t/*\n+\t * Iterate through all the sink pad links down the cascade to find any\n+\t * other Video Mux and Bridge devices.\n+\t */\n+\tfor (MediaLink *l : entitySourcePad->links()) {\n+\t\tenumerateVideoDevices(l);\n+\t\t/* Once we reach the Unicam entity, we are done. */\n+\t\tif (l->sink()->entity()->name() == \"unicam-image\") {\n+\t\t\tunicamFound = true;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\t/* This identifies the end of our entity enumeration recursion. */\n+\tif (link->source()->entity()->function() == MEDIA_ENT_F_CAM_SENSOR) {\n+\t\t/*\n+\t\t* If Unicam is not at the end of this cascade, we cannot configure\n+\t\t* this topology automatically, so remove all entity references.\n+\t\t*/\n+\t\tif (!unicamFound) {\n+\t\t\tLOG(RPI, Warning) << \"Cannot automatically configure this MC topology!\";\n+\t\t\tbridgeDevices_.clear();\n+\t\t}\n+\t}\n+}\n+\n void RPiCameraData::statsMetadataComplete(uint32_t bufferId, const ControlList &controls)\n {\n \tif (state_ == State::Stopped)\n",
    "prefixes": [
        "libcamera-devel",
        "v4",
        "2/2"
    ]
}