Skip to content

Commit 6cafdc8

Browse files
ndufresnemchehab
authored andcommitted
media: h264: Sort p/b reflist using frame_num
In the reference list builder, frame_num refers to FrameNumWrap in the spec, which is the same as the pic_num for frame decoding. The same applies for long_term_pic_num and long_term_frame_idx. Sort all type of references by frame_num so the sort can be reused for fields reflist were the sorting is done using frame_num instead. In short, pic_num is never actually used for building reference lists. 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 d3f756a commit 6cafdc8

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b,
5656
if (!(dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE))
5757
continue;
5858

59-
b->refs[i].pic_num = dpb[i].pic_num;
6059
if (dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM)
6160
b->refs[i].longterm = true;
6261

@@ -145,15 +144,19 @@ static int v4l2_h264_p_ref_list_cmp(const void *ptra, const void *ptrb,
145144
}
146145

147146
/*
148-
* Short term pics in descending pic num order, long term ones in
149-
* ascending order.
147+
* For frames, short term pics are in descending pic num order and long
148+
* term ones in ascending order. For fields, the same direction is used
149+
* but with frame_num (wrapped). For frames, the value of pic_num and
150+
* frame_num are the same (see formula (8-28) and (8-29)). For this
151+
* reason we can use frame_num only and share this function between
152+
* frames and fields reflist.
150153
*/
151154
if (!builder->refs[idxa].longterm)
152155
return builder->refs[idxb].frame_num <
153156
builder->refs[idxa].frame_num ?
154157
-1 : 1;
155158

156-
return builder->refs[idxa].pic_num < builder->refs[idxb].pic_num ?
159+
return builder->refs[idxa].frame_num < builder->refs[idxb].frame_num ?
157160
-1 : 1;
158161
}
159162

@@ -179,10 +182,10 @@ static int v4l2_h264_b0_ref_list_cmp(const void *ptra, const void *ptrb,
179182
return 1;
180183
}
181184

182-
/* Long term pics in ascending pic num order. */
185+
/* Long term pics in ascending frame num order. */
183186
if (builder->refs[idxa].longterm)
184-
return builder->refs[idxa].pic_num <
185-
builder->refs[idxb].pic_num ?
187+
return builder->refs[idxa].frame_num <
188+
builder->refs[idxb].frame_num ?
186189
-1 : 1;
187190

188191
poca = v4l2_h264_get_poc(builder, ptra);
@@ -224,10 +227,10 @@ static int v4l2_h264_b1_ref_list_cmp(const void *ptra, const void *ptrb,
224227
return 1;
225228
}
226229

227-
/* Long term pics in ascending pic num order. */
230+
/* Long term pics in ascending frame num order. */
228231
if (builder->refs[idxa].longterm)
229-
return builder->refs[idxa].pic_num <
230-
builder->refs[idxb].pic_num ?
232+
return builder->refs[idxa].frame_num <
233+
builder->refs[idxb].frame_num ?
231234
-1 : 1;
232235

233236
poca = v4l2_h264_get_poc(builder, ptra);

include/media/v4l2-h264.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* @refs.top_field_order_cnt: top field order count
1919
* @refs.bottom_field_order_cnt: bottom field order count
2020
* @refs.frame_num: reference frame number
21-
* @refs.pic_num: reference picture number
2221
* @refs.longterm: set to true for a long term reference
2322
* @refs: array of references
2423
* @cur_pic_order_count: picture order count of the frame being decoded
@@ -36,7 +35,6 @@ struct v4l2_h264_reflist_builder {
3635
s32 top_field_order_cnt;
3736
s32 bottom_field_order_cnt;
3837
int frame_num;
39-
u32 pic_num;
4038
u16 longterm : 1;
4139
} refs[V4L2_H264_NUM_DPB_ENTRIES];
4240

0 commit comments

Comments
 (0)