Patch Detail
Show a patch.
GET /api/patches/24791/?format=api
{ "id": 24791, "url": "https://patchwork.libcamera.org/api/patches/24791/?format=api", "web_url": "https://patchwork.libcamera.org/patch/24791/", "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": "<20251024085130.995967-26-stefan.klug@ideasonboard.com>", "date": "2025-10-24T08:50:49", "name": "[v1,25/35] pipeline: rkisp1: Add SequenceSyncHelper class", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "b46e326658bc5da10ee583c1402066bd41a8df44", "submitter": { "id": 184, "url": "https://patchwork.libcamera.org/api/people/184/?format=api", "name": "Stefan Klug", "email": "stefan.klug@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/24791/mbox/", "series": [ { "id": 5524, "url": "https://patchwork.libcamera.org/api/series/5524/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5524", "date": "2025-10-24T08:50:24", "name": "rkisp1: pipeline rework for PFC", "version": 1, "mbox": "https://patchwork.libcamera.org/series/5524/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/24791/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/24791/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 6AA02BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 24 Oct 2025 08:52:55 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 23A3F60931;\n\tFri, 24 Oct 2025 10:52:55 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 54CFE608F7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Oct 2025 10:52:53 +0200 (CEST)", "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:7edc:62f4:c118:1549])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id C4EA64AEB; \n\tFri, 24 Oct 2025 10:51:07 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"f7j2R2YW\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1761295867;\n\tbh=w0Hxg2XU1TUu/+ZvDaC8neBCy+QwzFpeQN0WFkwbwlQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=f7j2R2YW+AEoOtwfTf54jZaT9Zz4bVm3puzXCDftzEorZ/5GJtgSUN30ZYIHhq3d5\n\tOyScJA9cdXJfsJ9mO/KJdo1jsNVOOjQcZZwspmClwyFet9Cd46fEI/U2jVBO01OOA6\n\tOtdJFEXCsIPQNp0oA7Uk5zWoV2I6MeKGY/rt3Cxc=", "From": "Stefan Klug <stefan.klug@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>", "Subject": "[PATCH v1 25/35] pipeline: rkisp1: Add SequenceSyncHelper class", "Date": "Fri, 24 Oct 2025 10:50:49 +0200", "Message-ID": "<20251024085130.995967-26-stefan.klug@ideasonboard.com>", "X-Mailer": "git-send-email 2.48.1", "In-Reply-To": "<20251024085130.995967-1-stefan.klug@ideasonboard.com>", "References": "<20251024085130.995967-1-stefan.klug@ideasonboard.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": "On a V4L2 buffer the assigned sequence is not known until the buffer is\ndequeued. But for per frame controls we have to prepare other data like\nsensor controls and ISP params in advance. So we try to anticipate the\nsequence number a given buffer will be. In a perfect world this works\nwell as long as the initial sequence is assigned correctly. But it\nbreaks as soon as things like running out of buffers or incomplete\nimages happen. To make things even more complicated, in most cases\nmore than one buffer is queued to the kernel at a time.\n\nSo as soon as a sequence number doesn't match the expected one after\ndequeuing, most likely all the already queued buffers will be dequeued\nwith the same error. It is not sufficient to simply add the correction\nafter dequeuing because the error on all queued frames would accumulate\nand the whole system starts to oscillate. To work around that add a\nSequenceSyncHelper class that tracks the expected error and allows to\neasily query the necessary correction when queuing new buffers.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n---\n src/libcamera/pipeline/rkisp1/rkisp1.cpp | 2 +\n .../pipeline/rkisp1/sequence_sync_helper.h | 69 +++++++++++++++++++\n 2 files changed, 71 insertions(+)\n create mode 100644 src/libcamera/pipeline/rkisp1/sequence_sync_helper.h", "diff": "diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 7a4957d7e535..d83f7d787892 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -51,10 +51,12 @@\n #include \"libcamera/internal/yaml_parser.h\"\n \n #include \"rkisp1_path.h\"\n+#include \"sequence_sync_helper.h\"\n \n namespace libcamera {\n \n LOG_DEFINE_CATEGORY(RkISP1)\n+LOG_DEFINE_CATEGORY(RkISP1Schedule)\n \n class PipelineHandlerRkISP1;\n class RkISP1CameraData;\ndiff --git a/src/libcamera/pipeline/rkisp1/sequence_sync_helper.h b/src/libcamera/pipeline/rkisp1/sequence_sync_helper.h\nnew file mode 100644\nindex 000000000000..c3f91dbed45f\n--- /dev/null\n+++ b/src/libcamera/pipeline/rkisp1/sequence_sync_helper.h\n@@ -0,0 +1,69 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2025, Ideas on Board\n+ *\n+ * Sequence sync helper\n+ */\n+\n+#pragma once\n+\n+#include <queue>\n+\n+#include <libcamera/base/log.h>\n+\n+namespace libcamera {\n+\n+LOG_DECLARE_CATEGORY(RkISP1Schedule)\n+\n+class SequenceSyncHelper\n+{\n+public:\n+\tint gotFrame(size_t expectedSequence, size_t actualSequence)\n+\t{\n+\t\tASSERT(!corrections_.empty());\n+\t\tint diff = actualSequence - expectedSequence;\n+\t\tint corr = corrections_.front();\n+\t\tcorrections_.pop();\n+\t\texpectedOffset_ -= corr;\n+\t\tint necessaryCorrection = diff - expectedOffset_;\n+\t\tcorrectionToApply_ += necessaryCorrection;\n+\n+\t\tLOG(RkISP1Schedule, Debug) << \"Sync frame \"\n+\t\t\t\t\t << \"expected: \" << expectedSequence\n+\t\t\t\t\t << \" actual: \" << actualSequence\n+\t\t\t\t\t << \" correction: \" << corr\n+\t\t\t\t\t << \" expectedOffset: \" << expectedOffset_\n+\t\t\t\t\t << \" correctionToApply \" << correctionToApply_;\n+\n+\t\texpectedOffset_ += necessaryCorrection;\n+\t\treturn necessaryCorrection;\n+\t}\n+\n+\t/* Value to be added to the source sequence */\n+\tint correction()\n+\t{\n+\t\treturn correctionToApply_;\n+\t}\n+\n+\tvoid pushCorrection(int correction)\n+\t{\n+\t\tcorrections_.push(correction);\n+\t\tcorrectionToApply_ -= correction;\n+\t\tLOG(RkISP1Schedule, Debug)\n+\t\t\t<< \"Push correction \" << correction\n+\t\t\t<< \" correctionToApply \" << correctionToApply_;\n+\t}\n+\n+\tvoid reset()\n+\t{\n+\t\tcorrections_ = {};\n+\t\tcorrectionToApply_ = 0;\n+\t\texpectedOffset_ = 0;\n+\t}\n+\n+\tstd::queue<int> corrections_;\n+\tint correctionToApply_ = 0;\n+\tint expectedOffset_ = 0;\n+};\n+\n+} /* namespace libcamera */\n", "prefixes": [ "v1", "25/35" ] }