FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vvc/inter.c
Date: 2024-05-03 15:42:48
Exec Total Coverage
Lines: 590 599 98.5%
Functions: 31 31 100.0%
Branches: 257 278 92.4%

Line Branch Exec Source
1 /*
2 * VVC inter prediction
3 *
4 * Copyright (C) 2022 Nuo Mi
5 *
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 #include "libavutil/frame.h"
23
24 #include "data.h"
25 #include "inter.h"
26 #include "mvs.h"
27 #include "refs.h"
28
29 // +1 is enough, + 32 for asm alignment
30 #define PROF_TEMP_OFFSET (MAX_PB_SIZE + 32)
31 static const int bcw_w_lut[] = {4, 5, 3, 10, -2};
32
33 25809482 static void subpic_offset(int *x_off, int *y_off,
34 const VVCSPS *sps, const VVCPPS *pps, const int subpic_idx, const int is_luma)
35 {
36 25809482 *x_off -= pps->subpic_x[subpic_idx] >> sps->hshift[!is_luma];
37 25809482 *y_off -= pps->subpic_y[subpic_idx] >> sps->vshift[!is_luma];
38 25809482 }
39
40 19924158 static void subpic_width_height(int *pic_width, int *pic_height,
41 const VVCSPS *sps, const VVCPPS *pps, const int subpic_idx, const int is_luma)
42 {
43 19924158 *pic_width = pps->subpic_width[subpic_idx] >> sps->hshift[!is_luma];
44 19924158 *pic_height = pps->subpic_height[subpic_idx] >> sps->vshift[!is_luma];
45 19924158 }
46
47 12066102 static int emulated_edge(const VVCLocalContext *lc, uint8_t *dst, const uint8_t **src, ptrdiff_t *src_stride,
48 int x_off, int y_off, const int block_w, const int block_h, const int is_luma)
49 {
50 12066102 const VVCFrameContext *fc = lc->fc;
51 12066102 const VVCSPS *sps = fc->ps.sps;
52 12066102 const VVCPPS *pps = fc->ps.pps;
53 12066102 const int subpic_idx = lc->sc->sh.r->curr_subpic_idx;
54
2/2
✓ Branch 0 taken 5702438 times.
✓ Branch 1 taken 6363664 times.
12066102 const int extra_before = is_luma ? LUMA_EXTRA_BEFORE : CHROMA_EXTRA_BEFORE;
55
2/2
✓ Branch 0 taken 5702438 times.
✓ Branch 1 taken 6363664 times.
12066102 const int extra_after = is_luma ? LUMA_EXTRA_AFTER : CHROMA_EXTRA_AFTER;
56
2/2
✓ Branch 0 taken 5702438 times.
✓ Branch 1 taken 6363664 times.
12066102 const int extra = is_luma ? LUMA_EXTRA : CHROMA_EXTRA;
57 int pic_width, pic_height;
58
59 12066102 subpic_offset(&x_off, &y_off, sps, pps, subpic_idx, is_luma);
60 12066102 subpic_width_height(&pic_width, &pic_height, sps, pps, subpic_idx, is_luma);
61
62
4/4
✓ Branch 0 taken 12020079 times.
✓ Branch 1 taken 46023 times.
✓ Branch 2 taken 11921493 times.
✓ Branch 3 taken 98586 times.
12066102 if (x_off < extra_before || y_off < extra_before ||
63
2/2
✓ Branch 0 taken 11857503 times.
✓ Branch 1 taken 63990 times.
11921493 x_off >= pic_width - block_w - extra_after ||
64
2/2
✓ Branch 0 taken 116329 times.
✓ Branch 1 taken 11741174 times.
11857503 y_off >= pic_height - block_h - extra_after) {
65 324928 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << fc->ps.sps->pixel_shift;
66 324928 int offset = extra_before * *src_stride + (extra_before << fc->ps.sps->pixel_shift);
67 324928 int buf_offset = extra_before * edge_emu_stride + (extra_before << fc->ps.sps->pixel_shift);
68
69 324928 fc->vdsp.emulated_edge_mc(dst, *src - offset, edge_emu_stride, *src_stride,
70 block_w + extra, block_h + extra, x_off - extra_before, y_off - extra_before,
71 pic_width, pic_height);
72
73 324928 *src = dst + buf_offset;
74 324928 *src_stride = edge_emu_stride;
75 324928 return 1;
76 }
77 11741174 return 0;
78 }
79
80 5885324 static void emulated_edge_dmvr(const VVCLocalContext *lc, uint8_t *dst, const uint8_t **src, ptrdiff_t *src_stride,
81 int x_sb, int y_sb, int x_off, int y_off, const int block_w, const int block_h, const int is_luma)
82 {
83 5885324 const VVCFrameContext *fc = lc->fc;
84 5885324 const VVCSPS *sps = fc->ps.sps;
85 5885324 const VVCPPS *pps = fc->ps.pps;
86 5885324 const int subpic_idx = lc->sc->sh.r->curr_subpic_idx;
87
2/2
✓ Branch 0 taken 1972732 times.
✓ Branch 1 taken 3912592 times.
5885324 const int extra_before = is_luma ? LUMA_EXTRA_BEFORE : CHROMA_EXTRA_BEFORE;
88
2/2
✓ Branch 0 taken 1972732 times.
✓ Branch 1 taken 3912592 times.
5885324 const int extra_after = is_luma ? LUMA_EXTRA_AFTER : CHROMA_EXTRA_AFTER;
89
2/2
✓ Branch 0 taken 1972732 times.
✓ Branch 1 taken 3912592 times.
5885324 const int extra = is_luma ? LUMA_EXTRA : CHROMA_EXTRA;
90 int pic_width, pic_height;
91
92 5885324 subpic_offset(&x_off, &y_off, sps, pps, subpic_idx, is_luma);
93 5885324 subpic_offset(&x_sb, &y_sb, sps, pps, subpic_idx, is_luma);
94 5885324 subpic_width_height(&pic_width, &pic_height, sps, pps, subpic_idx, is_luma);
95
96
4/4
✓ Branch 0 taken 5824479 times.
✓ Branch 1 taken 60845 times.
✓ Branch 2 taken 5718300 times.
✓ Branch 3 taken 106179 times.
5885324 if (x_off < extra_before || y_off < extra_before ||
97
2/2
✓ Branch 0 taken 5655449 times.
✓ Branch 1 taken 62851 times.
5718300 x_off >= pic_width - block_w - extra_after ||
98
2/2
✓ Branch 0 taken 5560964 times.
✓ Branch 1 taken 94485 times.
5655449 y_off >= pic_height - block_h - extra_after||
99
4/4
✓ Branch 0 taken 4245342 times.
✓ Branch 1 taken 1315622 times.
✓ Branch 2 taken 398998 times.
✓ Branch 3 taken 3846344 times.
5560964 (x_off != x_sb || y_off != y_sb)) {
100 2038980 const int ps = fc->ps.sps->pixel_shift;
101 2038980 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << ps;
102 2038980 const int offset = extra_before * *src_stride + (extra_before << ps);
103 2038980 const int buf_offset = extra_before * edge_emu_stride + (extra_before << ps);
104
105
2/2
✓ Branch 0 taken 435 times.
✓ Branch 1 taken 2038545 times.
2038980 const int start_x = FFMIN(FFMAX(x_sb - extra_before, 0), pic_width - 1);
106
2/2
✓ Branch 0 taken 2812 times.
✓ Branch 1 taken 2036168 times.
2038980 const int start_y = FFMIN(FFMAX(y_sb - extra_before, 0), pic_height - 1);
107 2038980 const int width = FFMAX(FFMIN(pic_width, x_sb + block_w + extra_after) - start_x, 1);
108 2038980 const int height = FFMAX(FFMIN(pic_height, y_sb + block_h + extra_after) - start_y, 1);
109
110 2038980 fc->vdsp.emulated_edge_mc(dst, *src - offset, edge_emu_stride, *src_stride, block_w + extra, block_h + extra,
111 2038980 x_off - start_x - extra_before, y_off - start_y - extra_before, width, height);
112
113 2038980 *src = dst + buf_offset;
114 2038980 *src_stride = edge_emu_stride;
115 }
116 5885324 }
117
118 1972732 static void emulated_edge_bilinear(const VVCLocalContext *lc, uint8_t *dst, const uint8_t **src, ptrdiff_t *src_stride,
119 int x_off, int y_off, const int block_w, const int block_h)
120 {
121 1972732 const VVCFrameContext *fc = lc->fc;
122 1972732 const VVCSPS *sps = fc->ps.sps;
123 1972732 const VVCPPS *pps = fc->ps.pps;
124 1972732 const int subpic_idx = lc->sc->sh.r->curr_subpic_idx;
125 int pic_width, pic_height;
126
127 1972732 subpic_offset(&x_off, &y_off, sps, pps, subpic_idx, 1);
128 1972732 subpic_width_height(&pic_width, &pic_height, sps, pps, subpic_idx, 1);
129
130
4/4
✓ Branch 0 taken 1952317 times.
✓ Branch 1 taken 20415 times.
✓ Branch 2 taken 1916761 times.
✓ Branch 3 taken 35556 times.
1972732 if (x_off < BILINEAR_EXTRA_BEFORE || y_off < BILINEAR_EXTRA_BEFORE ||
131
2/2
✓ Branch 0 taken 1896059 times.
✓ Branch 1 taken 20702 times.
1916761 x_off >= pic_width - block_w - BILINEAR_EXTRA_AFTER ||
132
2/2
✓ Branch 0 taken 31207 times.
✓ Branch 1 taken 1864852 times.
1896059 y_off >= pic_height - block_h - BILINEAR_EXTRA_AFTER) {
133 107880 const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << fc->ps.sps->pixel_shift;
134 107880 const int offset = BILINEAR_EXTRA_BEFORE * *src_stride + (BILINEAR_EXTRA_BEFORE << fc->ps.sps->pixel_shift);
135 107880 const int buf_offset = BILINEAR_EXTRA_BEFORE * edge_emu_stride + (BILINEAR_EXTRA_BEFORE << fc->ps.sps->pixel_shift);
136
137 107880 fc->vdsp.emulated_edge_mc(dst, *src - offset, edge_emu_stride, *src_stride, block_w + BILINEAR_EXTRA, block_h + BILINEAR_EXTRA,
138 x_off - BILINEAR_EXTRA_BEFORE, y_off - BILINEAR_EXTRA_BEFORE, pic_width, pic_height);
139
140 107880 *src = dst + buf_offset;
141 107880 *src_stride = edge_emu_stride;
142 }
143 1972732 }
144
145
146 #define EMULATED_EDGE_LUMA(dst, src, src_stride, x_off, y_off) \
147 emulated_edge(lc, dst, src, src_stride, x_off, y_off, block_w, block_h, 1)
148
149 #define EMULATED_EDGE_CHROMA(dst, src, src_stride, x_off, y_off) \
150 emulated_edge(lc, dst, src, src_stride, x_off, y_off, block_w, block_h, 0)
151
152 #define EMULATED_EDGE_DMVR_LUMA(dst, src, src_stride, x_sb, y_sb, x_off, y_off) \
153 emulated_edge_dmvr(lc, dst, src, src_stride, x_sb, y_sb, x_off, y_off, block_w, block_h, 1)
154
155 #define EMULATED_EDGE_DMVR_CHROMA(dst, src, src_stride, x_sb, y_sb, x_off, y_off) \
156 emulated_edge_dmvr(lc, dst, src, src_stride, x_sb, y_sb, x_off, y_off, block_w, block_h, 0)
157
158 #define EMULATED_EDGE_BILINEAR(dst, src, src_stride, x_off, y_off) \
159 emulated_edge_bilinear(lc, dst, src, src_stride, x_off, y_off, pred_w, pred_h)
160
161 // part of 8.5.6.6 Weighted sample prediction process
162 5584642 static int derive_weight_uni(int *denom, int *wx, int *ox,
163 const VVCLocalContext *lc, const MvField *mvf, const int c_idx)
164 {
165 5584642 const VVCFrameContext *fc = lc->fc;
166 5584642 const VVCPPS *pps = fc->ps.pps;
167 5584642 const VVCSH *sh = &lc->sc->sh;
168
3/4
✓ Branch 0 taken 1593390 times.
✓ Branch 1 taken 3991252 times.
✓ Branch 2 taken 1593390 times.
✗ Branch 3 not taken.
11169284 const int weight_flag = (IS_P(sh->r) && pps->r->pps_weighted_pred_flag) ||
169
4/4
✓ Branch 0 taken 3991252 times.
✓ Branch 1 taken 1593390 times.
✓ Branch 2 taken 22668 times.
✓ Branch 3 taken 3968584 times.
5584642 (IS_B(sh->r) && pps->r->pps_weighted_bipred_flag);
170
2/2
✓ Branch 0 taken 22668 times.
✓ Branch 1 taken 5561974 times.
5584642 if (weight_flag) {
171 22668 const int lx = mvf->pred_flag - PF_L0;
172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22668 times.
22668 const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt;
173
174 22668 *denom = w->log2_denom[c_idx > 0];
175 22668 *wx = w->weight[lx][c_idx][mvf->ref_idx[lx]];
176 22668 *ox = w->offset[lx][c_idx][mvf->ref_idx[lx]];
177 }
178 5584642 return weight_flag;
179 }
180
181 // part of 8.5.6.6 Weighted sample prediction process
182 6114760 static int derive_weight(int *denom, int *w0, int *w1, int *o0, int *o1,
183 const VVCLocalContext *lc, const MvField *mvf, const int c_idx, const int dmvr_flag)
184 {
185 6114760 const VVCFrameContext *fc = lc->fc;
186 6114760 const VVCPPS *pps = fc->ps.pps;
187 6114760 const VVCSH *sh = &lc->sc->sh;
188 6114760 const int bcw_idx = mvf->bcw_idx;
189
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6114760 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12229520 const int weight_flag = (IS_P(sh->r) && pps->r->pps_weighted_pred_flag) ||
190
4/6
✓ Branch 0 taken 6114760 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16347 times.
✓ Branch 3 taken 6098413 times.
✓ Branch 4 taken 16347 times.
✗ Branch 5 not taken.
6114760 (IS_B(sh->r) && pps->r->pps_weighted_bipred_flag && !dmvr_flag);
191
8/8
✓ Branch 0 taken 6098413 times.
✓ Branch 1 taken 16347 times.
✓ Branch 2 taken 500326 times.
✓ Branch 3 taken 5598087 times.
✓ Branch 4 taken 500326 times.
✓ Branch 5 taken 16347 times.
✓ Branch 6 taken 3703 times.
✓ Branch 7 taken 496623 times.
6114760 if ((!weight_flag && !bcw_idx) || (bcw_idx && lc->cu->ciip_flag))
192 5601790 return 0;
193
194
2/2
✓ Branch 0 taken 496623 times.
✓ Branch 1 taken 16347 times.
512970 if (bcw_idx) {
195 496623 *denom = 2;
196 496623 *w1 = bcw_w_lut[bcw_idx];
197 496623 *w0 = 8 - *w1;
198 496623 *o0 = *o1 = 0;
199 } else {
200 16347 const VVCPPS *pps = fc->ps.pps;
201
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16347 times.
16347 const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt;
202
203 16347 *denom = w->log2_denom[c_idx > 0];
204 16347 *w0 = w->weight[L0][c_idx][mvf->ref_idx[L0]];
205 16347 *w1 = w->weight[L1][c_idx][mvf->ref_idx[L1]];
206 16347 *o0 = w->offset[L0][c_idx][mvf->ref_idx[L0]];
207 16347 *o1 = w->offset[L1][c_idx][mvf->ref_idx[L1]];
208 }
209 512970 return 1;
210 }
211
212 48796 static void luma_mc(VVCLocalContext *lc, int16_t *dst, const AVFrame *ref, const Mv *mv,
213 int x_off, int y_off, const int block_w, const int block_h)
214 {
215 48796 const VVCFrameContext *fc = lc->fc;
216 48796 const uint8_t *src = ref->data[0];
217 48796 ptrdiff_t src_stride = ref->linesize[0];
218 48796 const int idx = av_log2(block_w) - 1;
219 48796 const int mx = mv->x & 0xf;
220 48796 const int my = mv->y & 0xf;
221 48796 const int8_t *hf = ff_vvc_inter_luma_filters[0][mx];
222 48796 const int8_t *vf = ff_vvc_inter_luma_filters[0][my];
223
224 48796 x_off += mv->x >> 4;
225 48796 y_off += mv->y >> 4;
226 48796 src += y_off * src_stride + (x_off * (1 << fc->ps.sps->pixel_shift));
227
228 48796 EMULATED_EDGE_LUMA(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off);
229
230 48796 fc->vvcdsp.inter.put[LUMA][idx][!!my][!!mx](dst, src, src_stride, block_h, hf, vf, block_w);
231 48796 }
232
233 88468 static void chroma_mc(VVCLocalContext *lc, int16_t *dst, const AVFrame *ref, const Mv *mv,
234 int x_off, int y_off, const int block_w, const int block_h, const int c_idx)
235 {
236 88468 const VVCFrameContext *fc = lc->fc;
237 88468 const uint8_t *src = ref->data[c_idx];
238 88468 ptrdiff_t src_stride = ref->linesize[c_idx];
239 88468 int hs = fc->ps.sps->hshift[c_idx];
240 88468 int vs = fc->ps.sps->vshift[c_idx];
241 88468 const int idx = av_log2(block_w) - 1;
242 88468 const intptr_t mx = av_mod_uintp2(mv->x, 4 + hs) << (1 - hs);
243 88468 const intptr_t my = av_mod_uintp2(mv->y, 4 + vs) << (1 - vs);
244 88468 const int8_t *hf = ff_vvc_inter_chroma_filters[0][mx];
245 88468 const int8_t *vf = ff_vvc_inter_chroma_filters[0][my];
246
247 88468 x_off += mv->x >> (4 + hs);
248 88468 y_off += mv->y >> (4 + vs);
249 88468 src += y_off * src_stride + (x_off * (1 << fc->ps.sps->pixel_shift));
250
251 88468 EMULATED_EDGE_CHROMA(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off);
252 88468 fc->vvcdsp.inter.put[CHROMA][idx][!!my][!!mx](dst, src, src_stride, block_h, hf, vf, block_w);
253 88468 }
254
255 614666 static void luma_mc_uni(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride,
256 const AVFrame *ref, const MvField *mvf, int x_off, int y_off, const int block_w, const int block_h,
257 const int hf_idx, const int vf_idx)
258 {
259 614666 const VVCFrameContext *fc = lc->fc;
260 614666 const int lx = mvf->pred_flag - PF_L0;
261 614666 const Mv *mv = mvf->mv + lx;
262 614666 const uint8_t *src = ref->data[0];
263 614666 ptrdiff_t src_stride = ref->linesize[0];
264 614666 const int idx = av_log2(block_w) - 1;
265 614666 const int mx = mv->x & 0xf;
266 614666 const int my = mv->y & 0xf;
267 614666 const int8_t *hf = ff_vvc_inter_luma_filters[hf_idx][mx];
268 614666 const int8_t *vf = ff_vvc_inter_luma_filters[vf_idx][my];
269 int denom, wx, ox;
270
271 614666 x_off += mv->x >> 4;
272 614666 y_off += mv->y >> 4;
273 614666 src += y_off * src_stride + (x_off * (1 << fc->ps.sps->pixel_shift));
274
275 614666 EMULATED_EDGE_LUMA(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off);
276
277
2/2
✓ Branch 1 taken 4844 times.
✓ Branch 2 taken 609822 times.
614666 if (derive_weight_uni(&denom, &wx, &ox, lc, mvf, LUMA)) {
278 4844 fc->vvcdsp.inter.put_uni_w[LUMA][idx][!!my][!!mx](dst, dst_stride, src, src_stride,
279 block_h, denom, wx, ox, hf, vf, block_w);
280 } else {
281 609822 fc->vvcdsp.inter.put_uni[LUMA][idx][!!my][!!mx](dst, dst_stride, src, src_stride,
282 block_h, hf, vf, block_w);
283 }
284 614666 }
285
286 1512034 static void luma_mc_bi(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride,
287 const AVFrame *ref0, const Mv *mv0, const int x_off, const int y_off, const int block_w, const int block_h,
288 const AVFrame *ref1, const Mv *mv1, const MvField *mvf, const int hf_idx, const int vf_idx,
289 const MvField *orig_mv, const int sb_bdof_flag)
290 {
291 1512034 const VVCFrameContext *fc = lc->fc;
292 1512034 const PredictionUnit *pu = &lc->cu->pu;
293 1512034 const int idx = av_log2(block_w) - 1;
294 1512034 const AVFrame *ref[] = { ref0, ref1 };
295 1512034 int16_t *tmp[] = { lc->tmp + sb_bdof_flag * PROF_TEMP_OFFSET, lc->tmp1 + sb_bdof_flag * PROF_TEMP_OFFSET };
296 int denom, w0, w1, o0, o1;
297 1512034 const int weight_flag = derive_weight(&denom, &w0, &w1, &o0, &o1, lc, mvf, LUMA, pu->dmvr_flag);
298
299
2/2
✓ Branch 0 taken 3024068 times.
✓ Branch 1 taken 1512034 times.
4536102 for (int i = L0; i <= L1; i++) {
300 3024068 const Mv *mv = mvf->mv + i;
301 3024068 const int mx = mv->x & 0xf;
302 3024068 const int my = mv->y & 0xf;
303 3024068 const int ox = x_off + (mv->x >> 4);
304 3024068 const int oy = y_off + (mv->y >> 4);
305 3024068 ptrdiff_t src_stride = ref[i]->linesize[0];
306 3024068 const uint8_t *src = ref[i]->data[0] + oy * src_stride + (ox * (1 << fc->ps.sps->pixel_shift));
307 3024068 const int8_t *hf = ff_vvc_inter_luma_filters[hf_idx][mx];
308 3024068 const int8_t *vf = ff_vvc_inter_luma_filters[vf_idx][my];
309
310
2/2
✓ Branch 0 taken 1972732 times.
✓ Branch 1 taken 1051336 times.
3024068 if (pu->dmvr_flag) {
311 1972732 const int x_sb = x_off + (orig_mv->mv[i].x >> 4);
312 1972732 const int y_sb = y_off + (orig_mv->mv[i].y >> 4);
313
314 1972732 EMULATED_EDGE_DMVR_LUMA(lc->edge_emu_buffer, &src, &src_stride, x_sb, y_sb, ox, oy);
315 } else {
316 1051336 EMULATED_EDGE_LUMA(lc->edge_emu_buffer, &src, &src_stride, ox, oy);
317 }
318 3024068 fc->vvcdsp.inter.put[LUMA][idx][!!my][!!mx](tmp[i], src, src_stride, block_h, hf, vf, block_w);
319
2/2
✓ Branch 0 taken 700294 times.
✓ Branch 1 taken 2323774 times.
3024068 if (sb_bdof_flag)
320 700294 fc->vvcdsp.inter.bdof_fetch_samples(tmp[i], src, src_stride, mx, my, block_w, block_h);
321 }
322
323
2/2
✓ Branch 0 taken 350147 times.
✓ Branch 1 taken 1161887 times.
1512034 if (sb_bdof_flag)
324 350147 fc->vvcdsp.inter.apply_bdof(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h);
325
2/2
✓ Branch 0 taken 28432 times.
✓ Branch 1 taken 1133455 times.
1161887 else if (weight_flag)
326 28432 fc->vvcdsp.inter.w_avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h, denom, w0, w1, o0, o1);
327 else
328 1133455 fc->vvcdsp.inter.avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h);
329 1512034 }
330
331 2709216 static void chroma_mc_uni(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride,
332 const uint8_t *src, ptrdiff_t src_stride, int x_off, int y_off,
333 const int block_w, const int block_h, const MvField *mvf, const int c_idx,
334 const int hf_idx, const int vf_idx)
335 {
336 2709216 const VVCFrameContext *fc = lc->fc;
337 2709216 const int lx = mvf->pred_flag - PF_L0;
338 2709216 const int hs = fc->ps.sps->hshift[1];
339 2709216 const int vs = fc->ps.sps->vshift[1];
340 2709216 const int idx = av_log2(block_w) - 1;
341 2709216 const Mv *mv = &mvf->mv[lx];
342 2709216 const intptr_t mx = av_mod_uintp2(mv->x, 4 + hs) << (1 - hs);
343 2709216 const intptr_t my = av_mod_uintp2(mv->y, 4 + vs) << (1 - vs);
344 2709216 const int8_t *hf = ff_vvc_inter_chroma_filters[hf_idx][mx];
345 2709216 const int8_t *vf = ff_vvc_inter_chroma_filters[vf_idx][my];
346 int denom, wx, ox;
347
348 2709216 x_off += mv->x >> (4 + hs);
349 2709216 y_off += mv->y >> (4 + vs);
350 2709216 src += y_off * src_stride + (x_off * (1 << fc->ps.sps->pixel_shift));
351
352
353 2709216 EMULATED_EDGE_CHROMA(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off);
354
2/2
✓ Branch 1 taken 12400 times.
✓ Branch 2 taken 2696816 times.
2709216 if (derive_weight_uni(&denom, &wx, &ox, lc, mvf, c_idx)) {
355 12400 fc->vvcdsp.inter.put_uni_w[CHROMA][idx][!!my][!!mx](dst, dst_stride, src, src_stride,
356 block_h, denom, wx, ox, hf, vf, block_w);
357 } else {
358 2696816 fc->vvcdsp.inter.put_uni[CHROMA][idx][!!my][!!mx](dst, dst_stride, src, src_stride,
359 block_h, hf, vf, block_w);
360 }
361 2709216 }
362
363 3739286 static void chroma_mc_bi(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride,
364 const AVFrame *ref0, const AVFrame *ref1, const int x_off, const int y_off,
365 const int block_w, const int block_h, const MvField *mvf, const int c_idx,
366 const int hf_idx, const int vf_idx, const MvField *orig_mv, const int dmvr_flag, const int ciip_flag)
367 {
368 3739286 const VVCFrameContext *fc = lc->fc;
369 3739286 const int hs = fc->ps.sps->hshift[1];
370 3739286 const int vs = fc->ps.sps->vshift[1];
371 3739286 const int idx = av_log2(block_w) - 1;
372 3739286 const AVFrame *ref[] = { ref0, ref1 };
373 3739286 int16_t *tmp[] = { lc->tmp, lc->tmp1 };
374 int denom, w0, w1, o0, o1;
375 3739286 const int weight_flag = derive_weight(&denom, &w0, &w1, &o0, &o1, lc, mvf, c_idx, dmvr_flag);
376
377
2/2
✓ Branch 0 taken 7478572 times.
✓ Branch 1 taken 3739286 times.
11217858 for (int i = L0; i <= L1; i++) {
378 7478572 const Mv *mv = mvf->mv + i;
379 7478572 const int mx = av_mod_uintp2(mv->x, 4 + hs) << (1 - hs);
380 7478572 const int my = av_mod_uintp2(mv->y, 4 + vs) << (1 - vs);
381 7478572 const int ox = x_off + (mv->x >> (4 + hs));
382 7478572 const int oy = y_off + (mv->y >> (4 + vs));
383 7478572 ptrdiff_t src_stride = ref[i]->linesize[c_idx];
384 7478572 const uint8_t *src = ref[i]->data[c_idx] + oy * src_stride + (ox * (1 << fc->ps.sps->pixel_shift));
385 7478572 const int8_t *hf = ff_vvc_inter_chroma_filters[hf_idx][mx];
386 7478572 const int8_t *vf = ff_vvc_inter_chroma_filters[vf_idx][my];
387
2/2
✓ Branch 0 taken 3912592 times.
✓ Branch 1 taken 3565980 times.
7478572 if (dmvr_flag) {
388 3912592 const int x_sb = x_off + (orig_mv->mv[i].x >> (4 + hs));
389 3912592 const int y_sb = y_off + (orig_mv->mv[i].y >> (4 + vs));
390 3912592 EMULATED_EDGE_DMVR_CHROMA(lc->edge_emu_buffer, &src, &src_stride, x_sb, y_sb, ox, oy);
391 } else {
392 3565980 EMULATED_EDGE_CHROMA(lc->edge_emu_buffer, &src, &src_stride, ox, oy);
393 }
394 7478572 fc->vvcdsp.inter.put[CHROMA][idx][!!my][!!mx](tmp[i], src, src_stride, block_h, hf, vf, block_w);
395 }
396
2/2
✓ Branch 0 taken 281470 times.
✓ Branch 1 taken 3457816 times.
3739286 if (weight_flag)
397 281470 fc->vvcdsp.inter.w_avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h, denom, w0, w1, o0, o1);
398 else
399 3457816 fc->vvcdsp.inter.avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h);
400 3739286 }
401
402 2260760 static void luma_prof_uni(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride,
403 const AVFrame *ref, const MvField *mvf, int x_off, int y_off, const int block_w, const int block_h,
404 const int cb_prof_flag, const int16_t *diff_mv_x, const int16_t *diff_mv_y)
405 {
406 2260760 const VVCFrameContext *fc = lc->fc;
407 2260760 const uint8_t *src = ref->data[0];
408 2260760 ptrdiff_t src_stride = ref->linesize[0];
409 2260760 uint16_t *prof_tmp = lc->tmp + PROF_TEMP_OFFSET;
410 2260760 const int idx = av_log2(block_w) - 1;
411 2260760 const int lx = mvf->pred_flag - PF_L0;
412 2260760 const Mv *mv = mvf->mv + lx;
413 2260760 const int mx = mv->x & 0xf;
414 2260760 const int my = mv->y & 0xf;
415 2260760 const int8_t *hf = ff_vvc_inter_luma_filters[2][mx];
416 2260760 const int8_t *vf = ff_vvc_inter_luma_filters[2][my];
417 int denom, wx, ox;
418 2260760 const int weight_flag = derive_weight_uni(&denom, &wx, &ox, lc, mvf, LUMA);
419
420 2260760 x_off += mv->x >> 4;
421 2260760 y_off += mv->y >> 4;
422 2260760 src += y_off * src_stride + (x_off * (1 << fc->ps.sps->pixel_shift));
423
424 2260760 EMULATED_EDGE_LUMA(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off);
425
2/2
✓ Branch 0 taken 2104976 times.
✓ Branch 1 taken 155784 times.
2260760 if (cb_prof_flag) {
426 2104976 fc->vvcdsp.inter.put[LUMA][idx][!!my][!!mx](prof_tmp, src, src_stride, AFFINE_MIN_BLOCK_SIZE, hf, vf, AFFINE_MIN_BLOCK_SIZE);
427 2104976 fc->vvcdsp.inter.fetch_samples(prof_tmp, src, src_stride, mx, my);
428
2/2
✓ Branch 0 taken 2099692 times.
✓ Branch 1 taken 5284 times.
2104976 if (!weight_flag)
429 2099692 fc->vvcdsp.inter.apply_prof_uni(dst, dst_stride, prof_tmp, diff_mv_x, diff_mv_y);
430 else
431 5284 fc->vvcdsp.inter.apply_prof_uni_w(dst, dst_stride, prof_tmp, diff_mv_x, diff_mv_y, denom, wx, ox);
432 } else {
433
2/2
✓ Branch 0 taken 155644 times.
✓ Branch 1 taken 140 times.
155784 if (!weight_flag)
434 155644 fc->vvcdsp.inter.put_uni[LUMA][idx][!!my][!!mx](dst, dst_stride, src, src_stride, block_h, hf, vf, block_w);
435 else
436 140 fc->vvcdsp.inter.put_uni_w[LUMA][idx][!!my][!!mx](dst, dst_stride, src, src_stride, block_h, denom, wx, ox, hf, vf, block_w);
437 }
438 2260760 }
439
440 863440 static void luma_prof_bi(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride,
441 const AVFrame *ref0, const AVFrame *ref1, const MvField *mvf, const int x_off, const int y_off,
442 const int block_w, const int block_h)
443 {
444 863440 const VVCFrameContext *fc = lc->fc;
445 863440 const PredictionUnit *pu = &lc->cu->pu;
446 863440 const AVFrame *ref[] = { ref0, ref1 };
447 863440 int16_t *tmp[] = { lc->tmp, lc->tmp1 };
448 863440 uint16_t *prof_tmp = lc->tmp2 + PROF_TEMP_OFFSET;
449 863440 const int idx = av_log2(block_w) - 1;
450 int denom, w0, w1, o0, o1;
451 863440 const int weight_flag = derive_weight(&denom, &w0, &w1, &o0, &o1, lc, mvf, LUMA, 0);
452
453
2/2
✓ Branch 0 taken 1726880 times.
✓ Branch 1 taken 863440 times.
2590320 for (int i = L0; i <= L1; i++) {
454 1726880 const Mv *mv = mvf->mv + i;
455 1726880 const int mx = mv->x & 0xf;
456 1726880 const int my = mv->y & 0xf;
457 1726880 const int ox = x_off + (mv->x >> 4);
458 1726880 const int oy = y_off + (mv->y >> 4);
459 1726880 ptrdiff_t src_stride = ref[i]->linesize[0];
460 1726880 const uint8_t *src = ref[i]->data[0] + oy * src_stride + (ox * (1 << fc->ps.sps->pixel_shift));
461 1726880 const int8_t *hf = ff_vvc_inter_luma_filters[2][mx];
462 1726880 const int8_t *vf = ff_vvc_inter_luma_filters[2][my];
463
464 1726880 EMULATED_EDGE_LUMA(lc->edge_emu_buffer, &src, &src_stride, ox, oy);
465
2/2
✓ Branch 0 taken 363864 times.
✓ Branch 1 taken 1363016 times.
1726880 if (!pu->cb_prof_flag[i]) {
466 363864 fc->vvcdsp.inter.put[LUMA][idx][!!my][!!mx](tmp[i], src, src_stride, block_h, hf, vf, block_w);
467 } else {
468 1363016 fc->vvcdsp.inter.put[LUMA][idx][!!my][!!mx](prof_tmp, src, src_stride, AFFINE_MIN_BLOCK_SIZE, hf, vf, AFFINE_MIN_BLOCK_SIZE);
469 1363016 fc->vvcdsp.inter.fetch_samples(prof_tmp, src, src_stride, mx, my);
470 1363016 fc->vvcdsp.inter.apply_prof(tmp[i], prof_tmp, pu->diff_mv_x[i], pu->diff_mv_y[i]);
471 }
472 }
473
474
2/2
✓ Branch 0 taken 203068 times.
✓ Branch 1 taken 660372 times.
863440 if (weight_flag)
475 203068 fc->vvcdsp.inter.w_avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h, denom, w0, w1, o0, o1);
476 else
477 660372 fc->vvcdsp.inter.avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h);
478 863440 }
479
480 9461517 static int pred_get_refs(const VVCLocalContext *lc, VVCFrame *ref[2], const MvField *mv)
481 {
482 9461517 const RefPicList *rpl = lc->sc->rpl;
483
484
2/2
✓ Branch 0 taken 18923034 times.
✓ Branch 1 taken 9461517 times.
28384551 for (int mask = PF_L0; mask <= PF_L1; mask++) {
485
2/2
✓ Branch 0 taken 14693000 times.
✓ Branch 1 taken 4230034 times.
18923034 if (mv->pred_flag & mask) {
486 14693000 const int lx = mask - PF_L0;
487 14693000 ref[lx] = rpl[lx].ref[mv->ref_idx[lx]];
488
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14693000 times.
14693000 if (!ref[lx])
489 return AVERROR_INVALIDDATA;
490 }
491 }
492 9461517 return 0;
493 }
494
495 #define POS(c_idx, x, y) \
496 &fc->frame->data[c_idx][((y) >> fc->ps.sps->vshift[c_idx]) * fc->frame->linesize[c_idx] + \
497 (((x) >> fc->ps.sps->hshift[c_idx]) << fc->ps.sps->pixel_shift)]
498
499 24398 static void pred_gpm_blk(VVCLocalContext *lc)
500 {
501 24398 const VVCFrameContext *fc = lc->fc;
502 24398 const CodingUnit *cu = lc->cu;
503 24398 const PredictionUnit *pu = &cu->pu;
504
505 24398 const uint8_t angle_idx = ff_vvc_gpm_angle_idx[pu->gpm_partition_idx];
506 24398 const uint8_t weights_idx = ff_vvc_gpm_angle_to_weights_idx[angle_idx];
507 24398 const int w = av_log2(cu->cb_width) - 3;
508 24398 const int h = av_log2(cu->cb_height) - 3;
509 24398 const uint8_t off_x = ff_vvc_gpm_weights_offset_x[pu->gpm_partition_idx][h][w];
510 24398 const uint8_t off_y = ff_vvc_gpm_weights_offset_y[pu->gpm_partition_idx][h][w];
511 24398 const uint8_t mirror_type = ff_vvc_gpm_angle_to_mirror[angle_idx];
512 const uint8_t *weights;
513
514
2/2
✓ Branch 0 taken 22117 times.
✓ Branch 1 taken 2281 times.
24398 const int c_end = fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1;
515
516 24398 int16_t *tmp[2] = {lc->tmp, lc->tmp1};
517
518
2/2
✓ Branch 0 taken 68632 times.
✓ Branch 1 taken 24398 times.
93030 for (int c_idx = 0; c_idx < c_end; c_idx++) {
519 68632 const int hs = fc->ps.sps->hshift[c_idx];
520 68632 const int vs = fc->ps.sps->vshift[c_idx];
521 68632 const int x = lc->cu->x0 >> hs;
522 68632 const int y = lc->cu->y0 >> vs;
523 68632 const int width = cu->cb_width >> hs;
524 68632 const int height = cu->cb_height >> vs;
525 68632 uint8_t *dst = POS(c_idx, lc->cu->x0, lc->cu->y0);
526 68632 ptrdiff_t dst_stride = fc->frame->linesize[c_idx];
527
528 68632 int step_x = 1 << hs;
529 68632 int step_y = VVC_GPM_WEIGHT_SIZE << vs;
530
2/2
✓ Branch 0 taken 42847 times.
✓ Branch 1 taken 25785 times.
68632 if (!mirror_type) {
531 42847 weights = &ff_vvc_gpm_weights[weights_idx][off_y * VVC_GPM_WEIGHT_SIZE + off_x];
532
2/2
✓ Branch 0 taken 11051 times.
✓ Branch 1 taken 14734 times.
25785 } else if (mirror_type == 1) {
533 11051 step_x = -step_x;
534 11051 weights = &ff_vvc_gpm_weights[weights_idx][off_y * VVC_GPM_WEIGHT_SIZE + VVC_GPM_WEIGHT_SIZE - 1- off_x];
535 } else {
536 14734 step_y = -step_y;
537 14734 weights = &ff_vvc_gpm_weights[weights_idx][(VVC_GPM_WEIGHT_SIZE - 1 - off_y) * VVC_GPM_WEIGHT_SIZE + off_x];
538 }
539
540
2/2
✓ Branch 0 taken 137264 times.
✓ Branch 1 taken 68632 times.
205896 for (int i = 0; i < 2; i++) {
541 137264 const MvField *mv = pu->gpm_mv + i;
542 137264 const int lx = mv->pred_flag - PF_L0;
543 137264 VVCFrame *ref = lc->sc->rpl[lx].ref[mv->ref_idx[lx]];
544
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 137264 times.
137264 if (!ref)
545 return;
546
2/2
✓ Branch 0 taken 88468 times.
✓ Branch 1 taken 48796 times.
137264 if (c_idx)
547 88468 chroma_mc(lc, tmp[i], ref->frame, mv->mv + lx, x, y, width, height, c_idx);
548 else
549 48796 luma_mc(lc, tmp[i], ref->frame, mv->mv + lx, x, y, width, height);
550 }
551 68632 fc->vvcdsp.inter.put_gpm(dst, dst_stride, width, height, tmp[0], tmp[1], weights, step_x, step_y);
552 }
553 24398 return;
554 }
555
556 28285 static int ciip_derive_intra_weight(const VVCLocalContext *lc, const int x0, const int y0,
557 const int width, const int height)
558 {
559 28285 const VVCFrameContext *fc = lc->fc;
560 28285 const VVCSPS *sps = fc->ps.sps;
561 28285 const int x0b = av_mod_uintp2(x0, sps->ctb_log2_size_y);
562 28285 const int y0b = av_mod_uintp2(y0, sps->ctb_log2_size_y);
563
4/4
✓ Branch 0 taken 3206 times.
✓ Branch 1 taken 25079 times.
✓ Branch 2 taken 2626 times.
✓ Branch 3 taken 580 times.
28285 const int available_l = lc->ctb_left_flag || x0b;
564
4/4
✓ Branch 0 taken 4200 times.
✓ Branch 1 taken 24085 times.
✓ Branch 2 taken 3665 times.
✓ Branch 3 taken 535 times.
28285 const int available_u = lc->ctb_up_flag || y0b;
565 28285 const int min_pu_width = fc->ps.pps->min_pu_width;
566
567 28285 int w = 1;
568
569
4/4
✓ Branch 0 taken 27750 times.
✓ Branch 1 taken 535 times.
✓ Branch 2 taken 4026 times.
✓ Branch 3 taken 23724 times.
28285 if (available_u &&fc->tab.mvf[((y0 - 1) >> MIN_PU_LOG2) * min_pu_width + ((x0 - 1 + width)>> MIN_PU_LOG2)].pred_flag == PF_INTRA)
570 4026 w++;
571
572
4/4
✓ Branch 0 taken 27705 times.
✓ Branch 1 taken 580 times.
✓ Branch 2 taken 3810 times.
✓ Branch 3 taken 23895 times.
28285 if (available_l && fc->tab.mvf[((y0 - 1 + height)>> MIN_PU_LOG2) * min_pu_width + ((x0 - 1) >> MIN_PU_LOG2)].pred_flag == PF_INTRA)
573 3810 w++;
574
575 28285 return w;
576 }
577
578 2126700 static void pred_regular_luma(VVCLocalContext *lc, const int hf_idx, const int vf_idx, const MvField *mv,
579 const int x0, const int y0, const int sbw, const int sbh, const MvField *orig_mv, const int sb_bdof_flag)
580 {
581 2126700 const SliceContext *sc = lc->sc;
582 2126700 const VVCFrameContext *fc = lc->fc;
583 2126700 const int ciip_flag = lc->cu->ciip_flag;
584 2126700 uint8_t *dst = POS(0, x0, y0);
585 2126700 const ptrdiff_t dst_stride = fc->frame->linesize[0];
586
2/2
✓ Branch 0 taken 15407 times.
✓ Branch 1 taken 2111293 times.
2126700 uint8_t *inter = ciip_flag ? (uint8_t *)lc->ciip_tmp1 : dst;
587
2/2
✓ Branch 0 taken 2111293 times.
✓ Branch 1 taken 15407 times.
2126700 const ptrdiff_t inter_stride = ciip_flag ? (MAX_PB_SIZE * sizeof(uint16_t)) : dst_stride;
588 VVCFrame *ref[2];
589
590
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2126700 times.
2126700 if (pred_get_refs(lc, ref, mv) < 0)
591 return;
592
593
2/2
✓ Branch 0 taken 614666 times.
✓ Branch 1 taken 1512034 times.
2126700 if (mv->pred_flag != PF_BI) {
594 614666 const int lx = mv->pred_flag - PF_L0;
595 614666 luma_mc_uni(lc, inter, inter_stride, ref[lx]->frame,
596 mv, x0, y0, sbw, sbh, hf_idx, vf_idx);
597 } else {
598 1512034 luma_mc_bi(lc, inter, inter_stride, ref[0]->frame,
599 1512034 &mv->mv[0], x0, y0, sbw, sbh, ref[1]->frame, &mv->mv[1], mv,
600 hf_idx, vf_idx, orig_mv, sb_bdof_flag);
601 }
602
603
2/2
✓ Branch 0 taken 15407 times.
✓ Branch 1 taken 2111293 times.
2126700 if (ciip_flag) {
604 15407 const int intra_weight = ciip_derive_intra_weight(lc, x0, y0, sbw, sbh);
605 15407 fc->vvcdsp.intra.intra_pred(lc, x0, y0, sbw, sbh, 0);
606
2/2
✓ Branch 0 taken 8094 times.
✓ Branch 1 taken 7313 times.
15407 if (sc->sh.r->sh_lmcs_used_flag)
607 8094 fc->vvcdsp.lmcs.filter(inter, inter_stride, sbw, sbh, &fc->ps.lmcs.fwd_lut);
608 15407 fc->vvcdsp.inter.put_ciip(dst, dst_stride, sbw, sbh, inter, inter_stride, intra_weight);
609
610 }
611 }
612
613 3224251 static void pred_regular_chroma(VVCLocalContext *lc, const MvField *mv,
614 const int x0, const int y0, const int sbw, const int sbh, const MvField *orig_mv, const int dmvr_flag)
615 {
616 3224251 const VVCFrameContext *fc = lc->fc;
617 3224251 const int hs = fc->ps.sps->hshift[1];
618 3224251 const int vs = fc->ps.sps->vshift[1];
619 3224251 const int x0_c = x0 >> hs;
620 3224251 const int y0_c = y0 >> vs;
621 3224251 const int w_c = sbw >> hs;
622 3224251 const int h_c = sbh >> vs;
623
4/4
✓ Branch 0 taken 15090 times.
✓ Branch 1 taken 3209161 times.
✓ Branch 2 taken 12878 times.
✓ Branch 3 taken 2212 times.
3224251 const int do_ciip = lc->cu->ciip_flag && (w_c > 2);
624
625 3224251 uint8_t* dst1 = POS(1, x0, y0);
626 3224251 uint8_t* dst2 = POS(2, x0, y0);
627 3224251 const ptrdiff_t dst1_stride = fc->frame->linesize[1];
628 3224251 const ptrdiff_t dst2_stride = fc->frame->linesize[2];
629
630
2/2
✓ Branch 0 taken 12878 times.
✓ Branch 1 taken 3211373 times.
3224251 uint8_t *inter1 = do_ciip ? (uint8_t *)lc->ciip_tmp1 : dst1;
631
2/2
✓ Branch 0 taken 3211373 times.
✓ Branch 1 taken 12878 times.
3224251 const ptrdiff_t inter1_stride = do_ciip ? (MAX_PB_SIZE * sizeof(uint16_t)) : dst1_stride;
632
633
2/2
✓ Branch 0 taken 12878 times.
✓ Branch 1 taken 3211373 times.
3224251 uint8_t *inter2 = do_ciip ? (uint8_t *)lc->ciip_tmp2 : dst2;
634
2/2
✓ Branch 0 taken 3211373 times.
✓ Branch 1 taken 12878 times.
3224251 const ptrdiff_t inter2_stride = do_ciip ? (MAX_PB_SIZE * sizeof(uint16_t)) : dst2_stride;
635
636 //fix me
637 3224251 const int hf_idx = 0;
638 3224251 const int vf_idx = 0;
639 VVCFrame *ref[2];
640
641
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3224251 times.
3224251 if (pred_get_refs(lc, ref, mv) < 0)
642 return;
643
644
2/2
✓ Branch 0 taken 1354608 times.
✓ Branch 1 taken 1869643 times.
3224251 if (mv->pred_flag != PF_BI) {
645 1354608 const int lx = mv->pred_flag - PF_L0;
646
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1354608 times.
1354608 if (!ref[lx])
647 return;
648
649 1354608 chroma_mc_uni(lc, inter1, inter1_stride, ref[lx]->frame->data[1], ref[lx]->frame->linesize[1],
650 x0_c, y0_c, w_c, h_c, mv, CB, hf_idx, vf_idx);
651 1354608 chroma_mc_uni(lc, inter2, inter2_stride, ref[lx]->frame->data[2], ref[lx]->frame->linesize[2],
652 x0_c, y0_c, w_c, h_c, mv, CR, hf_idx, vf_idx);
653 } else {
654
2/4
✓ Branch 0 taken 1869643 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1869643 times.
1869643 if (!ref[0] || !ref[1])
655 return;
656
657 1869643 chroma_mc_bi(lc, inter1, inter1_stride, ref[0]->frame, ref[1]->frame,
658 1869643 x0_c, y0_c, w_c, h_c, mv, CB, hf_idx, vf_idx, orig_mv, dmvr_flag, lc->cu->ciip_flag);
659
660 1869643 chroma_mc_bi(lc, inter2, inter2_stride, ref[0]->frame, ref[1]->frame,
661 1869643 x0_c, y0_c, w_c, h_c, mv, CR, hf_idx, vf_idx, orig_mv, dmvr_flag, lc->cu->ciip_flag);
662
663 }
664
2/2
✓ Branch 0 taken 12878 times.
✓ Branch 1 taken 3211373 times.
3224251 if (do_ciip) {
665 12878 const int intra_weight = ciip_derive_intra_weight(lc, x0, y0, sbw, sbh);
666 12878 fc->vvcdsp.intra.intra_pred(lc, x0, y0, sbw, sbh, 1);
667 12878 fc->vvcdsp.intra.intra_pred(lc, x0, y0, sbw, sbh, 2);
668 12878 fc->vvcdsp.inter.put_ciip(dst1, dst1_stride, w_c, h_c, inter1, inter1_stride, intra_weight);
669 12878 fc->vvcdsp.inter.put_ciip(dst2, dst2_stride, w_c, h_c, inter2, inter2_stride, intra_weight);
670
671 }
672 }
673
674 // 8.5.3.5 Parametric motion vector refinement process
675 495844 static int parametric_mv_refine(const int *sad, const int stride)
676 {
677 495844 const int sad_minus = sad[-stride];
678 495844 const int sad_center = sad[0];
679 495844 const int sad_plus = sad[stride];
680 int dmvc;
681 495844 int denom = (( sad_minus + sad_plus) - (sad_center << 1 ) ) << 3;
682
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 495844 times.
495844 if (!denom)
683 dmvc = 0;
684 else {
685
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 495786 times.
495844 if (sad_minus == sad_center)
686 58 dmvc = -8;
687
2/2
✓ Branch 0 taken 239 times.
✓ Branch 1 taken 495547 times.
495786 else if (sad_plus == sad_center)
688 239 dmvc = 8;
689 else {
690 495547 int num = ( sad_minus - sad_plus ) * (1 << 4);
691 495547 int sign_num = 0;
692 495547 int quotient = 0;
693 495547 int counter = 3;
694
2/2
✓ Branch 0 taken 250788 times.
✓ Branch 1 taken 244759 times.
495547 if (num < 0 ) {
695 250788 num = - num;
696 250788 sign_num = 1;
697 }
698
2/2
✓ Branch 0 taken 1486641 times.
✓ Branch 1 taken 495547 times.
1982188 while (counter > 0) {
699 1486641 counter = counter - 1;
700 1486641 quotient = quotient << 1;
701
2/2
✓ Branch 0 taken 440303 times.
✓ Branch 1 taken 1046338 times.
1486641 if ( num >= denom ) {
702 440303 num = num - denom;
703 440303 quotient = quotient + 1;
704 }
705 1486641 denom = (denom >> 1);
706 }
707
2/2
✓ Branch 0 taken 250788 times.
✓ Branch 1 taken 244759 times.
495547 if (sign_num == 1 )
708 250788 dmvc = -quotient;
709 else
710 244759 dmvc = quotient;
711 }
712 }
713 495844 return dmvc;
714 }
715
716 #define SAD_ARRAY_SIZE 5
717 //8.5.3 Decoder-side motion vector refinement process
718 986366 static void dmvr_mv_refine(VVCLocalContext *lc, MvField *mvf, MvField *orig_mv, int *sb_bdof_flag,
719 const AVFrame *ref0, const AVFrame *ref1, const int x_off, const int y_off, const int block_w, const int block_h)
720 {
721 986366 const VVCFrameContext *fc = lc->fc;
722 986366 const int sr_range = 2;
723 986366 const AVFrame *ref[] = { ref0, ref1 };
724 986366 int16_t *tmp[] = { lc->tmp, lc->tmp1 };
725 int sad[SAD_ARRAY_SIZE][SAD_ARRAY_SIZE];
726 int min_dx, min_dy, min_sad, dx, dy;
727
728 986366 *orig_mv = *mvf;
729 986366 min_dx = min_dy = dx = dy = 2;
730
731
2/2
✓ Branch 0 taken 1972732 times.
✓ Branch 1 taken 986366 times.
2959098 for (int i = L0; i <= L1; i++) {
732 1972732 const int pred_w = block_w + 2 * sr_range;
733 1972732 const int pred_h = block_h + 2 * sr_range;
734 1972732 const Mv *mv = mvf->mv + i;
735 1972732 const int mx = mv->x & 0xf;
736 1972732 const int my = mv->y & 0xf;
737 1972732 const int ox = x_off + (mv->x >> 4) - sr_range;
738 1972732 const int oy = y_off + (mv->y >> 4) - sr_range;
739 1972732 ptrdiff_t src_stride = ref[i]->linesize[LUMA];
740 1972732 const uint8_t *src = ref[i]->data[LUMA] + oy * src_stride + (ox * (1 << fc->ps.sps->pixel_shift));
741 1972732 EMULATED_EDGE_BILINEAR(lc->edge_emu_buffer, &src, &src_stride, ox, oy);
742 1972732 fc->vvcdsp.inter.dmvr[!!my][!!mx](tmp[i], src, src_stride, pred_h, mx, my, pred_w);
743 }
744
745 986366 min_sad = fc->vvcdsp.inter.sad(tmp[L0], tmp[L1], dx, dy, block_w, block_h);
746 986366 min_sad -= min_sad >> 2;
747 986366 sad[dy][dx] = min_sad;
748
749
2/2
✓ Branch 0 taken 449927 times.
✓ Branch 1 taken 536439 times.
986366 if (min_sad >= block_w * block_h) {
750 int dmv[2];
751 // 8.5.3.4 Array entry selection process
752
2/2
✓ Branch 0 taken 2249635 times.
✓ Branch 1 taken 449927 times.
2699562 for (dy = 0; dy < SAD_ARRAY_SIZE; dy++) {
753
2/2
✓ Branch 0 taken 11248175 times.
✓ Branch 1 taken 2249635 times.
13497810 for (dx = 0; dx < SAD_ARRAY_SIZE; dx++) {
754
4/4
✓ Branch 0 taken 2249635 times.
✓ Branch 1 taken 8998540 times.
✓ Branch 2 taken 1799708 times.
✓ Branch 3 taken 449927 times.
11248175 if (dx != sr_range || dy != sr_range) {
755 10798248 sad[dy][dx] = fc->vvcdsp.inter.sad(lc->tmp, lc->tmp1, dx, dy, block_w, block_h);
756
2/2
✓ Branch 0 taken 645254 times.
✓ Branch 1 taken 10152994 times.
10798248 if (sad[dy][dx] < min_sad) {
757 645254 min_sad = sad[dy][dx];
758 645254 min_dx = dx;
759 645254 min_dy = dy;
760 }
761 }
762 }
763 }
764 449927 dmv[0] = (min_dx - sr_range) * (1 << 4);
765 449927 dmv[1] = (min_dy - sr_range) * (1 << 4);
766
8/8
✓ Branch 0 taken 372789 times.
✓ Branch 1 taken 77138 times.
✓ Branch 2 taken 308355 times.
✓ Branch 3 taken 64434 times.
✓ Branch 4 taken 256345 times.
✓ Branch 5 taken 52010 times.
✓ Branch 6 taken 247922 times.
✓ Branch 7 taken 8423 times.
449927 if (min_dx != 0 && min_dx != 4 && min_dy != 0 && min_dy != 4) {
767 247922 dmv[0] += parametric_mv_refine(&sad[min_dy][min_dx], 1);
768 247922 dmv[1] += parametric_mv_refine(&sad[min_dy][min_dx], SAD_ARRAY_SIZE);
769 }
770
771
2/2
✓ Branch 0 taken 899854 times.
✓ Branch 1 taken 449927 times.
1349781 for (int i = L0; i <= L1; i++) {
772 899854 Mv *mv = mvf->mv + i;
773 899854 mv->x += (1 - 2 * i) * dmv[0];
774 899854 mv->y += (1 - 2 * i) * dmv[1];
775 899854 ff_vvc_clip_mv(mv);
776 }
777 }
778
2/2
✓ Branch 0 taken 701731 times.
✓ Branch 1 taken 284635 times.
986366 if (min_sad < 2 * block_w * block_h) {
779 701731 *sb_bdof_flag = 0;
780 }
781 986366 }
782
783 986366 static void set_dmvr_info(VVCFrameContext *fc, const int x0, const int y0,
784 const int width, const int height, const MvField *mvf)
785
786 {
787 986366 const VVCPPS *pps = fc->ps.pps;
788
789
2/2
✓ Branch 0 taken 3903492 times.
✓ Branch 1 taken 986366 times.
4889858 for (int y = y0; y < y0 + height; y += MIN_PU_SIZE) {
790
2/2
✓ Branch 0 taken 15480184 times.
✓ Branch 1 taken 3903492 times.
19383676 for (int x = x0; x < x0 + width; x += MIN_PU_SIZE) {
791 15480184 const int idx = pps->min_pu_width * (y >> MIN_PU_LOG2) + (x >> MIN_PU_LOG2);
792 15480184 fc->ref->tab_dmvr_mvf[idx] = *mvf;
793 }
794 }
795 986366 }
796
797 2126700 static void derive_sb_mv(VVCLocalContext *lc, MvField *mv, MvField *orig_mv, int *sb_bdof_flag,
798 const int x0, const int y0, const int sbw, const int sbh)
799 {
800 2126700 VVCFrameContext *fc = lc->fc;
801 2126700 const PredictionUnit *pu = &lc->cu->pu;
802
803 2126700 *orig_mv = *mv = *ff_vvc_get_mvf(fc, x0, y0);
804
2/2
✓ Branch 0 taken 1051878 times.
✓ Branch 1 taken 1074822 times.
2126700 if (pu->bdof_flag)
805 1051878 *sb_bdof_flag = 1;
806
2/2
✓ Branch 0 taken 986366 times.
✓ Branch 1 taken 1140334 times.
2126700 if (pu->dmvr_flag) {
807 VVCFrame* ref[2];
808
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 986366 times.
986366 if (pred_get_refs(lc, ref, mv) < 0)
809 return;
810 986366 dmvr_mv_refine(lc, mv, orig_mv, sb_bdof_flag, ref[0]->frame, ref[1]->frame, x0, y0, sbw, sbh);
811 986366 set_dmvr_info(fc, x0, y0, sbw, sbh, mv);
812 }
813 }
814
815 352999 static void pred_regular_blk(VVCLocalContext *lc, const int skip_ciip)
816 {
817 352999 const VVCFrameContext *fc = lc->fc;
818 352999 const CodingUnit *cu = lc->cu;
819 352999 PredictionUnit *pu = &lc->cu->pu;
820 352999 const MotionInfo *mi = &pu->mi;
821 MvField mv, orig_mv;
822 352999 int sbw, sbh, sb_bdof_flag = 0;
823
824
4/4
✓ Branch 0 taken 30814 times.
✓ Branch 1 taken 322185 times.
✓ Branch 2 taken 15407 times.
✓ Branch 3 taken 15407 times.
352999 if (cu->ciip_flag && skip_ciip)
825 15407 return;
826
827 337592 sbw = cu->cb_width / mi->num_sb_x;
828 337592 sbh = cu->cb_height / mi->num_sb_y;
829
830
2/2
✓ Branch 0 taken 563688 times.
✓ Branch 1 taken 337592 times.
901280 for (int sby = 0; sby < mi->num_sb_y; sby++) {
831
2/2
✓ Branch 0 taken 2126700 times.
✓ Branch 1 taken 563688 times.
2690388 for (int sbx = 0; sbx < mi->num_sb_x; sbx++) {
832 2126700 const int x0 = cu->x0 + sbx * sbw;
833 2126700 const int y0 = cu->y0 + sby * sbh;
834
835
2/2
✓ Branch 0 taken 15407 times.
✓ Branch 1 taken 2111293 times.
2126700 if (cu->ciip_flag)
836 15407 ff_vvc_set_neighbour_available(lc, x0, y0, sbw, sbh);
837
838 2126700 derive_sb_mv(lc, &mv, &orig_mv, &sb_bdof_flag, x0, y0, sbw, sbh);
839 2126700 pred_regular_luma(lc, mi->hpel_if_idx, mi->hpel_if_idx, &mv, x0, y0, sbw, sbh, &orig_mv, sb_bdof_flag);
840
2/2
✓ Branch 0 taken 2098413 times.
✓ Branch 1 taken 28287 times.
2126700 if (fc->ps.sps->r->sps_chroma_format_idc)
841 2098413 pred_regular_chroma(lc, &mv, x0, y0, sbw, sbh, &orig_mv, pu->dmvr_flag);
842 }
843 }
844 }
845
846 1125838 static void derive_affine_mvc(MvField *mvc, const VVCFrameContext *fc, const MvField *mv,
847 const int x0, const int y0, const int sbw, const int sbh)
848 {
849 1125838 const int hs = fc->ps.sps->hshift[1];
850 1125838 const int vs = fc->ps.sps->vshift[1];
851 1125838 const MvField* mv2 = ff_vvc_get_mvf(fc, x0 + hs * sbw, y0 + vs * sbh);
852 1125838 *mvc = *mv;
853
854 // Due to different pred_flag, one of the motion vectors may have an invalid value.
855 // Cast them to an unsigned type to avoid undefined behavior.
856 1125838 mvc->mv[0].x += (unsigned int)mv2->mv[0].x;
857 1125838 mvc->mv[0].y += (unsigned int)mv2->mv[0].y;
858 1125838 mvc->mv[1].x += (unsigned int)mv2->mv[1].x;
859 1125838 mvc->mv[1].y += (unsigned int)mv2->mv[1].y;
860 1125838 ff_vvc_round_mv(mvc->mv + 0, 0, 1);
861 1125838 ff_vvc_round_mv(mvc->mv + 1, 0, 1);
862 1125838 }
863
864 32078 static void pred_affine_blk(VVCLocalContext *lc)
865 {
866 32078 const VVCFrameContext *fc = lc->fc;
867 32078 const CodingUnit *cu = lc->cu;
868 32078 const PredictionUnit *pu = &cu->pu;
869 32078 const MotionInfo *mi = &pu->mi;
870 32078 const int x0 = cu->x0;
871 32078 const int y0 = cu->y0;
872 32078 const int sbw = cu->cb_width / mi->num_sb_x;
873 32078 const int sbh = cu->cb_height / mi->num_sb_y;
874 32078 const int hs = fc->ps.sps->hshift[1];
875 32078 const int vs = fc->ps.sps->vshift[1];
876
877
2/2
✓ Branch 0 taken 253562 times.
✓ Branch 1 taken 32078 times.
285640 for (int sby = 0; sby < mi->num_sb_y; sby++) {
878
2/2
✓ Branch 0 taken 3124200 times.
✓ Branch 1 taken 253562 times.
3377762 for (int sbx = 0; sbx < mi->num_sb_x; sbx++) {
879 3124200 const int x = x0 + sbx * sbw;
880 3124200 const int y = y0 + sby * sbh;
881
882 3124200 uint8_t *dst0 = POS(0, x, y);
883 3124200 const MvField *mv = ff_vvc_get_mvf(fc, x, y);
884 VVCFrame *ref[2];
885
886
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3124200 times.
3124200 if (pred_get_refs(lc, ref, mv) < 0)
887 return;
888
889
2/2
✓ Branch 0 taken 2260760 times.
✓ Branch 1 taken 863440 times.
3124200 if (mi->pred_flag != PF_BI) {
890 2260760 const int lx = mi->pred_flag - PF_L0;
891 2260760 luma_prof_uni(lc, dst0, fc->frame->linesize[0], ref[lx]->frame,
892 2260760 mv, x, y, sbw, sbh, pu->cb_prof_flag[lx],
893 2260760 pu->diff_mv_x[lx], pu->diff_mv_y[lx]);
894 } else {
895 863440 luma_prof_bi(lc, dst0, fc->frame->linesize[0], ref[0]->frame, ref[1]->frame,
896 mv, x, y, sbw, sbh);
897 }
898
2/2
✓ Branch 0 taken 3086092 times.
✓ Branch 1 taken 38108 times.
3124200 if (fc->ps.sps->r->sps_chroma_format_idc) {
899
4/4
✓ Branch 0 taken 1779256 times.
✓ Branch 1 taken 1306836 times.
✓ Branch 2 taken 1125838 times.
✓ Branch 3 taken 653418 times.
3086092 if (!av_mod_uintp2(sby, vs) && !av_mod_uintp2(sbx, hs)) {
900 MvField mvc;
901 1125838 derive_affine_mvc(&mvc, fc, mv, x, y, sbw, sbh);
902 1125838 pred_regular_chroma(lc, &mvc, x, y, sbw<<hs, sbh<<vs, NULL, 0);
903
904 }
905 }
906
907 }
908 }
909 }
910
911 394068 static void predict_inter(VVCLocalContext *lc)
912 {
913 394068 const VVCFrameContext *fc = lc->fc;
914 394068 const CodingUnit *cu = lc->cu;
915 394068 const PredictionUnit *pu = &cu->pu;
916
917
2/2
✓ Branch 0 taken 24398 times.
✓ Branch 1 taken 369670 times.
394068 if (pu->merge_gpm_flag)
918 24398 pred_gpm_blk(lc);
919
2/2
✓ Branch 0 taken 32078 times.
✓ Branch 1 taken 337592 times.
369670 else if (pu->inter_affine_flag)
920 32078 pred_affine_blk(lc);
921 else
922 337592 pred_regular_blk(lc, 1); //intra block is not ready yet, skip ciip
923
924
4/4
✓ Branch 0 taken 171518 times.
✓ Branch 1 taken 222550 times.
✓ Branch 2 taken 163424 times.
✓ Branch 3 taken 8094 times.
394068 if (lc->sc->sh.r->sh_lmcs_used_flag && !cu->ciip_flag) {
925 163424 uint8_t* dst0 = POS(0, cu->x0, cu->y0);
926 163424 fc->vvcdsp.lmcs.filter(dst0, fc->frame->linesize[LUMA], cu->cb_width, cu->cb_height, &fc->ps.lmcs.fwd_lut);
927 }
928 394068 }
929
930 915428 static int has_inter_luma(const CodingUnit *cu)
931 {
932
4/6
✓ Branch 0 taken 521360 times.
✓ Branch 1 taken 394068 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 521360 times.
✓ Branch 4 taken 394068 times.
✗ Branch 5 not taken.
915428 return (cu->pred_mode == MODE_INTER || cu->pred_mode == MODE_SKIP) && cu->tree_type != DUAL_TREE_CHROMA;
933 }
934
935 42891 int ff_vvc_predict_inter(VVCLocalContext *lc, const int rs)
936 {
937 42891 const VVCFrameContext *fc = lc->fc;
938 42891 const CTU *ctu = fc->tab.ctus + rs;
939 42891 CodingUnit *cu = ctu->cus;
940
941
2/2
✓ Branch 0 taken 915428 times.
✓ Branch 1 taken 42891 times.
958319 while (cu) {
942 915428 lc->cu = cu;
943
2/2
✓ Branch 1 taken 394068 times.
✓ Branch 2 taken 521360 times.
915428 if (has_inter_luma(cu))
944 394068 predict_inter(lc);
945 915428 cu = cu->next;
946 }
947
948 42891 return 0;
949 }
950
951 15407 void ff_vvc_predict_ciip(VVCLocalContext *lc)
952 {
953
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15407 times.
15407 av_assert0(lc->cu->ciip_flag);
954
955 //todo: refact out ciip from pred_regular_blk
956 15407 pred_regular_blk(lc, 0);
957 15407 }
958
959 #undef POS
960