Show a patch.

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

{
    "id": 25453,
    "url": "https://patchwork.libcamera.org/api/patches/25453/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/25453/",
    "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": "<20251210131302.81887-3-naush@raspberrypi.com>",
    "date": "2025-12-10T13:09:14",
    "name": "[v1,2/2] pipeline: rpi: Rework internal buffer allocations",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "89394f7de3ffb106a328fb121c76a571454eb115",
    "submitter": {
        "id": 34,
        "url": "https://patchwork.libcamera.org/api/people/34/?format=api",
        "name": "Naushir Patuck",
        "email": "naush@raspberrypi.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/25453/mbox/",
    "series": [
        {
            "id": 5647,
            "url": "https://patchwork.libcamera.org/api/series/5647/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5647",
            "date": "2025-12-10T13:09:12",
            "name": "RPi: Internal buffer alloaction rework",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/5647/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/25453/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/25453/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 059BFC326B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 10 Dec 2025 13:13:12 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2785961469;\n\tWed, 10 Dec 2025 14:13:10 +0100 (CET)",
            "from mail-wr1-x430.google.com (mail-wr1-x430.google.com\n\t[IPv6:2a00:1450:4864:20::430])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 70579613F9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Dec 2025 14:13:07 +0100 (CET)",
            "by mail-wr1-x430.google.com with SMTP id\n\tffacd0b85a97d-42b2cff817aso653339f8f.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Dec 2025 05:13:07 -0800 (PST)",
            "from naush-dell.pitowers.org\n\t([2a00:1098:3142:1f:2883:e222:5478:b981])\n\tby smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-42f7cbfee71sm37871852f8f.15.2025.12.10.05.13.06\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 10 Dec 2025 05:13:06 -0800 (PST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"m5hkXQ8Q\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1765372387; x=1765977187;\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=E7Y5d44nPuHEoo5H5eQlzNCzdHZ7U0jIFghRTYAhT9w=;\n\tb=m5hkXQ8Q1sYgZVaSskgyaOhl5fHPf8cvmkpm5YcdNrb2GdODk8CUVVmxAL7u9wwZMn\n\t6IdWjqnnlc8HX3EjevmngzwAr0LPp3SMhW7R2RvIOIWuypXQkE9xJE7fIG3Dd9L6ttmq\n\t2YDljzieuxdLEL7TN637FNG62ngt8Cra2qVP9x4xSGEbhcZg/CSQTVPRyQAwgd9J2rGM\n\tCCQaFDMeDAO2+uLvIDPyl4QmsvJ2ZPpwMmvpLB7vUEqi6TM60CZuid2wg0HmAL1xShrz\n\tYBPmCQMy/HEzX7JiYC5oiuAKd8Huxn0OYUlX7u2HaaMJ1hCYFDyWXI+Lwaw0PjbHLZaw\n\ta+kg==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1765372387; x=1765977187;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n\t:to:cc:subject:date:message-id:reply-to;\n\tbh=E7Y5d44nPuHEoo5H5eQlzNCzdHZ7U0jIFghRTYAhT9w=;\n\tb=ERgRqrH7y02vyBaU7kQnG87AxvewCbajXBQR2VVuMM6DIQ66+KtVLtlUviJBrZO0Ar\n\trZtewzaIR9ys7bxEwKjvszzQYxJDERYWLoz3Aw3Aa3BXShV1adJeLAKyk1qND7NxhFDO\n\tZyqwhQXdiAyLkgvGvu7Y+qt44dq509IbBaOcg3awaDrhCy5I2HzuOWHnGkseI99sM4Lj\n\te9/ppXQlMAIgB8zbr27k0Yz70e2SCTJz/ICKol9k//ER9h9WfEWNGjKFUNH8EZsF6gMI\n\tczClVilxq7g3J3TAAP6Akt55SW/RVSQcB5//WCGosSbxPrjT8pASHFAe34u2VWpk0Vj8\n\ttZ4w==",
        "X-Gm-Message-State": "AOJu0YyWqGKS3XHzMTfIKBDPmzaFw/VRJceybEGnyczPEym/meDglBzC\n\tCMoNajRXg1sYTHbMcs5w7RUALU6UoGw57VPsuzYnFYZvqAC1OzCbO8mbf+FtK4vdPNNlrKJS/bL\n\tJcZM+dQc=",
        "X-Gm-Gg": "AY/fxX40WeCGg8crGmwY56GcHrYTVMX14fRzH8qja+m0R3r4xg86hc0zNbS2CQhjW1+\n\tBJpuQQZKD5r/jFDY9VV8Iz31xdjq6IJltmBGmbxmJahnvIx4hyoebL1HhiXzMNgg4Q2eD4hqEMK\n\tbA9IUeixgmNlhyokwUqzlPbRxPTJ8CnS2Un8HjRr7zFUnaCHil2PkgEEOLxwFH/9eD01kCwBJyG\n\tQg7EeFgKtGzu0AygMiExhLnVgCJ4nBKct1cPLyAYLDussKuPsTx5VebuMdHlU5XEPSZp7j2bIDX\n\tqtszXBNc4SG+iDrMAOqdwn5HDYOotLaqfh6JXNWrM53sKC1jj5nX4+EGzEvouUTOTl+NC6DJTFr\n\tz3yRyATNV9ToxI2XfZdtXxbbRbokzHNjpcFy6CG2We7RJlGg4aPb+HAm+NmF9/zN3D2riM3AN+f\n\tyRWwJ0PQ0wIN7TeoMXJNefSHiclupz9iz9l2yBf4UsBg==",
        "X-Google-Smtp-Source": "AGHT+IGPoHs7nhlJ1MGToD2ByYER9LjyKr0SJzAWKF6fBQjPohF7psOeechCc6vz9QUYwu9Vm1XAow==",
        "X-Received": "by 2002:a05:6000:288a:b0:429:ebf5:ff1d with SMTP id\n\tffacd0b85a97d-42fa399ba80mr1319332f8f.0.1765372386629; \n\tWed, 10 Dec 2025 05:13:06 -0800 (PST)",
        "From": "Naushir Patuck <naush@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Naushir Patuck <naush@raspberrypi.com>",
        "Subject": "[PATCH v1 2/2] pipeline: rpi: Rework internal buffer allocations",
        "Date": "Wed, 10 Dec 2025 13:09:14 +0000",
        "Message-ID": "<20251210131302.81887-3-naush@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.51.0",
        "In-Reply-To": "<20251210131302.81887-1-naush@raspberrypi.com>",
        "References": "<20251210131302.81887-1-naush@raspberrypi.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": "In order to clear the V4L2VideoDevice cache, we must call\nV4L2VideoDevice::releaseBuffers() when stopping the camera. To do this\nwithout releasing the allocated buffers, we have to rework the internal\nbuffer allocation logic.\n\nRemove calls to V4L2VideoDevice::importBuffers() and releaseBuffers()\nfrom within the RPi::Stream class. Instead, move these calls to the\nPipelineHandlerBase class, where we can call releaseBuffers(), i.e. clear\nthe V4L2VideoDevice cache unconditionally on stop without de-allocating\nthe internal buffers.\n\nThe loigc Stream::clearBuffers() can be then moved into releaseBuffers()\nwhich will actually de-allocate the internal buffers when required.\n\nCloses: https://gitlab.freedesktop.org/camera/libcamera/-/issues/265\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\n .../pipeline/rpi/common/pipeline_base.cpp     |  8 ++++++-\n .../pipeline/rpi/common/rpi_stream.cpp        | 23 ++++++-------------\n .../pipeline/rpi/common/rpi_stream.h          |  1 -\n 3 files changed, 14 insertions(+), 18 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\nindex 2b61b5d241c5..aa0af367d301 100644\n--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n@@ -719,8 +719,10 @@ void PipelineHandlerBase::stopDevice(Camera *camera)\n \tdata->state_ = CameraData::State::Stopped;\n \tdata->platformStop();\n \n-\tfor (auto const stream : data->streams_)\n+\tfor (auto const stream : data->streams_) {\n \t\tstream->dev()->streamOff();\n+\t\tstream->dev()->releaseBuffers();\n+\t}\n \n \t/* Disable SOF event generation. */\n \tdata->frontendDevice()->setFrameStartEnabled(false);\n@@ -901,6 +903,10 @@ int PipelineHandlerBase::queueAllBuffers(Camera *camera)\n \tint ret;\n \n \tfor (auto const stream : data->streams_) {\n+\t\tret = stream->dev()->importBuffers(VIDEO_MAX_FRAME);\n+\t\tif (ret < 0)\n+\t\t\treturn ret;\n+\n \t\tif (stream->getFlags() & StreamFlag::External)\n \t\t\tcontinue;\n \ndiff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\nindex e73f4b7d31af..f420400dfe18 100644\n--- a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n+++ b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp\n@@ -12,9 +12,6 @@\n \n #include <libcamera/base/log.h>\n \n-/* Maximum number of buffer slots to allocate in the V4L2 device driver. */\n-static constexpr unsigned int maxV4L2BufferCount = 32;\n-\n namespace libcamera {\n \n LOG_DEFINE_CATEGORY(RPISTREAM)\n@@ -108,7 +105,7 @@ void Stream::setExportedBuffer(FrameBuffer *buffer)\n \n int Stream::allocateBuffers(unsigned int count)\n {\n-\tint ret;\n+\tint ret = 0;\n \n \tif (!(flags_ & StreamFlag::ImportOnly)) {\n \t\t/* Export some frame buffers for internal use. */\n@@ -121,7 +118,7 @@ int Stream::allocateBuffers(unsigned int count)\n \t\tresetBuffers();\n \t}\n \n-\treturn dev_->importBuffers(maxV4L2BufferCount);\n+\treturn ret;\n }\n \n int Stream::queueBuffer(FrameBuffer *buffer)\n@@ -243,8 +240,11 @@ int Stream::queueAllBuffers()\n \n void Stream::releaseBuffers()\n {\n-\tdev_->releaseBuffers();\n-\tclearBuffers();\n+\tavailableBuffers_ = std::queue<FrameBuffer *>{};\n+\trequestBuffers_ = std::queue<FrameBuffer *>{};\n+\tinternalBuffers_.clear();\n+\tbufferMap_.clear();\n+\tid_ = 0;\n }\n \n void Stream::bufferEmplace(unsigned int id, FrameBuffer *buffer)\n@@ -257,15 +257,6 @@ void Stream::bufferEmplace(unsigned int id, FrameBuffer *buffer)\n \t\t\t\t   std::forward_as_tuple(buffer, false));\n }\n \n-void Stream::clearBuffers()\n-{\n-\tavailableBuffers_ = std::queue<FrameBuffer *>{};\n-\trequestBuffers_ = std::queue<FrameBuffer *>{};\n-\tinternalBuffers_.clear();\n-\tbufferMap_.clear();\n-\tid_ = 0;\n-}\n-\n int Stream::queueToDevice(FrameBuffer *buffer)\n {\n \tLOG(RPISTREAM, Debug) << \"Queuing buffer \" << getBufferId(buffer)\ndiff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.h b/src/libcamera/pipeline/rpi/common/rpi_stream.h\nindex c267447e5ab5..300a352a7d39 100644\n--- a/src/libcamera/pipeline/rpi/common/rpi_stream.h\n+++ b/src/libcamera/pipeline/rpi/common/rpi_stream.h\n@@ -140,7 +140,6 @@ public:\n \n private:\n \tvoid bufferEmplace(unsigned int id, FrameBuffer *buffer);\n-\tvoid clearBuffers();\n \tint queueToDevice(FrameBuffer *buffer);\n \n \tStreamFlags flags_;\n",
    "prefixes": [
        "v1",
        "2/2"
    ]
}