Patch Detail
Show a patch.
GET /api/1.1/patches/27125/?format=api
{ "id": 27125, "url": "https://patchwork.libcamera.org/api/1.1/patches/27125/?format=api", "web_url": "https://patchwork.libcamera.org/patch/27125/", "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": "<20260629163017.863145-48-barnabas.pocze@ideasonboard.com>", "date": "2026-06-29T16:30:10", "name": "[RFC,v1,47/54] gstreamer: Use camera buffer pool", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "ee498fd40841c06ccd1e67dd7f34922f92528481", "submitter": { "id": 216, "url": "https://patchwork.libcamera.org/api/1.1/people/216/?format=api", "name": "Barnabás Pőcze", "email": "barnabas.pocze@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/27125/mbox/", "series": [ { "id": 6025, "url": "https://patchwork.libcamera.org/api/1.1/series/6025/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=6025", "date": "2026-06-29T16:29:23", "name": "libcamera: Split requests and buffers", "version": 1, "mbox": "https://patchwork.libcamera.org/series/6025/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/27125/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/27125/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 912B7C3261\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 29 Jun 2026 16:31:38 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2E1CD65FA7;\n\tMon, 29 Jun 2026 18:31:38 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CD75965F6C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Jun 2026 18:30:31 +0200 (CEST)", "from pb-laptop.local (185.221.140.128.nat.pool.zt.hu\n\t[185.221.140.128])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A2CA1E91\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Jun 2026 18:29:48 +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=\"uBb3rZh0\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1782750588;\n\tbh=A7RzXyNilVle6ZNxDCeLorY7SJjPqpPuLemMS8BMaTg=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=uBb3rZh0Ods9LLp4Cr6rkSpvY8pSJtldH54MDmAnzElP616LK8xGNYgyrBkVTYp3w\n\t2OrloXBMZohQhvByUAuMF03pRXfHT30Shwg+aSquYf6SZflzZzv8gpMTpLIDugPG1j\n\t9rziOI5cJpmOy879lIEklrHuRYr7vRHoIleslvUs=", "From": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Subject": "[RFC PATCH v1 47/54] gstreamer: Use camera buffer pool", "Date": "Mon, 29 Jun 2026 18:30:10 +0200", "Message-ID": "<20260629163017.863145-48-barnabas.pocze@ideasonboard.com>", "X-Mailer": "git-send-email 2.54.0", "In-Reply-To": "<20260629163017.863145-1-barnabas.pocze@ideasonboard.com>", "References": "<20260629163017.863145-1-barnabas.pocze@ideasonboard.com>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "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": "Port to using the camera's buffer pool.\n\nTODO: this is a horrible mess, probably incorrect in many places,\nbut this is the best for now.\n\nSigned-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\n src/gstreamer/gstlibcamerasrc.cpp | 136 ++++++++++++++++++++++--------\n 1 file changed, 102 insertions(+), 34 deletions(-)", "diff": "diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\nindex 9061f9163c..b65422b2a3 100644\n--- a/src/gstreamer/gstlibcamerasrc.cpp\n+++ b/src/gstreamer/gstlibcamerasrc.cpp\n@@ -48,7 +48,6 @@ struct RequestWrap {\n \tRequestWrap(std::unique_ptr<Request> request);\n \t~RequestWrap();\n \n-\tvoid attachBuffer(GstPad *srcpad, GstBuffer *buffer);\n \tGstBuffer *detachBuffer(GstPad *srcpad);\n \n \tstd::unique_ptr<Request> request_;\n@@ -68,6 +67,9 @@ RequestWrap::~RequestWrap()\n \t\treturn;\n \n \tfor (const auto &[stream, fb] : request_->buffers()) {\n+\t\tif (!fb)\n+\t\t\tcontinue;\n+\n \t\tauto *buffer = reinterpret_cast<GstBuffer *>(fb->cookie());\n \t\tif (buffer)\n \t\t\tgst_buffer_unref(buffer);\n@@ -76,15 +78,6 @@ RequestWrap::~RequestWrap()\n \t}\n }\n \n-void RequestWrap::attachBuffer(GstPad *srcpad, GstBuffer *buffer)\n-{\n-\tFrameBuffer *fb = gst_libcamera_buffer_get_frame_buffer(buffer);\n-\tStream *stream = gst_libcamera_pad_get_stream(srcpad);\n-\n-\trequest_->addBuffer(stream, fb);\n-\tfb->setCookie(reinterpret_cast<uint64_t>(buffer));\n-}\n-\n GstBuffer *RequestWrap::detachBuffer(GstPad *srcpad)\n {\n \tconst Stream *stream = gst_libcamera_pad_get_stream(srcpad);\n@@ -128,11 +121,80 @@ struct GstLibcameraSrcState {\n \tControlList initControls_;\n \tguint group_id_;\n \tGstCameraControls controls_;\n+\tsize_t maxRequests_ = 0;\n \n \tint queueRequest();\n \tvoid requestCompleted(Request *request);\n \tint processRequest();\n \tvoid clearRequests();\n+\n+\tvoid addBuffers(GstLibcameraPool *pool)\n+\t{\n+\t\tconst Stream *stream = gst_libcamera_pool_get_stream(pool);\n+\n+\t\tfor (;;) {\n+\t\t\tGstBuffer *buffer = nullptr;\n+\t\t\tGstFlowReturn ret = gst_buffer_pool_acquire_buffer(GST_BUFFER_POOL(pool), &buffer, nullptr);\n+\t\t\tif (ret != GST_FLOW_OK)\n+\t\t\t\tbreak;\n+\n+\t\t\tFrameBuffer *fb = gst_libcamera_buffer_get_frame_buffer(buffer);\n+\t\t\tfb->setCookie(reinterpret_cast<uint64_t>(buffer));\n+\n+\t\t\tGST_TRACE_OBJECT(src_, \"Adding buffer for stream:%p fb:%p buffer:%p\",\n+\t\t\t\t\t stream, fb, buffer);\n+\n+\t\t\tif (cam_->addBuffer(stream, fb)) {\n+\t\t\t\tfb->setCookie(0);\n+\t\t\t\tgst_buffer_pool_release_buffer(GST_BUFFER_POOL(pool), buffer);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\tvoid addAllBuffers()\n+\t{\n+\t\tfor (auto *srcpad : srcpads_)\n+\t\t\taddBuffers(gst_libcamera_pad_get_pool(srcpad));\n+\t}\n+\n+\tint start()\n+\t{\n+\t\tint ret = cam_->start(&initControls_);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\n+\t\taddAllBuffers();\n+\n+\t\treturn 0;\n+\t}\n+\n+\tvoid stop()\n+\t{\n+\t\tcam_->bufferCompleted.connect(this, [&](Request *request, const Stream *stream, FrameBuffer *fb) {\n+\t\t\tif (request)\n+\t\t\t\treturn;\n+\n+\t\t\t// \\todo no... just no...\n+\t\t\tfor (auto *pad : srcpads_) {\n+\t\t\t\tif (gst_libcamera_pad_get_stream(pad) != stream)\n+\t\t\t\t\tcontinue;\n+\n+\t\t\t\tauto *pool = gst_libcamera_pad_get_pool(pad);\n+\t\t\t\tauto *buffer = reinterpret_cast<GstBuffer *>(fb->cookie());\n+\t\t\t\tfb->setCookie(0);\n+\n+\t\t\t\tgst_buffer_pool_release_buffer(GST_BUFFER_POOL(pool), buffer);\n+\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t});\n+\n+\t\tcam_->stop();\n+\n+\t\tcam_->bufferCompleted.disconnect(this);\n+\t\tclearRequests();\n+\t}\n };\n \n struct _GstLibcameraSrc {\n@@ -182,6 +244,13 @@ GstStaticPadTemplate request_src_template = {\n /* Must be called with stream_lock held. */\n int GstLibcameraSrcState::queueRequest()\n {\n+\t{\n+\t\tGLibLocker locker(&lock_);\n+\n+\t\tif (queuedRequests_.size() + completedRequests_.size() >= maxRequests_)\n+\t\t\treturn -EAGAIN;\n+\t}\n+\n \tstd::unique_ptr<Request> request = cam_->createRequest();\n \tif (!request)\n \t\treturn -ENOMEM;\n@@ -189,27 +258,12 @@ int GstLibcameraSrcState::queueRequest()\n \t/* Apply controls */\n \tcontrols_.applyControls(request);\n \n+\tfor (auto *srcpad : srcpads_)\n+\t\trequest->enableStream(gst_libcamera_pad_get_stream(srcpad), true);\n+\n \tstd::unique_ptr<RequestWrap> wrap =\n \t\tstd::make_unique<RequestWrap>(std::move(request));\n \n-\tfor (GstPad *srcpad : srcpads_) {\n-\t\tGstLibcameraPool *pool = gst_libcamera_pad_get_pool(srcpad);\n-\t\tGstBuffer *buffer;\n-\t\tGstFlowReturn ret;\n-\n-\t\tret = gst_buffer_pool_acquire_buffer(GST_BUFFER_POOL(pool),\n-\t\t\t\t\t\t &buffer, nullptr);\n-\t\tif (ret != GST_FLOW_OK) {\n-\t\t\t/*\n-\t\t\t * RequestWrap has ownership of the request, and we\n-\t\t\t * won't be queueing this one due to lack of buffers.\n-\t\t\t */\n-\t\t\treturn -ENOBUFS;\n-\t\t}\n-\n-\t\twrap->attachBuffer(srcpad, buffer);\n-\t}\n-\n \tGST_TRACE_OBJECT(src_, \"Requesting buffers\");\n \n \t{\n@@ -363,6 +417,8 @@ int GstLibcameraSrcState::processRequest()\n \t\tconst StreamConfiguration &stream_cfg = stream->configuration();\n \t\tGstBufferPool *video_pool = gst_libcamera_pad_get_video_pool(srcpad);\n \n+\t\tGST_TRACE_OBJECT(src_, \"Received fb:%p buffer:%p on stream:%p\", fb, buffer, stream);\n+\n \t\tif (video_pool) {\n \t\t\t/* Only set video pool when a copy is needed. */\n \t\t\tGstBuffer *copy = nullptr;\n@@ -702,6 +758,18 @@ gst_libcamera_src_negotiate(GstLibcameraSrc *self)\n \t\tgst_pad_check_reconfigure(srcpad);\n \t}\n \n+\tstate->maxRequests_ = 0;\n+\n+\tfor (auto *srcpad : state->srcpads_) {\n+\t\tStream *stream = gst_libcamera_pad_get_stream(srcpad);\n+\t\tsize_t poolSize = gst_libcamera_allocator_get_pool_size(self->allocator, stream);\n+\n+\t\tstate->maxRequests_ = std::max(state->maxRequests_, poolSize);\n+\t}\n+\n+\tif (state->maxRequests_ <= 0)\n+\t\treturn false;\n+\n \treturn true;\n }\n \n@@ -748,17 +816,18 @@ gst_libcamera_src_task_run(gpointer user_data)\n \t}\n \n \tif (reconfigure) {\n-\t\tstate->cam_->stop();\n-\t\tstate->clearRequests();\n+\t\tstate->stop();\n \n \t\tif (!gst_libcamera_src_negotiate(self)) {\n \t\t\tGST_ELEMENT_FLOW_ERROR(self, GST_FLOW_NOT_NEGOTIATED);\n \t\t\tgst_task_stop(self->task);\n \t\t}\n \n-\t\tstate->cam_->start(&state->initControls_);\n+\t\tstate->start();\n \t}\n \n+\tstate->addAllBuffers();\n+\n \t/*\n \t * Create and queue one request. If no buffers are available the\n \t * function returns -ENOBUFS, which we ignore here as that's not a\n@@ -915,7 +984,7 @@ gst_libcamera_src_task_enter(GstTask *task, [[maybe_unused]] GThread *thread,\n \t\tgst_pad_push_event(srcpad, gst_event_new_segment(&segment));\n \t}\n \n-\tret = state->cam_->start(&state->initControls_);\n+\tret = state->start();\n \tif (ret) {\n \t\tGST_ELEMENT_ERROR(self, RESOURCE, SETTINGS,\n \t\t\t\t (\"Failed to start the camera: %s\", g_strerror(-ret)),\n@@ -935,8 +1004,7 @@ gst_libcamera_src_task_leave([[maybe_unused]] GstTask *task,\n \n \tGST_DEBUG_OBJECT(self, \"Streaming thread is about to stop\");\n \n-\tstate->cam_->stop();\n-\tstate->clearRequests();\n+\tstate->stop();\n \n \t{\n \t\tGLibRecLocker locker(&self->stream_lock);\n", "prefixes": [ "RFC", "v1", "47/54" ] }