Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Nicolas Dufresne and committed by
Mauro Carvalho Chehab
6cafdc8c d3f756ad

+13 -12
+13 -10
drivers/media/v4l2-core/v4l2-h264.c
··· 56 56 if (!(dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE)) 57 57 continue; 58 58 59 - b->refs[i].pic_num = dpb[i].pic_num; 60 59 if (dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM) 61 60 b->refs[i].longterm = true; 62 61 ··· 144 145 } 145 146 146 147 /* 147 - * Short term pics in descending pic num order, long term ones in 148 - * ascending order. 148 + * For frames, short term pics are in descending pic num order and long 149 + * term ones in ascending order. For fields, the same direction is used 150 + * but with frame_num (wrapped). For frames, the value of pic_num and 151 + * frame_num are the same (see formula (8-28) and (8-29)). For this 152 + * reason we can use frame_num only and share this function between 153 + * frames and fields reflist. 149 154 */ 150 155 if (!builder->refs[idxa].longterm) 151 156 return builder->refs[idxb].frame_num < 152 157 builder->refs[idxa].frame_num ? 153 158 -1 : 1; 154 159 155 - return builder->refs[idxa].pic_num < builder->refs[idxb].pic_num ? 160 + return builder->refs[idxa].frame_num < builder->refs[idxb].frame_num ? 156 161 -1 : 1; 157 162 } 158 163 ··· 182 179 return 1; 183 180 } 184 181 185 - /* Long term pics in ascending pic num order. */ 182 + /* Long term pics in ascending frame num order. */ 186 183 if (builder->refs[idxa].longterm) 187 - return builder->refs[idxa].pic_num < 188 - builder->refs[idxb].pic_num ? 184 + return builder->refs[idxa].frame_num < 185 + builder->refs[idxb].frame_num ? 189 186 -1 : 1; 190 187 191 188 poca = v4l2_h264_get_poc(builder, ptra); ··· 227 224 return 1; 228 225 } 229 226 230 - /* Long term pics in ascending pic num order. */ 227 + /* Long term pics in ascending frame num order. */ 231 228 if (builder->refs[idxa].longterm) 232 - return builder->refs[idxa].pic_num < 233 - builder->refs[idxb].pic_num ? 229 + return builder->refs[idxa].frame_num < 230 + builder->refs[idxb].frame_num ? 234 231 -1 : 1; 235 232 236 233 poca = v4l2_h264_get_poc(builder, ptra);
-2
include/media/v4l2-h264.h
··· 18 18 * @refs.top_field_order_cnt: top field order count 19 19 * @refs.bottom_field_order_cnt: bottom field order count 20 20 * @refs.frame_num: reference frame number 21 - * @refs.pic_num: reference picture number 22 21 * @refs.longterm: set to true for a long term reference 23 22 * @refs: array of references 24 23 * @cur_pic_order_count: picture order count of the frame being decoded ··· 35 36 s32 top_field_order_cnt; 36 37 s32 bottom_field_order_cnt; 37 38 int frame_num; 38 - u32 pic_num; 39 39 u16 longterm : 1; 40 40 } refs[V4L2_H264_NUM_DPB_ENTRIES]; 41 41