[v2,4/5] libcamera: v4l2_videodevice: Expand d/qbuf logging
diff mbox series

Message ID 20260910160309.940584-4-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • [v2,1/5] libcamera: v4l2_videodevice: V4L2DeviceFormat: Expand formatting
Related show

Commit Message

Barnabás Pőcze Sept. 10, 2026, 4:03 p.m. UTC
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 <barnabas.pocze@ideasonboard.com>
---
 src/libcamera/v4l2_videodevice.cpp | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

Patch
diff mbox series

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);