Lines Matching +full:long +full:- +full:term
1 // SPDX-License-Identifier: GPL-2.0
13 #include <media/v4l2-h264.h>
22 * v4l2_h264_init_reflist_builder() - Initialize a P/B0/B1 reference list
39 max_frame_num = 1 << (sps->log2_max_frame_num_minus4 + 4); in v4l2_h264_init_reflist_builder()
40 cur_frame_num = dec_params->frame_num; in v4l2_h264_init_reflist_builder()
43 if (!(dec_params->flags & V4L2_H264_DECODE_PARAM_FLAG_FIELD_PIC)) { in v4l2_h264_init_reflist_builder()
44 b->cur_pic_order_count = min(dec_params->bottom_field_order_cnt, in v4l2_h264_init_reflist_builder()
45 dec_params->top_field_order_cnt); in v4l2_h264_init_reflist_builder()
46 b->cur_pic_fields = V4L2_H264_FRAME_REF; in v4l2_h264_init_reflist_builder()
47 } else if (dec_params->flags & V4L2_H264_DECODE_PARAM_FLAG_BOTTOM_FIELD) { in v4l2_h264_init_reflist_builder()
48 b->cur_pic_order_count = dec_params->bottom_field_order_cnt; in v4l2_h264_init_reflist_builder()
49 b->cur_pic_fields = V4L2_H264_BOTTOM_FIELD_REF; in v4l2_h264_init_reflist_builder()
51 b->cur_pic_order_count = dec_params->top_field_order_cnt; in v4l2_h264_init_reflist_builder()
52 b->cur_pic_fields = V4L2_H264_TOP_FIELD_REF; in v4l2_h264_init_reflist_builder()
60 b->refs[i].longterm = true; in v4l2_h264_init_reflist_builder()
65 * For long term references, frame_num is set to in v4l2_h264_init_reflist_builder()
68 if (!b->refs[i].longterm && dpb[i].frame_num > cur_frame_num) in v4l2_h264_init_reflist_builder()
69 b->refs[i].frame_num = (int)dpb[i].frame_num - in v4l2_h264_init_reflist_builder()
72 b->refs[i].frame_num = dpb[i].frame_num; in v4l2_h264_init_reflist_builder()
74 b->refs[i].top_field_order_cnt = dpb[i].top_field_order_cnt; in v4l2_h264_init_reflist_builder()
75 b->refs[i].bottom_field_order_cnt = dpb[i].bottom_field_order_cnt; in v4l2_h264_init_reflist_builder()
77 if (b->cur_pic_fields == V4L2_H264_FRAME_REF) { in v4l2_h264_init_reflist_builder()
80 b->unordered_reflist[b->num_valid].index = i; in v4l2_h264_init_reflist_builder()
81 b->unordered_reflist[b->num_valid].fields = fields; in v4l2_h264_init_reflist_builder()
82 b->num_valid++; in v4l2_h264_init_reflist_builder()
89 b->unordered_reflist[b->num_valid].index = i; in v4l2_h264_init_reflist_builder()
90 b->unordered_reflist[b->num_valid].fields = fields; in v4l2_h264_init_reflist_builder()
91 b->num_valid++; in v4l2_h264_init_reflist_builder()
97 b->unordered_reflist[b->num_valid].index = i; in v4l2_h264_init_reflist_builder()
98 b->unordered_reflist[b->num_valid].fields = fields; in v4l2_h264_init_reflist_builder()
99 b->num_valid++; in v4l2_h264_init_reflist_builder()
103 for (i = b->num_valid; i < ARRAY_SIZE(b->unordered_reflist); i++) in v4l2_h264_init_reflist_builder()
104 b->unordered_reflist[i].index = i; in v4l2_h264_init_reflist_builder()
111 switch (ref->fields) { in v4l2_h264_get_poc()
113 return min(b->refs[ref->index].top_field_order_cnt, in v4l2_h264_get_poc()
114 b->refs[ref->index].bottom_field_order_cnt); in v4l2_h264_get_poc()
116 return b->refs[ref->index].top_field_order_cnt; in v4l2_h264_get_poc()
118 return b->refs[ref->index].bottom_field_order_cnt; in v4l2_h264_get_poc()
131 idxa = ((struct v4l2_h264_reference *)ptra)->index; in v4l2_h264_p_ref_list_cmp()
132 idxb = ((struct v4l2_h264_reference *)ptrb)->index; in v4l2_h264_p_ref_list_cmp()
138 if (builder->refs[idxa].longterm != builder->refs[idxb].longterm) { in v4l2_h264_p_ref_list_cmp()
139 /* Short term pics first. */ in v4l2_h264_p_ref_list_cmp()
140 if (!builder->refs[idxa].longterm) in v4l2_h264_p_ref_list_cmp()
141 return -1; in v4l2_h264_p_ref_list_cmp()
147 * For frames, short term pics are in descending pic num order and long in v4l2_h264_p_ref_list_cmp()
148 * term ones in ascending order. For fields, the same direction is used in v4l2_h264_p_ref_list_cmp()
150 * frame_num are the same (see formula (8-28) and (8-29)). For this in v4l2_h264_p_ref_list_cmp()
154 if (!builder->refs[idxa].longterm) in v4l2_h264_p_ref_list_cmp()
155 return builder->refs[idxb].frame_num < in v4l2_h264_p_ref_list_cmp()
156 builder->refs[idxa].frame_num ? in v4l2_h264_p_ref_list_cmp()
157 -1 : 1; in v4l2_h264_p_ref_list_cmp()
159 return builder->refs[idxa].frame_num < builder->refs[idxb].frame_num ? in v4l2_h264_p_ref_list_cmp()
160 -1 : 1; in v4l2_h264_p_ref_list_cmp()
170 idxa = ((struct v4l2_h264_reference *)ptra)->index; in v4l2_h264_b0_ref_list_cmp()
171 idxb = ((struct v4l2_h264_reference *)ptrb)->index; in v4l2_h264_b0_ref_list_cmp()
177 if (builder->refs[idxa].longterm != builder->refs[idxb].longterm) { in v4l2_h264_b0_ref_list_cmp()
178 /* Short term pics first. */ in v4l2_h264_b0_ref_list_cmp()
179 if (!builder->refs[idxa].longterm) in v4l2_h264_b0_ref_list_cmp()
180 return -1; in v4l2_h264_b0_ref_list_cmp()
185 /* Long term pics in ascending frame num order. */ in v4l2_h264_b0_ref_list_cmp()
186 if (builder->refs[idxa].longterm) in v4l2_h264_b0_ref_list_cmp()
187 return builder->refs[idxa].frame_num < in v4l2_h264_b0_ref_list_cmp()
188 builder->refs[idxb].frame_num ? in v4l2_h264_b0_ref_list_cmp()
189 -1 : 1; in v4l2_h264_b0_ref_list_cmp()
195 * Short term pics with POC < cur POC first in POC descending order in v4l2_h264_b0_ref_list_cmp()
196 * followed by short term pics with POC > cur POC in POC ascending in v4l2_h264_b0_ref_list_cmp()
199 if ((poca < builder->cur_pic_order_count) != in v4l2_h264_b0_ref_list_cmp()
200 (pocb < builder->cur_pic_order_count)) in v4l2_h264_b0_ref_list_cmp()
201 return poca < pocb ? -1 : 1; in v4l2_h264_b0_ref_list_cmp()
202 else if (poca < builder->cur_pic_order_count) in v4l2_h264_b0_ref_list_cmp()
203 return pocb < poca ? -1 : 1; in v4l2_h264_b0_ref_list_cmp()
205 return poca < pocb ? -1 : 1; in v4l2_h264_b0_ref_list_cmp()
215 idxa = ((struct v4l2_h264_reference *)ptra)->index; in v4l2_h264_b1_ref_list_cmp()
216 idxb = ((struct v4l2_h264_reference *)ptrb)->index; in v4l2_h264_b1_ref_list_cmp()
222 if (builder->refs[idxa].longterm != builder->refs[idxb].longterm) { in v4l2_h264_b1_ref_list_cmp()
223 /* Short term pics first. */ in v4l2_h264_b1_ref_list_cmp()
224 if (!builder->refs[idxa].longterm) in v4l2_h264_b1_ref_list_cmp()
225 return -1; in v4l2_h264_b1_ref_list_cmp()
230 /* Long term pics in ascending frame num order. */ in v4l2_h264_b1_ref_list_cmp()
231 if (builder->refs[idxa].longterm) in v4l2_h264_b1_ref_list_cmp()
232 return builder->refs[idxa].frame_num < in v4l2_h264_b1_ref_list_cmp()
233 builder->refs[idxb].frame_num ? in v4l2_h264_b1_ref_list_cmp()
234 -1 : 1; in v4l2_h264_b1_ref_list_cmp()
240 * Short term pics with POC > cur POC first in POC ascending order in v4l2_h264_b1_ref_list_cmp()
241 * followed by short term pics with POC < cur POC in POC descending in v4l2_h264_b1_ref_list_cmp()
244 if ((poca < builder->cur_pic_order_count) != in v4l2_h264_b1_ref_list_cmp()
245 (pocb < builder->cur_pic_order_count)) in v4l2_h264_b1_ref_list_cmp()
246 return pocb < poca ? -1 : 1; in v4l2_h264_b1_ref_list_cmp()
247 else if (poca < builder->cur_pic_order_count) in v4l2_h264_b1_ref_list_cmp()
248 return pocb < poca ? -1 : 1; in v4l2_h264_b1_ref_list_cmp()
250 return poca < pocb ? -1 : 1; in v4l2_h264_b1_ref_list_cmp()
256 * parity. This has to be done for short term and long term references
265 memcpy(tmplist, reflist, sizeof(tmplist[0]) * b->num_valid); in reorder_field_reflist()
269 for (; i < b->num_valid && b->refs[tmplist[i].index].longterm == lt; i++) { in reorder_field_reflist()
270 if (tmplist[i].fields == b->cur_pic_fields) { in reorder_field_reflist()
276 for (; j < b->num_valid && b->refs[tmplist[j].index].longterm == lt; j++) { in reorder_field_reflist()
277 if (tmplist[j].fields != b->cur_pic_fields) { in reorder_field_reflist()
282 } while ((i < b->num_valid && b->refs[tmplist[i].index].longterm == lt) || in reorder_field_reflist()
283 (j < b->num_valid && b->refs[tmplist[j].index].longterm == lt)); in reorder_field_reflist()
311 n += snprintf(*out_str + n, tmp_str_size - n, "|"); in format_ref_list_p()
313 for (i = 0; i < builder->num_valid; i++) { in format_ref_list_p()
317 int frame_num = builder->refs[reflist[i].index].frame_num; in format_ref_list_p()
318 bool longterm = builder->refs[reflist[i].index].longterm; in format_ref_list_p()
320 n += scnprintf(*out_str + n, tmp_str_size - n, "%i%c%c|", in format_ref_list_p()
334 builder->cur_pic_order_count, in print_ref_list_p()
335 ref_type_to_char(builder->cur_pic_fields), in print_ref_list_p()
351 n += snprintf(*out_str + n, tmp_str_size - n, "|"); in format_ref_list_b()
353 for (i = 0; i < builder->num_valid; i++) { in format_ref_list_b()
354 int frame_num = builder->refs[reflist[i].index].frame_num; in format_ref_list_b()
356 bool longterm = builder->refs[reflist[i].index].longterm; in format_ref_list_b()
358 n += scnprintf(*out_str + n, tmp_str_size - n, "%i%c%c|", in format_ref_list_b()
373 list_num, builder->cur_pic_order_count, in print_ref_list_b()
374 ref_type_to_char(builder->cur_pic_fields), in print_ref_list_b()
381 * v4l2_h264_build_p_ref_list() - Build the P reference list
396 memcpy(reflist, builder->unordered_reflist, in v4l2_h264_build_p_ref_list()
397 sizeof(builder->unordered_reflist[0]) * builder->num_valid); in v4l2_h264_build_p_ref_list()
398 sort_r(reflist, builder->num_valid, sizeof(*reflist), in v4l2_h264_build_p_ref_list()
401 if (builder->cur_pic_fields != V4L2_H264_FRAME_REF) in v4l2_h264_build_p_ref_list()
409 * v4l2_h264_build_b_ref_lists() - Build the B0/B1 reference lists
427 memcpy(b0_reflist, builder->unordered_reflist, in v4l2_h264_build_b_ref_lists()
428 sizeof(builder->unordered_reflist[0]) * builder->num_valid); in v4l2_h264_build_b_ref_lists()
429 sort_r(b0_reflist, builder->num_valid, sizeof(*b0_reflist), in v4l2_h264_build_b_ref_lists()
432 memcpy(b1_reflist, builder->unordered_reflist, in v4l2_h264_build_b_ref_lists()
433 sizeof(builder->unordered_reflist[0]) * builder->num_valid); in v4l2_h264_build_b_ref_lists()
434 sort_r(b1_reflist, builder->num_valid, sizeof(*b1_reflist), in v4l2_h264_build_b_ref_lists()
437 if (builder->cur_pic_fields != V4L2_H264_FRAME_REF) { in v4l2_h264_build_b_ref_lists()
442 if (builder->num_valid > 1 && in v4l2_h264_build_b_ref_lists()
443 !memcmp(b1_reflist, b0_reflist, builder->num_valid)) in v4l2_h264_build_b_ref_lists()