diff mbox series

[5/8] v4l2-tracer: get decoded bytesused from DQBUF

Message ID 74dffcc4bac749b406030747bfdf6b78d0a1975c.1699904350.git.deborah.brouwer@collabora.com
State New
Headers show
Series v4l2-tracer: expand to stateful decoding | expand

Commit Message

Deborah Brouwer Nov. 13, 2023, 8:06 p.m. UTC
To write the decoded video data to a file, the tracer gets the bytesused
from userspace arguments when the capture buffers are queued for reuse.
But this only works by accident because the values in the buffers
haven’t been cleared for reuse. Instead get the bytesused from the
driver arguments when the capture buffer is dequeued.

Signed-off-by: Deborah Brouwer <deborah.brouwer@collabora.com>
---
 utils/v4l2-tracer/libv4l2tracer.cpp |  2 ++
 utils/v4l2-tracer/trace-helper.cpp  | 27 +++++++++++++++++++++++----
 utils/v4l2-tracer/trace.h           |  1 +
 3 files changed, 26 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/utils/v4l2-tracer/libv4l2tracer.cpp b/utils/v4l2-tracer/libv4l2tracer.cpp
index c6a74afb..7618f554 100644
--- a/utils/v4l2-tracer/libv4l2tracer.cpp
+++ b/utils/v4l2-tracer/libv4l2tracer.cpp
@@ -309,6 +309,8 @@  int ioctl(int fd, unsigned long cmd, ...)
 		expbuf_setup(static_cast<struct v4l2_exportbuffer*>(arg));
 	if (cmd == VIDIOC_QUERYBUF)
 		querybuf_setup(fd, static_cast<struct v4l2_buffer*>(arg));
+	if (cmd == VIDIOC_DQBUF)
+		dqbuf_setup(static_cast<struct v4l2_buffer*>(arg));
 
 	/* Get info needed for tracing dynamic arrays */
 	if (cmd == VIDIOC_QUERY_EXT_CTRL)
diff --git a/utils/v4l2-tracer/trace-helper.cpp b/utils/v4l2-tracer/trace-helper.cpp
index f58671df..3eee20c2 100644
--- a/utils/v4l2-tracer/trace-helper.cpp
+++ b/utils/v4l2-tracer/trace-helper.cpp
@@ -324,12 +324,13 @@  void qbuf_setup(struct v4l2_buffer *buf)
 	__u32 buf_offset = get_buffer_offset_trace(buf->type, buf->index);
 
 	__u32 bytesused = 0;
-	if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ||
-	    buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
+	if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
 		bytesused = buf->m.planes[0].bytesused;
-	if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT || buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
+	else if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
 		bytesused = buf->bytesused;
-	set_buffer_bytesused_trace(buf_fd, buf_offset, bytesused);
+	if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ||
+	    buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
+		set_buffer_bytesused_trace(buf_fd, buf_offset, bytesused);
 
 	/* The output buffer should have compressed data just before it is queued, so trace it. */
 	if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ||
@@ -356,6 +357,24 @@  void qbuf_setup(struct v4l2_buffer *buf)
 	}
 }
 
+void dqbuf_setup(struct v4l2_buffer *buf)
+{
+	debug_line_info("\n\t%s, index: %d", val2s(buf->type, v4l2_buf_type_val_def).c_str(), buf->index);
+
+	int buf_fd = get_buffer_fd_trace(buf->type, buf->index);
+	__u32 buf_offset = get_buffer_offset_trace(buf->type, buf->index);
+
+	__u32 bytesused = 0;
+	if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
+		bytesused = buf->m.planes[0].bytesused;
+	else if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
+		bytesused = buf->bytesused;
+
+	if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ||
+	    buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
+		set_buffer_bytesused_trace(buf_fd, buf_offset, bytesused);
+}
+
 void streamoff_cleanup(v4l2_buf_type buf_type)
 {
 	debug_line_info();
diff --git a/utils/v4l2-tracer/trace.h b/utils/v4l2-tracer/trace.h
index 272f6c3c..a74a5f3f 100644
--- a/utils/v4l2-tracer/trace.h
+++ b/utils/v4l2-tracer/trace.h
@@ -62,6 +62,7 @@  bool buffer_is_mapped(unsigned long buffer_address);
 unsigned get_expected_length_trace(void);
 void s_ext_ctrls_setup(struct v4l2_ext_controls *ext_controls);
 void qbuf_setup(struct v4l2_buffer *buf);
+void dqbuf_setup(struct v4l2_buffer *buf);
 void streamoff_cleanup(v4l2_buf_type buf_type);
 void g_fmt_setup_trace(struct v4l2_format *format);
 void s_fmt_setup(struct v4l2_format *format);