Skip to content

Commit d3f756a

Browse files
ndufresnemchehab
authored andcommitted
media: v4l2: Trace calculated p/b0/b1 initial reflist
Add debug print statements to print the content of P & B reference lists, to verify that the ordering of the generated reference lists is correct. This is especially important for the field decoding mode, where sorting is more complex. Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Tested-by: Sebastian Fricke <sebastian.fricke@collabora.com> Reviewed-by: Sebastian Fricke <sebastian.fricke@collabora.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
1 parent e5991e1 commit d3f756a

1 file changed

Lines changed: 100 additions & 0 deletions

File tree

drivers/media/v4l2-core/v4l2-h264.c

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212

1313
#include <media/v4l2-h264.h>
1414

15+
/*
16+
* Size of the tempory buffer allocated when printing reference lists. The
17+
* output will be truncated if the size is too small.
18+
*/
19+
static const int tmp_str_size = 1024;
20+
1521
/**
1622
* v4l2_h264_init_reflist_builder() - Initialize a P/B0/B1 reference list
1723
* builder
@@ -241,6 +247,95 @@ static int v4l2_h264_b1_ref_list_cmp(const void *ptra, const void *ptrb,
241247
return poca < pocb ? -1 : 1;
242248
}
243249

250+
static char ref_type_to_char(u8 ref_type)
251+
{
252+
switch (ref_type) {
253+
case V4L2_H264_FRAME_REF:
254+
return 'f';
255+
case V4L2_H264_TOP_FIELD_REF:
256+
return 't';
257+
case V4L2_H264_BOTTOM_FIELD_REF:
258+
return 'b';
259+
}
260+
261+
return '?';
262+
}
263+
264+
static const char *format_ref_list_p(const struct v4l2_h264_reflist_builder *builder,
265+
struct v4l2_h264_reference *reflist,
266+
char **out_str)
267+
{
268+
int n = 0, i;
269+
270+
*out_str = kmalloc(tmp_str_size, GFP_KERNEL);
271+
272+
n += snprintf(*out_str + n, tmp_str_size - n, "|");
273+
274+
for (i = 0; i < builder->num_valid; i++) {
275+
/* this is pic_num for frame and frame_num (wrapped) for field,
276+
* but for frame pic_num is equal to frame_num (wrapped).
277+
*/
278+
int frame_num = builder->refs[reflist[i].index].frame_num;
279+
bool longterm = builder->refs[reflist[i].index].longterm;
280+
281+
n += scnprintf(*out_str + n, tmp_str_size - n, "%i%c%c|",
282+
frame_num, longterm ? 'l' : 's',
283+
ref_type_to_char(reflist[i].fields));
284+
}
285+
286+
return *out_str;
287+
}
288+
289+
static void print_ref_list_p(const struct v4l2_h264_reflist_builder *builder,
290+
struct v4l2_h264_reference *reflist)
291+
{
292+
char *buf = NULL;
293+
294+
pr_debug("ref_pic_list_p (cur_poc %u%c) %s\n",
295+
builder->cur_pic_order_count,
296+
ref_type_to_char(builder->cur_pic_fields),
297+
format_ref_list_p(builder, reflist, &buf));
298+
299+
kfree(buf);
300+
}
301+
302+
static const char *format_ref_list_b(const struct v4l2_h264_reflist_builder *builder,
303+
struct v4l2_h264_reference *reflist,
304+
char **out_str)
305+
{
306+
int n = 0, i;
307+
308+
*out_str = kmalloc(tmp_str_size, GFP_KERNEL);
309+
310+
n += snprintf(*out_str + n, tmp_str_size - n, "|");
311+
312+
for (i = 0; i < builder->num_valid; i++) {
313+
int frame_num = builder->refs[reflist[i].index].frame_num;
314+
u32 poc = v4l2_h264_get_poc(builder, reflist + i);
315+
bool longterm = builder->refs[reflist[i].index].longterm;
316+
317+
n += scnprintf(*out_str + n, tmp_str_size - n, "%i%c%c|",
318+
longterm ? frame_num : poc,
319+
longterm ? 'l' : 's',
320+
ref_type_to_char(reflist[i].fields));
321+
}
322+
323+
return *out_str;
324+
}
325+
326+
static void print_ref_list_b(const struct v4l2_h264_reflist_builder *builder,
327+
struct v4l2_h264_reference *reflist, u8 list_num)
328+
{
329+
char *buf = NULL;
330+
331+
pr_debug("ref_pic_list_b%u (cur_poc %u%c) %s",
332+
list_num, builder->cur_pic_order_count,
333+
ref_type_to_char(builder->cur_pic_fields),
334+
format_ref_list_b(builder, reflist, &buf));
335+
336+
kfree(buf);
337+
}
338+
244339
/**
245340
* v4l2_h264_build_p_ref_list() - Build the P reference list
246341
*
@@ -261,6 +356,8 @@ v4l2_h264_build_p_ref_list(const struct v4l2_h264_reflist_builder *builder,
261356
sizeof(builder->unordered_reflist[0]) * builder->num_valid);
262357
sort_r(reflist, builder->num_valid, sizeof(*reflist),
263358
v4l2_h264_p_ref_list_cmp, NULL, builder);
359+
360+
print_ref_list_p(builder, reflist);
264361
}
265362
EXPORT_SYMBOL_GPL(v4l2_h264_build_p_ref_list);
266363

@@ -296,6 +393,9 @@ v4l2_h264_build_b_ref_lists(const struct v4l2_h264_reflist_builder *builder,
296393
if (builder->num_valid > 1 &&
297394
!memcmp(b1_reflist, b0_reflist, builder->num_valid))
298395
swap(b1_reflist[0], b1_reflist[1]);
396+
397+
print_ref_list_b(builder, b0_reflist, 0);
398+
print_ref_list_b(builder, b1_reflist, 1);
299399
}
300400
EXPORT_SYMBOL_GPL(v4l2_h264_build_b_ref_lists);
301401

0 commit comments

Comments
 (0)