Show a patch.

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

{
    "id": 21817,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/21817/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/21817/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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": "<20241106173651.2859827-2-chenghaoyang@chromium.org>",
    "date": "2024-11-06T17:35:32",
    "name": "[v2,1/1] libcamera: Add request API support for media controller device",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "0aed7a9a955f153ea6516f4043ac77f1b9323c67",
    "submitter": {
        "id": 117,
        "url": "https://patchwork.libcamera.org/api/1.1/people/117/?format=api",
        "name": "Cheng-Hao Yang",
        "email": "chenghaoyang@chromium.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/21817/mbox/",
    "series": [
        {
            "id": 4772,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4772/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4772",
            "date": "2024-11-06T17:35:31",
            "name": "Add request API support for MediaDevice",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/4772/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/21817/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/21817/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 B5453BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  6 Nov 2024 17:37:03 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7CD0965434;\n\tWed,  6 Nov 2024 18:37:01 +0100 (CET)",
            "from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com\n\t[IPv6:2607:f8b0:4864:20::1029])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EDFEF653C5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  6 Nov 2024 18:36:58 +0100 (CET)",
            "by mail-pj1-x1029.google.com with SMTP id\n\t98e67ed59e1d1-2e2e8c8915eso44585a91.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 06 Nov 2024 09:36:58 -0800 (PST)",
            "from chenghaoyang-low.c.googlers.com.com\n\t(27.247.221.35.bc.googleusercontent.com. [35.221.247.27])\n\tby smtp.gmail.com with ESMTPSA id\n\t98e67ed59e1d1-2e99a5f98a8sm1793400a91.38.2024.11.06.09.36.55\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 06 Nov 2024 09:36:56 -0800 (PST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"ZtJ07MjL\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google; t=1730914617; x=1731519417;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=Mmt8xNR5TxiZqXeDF8uJiF4BykrrWATBKTdFJk8Vzrs=;\n\tb=ZtJ07MjLf62Atw6UGhoM3rA9J9NrCIowYn8jLGUYfy9zx/l6rV634V0DwKOw7skW2H\n\t8xK1cMN4r5OQyRgra7y54BjFMk1pKqyuGZHRb1aK2csdmWzuwN5jGboLxAFlcByOGcIT\n\tsfJjfELiu0zXxT4+ph0IH8V11qIdkbrdpW5ng=",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1730914617; x=1731519417;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=Mmt8xNR5TxiZqXeDF8uJiF4BykrrWATBKTdFJk8Vzrs=;\n\tb=Oo8rcutls0KHsx1TGqVaMsHWwZHQ3I4mBTRI1FM8BkZhA9+6v3vSbX6sX0Y0xCn+mP\n\tg8a1ULcwsiwk1Iz8XRr35aWBWmnH2maIePBdcPeFwpTvVckTZbct26gr4lDww6z/jSwZ\n\txr+kTPbjA4y22bvZFwuIvBz+iRy4rggGBpH/lc9ot0PECK4zwkCpTS9kV9CRt+dtA45X\n\txPEVK12R1aRFfw+pYwwKjrVRlkbTQ0ToH/Opp1mB4pmarPRrYuPKpIBUzuU49r1nL0X7\n\t4aV+fUh+fSpE3NkLO4GnGgjweAGBo+XBTcVIi+5sBctw1BoQvWQ+BlFrDKZjIhYQLoxu\n\t4Bkw==",
        "X-Gm-Message-State": "AOJu0Yxd4bvQNWZ7CDTV/4pOMws5YePtQBwM8rWwVmjHQUzfprPR52Et\n\tFmFFoT+DSpLQC+epVYpW9rpvNvxl1Xl/nmT6rCTZ+Mwwh4LBZrcD9QbakzUOsXQj62KUH8py7n8\n\tCRQ==",
        "X-Google-Smtp-Source": "AGHT+IH0rfbi8j7rz+6zFSEtfZIyZ5nIlOyk3OpgrnjzvE8+0P9ULOCO6SHfr8mSNO1/O3HxddZLwA==",
        "X-Received": "by 2002:a17:90b:1bd2:b0:2e0:9d3e:bc2a with SMTP id\n\t98e67ed59e1d1-2e94c51c5f2mr27980288a91.32.1730914617094; \n\tWed, 06 Nov 2024 09:36:57 -0800 (PST)",
        "From": "Harvey Yang <chenghaoyang@chromium.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Han-Lin Chen <hanlinchen@chromium.org>,\n\tHarvey Yang <chenghaoyang@chromium.org>",
        "Subject": "[PATCH v2 1/1] libcamera: Add request API support for media\n\tcontroller device",
        "Date": "Wed,  6 Nov 2024 17:35:32 +0000",
        "Message-ID": "<20241106173651.2859827-2-chenghaoyang@chromium.org>",
        "X-Mailer": "git-send-email 2.47.0.199.ga7371fff76-goog",
        "In-Reply-To": "<20241106173651.2859827-1-chenghaoyang@chromium.org>",
        "References": "<20241106173651.2859827-1-chenghaoyang@chromium.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "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": "From: Han-Lin Chen <hanlinchen@chromium.org>\n\nThis patch adds `allocateRequest` with MEDIA_IOC_REQUEST_ALLOC in\nMediaDevice, and introduces class MediaDevice::Request that allows users\nto queue the request and be notified when the request is recycled.\n\nSigned-off-by: Han-Lin Chen <hanlinchen@chromium.org>\nCo-developed-by: Harvey Yang <chenghaoyang@chromium.org>\n---\n include/libcamera/internal/media_device.h |  26 ++++++\n src/libcamera/media_device.cpp            | 106 ++++++++++++++++++++++\n 2 files changed, 132 insertions(+)",
    "diff": "diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h\nindex e412d3a0b..c7ac76440 100644\n--- a/include/libcamera/internal/media_device.h\n+++ b/include/libcamera/internal/media_device.h\n@@ -13,6 +13,7 @@\n \n #include <linux/media.h>\n \n+#include <libcamera/base/event_notifier.h>\n #include <libcamera/base/log.h>\n #include <libcamera/base/signal.h>\n #include <libcamera/base/unique_fd.h>\n@@ -24,6 +25,29 @@ namespace libcamera {\n class MediaDevice : protected Loggable\n {\n public:\n+\tclass Request : protected Loggable\n+\t{\n+\tpublic:\n+\t\tRequest(MediaDevice *mediaDevice, UniqueFD fd);\n+\n+\t\tint queueRequest();\n+\n+\t\tint fd() const { return fd_.get(); }\n+\n+\t\tSignal<Request *> recycled_;\n+\n+\tprotected:\n+\t\tstd::string logPrefix() const override;\n+\n+\tprivate:\n+\t\tvoid reinit();\n+\n+\t\tMediaDevice *mediaDevice_;\n+\t\tUniqueFD fd_;\n+\n+\t\tEventNotifier eventNotifier_;\n+\t};\n+\n \tMediaDevice(const std::string &deviceNode);\n \t~MediaDevice();\n \n@@ -53,6 +77,8 @@ public:\n \tMediaLink *link(const MediaPad *source, const MediaPad *sink);\n \tint disableLinks();\n \n+\tstd::unique_ptr<Request> allocateRequest();\n+\n \tSignal<> disconnected;\n \n protected:\ndiff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\nindex d71dad74d..f25d05043 100644\n--- a/src/libcamera/media_device.cpp\n+++ b/src/libcamera/media_device.cpp\n@@ -55,6 +55,91 @@ LOG_DEFINE_CATEGORY(MediaDevice)\n  * managers to claim media devices they support during enumeration.\n  */\n \n+/**\n+ * \\class MediaDevice::Request\n+ * \\brief The request from a MediaDevice that supports request API\n+ */\n+\n+/**\n+ * \\brief Construct a MediaDevice::Request\n+ * \\param[in] mediaDevice The MediaDevice instance that allocate this request\n+ * \\param[in] fd The request's fild descriptor\n+ */\n+MediaDevice::Request::Request(MediaDevice *mediaDevice, UniqueFD fd)\n+\t: mediaDevice_(mediaDevice), fd_(std::move(fd)),\n+\t  eventNotifier_(fd_.get(), EventNotifier::Type::Exception)\n+{\n+\teventNotifier_.activated.connect(this, &MediaDevice::Request::reinit);\n+}\n+\n+std::string MediaDevice::Request::logPrefix() const\n+{\n+\treturn mediaDevice_->logPrefix() + \" Request\";\n+}\n+\n+/**\n+ * \\brief Queue a request to the media device\n+ *\n+ * A request needs to be re-init'ed before being queued again. This class will\n+ * notify the user with signal `recycled` when the request is re-init'ed.\n+ *\n+ * \\sa reinit()\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int MediaDevice::Request::queueRequest()\n+{\n+\tint requestFd = fd_.get();\n+\tint ret = ioctl(requestFd, MEDIA_REQUEST_IOC_QUEUE, NULL);\n+\tif (ret) {\n+\t\tLOG(MediaDevice, Error) << \"QueueRequest fd \" << requestFd\n+\t\t\t\t\t<< \"failed: \" << strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\n+\teventNotifier_.setEnabled(true);\n+\n+\treturn ret;\n+}\n+\n+/**\n+ * \\fn int MediaDevice::Request::fd()\n+ * \\return The request's file descriptor in int\n+ */\n+\n+/**\n+ * \\var MediaDevice::Request::recycled_\n+ * \\brief The signal to notify the user when this request is recycled and ready\n+ * to be queued again\n+ *\n+ * After this request is queued with `queueRequest()`, the user needs to wait\n+ * for signal `recycled_` being emitted, before queueing this request again.\n+ */\n+\n+/**\n+ * \\brief Re-init a request\n+ *\n+ * This function recycles a request that was queued before. It's triggered when\n+ * `eventNotifier_` confirms the file descriptor is completed.\n+ *\n+ * \\sa queueRequest()\n+ */\n+void MediaDevice::Request::reinit()\n+{\n+\teventNotifier_.setEnabled(false);\n+\n+\tint requestFd = fd_.get();\n+\tint ret = ::ioctl(requestFd, MEDIA_REQUEST_IOC_REINIT, NULL);\n+\tif (ret) {\n+\t\tLOG(MediaDevice, Error) << \"The request \" << requestFd\n+\t\t\t\t\t<< \" is queued but not yet completed: \"\n+\t\t\t\t\t<< strerror(-ret);\n+\t\treturn;\n+\t}\n+\n+\trecycled_.emit(this);\n+}\n+\n /**\n  * \\brief Construct a MediaDevice\n  * \\param[in] deviceNode The media device node path\n@@ -828,4 +913,25 @@ int MediaDevice::setupLink(const MediaLink *link, unsigned int flags)\n \treturn 0;\n }\n \n+/**\n+ * \\brief Allocate a request from the media device\n+ *\n+ * This function returns a request containing a file descriptor if the\n+ * MediaDevice supports request API.\n+ *\n+ * \\return A request on success or nullptr otherwise\n+ */\n+std::unique_ptr<MediaDevice::Request> MediaDevice::allocateRequest()\n+{\n+\tint fd;\n+\tint ret = ioctl(fd_.get(), MEDIA_IOC_REQUEST_ALLOC, &fd);\n+\tif (ret) {\n+\t\tLOG(MediaDevice, Error) << \"Allocate request failed \"\n+\t\t\t\t\t<< strerror(-ret);\n+\t\treturn nullptr;\n+\t}\n+\n+\treturn std::make_unique<MediaDevice::Request>(this, UniqueFD(fd));\n+}\n+\n } /* namespace libcamera */\n",
    "prefixes": [
        "v2",
        "1/1"
    ]
}