Skip to content

Commit e5991e1

Browse files
ndufresnemchehab
authored andcommitted
media: h264: Store all fields into the unordered list
When the current picture is a field, store each field into the unordered_list and preserve both top and bottom picture order count. Signed-off-by: Nicolas Dufresne <nicolas.dufresne@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 adc8a8d commit e5991e1

3 files changed

Lines changed: 52 additions & 21 deletions

File tree

drivers/media/platform/nvidia/tegra-vde/h264.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ static int tegra_vde_h264_setup_frames(struct tegra_ctx *ctx,
820820
if (err)
821821
return err;
822822

823-
if (b.refs[dpb_idx].pic_order_count < b.cur_pic_order_count)
823+
if (b.refs[dpb_idx].top_field_order_cnt < b.cur_pic_order_count)
824824
h264->dpb_ref_frames_with_earlier_poc_nb++;
825825
}
826826

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

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b,
4747
}
4848

4949
for (i = 0; i < V4L2_H264_NUM_DPB_ENTRIES; i++) {
50-
u32 pic_order_count;
51-
5250
if (!(dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE))
5351
continue;
5452

@@ -59,8 +57,6 @@ v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b,
5957
/*
6058
* Handle frame_num wraparound as described in section
6159
* '8.2.4.1 Decoding process for picture numbers' of the spec.
62-
* TODO: This logic will have to be adjusted when we start
63-
* supporting interlaced content.
6460
* For long term references, frame_num is set to
6561
* long_term_frame_idx which requires no wrapping.
6662
*/
@@ -70,24 +66,57 @@ v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b,
7066
else
7167
b->refs[i].frame_num = dpb[i].frame_num;
7268

73-
if (dpb[i].fields == V4L2_H264_FRAME_REF)
74-
pic_order_count = min(dpb[i].top_field_order_cnt,
75-
dpb[i].bottom_field_order_cnt);
76-
else if (dpb[i].fields & V4L2_H264_BOTTOM_FIELD_REF)
77-
pic_order_count = dpb[i].bottom_field_order_cnt;
78-
else
79-
pic_order_count = dpb[i].top_field_order_cnt;
69+
b->refs[i].top_field_order_cnt = dpb[i].top_field_order_cnt;
70+
b->refs[i].bottom_field_order_cnt = dpb[i].bottom_field_order_cnt;
71+
72+
if (b->cur_pic_fields == V4L2_H264_FRAME_REF) {
73+
u8 fields = V4L2_H264_FRAME_REF;
74+
75+
b->unordered_reflist[b->num_valid].index = i;
76+
b->unordered_reflist[b->num_valid].fields = fields;
77+
b->num_valid++;
78+
continue;
79+
}
80+
81+
if (dpb[i].fields & V4L2_H264_TOP_FIELD_REF) {
82+
u8 fields = V4L2_H264_TOP_FIELD_REF;
83+
84+
b->unordered_reflist[b->num_valid].index = i;
85+
b->unordered_reflist[b->num_valid].fields = fields;
86+
b->num_valid++;
87+
}
8088

81-
b->refs[i].pic_order_count = pic_order_count;
82-
b->unordered_reflist[b->num_valid].index = i;
83-
b->num_valid++;
89+
if (dpb[i].fields & V4L2_H264_BOTTOM_FIELD_REF) {
90+
u8 fields = V4L2_H264_BOTTOM_FIELD_REF;
91+
92+
b->unordered_reflist[b->num_valid].index = i;
93+
b->unordered_reflist[b->num_valid].fields = fields;
94+
b->num_valid++;
95+
}
8496
}
8597

8698
for (i = b->num_valid; i < ARRAY_SIZE(b->unordered_reflist); i++)
8799
b->unordered_reflist[i].index = i;
88100
}
89101
EXPORT_SYMBOL_GPL(v4l2_h264_init_reflist_builder);
90102

103+
static s32 v4l2_h264_get_poc(const struct v4l2_h264_reflist_builder *b,
104+
const struct v4l2_h264_reference *ref)
105+
{
106+
switch (ref->fields) {
107+
case V4L2_H264_FRAME_REF:
108+
return min(b->refs[ref->index].top_field_order_cnt,
109+
b->refs[ref->index].bottom_field_order_cnt);
110+
case V4L2_H264_TOP_FIELD_REF:
111+
return b->refs[ref->index].top_field_order_cnt;
112+
case V4L2_H264_BOTTOM_FIELD_REF:
113+
return b->refs[ref->index].bottom_field_order_cnt;
114+
}
115+
116+
/* not reached */
117+
return 0;
118+
}
119+
91120
static int v4l2_h264_p_ref_list_cmp(const void *ptra, const void *ptrb,
92121
const void *data)
93122
{
@@ -150,8 +179,8 @@ static int v4l2_h264_b0_ref_list_cmp(const void *ptra, const void *ptrb,
150179
builder->refs[idxb].pic_num ?
151180
-1 : 1;
152181

153-
poca = builder->refs[idxa].pic_order_count;
154-
pocb = builder->refs[idxb].pic_order_count;
182+
poca = v4l2_h264_get_poc(builder, ptra);
183+
pocb = v4l2_h264_get_poc(builder, ptrb);
155184

156185
/*
157186
* Short term pics with POC < cur POC first in POC descending order
@@ -195,8 +224,8 @@ static int v4l2_h264_b1_ref_list_cmp(const void *ptra, const void *ptrb,
195224
builder->refs[idxb].pic_num ?
196225
-1 : 1;
197226

198-
poca = builder->refs[idxa].pic_order_count;
199-
pocb = builder->refs[idxb].pic_order_count;
227+
poca = v4l2_h264_get_poc(builder, ptra);
228+
pocb = v4l2_h264_get_poc(builder, ptrb);
200229

201230
/*
202231
* Short term pics with POC > cur POC first in POC ascending order

include/media/v4l2-h264.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
/**
1616
* struct v4l2_h264_reflist_builder - Reference list builder object
1717
*
18-
* @refs.pic_order_count: reference picture order count
18+
* @refs.top_field_order_cnt: top field order count
19+
* @refs.bottom_field_order_cnt: bottom field order count
1920
* @refs.frame_num: reference frame number
2021
* @refs.pic_num: reference picture number
2122
* @refs.longterm: set to true for a long term reference
@@ -32,7 +33,8 @@
3233
*/
3334
struct v4l2_h264_reflist_builder {
3435
struct {
35-
s32 pic_order_count;
36+
s32 top_field_order_cnt;
37+
s32 bottom_field_order_cnt;
3638
int frame_num;
3739
u32 pic_num;
3840
u16 longterm : 1;

0 commit comments

Comments
 (0)