Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * VVC motion vector decoder | ||
3 | * | ||
4 | * Copyright (C) 2023 Nuo Mi | ||
5 | * Copyright (C) 2022 Xu Mu | ||
6 | * This file is part of FFmpeg. | ||
7 | * | ||
8 | * FFmpeg is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU Lesser General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2.1 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | * FFmpeg is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with FFmpeg; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | */ | ||
22 | |||
23 | #include "ctu.h" | ||
24 | #include "data.h" | ||
25 | #include "refs.h" | ||
26 | #include "mvs.h" | ||
27 | |||
28 | #define IS_SAME_MV(a, b) (AV_RN64A(a) == AV_RN64A(b)) | ||
29 | |||
30 | //check if the two luma locations belong to the same motion estimation region | ||
31 | 629997 | static av_always_inline int is_same_mer(const VVCFrameContext *fc, const int xN, const int yN, const int xP, const int yP) | |
32 | { | ||
33 | 629997 | const uint8_t plevel = fc->ps.sps->log2_parallel_merge_level; | |
34 | |||
35 |
2/2✓ Branch 0 taken 40744 times.
✓ Branch 1 taken 589253 times.
|
670741 | return xN >> plevel == xP >> plevel && |
36 |
2/2✓ Branch 0 taken 6192 times.
✓ Branch 1 taken 34552 times.
|
40744 | yN >> plevel == yP >> plevel; |
37 | } | ||
38 | |||
39 | //return true if we have same mvs and ref_idxs | ||
40 | 2028140 | static av_always_inline int compare_mv_ref_idx(const MvField *n, const MvField *o) | |
41 | { | ||
42 |
4/4✓ Branch 0 taken 1708169 times.
✓ Branch 1 taken 319971 times.
✓ Branch 2 taken 527706 times.
✓ Branch 3 taken 1180463 times.
|
2028140 | if (!o || n->pred_flag != o->pred_flag) |
43 | 847677 | return 0; | |
44 |
2/2✓ Branch 0 taken 1482452 times.
✓ Branch 1 taken 252424 times.
|
1734876 | for (int i = 0; i < 2; i++) { |
45 | 1482452 | PredFlag mask = i + 1; | |
46 |
2/2✓ Branch 0 taken 1343220 times.
✓ Branch 1 taken 139232 times.
|
1482452 | if (n->pred_flag & mask) { |
47 | 1343220 | const int same_ref_idx = n->ref_idx[i] == o->ref_idx[i]; | |
48 | 1343220 | const int same_mv = IS_SAME_MV(n->mv + i, o->mv + i); | |
49 |
4/4✓ Branch 0 taken 1222760 times.
✓ Branch 1 taken 120460 times.
✓ Branch 2 taken 807579 times.
✓ Branch 3 taken 415181 times.
|
1343220 | if (!same_ref_idx || !same_mv) |
50 | 928039 | return 0; | |
51 | } | ||
52 | } | ||
53 | 252424 | return 1; | |
54 | } | ||
55 | |||
56 | // 8.5.2.15 Temporal motion buffer compression process for collocated motion vectors | ||
57 | 1912770 | static av_always_inline void mv_compression(Mv *motion) | |
58 | { | ||
59 | 1912770 | int mv[2] = {motion->x, motion->y}; | |
60 |
2/2✓ Branch 0 taken 3825540 times.
✓ Branch 1 taken 1912770 times.
|
5738310 | for (int i = 0; i < 2; i++) { |
61 | 3825540 | const int s = mv[i] >> 17; | |
62 | 3825540 | const int f = av_log2((mv[i] ^ s) | 31) - 4; | |
63 | 3825540 | const int mask = (-1 * (1 << f)) >> 1; | |
64 | 3825540 | const int round = (1 << f) >> 2; | |
65 | 3825540 | mv[i] = (mv[i] + round) & mask; | |
66 | } | ||
67 | 1912770 | motion->x = mv[0]; | |
68 | 1912770 | motion->y = mv[1]; | |
69 | 1912770 | } | |
70 | |||
71 | 1512837 | void ff_vvc_mv_scale(Mv *dst, const Mv *src, int td, int tb) | |
72 | { | ||
73 | int tx, scale_factor; | ||
74 | |||
75 | 1512837 | td = av_clip_int8(td); | |
76 | 1512837 | tb = av_clip_int8(tb); | |
77 | 1512837 | tx = (0x4000 + (abs(td) >> 1)) / td; | |
78 | 1512837 | scale_factor = av_clip_intp2((tb * tx + 32) >> 6, 12); | |
79 | 1512837 | dst->x = av_clip_intp2((scale_factor * src->x + 127 + | |
80 | 1512837 | (scale_factor * src->x < 0)) >> 8, 17); | |
81 | 1512837 | dst->y = av_clip_intp2((scale_factor * src->y + 127 + | |
82 | 1512837 | (scale_factor * src->y < 0)) >> 8, 17); | |
83 | 1512837 | } | |
84 | |||
85 | //part of 8.5.2.12 Derivation process for collocated motion vectors | ||
86 | 1924839 | static int check_mvset(Mv *mvLXCol, Mv *mvCol, | |
87 | int colPic, int poc, | ||
88 | const RefPicList *refPicList, int X, int refIdxLx, | ||
89 | const RefPicList *refPicList_col, int listCol, int refidxCol) | ||
90 | { | ||
91 | 1924839 | int cur_lt = refPicList[X].refs[refIdxLx].is_lt; | |
92 | 1924839 | int col_lt = refPicList_col[listCol].refs[refidxCol].is_lt; | |
93 | int col_poc_diff, cur_poc_diff; | ||
94 | |||
95 |
2/2✓ Branch 0 taken 12069 times.
✓ Branch 1 taken 1912770 times.
|
1924839 | if (cur_lt != col_lt) { |
96 | 12069 | mvLXCol->x = 0; | |
97 | 12069 | mvLXCol->y = 0; | |
98 | 12069 | return 0; | |
99 | } | ||
100 | |||
101 | 1912770 | col_poc_diff = colPic - refPicList_col[listCol].refs[refidxCol].poc; | |
102 | 1912770 | cur_poc_diff = poc - refPicList[X].refs[refIdxLx].poc; | |
103 | |||
104 | 1912770 | mv_compression(mvCol); | |
105 |
4/4✓ Branch 0 taken 1904552 times.
✓ Branch 1 taken 8218 times.
✓ Branch 2 taken 406776 times.
✓ Branch 3 taken 1497776 times.
|
1912770 | if (cur_lt || col_poc_diff == cur_poc_diff) { |
106 | 414994 | mvLXCol->x = av_clip_intp2(mvCol->x, 17); | |
107 | 414994 | mvLXCol->y = av_clip_intp2(mvCol->y, 17); | |
108 | } else { | ||
109 | 1497776 | ff_vvc_mv_scale(mvLXCol, mvCol, col_poc_diff, cur_poc_diff); | |
110 | } | ||
111 | 1912770 | return 1; | |
112 | } | ||
113 | |||
114 | #define CHECK_MVSET(l) \ | ||
115 | check_mvset(mvLXCol, temp_col.mv + l, \ | ||
116 | colPic, fc->ps.ph.poc, \ | ||
117 | refPicList, X, refIdxLx, \ | ||
118 | refPicList_col, L ## l, temp_col.ref_idx[l]) | ||
119 | |||
120 | //derive NoBackwardPredFlag | ||
121 | 452494 | int ff_vvc_no_backward_pred_flag(const VVCLocalContext *lc) | |
122 | { | ||
123 | 452494 | int check_diffpicount = 0; | |
124 | int i, j; | ||
125 | 452494 | const RefPicList *rpl = lc->sc->rpl; | |
126 | |||
127 |
2/2✓ Branch 0 taken 904988 times.
✓ Branch 1 taken 452494 times.
|
1357482 | for (j = 0; j < 2; j++) { |
128 |
2/2✓ Branch 0 taken 1448759 times.
✓ Branch 1 taken 408999 times.
|
1857758 | for (i = 0; i < lc->sc->sh.r->num_ref_idx_active[j]; i++) { |
129 |
2/2✓ Branch 0 taken 495989 times.
✓ Branch 1 taken 952770 times.
|
1448759 | if (rpl[j].refs[i].poc > lc->fc->ps.ph.poc) { |
130 | 495989 | check_diffpicount++; | |
131 | 495989 | break; | |
132 | } | ||
133 | } | ||
134 | } | ||
135 | 452494 | return !check_diffpicount; | |
136 | } | ||
137 | |||
138 | //8.5.2.12 Derivation process for collocated motion vectors | ||
139 | 2328424 | static int derive_temporal_colocated_mvs(const VVCLocalContext *lc, MvField temp_col, | |
140 | int refIdxLx, Mv *mvLXCol, int X, | ||
141 | int colPic, const RefPicList *refPicList_col, int sb_flag) | ||
142 | { | ||
143 | 2328424 | const VVCFrameContext *fc = lc->fc; | |
144 | 2328424 | const SliceContext *sc = lc->sc; | |
145 | 2328424 | RefPicList* refPicList = sc->rpl; | |
146 | |||
147 |
2/2✓ Branch 0 taken 2253367 times.
✓ Branch 1 taken 75057 times.
|
2328424 | if (temp_col.pred_flag == PF_INTRA || |
148 |
2/2✓ Branch 0 taken 2251434 times.
✓ Branch 1 taken 1933 times.
|
2253367 | temp_col.pred_flag == PF_IBC || |
149 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2251434 times.
|
2251434 | temp_col.pred_flag == PF_PLT) |
150 | 76990 | return 0; | |
151 | |||
152 |
2/2✓ Branch 0 taken 2133993 times.
✓ Branch 1 taken 117441 times.
|
2251434 | if (sb_flag){ |
153 |
2/2✓ Branch 0 taken 1239369 times.
✓ Branch 1 taken 894624 times.
|
2133993 | if (X == 0) { |
154 |
2/2✓ Branch 0 taken 1123381 times.
✓ Branch 1 taken 115988 times.
|
1239369 | if (temp_col.pred_flag & PF_L0) |
155 | 1123381 | return CHECK_MVSET(0); | |
156 |
3/4✓ Branch 1 taken 2338 times.
✓ Branch 2 taken 113650 times.
✓ Branch 3 taken 2338 times.
✗ Branch 4 not taken.
|
115988 | else if (ff_vvc_no_backward_pred_flag(lc) && (temp_col.pred_flag & PF_L1)) |
157 | 2338 | return CHECK_MVSET(1); | |
158 | } else { | ||
159 |
2/2✓ Branch 0 taken 618500 times.
✓ Branch 1 taken 276124 times.
|
894624 | if (temp_col.pred_flag & PF_L1) |
160 | 618500 | return CHECK_MVSET(1); | |
161 |
3/4✓ Branch 1 taken 63179 times.
✓ Branch 2 taken 212945 times.
✓ Branch 3 taken 63179 times.
✗ Branch 4 not taken.
|
276124 | else if (ff_vvc_no_backward_pred_flag(lc) && (temp_col.pred_flag & PF_L0)) |
162 | 63179 | return CHECK_MVSET(0); | |
163 | } | ||
164 | } else { | ||
165 |
2/2✓ Branch 0 taken 14563 times.
✓ Branch 1 taken 102878 times.
|
117441 | if (!(temp_col.pred_flag & PF_L0)) |
166 | 14563 | return CHECK_MVSET(1); | |
167 |
2/2✓ Branch 0 taken 53741 times.
✓ Branch 1 taken 49137 times.
|
102878 | else if (temp_col.pred_flag == PF_L0) |
168 | 53741 | return CHECK_MVSET(0); | |
169 |
1/2✓ Branch 0 taken 49137 times.
✗ Branch 1 not taken.
|
49137 | else if (temp_col.pred_flag == PF_BI) { |
170 |
2/2✓ Branch 1 taken 9308 times.
✓ Branch 2 taken 39829 times.
|
49137 | if (ff_vvc_no_backward_pred_flag(lc)) { |
171 |
2/2✓ Branch 0 taken 4853 times.
✓ Branch 1 taken 4455 times.
|
9308 | if (X == 0) |
172 | 4853 | return CHECK_MVSET(0); | |
173 | else | ||
174 | 4455 | return CHECK_MVSET(1); | |
175 | } else { | ||
176 |
2/2✓ Branch 0 taken 22401 times.
✓ Branch 1 taken 17428 times.
|
39829 | if (!lc->sc->sh.r->sh_collocated_from_l0_flag) |
177 | 22401 | return CHECK_MVSET(0); | |
178 | else | ||
179 | 17428 | return CHECK_MVSET(1); | |
180 | } | ||
181 | } | ||
182 | } | ||
183 | 326595 | return 0; | |
184 | } | ||
185 | |||
186 | #define TAB_MVF(x, y) \ | ||
187 | tab_mvf[((y) >> MIN_PU_LOG2) * min_pu_width + ((x) >> MIN_PU_LOG2)] | ||
188 | |||
189 | #define TAB_MVF_PU(v) \ | ||
190 | TAB_MVF(x ## v, y ## v) | ||
191 | |||
192 | #define TAB_CP_MV(lx, x, y) \ | ||
193 | fc->tab.cp_mv[lx][((((y) >> min_cb_log2_size) * min_cb_width + ((x) >> min_cb_log2_size)) ) * MAX_CONTROL_POINTS] | ||
194 | |||
195 | |||
196 | #define DERIVE_TEMPORAL_COLOCATED_MVS(sb_flag) \ | ||
197 | derive_temporal_colocated_mvs(lc, temp_col, \ | ||
198 | refIdxLx, mvLXCol, X, colPic, \ | ||
199 | ff_vvc_get_ref_list(fc, ref, x, y), sb_flag) | ||
200 | |||
201 | //8.5.2.11 Derivation process for temporal luma motion vector prediction | ||
202 | 144928 | static int temporal_luma_motion_vector(const VVCLocalContext *lc, | |
203 | const int refIdxLx, Mv *mvLXCol, const int X, int check_center, int sb_flag) | ||
204 | { | ||
205 | 144928 | const VVCFrameContext *fc = lc->fc; | |
206 | 144928 | const VVCSPS *sps = fc->ps.sps; | |
207 | 144928 | const VVCPPS *pps = fc->ps.pps; | |
208 | 144928 | const CodingUnit *cu = lc->cu; | |
209 | 144928 | const int subpic_idx = lc->sc->sh.r->curr_subpic_idx; | |
210 | 144928 | int x, y, x_end, y_end, colPic, availableFlagLXCol = 0; | |
211 | 144928 | int min_pu_width = fc->ps.pps->min_pu_width; | |
212 | 144928 | VVCFrame *ref = fc->ref->collocated_ref; | |
213 | MvField *tab_mvf; | ||
214 | MvField temp_col; | ||
215 | |||
216 |
2/2✓ Branch 0 taken 66 times.
✓ Branch 1 taken 144862 times.
|
144928 | if (!ref) { |
217 | 66 | memset(mvLXCol, 0, sizeof(*mvLXCol)); | |
218 | 66 | return 0; | |
219 | } | ||
220 | |||
221 |
3/4✓ Branch 0 taken 144862 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4440 times.
✓ Branch 3 taken 140422 times.
|
144862 | if (!fc->ps.ph.r->ph_temporal_mvp_enabled_flag || (cu->cb_width * cu->cb_height <= 32)) |
222 | 4440 | return 0; | |
223 | |||
224 | 140422 | tab_mvf = ref->tab_dmvr_mvf; | |
225 | 140422 | colPic = ref->poc; | |
226 | |||
227 | //bottom right collocated motion vector | ||
228 | 140422 | x = cu->x0 + cu->cb_width; | |
229 | 140422 | y = cu->y0 + cu->cb_height; | |
230 | |||
231 | 140422 | x_end = pps->subpic_x[subpic_idx] + pps->subpic_width[subpic_idx]; | |
232 | 140422 | y_end = pps->subpic_y[subpic_idx] + pps->subpic_height[subpic_idx]; | |
233 | |||
234 |
1/2✓ Branch 0 taken 140422 times.
✗ Branch 1 not taken.
|
140422 | if (tab_mvf && |
235 |
4/4✓ Branch 0 taken 118672 times.
✓ Branch 1 taken 21750 times.
✓ Branch 2 taken 116378 times.
✓ Branch 3 taken 2294 times.
|
140422 | (cu->y0 >> sps->ctb_log2_size_y) == (y >> sps->ctb_log2_size_y) && |
236 |
2/2✓ Branch 0 taken 112486 times.
✓ Branch 1 taken 3892 times.
|
116378 | x < x_end && y < y_end) { |
237 | 112486 | x &= ~7; | |
238 | 112486 | y &= ~7; | |
239 | 112486 | temp_col = TAB_MVF(x, y); | |
240 | 112486 | availableFlagLXCol = DERIVE_TEMPORAL_COLOCATED_MVS(sb_flag); | |
241 | } | ||
242 |
2/2✓ Branch 0 taken 127148 times.
✓ Branch 1 taken 13274 times.
|
140422 | if (check_center) { |
243 | // derive center collocated motion vector | ||
244 |
3/4✓ Branch 0 taken 127148 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 54820 times.
✓ Branch 3 taken 72328 times.
|
127148 | if (tab_mvf && !availableFlagLXCol) { |
245 | 54820 | x = cu->x0 + (cu->cb_width >> 1); | |
246 | 54820 | y = cu->y0 + (cu->cb_height >> 1); | |
247 | 54820 | x &= ~7; | |
248 | 54820 | y &= ~7; | |
249 | 54820 | temp_col = TAB_MVF(x, y); | |
250 | 54820 | availableFlagLXCol = DERIVE_TEMPORAL_COLOCATED_MVS(sb_flag); | |
251 | } | ||
252 | } | ||
253 | 140422 | return availableFlagLXCol; | |
254 | } | ||
255 | |||
256 | 5486429 | void ff_vvc_set_mvf(const VVCLocalContext *lc, const int x0, const int y0, const int w, const int h, const MvField *mvf) | |
257 | { | ||
258 | 5486429 | const VVCFrameContext *fc = lc->fc; | |
259 | 5486429 | MvField *tab_mvf = fc->tab.mvf; | |
260 | 5486429 | const int min_pu_width = fc->ps.pps->min_pu_width; | |
261 | 5486429 | const int min_pu_size = 1 << MIN_PU_LOG2; | |
262 |
2/2✓ Branch 0 taken 8527283 times.
✓ Branch 1 taken 5486429 times.
|
14013712 | for (int dy = 0; dy < h; dy += min_pu_size) { |
263 |
2/2✓ Branch 0 taken 37531700 times.
✓ Branch 1 taken 8527283 times.
|
46058983 | for (int dx = 0; dx < w; dx += min_pu_size) { |
264 | 37531700 | const int x = x0 + dx; | |
265 | 37531700 | const int y = y0 + dy; | |
266 | 37531700 | TAB_MVF(x, y) = *mvf; | |
267 | } | ||
268 | } | ||
269 | 5486429 | } | |
270 | |||
271 | 627898 | void ff_vvc_set_intra_mvf(const VVCLocalContext *lc, const bool dmvr, const PredFlag pf, const bool ciip_flag) | |
272 | { | ||
273 | 627898 | const VVCFrameContext *fc = lc->fc; | |
274 | 627898 | const CodingUnit *cu = lc->cu; | |
275 |
2/2✓ Branch 0 taken 31182 times.
✓ Branch 1 taken 596716 times.
|
627898 | MvField *tab_mvf = dmvr ? fc->ref->tab_dmvr_mvf : fc->tab.mvf; |
276 | 627898 | const int min_pu_width = fc->ps.pps->min_pu_width; | |
277 | 627898 | const int min_pu_size = 1 << MIN_PU_LOG2; | |
278 |
2/2✓ Branch 0 taken 1567115 times.
✓ Branch 1 taken 627898 times.
|
2195013 | for (int dy = 0; dy < cu->cb_height; dy += min_pu_size) { |
279 |
2/2✓ Branch 0 taken 6542224 times.
✓ Branch 1 taken 1567115 times.
|
8109339 | for (int dx = 0; dx < cu->cb_width; dx += min_pu_size) { |
280 | 6542224 | const int x = cu->x0 + dx; | |
281 | 6542224 | const int y = cu->y0 + dy; | |
282 | 6542224 | MvField *mv = &TAB_MVF(x, y); | |
283 | |||
284 | 6542224 | mv->pred_flag = pf; | |
285 | 6542224 | mv->ciip_flag = ciip_flag; | |
286 | } | ||
287 | } | ||
288 | 627898 | } | |
289 | |||
290 | //cbProfFlagLX from 8.5.5.9 Derivation process for motion vector arrays from affine control point motion vectors | ||
291 | 44339 | static int derive_cb_prof_flag_lx(const VVCLocalContext *lc, const PredictionUnit* pu, int lx, int is_fallback) | |
292 | { | ||
293 | 44339 | const MotionInfo* mi = &pu->mi; | |
294 | 44339 | const Mv* cp_mv = &mi->mv[lx][0]; | |
295 |
4/4✓ Branch 0 taken 44172 times.
✓ Branch 1 taken 167 times.
✓ Branch 2 taken 1090 times.
✓ Branch 3 taken 43082 times.
|
44339 | if (lc->fc->ps.ph.r->ph_prof_disabled_flag || is_fallback) |
296 | 1257 | return 0; | |
297 |
2/2✓ Branch 0 taken 17858 times.
✓ Branch 1 taken 25224 times.
|
43082 | if (mi->motion_model_idc == MOTION_4_PARAMS_AFFINE) { |
298 |
2/2✓ Branch 0 taken 4720 times.
✓ Branch 1 taken 13138 times.
|
17858 | if (IS_SAME_MV(cp_mv, cp_mv + 1)) |
299 | 4720 | return 0; | |
300 | } | ||
301 |
2/2✓ Branch 0 taken 25224 times.
✓ Branch 1 taken 13138 times.
|
38362 | if (mi->motion_model_idc == MOTION_6_PARAMS_AFFINE) { |
302 |
4/4✓ Branch 0 taken 4237 times.
✓ Branch 1 taken 20987 times.
✓ Branch 2 taken 891 times.
✓ Branch 3 taken 3346 times.
|
25224 | if (IS_SAME_MV(cp_mv, cp_mv + 1) && IS_SAME_MV(cp_mv, cp_mv + 2)) |
303 | 891 | return 0; | |
304 | } | ||
305 |
2/2✓ Branch 0 taken 137 times.
✓ Branch 1 taken 37334 times.
|
37471 | if (lc->sc->rpl[lx].refs[mi->ref_idx[lx]].is_scaled) |
306 | 137 | return 0; | |
307 | 37334 | return 1; | |
308 | } | ||
309 | |||
310 | typedef struct SubblockParams { | ||
311 | int d_hor_x; | ||
312 | int d_ver_x; | ||
313 | int d_hor_y; | ||
314 | int d_ver_y; | ||
315 | int mv_scale_hor; | ||
316 | int mv_scale_ver; | ||
317 | int is_fallback; | ||
318 | |||
319 | int cb_width; | ||
320 | int cb_height; | ||
321 | } SubblockParams; | ||
322 | |||
323 | 44339 | static int is_fallback_mode(const SubblockParams *sp, const PredFlag pred_flag) | |
324 | { | ||
325 | 44339 | const int a = 4 * (2048 + sp->d_hor_x); | |
326 | 44339 | const int b = 4 * sp->d_hor_y; | |
327 | 44339 | const int c = 4 * (2048 + sp->d_ver_y); | |
328 | 44339 | const int d = 4 * sp->d_ver_x; | |
329 |
2/2✓ Branch 0 taken 19232 times.
✓ Branch 1 taken 25107 times.
|
44339 | if (pred_flag == PF_BI) { |
330 |
2/2✓ Branch 0 taken 19124 times.
✓ Branch 1 taken 108 times.
|
19232 | const int max_w4 = FFMAX(0, FFMAX(a, FFMAX(b, a + b))); |
331 |
2/2✓ Branch 0 taken 108 times.
✓ Branch 1 taken 19124 times.
|
19232 | const int min_w4 = FFMIN(0, FFMIN(a, FFMIN(b, a + b))); |
332 |
2/2✓ Branch 0 taken 19133 times.
✓ Branch 1 taken 99 times.
|
19232 | const int max_h4 = FFMAX(0, FFMAX(c, FFMAX(d, c + d))); |
333 |
2/2✓ Branch 0 taken 99 times.
✓ Branch 1 taken 19133 times.
|
19232 | const int min_h4 = FFMIN(0, FFMIN(c, FFMIN(d, c + d))); |
334 | 19232 | const int bx_wx4 = ((max_w4 - min_w4) >> 11) + 9; | |
335 | 19232 | const int bx_hx4 = ((max_h4 - min_h4) >> 11) + 9; | |
336 | 19232 | return bx_wx4 * bx_hx4 > 225; | |
337 | } else { | ||
338 | 25107 | const int bx_wxh = (FFABS(a) >> 11) + 9; | |
339 | 25107 | const int bx_hxh = (FFABS(d) >> 11) + 9; | |
340 | 25107 | const int bx_wxv = (FFABS(b) >> 11) + 9; | |
341 | 25107 | const int bx_hxv = (FFABS(c) >> 11) + 9; | |
342 |
4/4✓ Branch 0 taken 24445 times.
✓ Branch 1 taken 662 times.
✓ Branch 2 taken 24355 times.
✓ Branch 3 taken 90 times.
|
25107 | if (bx_wxh * bx_hxh <= 165 && bx_wxv * bx_hxv <= 165) |
343 | 24355 | return 0; | |
344 | } | ||
345 | 752 | return 1; | |
346 | } | ||
347 | |||
348 | 44339 | static void init_subblock_params(SubblockParams *sp, const MotionInfo* mi, | |
349 | const int cb_width, const int cb_height, const int lx) | ||
350 | { | ||
351 | 44339 | const int log2_cbw = av_log2(cb_width); | |
352 | 44339 | const int log2_cbh = av_log2(cb_height); | |
353 | 44339 | const Mv* cp_mv = mi->mv[lx]; | |
354 | 44339 | const int num_cp_mv = mi->motion_model_idc + 1; | |
355 | 44339 | sp->d_hor_x = (cp_mv[1].x - cp_mv[0].x) * (1 << (MAX_CU_DEPTH - log2_cbw)); | |
356 | 44339 | sp->d_ver_x = (cp_mv[1].y - cp_mv[0].y) * (1 << (MAX_CU_DEPTH - log2_cbw)); | |
357 |
2/2✓ Branch 0 taken 25604 times.
✓ Branch 1 taken 18735 times.
|
44339 | if (num_cp_mv == 3) { |
358 | 25604 | sp->d_hor_y = (cp_mv[2].x - cp_mv[0].x) * (1 << (MAX_CU_DEPTH - log2_cbh)); | |
359 | 25604 | sp->d_ver_y = (cp_mv[2].y - cp_mv[0].y) * (1 << (MAX_CU_DEPTH - log2_cbh)); | |
360 | } else { | ||
361 | 18735 | sp->d_hor_y = -sp->d_ver_x; | |
362 | 18735 | sp->d_ver_y = sp->d_hor_x; | |
363 | } | ||
364 | 44339 | sp->mv_scale_hor = (cp_mv[0].x) * (1 << MAX_CU_DEPTH); | |
365 | 44339 | sp->mv_scale_ver = (cp_mv[0].y) * (1 << MAX_CU_DEPTH); | |
366 | 44339 | sp->cb_width = cb_width; | |
367 | 44339 | sp->cb_height = cb_height; | |
368 | 44339 | sp->is_fallback = is_fallback_mode(sp, mi->pred_flag); | |
369 | 44339 | } | |
370 | |||
371 | 44339 | static void derive_subblock_diff_mvs(const VVCLocalContext *lc, PredictionUnit* pu, const SubblockParams* sp, const int lx) | |
372 | { | ||
373 | 44339 | pu->cb_prof_flag[lx] = derive_cb_prof_flag_lx(lc, pu, lx, sp->is_fallback); | |
374 |
2/2✓ Branch 0 taken 37334 times.
✓ Branch 1 taken 7005 times.
|
44339 | if (pu->cb_prof_flag[lx]) { |
375 | 37334 | const int dmv_limit = 1 << 5; | |
376 | 37334 | const int pos_offset_x = 6 * (sp->d_hor_x + sp->d_hor_y); | |
377 | 37334 | const int pos_offset_y = 6 * (sp->d_ver_x + sp->d_ver_y); | |
378 |
2/2✓ Branch 0 taken 149336 times.
✓ Branch 1 taken 37334 times.
|
186670 | for (int x = 0; x < AFFINE_MIN_BLOCK_SIZE; x++) { |
379 |
2/2✓ Branch 0 taken 597344 times.
✓ Branch 1 taken 149336 times.
|
746680 | for (int y = 0; y < AFFINE_MIN_BLOCK_SIZE; y++) { |
380 | 597344 | LOCAL_ALIGNED_8(Mv, diff, [1]); | |
381 | 597344 | diff->x = x * (sp->d_hor_x * (1 << 2)) + y * (sp->d_hor_y * (1 << 2)) - pos_offset_x; | |
382 | 597344 | diff->y = x * (sp->d_ver_x * (1 << 2)) + y * (sp->d_ver_y * (1 << 2)) - pos_offset_y; | |
383 | 597344 | ff_vvc_round_mv(diff, 0, 8); | |
384 | 597344 | pu->diff_mv_x[lx][AFFINE_MIN_BLOCK_SIZE * y + x] = av_clip(diff->x, -dmv_limit + 1, dmv_limit - 1); | |
385 | 597344 | pu->diff_mv_y[lx][AFFINE_MIN_BLOCK_SIZE * y + x] = av_clip(diff->y, -dmv_limit + 1, dmv_limit - 1); | |
386 | } | ||
387 | } | ||
388 | } | ||
389 | 44339 | } | |
390 | |||
391 | 44339 | static void store_cp_mv(const VVCLocalContext *lc, const MotionInfo *mi, const int lx) | |
392 | { | ||
393 | 44339 | VVCFrameContext *fc = lc->fc; | |
394 | 44339 | const CodingUnit *cu = lc->cu; | |
395 | 44339 | const int log2_min_cb_size = fc->ps.sps->min_cb_log2_size_y; | |
396 | 44339 | const int min_cb_size = fc->ps.sps->min_cb_size_y; | |
397 | 44339 | const int min_cb_width = fc->ps.pps->min_cb_width; | |
398 | 44339 | const int num_cp_mv = mi->motion_model_idc + 1; | |
399 | |||
400 |
2/2✓ Branch 0 taken 348128 times.
✓ Branch 1 taken 44339 times.
|
392467 | for (int dy = 0; dy < cu->cb_height; dy += min_cb_size) { |
401 |
2/2✓ Branch 0 taken 4317728 times.
✓ Branch 1 taken 348128 times.
|
4665856 | for (int dx = 0; dx < cu->cb_width; dx += min_cb_size) { |
402 | 4317728 | const int x_cb = (cu->x0 + dx) >> log2_min_cb_size; | |
403 | 4317728 | const int y_cb = (cu->y0 + dy) >> log2_min_cb_size; | |
404 | 4317728 | const int offset = (y_cb * min_cb_width + x_cb) * MAX_CONTROL_POINTS; | |
405 | |||
406 | 4317728 | memcpy(&fc->tab.cp_mv[lx][offset], mi->mv[lx], sizeof(Mv) * num_cp_mv); | |
407 | } | ||
408 | } | ||
409 | 44339 | } | |
410 | |||
411 | //8.5.5.9 Derivation process for motion vector arrays from affine control point motion vectors | ||
412 | 34723 | void ff_vvc_store_sb_mvs(const VVCLocalContext *lc, PredictionUnit *pu) | |
413 | { | ||
414 | 34723 | const CodingUnit *cu = lc->cu; | |
415 | 34723 | const MotionInfo *mi = &pu->mi; | |
416 | 34723 | const int sbw = cu->cb_width / mi->num_sb_x; | |
417 | 34723 | const int sbh = cu->cb_height / mi->num_sb_y; | |
418 | SubblockParams params[2]; | ||
419 | 34723 | MvField mvf = {0}; | |
420 | |||
421 | 34723 | mvf.pred_flag = mi->pred_flag; | |
422 | 34723 | mvf.bcw_idx = mi->bcw_idx; | |
423 | 34723 | mvf.hpel_if_idx = mi->hpel_if_idx; | |
424 |
2/2✓ Branch 0 taken 69446 times.
✓ Branch 1 taken 34723 times.
|
104169 | for (int i = 0; i < 2; i++) { |
425 | 69446 | const PredFlag mask = i + 1; | |
426 |
2/2✓ Branch 0 taken 44339 times.
✓ Branch 1 taken 25107 times.
|
69446 | if (mi->pred_flag & mask) { |
427 | 44339 | store_cp_mv(lc, mi, i); | |
428 | 44339 | init_subblock_params(params + i, mi, cu->cb_width, cu->cb_height, i); | |
429 | 44339 | derive_subblock_diff_mvs(lc, pu, params + i, i); | |
430 | 44339 | mvf.ref_idx[i] = mi->ref_idx[i]; | |
431 | } | ||
432 | } | ||
433 | |||
434 |
2/2✓ Branch 0 taken 274454 times.
✓ Branch 1 taken 34723 times.
|
309177 | for (int sby = 0; sby < mi->num_sb_y; sby++) { |
435 |
2/2✓ Branch 0 taken 3378072 times.
✓ Branch 1 taken 274454 times.
|
3652526 | for (int sbx = 0; sbx < mi->num_sb_x; sbx++) { |
436 | 3378072 | const int x0 = cu->x0 + sbx * sbw; | |
437 | 3378072 | const int y0 = cu->y0 + sby * sbh; | |
438 |
2/2✓ Branch 0 taken 6756144 times.
✓ Branch 1 taken 3378072 times.
|
10134216 | for (int i = 0; i < 2; i++) { |
439 | 6756144 | const PredFlag mask = i + 1; | |
440 |
2/2✓ Branch 0 taken 4317728 times.
✓ Branch 1 taken 2438416 times.
|
6756144 | if (mi->pred_flag & mask) { |
441 | 4317728 | const SubblockParams* sp = params + i; | |
442 |
2/2✓ Branch 0 taken 141368 times.
✓ Branch 1 taken 4176360 times.
|
4317728 | const int x_pos_cb = sp->is_fallback ? (cu->cb_width >> 1) : (2 + (sbx << MIN_CU_LOG2)); |
443 |
2/2✓ Branch 0 taken 141368 times.
✓ Branch 1 taken 4176360 times.
|
4317728 | const int y_pos_cb = sp->is_fallback ? (cu->cb_height >> 1) : (2 + (sby << MIN_CU_LOG2)); |
444 | 4317728 | Mv *mv = mvf.mv + i; | |
445 | |||
446 | 4317728 | mv->x = sp->mv_scale_hor + sp->d_hor_x * x_pos_cb + sp->d_hor_y * y_pos_cb; | |
447 | 4317728 | mv->y = sp->mv_scale_ver + sp->d_ver_x * x_pos_cb + sp->d_ver_y * y_pos_cb; | |
448 | 4317728 | ff_vvc_round_mv(mv, 0, MAX_CU_DEPTH); | |
449 | 4317728 | ff_vvc_clip_mv(mv); | |
450 | } | ||
451 | } | ||
452 | 3378072 | ff_vvc_set_mvf(lc, x0, y0, sbw, sbh, &mvf); | |
453 | } | ||
454 | } | ||
455 | 34723 | } | |
456 | |||
457 | 25615 | void ff_vvc_store_gpm_mvf(const VVCLocalContext *lc, const PredictionUnit *pu) | |
458 | { | ||
459 | 25615 | const CodingUnit *cu = lc->cu; | |
460 | 25615 | const int angle_idx = ff_vvc_gpm_angle_idx[pu->gpm_partition_idx]; | |
461 | 25615 | const int distance_idx = ff_vvc_gpm_distance_idx[pu->gpm_partition_idx]; | |
462 | 25615 | const int displacement_x = ff_vvc_gpm_distance_lut[angle_idx]; | |
463 | 25615 | const int displacement_y = ff_vvc_gpm_distance_lut[(angle_idx + 8) % 32]; | |
464 |
4/4✓ Branch 0 taken 13514 times.
✓ Branch 1 taken 12101 times.
✓ Branch 2 taken 10810 times.
✓ Branch 3 taken 2704 times.
|
25615 | const int is_flip = angle_idx >= 13 &&angle_idx <= 27; |
465 |
6/6✓ Branch 0 taken 24018 times.
✓ Branch 1 taken 1597 times.
✓ Branch 2 taken 21262 times.
✓ Branch 3 taken 2756 times.
✓ Branch 4 taken 5180 times.
✓ Branch 5 taken 16082 times.
|
25615 | const int shift_hor = (angle_idx % 16 == 8 || (angle_idx % 16 && cu->cb_height >= cu->cb_width)) ? 0 : 1; |
466 |
2/2✓ Branch 0 taken 15033 times.
✓ Branch 1 taken 10582 times.
|
25615 | const int sign = angle_idx < 16 ? 1 : -1; |
467 | 25615 | const int block_size = 4; | |
468 | 25615 | int offset_x = (-cu->cb_width) >> 1; | |
469 | 25615 | int offset_y = (-cu->cb_height) >> 1; | |
470 | |||
471 |
2/2✓ Branch 0 taken 17679 times.
✓ Branch 1 taken 7936 times.
|
25615 | if (!shift_hor) |
472 | 17679 | offset_y += sign * ((distance_idx * cu->cb_height) >> 3); | |
473 | else | ||
474 | 7936 | offset_x += sign * ((distance_idx * cu->cb_width) >> 3); | |
475 | |||
476 |
2/2✓ Branch 0 taken 115142 times.
✓ Branch 1 taken 25615 times.
|
140757 | for (int y = 0; y < cu->cb_height; y += block_size) { |
477 |
2/2✓ Branch 0 taken 534628 times.
✓ Branch 1 taken 115142 times.
|
649770 | for (int x = 0; x < cu->cb_width; x += block_size) { |
478 | 534628 | const int motion_idx = (((x + offset_x) * (1 << 1)) + 5) * displacement_x + | |
479 | 534628 | (((y + offset_y) * (1 << 1)) + 5) * displacement_y; | |
480 |
6/6✓ Branch 0 taken 267838 times.
✓ Branch 1 taken 266790 times.
✓ Branch 2 taken 162504 times.
✓ Branch 3 taken 105334 times.
✓ Branch 4 taken 266790 times.
✓ Branch 5 taken 162504 times.
|
534628 | const int s_type = FFABS(motion_idx) < 32 ? 2 : (motion_idx <= 0 ? (1 - is_flip) : is_flip); |
481 | 534628 | const int pred_flag = pu->gpm_mv[0].pred_flag | pu->gpm_mv[1].pred_flag; | |
482 | 534628 | const int x0 = cu->x0 + x; | |
483 | 534628 | const int y0 = cu->y0 + y; | |
484 | |||
485 |
2/2✓ Branch 0 taken 208313 times.
✓ Branch 1 taken 326315 times.
|
534628 | if (!s_type) |
486 | 208313 | ff_vvc_set_mvf(lc, x0, y0, block_size, block_size, pu->gpm_mv + 0); | |
487 |
5/6✓ Branch 0 taken 105334 times.
✓ Branch 1 taken 220981 times.
✓ Branch 2 taken 105334 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 56236 times.
✓ Branch 5 taken 49098 times.
|
326315 | else if (s_type == 1 || (s_type == 2 && pred_flag != PF_BI)) |
488 | 277217 | ff_vvc_set_mvf(lc, x0, y0, block_size, block_size, pu->gpm_mv + 1); | |
489 | else { | ||
490 | 49098 | MvField mvf = pu->gpm_mv[0]; | |
491 | 49098 | const MvField *mv1 = &pu->gpm_mv[1]; | |
492 | 49098 | const int lx = mv1->pred_flag - PF_L0; | |
493 | 49098 | mvf.pred_flag = PF_BI; | |
494 | 49098 | mvf.ref_idx[lx] = mv1->ref_idx[lx]; | |
495 | 49098 | mvf.mv[lx] = mv1->mv[lx]; | |
496 | 49098 | ff_vvc_set_mvf(lc, x0, y0, block_size, block_size, &mvf); | |
497 | } | ||
498 | } | ||
499 | } | ||
500 | 25615 | } | |
501 | |||
502 | 273411 | void ff_vvc_store_mvf(const VVCLocalContext *lc, const MvField *mvf) | |
503 | { | ||
504 | 273411 | const CodingUnit *cu = lc->cu; | |
505 | 273411 | ff_vvc_set_mvf(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height, mvf); | |
506 | 273411 | } | |
507 | |||
508 | 96186 | void ff_vvc_store_mv(const VVCLocalContext *lc, const MotionInfo *mi) | |
509 | { | ||
510 | 96186 | const CodingUnit *cu = lc->cu; | |
511 | 96186 | MvField mvf = {0}; | |
512 | |||
513 | 96186 | mvf.hpel_if_idx = mi->hpel_if_idx; | |
514 | 96186 | mvf.bcw_idx = mi->bcw_idx; | |
515 | 96186 | mvf.pred_flag = mi->pred_flag; | |
516 | |||
517 |
2/2✓ Branch 0 taken 192372 times.
✓ Branch 1 taken 96186 times.
|
288558 | for (int i = 0; i < 2; i++) { |
518 | 192372 | const PredFlag mask = i + 1; | |
519 |
2/2✓ Branch 0 taken 114541 times.
✓ Branch 1 taken 77831 times.
|
192372 | if (mvf.pred_flag & mask) { |
520 | 114541 | mvf.mv[i] = mi->mv[i][0]; | |
521 | 114541 | mvf.ref_idx[i] = mi->ref_idx[i]; | |
522 | } | ||
523 | } | ||
524 | 96186 | ff_vvc_set_mvf(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height, &mvf); | |
525 | 96186 | } | |
526 | |||
527 | typedef enum NeighbourIdx { | ||
528 | A0, | ||
529 | A1, | ||
530 | A2, | ||
531 | B0, | ||
532 | B1, | ||
533 | B2, | ||
534 | B3, | ||
535 | NUM_NBS, | ||
536 | NB_IDX_NONE = NUM_NBS, | ||
537 | } NeighbourIdx; | ||
538 | |||
539 | typedef struct Neighbour { | ||
540 | int x; | ||
541 | int y; | ||
542 | |||
543 | int checked; | ||
544 | int available; | ||
545 | } Neighbour; | ||
546 | |||
547 | typedef struct NeighbourContext { | ||
548 | Neighbour neighbours[NUM_NBS]; | ||
549 | const VVCLocalContext *lc; | ||
550 | } NeighbourContext; | ||
551 | |||
552 | 1305319 | static int is_available(const VVCFrameContext *fc, const int x0, const int y0) | |
553 | { | ||
554 | 1305319 | const VVCSPS *sps = fc->ps.sps; | |
555 | 1305319 | const int x = x0 >> sps->min_cb_log2_size_y; | |
556 | 1305319 | const int y = y0 >> sps->min_cb_log2_size_y; | |
557 | 1305319 | const int min_cb_width = fc->ps.pps->min_cb_width; | |
558 | |||
559 | 1305319 | return SAMPLE_CTB(fc->tab.cb_width[0], x, y) != 0; | |
560 | } | ||
561 | |||
562 | 458240 | static int is_a0_available(const VVCLocalContext *lc, const CodingUnit *cu) | |
563 | { | ||
564 | 458240 | const VVCFrameContext *fc = lc->fc; | |
565 | 458240 | const VVCSPS *sps = fc->ps.sps; | |
566 | 458240 | const int x0b = av_zero_extend(cu->x0, sps->ctb_log2_size_y); | |
567 | int cand_bottom_left; | ||
568 | |||
569 |
4/4✓ Branch 0 taken 99484 times.
✓ Branch 1 taken 358756 times.
✓ Branch 2 taken 14751 times.
✓ Branch 3 taken 84733 times.
|
458240 | if (!x0b && !lc->ctb_left_flag) { |
570 | 14751 | cand_bottom_left = 0; | |
571 | } else { | ||
572 | 443489 | const int max_y = FFMIN(fc->ps.pps->height, ((cu->y0 >> sps->ctb_log2_size_y) + 1) << sps->ctb_log2_size_y); | |
573 |
2/2✓ Branch 0 taken 92400 times.
✓ Branch 1 taken 351089 times.
|
443489 | if (cu->y0 + cu->cb_height >= max_y) |
574 | 92400 | cand_bottom_left = 0; | |
575 | else | ||
576 | 351089 | cand_bottom_left = is_available(fc, cu->x0 - 1, cu->y0 + cu->cb_height); | |
577 | } | ||
578 | 458240 | return cand_bottom_left; | |
579 | } | ||
580 | |||
581 | 458240 | static void init_neighbour_context(NeighbourContext *ctx, const VVCLocalContext *lc) | |
582 | { | ||
583 | 458240 | const CodingUnit *cu = lc->cu; | |
584 | 458240 | const NeighbourAvailable *na = &lc->na; | |
585 | 458240 | const int x0 = cu->x0; | |
586 | 458240 | const int y0 = cu->y0; | |
587 | 458240 | const int cb_width = cu->cb_width; | |
588 | 458240 | const int cb_height = cu->cb_height; | |
589 | 458240 | const int a0_available = is_a0_available(lc, cu); | |
590 | |||
591 | 458240 | Neighbour neighbours[NUM_NBS] = { | |
592 | 458240 | { x0 - 1, y0 + cb_height, !a0_available }, //A0 | |
593 | 458240 | { x0 - 1, y0 + cb_height - 1, !na->cand_left }, //A1 | |
594 | 458240 | { x0 - 1, y0, !na->cand_left }, //A2 | |
595 | 458240 | { x0 + cb_width, y0 - 1, !na->cand_up_right }, //B0 | |
596 | 458240 | { x0 + cb_width - 1, y0 - 1, !na->cand_up }, //B1 | |
597 | 458240 | { x0 - 1, y0 - 1, !na->cand_up_left }, //B2 | |
598 | 458240 | { x0, y0 - 1, !na->cand_up }, //B3 | |
599 | }; | ||
600 | |||
601 | 458240 | memcpy(ctx->neighbours, neighbours, sizeof(neighbours)); | |
602 | 458240 | ctx->lc = lc; | |
603 | 458240 | } | |
604 | |||
605 | 907066 | static av_always_inline PredMode pred_flag_to_mode(PredFlag pred) | |
606 | { | ||
607 | static const PredMode lut[] = { | ||
608 | MODE_INTRA, // PF_INTRA | ||
609 | MODE_INTER, // PF_L0 | ||
610 | MODE_INTER, // PF_L1 | ||
611 | MODE_INTER, // PF_BI | ||
612 | 0, // invalid | ||
613 | MODE_IBC, // PF_IBC | ||
614 | 0, // invalid | ||
615 | 0, // invalid | ||
616 | MODE_PLT, // PF_PLT | ||
617 | }; | ||
618 | |||
619 | 907066 | return lut[pred]; | |
620 | } | ||
621 | |||
622 | 1240586 | static int check_available(Neighbour *n, const VVCLocalContext *lc, const int check_mer) | |
623 | { | ||
624 | 1240586 | const VVCFrameContext *fc = lc->fc; | |
625 | 1240586 | const VVCSPS *sps = fc->ps.sps; | |
626 | 1240586 | const CodingUnit *cu = lc->cu; | |
627 | 1240586 | const MvField *tab_mvf = fc->tab.mvf; | |
628 | 1240586 | const int min_pu_width = fc->ps.pps->min_pu_width; | |
629 | |||
630 |
2/2✓ Branch 0 taken 954430 times.
✓ Branch 1 taken 286156 times.
|
1240586 | if (!n->checked) { |
631 | 954430 | n->checked = 1; | |
632 |
4/4✓ Branch 0 taken 87906 times.
✓ Branch 1 taken 866524 times.
✓ Branch 2 taken 87706 times.
✓ Branch 3 taken 200 times.
|
954430 | n->available = !sps->r->sps_entropy_coding_sync_enabled_flag || ((n->x >> sps->ctb_log2_size_y) <= (cu->x0 >> sps->ctb_log2_size_y)); |
633 |
6/6✓ Branch 0 taken 954230 times.
✓ Branch 1 taken 200 times.
✓ Branch 3 taken 907066 times.
✓ Branch 4 taken 47164 times.
✓ Branch 6 taken 810137 times.
✓ Branch 7 taken 96929 times.
|
954430 | n->available = n->available && is_available(fc, n->x, n->y) && cu->pred_mode == pred_flag_to_mode(TAB_MVF(n->x, n->y).pred_flag); |
634 |
2/2✓ Branch 0 taken 699451 times.
✓ Branch 1 taken 254979 times.
|
954430 | if (check_mer) |
635 |
4/4✓ Branch 0 taken 629997 times.
✓ Branch 1 taken 69454 times.
✓ Branch 3 taken 623805 times.
✓ Branch 4 taken 6192 times.
|
699451 | n->available = n->available && !is_same_mer(fc, n->x, n->y, cu->x0, cu->y0); |
636 | } | ||
637 | 1240586 | return n->available; | |
638 | } | ||
639 | |||
640 | 526431 | static const MvField *mv_merge_candidate(const VVCLocalContext *lc, const int x_cand, const int y_cand) | |
641 | { | ||
642 | 526431 | const VVCFrameContext *fc = lc->fc; | |
643 | 526431 | const int min_pu_width = fc->ps.pps->min_pu_width; | |
644 | 526431 | const MvField* tab_mvf = fc->tab.mvf; | |
645 | 526431 | const MvField *mvf = &TAB_MVF(x_cand, y_cand); | |
646 | |||
647 | 526431 | return mvf; | |
648 | } | ||
649 | |||
650 | 669541 | static const MvField* mv_merge_from_nb(NeighbourContext *ctx, const NeighbourIdx nb) | |
651 | { | ||
652 | 669541 | const VVCLocalContext *lc = ctx->lc; | |
653 | 669541 | Neighbour *n = &ctx->neighbours[nb]; | |
654 | |||
655 |
2/2✓ Branch 1 taken 526431 times.
✓ Branch 2 taken 143110 times.
|
669541 | if (check_available(n, lc, 1)) |
656 | 526431 | return mv_merge_candidate(lc, n->x, n->y); | |
657 | 143110 | return 0; | |
658 | } | ||
659 | #define MV_MERGE_FROM_NB(nb) mv_merge_from_nb(&nctx, nb) | ||
660 | |||
661 | //8.5.2.3 Derivation process for spatial merging candidates | ||
662 | 299026 | static int mv_merge_spatial_candidates(const VVCLocalContext *lc, const int merge_idx, | |
663 | const MvField **nb_list, MvField *cand_list, int *nb_merge_cand) | ||
664 | { | ||
665 | const MvField *cand; | ||
666 | 299026 | int num_cands = 0; | |
667 | NeighbourContext nctx; | ||
668 | |||
669 | static NeighbourIdx nbs[][2] = { | ||
670 | {B1, NB_IDX_NONE }, | ||
671 | {A1, B1 }, | ||
672 | {B0, B1 }, | ||
673 | {A0, A1 }, | ||
674 | }; | ||
675 | |||
676 | 299026 | init_neighbour_context(&nctx, lc); | |
677 |
2/2✓ Branch 0 taken 604840 times.
✓ Branch 1 taken 65371 times.
|
670211 | for (int i = 0; i < FF_ARRAY_ELEMS(nbs); i++) { |
678 | 604840 | NeighbourIdx nb = nbs[i][0]; | |
679 | 604840 | NeighbourIdx old = nbs[i][1]; | |
680 | 604840 | cand = nb_list[nb] = MV_MERGE_FROM_NB(nb); | |
681 |
4/4✓ Branch 0 taken 475502 times.
✓ Branch 1 taken 129338 times.
✓ Branch 3 taken 429048 times.
✓ Branch 4 taken 46454 times.
|
604840 | if (cand && !compare_mv_ref_idx(cand, nb_list[old])) { |
682 | 429048 | cand_list[num_cands] = *cand; | |
683 |
2/2✓ Branch 0 taken 233655 times.
✓ Branch 1 taken 195393 times.
|
429048 | if (merge_idx == num_cands) |
684 | 233655 | return 1; | |
685 | 195393 | num_cands++; | |
686 | } | ||
687 | } | ||
688 |
2/2✓ Branch 0 taken 64701 times.
✓ Branch 1 taken 670 times.
|
65371 | if (num_cands != 4) { |
689 | 64701 | cand = MV_MERGE_FROM_NB(B2); | |
690 |
4/4✓ Branch 0 taken 50929 times.
✓ Branch 1 taken 13772 times.
✓ Branch 3 taken 30808 times.
✓ Branch 4 taken 20121 times.
|
64701 | if (cand && !compare_mv_ref_idx(cand, nb_list[A1]) |
691 |
2/2✓ Branch 1 taken 21848 times.
✓ Branch 2 taken 8960 times.
|
30808 | && !compare_mv_ref_idx(cand, nb_list[B1])) { |
692 | 21848 | cand_list[num_cands] = *cand; | |
693 |
2/2✓ Branch 0 taken 9748 times.
✓ Branch 1 taken 12100 times.
|
21848 | if (merge_idx == num_cands) |
694 | 9748 | return 1; | |
695 | 12100 | num_cands++; | |
696 | } | ||
697 | } | ||
698 | 55623 | *nb_merge_cand = num_cands; | |
699 | 55623 | return 0; | |
700 | } | ||
701 | |||
702 | 55623 | static int mv_merge_temporal_candidate(const VVCLocalContext *lc, MvField *cand) | |
703 | { | ||
704 | 55623 | const VVCFrameContext *fc = lc->fc; | |
705 | 55623 | const CodingUnit *cu = lc->cu; | |
706 | |||
707 | 55623 | memset(cand, 0, sizeof(*cand)); | |
708 |
4/4✓ Branch 0 taken 55476 times.
✓ Branch 1 taken 147 times.
✓ Branch 2 taken 51853 times.
✓ Branch 3 taken 3623 times.
|
55623 | if (fc->ps.ph.r->ph_temporal_mvp_enabled_flag && (cu->cb_width * cu->cb_height > 32)) { |
709 | 51853 | int available_l0 = temporal_luma_motion_vector(lc, 0, cand->mv + 0, 0, 1, 0); | |
710 | 103706 | int available_l1 = IS_B(lc->sc->sh.r) ? | |
711 |
2/2✓ Branch 0 taken 49064 times.
✓ Branch 1 taken 2789 times.
|
51853 | temporal_luma_motion_vector(lc, 0, cand->mv + 1, 1, 1, 0) : 0; |
712 | 51853 | cand->pred_flag = available_l0 + (available_l1 << 1); | |
713 | } | ||
714 | 55623 | return cand->pred_flag; | |
715 | } | ||
716 | |||
717 | //8.5.2.6 Derivation process for history-based merging candidates | ||
718 | 35237 | static int mv_merge_history_candidates(const VVCLocalContext *lc, const int merge_idx, | |
719 | const MvField **nb_list, MvField *cand_list, int *num_cands) | ||
720 | { | ||
721 | 35237 | const VVCSPS *sps = lc->fc->ps.sps; | |
722 | 35237 | const EntryPoint* ep = lc->ep; | |
723 |
4/4✓ Branch 0 taken 90135 times.
✓ Branch 1 taken 2704 times.
✓ Branch 2 taken 81538 times.
✓ Branch 3 taken 8597 times.
|
92839 | for (int i = 1; i <= ep->num_hmvp && (*num_cands < sps->max_num_merge_cand - 1); i++) { |
724 | 81538 | const MvField *h = &ep->hmvp[ep->num_hmvp - i]; | |
725 |
6/6✓ Branch 0 taken 59969 times.
✓ Branch 1 taken 21569 times.
✓ Branch 3 taken 41301 times.
✓ Branch 4 taken 18668 times.
✓ Branch 6 taken 10171 times.
✓ Branch 7 taken 31130 times.
|
81538 | const int same_motion = i <= 2 && (compare_mv_ref_idx(h, nb_list[A1]) || compare_mv_ref_idx(h, nb_list[B1])); |
726 |
2/2✓ Branch 0 taken 52699 times.
✓ Branch 1 taken 28839 times.
|
81538 | if (!same_motion) { |
727 | 52699 | cand_list[*num_cands] = *h; | |
728 |
2/2✓ Branch 0 taken 23936 times.
✓ Branch 1 taken 28763 times.
|
52699 | if (merge_idx == *num_cands) |
729 | 23936 | return 1; | |
730 | 28763 | (*num_cands)++; | |
731 | } | ||
732 | } | ||
733 | 11301 | return 0; | |
734 | } | ||
735 | |||
736 | //8.5.2.4 Derivation process for pairwise average merging candidate | ||
737 | 11301 | static int mv_merge_pairwise_candidate(MvField *cand_list, const int num_cands, const int is_b) | |
738 | { | ||
739 |
2/2✓ Branch 0 taken 10499 times.
✓ Branch 1 taken 802 times.
|
11301 | if (num_cands > 1) { |
740 |
2/2✓ Branch 0 taken 9975 times.
✓ Branch 1 taken 524 times.
|
10499 | const int num_ref_rists = is_b ? 2 : 1; |
741 | 10499 | const MvField* p0 = cand_list + 0; | |
742 | 10499 | const MvField* p1 = cand_list + 1; | |
743 | 10499 | MvField* cand = cand_list + num_cands; | |
744 | |||
745 | 10499 | cand->pred_flag = 0; | |
746 |
2/2✓ Branch 0 taken 20474 times.
✓ Branch 1 taken 10499 times.
|
30973 | for (int i = 0; i < num_ref_rists; i++) { |
747 | 20474 | PredFlag mask = i + 1; | |
748 |
2/2✓ Branch 0 taken 16838 times.
✓ Branch 1 taken 3636 times.
|
20474 | if (p0->pred_flag & mask) { |
749 | 16838 | cand->pred_flag |= mask; | |
750 | 16838 | cand->ref_idx[i] = p0->ref_idx[i]; | |
751 |
2/2✓ Branch 0 taken 14930 times.
✓ Branch 1 taken 1908 times.
|
16838 | if (p1->pred_flag & mask) { |
752 | 14930 | Mv *mv = cand->mv + i; | |
753 | 14930 | mv->x = p0->mv[i].x + p1->mv[i].x; | |
754 | 14930 | mv->y = p0->mv[i].y + p1->mv[i].y; | |
755 | 14930 | ff_vvc_round_mv(mv, 0, 1); | |
756 | } else { | ||
757 | 1908 | cand->mv[i] = p0->mv[i]; | |
758 | } | ||
759 |
2/2✓ Branch 0 taken 2170 times.
✓ Branch 1 taken 1466 times.
|
3636 | } else if (p1->pred_flag & mask) { |
760 | 2170 | cand->pred_flag |= mask; | |
761 | 2170 | cand->mv[i] = p1->mv[i]; | |
762 | 2170 | cand->ref_idx[i] = p1->ref_idx[i]; | |
763 | } | ||
764 | } | ||
765 |
1/2✓ Branch 0 taken 10499 times.
✗ Branch 1 not taken.
|
10499 | if (cand->pred_flag) { |
766 |
2/2✓ Branch 0 taken 9739 times.
✓ Branch 1 taken 760 times.
|
10499 | cand->hpel_if_idx = p0->hpel_if_idx == p1->hpel_if_idx ? p0->hpel_if_idx : 0; |
767 | 10499 | cand->bcw_idx = 0; | |
768 | 10499 | cand->ciip_flag = 0; | |
769 | 10499 | return 1; | |
770 | } | ||
771 | } | ||
772 | 802 | return 0; | |
773 | } | ||
774 | |||
775 | //8.5.2.5 Derivation process for zero motion vector merging candidates | ||
776 | 1353 | static void mv_merge_zero_motion_candidate(const VVCLocalContext *lc, const int merge_idx, | |
777 | MvField *cand_list, int num_cands) | ||
778 | { | ||
779 | 1353 | const VVCSPS *sps = lc->fc->ps.sps; | |
780 | 1353 | const H266RawSliceHeader *rsh = lc->sc->sh.r; | |
781 | 2706 | const int num_ref_idx = IS_P(rsh) ? | |
782 |
2/2✓ Branch 0 taken 210 times.
✓ Branch 1 taken 1143 times.
|
1353 | rsh->num_ref_idx_active[L0] : FFMIN(rsh->num_ref_idx_active[L0], rsh->num_ref_idx_active[L1]); |
783 | 1353 | int zero_idx = 0; | |
784 | |||
785 |
1/2✓ Branch 0 taken 2727 times.
✗ Branch 1 not taken.
|
2727 | while (num_cands < sps->max_num_merge_cand) { |
786 | 2727 | MvField *cand = cand_list + num_cands; | |
787 | |||
788 |
2/2✓ Branch 0 taken 2290 times.
✓ Branch 1 taken 437 times.
|
2727 | cand->pred_flag = PF_L0 + (IS_B(rsh) << 1); |
789 | 2727 | AV_ZERO64(cand->mv + 0); | |
790 | 2727 | AV_ZERO64(cand->mv + 1); | |
791 |
2/2✓ Branch 0 taken 2494 times.
✓ Branch 1 taken 233 times.
|
2727 | cand->ref_idx[0] = zero_idx < num_ref_idx ? zero_idx : 0; |
792 |
2/2✓ Branch 0 taken 2494 times.
✓ Branch 1 taken 233 times.
|
2727 | cand->ref_idx[1] = zero_idx < num_ref_idx ? zero_idx : 0; |
793 | 2727 | cand->bcw_idx = 0; | |
794 | 2727 | cand->hpel_if_idx = 0; | |
795 |
2/2✓ Branch 0 taken 1353 times.
✓ Branch 1 taken 1374 times.
|
2727 | if (merge_idx == num_cands) |
796 | 1353 | return; | |
797 | 1374 | num_cands++; | |
798 | 1374 | zero_idx++; | |
799 | } | ||
800 | } | ||
801 | |||
802 | 299026 | static void mv_merge_mode(const VVCLocalContext *lc, const int merge_idx, MvField *cand_list) | |
803 | { | ||
804 | 299026 | int num_cands = 0; | |
805 | 299026 | const MvField *nb_list[NUM_NBS + 1] = { NULL }; | |
806 | |||
807 |
2/2✓ Branch 1 taken 243403 times.
✓ Branch 2 taken 55623 times.
|
299026 | if (mv_merge_spatial_candidates(lc, merge_idx, nb_list, cand_list, &num_cands)) |
808 | 297673 | return; | |
809 | |||
810 |
2/2✓ Branch 1 taken 42428 times.
✓ Branch 2 taken 13195 times.
|
55623 | if (mv_merge_temporal_candidate(lc, &cand_list[num_cands])) { |
811 |
2/2✓ Branch 0 taken 20386 times.
✓ Branch 1 taken 22042 times.
|
42428 | if (merge_idx == num_cands) |
812 | 20386 | return; | |
813 | 22042 | num_cands++; | |
814 | } | ||
815 | |||
816 |
2/2✓ Branch 1 taken 23936 times.
✓ Branch 2 taken 11301 times.
|
35237 | if (mv_merge_history_candidates(lc, merge_idx, nb_list, cand_list, &num_cands)) |
817 | 23936 | return; | |
818 | |||
819 |
2/2✓ Branch 1 taken 10499 times.
✓ Branch 2 taken 802 times.
|
11301 | if (mv_merge_pairwise_candidate(cand_list, num_cands, IS_B(lc->sc->sh.r))) { |
820 |
2/2✓ Branch 0 taken 9948 times.
✓ Branch 1 taken 551 times.
|
10499 | if (merge_idx == num_cands) |
821 | 9948 | return; | |
822 | 551 | num_cands++; | |
823 | } | ||
824 | |||
825 | 1353 | mv_merge_zero_motion_candidate(lc, merge_idx, cand_list, num_cands); | |
826 | } | ||
827 | |||
828 | //8.5.2.2 Derivation process for luma motion vectors for merge mode | ||
829 | 273411 | void ff_vvc_luma_mv_merge_mode(VVCLocalContext *lc, const int merge_idx, const int ciip_flag, MvField *mv) | |
830 | { | ||
831 | 273411 | const CodingUnit *cu = lc->cu; | |
832 | MvField cand_list[MRG_MAX_NUM_CANDS]; | ||
833 | |||
834 | 273411 | ff_vvc_set_neighbour_available(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height); | |
835 | 273411 | mv_merge_mode(lc, merge_idx, cand_list); | |
836 | 273411 | *mv = cand_list[merge_idx]; | |
837 | //ciip flag in not inhritable | ||
838 | 273411 | mv->ciip_flag = ciip_flag; | |
839 | 273411 | } | |
840 | |||
841 | //8.5.4.2 Derivation process for luma motion vectors for geometric partitioning merge mode | ||
842 | 25615 | void ff_vvc_luma_mv_merge_gpm(VVCLocalContext *lc, const int merge_gpm_idx[2], MvField *mv) | |
843 | { | ||
844 | 25615 | const CodingUnit *cu = lc->cu; | |
845 | MvField cand_list[MRG_MAX_NUM_CANDS]; | ||
846 | |||
847 | 25615 | const int idx[] = { merge_gpm_idx[0], merge_gpm_idx[1] + (merge_gpm_idx[1] >= merge_gpm_idx[0]) }; | |
848 | |||
849 | 25615 | ff_vvc_set_neighbour_available(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height); | |
850 | 25615 | mv_merge_mode(lc, FFMAX(idx[0], idx[1]), cand_list); | |
851 | 25615 | memset(mv, 0, 2 * sizeof(*mv)); | |
852 |
2/2✓ Branch 0 taken 51230 times.
✓ Branch 1 taken 25615 times.
|
76845 | for (int i = 0; i < 2; i++) { |
853 | 51230 | int lx = idx[i] & 1; | |
854 | 51230 | int mask = lx + PF_L0; | |
855 | 51230 | MvField *cand = cand_list + idx[i]; | |
856 |
2/2✓ Branch 0 taken 13878 times.
✓ Branch 1 taken 37352 times.
|
51230 | if (!(cand->pred_flag & mask)) { |
857 | 13878 | lx = !lx; | |
858 | 13878 | mask = lx + PF_L0; | |
859 | } | ||
860 | 51230 | mv[i].pred_flag = mask; | |
861 | 51230 | mv[i].ref_idx[lx] = cand->ref_idx[lx]; | |
862 | 51230 | mv[i].mv[lx] = cand->mv[lx]; | |
863 | } | ||
864 | |||
865 | 25615 | } | |
866 | |||
867 | //8.5.5.5 Derivation process for luma affine control point motion vectors from a neighbouring block | ||
868 | 29163 | static void affine_cps_from_nb(const VVCLocalContext *lc, | |
869 | const int x_nb, int y_nb, const int nbw, const int nbh, const int lx, | ||
870 | Mv *cps, int num_cps) | ||
871 | { | ||
872 | 29163 | const VVCFrameContext *fc = lc->fc; | |
873 | 29163 | const CodingUnit *cu = lc->cu; | |
874 | 29163 | const int x0 = cu->x0; | |
875 | 29163 | const int y0 = cu->y0; | |
876 | 29163 | const int cb_width = cu->cb_width; | |
877 | 29163 | const int cb_height = cu->cb_height; | |
878 | 29163 | const MvField* tab_mvf = fc->tab.mvf; | |
879 | 29163 | const int min_cb_log2_size = fc->ps.sps->min_cb_log2_size_y; | |
880 | 29163 | const int min_cb_width = fc->ps.pps->min_cb_width; | |
881 | |||
882 | 29163 | const int log2_nbw = ff_log2(nbw); | |
883 | 29163 | const int log2_nbh = ff_log2(nbh); | |
884 |
4/4✓ Branch 0 taken 8724 times.
✓ Branch 1 taken 20439 times.
✓ Branch 2 taken 3398 times.
✓ Branch 3 taken 5326 times.
|
29163 | const int is_ctb_boundary = !((y_nb + nbh) % fc->ps.sps->ctb_size_y) && (y_nb + nbh == y0); |
885 | const Mv *l, *r; | ||
886 | int mv_scale_hor, mv_scale_ver, d_hor_x, d_ver_x, d_hor_y, d_ver_y, motion_model_idc_nb; | ||
887 |
2/2✓ Branch 0 taken 3398 times.
✓ Branch 1 taken 25765 times.
|
29163 | if (is_ctb_boundary) { |
888 | 3398 | const int min_pu_width = fc->ps.pps->min_pu_width; | |
889 | 3398 | l = &TAB_MVF(x_nb, y_nb + nbh - 1).mv[lx]; | |
890 | 3398 | r = &TAB_MVF(x_nb + nbw - 1, y_nb + nbh - 1).mv[lx]; | |
891 | } else { | ||
892 | 25765 | const int x = x_nb >> min_cb_log2_size; | |
893 | 25765 | const int y = y_nb >> min_cb_log2_size; | |
894 | 25765 | motion_model_idc_nb = SAMPLE_CTB(fc->tab.mmi, x, y); | |
895 | |||
896 | 25765 | l = &TAB_CP_MV(lx, x_nb, y_nb); | |
897 | 25765 | r = &TAB_CP_MV(lx, x_nb + nbw - 1, y_nb) + 1; | |
898 | } | ||
899 | 29163 | mv_scale_hor = l->x * (1 << 7); | |
900 | 29163 | mv_scale_ver = l->y * (1 << 7); | |
901 | 29163 | d_hor_x = (r->x - l->x) * (1 << (7 - log2_nbw)); | |
902 | 29163 | d_ver_x = (r->y - l->y) * (1 << (7 - log2_nbw)); | |
903 |
4/4✓ Branch 0 taken 25765 times.
✓ Branch 1 taken 3398 times.
✓ Branch 2 taken 14644 times.
✓ Branch 3 taken 11121 times.
|
29163 | if (!is_ctb_boundary && motion_model_idc_nb == MOTION_6_PARAMS_AFFINE) { |
904 | 14644 | const Mv* lb = &TAB_CP_MV(lx, x_nb, y_nb + nbh - 1) + 2; | |
905 | 14644 | d_hor_y = (lb->x - l->x) * (1 << (7 - log2_nbh)); | |
906 | 14644 | d_ver_y = (lb->y - l->y) * (1 << (7 - log2_nbh)); | |
907 | } else { | ||
908 | 14519 | d_hor_y = -d_ver_x; | |
909 | 14519 | d_ver_y = d_hor_x; | |
910 | } | ||
911 | |||
912 |
2/2✓ Branch 0 taken 3398 times.
✓ Branch 1 taken 25765 times.
|
29163 | if (is_ctb_boundary) { |
913 | 3398 | y_nb = y0; | |
914 | } | ||
915 | 29163 | cps[0].x = mv_scale_hor + d_hor_x * (x0 - x_nb) + d_hor_y * (y0 - y_nb); | |
916 | 29163 | cps[0].y = mv_scale_ver + d_ver_x * (x0 - x_nb) + d_ver_y * (y0 - y_nb); | |
917 | 29163 | cps[1].x = mv_scale_hor + d_hor_x * (x0 + cb_width - x_nb) + d_hor_y * (y0 - y_nb); | |
918 | 29163 | cps[1].y = mv_scale_ver + d_ver_x * (x0 + cb_width - x_nb) + d_ver_y * (y0 - y_nb); | |
919 |
2/2✓ Branch 0 taken 16185 times.
✓ Branch 1 taken 12978 times.
|
29163 | if (num_cps == 3) { |
920 | 16185 | cps[2].x = mv_scale_hor + d_hor_x * (x0 - x_nb) + d_hor_y * (y0 + cb_height - y_nb); | |
921 | 16185 | cps[2].y = mv_scale_ver + d_ver_x * (x0 - x_nb) + d_ver_y * (y0 + cb_height - y_nb); | |
922 | } | ||
923 |
2/2✓ Branch 0 taken 74511 times.
✓ Branch 1 taken 29163 times.
|
103674 | for (int i = 0; i < num_cps; i++) { |
924 | 74511 | ff_vvc_round_mv(cps + i, 0, 7); | |
925 | 74511 | ff_vvc_clip_mv(cps + i); | |
926 | } | ||
927 | 29163 | } | |
928 | |||
929 | //derive affine neighbour's postion, width and height, | ||
930 | 92967 | static int affine_neighbour_cb(const VVCFrameContext *fc, const int x_nb, const int y_nb, int *x_cb, int *y_cb, int *cbw, int *cbh) | |
931 | { | ||
932 | 92967 | const int log2_min_cb_size = fc->ps.sps->min_cb_log2_size_y; | |
933 | 92967 | const int min_cb_width = fc->ps.pps->min_cb_width; | |
934 | 92967 | const int x = x_nb >> log2_min_cb_size; | |
935 | 92967 | const int y = y_nb >> log2_min_cb_size; | |
936 | 92967 | const int motion_model_idc = SAMPLE_CTB(fc->tab.mmi, x, y); | |
937 |
2/2✓ Branch 0 taken 26328 times.
✓ Branch 1 taken 66639 times.
|
92967 | if (motion_model_idc) { |
938 | 26328 | *x_cb = SAMPLE_CTB(fc->tab.cb_pos_x[0], x, y); | |
939 | 26328 | *y_cb = SAMPLE_CTB(fc->tab.cb_pos_y[0], x, y); | |
940 | 26328 | *cbw = SAMPLE_CTB(fc->tab.cb_width[0], x, y); | |
941 | 26328 | *cbh = SAMPLE_CTB(fc->tab.cb_height[0], x, y); | |
942 | } | ||
943 | 92967 | return motion_model_idc; | |
944 | } | ||
945 | |||
946 | //part of 8.5.5.2 Derivation process for motion vectors and reference indices in subblock merge mode | ||
947 | 63288 | static int affine_merge_candidate(const VVCLocalContext *lc, const int x_cand, const int y_cand, MotionInfo* mi) | |
948 | { | ||
949 | 63288 | const VVCFrameContext *fc = lc->fc; | |
950 | int x, y, w, h, motion_model_idc; | ||
951 | |||
952 | 63288 | motion_model_idc = affine_neighbour_cb(fc, x_cand, y_cand, &x, &y, &w, &h); | |
953 |
2/2✓ Branch 0 taken 18839 times.
✓ Branch 1 taken 44449 times.
|
63288 | if (motion_model_idc) { |
954 | 18839 | const int min_pu_width = fc->ps.pps->min_pu_width; | |
955 | 18839 | const MvField* tab_mvf = fc->tab.mvf; | |
956 | 18839 | const MvField *mvf = &TAB_MVF(x, y); | |
957 | |||
958 | 18839 | mi->bcw_idx = mvf->bcw_idx; | |
959 | 18839 | mi->pred_flag = mvf->pred_flag; | |
960 |
2/2✓ Branch 0 taken 37678 times.
✓ Branch 1 taken 18839 times.
|
56517 | for (int i = 0; i < 2; i++) { |
961 | 37678 | PredFlag mask = i + 1; | |
962 |
2/2✓ Branch 0 taken 23264 times.
✓ Branch 1 taken 14414 times.
|
37678 | if (mi->pred_flag & mask) { |
963 | 23264 | affine_cps_from_nb(lc, x, y, w, h, i, &mi->mv[i][0], motion_model_idc + 1); | |
964 | } | ||
965 | 37678 | mi->ref_idx[i] = mvf->ref_idx[i]; | |
966 | } | ||
967 | 18839 | mi->motion_model_idc = motion_model_idc; | |
968 | } | ||
969 | 63288 | return motion_model_idc; | |
970 | } | ||
971 | |||
972 | 44229 | static int affine_merge_from_nbs(NeighbourContext *ctx, const NeighbourIdx *nbs, const int num_nbs, MotionInfo* cand) | |
973 | { | ||
974 | 44229 | const VVCLocalContext *lc = ctx->lc; | |
975 |
2/2✓ Branch 0 taken 93127 times.
✓ Branch 1 taken 25390 times.
|
118517 | for (int i = 0; i < num_nbs; i++) { |
976 | 93127 | Neighbour *n = &ctx->neighbours[nbs[i]]; | |
977 |
4/4✓ Branch 1 taken 63288 times.
✓ Branch 2 taken 29839 times.
✓ Branch 4 taken 18839 times.
✓ Branch 5 taken 44449 times.
|
93127 | if (check_available(n, lc, 1) && affine_merge_candidate(lc, n->x, n->y, cand)) |
978 | 18839 | return 1; | |
979 | } | ||
980 | 25390 | return 0; | |
981 | } | ||
982 | #define AFFINE_MERGE_FROM_NBS(nbs) affine_merge_from_nbs(&nctx, nbs, FF_ARRAY_ELEMS(nbs), mi) | ||
983 | |||
984 | |||
985 | 95426 | static const MvField* derive_corner_mvf(NeighbourContext *ctx, const NeighbourIdx *neighbour, const int num_neighbour) | |
986 | { | ||
987 | 95426 | const VVCFrameContext *fc = ctx->lc->fc; | |
988 | 95426 | const MvField *tab_mvf = fc->tab.mvf; | |
989 | 95426 | const int min_pu_width = fc->ps.pps->min_pu_width; | |
990 |
2/2✓ Branch 0 taken 101859 times.
✓ Branch 1 taken 7203 times.
|
109062 | for (int i = 0; i < num_neighbour; i++) { |
991 | 101859 | Neighbour *n = &ctx->neighbours[neighbour[i]]; | |
992 |
2/2✓ Branch 1 taken 88223 times.
✓ Branch 2 taken 13636 times.
|
101859 | if (check_available(n, ctx->lc, 1)) { |
993 | 88223 | return &TAB_MVF(n->x, n->y); | |
994 | } | ||
995 | } | ||
996 | 7203 | return NULL; | |
997 | } | ||
998 | |||
999 | #define DERIVE_CORNER_MV(nbs) derive_corner_mvf(nctx, nbs, FF_ARRAY_ELEMS(nbs)) | ||
1000 | |||
1001 | // check if the mv's and refidx are the same between A and B | ||
1002 | 51704 | static av_always_inline int compare_pf_ref_idx(const MvField *A, const struct MvField *B, const struct MvField *C, const int lx) | |
1003 | { | ||
1004 | |||
1005 | 51704 | const PredFlag mask = (lx + 1) & A->pred_flag; | |
1006 |
2/2✓ Branch 0 taken 18464 times.
✓ Branch 1 taken 33240 times.
|
51704 | if (!(B->pred_flag & mask)) |
1007 | 18464 | return 0; | |
1008 |
2/2✓ Branch 0 taken 1615 times.
✓ Branch 1 taken 31625 times.
|
33240 | if (A->ref_idx[lx] != B->ref_idx[lx]) |
1009 | 1615 | return 0; | |
1010 |
2/2✓ Branch 0 taken 26272 times.
✓ Branch 1 taken 5353 times.
|
31625 | if (C) { |
1011 |
2/2✓ Branch 0 taken 895 times.
✓ Branch 1 taken 25377 times.
|
26272 | if (!(C->pred_flag & mask)) |
1012 | 895 | return 0; | |
1013 |
2/2✓ Branch 0 taken 1007 times.
✓ Branch 1 taken 24370 times.
|
25377 | if (A->ref_idx[lx] != C->ref_idx[lx]) |
1014 | 1007 | return 0; | |
1015 | } | ||
1016 | 29723 | return 1; | |
1017 | } | ||
1018 | |||
1019 | 1254033 | static av_always_inline void sb_clip_location(const VVCLocalContext *lc, | |
1020 | const int x_ctb, const int y_ctb, const Mv* temp_mv, int *x, int *y) | ||
1021 | { | ||
1022 | 1254033 | const VVCFrameContext *fc = lc->fc; | |
1023 | 1254033 | const VVCPPS *pps = fc->ps.pps; | |
1024 | 1254033 | const int ctb_log2_size = fc->ps.sps->ctb_log2_size_y; | |
1025 | 1254033 | const int subpic_idx = lc->sc->sh.r->curr_subpic_idx; | |
1026 | 1254033 | const int x_end = pps->subpic_x[subpic_idx] + pps->subpic_width[subpic_idx]; | |
1027 | 1254033 | const int y_end = pps->subpic_y[subpic_idx] + pps->subpic_height[subpic_idx]; | |
1028 | |||
1029 | 1254033 | *x = av_clip(*x + temp_mv->x, x_ctb, FFMIN(x_end - 1, x_ctb + (1 << ctb_log2_size) + 3)) & ~7; | |
1030 |
2/2✓ Branch 0 taken 1109275 times.
✓ Branch 1 taken 144758 times.
|
1254033 | *y = av_clip(*y + temp_mv->y, y_ctb, FFMIN(y_end - 1, y_ctb + (1 << ctb_log2_size) - 1)) & ~7; |
1031 | 1254033 | } | |
1032 | |||
1033 | 1254033 | static void sb_temproal_luma_motion(const VVCLocalContext *lc, | |
1034 | const int x_ctb, const int y_ctb, const Mv *temp_mv, | ||
1035 | int x, int y, uint8_t *pred_flag, Mv *mv) | ||
1036 | { | ||
1037 | MvField temp_col; | ||
1038 | Mv* mvLXCol; | ||
1039 | 1254033 | const int refIdxLx = 0; | |
1040 | 1254033 | const VVCFrameContext *fc = lc->fc; | |
1041 | 1254033 | const VVCSH *sh = &lc->sc->sh; | |
1042 | 1254033 | const int min_pu_width = fc->ps.pps->min_pu_width; | |
1043 | 1254033 | VVCFrame *ref = fc->ref->collocated_ref; | |
1044 | 1254033 | MvField *tab_mvf = ref->tab_dmvr_mvf; | |
1045 | 1254033 | int colPic = ref->poc; | |
1046 | 1254033 | int X = 0; | |
1047 | |||
1048 | 1254033 | sb_clip_location(lc, x_ctb, y_ctb, temp_mv, &x, &y); | |
1049 | |||
1050 | 1254033 | temp_col = TAB_MVF(x, y); | |
1051 | 1254033 | mvLXCol = mv + 0; | |
1052 | 1254033 | *pred_flag = DERIVE_TEMPORAL_COLOCATED_MVS(1); | |
1053 |
2/2✓ Branch 0 taken 907085 times.
✓ Branch 1 taken 346948 times.
|
1254033 | if (IS_B(sh->r)) { |
1054 | 907085 | X = 1; | |
1055 | 907085 | mvLXCol = mv + 1; | |
1056 | 907085 | *pred_flag |= (DERIVE_TEMPORAL_COLOCATED_MVS(1)) << 1; | |
1057 | } | ||
1058 | 1254033 | } | |
1059 | |||
1060 | //8.5.5.4 Derivation process for subblock-based temporal merging base motion data | ||
1061 | 49901 | static int sb_temporal_luma_motion_data(const VVCLocalContext *lc, const MvField *a1, | |
1062 | const int x_ctb, const int y_ctb, MvField *ctr_mvf, Mv *temp_mv) | ||
1063 | { | ||
1064 | 49901 | const VVCFrameContext *fc = lc->fc; | |
1065 | 49901 | const RefPicList *rpl = lc->sc->rpl; | |
1066 | 49901 | const CodingUnit *cu = lc->cu; | |
1067 | 49901 | const int x = cu->x0 + cu->cb_width / 2; | |
1068 | 49901 | const int y = cu->y0 + cu->cb_height / 2; | |
1069 | 49901 | const VVCFrame *ref = fc->ref->collocated_ref; | |
1070 | |||
1071 | int colPic; | ||
1072 | |||
1073 | 49901 | memset(temp_mv, 0, sizeof(*temp_mv)); | |
1074 | |||
1075 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 49901 times.
|
49901 | if (!ref) { |
1076 | ✗ | memset(ctr_mvf, 0, sizeof(*ctr_mvf)); | |
1077 | ✗ | return 0; | |
1078 | } | ||
1079 | |||
1080 | 49901 | colPic = ref->poc; | |
1081 | |||
1082 |
2/2✓ Branch 0 taken 46448 times.
✓ Branch 1 taken 3453 times.
|
49901 | if (a1) { |
1083 |
4/4✓ Branch 0 taken 42491 times.
✓ Branch 1 taken 3957 times.
✓ Branch 2 taken 29079 times.
✓ Branch 3 taken 13412 times.
|
46448 | if ((a1->pred_flag & PF_L0) && colPic == rpl[L0].refs[a1->ref_idx[L0]].poc) |
1084 | 29079 | *temp_mv = a1->mv[0]; | |
1085 |
4/4✓ Branch 0 taken 12025 times.
✓ Branch 1 taken 5344 times.
✓ Branch 2 taken 9770 times.
✓ Branch 3 taken 2255 times.
|
17369 | else if ((a1->pred_flag & PF_L1) && colPic == rpl[L1].refs[a1->ref_idx[L1]].poc) |
1086 | 9770 | *temp_mv = a1->mv[1]; | |
1087 | 46448 | ff_vvc_round_mv(temp_mv, 0, 4); | |
1088 | } | ||
1089 | 49901 | sb_temproal_luma_motion(lc, x_ctb, y_ctb, temp_mv, x, y, &ctr_mvf->pred_flag , ctr_mvf->mv); | |
1090 | |||
1091 | 49901 | return ctr_mvf->pred_flag; | |
1092 | } | ||
1093 | |||
1094 | |||
1095 | //8.5.5.3 Derivation process for subblock-based temporal merging candidates | ||
1096 | 50089 | static int sb_temporal_merge_candidate(const VVCLocalContext* lc, NeighbourContext *nctx, PredictionUnit *pu) | |
1097 | { | ||
1098 | 50089 | const VVCFrameContext *fc = lc->fc; | |
1099 | 50089 | const CodingUnit *cu = lc->cu; | |
1100 | 50089 | const VVCSPS *sps = fc->ps.sps; | |
1101 | 50089 | const VVCPH *ph = &fc->ps.ph; | |
1102 | 50089 | MotionInfo *mi = &pu->mi; | |
1103 | 50089 | const int ctb_log2_size = sps->ctb_log2_size_y; | |
1104 | 50089 | const int x0 = cu->x0; | |
1105 | 50089 | const int y0 = cu->y0; | |
1106 | 50089 | const NeighbourIdx n = A1; | |
1107 | const MvField *a1; | ||
1108 | MvField ctr_mvf; | ||
1109 | 50089 | LOCAL_ALIGNED_8(Mv, temp_mv, [1]); | |
1110 | 50089 | const int x_ctb = (x0 >> ctb_log2_size) << ctb_log2_size; | |
1111 | 50089 | const int y_ctb = (y0 >> ctb_log2_size) << ctb_log2_size; | |
1112 | |||
1113 | |||
1114 |
2/2✓ Branch 0 taken 50002 times.
✓ Branch 1 taken 87 times.
|
50089 | if (!ph->r->ph_temporal_mvp_enabled_flag || |
1115 |
2/2✓ Branch 0 taken 49901 times.
✓ Branch 1 taken 101 times.
|
50002 | !sps->r->sps_sbtmvp_enabled_flag || |
1116 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 49901 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
49901 | (cu->cb_width < 8 && cu->cb_height < 8)) |
1117 | 188 | return 0; | |
1118 | |||
1119 | 49901 | mi->num_sb_x = cu->cb_width >> 3; | |
1120 | 49901 | mi->num_sb_y = cu->cb_height >> 3; | |
1121 | |||
1122 | 49901 | a1 = derive_corner_mvf(nctx, &n, 1); | |
1123 |
2/2✓ Branch 1 taken 41932 times.
✓ Branch 2 taken 7969 times.
|
49901 | if (sb_temporal_luma_motion_data(lc, a1, x_ctb, y_ctb, &ctr_mvf, temp_mv)) { |
1124 | 41932 | const int sbw = cu->cb_width / mi->num_sb_x; | |
1125 | 41932 | const int sbh = cu->cb_height / mi->num_sb_y; | |
1126 | 41932 | MvField mvf = {0}; | |
1127 |
2/2✓ Branch 0 taken 172498 times.
✓ Branch 1 taken 41932 times.
|
214430 | for (int sby = 0; sby < mi->num_sb_y; sby++) { |
1128 |
2/2✓ Branch 0 taken 1204132 times.
✓ Branch 1 taken 172498 times.
|
1376630 | for (int sbx = 0; sbx < mi->num_sb_x; sbx++) { |
1129 | 1204132 | int x = x0 + sbx * sbw; | |
1130 | 1204132 | int y = y0 + sby * sbh; | |
1131 | 1204132 | sb_temproal_luma_motion(lc, x_ctb, y_ctb, temp_mv, x + sbw / 2, y + sbh / 2, &mvf.pred_flag, mvf.mv); | |
1132 |
2/2✓ Branch 0 taken 7496 times.
✓ Branch 1 taken 1196636 times.
|
1204132 | if (!mvf.pred_flag) { |
1133 | 7496 | mvf.pred_flag = ctr_mvf.pred_flag; | |
1134 | 7496 | memcpy(mvf.mv, ctr_mvf.mv, sizeof(mvf.mv)); | |
1135 | } | ||
1136 | 1204132 | ff_vvc_set_mvf(lc, x, y, sbw, sbh, &mvf); | |
1137 | } | ||
1138 | } | ||
1139 | 41932 | return 1; | |
1140 | } | ||
1141 | 7969 | return 0; | |
1142 | } | ||
1143 | |||
1144 | 13909 | static int affine_merge_const1(const MvField *c0, const MvField *c1, const MvField *c2, MotionInfo *mi) | |
1145 | { | ||
1146 |
6/6✓ Branch 0 taken 13844 times.
✓ Branch 1 taken 65 times.
✓ Branch 2 taken 13220 times.
✓ Branch 3 taken 624 times.
✓ Branch 4 taken 12719 times.
✓ Branch 5 taken 501 times.
|
13909 | if (c0 && c1 && c2) { |
1147 | 12719 | mi->pred_flag = 0; | |
1148 |
2/2✓ Branch 0 taken 25438 times.
✓ Branch 1 taken 12719 times.
|
38157 | for (int i = 0; i < 2; i++) { |
1149 | 25438 | PredFlag mask = i + 1; | |
1150 |
2/2✓ Branch 1 taken 14958 times.
✓ Branch 2 taken 10480 times.
|
25438 | if (compare_pf_ref_idx(c0, c1, c2, i)) { |
1151 | 14958 | mi->pred_flag |= mask; | |
1152 | 14958 | mi->ref_idx[i] = c0->ref_idx[i]; | |
1153 | 14958 | mi->mv[i][0] = c0->mv[i]; | |
1154 | 14958 | mi->mv[i][1] = c1->mv[i]; | |
1155 | 14958 | mi->mv[i][2] = c2->mv[i]; | |
1156 | } | ||
1157 | } | ||
1158 |
2/2✓ Branch 0 taken 11780 times.
✓ Branch 1 taken 939 times.
|
12719 | if (mi->pred_flag) { |
1159 |
2/2✓ Branch 0 taken 3178 times.
✓ Branch 1 taken 8602 times.
|
11780 | if (mi->pred_flag == PF_BI) |
1160 | 3178 | mi->bcw_idx = c0->bcw_idx; | |
1161 | 11780 | mi->motion_model_idc = MOTION_6_PARAMS_AFFINE; | |
1162 | 11780 | return 1; | |
1163 | } | ||
1164 | } | ||
1165 | 2129 | return 0; | |
1166 | } | ||
1167 | |||
1168 | 7375 | static int affine_merge_const2(const MvField *c0, const MvField *c1, const MvField *c3, MotionInfo *mi) | |
1169 | { | ||
1170 |
6/6✓ Branch 0 taken 7310 times.
✓ Branch 1 taken 65 times.
✓ Branch 2 taken 6686 times.
✓ Branch 3 taken 624 times.
✓ Branch 4 taken 4527 times.
✓ Branch 5 taken 2159 times.
|
7375 | if (c0 && c1 && c3) { |
1171 | 4527 | mi->pred_flag = 0; | |
1172 |
2/2✓ Branch 0 taken 9054 times.
✓ Branch 1 taken 4527 times.
|
13581 | for (int i = 0; i < 2; i++) { |
1173 | 9054 | PredFlag mask = i + 1; | |
1174 |
2/2✓ Branch 1 taken 5328 times.
✓ Branch 2 taken 3726 times.
|
9054 | if (compare_pf_ref_idx(c0, c1, c3, i)) { |
1175 | 5328 | mi->pred_flag |= mask; | |
1176 | 5328 | mi->ref_idx[i] = c0->ref_idx[i]; | |
1177 | 5328 | mi->mv[i][0] = c0->mv[i]; | |
1178 | 5328 | mi->mv[i][1] = c1->mv[i]; | |
1179 | 5328 | mi->mv[i][2].x = c3->mv[i].x + c0->mv[i].x - c1->mv[i].x; | |
1180 | 5328 | mi->mv[i][2].y = c3->mv[i].y + c0->mv[i].y - c1->mv[i].y; | |
1181 | 5328 | ff_vvc_clip_mv(&mi->mv[i][2]); | |
1182 | } | ||
1183 | } | ||
1184 |
2/2✓ Branch 0 taken 3960 times.
✓ Branch 1 taken 567 times.
|
4527 | if (mi->pred_flag) { |
1185 |
2/2✓ Branch 0 taken 1368 times.
✓ Branch 1 taken 2592 times.
|
3960 | mi->bcw_idx = mi->pred_flag == PF_BI ? c0->bcw_idx : 0; |
1186 | 3960 | mi->motion_model_idc = MOTION_6_PARAMS_AFFINE; | |
1187 | 3960 | return 1; | |
1188 | } | ||
1189 | } | ||
1190 | 3415 | return 0; | |
1191 | } | ||
1192 | |||
1193 | 5293 | static int affine_merge_const3(const MvField *c0, const MvField *c2, const MvField *c3, MotionInfo *mi) | |
1194 | { | ||
1195 |
6/6✓ Branch 0 taken 5228 times.
✓ Branch 1 taken 65 times.
✓ Branch 2 taken 4910 times.
✓ Branch 3 taken 318 times.
✓ Branch 4 taken 2767 times.
✓ Branch 5 taken 2143 times.
|
5293 | if (c0 && c2 && c3) { |
1196 | 2767 | mi->pred_flag = 0; | |
1197 |
2/2✓ Branch 0 taken 5534 times.
✓ Branch 1 taken 2767 times.
|
8301 | for (int i = 0; i < 2; i++) { |
1198 | 5534 | PredFlag mask = i + 1; | |
1199 |
2/2✓ Branch 1 taken 3172 times.
✓ Branch 2 taken 2362 times.
|
5534 | if (compare_pf_ref_idx(c0, c2, c3, i)) { |
1200 | 3172 | mi->pred_flag |= mask; | |
1201 | 3172 | mi->ref_idx[i] = c0->ref_idx[i]; | |
1202 | 3172 | mi->mv[i][0] = c0->mv[i]; | |
1203 | 3172 | mi->mv[i][1].x = c3->mv[i].x + c0->mv[i].x - c2->mv[i].x; | |
1204 | 3172 | mi->mv[i][1].y = c3->mv[i].y + c0->mv[i].y - c2->mv[i].y; | |
1205 | 3172 | ff_vvc_clip_mv(&mi->mv[i][1]); | |
1206 | 3172 | mi->mv[i][2] = c2->mv[i]; | |
1207 | } | ||
1208 | } | ||
1209 |
2/2✓ Branch 0 taken 2347 times.
✓ Branch 1 taken 420 times.
|
2767 | if (mi->pred_flag) { |
1210 |
2/2✓ Branch 0 taken 825 times.
✓ Branch 1 taken 1522 times.
|
2347 | mi->bcw_idx = mi->pred_flag == PF_BI ? c0->bcw_idx : 0; |
1211 | 2347 | mi->motion_model_idc = MOTION_6_PARAMS_AFFINE; | |
1212 | 2347 | return 1; | |
1213 | } | ||
1214 | } | ||
1215 | 2946 | return 0; | |
1216 | } | ||
1217 | |||
1218 | 3706 | static int affine_merge_const4(const MvField *c1, const MvField *c2, const MvField *c3, MotionInfo *mi) | |
1219 | { | ||
1220 |
6/6✓ Branch 0 taken 3311 times.
✓ Branch 1 taken 395 times.
✓ Branch 2 taken 2999 times.
✓ Branch 3 taken 312 times.
✓ Branch 4 taken 1061 times.
✓ Branch 5 taken 1938 times.
|
3706 | if (c1 && c2 && c3) { |
1221 | 1061 | mi->pred_flag = 0; | |
1222 |
2/2✓ Branch 0 taken 2122 times.
✓ Branch 1 taken 1061 times.
|
3183 | for (int i = 0; i < 2; i++) { |
1223 | 2122 | PredFlag mask = i + 1; | |
1224 |
2/2✓ Branch 1 taken 912 times.
✓ Branch 2 taken 1210 times.
|
2122 | if (compare_pf_ref_idx(c1, c2, c3, i)) { |
1225 | 912 | mi->pred_flag |= mask; | |
1226 | 912 | mi->ref_idx[i] = c1->ref_idx[i]; | |
1227 | 912 | mi->mv[i][0].x = c1->mv[i].x + c2->mv[i].x - c3->mv[i].x; | |
1228 | 912 | mi->mv[i][0].y = c1->mv[i].y + c2->mv[i].y - c3->mv[i].y; | |
1229 | 912 | ff_vvc_clip_mv(&mi->mv[i][0]); | |
1230 | 912 | mi->mv[i][1] = c1->mv[i]; | |
1231 | 912 | mi->mv[i][2] = c2->mv[i]; | |
1232 | } | ||
1233 | } | ||
1234 |
2/2✓ Branch 0 taken 670 times.
✓ Branch 1 taken 391 times.
|
1061 | if (mi->pred_flag) { |
1235 |
2/2✓ Branch 0 taken 242 times.
✓ Branch 1 taken 428 times.
|
670 | mi->bcw_idx = mi->pred_flag == PF_BI ? c1->bcw_idx : 0; |
1236 | 670 | mi->motion_model_idc = MOTION_6_PARAMS_AFFINE; | |
1237 | 670 | return 1; | |
1238 | } | ||
1239 | } | ||
1240 | 3036 | return 0; | |
1241 | } | ||
1242 | |||
1243 | 4347 | static int affine_merge_const5(const MvField *c0, const MvField *c1, MotionInfo *mi) | |
1244 | { | ||
1245 |
4/4✓ Branch 0 taken 3589 times.
✓ Branch 1 taken 758 times.
✓ Branch 2 taken 3000 times.
✓ Branch 3 taken 589 times.
|
4347 | if (c0 && c1) { |
1246 | 3000 | mi->pred_flag = 0; | |
1247 |
2/2✓ Branch 0 taken 6000 times.
✓ Branch 1 taken 3000 times.
|
9000 | for (int i = 0; i < 2; i++) { |
1248 | 6000 | PredFlag mask = i + 1; | |
1249 |
2/2✓ Branch 1 taken 3316 times.
✓ Branch 2 taken 2684 times.
|
6000 | if (compare_pf_ref_idx(c0, c1, NULL, i)) { |
1250 | 3316 | mi->pred_flag |= mask; | |
1251 | 3316 | mi->ref_idx[i] = c0->ref_idx[i]; | |
1252 | 3316 | mi->mv[i][0] = c0->mv[i]; | |
1253 | 3316 | mi->mv[i][1] = c1->mv[i]; | |
1254 | } | ||
1255 | } | ||
1256 |
2/2✓ Branch 0 taken 2623 times.
✓ Branch 1 taken 377 times.
|
3000 | if (mi->pred_flag) { |
1257 |
2/2✓ Branch 0 taken 693 times.
✓ Branch 1 taken 1930 times.
|
2623 | if (mi->pred_flag == PF_BI) |
1258 | 693 | mi->bcw_idx = c0->bcw_idx; | |
1259 | 2623 | mi->motion_model_idc = MOTION_4_PARAMS_AFFINE; | |
1260 | 2623 | return 1; | |
1261 | } | ||
1262 | } | ||
1263 | 1724 | return 0; | |
1264 | } | ||
1265 | |||
1266 | 2837 | static int affine_merge_const6(const MvField* c0, const MvField* c2, const int cb_width, const int cb_height, MotionInfo *mi) | |
1267 | { | ||
1268 |
4/4✓ Branch 0 taken 2079 times.
✓ Branch 1 taken 758 times.
✓ Branch 2 taken 1778 times.
✓ Branch 3 taken 301 times.
|
2837 | if (c0 && c2) { |
1269 | 1778 | const int shift = 7 + av_log2(cb_width) - av_log2(cb_height); | |
1270 | 1778 | mi->pred_flag = 0; | |
1271 |
2/2✓ Branch 0 taken 3556 times.
✓ Branch 1 taken 1778 times.
|
5334 | for (int i = 0; i < 2; i++) { |
1272 | 3556 | PredFlag mask = i + 1; | |
1273 |
2/2✓ Branch 1 taken 2037 times.
✓ Branch 2 taken 1519 times.
|
3556 | if (compare_pf_ref_idx(c0, c2, NULL, i)) { |
1274 | 2037 | mi->pred_flag |= mask; | |
1275 | 2037 | mi->ref_idx[i] = c0->ref_idx[i]; | |
1276 | 2037 | mi->mv[i][0] = c0->mv[i]; | |
1277 | 2037 | mi->mv[i][1].x = (c0->mv[i].x * (1 << 7)) + ((c2->mv[i].y - c0->mv[i].y) * (1 << shift)); | |
1278 | 2037 | mi->mv[i][1].y = (c0->mv[i].y * (1 << 7)) - ((c2->mv[i].x - c0->mv[i].x) * (1 << shift)); | |
1279 | 2037 | ff_vvc_round_mv(&mi->mv[i][1], 0, 7); | |
1280 | 2037 | ff_vvc_clip_mv(&mi->mv[i][1]); | |
1281 | } | ||
1282 | } | ||
1283 |
2/2✓ Branch 0 taken 1606 times.
✓ Branch 1 taken 172 times.
|
1778 | if (mi->pred_flag) { |
1284 |
2/2✓ Branch 0 taken 431 times.
✓ Branch 1 taken 1175 times.
|
1606 | if (mi->pred_flag == PF_BI) |
1285 | 431 | mi->bcw_idx = c0->bcw_idx; | |
1286 | 1606 | mi->motion_model_idc = MOTION_4_PARAMS_AFFINE; | |
1287 | 1606 | return 1; | |
1288 | } | ||
1289 | } | ||
1290 | 1231 | return 0; | |
1291 | } | ||
1292 | |||
1293 | 1661 | static void affine_merge_zero_motion(const VVCLocalContext *lc, MotionInfo *mi) | |
1294 | { | ||
1295 | 1661 | const CodingUnit *cu = lc->cu; | |
1296 | |||
1297 | 1661 | memset(mi, 0, sizeof(*mi)); | |
1298 |
2/2✓ Branch 0 taken 1207 times.
✓ Branch 1 taken 454 times.
|
1661 | mi->pred_flag = PF_L0 + (IS_B(lc->sc->sh.r) << 1); |
1299 | 1661 | mi->motion_model_idc = MOTION_4_PARAMS_AFFINE; | |
1300 | 1661 | mi->num_sb_x = cu->cb_width >> MIN_PU_LOG2; | |
1301 | 1661 | mi->num_sb_y = cu->cb_height >> MIN_PU_LOG2; | |
1302 | 1661 | } | |
1303 | |||
1304 | //8.5.5.6 Derivation process for constructed affine control point motion vector merging candidates | ||
1305 | 15175 | static int affine_merge_const_candidates(const VVCLocalContext *lc, MotionInfo *mi, | |
1306 | NeighbourContext *nctx, const int merge_subblock_idx, int num_cands) | ||
1307 | { | ||
1308 | 15175 | const VVCFrameContext *fc = lc->fc; | |
1309 | 15175 | const CodingUnit *cu = lc->cu; | |
1310 | 15175 | const NeighbourIdx tl[] = { B2, B3, A2 }; | |
1311 | 15175 | const NeighbourIdx tr[] = { B1, B0}; | |
1312 | 15175 | const NeighbourIdx bl[] = { A1, A0}; | |
1313 | const MvField *c0, *c1, *c2; | ||
1314 | |||
1315 | 15175 | c0 = DERIVE_CORNER_MV(tl); | |
1316 | 15175 | c1 = DERIVE_CORNER_MV(tr); | |
1317 | 15175 | c2 = DERIVE_CORNER_MV(bl); | |
1318 | |||
1319 |
2/2✓ Branch 0 taken 13909 times.
✓ Branch 1 taken 1266 times.
|
15175 | if (fc->ps.sps->r->sps_6param_affine_enabled_flag) { |
1320 | 13909 | MvField corner3, *c3 = NULL; | |
1321 | //Const1 | ||
1322 |
2/2✓ Branch 1 taken 11780 times.
✓ Branch 2 taken 2129 times.
|
13909 | if (affine_merge_const1(c0, c1, c2, mi)) { |
1323 |
2/2✓ Branch 0 taken 6534 times.
✓ Branch 1 taken 5246 times.
|
11780 | if (merge_subblock_idx == num_cands) |
1324 | 10828 | return 1; | |
1325 | 5246 | num_cands++; | |
1326 | } | ||
1327 | |||
1328 | 7375 | memset(&corner3, 0, sizeof(corner3)); | |
1329 |
2/2✓ Branch 0 taken 7349 times.
✓ Branch 1 taken 26 times.
|
7375 | if (fc->ps.ph.r->ph_temporal_mvp_enabled_flag){ |
1330 | 7349 | const int available_l0 = temporal_luma_motion_vector(lc, 0, corner3.mv + 0, 0, 0, 0); | |
1331 | 14698 | const int available_l1 = (lc->sc->sh.r->sh_slice_type == VVC_SLICE_TYPE_B) ? | |
1332 |
2/2✓ Branch 0 taken 5925 times.
✓ Branch 1 taken 1424 times.
|
7349 | temporal_luma_motion_vector(lc, 0, corner3.mv + 1, 1, 0, 0) : 0; |
1333 | |||
1334 | 7349 | corner3.pred_flag = available_l0 + (available_l1 << 1); | |
1335 |
2/2✓ Branch 0 taken 4961 times.
✓ Branch 1 taken 2388 times.
|
7349 | if (corner3.pred_flag) |
1336 | 4961 | c3 = &corner3; | |
1337 | } | ||
1338 | |||
1339 | //Const2 | ||
1340 |
2/2✓ Branch 1 taken 3960 times.
✓ Branch 2 taken 3415 times.
|
7375 | if (affine_merge_const2(c0, c1, c3, mi)) { |
1341 |
2/2✓ Branch 0 taken 2082 times.
✓ Branch 1 taken 1878 times.
|
3960 | if (merge_subblock_idx == num_cands) |
1342 | 2082 | return 1; | |
1343 | 1878 | num_cands++; | |
1344 | } | ||
1345 | |||
1346 | //Const3 | ||
1347 |
2/2✓ Branch 1 taken 2347 times.
✓ Branch 2 taken 2946 times.
|
5293 | if (affine_merge_const3(c0, c2, c3, mi)) { |
1348 |
2/2✓ Branch 0 taken 1587 times.
✓ Branch 1 taken 760 times.
|
2347 | if (merge_subblock_idx == num_cands) |
1349 | 1587 | return 1; | |
1350 | 760 | num_cands++; | |
1351 | } | ||
1352 | |||
1353 | //Const4 | ||
1354 |
2/2✓ Branch 1 taken 670 times.
✓ Branch 2 taken 3036 times.
|
3706 | if (affine_merge_const4(c1, c2, c3, mi)) { |
1355 |
2/2✓ Branch 0 taken 625 times.
✓ Branch 1 taken 45 times.
|
670 | if (merge_subblock_idx == num_cands) |
1356 | 625 | return 1; | |
1357 | 45 | num_cands++; | |
1358 | } | ||
1359 | } | ||
1360 | |||
1361 | //Const5 | ||
1362 |
2/2✓ Branch 1 taken 2623 times.
✓ Branch 2 taken 1724 times.
|
4347 | if (affine_merge_const5(c0, c1, mi)) { |
1363 |
2/2✓ Branch 0 taken 1510 times.
✓ Branch 1 taken 1113 times.
|
2623 | if (merge_subblock_idx == num_cands) |
1364 | 1510 | return 1; | |
1365 | 1113 | num_cands++; | |
1366 | } | ||
1367 | |||
1368 |
2/2✓ Branch 1 taken 1606 times.
✓ Branch 2 taken 1231 times.
|
2837 | if (affine_merge_const6(c0, c2, cu->cb_width, cu->cb_height, mi)) { |
1369 |
2/2✓ Branch 0 taken 1176 times.
✓ Branch 1 taken 430 times.
|
1606 | if (merge_subblock_idx == num_cands) |
1370 | 1176 | return 1; | |
1371 | } | ||
1372 | 1661 | return 0; | |
1373 | } | ||
1374 | |||
1375 | //8.5.5.2 Derivation process for motion vectors and reference indices in subblock merge mode | ||
1376 | //return 1 if candidate is SbCol | ||
1377 | 50089 | static int sb_mv_merge_mode(const VVCLocalContext *lc, const int merge_subblock_idx, PredictionUnit *pu) | |
1378 | { | ||
1379 | 50089 | const VVCSPS *sps = lc->fc->ps.sps; | |
1380 | 50089 | const CodingUnit *cu = lc->cu; | |
1381 | 50089 | MotionInfo *mi = &pu->mi; | |
1382 | 50089 | int num_cands = 0; | |
1383 | NeighbourContext nctx; | ||
1384 | |||
1385 | 50089 | init_neighbour_context(&nctx, lc); | |
1386 | |||
1387 | //SbCol | ||
1388 |
2/2✓ Branch 1 taken 41932 times.
✓ Branch 2 taken 8157 times.
|
50089 | if (sb_temporal_merge_candidate(lc, &nctx, pu)) { |
1389 |
2/2✓ Branch 0 taken 25313 times.
✓ Branch 1 taken 16619 times.
|
41932 | if (merge_subblock_idx == num_cands) |
1390 | 25313 | return 1; | |
1391 | 16619 | num_cands++; | |
1392 | } | ||
1393 | |||
1394 | 24776 | pu->inter_affine_flag = 1; | |
1395 | 24776 | mi->num_sb_x = cu->cb_width >> MIN_PU_LOG2; | |
1396 | 24776 | mi->num_sb_y = cu->cb_height >> MIN_PU_LOG2; | |
1397 | |||
1398 |
1/2✓ Branch 0 taken 24776 times.
✗ Branch 1 not taken.
|
24776 | if (sps->r->sps_affine_enabled_flag) { |
1399 | 24776 | const NeighbourIdx ak[] = { A0, A1 }; | |
1400 | 24776 | const NeighbourIdx bk[] = { B0, B1, B2 }; | |
1401 | //A | ||
1402 |
2/2✓ Branch 1 taken 9737 times.
✓ Branch 2 taken 15039 times.
|
24776 | if (AFFINE_MERGE_FROM_NBS(ak)) { |
1403 |
2/2✓ Branch 0 taken 5323 times.
✓ Branch 1 taken 4414 times.
|
9737 | if (merge_subblock_idx == num_cands) |
1404 | 23115 | return 0; | |
1405 | 4414 | num_cands++; | |
1406 | } | ||
1407 | |||
1408 | //B | ||
1409 |
2/2✓ Branch 1 taken 9102 times.
✓ Branch 2 taken 10351 times.
|
19453 | if (AFFINE_MERGE_FROM_NBS(bk)) { |
1410 |
2/2✓ Branch 0 taken 4278 times.
✓ Branch 1 taken 4824 times.
|
9102 | if (merge_subblock_idx == num_cands) |
1411 | 4278 | return 0; | |
1412 | 4824 | num_cands++; | |
1413 | } | ||
1414 | |||
1415 | //Const1 to Const6 | ||
1416 |
2/2✓ Branch 1 taken 13514 times.
✓ Branch 2 taken 1661 times.
|
15175 | if (affine_merge_const_candidates(lc, mi, &nctx, merge_subblock_idx, num_cands)) |
1417 | 13514 | return 0; | |
1418 | } | ||
1419 | //Zero | ||
1420 | 1661 | affine_merge_zero_motion(lc, mi); | |
1421 | 1661 | return 0; | |
1422 | } | ||
1423 | |||
1424 | 50089 | void ff_vvc_sb_mv_merge_mode(VVCLocalContext *lc, const int merge_subblock_idx, PredictionUnit *pu) | |
1425 | { | ||
1426 | 50089 | const CodingUnit *cu = lc->cu; | |
1427 | 50089 | ff_vvc_set_neighbour_available(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height); | |
1428 |
2/2✓ Branch 1 taken 24776 times.
✓ Branch 2 taken 25313 times.
|
50089 | if (!sb_mv_merge_mode(lc, merge_subblock_idx, pu)) { |
1429 | 24776 | ff_vvc_store_sb_mvs(lc, pu); | |
1430 | } | ||
1431 | 50089 | } | |
1432 | |||
1433 | 137853 | static int mvp_candidate(const VVCLocalContext *lc, const int x_cand, const int y_cand, | |
1434 | const int lx, const int8_t *ref_idx, Mv *mv) | ||
1435 | { | ||
1436 | 137853 | const VVCFrameContext *fc = lc->fc; | |
1437 | 137853 | const RefPicList *rpl = lc->sc->rpl; | |
1438 | 137853 | const int min_pu_width = fc->ps.pps->min_pu_width; | |
1439 | 137853 | const MvField* tab_mvf = fc->tab.mvf; | |
1440 | 137853 | const MvField *mvf = &TAB_MVF(x_cand, y_cand); | |
1441 | 137853 | const PredFlag maskx = lx + 1; | |
1442 | 137853 | const int poc = rpl[lx].refs[ref_idx[lx]].poc; | |
1443 | 137853 | int available = 0; | |
1444 | |||
1445 |
4/4✓ Branch 0 taken 106839 times.
✓ Branch 1 taken 31014 times.
✓ Branch 2 taken 72038 times.
✓ Branch 3 taken 34801 times.
|
137853 | if ((mvf->pred_flag & maskx) && rpl[lx].refs[mvf->ref_idx[lx]].poc == poc) { |
1446 | 72038 | available = 1; | |
1447 | 72038 | *mv = mvf->mv[lx]; | |
1448 | } else { | ||
1449 | 65815 | const int ly = !lx; | |
1450 | 65815 | const PredFlag masky = ly + 1; | |
1451 |
4/4✓ Branch 0 taken 44824 times.
✓ Branch 1 taken 20991 times.
✓ Branch 2 taken 10165 times.
✓ Branch 3 taken 34659 times.
|
65815 | if ((mvf->pred_flag & masky) && rpl[ly].refs[mvf->ref_idx[ly]].poc == poc) { |
1452 | 10165 | available = 1; | |
1453 | 10165 | *mv = mvf->mv[ly]; | |
1454 | } | ||
1455 | } | ||
1456 | |||
1457 | 137853 | return available; | |
1458 | } | ||
1459 | |||
1460 | 29679 | static int affine_mvp_candidate(const VVCLocalContext *lc, | |
1461 | const int x_cand, const int y_cand, const int lx, const int8_t *ref_idx, | ||
1462 | Mv *cps, const int num_cp) | ||
1463 | { | ||
1464 | 29679 | const VVCFrameContext *fc = lc->fc; | |
1465 | 29679 | int x_nb, y_nb, nbw, nbh, motion_model_idc, available = 0; | |
1466 | |||
1467 | 29679 | motion_model_idc = affine_neighbour_cb(fc, x_cand, y_cand, &x_nb, &y_nb, &nbw, &nbh); | |
1468 |
2/2✓ Branch 0 taken 7489 times.
✓ Branch 1 taken 22190 times.
|
29679 | if (motion_model_idc) { |
1469 | 7489 | const int min_pu_width = fc->ps.pps->min_pu_width; | |
1470 | 7489 | const MvField* tab_mvf = fc->tab.mvf; | |
1471 | 7489 | const MvField *mvf = &TAB_MVF(x_nb, y_nb); | |
1472 | 7489 | RefPicList* rpl = lc->sc->rpl; | |
1473 | 7489 | const PredFlag maskx = lx + 1; | |
1474 | 7489 | const int poc = rpl[lx].refs[ref_idx[lx]].poc; | |
1475 | |||
1476 |
4/4✓ Branch 0 taken 6315 times.
✓ Branch 1 taken 1174 times.
✓ Branch 2 taken 5145 times.
✓ Branch 3 taken 1170 times.
|
7489 | if ((mvf->pred_flag & maskx) && rpl[lx].refs[mvf->ref_idx[lx]].poc == poc) { |
1477 | 5145 | available = 1; | |
1478 | 5145 | affine_cps_from_nb(lc, x_nb, y_nb, nbw, nbh, lx, cps, num_cp); | |
1479 | } else { | ||
1480 | 2344 | const int ly = !lx; | |
1481 | 2344 | const PredFlag masky = ly + 1; | |
1482 |
4/4✓ Branch 0 taken 1522 times.
✓ Branch 1 taken 822 times.
✓ Branch 2 taken 754 times.
✓ Branch 3 taken 768 times.
|
2344 | if ((mvf->pred_flag & masky) && rpl[ly].refs[mvf->ref_idx[ly]].poc == poc) { |
1483 | 754 | available = 1; | |
1484 | 754 | affine_cps_from_nb(lc, x_nb, y_nb, nbw, nbh, ly, cps, num_cp); | |
1485 | } | ||
1486 | } | ||
1487 | |||
1488 | } | ||
1489 | 29679 | return available; | |
1490 | } | ||
1491 | |||
1492 | 159161 | static int mvp_from_nbs(NeighbourContext *ctx, | |
1493 | const NeighbourIdx *nbs, const int num_nbs, const int lx, const int8_t *ref_idx, const int amvr_shift, | ||
1494 | Mv *cps, const int num_cps) | ||
1495 | { | ||
1496 | 159161 | const VVCLocalContext *lc = ctx->lc; | |
1497 | 159161 | int available = 0; | |
1498 | |||
1499 |
2/2✓ Branch 0 taken 314623 times.
✓ Branch 1 taken 71059 times.
|
385682 | for (int i = 0; i < num_nbs; i++) { |
1500 | 314623 | Neighbour *n = &ctx->neighbours[nbs[i]]; | |
1501 |
2/2✓ Branch 1 taken 167532 times.
✓ Branch 2 taken 147091 times.
|
314623 | if (check_available(n, lc, 0)) { |
1502 |
2/2✓ Branch 0 taken 29679 times.
✓ Branch 1 taken 137853 times.
|
167532 | if (num_cps > 1) |
1503 | 29679 | available = affine_mvp_candidate(lc, n->x, n->y, lx, ref_idx, cps, num_cps); | |
1504 | else | ||
1505 | 137853 | available = mvp_candidate(lc, n->x, n->y, lx, ref_idx, cps); | |
1506 |
2/2✓ Branch 0 taken 88102 times.
✓ Branch 1 taken 79430 times.
|
167532 | if (available) { |
1507 |
2/2✓ Branch 0 taken 96915 times.
✓ Branch 1 taken 88102 times.
|
185017 | for (int c = 0; c < num_cps; c++) |
1508 | 96915 | ff_vvc_round_mv(cps + c, amvr_shift, amvr_shift); | |
1509 | 88102 | return 1; | |
1510 | } | ||
1511 | } | ||
1512 | } | ||
1513 | 71059 | return 0; | |
1514 | } | ||
1515 | |||
1516 | //get mvp from neighbours | ||
1517 | #define AFFINE_MVP_FROM_NBS(nbs) \ | ||
1518 | mvp_from_nbs(&nctx, nbs, FF_ARRAY_ELEMS(nbs), lx, ref_idx, amvr_shift, cps, num_cp) \ | ||
1519 | |||
1520 | #define MVP_FROM_NBS(nbs) \ | ||
1521 | mvp_from_nbs(&nctx, nbs, FF_ARRAY_ELEMS(nbs), lx, ref_idx, amvr_shift, mv, 1) \ | ||
1522 | |||
1523 | 83359 | static int mvp_spatial_candidates(const VVCLocalContext *lc, | |
1524 | const int mvp_lx_flag, const int lx, const int8_t* ref_idx, const int amvr_shift, | ||
1525 | Mv* mv, int *nb_merge_cand) | ||
1526 | { | ||
1527 | 83359 | const NeighbourIdx ak[] = { A0, A1 }; | |
1528 | 83359 | const NeighbourIdx bk[] = { B0, B1, B2 }; | |
1529 | NeighbourContext nctx; | ||
1530 | 83359 | int available_a, num_cands = 0; | |
1531 | 83359 | LOCAL_ALIGNED_8(Mv, mv_a, [1]); | |
1532 | |||
1533 | 83359 | init_neighbour_context(&nctx, lc); | |
1534 | |||
1535 | 83359 | available_a = MVP_FROM_NBS(ak); | |
1536 |
2/2✓ Branch 0 taken 49764 times.
✓ Branch 1 taken 33595 times.
|
83359 | if (available_a) { |
1537 |
2/2✓ Branch 0 taken 29899 times.
✓ Branch 1 taken 19865 times.
|
49764 | if (mvp_lx_flag == num_cands) |
1538 | 29899 | return 1; | |
1539 | 19865 | num_cands++; | |
1540 | 19865 | *mv_a = *mv; | |
1541 | } | ||
1542 |
2/2✓ Branch 1 taken 32439 times.
✓ Branch 2 taken 21021 times.
|
53460 | if (MVP_FROM_NBS(bk)) { |
1543 |
4/4✓ Branch 0 taken 17126 times.
✓ Branch 1 taken 15313 times.
✓ Branch 2 taken 14397 times.
✓ Branch 3 taken 2729 times.
|
32439 | if (!available_a || !IS_SAME_MV(mv_a, mv)) { |
1544 |
2/2✓ Branch 0 taken 24323 times.
✓ Branch 1 taken 5387 times.
|
29710 | if (mvp_lx_flag == num_cands) |
1545 | 24323 | return 1; | |
1546 | 5387 | num_cands++; | |
1547 | } | ||
1548 | } | ||
1549 | 29137 | *nb_merge_cand = num_cands; | |
1550 | 29137 | return 0; | |
1551 | } | ||
1552 | |||
1553 | 29137 | static int mvp_temporal_candidates(const VVCLocalContext* lc, | |
1554 | const int mvp_lx_flag, const int lx, const int8_t *ref_idx, const int amvr_shift, | ||
1555 | Mv* mv, int *num_cands) | ||
1556 | { | ||
1557 |
2/2✓ Branch 1 taken 16320 times.
✓ Branch 2 taken 12817 times.
|
29137 | if (temporal_luma_motion_vector(lc, ref_idx[lx], mv, lx, 1, 0)) { |
1558 |
2/2✓ Branch 0 taken 13381 times.
✓ Branch 1 taken 2939 times.
|
16320 | if (mvp_lx_flag == *num_cands) { |
1559 | 13381 | ff_vvc_round_mv(mv, amvr_shift, amvr_shift); | |
1560 | 13381 | return 1; | |
1561 | } | ||
1562 | 2939 | (*num_cands)++; | |
1563 | } | ||
1564 | 15756 | return 0; | |
1565 | |||
1566 | } | ||
1567 | |||
1568 | 15756 | static int mvp_history_candidates(const VVCLocalContext *lc, | |
1569 | const int mvp_lx_flag, const int lx, const int8_t ref_idx, const int amvr_shift, | ||
1570 | Mv *mv, int num_cands) | ||
1571 | { | ||
1572 | 15756 | const EntryPoint* ep = lc->ep; | |
1573 | 15756 | const RefPicList* rpl = lc->sc->rpl; | |
1574 | 15756 | const int poc = rpl[lx].refs[ref_idx].poc; | |
1575 | |||
1576 |
2/2✓ Branch 0 taken 1928 times.
✓ Branch 1 taken 13828 times.
|
15756 | if (ep->num_hmvp == 0) |
1577 | 1928 | return 0; | |
1578 |
2/2✓ Branch 0 taken 28639 times.
✓ Branch 1 taken 4349 times.
|
32988 | for (int i = 1; i <= FFMIN(4, ep->num_hmvp); i++) { |
1579 | 28639 | const MvField* h = &ep->hmvp[i - 1]; | |
1580 |
2/2✓ Branch 0 taken 49182 times.
✓ Branch 1 taken 19160 times.
|
68342 | for (int j = 0; j < 2; j++) { |
1581 |
2/2✓ Branch 0 taken 20543 times.
✓ Branch 1 taken 28639 times.
|
49182 | const int ly = (j ? !lx : lx); |
1582 | 49182 | PredFlag mask = PF_L0 + ly; | |
1583 |
4/4✓ Branch 0 taken 33745 times.
✓ Branch 1 taken 15437 times.
✓ Branch 2 taken 11626 times.
✓ Branch 3 taken 22119 times.
|
49182 | if ((h->pred_flag & mask) && poc == rpl[ly].refs[h->ref_idx[ly]].poc) { |
1584 |
2/2✓ Branch 0 taken 9479 times.
✓ Branch 1 taken 2147 times.
|
11626 | if (mvp_lx_flag == num_cands) { |
1585 | 9479 | *mv = h->mv[ly]; | |
1586 | 9479 | ff_vvc_round_mv(mv, amvr_shift, amvr_shift); | |
1587 | 9479 | return 1; | |
1588 | } | ||
1589 | 2147 | num_cands++; | |
1590 | } | ||
1591 | } | ||
1592 | } | ||
1593 | 4349 | return 0; | |
1594 | } | ||
1595 | |||
1596 | //8.5.2.8 Derivation process for luma motion vector prediction | ||
1597 | 83359 | static void mvp(const VVCLocalContext *lc, const int mvp_lx_flag, const int lx, | |
1598 | const int8_t *ref_idx, const int amvr_shift, Mv *mv) | ||
1599 | { | ||
1600 | int num_cands; | ||
1601 | |||
1602 |
2/2✓ Branch 1 taken 54222 times.
✓ Branch 2 taken 29137 times.
|
83359 | if (mvp_spatial_candidates(lc, mvp_lx_flag, lx, ref_idx, amvr_shift, mv, &num_cands)) |
1603 | 77082 | return; | |
1604 | |||
1605 |
2/2✓ Branch 1 taken 13381 times.
✓ Branch 2 taken 15756 times.
|
29137 | if (mvp_temporal_candidates(lc, mvp_lx_flag, lx, ref_idx, amvr_shift, mv, &num_cands)) |
1606 | 13381 | return; | |
1607 | |||
1608 |
2/2✓ Branch 1 taken 9479 times.
✓ Branch 2 taken 6277 times.
|
15756 | if (mvp_history_candidates(lc, mvp_lx_flag, lx, ref_idx[lx], amvr_shift, mv, num_cands)) |
1609 | 9479 | return; | |
1610 | |||
1611 | 6277 | memset(mv, 0, sizeof(*mv)); | |
1612 | } | ||
1613 | |||
1614 | 65004 | void ff_vvc_mvp(VVCLocalContext *lc, const int *mvp_lx_flag, const int amvr_shift, MotionInfo *mi) | |
1615 | { | ||
1616 | 65004 | const CodingUnit *cu = lc->cu; | |
1617 | 65004 | mi->num_sb_x = 1; | |
1618 | 65004 | mi->num_sb_y = 1; | |
1619 | |||
1620 | 65004 | ff_vvc_set_neighbour_available(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height); | |
1621 |
2/2✓ Branch 0 taken 53651 times.
✓ Branch 1 taken 11353 times.
|
65004 | if (mi->pred_flag != PF_L1) |
1622 | 53651 | mvp(lc, mvp_lx_flag[L0], L0, mi->ref_idx, amvr_shift, &mi->mv[L0][0]); | |
1623 |
2/2✓ Branch 0 taken 29708 times.
✓ Branch 1 taken 35296 times.
|
65004 | if (mi->pred_flag != PF_L0) |
1624 | 29708 | mvp(lc, mvp_lx_flag[L1], L1, mi->ref_idx, amvr_shift, &mi->mv[L1][0]); | |
1625 | 65004 | } | |
1626 | |||
1627 | 31182 | static int ibc_spatial_candidates(const VVCLocalContext *lc, const int merge_idx, Mv *const cand_list, int *nb_merge_cand) | |
1628 | { | ||
1629 | 31182 | const CodingUnit *cu = lc->cu; | |
1630 | 31182 | const VVCFrameContext *fc = lc->fc; | |
1631 | 31182 | const int min_pu_width = fc->ps.pps->min_pu_width; | |
1632 | 31182 | const MvField *tab_mvf = fc->tab.mvf; | |
1633 | 31182 | const int is_gt4by4 = (cu->cb_width * cu->cb_height) > 16; | |
1634 | 31182 | int num_cands = 0; | |
1635 | |||
1636 | NeighbourContext nctx; | ||
1637 | 31182 | Neighbour *a1 = &nctx.neighbours[A1]; | |
1638 | 31182 | Neighbour *b1 = &nctx.neighbours[B1]; | |
1639 | |||
1640 |
2/2✓ Branch 0 taken 17582 times.
✓ Branch 1 taken 13600 times.
|
31182 | if (!is_gt4by4) { |
1641 | 17582 | *nb_merge_cand = 0; | |
1642 | 17582 | return 0; | |
1643 | } | ||
1644 | |||
1645 | 13600 | init_neighbour_context(&nctx, lc); | |
1646 | |||
1647 |
2/2✓ Branch 1 taken 4658 times.
✓ Branch 2 taken 8942 times.
|
13600 | if (check_available(a1, lc, 0)) { |
1648 | 4658 | cand_list[num_cands++] = TAB_MVF(a1->x, a1->y).mv[L0]; | |
1649 |
2/2✓ Branch 0 taken 3424 times.
✓ Branch 1 taken 1234 times.
|
4658 | if (num_cands > merge_idx) |
1650 | 3424 | return 1; | |
1651 | } | ||
1652 |
2/2✓ Branch 1 taken 2741 times.
✓ Branch 2 taken 7435 times.
|
10176 | if (check_available(b1, lc, 0)) { |
1653 | 2741 | const MvField *mvf = &TAB_MVF(b1->x, b1->y); | |
1654 |
4/4✓ Branch 0 taken 366 times.
✓ Branch 1 taken 2375 times.
✓ Branch 2 taken 295 times.
✓ Branch 3 taken 71 times.
|
2741 | if (!num_cands || !IS_SAME_MV(&cand_list[0], mvf->mv)) { |
1655 | 2670 | cand_list[num_cands++] = mvf->mv[L0]; | |
1656 |
2/2✓ Branch 0 taken 1850 times.
✓ Branch 1 taken 820 times.
|
2670 | if (num_cands > merge_idx) |
1657 | 1850 | return 1; | |
1658 | } | ||
1659 | } | ||
1660 | |||
1661 | 8326 | *nb_merge_cand = num_cands; | |
1662 | 8326 | return 0; | |
1663 | } | ||
1664 | |||
1665 | 25908 | static int ibc_history_candidates(const VVCLocalContext *lc, | |
1666 | const int merge_idx, Mv *cand_list, int *nb_merge_cand) | ||
1667 | { | ||
1668 | 25908 | const CodingUnit *cu = lc->cu; | |
1669 | 25908 | const EntryPoint *ep = lc->ep; | |
1670 | 25908 | const int is_gt4by4 = (cu->cb_width * cu->cb_height) > 16; | |
1671 | 25908 | int num_cands = *nb_merge_cand; | |
1672 | |||
1673 |
2/2✓ Branch 0 taken 37561 times.
✓ Branch 1 taken 1397 times.
|
38958 | for (int i = 1; i <= ep->num_hmvp_ibc; i++) { |
1674 | 37561 | int same_motion = 0; | |
1675 | 37561 | const MvField *mvf = &ep->hmvp_ibc[ep->num_hmvp_ibc - i]; | |
1676 |
2/2✓ Branch 0 taken 3490 times.
✓ Branch 1 taken 36530 times.
|
40020 | for (int j = 0; j < *nb_merge_cand; j++) { |
1677 |
5/6✓ Branch 0 taken 3490 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1774 times.
✓ Branch 3 taken 1716 times.
✓ Branch 4 taken 1031 times.
✓ Branch 5 taken 743 times.
|
3490 | same_motion = is_gt4by4 && i == 1 && IS_SAME_MV(&mvf->mv[L0], &cand_list[j]); |
1678 |
2/2✓ Branch 0 taken 1031 times.
✓ Branch 1 taken 2459 times.
|
3490 | if (same_motion) |
1679 | 1031 | break; | |
1680 | } | ||
1681 |
2/2✓ Branch 0 taken 36530 times.
✓ Branch 1 taken 1031 times.
|
37561 | if (!same_motion) { |
1682 | 36530 | cand_list[num_cands++] = mvf->mv[L0]; | |
1683 |
2/2✓ Branch 0 taken 24511 times.
✓ Branch 1 taken 12019 times.
|
36530 | if (num_cands > merge_idx) |
1684 | 24511 | return 1; | |
1685 | } | ||
1686 | } | ||
1687 | |||
1688 | 1397 | *nb_merge_cand = num_cands; | |
1689 | 1397 | return 0; | |
1690 | } | ||
1691 | |||
1692 | #define MV_BITS 18 | ||
1693 | #define IBC_SHIFT(v) ((v) >= (1 << (MV_BITS - 1)) ? ((v) - (1 << MV_BITS)) : (v)) | ||
1694 | |||
1695 | 17036 | static inline void ibc_add_mvp(Mv *mv, Mv *mvp, const int amvr_shift) | |
1696 | { | ||
1697 | 17036 | ff_vvc_round_mv(mv, amvr_shift, 0); | |
1698 | 17036 | ff_vvc_round_mv(mvp, amvr_shift, amvr_shift); | |
1699 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17036 times.
|
17036 | mv->x = IBC_SHIFT(mv->x + mvp->x); |
1700 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17036 times.
|
17036 | mv->y = IBC_SHIFT(mv->y + mvp->y); |
1701 | 17036 | } | |
1702 | |||
1703 | 31182 | static void ibc_merge_candidates(VVCLocalContext *lc, const int merge_idx, Mv *mv) | |
1704 | { | ||
1705 | 31182 | const CodingUnit *cu = lc->cu; | |
1706 | 31182 | LOCAL_ALIGNED_8(Mv, cand_list, [MRG_MAX_NUM_CANDS]); | |
1707 | int nb_cands; | ||
1708 | |||
1709 | 31182 | ff_vvc_set_neighbour_available(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height); | |
1710 |
4/4✓ Branch 1 taken 25908 times.
✓ Branch 2 taken 5274 times.
✓ Branch 3 taken 24511 times.
✓ Branch 4 taken 1397 times.
|
57090 | if (ibc_spatial_candidates(lc, merge_idx, cand_list, &nb_cands) || |
1711 | 25908 | ibc_history_candidates(lc, merge_idx, cand_list, &nb_cands)) { | |
1712 | 29785 | *mv = cand_list[merge_idx]; | |
1713 | 29785 | return; | |
1714 | } | ||
1715 | |||
1716 | //zero mv | ||
1717 | 1397 | memset(mv, 0, sizeof(*mv)); | |
1718 | } | ||
1719 | |||
1720 | 31182 | static int ibc_check_mv(VVCLocalContext *lc, Mv *mv) | |
1721 | { | ||
1722 | 31182 | const VVCFrameContext *fc = lc->fc; | |
1723 | 31182 | const VVCSPS *sps = lc->fc->ps.sps; | |
1724 | 31182 | const CodingUnit *cu = lc->cu; | |
1725 | 31182 | const Mv *bv = &cu->pu.mi.mv[L0][0]; | |
1726 | |||
1727 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31182 times.
|
31182 | if (sps->ctb_size_y < ((cu->y0 + (bv->y >> 4)) & (sps->ctb_size_y - 1)) + cu->cb_height) { |
1728 | ✗ | av_log(fc->log_ctx, AV_LOG_ERROR, "IBC region spans multiple CTBs.\n"); | |
1729 | ✗ | return AVERROR_INVALIDDATA; | |
1730 | } | ||
1731 | |||
1732 | 31182 | return 0; | |
1733 | } | ||
1734 | |||
1735 | 17036 | int ff_vvc_mvp_ibc(VVCLocalContext *lc, const int mvp_l0_flag, const int amvr_shift, Mv *mv) | |
1736 | { | ||
1737 | 17036 | LOCAL_ALIGNED_8(Mv, mvp, [1]); | |
1738 | |||
1739 | 17036 | ibc_merge_candidates(lc, mvp_l0_flag, mvp); | |
1740 | 17036 | ibc_add_mvp(mv, mvp, amvr_shift); | |
1741 | 17036 | return ibc_check_mv(lc, mv); | |
1742 | } | ||
1743 | |||
1744 | 14146 | int ff_vvc_luma_mv_merge_ibc(VVCLocalContext *lc, const int merge_idx, Mv *mv) | |
1745 | { | ||
1746 | 14146 | ibc_merge_candidates(lc, merge_idx, mv); | |
1747 | 14146 | return ibc_check_mv(lc, mv); | |
1748 | } | ||
1749 | |||
1750 | 24168 | static int affine_mvp_constructed_cp(NeighbourContext *ctx, | |
1751 | const NeighbourIdx *neighbour, const int num_neighbour, | ||
1752 | const int lx, const int8_t ref_idx, const int amvr_shift, Mv *cp) | ||
1753 | { | ||
1754 | 24168 | const VVCLocalContext *lc = ctx->lc; | |
1755 | 24168 | const VVCFrameContext *fc = lc->fc; | |
1756 | 24168 | const MvField *tab_mvf = fc->tab.mvf; | |
1757 | 24168 | const int min_pu_width = fc->ps.pps->min_pu_width; | |
1758 | 24168 | const RefPicList* rpl = lc->sc->rpl; | |
1759 | 24168 | int available = 0; | |
1760 | |||
1761 |
2/2✓ Branch 0 taken 37660 times.
✓ Branch 1 taken 8187 times.
|
45847 | for (int i = 0; i < num_neighbour; i++) { |
1762 | 37660 | Neighbour *n = &ctx->neighbours[neighbour[i]]; | |
1763 |
2/2✓ Branch 1 taken 23602 times.
✓ Branch 2 taken 14058 times.
|
37660 | if (check_available(n, ctx->lc, 0)) { |
1764 | 23602 | const PredFlag maskx = lx + 1; | |
1765 | 23602 | const MvField* mvf = &TAB_MVF(n->x, n->y); | |
1766 | 23602 | const int poc = rpl[lx].refs[ref_idx].poc; | |
1767 |
4/4✓ Branch 0 taken 19262 times.
✓ Branch 1 taken 4340 times.
✓ Branch 2 taken 14169 times.
✓ Branch 3 taken 5093 times.
|
23602 | if ((mvf->pred_flag & maskx) && rpl[lx].refs[mvf->ref_idx[lx]].poc == poc) { |
1768 | 14169 | available = 1; | |
1769 | 14169 | *cp = mvf->mv[lx]; | |
1770 | } else { | ||
1771 | 9433 | const int ly = !lx; | |
1772 | 9433 | const PredFlag masky = ly + 1; | |
1773 |
4/4✓ Branch 0 taken 6356 times.
✓ Branch 1 taken 3077 times.
✓ Branch 2 taken 1812 times.
✓ Branch 3 taken 4544 times.
|
9433 | if ((mvf->pred_flag & masky) && rpl[ly].refs[mvf->ref_idx[ly]].poc == poc) { |
1774 | 1812 | available = 1; | |
1775 | 1812 | *cp = mvf->mv[ly]; | |
1776 | } | ||
1777 | } | ||
1778 |
2/2✓ Branch 0 taken 15981 times.
✓ Branch 1 taken 7621 times.
|
23602 | if (available) { |
1779 | 15981 | ff_vvc_round_mv(cp, amvr_shift, amvr_shift); | |
1780 | 15981 | return 1; | |
1781 | } | ||
1782 | } | ||
1783 | } | ||
1784 | 8187 | return 0; | |
1785 | } | ||
1786 | |||
1787 | #define AFFINE_MVP_CONSTRUCTED_CP(cands, cp) \ | ||
1788 | affine_mvp_constructed_cp(nctx, cands, FF_ARRAY_ELEMS(cands), lx, ref_idx, \ | ||
1789 | amvr_shift, cp) | ||
1790 | |||
1791 | //8.5.5.8 Derivation process for constructed affine control point motion vector prediction candidates | ||
1792 | 8056 | static int affine_mvp_const1(NeighbourContext* nctx, | |
1793 | const int lx, const int8_t ref_idx, const int amvr_shift, | ||
1794 | Mv *cps, int *available) | ||
1795 | { | ||
1796 | 8056 | const NeighbourIdx tl[] = { B2, B3, A2 }; | |
1797 | 8056 | const NeighbourIdx tr[] = { B1, B0 }; | |
1798 | 8056 | const NeighbourIdx bl[] = { A1, A0 }; | |
1799 | |||
1800 | 8056 | available[0] = AFFINE_MVP_CONSTRUCTED_CP(tl, cps + 0); | |
1801 | 8056 | available[1] = AFFINE_MVP_CONSTRUCTED_CP(tr, cps + 1); | |
1802 | 8056 | available[2] = AFFINE_MVP_CONSTRUCTED_CP(bl, cps + 2); | |
1803 |
4/4✓ Branch 0 taken 6186 times.
✓ Branch 1 taken 1870 times.
✓ Branch 2 taken 4713 times.
✓ Branch 3 taken 1473 times.
|
8056 | return available[0] && available[1]; |
1804 | } | ||
1805 | |||
1806 | //8.5.5.7 item 7 | ||
1807 | 3579 | static void affine_mvp_const2(const int idx, Mv *cps, const int num_cp) | |
1808 | { | ||
1809 | 3579 | const Mv mv = cps[idx]; | |
1810 |
2/2✓ Branch 0 taken 8879 times.
✓ Branch 1 taken 3579 times.
|
12458 | for (int j = 0; j < num_cp; j++) |
1811 | 8879 | cps[j] = mv; | |
1812 | 3579 | } | |
1813 | |||
1814 | //8.5.5.7 Derivation process for luma affine control point motion vector predictors | ||
1815 | 12166 | static void affine_mvp(const VVCLocalContext *lc, | |
1816 | const int mvp_lx_flag, const int lx, const int8_t *ref_idx, const int amvr_shift, | ||
1817 | MotionModelIdc motion_model_idc, Mv *cps) | ||
1818 | { | ||
1819 | 12166 | const NeighbourIdx ak[] = { A0, A1 }; | |
1820 | 12166 | const NeighbourIdx bk[] = { B0, B1, B2 }; | |
1821 | 12166 | const int num_cp = motion_model_idc + 1; | |
1822 | NeighbourContext nctx; | ||
1823 | int available[MAX_CONTROL_POINTS]; | ||
1824 | 12166 | int num_cands = 0; | |
1825 | |||
1826 | 12166 | init_neighbour_context(&nctx, lc); | |
1827 | //Ak | ||
1828 |
2/2✓ Branch 1 taken 2972 times.
✓ Branch 2 taken 9194 times.
|
12166 | if (AFFINE_MVP_FROM_NBS(ak)) { |
1829 |
2/2✓ Branch 0 taken 1990 times.
✓ Branch 1 taken 982 times.
|
2972 | if (mvp_lx_flag == num_cands) |
1830 | 11435 | return; | |
1831 | 982 | num_cands++; | |
1832 | } | ||
1833 | //Bk | ||
1834 |
2/2✓ Branch 1 taken 2927 times.
✓ Branch 2 taken 7249 times.
|
10176 | if (AFFINE_MVP_FROM_NBS(bk)) { |
1835 |
2/2✓ Branch 0 taken 2120 times.
✓ Branch 1 taken 807 times.
|
2927 | if (mvp_lx_flag == num_cands) |
1836 | 2120 | return; | |
1837 | 807 | num_cands++; | |
1838 | } | ||
1839 | |||
1840 | //Const1 | ||
1841 |
2/2✓ Branch 1 taken 4713 times.
✓ Branch 2 taken 3343 times.
|
8056 | if (affine_mvp_const1(&nctx, lx, ref_idx[lx], amvr_shift, cps, available)) { |
1842 |
4/4✓ Branch 0 taken 1270 times.
✓ Branch 1 taken 3443 times.
✓ Branch 2 taken 725 times.
✓ Branch 3 taken 545 times.
|
4713 | if (available[2] || motion_model_idc == MOTION_4_PARAMS_AFFINE) { |
1843 |
2/2✓ Branch 0 taken 2877 times.
✓ Branch 1 taken 1291 times.
|
4168 | if (mvp_lx_flag == num_cands) |
1844 | 2877 | return; | |
1845 | 1291 | num_cands++; | |
1846 | } | ||
1847 | } | ||
1848 | |||
1849 | //Const2 | ||
1850 |
2/2✓ Branch 0 taken 10400 times.
✓ Branch 1 taken 1600 times.
|
12000 | for (int i = 2; i >= 0; i--) { |
1851 |
2/2✓ Branch 0 taken 4140 times.
✓ Branch 1 taken 6260 times.
|
10400 | if (available[i]) { |
1852 |
2/2✓ Branch 0 taken 3579 times.
✓ Branch 1 taken 561 times.
|
4140 | if (mvp_lx_flag == num_cands) { |
1853 | 3579 | affine_mvp_const2(i, cps, num_cp); | |
1854 | 3579 | return; | |
1855 | } | ||
1856 | 561 | num_cands++; | |
1857 | } | ||
1858 | } | ||
1859 |
2/2✓ Branch 1 taken 1073 times.
✓ Branch 2 taken 527 times.
|
1600 | if (temporal_luma_motion_vector(lc, ref_idx[lx], cps, lx, 1, 0)) { |
1860 |
2/2✓ Branch 0 taken 869 times.
✓ Branch 1 taken 204 times.
|
1073 | if (mvp_lx_flag == num_cands) { |
1861 | 869 | ff_vvc_round_mv(cps, amvr_shift, amvr_shift); | |
1862 |
2/2✓ Branch 0 taken 1150 times.
✓ Branch 1 taken 869 times.
|
2019 | for (int i = 1; i < num_cp; i++) |
1863 | 1150 | cps[i] = cps[0]; | |
1864 | 869 | return; | |
1865 | } | ||
1866 | 204 | num_cands++; | |
1867 | } | ||
1868 | |||
1869 | //Zero Mv | ||
1870 | 731 | memset(cps, 0, num_cp * sizeof(Mv)); | |
1871 | } | ||
1872 | |||
1873 | 9947 | void ff_vvc_affine_mvp(VVCLocalContext *lc, const int *mvp_lx_flag, const int amvr_shift, MotionInfo *mi) | |
1874 | { | ||
1875 | 9947 | const CodingUnit *cu = lc->cu; | |
1876 | |||
1877 | 9947 | mi->num_sb_x = cu->cb_width >> MIN_PU_LOG2; | |
1878 | 9947 | mi->num_sb_y = cu->cb_height >> MIN_PU_LOG2; | |
1879 | |||
1880 | 9947 | ff_vvc_set_neighbour_available(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height); | |
1881 |
2/2✓ Branch 0 taken 8767 times.
✓ Branch 1 taken 1180 times.
|
9947 | if (mi->pred_flag != PF_L1) |
1882 | 8767 | affine_mvp(lc, mvp_lx_flag[L0], L0, mi->ref_idx, amvr_shift, mi->motion_model_idc, &mi->mv[L0][0]); | |
1883 |
2/2✓ Branch 0 taken 3399 times.
✓ Branch 1 taken 6548 times.
|
9947 | if (mi->pred_flag != PF_L0) |
1884 | 3399 | affine_mvp(lc, mvp_lx_flag[L1], L1, mi->ref_idx, amvr_shift, mi->motion_model_idc, &mi->mv[L1][0]); | |
1885 | 9947 | } | |
1886 | |||
1887 | //8.5.2.14 Rounding process for motion vectors | ||
1888 | 7602307 | void ff_vvc_round_mv(Mv *mv, const int lshift, const int rshift) | |
1889 | { | ||
1890 |
2/2✓ Branch 0 taken 7583633 times.
✓ Branch 1 taken 18674 times.
|
7602307 | if (rshift) { |
1891 | 7583633 | const int offset = 1 << (rshift - 1); | |
1892 | 7583633 | mv->x = ((mv->x + offset - (mv->x >= 0)) >> rshift) * (1 << lshift); | |
1893 | 7583633 | mv->y = ((mv->y + offset - (mv->y >= 0)) >> rshift) * (1 << lshift); | |
1894 | } else { | ||
1895 | 18674 | mv->x = mv->x * (1 << lshift); | |
1896 | 18674 | mv->y = mv->y * (1 << lshift); | |
1897 | } | ||
1898 | 7602307 | } | |
1899 | |||
1900 | 5299524 | void ff_vvc_clip_mv(Mv *mv) | |
1901 | { | ||
1902 | 5299524 | mv->x = av_clip(mv->x, -(1 << 17), (1 << 17) - 1); | |
1903 | 5299524 | mv->y = av_clip(mv->y, -(1 << 17), (1 << 17) - 1); | |
1904 | 5299524 | } | |
1905 | |||
1906 | //8.5.2.1 Derivation process for motion vector components and reference indices | ||
1907 | 338415 | static av_always_inline int is_greater_mer(const VVCFrameContext *fc, const int x0, const int y0, const int x0_br, const int y0_br) | |
1908 | { | ||
1909 | 338415 | const uint8_t plevel = fc->ps.sps->log2_parallel_merge_level; | |
1910 | |||
1911 |
2/2✓ Branch 0 taken 328291 times.
✓ Branch 1 taken 10124 times.
|
666706 | return x0_br >> plevel > x0 >> plevel && |
1912 |
2/2✓ Branch 0 taken 323519 times.
✓ Branch 1 taken 4772 times.
|
328291 | y0_br >> plevel > y0 >> plevel; |
1913 | } | ||
1914 | |||
1915 | 337119 | static void update_hmvp(MvField *hmvp, int *num_hmvp, const MvField *mvf, | |
1916 | int (*compare)(const MvField *n, const MvField *o)) | ||
1917 | { | ||
1918 | int i; | ||
1919 |
2/2✓ Branch 0 taken 1418063 times.
✓ Branch 1 taken 180843 times.
|
1598906 | for (i = 0; i < *num_hmvp; i++) { |
1920 |
2/2✓ Branch 1 taken 156276 times.
✓ Branch 2 taken 1261787 times.
|
1418063 | if (compare(mvf, hmvp + i)) { |
1921 | 156276 | (*num_hmvp)--; | |
1922 | 156276 | break; | |
1923 | } | ||
1924 | } | ||
1925 |
2/2✓ Branch 0 taken 158975 times.
✓ Branch 1 taken 178144 times.
|
337119 | if (i == MAX_NUM_HMVP_CANDS) { |
1926 | 158975 | (*num_hmvp)--; | |
1927 | 158975 | i = 0; | |
1928 | } | ||
1929 | |||
1930 | 337119 | memmove(hmvp + i, hmvp + i + 1, (*num_hmvp - i) * sizeof(MvField)); | |
1931 | 337119 | hmvp[(*num_hmvp)++] = *mvf; | |
1932 | 337119 | } | |
1933 | |||
1934 | 48432 | static int compare_l0_mv(const MvField *n, const MvField *o) | |
1935 | { | ||
1936 | 48432 | return IS_SAME_MV(&n->mv[L0], &o->mv[L0]); | |
1937 | } | ||
1938 | |||
1939 | //8.6.2.4 Derivation process for IBC history-based block vector candidates | ||
1940 | //8.5.2.16 Updating process for the history-based motion vector predictor candidate list | ||
1941 | 369597 | void ff_vvc_update_hmvp(VVCLocalContext *lc, const MotionInfo *mi) | |
1942 | { | ||
1943 | 369597 | const VVCFrameContext *fc = lc->fc; | |
1944 | 369597 | const CodingUnit *cu = lc->cu; | |
1945 | 369597 | const int min_pu_width = fc->ps.pps->min_pu_width; | |
1946 | 369597 | const MvField *tab_mvf = fc->tab.mvf; | |
1947 | 369597 | EntryPoint *ep = lc->ep; | |
1948 | |||
1949 |
2/2✓ Branch 0 taken 31182 times.
✓ Branch 1 taken 338415 times.
|
369597 | if (cu->pred_mode == MODE_IBC) { |
1950 |
2/2✓ Branch 0 taken 17582 times.
✓ Branch 1 taken 13600 times.
|
31182 | if (cu->cb_width * cu->cb_height <= 16) |
1951 | 17582 | return; | |
1952 | 13600 | update_hmvp(ep->hmvp_ibc, &ep->num_hmvp_ibc, &TAB_MVF(cu->x0, cu->y0), compare_l0_mv); | |
1953 | } else { | ||
1954 |
2/2✓ Branch 1 taken 14896 times.
✓ Branch 2 taken 323519 times.
|
338415 | if (!is_greater_mer(fc, cu->x0, cu->y0, cu->x0 + cu->cb_width, cu->y0 + cu->cb_height)) |
1955 | 14896 | return; | |
1956 | 323519 | update_hmvp(ep->hmvp, &ep->num_hmvp, &TAB_MVF(cu->x0, cu->y0), compare_mv_ref_idx); | |
1957 | } | ||
1958 | } | ||
1959 | |||
1960 | 12257218 | MvField* ff_vvc_get_mvf(const VVCFrameContext *fc, const int x0, const int y0) | |
1961 | { | ||
1962 | 12257218 | const int min_pu_width = fc->ps.pps->min_pu_width; | |
1963 | 12257218 | MvField* tab_mvf = fc->tab.mvf; | |
1964 | |||
1965 | 12257218 | return &TAB_MVF(x0, y0); | |
1966 | } | ||
1967 |