Patch Detail
Show a patch.
GET /api/patches/21553/?format=api
{ "id": 21553, "url": "https://patchwork.libcamera.org/api/patches/21553/?format=api", "web_url": "https://patchwork.libcamera.org/patch/21553/", "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": "<20241009074642.2965791-2-chenghaoyang@chromium.org>", "date": "2024-10-09T07:41:19", "name": "[1/5] libcamera: Add mailbox template helper", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "5ffb0c8967af01c3c8bac0bba79e17085a6fd3aa", "submitter": { "id": 117, "url": "https://patchwork.libcamera.org/api/people/117/?format=api", "name": "Cheng-Hao Yang", "email": "chenghaoyang@chromium.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/21553/mbox/", "series": [ { "id": 4670, "url": "https://patchwork.libcamera.org/api/series/4670/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4670", "date": "2024-10-09T07:41:18", "name": "Add InfoFrame", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4670/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/21553/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/21553/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 F09F7C32DE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 9 Oct 2024 07:46:54 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 65DF06536A;\n\tWed, 9 Oct 2024 09:46:52 +0200 (CEST)", "from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com\n\t[IPv6:2607:f8b0:4864:20::1031])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 94C1B6353B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 9 Oct 2024 09:46:50 +0200 (CEST)", "by mail-pj1-x1031.google.com with SMTP id\n\t98e67ed59e1d1-2e09f67bc39so5423308a91.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 09 Oct 2024 00:46:50 -0700 (PDT)", "from chenghaoyang-low.c.googlers.com.com\n\t(199.211.81.34.bc.googleusercontent.com. [34.81.211.199])\n\tby smtp.gmail.com with ESMTPSA id\n\t98e67ed59e1d1-2e2a57077c2sm944414a91.17.2024.10.09.00.46.47\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 09 Oct 2024 00:46:48 -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=\"K3IoTonb\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google; t=1728460009; x=1729064809;\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=tIeh9OOzrh2fB+2XUMZ2I8IIwRldeYy5fiX65sGidRY=;\n\tb=K3IoTonbKXVZVnCTps3bei1Av+yL3ND3XuYBB67RjM7JqcyNCR5AC2NI9+x6VtRFFc\n\tc2qrsUSaHmysUHHEEVCl+6RaJR5DDx+EvW56W9TXODQQJJWP9M2pc4C1W4paSOal+/0g\n\t7lsMC1e59Kh/sd1cK+lBoR+ssCShN8vDRtuO8=", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1728460009; x=1729064809;\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=tIeh9OOzrh2fB+2XUMZ2I8IIwRldeYy5fiX65sGidRY=;\n\tb=xBrBWaXWycfdGUMdfVOxjksOu7mSSP2uUW7533Txm4ztqDgc4tbIAbVkiN53G0RMRO\n\tUXpf9clNrXLmxH0Xdpk2CzndoomiU0IbUUtWnjGYdmz/bXNKTCRYvg9CEQ17zf9c+CO6\n\tDOWCT7QbyylL/nx8nWwwsKrb0M7yhmp6NWBr8fbpNgO1A6L5s4NQ0wYIUZRovvsWuXzr\n\tUvAIfcp+ucJw+s5NBphgzkdX5EFXPN07twVJ2n6t/R8gbGnnk3DsAyUZMYozpyRyJ0Ep\n\tQYZs4FUj0zxEN+qtswzS9mp0ROlQwjrLR7MGdt8u5wk3jWrgBSsWcQ8//yNqZnfGFjdP\n\twVxQ==", "X-Gm-Message-State": "AOJu0YzaV6yqH390UcE71BUyfQ0DXYz8fUSR/T+zMsH1+6TFrif5f9A/\n\t4PhP7YWnD74WlWR4UbqYAbX3jecooJ58W1WPq5z3hNuvxo/bExFxL0Skax3FMZrqGapU/w5XX2o\n\t=", "X-Google-Smtp-Source": "AGHT+IE1MbJ1uLEKY4uI/8OoZeYfydbkVINyPrZ/at025/EE0D2okHXPplA6juoqYHbAhWt5Iw423Q==", "X-Received": "by 2002:a17:90a:46ca:b0:2d3:cd27:c480 with SMTP id\n\t98e67ed59e1d1-2e2a25519aamr2098551a91.33.1728460008755; \n\tWed, 09 Oct 2024 00:46:48 -0700 (PDT)", "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 1/5] libcamera: Add mailbox template helper", "Date": "Wed, 9 Oct 2024 07:41:19 +0000", "Message-ID": "<20241009074642.2965791-2-chenghaoyang@chromium.org>", "X-Mailer": "git-send-email 2.47.0.rc0.187.ge670bccf7e-goog", "In-Reply-To": "<20241009074642.2965791-1-chenghaoyang@chromium.org>", "References": "<20241009074642.2965791-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\nMailBox is designed to be used to shares data, usually a frame buffer, among\ntasks. A Mailbox can store a data which the producer task should set into,\nand multiple consumer tasks could read the data from it. The data could\nbe set only once, i.e., there should be only one producer. All tasks shares\nthe Mailbox with share_ptr and the data it contains should be recycled when\nall tasks are finished.\n\nSigned-off-by: Han-Lin Chen <hanlinchen@chromium.org>\nCo-developed-by: Harvey Yang <chenghaoyang@chromium.org>\nSigned-off-by: Harvey Yang <chenghaoyang@chromium.org>\n---\n include/libcamera/internal/mailbox.h | 75 ++++++++++++++++++++++++++\n include/libcamera/internal/meson.build | 1 +\n src/libcamera/mailbox.cpp | 60 +++++++++++++++++++++\n src/libcamera/meson.build | 1 +\n 4 files changed, 137 insertions(+)\n create mode 100644 include/libcamera/internal/mailbox.h\n create mode 100644 src/libcamera/mailbox.cpp", "diff": "diff --git a/include/libcamera/internal/mailbox.h b/include/libcamera/internal/mailbox.h\nnew file mode 100644\nindex 000000000..4c76eade9\n--- /dev/null\n+++ b/include/libcamera/internal/mailbox.h\n@@ -0,0 +1,75 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Google Inc.\n+ *\n+ * mailbox.h - Template class for generic mailbox\n+ */\n+\n+#pragma once\n+\n+#include <functional>\n+#include <memory>\n+#include <vector>\n+\n+#include <libcamera/base/log.h>\n+\n+namespace libcamera {\n+\n+template<class T>\n+class MailBox\n+{\n+public:\n+\tusing Recycler = std::function<void(T &)>;\n+\n+\tMailBox()\n+\t\t: valid_(false) {}\n+\t~MailBox()\n+\t{\n+\t\tif (valid_ && recycler_)\n+\t\t\trecycler_(item_);\n+\t}\n+\n+\tvoid put(const T &item, Recycler recycler)\n+\t{\n+\t\tASSERT(!valid_);\n+\n+\t\tvalid_ = true;\n+\t\trecycler_ = recycler;\n+\t\titem_ = item;\n+\t}\n+\n+\tconst T &get()\n+\t{\n+\t\tASSERT(valid_);\n+\t\treturn item_;\n+\t}\n+\n+\tbool valid() { return valid_; }\n+\n+private:\n+\tT item_;\n+\tbool valid_;\n+\tstd::function<void(T &)> recycler_;\n+};\n+\n+template<class T>\n+using SharedMailBox = std::shared_ptr<MailBox<T>>;\n+\n+template<class T>\n+SharedMailBox<T> makeMailBox()\n+{\n+\treturn std::make_shared<MailBox<T>>();\n+}\n+\n+template<class T>\n+std::vector<SharedMailBox<T>> makeMailBoxVector(const unsigned int count)\n+{\n+\tstd::vector<SharedMailBox<T>> mailBoxes;\n+\tmailBoxes.resize(count);\n+\tfor (unsigned int i = 0; i < count; i++)\n+\t\tmailBoxes[i] = makeMailBox<T>();\n+\n+\treturn mailBoxes;\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build\nindex 1c5eef9ca..4c1228b95 100644\n--- a/include/libcamera/internal/meson.build\n+++ b/include/libcamera/internal/meson.build\n@@ -27,6 +27,7 @@ libcamera_internal_headers = files([\n 'ipa_proxy.h',\n 'ipc_pipe.h',\n 'ipc_unixsocket.h',\n+ 'mailbox.h',\n 'mapped_framebuffer.h',\n 'media_device.h',\n 'media_object.h',\ndiff --git a/src/libcamera/mailbox.cpp b/src/libcamera/mailbox.cpp\nnew file mode 100644\nindex 000000000..7335122e3\n--- /dev/null\n+++ b/src/libcamera/mailbox.cpp\n@@ -0,0 +1,60 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Google Inc.\n+ *\n+ * mailbox.cpp - Template class for generic mailbox\n+ */\n+\n+/**\n+ * \\class libcamera::MailBox\n+ * \\brief MailBox of data\n+ *\n+ * A MailBox contains a block of data that has a single producer, and one or\n+ * multiple consumers. It's often used as a shared_ptr (SharedMailBox) and\n+ * being held by different tasks in pipelines.\n+ */\n+\n+/**\n+ * \\typedef MailBox::Recycler\n+ * \\brief A function that recycles the data when the mailbox is destructed\n+ */\n+\n+/**\n+ * \\fn MailBox::put(const T &item, MailBox<T>::Recycler recycler)\n+ * \\brief Set the data as the producer. Should be called only once\n+ * \\param[in] item The data to be stored\n+ * \\param[in] recycler The function that recycles \\a data when destructing the\n+ * mailbox. Mostly used for recycling buffers.\n+ */\n+\n+/**\n+ * \\fn MailBox::get()\n+ * \\brief Get the data as a consumer. put() function should be called ahead\n+ *\n+ * \\return The stored data\n+ */\n+\n+/**\n+ * \\fn MailBox::valid()\n+ * \\return True if put() function has been called\n+ */\n+\n+/**\n+ * \\typedef libcamera::SharedMailBox\n+ * \\brief A mailbox as a shared_ptr\n+ */\n+\n+/**\n+ * \\fn libcamera::makeMailBox()\n+ * \\brief A helper function to create a SharedMailBox\n+ *\n+ * \\return A mailbox as a SharedMailBox\n+ */\n+\n+/**\n+ * \\fn libcamera::makeMailBoxVector(const unsigned int count)\n+ * \\brief A helper function to create a list of mailboxes\n+ * \\param[in] count The number of mailboxes requested\n+ *\n+ * \\return Mailboxes as a vector\n+ */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex aa9ab0291..6c3ef5377 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -38,6 +38,7 @@ libcamera_internal_sources = files([\n 'ipc_pipe.cpp',\n 'ipc_pipe_unixsocket.cpp',\n 'ipc_unixsocket.cpp',\n+ 'mailbox.cpp',\n 'mapped_framebuffer.cpp',\n 'media_device.cpp',\n 'media_object.cpp',\n", "prefixes": [ "1/5" ] }