public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Sarah Gershuni <sarah556726@gmail.com>
To: linux-media@vger.kernel.org
Cc: Sarah Gershuni <sarah556726@gmail.com>
Subject: [PATCH v4l-utils 2/2] calculate expected length using v4l2-fwht info
Date: Mon, 16 Mar 2026 15:22:23 +0200	[thread overview]
Message-ID: <20260316132223.7337-3-sarah556726@gmail.com> (raw)
In-Reply-To: <20260316132223.7337-1-sarah556726@gmail.com>

Update get_expected_length_trace to calculate the expected buffer length
based on v4l2_fwht_find_pixfmt info.

Signed-off-by: Sarah Gershuni <sarah556726@gmail.com>
---
 utils/v4l2-tracer/trace-helper.cpp | 40 +++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 12 deletions(-)

diff --git a/utils/v4l2-tracer/trace-helper.cpp b/utils/v4l2-tracer/trace-helper.cpp
index 6c296dbf..a59d7761 100644
--- a/utils/v4l2-tracer/trace-helper.cpp
+++ b/utils/v4l2-tracer/trace-helper.cpp
@@ -6,6 +6,11 @@
 #include "trace.h"
 #include <math.h>
 
+extern "C" {
+#include "codec-v4l2-fwht.h"
+}
+
+
 struct trace_context ctx_trace = {};
 
 bool is_video_or_media_device(const char *path)
@@ -233,18 +238,29 @@ void print_buffers_trace(void)
 
 unsigned get_expected_length_trace()
 {
-	/*
-	 * TODO: this assumes that the stride is equal to the real width and that the
-	 * padding follows the end of the chroma plane. It could be improved by
-	 * following the model in v4l2-ctl-streaming.cpp read_write_padded_frame()
-	 */
-	unsigned expected_length = ctx_trace.width * ctx_trace.height;
-	if (ctx_trace.pixelformat == V4L2_PIX_FMT_NV12 || ctx_trace.pixelformat == V4L2_PIX_FMT_YUV420) {
-		expected_length *= 3;
-		expected_length /= 2;
-		expected_length += (expected_length % 2);
-	}
-	return expected_length;
+	const auto *info = v4l2_fwht_find_pixfmt(ctx_trace.pixelformat);
+    if (!info)
+		return 0;
+
+    unsigned coded_height = ctx_trace.height;
+    unsigned expected = 0;
+
+    for (unsigned plane_idx = 0; plane_idx < info->planes_num; ++plane_idx) {
+        unsigned stride = ctx_trace.plane_bytesperline[plane_idx];
+        
+        bool is_chroma = (plane_idx == 1 || plane_idx == 2);
+        unsigned h_div = is_chroma ? info->height_div : 1;
+
+        if (info->planes_num == 3 && plane_idx == 1)
+            stride /= 2;
+
+        if (plane_idx == 1 &&
+            (info->id == V4L2_PIX_FMT_NV24 || info->id == V4L2_PIX_FMT_NV42))
+            stride *= 2;
+
+        expected += stride * (coded_height / h_div);
+    }
+    return expected;
 }
 
 void s_ext_ctrls_setup(struct v4l2_ext_controls *ext_controls)
-- 
2.43.0


  parent reply	other threads:[~2026-03-16 13:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-16 13:22 [PATCH v4l-utils 0/2] v4l2-tracer: fix expected frame length calculation Sarah Gershuni
2026-03-16 13:22 ` [PATCH v4l-utils 1/2] add plane_bytesperline to trace_context Sarah Gershuni
2026-03-16 13:22 ` Sarah Gershuni [this message]
2026-03-17 12:10   ` [PATCH v4l-utils 2/2] calculate expected length using v4l2-fwht info Hans Verkuil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260316132223.7337-3-sarah556726@gmail.com \
    --to=sarah556726@gmail.com \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox