From patchwork Thu Sep 10 16:03:08 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 28223 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id AB63EBDCBE for ; Thu, 10 Sep 2026 16:03:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3E4E16866D; Thu, 10 Sep 2026 18:03:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Xx/xxmzS"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 284CF68655 for ; Thu, 10 Sep 2026 18:03:15 +0200 (CEST) Received: from pb-laptop.local (185.221.140.18.nat.pool.zt.hu [185.221.140.18]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DCD286DF for ; Thu, 10 Sep 2026 18:01:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1789056098; bh=svJ3stCC03m4jFUh61B1M7sRXgTicWRKO+yjeYMDJJU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Xx/xxmzSAIQwXJ73fK6uz2i+6tcE/OaQc4I1GTd6OdZ0a8Ja0E1bk0x9omQy+1Cki YfmYhd0IvAaWlXopDo1coyZVJS5I9I5NNmOW/sdIn7nuU0XF5mJ7lmewe/VY0ysF+9 MuegQmKdL6YFytiIRcOUJwCeKjMuwnUEAlpFh7Ls= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v2 4/5] libcamera: v4l2_videodevice: Expand d/qbuf logging Date: Thu, 10 Sep 2026 18:03:08 +0200 Message-ID: <20260910160309.940584-4-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260910160309.940584-1-barnabas.pocze@ideasonboard.com> References: <20260910160309.940584-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In addition to the index, make sure that the address of the `FrameBuffer` object is present in the log message. This is useful for debugging to be able to correlate requests with specific buffer queue/dequeue operations. Furthermore, also log exactly which buffers are implicitly cancelled when streaming is stopped. Example: DEBUG V4L2 v4l2_videodevice.cpp:1915 /dev/video16[22:cap]: Dequeuing buffer 1 0x50200008b970 DEBUG V4L2 v4l2_videodevice.cpp:1826 /dev/video16[22:cap]: Queueing buffer 1 0x50200008b970 DEBUG V4L2 v4l2_videodevice.cpp:2088 /dev/video16[22:cap]: Cancelling buffer 1 0x50200008b970 Signed-off-by: Barnabás Pőcze --- src/libcamera/v4l2_videodevice.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index ea6270fdf2..19ac758888 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1823,7 +1823,7 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer, const V4L2Request *request buf.timestamp.tv_usec = (metadata.timestamp / 1000) % 1000000; } - LOG(V4L2, Debug) << "Queueing buffer " << buf.index; + LOG(V4L2, Debug) << "Queueing buffer " << buf.index << ' ' << buffer; ret = ioctl(VIDIOC_QBUF, &buf); if (ret < 0) { @@ -1895,8 +1895,6 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() return nullptr; } - LOG(V4L2, Debug) << "Dequeuing buffer " << buf.index; - /* * If the video node fails to stream-on successfully (which can occur * when queuing a buffer), a vb2 kernel bug can lead to the buffer which @@ -1909,8 +1907,14 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() * safely ignore buffers which are unexpected to prevent crashes on * older kernels. */ - auto it = queuedBuffers_.find(buf.index); - if (it == queuedBuffers_.end()) { + + FrameBuffer *buffer = nullptr; + if (auto nh = queuedBuffers_.extract(buf.index)) + buffer = nh.mapped(); + + LOG(V4L2, Debug) << "Dequeuing buffer " << buf.index << ' ' << buffer; + + if (!buffer) { LOG(V4L2, Error) << "Dequeued unexpected buffer index " << buf.index; @@ -1919,9 +1923,6 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() cache_->put(buf.index); - FrameBuffer *buffer = it->second; - queuedBuffers_.erase(it); - if (queuedBuffers_.empty()) { fdBufferNotifier_->setEnabled(false); watchdog_.stop(); @@ -2084,6 +2085,8 @@ int V4L2VideoDevice::streamOff() /* Send back all queued buffers. */ for (const auto &[id, buffer] : queuedBuffers_) { + LOG(V4L2, Debug) << "Cancelling buffer " << id << ' ' << buffer; + cache_->put(id); buffer->_d()->cancel(); bufferReady.emit(buffer);