v4l2-tracer: retrace: support all mplane planes
PATCH v2 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.
---
v1 -> v2:
- allocate planes as a single array and populate it directly
- change retrace_v4l2_plane() to fill a provided struct instead of allocating one
- fix indentation to use tabs instead of spaces
- add blank lines between scopes for readability
--- utils/v4l2-tracer/retrace.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
utils/v4l2-tracer/retrace.cpp +15 -8
@@ -199,10 +199,8 @@ void retrace_vidioc_reqbufs(int fd_retrace, json_object *ioctl_args) free(ptr); } -struct v4l2_plane *retrace_v4l2_plane(json_object *plane_obj, __u32 memory) +void retrace_v4l2_plane(json_object *plane_obj, __u32 memory, struct v4l2_plane *ptr) { - struct v4l2_plane *ptr = (struct v4l2_plane *) calloc(1, sizeof(v4l2_plane)); - json_object *bytesused_obj; json_object_object_get_ex(plane_obj, "bytesused", &bytesused_obj); ptr->bytesused = (__u32) json_object_get_int64(bytesused_obj);
@@ -222,8 +220,6 @@ struct v4l2_plane *retrace_v4l2_plane(json_object *plane_obj, __u32 memory) json_object *data_offset_obj; json_object_object_get_ex(plane_obj, "data_offset", &data_offset_obj); ptr->data_offset = (__u32) json_object_get_int64(data_offset_obj); - - return ptr; } struct v4l2_buffer *retrace_v4l2_buffer(json_object *ioctl_args)
@@ -284,9 +280,20 @@ 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; + retrace_v4l2_plane(plane_obj, buf->memory, &buf->m.planes[i]); + } } if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
Signature · 1 line
2.43.0
Quoted 72 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_planeentry, assigning them into a properly allocated array.This ensures consistency with trace output and prevents incorrect buffer reconstruction for multiplanar formats.
Signed-off-by Esther Zilberberg <[email protected]>---
v1 -> v2:
- allocate planes as a single array and populate it directly
- changeretrace_v4l2_plane()to fill a provided struct instead of allocating one
- fix indentation to use tabs instead of spaces
- add blank lines between scopes for readability--- utils/v4l2-tracer/retrace.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)utils/v4l2-tracer/retrace.cpp +15
-9@@ -199,10 +199,8 @@ void retrace_vidioc_reqbufs(int fd_retrace, json_object *ioctl_args) free(ptr); } -struct v4l2_plane *retrace_v4l2_plane(json_object *plane_obj, __u32 memory) +void retrace_v4l2_plane(json_object *plane_obj, __u32 memory, struct v4l2_plane *ptr) { - struct v4l2_plane *ptr = (struct v4l2_plane *) calloc(1, sizeof(v4l2_plane)); - json_object *bytesused_obj; json_object_object_get_ex(plane_obj, "bytesused", &bytesused_obj); ptr->bytesused = (__u32) json_object_get_int64(bytesused_obj);@@ -222,8 +220,6 @@ struct v4l2_plane *retrace_v4l2_plane(json_object *plane_obj, __u32 memory) json_object *data_offset_obj; json_object_object_get_ex(plane_obj, "data_offset", &data_offset_obj); ptr->data_offset = (__u32) json_object_get_int64(data_offset_obj); - - return ptr; } struct v4l2_buffer *retrace_v4l2_buffer(json_object *ioctl_args)@@ -284,9 +280,20 @@ 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; + retrace_v4l2_plane(plane_obj, buf->memory, &buf->m.planes[i]); + } } if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE || --
Quoted 2 lines
2.43.0
Hi,
Gentle reminder to review the patch below.
Thanks,
Esther
Le lundi 13 avril 2026 à 09:46 +0000, Esther Zilberberg a écrit :
Quoted 11 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_planeentry, assigning them into a properly allocated array.This ensures consistency with trace output and prevents incorrect buffer reconstruction for multiplanar formats.
Signed-off-by Esther Zilberberg <[email protected]>
Quoted 59 lines
---
v1 -> v2:
- allocate planes as a single array and populate it directly
- changeretrace_v4l2_plane()to fill a provided struct instead of allocating one
- fix indentation to use tabs instead of spaces
- add blank lines between scopes for readability
---
utils/v4l2-tracer/retrace.cpp | 23 +++++++++++++++--------1 file changed, 15 insertions(+), 8 deletions(-)utils/v4l2-tracer/retrace.cpp +0
-0@@ -199,10 +199,8 @@ void retrace_vidioc_reqbufs(int fd_retrace, json_object *ioctl_args) free(ptr); }utils/v4l2-tracer/retrace.cpp +1
-1-struct v4l2_plane *retrace_v4l2_plane(json_object *plane_obj, __u32 memory) +void retrace_v4l2_plane(json_object *plane_obj, __u32 memory, struct v4l2_plane *ptr){
utils/v4l2-tracer/retrace.cpp +0
-2- struct v4l2_plane *ptr = (struct v4l2_plane *) calloc(1, sizeof(v4l2_plane)); -
json_object*bytesused_obj;json_object_object_get_ex(plane_obj, "bytesused", &bytesused_obj);ptr->bytesused= (__u32)json_object_get_int64(bytesused_obj);utils/v4l2-tracer/retrace.cpp +0
-2@@ -222,8 +220,6 @@ struct v4l2_plane *retrace_v4l2_plane(json_object *plane_obj, __u32 memory) json_object *data_offset_obj; json_object_object_get_ex(plane_obj, "data_offset", &data_offset_obj); ptr->data_offset = (__u32) json_object_get_int64(data_offset_obj); - - return ptr; }
structv4l2_buffer*retrace_v4l2_buffer(json_object*ioctl_args)utils/v4l2-tracer/retrace.cpp +14
-3@@ -284,9 +280,20 @@ 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; + retrace_v4l2_plane(plane_obj, buf->memory, &buf->m.planes[i]); + } }
if (buf->type==V4L2_BUF_TYPE_VIDEO_CAPTURE||