{"id":21325,"url":"https://patchwork.libcamera.org/api/patches/21325/?format=json","web_url":"https://patchwork.libcamera.org/patch/21325/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20240923060551.1849065-2-chenghaoyang@google.com>","date":"2024-09-23T06:02:35","name":"[1/1] libcamera: Add request API support for media controller device","commit_ref":null,"pull_url":null,"state":"changes-requested","archived":false,"hash":"51d51551f5876cce837d2a2e0831ff79a127593b","submitter":{"id":117,"url":"https://patchwork.libcamera.org/api/people/117/?format=json","name":"Cheng-Hao Yang","email":"chenghaoyang@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/21325/mbox/","series":[{"id":4611,"url":"https://patchwork.libcamera.org/api/series/4611/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4611","date":"2024-09-23T06:02:34","name":"Add request API support for MediaDevice","version":1,"mbox":"https://patchwork.libcamera.org/series/4611/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/21325/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/21325/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 F27FCC0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 23 Sep 2024 06:06:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4306163508;\n\tMon, 23 Sep 2024 08:06:04 +0200 (CEST)","from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com\n\t[IPv6:2607:f8b0:4864:20::52e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1E3AA634F4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Sep 2024 08:06:02 +0200 (CEST)","by mail-pg1-x52e.google.com with SMTP id\n\t41be03b00d2f7-7db12af2f31so3315999a12.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 22 Sep 2024 23:06:02 -0700 (PDT)","from chenghaoyang-low.c.googlers.com.com\n\t(208.158.221.35.bc.googleusercontent.com. [35.221.158.208])\n\tby smtp.gmail.com with ESMTPSA id\n\t98e67ed59e1d1-2dd50bfc88asm6369920a91.0.2024.09.22.23.05.58\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSun, 22 Sep 2024 23:05:59 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"kY1MCxxv\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google; t=1727071560; x=1727676360;\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=TQTkOyswq9G1VDrDGvJyIsuI03VF30js8vfGj2qnPNg=;\n\tb=kY1MCxxvXudYYiE4gYp/lE3NJi3My4GN0CHPHa2bHxg7MtTo6/97orZa8/YGQn6shb\n\tR7Kss9+h4GkUqaXa1qx01m/JSR3cl47cE7k09+R+u4fVfs0WZ9s0ailnsiUkI0cQTUAA\n\tvoPTgNXF524xtMGDoJQKcil+zhWAVLVyERq6Q=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1727071560; x=1727676360;\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=TQTkOyswq9G1VDrDGvJyIsuI03VF30js8vfGj2qnPNg=;\n\tb=U71DkCpeI+YgCtayoLBFOJqUDCut3Gitxspf+BF+XfE3GtoiYRDR0tVWLeGrjf97R7\n\tNePENx8bxy5ZDmxwoJJhtUc4sr0uIEy79aHZjIaB73qGgQx9zW9rg2IyGJKr5+GdjbGO\n\txv+URnKs7T68QVZUZErP3mgf7QmFT4is5zefjKDMiDzGsV4tkouzS6KLUX7x9Yn0D0Gd\n\twjaxur7C30QJ5R+/6pwMwB2wplPLc6qfh3qA9oBEG6K/XUul4pk9TFXapK2HI44egXTD\n\twmNaLP9GruAnS1mxaJ9XRFxj80yHvA/BhmOmS35iKg8eZK1bj1z84Kvz0MIZmaQ59XGz\n\thuqQ==","X-Gm-Message-State":"AOJu0Ywx3MrCwSVt9hHFEhu3fx21TW7xP5z1CVOsL+98qgcDc9iqtHL7\n\tW8Q4DrOir2Rt92c9oEex6C7qOMhmVnXvrftd42UVwncZ81bbwApZfqYwWjFfrjiE16Z+fmSscJc\n\t=","X-Google-Smtp-Source":"AGHT+IFr4lD3Fl2RWt7jbt+P2l6J5YciwQsa2mvgPTKmAemipCkt85bgOKNXYUHr6qR5y7lJNN3S8g==","X-Received":"by 2002:a17:90a:d908:b0:2d8:83ce:d4c0 with SMTP id\n\t98e67ed59e1d1-2dd7f40ad24mr13908919a91.13.1727071559826; \n\tSun, 22 Sep 2024 23:05:59 -0700 (PDT)","From":"Harvey Yang <chenghaoyang@chromium.org>","X-Google-Original-From":"Harvey Yang <chenghaoyang@google.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Han-Lin Chen <hanlinchen@chromium.org>,\n\tHarvey Yang <chenghaoyang@chromium.org>","Subject":"[PATCH 1/1] libcamera: Add request API support for media controller\n\tdevice","Date":"Mon, 23 Sep 2024 06:02:35 +0000","Message-ID":"<20240923060551.1849065-2-chenghaoyang@google.com>","X-Mailer":"git-send-email 2.46.0.792.g87dc391469-goog","In-Reply-To":"<20240923060551.1849065-1-chenghaoyang@google.com>","References":"<20240923060551.1849065-1-chenghaoyang@google.com>","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 `allocateRequests` with MEDIA_IOC_REQUEST_ALLOC\n, `queueRequest` with MEDIA_REQUEST_IOC_QUEUE, and `reInitRequest`\nwith MEDIA_REQUEST_IOC_REINIT.\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 |  4 ++\n src/libcamera/media_device.cpp            | 87 +++++++++++++++++++++++\n 2 files changed, 91 insertions(+)","diff":"diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h\nindex e412d3a0..8f54dd12 100644\n--- a/include/libcamera/internal/media_device.h\n+++ b/include/libcamera/internal/media_device.h\n@@ -53,6 +53,10 @@ public:\n \tMediaLink *link(const MediaPad *source, const MediaPad *sink);\n \tint disableLinks();\n \n+\tint allocateRequests(unsigned int count, std::vector<UniqueFD> &requests);\n+\tint queueRequest(int requestFd);\n+\tint reInitRequest(int requestFd);\n+\n \tSignal<> disconnected;\n \n protected:\ndiff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\nindex bd054552..47b75809 100644\n--- a/src/libcamera/media_device.cpp\n+++ b/src/libcamera/media_device.cpp\n@@ -9,6 +9,7 @@\n \n #include <errno.h>\n #include <fcntl.h>\n+#include <poll.h>\n #include <stdint.h>\n #include <string>\n #include <string.h>\n@@ -836,4 +837,90 @@ int MediaDevice::setupLink(const MediaLink *link, unsigned int flags)\n \treturn 0;\n }\n \n+/**\n+ * \\brief Allocate \\a count requests with ioctl\n+ * \\param[in] count The number of requests to be allocated\n+ * \\param[out] requests The request file descriptors to be returned\n+ *\n+ * This function returns request file descriptors if the MediaDevice supports\n+ * requests. The file descriptors can then be queued and re-inited afterwards.\n+ *\n+ * \\sa queueRequest(int requestFd)\n+ * \\sa reInitRequest(int requestFd)\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int MediaDevice::allocateRequests(unsigned int count, std::vector<UniqueFD> &requests)\n+{\n+\tfor (unsigned int i = 0; i < count; i++) {\n+\t\tint fd;\n+\t\tint ret = ioctl(fd_.get(), MEDIA_IOC_REQUEST_ALLOC, &fd);\n+\t\tif (ret) {\n+\t\t\tLOG(MediaDevice, Error) << \"Allocate request failed \"\n+\t\t\t\t\t\t<< strerror(-ret);\n+\t\t\treturn -EBUSY;\n+\t\t}\n+\t\trequests.emplace_back(fd);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Queue a request with ioctl\n+ * \\param[in] requestFd The request file descriptor\n+ *\n+ * This function queues a request that was allocated before.\n+ *\n+ * \\sa allocateRequests(unsigned int count, std::vector<UniqueFD> &requests)\n+ * \\sa reInitRequest(int requestFd)\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int MediaDevice::queueRequest(int requestFd)\n+{\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+\treturn ret;\n+}\n+\n+/**\n+ * \\brief Re-init a request with ioctl\n+ * \\param[in] requestFd The request file descriptor\n+ *\n+ * This function recycles a request that was allocated and queued before. It\n+ * polls on \\a requestFd to ensure the request is completed, and reinits the\n+ * request.\n+ *\n+ * \\sa allocateRequests(unsigned int count, std::vector<UniqueFD> &requests)\n+ * \\sa queueRequest(int requestFd)\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int MediaDevice::reInitRequest(int requestFd)\n+{\n+\tstruct pollfd pfd;\n+\n+\tpfd.fd = requestFd;\n+\tpfd.events = POLLPRI;\n+\n+\tint ret = TEMP_FAILURE_RETRY(poll(&pfd, 1, 300));\n+\tif (ret < 0)\n+\t\tLOG(MediaDevice, Error) << \"The request \" << requestFd\n+\t\t\t\t\t<< \" polled failed: \" << strerror(-ret);\n+\telse if (ret == 0)\n+\t\tLOG(MediaDevice, Error) << \"The request \" << requestFd\n+\t\t\t\t\t<< \" polled timeout: \" << strerror(-ret);\n+\n+\tret = ::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+\n+\treturn ret;\n+}\n+\n } /* namespace libcamera */\n","prefixes":["1/1"]}