Patch Detail
Show a patch.
GET /api/1.1/patches/2269/?format=api
{ "id": 2269, "url": "https://patchwork.libcamera.org/api/1.1/patches/2269/?format=api", "web_url": "https://patchwork.libcamera.org/patch/2269/", "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": "<20191028022525.796995-10-niklas.soderlund@ragnatech.se>", "date": "2019-10-28T02:25:22", "name": "[libcamera-devel,RFC,09/12] libcamera: v4l2_videodevice: Add a buffer cache class", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "cca6a6213423da32b78f52b0358a57e4f47233a3", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/2269/mbox/", "series": [ { "id": 561, "url": "https://patchwork.libcamera.org/api/1.1/series/561/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=561", "date": "2019-10-28T02:25:13", "name": "libcamera: Rework buffer API", "version": 1, "mbox": "https://patchwork.libcamera.org/series/561/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/2269/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/2269/checks/", "tags": {}, "headers": { "Return-Path": "<niklas.soderlund@ragnatech.se>", "Received": [ "from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net\n\t[195.74.38.228])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AFACB6017E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 28 Oct 2019 03:25:55 +0100 (CET)", "from localhost.localdomain (unknown [93.2.121.143])\n\tby bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA\n\tid 434a2b97-f92a-11e9-903a-005056917f90;\n\tMon, 28 Oct 2019 03:25:52 +0100 (CET)" ], "X-Halon-ID": "434a2b97-f92a-11e9-903a-005056917f90", "Authorized-sender": "niklas@soderlund.pp.se", "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 28 Oct 2019 03:25:22 +0100", "Message-Id": "<20191028022525.796995-10-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.23.0", "In-Reply-To": "<20191028022525.796995-1-niklas.soderlund@ragnatech.se>", "References": "<20191028022525.796995-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [RFC 09/12] libcamera: v4l2_videodevice: Add a\n\tbuffer cache class", "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>", "X-List-Received-Date": "Mon, 28 Oct 2019 02:25:56 -0000" }, "content": "In preparation for the new buffer handling add a class which will deal\nwith keeping the cache between dmafds and V4L2 video device buffer\nindexes. Previously this responsibility have been split between multiple\nclasses.\n\nThis initial implement ensures that no hot association is lost while its\neviction strategy could be improved in the future.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/include/v4l2_videodevice.h | 19 ++++++++++\n src/libcamera/v4l2_videodevice.cpp | 47 ++++++++++++++++++++++++\n 2 files changed, 66 insertions(+)", "diff": "diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\nindex 4b8cf9394eb9516f..5b178339d0ce7e2c 100644\n--- a/src/libcamera/include/v4l2_videodevice.h\n+++ b/src/libcamera/include/v4l2_videodevice.h\n@@ -104,6 +104,25 @@ struct V4L2Capability final : v4l2_capability {\n \t}\n };\n \n+class V4L2BufferCache\n+{\n+public:\n+\tV4L2BufferCache(unsigned int size);\n+\n+\tvoid populate(unsigned int index, const std::array<int, 3> &fds);\n+\n+\tint pop(const std::array<int, 3> &fds);\n+\tvoid push(unsigned int index);\n+\n+private:\n+\tstruct CacheInfo {\n+\t\tbool free;\n+\t\tstd::array<int, 3> last;\n+\t};\n+\n+\tstd::map<unsigned int, CacheInfo> cache_;\n+};\n+\n class V4L2DeviceFormat\n {\n public:\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex a2a9eab2bcc0d7e8..8bc2e439e4faeb68 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -132,6 +132,53 @@ LOG_DECLARE_CATEGORY(V4L2)\n * \\return True if the video device provides Streaming I/O IOCTLs\n */\n \n+V4L2BufferCache::V4L2BufferCache(unsigned int size)\n+{\n+\tfor (unsigned int i = 0; i < size; i++)\n+\t\tcache_[i] = { .free = true, .last = { -1, -1, -1 } };\n+}\n+\n+void V4L2BufferCache::populate(unsigned int index, const std::array<int, 3> &fds)\n+{\n+\tASSERT(index < cache_.size());\n+\tcache_[index].last = fds;\n+}\n+\n+int V4L2BufferCache::pop(const std::array<int, 3> &fds)\n+{\n+\tint use = -1;\n+\n+\tfor (auto &it : cache_) {\n+\t\tint index = it.first;\n+\t\tCacheInfo &info = it.second;\n+\n+\t\tif (!info.free)\n+\t\t\tcontinue;\n+\n+\t\tif (use < 0)\n+\t\t\tuse = index;\n+\n+\t\tif (info.last == fds) {\n+\t\t\tuse = index;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tif (use < 0)\n+\t\treturn -ENOENT;\n+\n+\tcache_[use].free = false;\n+\tcache_[use].last = fds;\n+\n+\treturn use;\n+}\n+\n+void V4L2BufferCache::push(unsigned int index)\n+{\n+\tASSERT(index < cache_.size());\n+\tcache_[index].free = true;\n+}\n+\n /**\n * \\class V4L2DeviceFormat\n * \\brief The V4L2 video device image format and sizes\n", "prefixes": [ "libcamera-devel", "RFC", "09/12" ] }