Skip to contentSkip to conversation

v4l2-tracer: retrace: support all mplane planes

PATCH Superseded Esther Zilberberg 2 participants 4 messages Mar 18 – Mar 30 Media (V4L/DVB)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 v4l2-tracer: retrace: support all mplane planes

For V4L2_BUF_TYPE_*_MPLANE buffers, retrace_v4l2_buffer() only restored the first plane from the JSON trace.

Restore all planes by iterating over the "planes" array and reconstructing each struct v4l2_plane entry, assigning them into a properly allocated array.

This ensures consistency with trace output and prevents incorrect buffer reconstruction for multiplanar formats.

---
 utils/v4l2-tracer/retrace.cpp | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
utils/v4l2-tracer/retrace.cpp +16 -3
index 010936c0..844c25c7 100644
@@ -284,9 +284,22 @@ struct v4l2_buffer *retrace_v4l2_buffer(json_object *ioctl_args)
 	    buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
 		json_object *planes_obj;
 		json_object_object_get_ex(m_obj, "planes", &planes_obj);
-		 /* TODO add planes > 0 */
-		json_object *plane_obj = json_object_array_get_idx(planes_obj, 0);
-		buf->m.planes = retrace_v4l2_plane(plane_obj, buf->memory);
+		buf->m.planes = (struct v4l2_plane *) calloc(buf->length, sizeof(struct v4l2_plane));
+        if (buf->m.planes == nullptr) {
+            line_info("\n\tMemory allocation failed.");
+            free(buf);
+            return nullptr;
+        }
+        for (__u32 i = 0; i < buf->length; i++) {
+            json_object *plane_obj = json_object_array_get_idx(planes_obj, i);
+            if (plane_obj == nullptr)
+                break;
+            struct v4l2_plane *plane_ptr = retrace_v4l2_plane(plane_obj, buf->memory);
+            if (plane_ptr != nullptr) {
+                buf->m.planes[i] = *plane_ptr;
+                free(plane_ptr);
+            }
+        }
 	}
 
 	if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
Signature · 1 line
2.43.0
#1 lore raw
Quoted 47 lines · Esther Zilberberg

For V4L2_BUF_TYPE_*_MPLANE buffers, retrace_v4l2_buffer() only restored the first plane from the JSON trace.

Restore all planes by iterating over the "planes" array and reconstructing each struct v4l2_plane entry, assigning them into a properly allocated array.

This ensures consistency with trace output and prevents incorrect buffer reconstruction for multiplanar formats.

---
 utils/v4l2-tracer/retrace.cpp | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
utils/v4l2-tracer/retrace.cpp +16 -4
index 010936c0..844c25c7 100644
@@ -284,9 +284,22 @@ struct v4l2_buffer *retrace_v4l2_buffer(json_object *ioctl_args)
            buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
                json_object *planes_obj;
                json_object_object_get_ex(m_obj, "planes", &planes_obj);
-                /* TODO add planes > 0 */
-               json_object *plane_obj = json_object_array_get_idx(planes_obj, 0);
-               buf->m.planes = retrace_v4l2_plane(plane_obj, buf->memory);
+               buf->m.planes = (struct v4l2_plane *) calloc(buf->length, sizeof(struct v4l2_plane));
+        if (buf->m.planes == nullptr) {
+            line_info("\n\tMemory allocation failed.");
+            free(buf);
+            return nullptr;
+        }
+        for (__u32 i = 0; i < buf->length; i++) {
+            json_object *plane_obj = json_object_array_get_idx(planes_obj, i);
+            if (plane_obj == nullptr)
+                break;
+            struct v4l2_plane *plane_ptr = retrace_v4l2_plane(plane_obj, buf->memory);
+            if (plane_ptr != nullptr) {
+                buf->m.planes[i] = *plane_ptr;
+                free(plane_ptr);
+            }
+        }
        }
 
        if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
--
Quoted 2 lines

2.43.0

Hi,

Gentle reminder to review the patch below.

Thanks,
Esther

#2 lore raw

Hi,

Le lundi 30 mars 2026 à 04:50 +0300, Esther Zilberberg a écrit :

Quoted 1 line

Gentle reminder to review the patch below.

Since its a continuation of a previous patch you sent, try and CC your previous reviewers.

Nicolas

#3 lore raw
In reply to Esther Zilberberg

Le mercredi 18 mars 2026 à 08:49 +0000, Esther Zilberberg a écrit :

Quoted 20 lines

For V4L2_BUF_TYPE_*_MPLANE buffers, retrace_v4l2_buffer() only restored the first plane from the JSON trace.

Restore all planes by iterating over the "planes" array and reconstructing each struct v4l2_plane entry, assigning them into a properly allocated array.

This ensures consistency with trace output and prevents incorrect buffer reconstruction for multiplanar formats.

---
 utils/v4l2-tracer/retrace.cpp | 19 ++++++++++++++++---

 1 file changed, 16 insertions(+), 3 deletions(-)
utils/v4l2-tracer/retrace.cpp +0 -0
index 010936c0..844c25c7 100644

utils/v4l2-tracer/retrace.cpp struct v4l2_buffer *retrace_v4l2_buffer(json_object *ioctl_args) · line 288

Quoted 8 lines
utils/v4l2-tracer/retrace.cpp +2 -3
@@ -284,9 +284,22 @@ struct v4l2_buffer *retrace_v4l2_buffer(json_object *ioctl_args)
  	    buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
  		json_object *planes_obj;
  		json_object_object_get_ex(m_obj, "planes", &planes_obj);
-		 /* TODO add planes > 0 */
-		json_object *plane_obj = json_object_array_get_idx(planes_obj, 0);
-		buf->m.planes = retrace_v4l2_plane(plane_obj, buf->memory);
+		buf->m.planes = (struct v4l2_plane *) calloc(buf->length, sizeof(struct v4l2_plane));
+        if (buf->m.planes == nullptr) {

I see that you use spaces instead of tabs. Can you fix it to follow appropriate style. The two lines above are suppose to line-up.

utils/v4l2-tracer/retrace.cpp struct v4l2_buffer *retrace_v4l2_buffer(json_object *ioctl_args) · line 290

Quoted 2 lines
utils/v4l2-tracer/retrace.cpp +2 -0
+            line_info("\n\tMemory allocation failed.");
+            free(buf);

If you are on plane 1 or 2, the previous planes are going to be leaked. One simplification you could make, is to allocate the planes as an array and set pointers into that array. Then you just have to free the very first one, regardless how many planes.

utils/v4l2-tracer/retrace.cpp struct v4l2_buffer *retrace_v4l2_buffer(json_object *ioctl_args) · line 293

Quoted 3 lines
utils/v4l2-tracer/retrace.cpp +3 -0
+            return nullptr;
+        }
+        for (__u32 i = 0; i < buf->length; i++) {

I find it easier to read with blank liens between scopes, if you don't mind adding it.

Quoted 12 lines
utils/v4l2-tracer/retrace.cpp +9 -0
+            json_object *plane_obj = json_object_array_get_idx(planes_obj, i);
+            if (plane_obj == nullptr)
+                break;
+            struct v4l2_plane *plane_ptr = retrace_v4l2_plane(plane_obj, buf->memory);
+            if (plane_ptr != nullptr) {
+                buf->m.planes[i] = *plane_ptr;
+                free(plane_ptr);
+            }
+        }
  	}


  if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||