| 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 | 23771521 | static void subpic_get_rect(VVCRect *r, const VVCFrame *src_frame, const int subpic_idx, const int is_chroma) | |
| 34 | { | ||
| 35 | 23771521 | const VVCSPS *sps = src_frame->sps; | |
| 36 | 23771521 | const VVCPPS *pps = src_frame->pps; | |
| 37 | 23771521 | const int hs = sps->hshift[is_chroma]; | |
| 38 | 23771521 | const int vs = sps->vshift[is_chroma]; | |
| 39 | |||
| 40 | 23771521 | r->l = pps->subpic_x[subpic_idx] >> hs; | |
| 41 | 23771521 | r->t = pps->subpic_y[subpic_idx] >> vs; | |
| 42 | 23771521 | r->r = r->l + (pps->subpic_width[subpic_idx] >> hs); | |
| 43 | 23771521 | r->b = r->t + (pps->subpic_height[subpic_idx] >> vs); | |
| 44 | 23771521 | } | |
| 45 | |||
| 46 | // clip to subblock and subpicture process in 8.5.6.3.2 Luma sample interpolation filtering process | ||
| 47 | 23773762 | static void clip_to_subpic(int *x_off, int *y_off, int *pic_width, int *pic_height, const VVCRect *subpic, const VVCRect *sb, const int dmvr_clip) | |
| 48 | { | ||
| 49 |
4/4✓ Branch 0 taken 1801622 times.
✓ Branch 1 taken 21972140 times.
✓ Branch 2 taken 128 times.
✓ Branch 3 taken 1801494 times.
|
23773762 | const int l = dmvr_clip ? FFMIN(FFMAX(subpic->l, sb->l), subpic->r - 1) : subpic->l; |
| 50 |
4/4✓ Branch 0 taken 1801622 times.
✓ Branch 1 taken 21972140 times.
✓ Branch 2 taken 1066 times.
✓ Branch 3 taken 1800556 times.
|
23773762 | const int t = dmvr_clip ? FFMIN(FFMAX(subpic->t, sb->t), subpic->b - 1) : subpic->t; |
| 51 |
2/2✓ Branch 0 taken 1801622 times.
✓ Branch 1 taken 21972140 times.
|
23773762 | const int r = dmvr_clip ? FFMAX(FFMIN(subpic->r, sb->r), subpic->l + 1) : subpic->r; |
| 52 |
2/2✓ Branch 0 taken 1801622 times.
✓ Branch 1 taken 21972140 times.
|
23773762 | const int b = dmvr_clip ? FFMAX(FFMIN(subpic->b, sb->b), subpic->t + 1) : subpic->b; |
| 53 | |||
| 54 | 23773762 | *x_off -= l; | |
| 55 | 23773762 | *y_off -= t; | |
| 56 | 23773762 | *pic_width = r - l; | |
| 57 | 23773762 | *pic_height = b - t; | |
| 58 | 23773762 | } | |
| 59 | |||
| 60 | 23769280 | static void emulated_edge_no_wrap(const VVCLocalContext *lc, uint8_t *dst, | |
| 61 | const uint8_t **src, ptrdiff_t *src_stride, | ||
| 62 | int x_off, int y_off, const int block_w, const int block_h, | ||
| 63 | const int extra_before, const int extra_after, | ||
| 64 | const VVCRect *subpic, const VVCRect *sb, const int dmvr_clip) | ||
| 65 | { | ||
| 66 | 23769280 | const VVCFrameContext *fc = lc->fc; | |
| 67 | 23769280 | const int extra = extra_before + extra_after; | |
| 68 | int pic_width, pic_height; | ||
| 69 | |||
| 70 | 23769280 | *src += y_off * *src_stride + (x_off * (1 << fc->ps.sps->pixel_shift)); | |
| 71 | |||
| 72 | 23769280 | clip_to_subpic(&x_off, &y_off, &pic_width, &pic_height, subpic, sb, dmvr_clip); | |
| 73 | |||
| 74 |
6/6✓ Branch 0 taken 21967768 times.
✓ Branch 1 taken 1801512 times.
✓ Branch 2 taken 21764932 times.
✓ Branch 3 taken 202836 times.
✓ Branch 4 taken 21432882 times.
✓ Branch 5 taken 332050 times.
|
23769280 | if (dmvr_clip || x_off < extra_before || y_off < extra_before || |
| 75 |
2/2✓ Branch 0 taken 21206265 times.
✓ Branch 1 taken 226617 times.
|
21432882 | x_off >= pic_width - block_w - extra_after || |
| 76 |
2/2✓ Branch 0 taken 295064 times.
✓ Branch 1 taken 20911201 times.
|
21206265 | y_off >= pic_height - block_h - extra_after) { |
| 77 | 2858079 | const int ps = fc->ps.sps->pixel_shift; | |
| 78 | 2858079 | const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << ps; | |
| 79 | 2858079 | const int offset = extra_before * *src_stride + (extra_before << ps); | |
| 80 | 2858079 | const int buf_offset = extra_before * edge_emu_stride + (extra_before << ps); | |
| 81 | |||
| 82 | 2858079 | fc->vdsp.emulated_edge_mc(dst, *src - offset, edge_emu_stride, *src_stride, | |
| 83 | block_w + extra, block_h + extra, x_off - extra_before, y_off - extra_before, | ||
| 84 | pic_width, pic_height); | ||
| 85 | |||
| 86 | 2858079 | *src = dst + buf_offset; | |
| 87 | 2858079 | *src_stride = edge_emu_stride; | |
| 88 | } | ||
| 89 | 23769280 | } | |
| 90 | |||
| 91 | 4482 | static void emulated_half(const VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, | |
| 92 | const uint8_t *src, const ptrdiff_t src_stride, const int ps, | ||
| 93 | int x_off, int y_off, const int block_w, const int block_h, | ||
| 94 | const VVCRect *subpic,const VVCRect *half_sb, const int dmvr_clip) | ||
| 95 | { | ||
| 96 | 4482 | const VVCFrameContext *fc = lc->fc; | |
| 97 | int pic_width, pic_height; | ||
| 98 | |||
| 99 | 4482 | src += y_off * src_stride + x_off * (1 << ps); | |
| 100 | |||
| 101 | 4482 | clip_to_subpic(&x_off, &y_off, &pic_width, &pic_height, subpic, half_sb, dmvr_clip); | |
| 102 | |||
| 103 | 4482 | fc->vdsp.emulated_edge_mc(dst, src, dst_stride, src_stride, | |
| 104 | block_w, block_h, x_off, y_off, pic_width, pic_height); | ||
| 105 | 4482 | } | |
| 106 | |||
| 107 | 9897 | static void sb_set_lr(VVCRect *sb, const int l, const int r) | |
| 108 | { | ||
| 109 | 9897 | sb->l = l; | |
| 110 | 9897 | sb->r = r; | |
| 111 | 9897 | } | |
| 112 | |||
| 113 | 7656 | static void sb_wrap(VVCRect *sb, const int wrap) | |
| 114 | { | ||
| 115 | 7656 | sb_set_lr(sb, sb->l + wrap, sb->r + wrap); | |
| 116 | 7656 | } | |
| 117 | |||
| 118 | 23771521 | static void emulated_edge(const VVCLocalContext *lc, uint8_t *dst, | |
| 119 | const uint8_t **src, ptrdiff_t *src_stride, const VVCFrame *src_frame, | ||
| 120 | int x_sb, int y_sb, int x_off, int y_off, int block_w, int block_h, const int wrap_enabled, | ||
| 121 | const int is_chroma, const int extra_before, const int extra_after) | ||
| 122 | { | ||
| 123 | 23771521 | const VVCSPS *sps = src_frame->sps; | |
| 124 | 23771521 | const VVCPPS *pps = src_frame->pps; | |
| 125 | 23771521 | const int ps = sps->pixel_shift; | |
| 126 | 23771521 | const int subpic_idx = lc->sc->sh.r->curr_subpic_idx; | |
| 127 | 23771521 | const int extra = extra_before + extra_after; | |
| 128 |
4/4✓ Branch 0 taken 22391254 times.
✓ Branch 1 taken 1380267 times.
✓ Branch 2 taken 421300 times.
✓ Branch 3 taken 21969954 times.
|
23771521 | const int dmvr_clip = x_sb != x_off || y_sb != y_off; |
| 129 | 23771521 | const int dmvr_left = FFMAX(x_off, x_sb) - extra_before; | |
| 130 | 23771521 | const int dmvr_right = FFMIN(x_off, x_sb) + block_w + extra_after; | |
| 131 | 23771521 | const int left = x_off - extra_before; | |
| 132 | 23771521 | const int top = y_off - extra_before; | |
| 133 | 23771521 | const int pic_width = pps->width >> sps->hshift[is_chroma]; | |
| 134 | 23771521 | const int wrap = pps->ref_wraparound_offset << (sps->min_cb_log2_size_y - sps->hshift[is_chroma]); | |
| 135 | 23771521 | const ptrdiff_t dst_stride = EDGE_EMU_BUFFER_STRIDE << ps; | |
| 136 | 23771521 | VVCRect sb = { x_sb - extra_before, y_sb - extra_before, x_sb + block_w + extra_after, y_sb + block_h + extra_after }; | |
| 137 | VVCRect subpic; | ||
| 138 | |||
| 139 | 23771521 | subpic_get_rect(&subpic, src_frame, subpic_idx, is_chroma); | |
| 140 | |||
| 141 |
6/6✓ Branch 0 taken 257536 times.
✓ Branch 1 taken 23513985 times.
✓ Branch 2 taken 251971 times.
✓ Branch 3 taken 5565 times.
✓ Branch 4 taken 247639 times.
✓ Branch 5 taken 4332 times.
|
23771521 | if (!wrap_enabled || (dmvr_left >= 0 && dmvr_right <= pic_width)) { |
| 142 | 23761624 | emulated_edge_no_wrap(lc, dst, src, src_stride, | |
| 143 | x_off, y_off, block_w, block_h, extra_before, extra_after, &subpic, &sb, dmvr_clip); | ||
| 144 | 23769280 | return; | |
| 145 | } | ||
| 146 |
2/2✓ Branch 0 taken 4161 times.
✓ Branch 1 taken 5736 times.
|
9897 | if (dmvr_right <= 0) { |
| 147 | 4161 | sb_wrap(&sb, wrap); | |
| 148 | 4161 | emulated_edge_no_wrap(lc, dst, src, src_stride, | |
| 149 | x_off + wrap, y_off, block_w, block_h, extra_before, extra_after, &subpic, &sb, dmvr_clip); | ||
| 150 | 4161 | return; | |
| 151 | } | ||
| 152 |
2/2✓ Branch 0 taken 3495 times.
✓ Branch 1 taken 2241 times.
|
5736 | if (dmvr_left >= pic_width) { |
| 153 | 3495 | sb_wrap(&sb, -wrap); | |
| 154 | 3495 | emulated_edge_no_wrap(lc, dst, src, src_stride, | |
| 155 | x_off - wrap, y_off, block_w, block_h, extra_before, extra_after, &subpic, &sb, dmvr_clip); | ||
| 156 | 3495 | return; | |
| 157 | } | ||
| 158 | |||
| 159 | 2241 | block_w += extra; | |
| 160 | 2241 | block_h += extra; | |
| 161 | |||
| 162 | // half block are wrapped | ||
| 163 |
2/2✓ Branch 0 taken 1404 times.
✓ Branch 1 taken 837 times.
|
2241 | if (dmvr_left < 0 ) { |
| 164 | 1404 | const int w = -left; | |
| 165 | 1404 | VVCRect half_sb = { sb.l + wrap, sb.t, 0 + wrap, sb.b }; | |
| 166 | 1404 | emulated_half(lc, dst, dst_stride, *src, *src_stride, ps, | |
| 167 | left + wrap, top, w, block_h, &subpic, &half_sb, dmvr_clip); | ||
| 168 | |||
| 169 | 1404 | sb_set_lr(&half_sb, 0, sb.r); | |
| 170 | 1404 | emulated_half(lc, dst + (w << ps), dst_stride, *src, *src_stride, ps, | |
| 171 | 0, top, block_w - w, block_h, &subpic, &half_sb, dmvr_clip); | ||
| 172 | } else { | ||
| 173 | 837 | const int w = pic_width - left; | |
| 174 | 837 | VVCRect half_sb = { sb.l, sb.t, pic_width, sb.b }; | |
| 175 | 837 | emulated_half(lc, dst, dst_stride, *src, *src_stride, ps, | |
| 176 | left, top, w, block_h, &subpic, &half_sb, dmvr_clip); | ||
| 177 | |||
| 178 | 837 | sb_set_lr(&half_sb, pic_width - wrap, sb.r - wrap); | |
| 179 | 837 | emulated_half(lc, dst + (w << ps), dst_stride, *src, *src_stride, ps, | |
| 180 | pic_width - wrap , top, block_w - w, block_h, &subpic, &half_sb, dmvr_clip); | ||
| 181 | } | ||
| 182 | |||
| 183 | 2241 | *src = dst + extra_before * dst_stride + (extra_before << ps); | |
| 184 | 2241 | *src_stride = dst_stride; | |
| 185 | } | ||
| 186 | |||
| 187 | #define MC_EMULATED_EDGE(dst, src, src_stride, x_off, y_off) \ | ||
| 188 | emulated_edge(lc, dst, src, src_stride, ref, x_off, y_off, x_off, y_off, block_w, block_h, wrap_enabled, is_chroma, \ | ||
| 189 | is_chroma ? CHROMA_EXTRA_BEFORE : LUMA_EXTRA_BEFORE, is_chroma ? CHROMA_EXTRA_AFTER : LUMA_EXTRA_AFTER) | ||
| 190 | |||
| 191 | #define MC_EMULATED_EDGE_DMVR(dst, src, src_stride, x_sb, y_sb, x_off, y_off) \ | ||
| 192 | emulated_edge(lc, dst, src, src_stride, ref, x_sb, y_sb, x_off, y_off, block_w, block_h, wrap_enabled, is_chroma, \ | ||
| 193 | is_chroma ? CHROMA_EXTRA_BEFORE : LUMA_EXTRA_BEFORE, is_chroma ? CHROMA_EXTRA_AFTER : LUMA_EXTRA_AFTER) | ||
| 194 | |||
| 195 | #define MC_EMULATED_EDGE_BILINEAR(dst, src, src_stride, x_off, y_off) \ | ||
| 196 | emulated_edge(lc, dst, src, src_stride, ref, x_off, y_off, x_off, y_off, pred_w, pred_h, wrap_enabled, 0, \ | ||
| 197 | BILINEAR_EXTRA_BEFORE, BILINEAR_EXTRA_AFTER) | ||
| 198 | |||
| 199 | // part of 8.5.6.6 Weighted sample prediction process | ||
| 200 | 6467183 | static int derive_weight_uni(int *denom, int *wx, int *ox, | |
| 201 | const VVCLocalContext *lc, const MvField *mvf, const int c_idx) | ||
| 202 | { | ||
| 203 | 6467183 | const VVCFrameContext *fc = lc->fc; | |
| 204 | 6467183 | const VVCPPS *pps = fc->ps.pps; | |
| 205 | 6467183 | const VVCSH *sh = &lc->sc->sh; | |
| 206 |
4/4✓ Branch 0 taken 1707465 times.
✓ Branch 1 taken 4759718 times.
✓ Branch 2 taken 1593390 times.
✓ Branch 3 taken 114075 times.
|
12820291 | const int weight_flag = (IS_P(sh->r) && pps->r->pps_weighted_pred_flag) || |
| 207 |
4/4✓ Branch 0 taken 4759718 times.
✓ Branch 1 taken 1593390 times.
✓ Branch 2 taken 163995 times.
✓ Branch 3 taken 4595723 times.
|
6353108 | (IS_B(sh->r) && pps->r->pps_weighted_bipred_flag); |
| 208 |
2/2✓ Branch 0 taken 278070 times.
✓ Branch 1 taken 6189113 times.
|
6467183 | if (weight_flag) { |
| 209 | 278070 | const int lx = mvf->pred_flag - PF_L0; | |
| 210 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 278070 times.
|
278070 | const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt; |
| 211 | |||
| 212 | 278070 | *denom = w->log2_denom[c_idx > 0]; | |
| 213 | 278070 | *wx = w->weight[lx][c_idx][mvf->ref_idx[lx]]; | |
| 214 | 278070 | *ox = w->offset[lx][c_idx][mvf->ref_idx[lx]]; | |
| 215 | } | ||
| 216 | 6467183 | return weight_flag; | |
| 217 | } | ||
| 218 | |||
| 219 | // part of 8.5.6.6 Weighted sample prediction process | ||
| 220 | 7457655 | static int derive_weight(int *denom, int *w0, int *w1, int *o0, int *o1, | |
| 221 | const VVCLocalContext *lc, const MvField *mvf, const int c_idx, const int dmvr_flag) | ||
| 222 | { | ||
| 223 | 7457655 | const VVCFrameContext *fc = lc->fc; | |
| 224 | 7457655 | const VVCPPS *pps = fc->ps.pps; | |
| 225 | 7457655 | const VVCSH *sh = &lc->sc->sh; | |
| 226 | 7457655 | const int bcw_idx = mvf->bcw_idx; | |
| 227 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 7457655 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
14915310 | const int weight_flag = (IS_P(sh->r) && pps->r->pps_weighted_pred_flag) || |
| 228 |
5/6✓ Branch 0 taken 7457655 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 134292 times.
✓ Branch 3 taken 7323363 times.
✓ Branch 4 taken 134280 times.
✓ Branch 5 taken 12 times.
|
7457655 | (IS_B(sh->r) && pps->r->pps_weighted_bipred_flag && !dmvr_flag); |
| 229 |
8/8✓ Branch 0 taken 7323375 times.
✓ Branch 1 taken 134280 times.
✓ Branch 2 taken 537580 times.
✓ Branch 3 taken 6785795 times.
✓ Branch 4 taken 538183 times.
✓ Branch 5 taken 133677 times.
✓ Branch 6 taken 3844 times.
✓ Branch 7 taken 534339 times.
|
7457655 | if ((!weight_flag && !bcw_idx) || (bcw_idx && lc->cu->ciip_flag)) |
| 230 | 6789639 | return 0; | |
| 231 | |||
| 232 |
2/2✓ Branch 0 taken 534339 times.
✓ Branch 1 taken 133677 times.
|
668016 | if (bcw_idx) { |
| 233 | 534339 | *denom = 2; | |
| 234 | 534339 | *w1 = bcw_w_lut[bcw_idx]; | |
| 235 | 534339 | *w0 = 8 - *w1; | |
| 236 | 534339 | *o0 = *o1 = 0; | |
| 237 | } else { | ||
| 238 | 133677 | const VVCPPS *pps = fc->ps.pps; | |
| 239 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 133677 times.
|
133677 | const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt; |
| 240 | |||
| 241 | 133677 | *denom = w->log2_denom[c_idx > 0]; | |
| 242 | 133677 | *w0 = w->weight[L0][c_idx][mvf->ref_idx[L0]]; | |
| 243 | 133677 | *w1 = w->weight[L1][c_idx][mvf->ref_idx[L1]]; | |
| 244 | 133677 | *o0 = w->offset[L0][c_idx][mvf->ref_idx[L0]]; | |
| 245 | 133677 | *o1 = w->offset[L1][c_idx][mvf->ref_idx[L1]]; | |
| 246 | } | ||
| 247 | 668016 | return 1; | |
| 248 | } | ||
| 249 | |||
| 250 | #define INTER_FILTER(t, frac) (is_chroma ? ff_vvc_inter_chroma_filters[t][frac] : ff_vvc_inter_luma_filters[t][frac]) | ||
| 251 | |||
| 252 | 155738 | static void mc(VVCLocalContext *lc, int16_t *dst, const VVCFrame *ref, const Mv *mv, | |
| 253 | int x_off, int y_off, const int block_w, const int block_h, const int c_idx) | ||
| 254 | { | ||
| 255 | 155738 | const VVCFrameContext *fc = lc->fc; | |
| 256 | 155738 | const PredictionUnit *pu = &lc->cu->pu; | |
| 257 | 155738 | const uint8_t *src = ref->frame->data[c_idx]; | |
| 258 | 155738 | ptrdiff_t src_stride = ref->frame->linesize[c_idx]; | |
| 259 | 155738 | const int is_chroma = !!c_idx; | |
| 260 | 155738 | const int hs = fc->ps.sps->hshift[c_idx]; | |
| 261 | 155738 | const int vs = fc->ps.sps->vshift[c_idx]; | |
| 262 | 155738 | const int idx = av_log2(block_w) - 1; | |
| 263 | 155738 | const intptr_t mx = av_zero_extend(mv->x, 4 + hs) << (is_chroma - hs); | |
| 264 | 155738 | const intptr_t my = av_zero_extend(mv->y, 4 + vs) << (is_chroma - vs); | |
| 265 |
4/4✓ Branch 0 taken 54954 times.
✓ Branch 1 taken 100784 times.
✓ Branch 2 taken 39 times.
✓ Branch 3 taken 54915 times.
|
155738 | const int hpel_if_idx = (is_chroma || pu->merge_gpm_flag) ? 0 : pu->mi.hpel_if_idx; |
| 266 |
2/2✓ Branch 0 taken 100784 times.
✓ Branch 1 taken 54954 times.
|
155738 | const int8_t *hf = INTER_FILTER(hpel_if_idx, mx); |
| 267 |
2/2✓ Branch 0 taken 100784 times.
✓ Branch 1 taken 54954 times.
|
155738 | const int8_t *vf = INTER_FILTER(hpel_if_idx, my); |
| 268 | 155738 | const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag; | |
| 269 | |||
| 270 | 155738 | x_off += mv->x >> (4 + hs); | |
| 271 | 155738 | y_off += mv->y >> (4 + vs); | |
| 272 | |||
| 273 |
4/4✓ Branch 0 taken 100784 times.
✓ Branch 1 taken 54954 times.
✓ Branch 2 taken 100784 times.
✓ Branch 3 taken 54954 times.
|
155738 | MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off); |
| 274 | 155738 | fc->vvcdsp.inter.put[is_chroma][idx][!!my][!!mx](dst, src, src_stride, block_h, hf, vf, block_w); | |
| 275 | 155738 | } | |
| 276 | |||
| 277 | 3980338 | static void mc_uni(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, | |
| 278 | const VVCFrame *ref, const MvField *mvf, int x_off, int y_off, const int block_w, const int block_h, | ||
| 279 | const int c_idx) | ||
| 280 | { | ||
| 281 | 3980338 | const VVCFrameContext *fc = lc->fc; | |
| 282 | 3980338 | const PredictionUnit *pu = &lc->cu->pu; | |
| 283 | 3980338 | const uint8_t *src = ref->frame->data[c_idx]; | |
| 284 | 3980338 | ptrdiff_t src_stride = ref->frame->linesize[c_idx]; | |
| 285 | 3980338 | const int lx = mvf->pred_flag - PF_L0; | |
| 286 | 3980338 | const int hs = fc->ps.sps->hshift[c_idx]; | |
| 287 | 3980338 | const int vs = fc->ps.sps->vshift[c_idx]; | |
| 288 | 3980338 | const int idx = av_log2(block_w) - 1; | |
| 289 | 3980338 | const Mv *mv = &mvf->mv[lx]; | |
| 290 | 3980338 | const int is_chroma = !!c_idx; | |
| 291 | 3980338 | const intptr_t mx = av_zero_extend(mv->x, 4 + hs) << (is_chroma - hs); | |
| 292 | 3980338 | const intptr_t my = av_zero_extend(mv->y, 4 + vs) << (is_chroma - vs); | |
| 293 |
2/2✓ Branch 0 taken 786876 times.
✓ Branch 1 taken 3193462 times.
|
3980338 | const int hpel_if_idx = is_chroma ? 0 : pu->mi.hpel_if_idx; |
| 294 |
2/2✓ Branch 0 taken 3193462 times.
✓ Branch 1 taken 786876 times.
|
3980338 | const int8_t *hf = INTER_FILTER(hpel_if_idx, mx); |
| 295 |
2/2✓ Branch 0 taken 3193462 times.
✓ Branch 1 taken 786876 times.
|
3980338 | const int8_t *vf = INTER_FILTER(hpel_if_idx, my); |
| 296 | 3980338 | const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag; | |
| 297 | int denom, wx, ox; | ||
| 298 | |||
| 299 | 3980338 | x_off += mv->x >> (4 + hs); | |
| 300 | 3980338 | y_off += mv->y >> (4 + vs); | |
| 301 | |||
| 302 |
4/4✓ Branch 0 taken 3193462 times.
✓ Branch 1 taken 786876 times.
✓ Branch 2 taken 3193462 times.
✓ Branch 3 taken 786876 times.
|
3980338 | MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off); |
| 303 |
2/2✓ Branch 1 taken 133490 times.
✓ Branch 2 taken 3846848 times.
|
3980338 | if (derive_weight_uni(&denom, &wx, &ox, lc, mvf, c_idx)) { |
| 304 | 133490 | fc->vvcdsp.inter.put_uni_w[is_chroma][idx][!!my][!!mx](dst, dst_stride, src, src_stride, | |
| 305 | block_h, denom, wx, ox, hf, vf, block_w); | ||
| 306 | } else { | ||
| 307 | 3846848 | fc->vvcdsp.inter.put_uni[is_chroma][idx][!!my][!!mx](dst, dst_stride, src, src_stride, | |
| 308 | block_h, hf, vf, block_w); | ||
| 309 | } | ||
| 310 | 3980338 | } | |
| 311 | |||
| 312 | 6403365 | static void mc_bi(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, | |
| 313 | const VVCFrame *ref0, const VVCFrame *ref1, const MvField *mvf, const MvField *orig_mv, | ||
| 314 | const int x_off, const int y_off, const int block_w, const int block_h, const int c_idx, | ||
| 315 | const int sb_bdof_flag) | ||
| 316 | { | ||
| 317 | 6403365 | const VVCFrameContext *fc = lc->fc; | |
| 318 | 6403365 | const PredictionUnit *pu = &lc->cu->pu; | |
| 319 | 6403365 | const int hs = fc->ps.sps->hshift[c_idx]; | |
| 320 | 6403365 | const int vs = fc->ps.sps->vshift[c_idx]; | |
| 321 | 6403365 | const int idx = av_log2(block_w) - 1; | |
| 322 | 6403365 | const VVCFrame *refs[] = { ref0, ref1 }; | |
| 323 | 6403365 | int16_t *tmp[] = { lc->tmp + sb_bdof_flag * PROF_TEMP_OFFSET, lc->tmp1 + sb_bdof_flag * PROF_TEMP_OFFSET }; | |
| 324 | int denom, w0, w1, o0, o1; | ||
| 325 | 6403365 | const int weight_flag = derive_weight(&denom, &w0, &w1, &o0, &o1, lc, mvf, c_idx, pu->dmvr_flag); | |
| 326 | 6403365 | const int is_chroma = !!c_idx; | |
| 327 |
2/2✓ Branch 0 taken 1817441 times.
✓ Branch 1 taken 4585924 times.
|
6403365 | const int hpel_if_idx = is_chroma ? 0 : pu->mi.hpel_if_idx; |
| 328 | |||
| 329 |
2/2✓ Branch 0 taken 12806730 times.
✓ Branch 1 taken 6403365 times.
|
19210095 | for (int i = L0; i <= L1; i++) { |
| 330 | 12806730 | const Mv *mv = mvf->mv + i; | |
| 331 | 12806730 | const int mx = av_zero_extend(mv->x, 4 + hs) << (is_chroma - hs); | |
| 332 | 12806730 | const int my = av_zero_extend(mv->y, 4 + vs) << (is_chroma - vs); | |
| 333 | 12806730 | const int ox = x_off + (mv->x >> (4 + hs)); | |
| 334 | 12806730 | const int oy = y_off + (mv->y >> (4 + vs)); | |
| 335 | 12806730 | const VVCFrame *ref = refs[i]; | |
| 336 | 12806730 | ptrdiff_t src_stride = ref->frame->linesize[c_idx]; | |
| 337 | 12806730 | const uint8_t *src = ref->frame->data[c_idx]; | |
| 338 |
2/2✓ Branch 0 taken 9171848 times.
✓ Branch 1 taken 3634882 times.
|
12806730 | const int8_t *hf = INTER_FILTER(hpel_if_idx, mx); |
| 339 |
2/2✓ Branch 0 taken 9171848 times.
✓ Branch 1 taken 3634882 times.
|
12806730 | const int8_t *vf = INTER_FILTER(hpel_if_idx, my); |
| 340 | 12806730 | const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag; | |
| 341 | |||
| 342 |
2/2✓ Branch 0 taken 6664892 times.
✓ Branch 1 taken 6141838 times.
|
12806730 | if (pu->dmvr_flag) { |
| 343 | 6664892 | const int x_sb = x_off + (orig_mv->mv[i].x >> (4 + hs)); | |
| 344 | 6664892 | const int y_sb = y_off + (orig_mv->mv[i].y >> (4 + vs)); | |
| 345 | |||
| 346 |
4/4✓ Branch 0 taken 4432304 times.
✓ Branch 1 taken 2232588 times.
✓ Branch 2 taken 4432304 times.
✓ Branch 3 taken 2232588 times.
|
6664892 | MC_EMULATED_EDGE_DMVR(lc->edge_emu_buffer, &src, &src_stride, x_sb, y_sb, ox, oy); |
| 347 | } else { | ||
| 348 |
4/4✓ Branch 0 taken 4739544 times.
✓ Branch 1 taken 1402294 times.
✓ Branch 2 taken 4739544 times.
✓ Branch 3 taken 1402294 times.
|
6141838 | MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, ox, oy); |
| 349 | } | ||
| 350 | 12806730 | fc->vvcdsp.inter.put[is_chroma][idx][!!my][!!mx](tmp[i], src, src_stride, block_h, hf, vf, block_w); | |
| 351 |
2/2✓ Branch 0 taken 715100 times.
✓ Branch 1 taken 12091630 times.
|
12806730 | if (sb_bdof_flag) |
| 352 | 715100 | fc->vvcdsp.inter.bdof_fetch_samples(tmp[i], src, src_stride, mx, my, block_w, block_h); | |
| 353 | } | ||
| 354 |
2/2✓ Branch 0 taken 357550 times.
✓ Branch 1 taken 6045815 times.
|
6403365 | if (sb_bdof_flag) |
| 355 | 357550 | fc->vvcdsp.inter.apply_bdof(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h); | |
| 356 |
2/2✓ Branch 0 taken 381272 times.
✓ Branch 1 taken 5664543 times.
|
6045815 | else if (weight_flag) |
| 357 | 381272 | fc->vvcdsp.inter.w_avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h, denom, w0, w1, o0, o1); | |
| 358 | else | ||
| 359 | 5664543 | fc->vvcdsp.inter.avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h); | |
| 360 | 6403365 | } | |
| 361 | |||
| 362 | 65406 | static const int8_t* inter_filter_scaled(const int scale, const int is_chroma, const int is_affine) | |
| 363 | { | ||
| 364 | #define SCALE_THRESHOLD_1 20480 | ||
| 365 | #define SCALE_THRESHOLD_2 28672 | ||
| 366 | |||
| 367 | 65406 | const int i = (scale > SCALE_THRESHOLD_2) + (scale > SCALE_THRESHOLD_1); | |
| 368 | |||
| 369 |
2/2✓ Branch 0 taken 40882 times.
✓ Branch 1 taken 24524 times.
|
65406 | if (!is_chroma) { |
| 370 |
2/2✓ Branch 0 taken 2722 times.
✓ Branch 1 taken 38160 times.
|
40882 | if (!is_affine) |
| 371 | 2722 | return &ff_vvc_inter_luma_filters[i + !!i][0][0]; //hpel 1 is not needed for scaled | |
| 372 | 38160 | return &ff_vvc_inter_luma_filters[VVC_INTER_LUMA_FILTER_TYPE_AFFINE + i][0][0]; | |
| 373 | } | ||
| 374 | |||
| 375 | 24524 | return &ff_vvc_inter_chroma_filters[i][0][0]; | |
| 376 | } | ||
| 377 | #define INTER_FILTER_SCALED(scale) inter_filter_scaled(scale, is_chroma, is_affine) | ||
| 378 | |||
| 379 | #define SCALED_CHROMA_ADDIN(scale, collocated_flag) (is_chroma ? (collocated_flag ? 0 : 8 * (scale - (1 << 14))) : 0) | ||
| 380 | #define SCALED_REF_SB(off, scaling_off, ref_mv, scale, add, shift) ((((off - (scaling_off << shift)) << (4 + shift)) + ref_mv) * scale + add) | ||
| 381 | #define SCALED_REF(ref_sb, offset, shift) (FFSIGN(ref_sb) * ((FFABS(ref_sb) + (128 << is_chroma)) >> (8 + is_chroma)) + (offset << (10 - shift)) + (32 >> is_chroma)) | ||
| 382 | #define SCALED_STEP(scale) ((scale + 8) >> 4) | ||
| 383 | |||
| 384 | 32703 | static void scaled_ref_pos_and_step(const VVCLocalContext *lc, const VVCRefPic *refp, const Mv *mv, const int x_off, const int y_off, const int c_idx, | |
| 385 | int *x, int *y, int *dx, int *dy) | ||
| 386 | { | ||
| 387 | 32703 | const VVCFrameContext *fc = lc->fc; | |
| 388 | 32703 | const VVCSPS *sps = fc->ps.sps; | |
| 389 | 32703 | const int is_chroma = !!c_idx; | |
| 390 | 32703 | const int hs = sps->hshift[c_idx]; | |
| 391 | 32703 | const int vs = sps->vshift[c_idx]; | |
| 392 | 32703 | const int left_offset = fc->ref->scaling_win.left_offset; | |
| 393 | 32703 | const int top_offset = fc->ref->scaling_win.top_offset; | |
| 394 |
3/4✓ Branch 0 taken 12262 times.
✓ Branch 1 taken 20441 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12262 times.
|
32703 | const int addx = SCALED_CHROMA_ADDIN(refp->scale[0], sps->r->sps_chroma_horizontal_collocated_flag); |
| 395 |
3/4✓ Branch 0 taken 12262 times.
✓ Branch 1 taken 20441 times.
✓ Branch 2 taken 12262 times.
✗ Branch 3 not taken.
|
32703 | const int addy = SCALED_CHROMA_ADDIN(refp->scale[1], sps->r->sps_chroma_vertical_collocated_flag); |
| 396 | 32703 | const int refx_sb = SCALED_REF_SB(x_off, left_offset, mv->x, refp->scale[0], addx, hs); | |
| 397 | 32703 | const int refy_sb = SCALED_REF_SB(y_off, top_offset, mv->y, refp->scale[1], addy, vs); | |
| 398 | |||
| 399 |
2/2✓ Branch 0 taken 32637 times.
✓ Branch 1 taken 66 times.
|
32703 | *x = SCALED_REF(refx_sb, left_offset, hs); |
| 400 |
2/2✓ Branch 0 taken 32535 times.
✓ Branch 1 taken 168 times.
|
32703 | *y = SCALED_REF(refy_sb, top_offset, vs); |
| 401 | 32703 | *dx = SCALED_STEP(refp->scale[0]); | |
| 402 | 32703 | *dy = SCALED_STEP(refp->scale[1]); | |
| 403 | 32703 | } | |
| 404 | |||
| 405 | 32703 | static void emulated_edge_scaled(VVCLocalContext *lc, const uint8_t **src, ptrdiff_t *src_stride, int *src_height, | |
| 406 | const VVCFrame *ref, const int x, const int y, const int dx, const int dy, const int w, const int h, const int is_chroma) | ||
| 407 | { | ||
| 408 | 32703 | const int x_off = SCALED_INT(x); | |
| 409 | 32703 | const int y_off = SCALED_INT(y); | |
| 410 | 32703 | const int x_end = SCALED_INT(x + w * dx); | |
| 411 | 32703 | const int y_end = SCALED_INT(y + h * dy); | |
| 412 | 32703 | const int x_last = SCALED_INT(x + (w - 1) * dx); | |
| 413 | 32703 | const int y_last = SCALED_INT(y + (h - 1) * dy); | |
| 414 | 32703 | const int block_w = x_end - x_off + (x_end == x_last); | |
| 415 | 32703 | const int block_h = *src_height = y_end - y_off + (y_end == y_last); | |
| 416 | 32703 | const int wrap_enabled = 0; | |
| 417 | |||
| 418 |
4/4✓ Branch 0 taken 12262 times.
✓ Branch 1 taken 20441 times.
✓ Branch 2 taken 12262 times.
✓ Branch 3 taken 20441 times.
|
32703 | MC_EMULATED_EDGE(lc->edge_emu_buffer, src, src_stride, x_off, y_off); |
| 419 | 32703 | } | |
| 420 | |||
| 421 | 5946 | static void mc_scaled(VVCLocalContext *lc, int16_t *dst, const VVCRefPic *refp, const Mv *mv, | |
| 422 | int x_off, int y_off, const int block_w, const int block_h, const int c_idx) | ||
| 423 | { | ||
| 424 | 5946 | const VVCFrameContext *fc = lc->fc; | |
| 425 | 5946 | const PredictionUnit *pu = &lc->cu->pu; | |
| 426 | 5946 | const uint8_t *src = refp->ref->frame->data[c_idx]; | |
| 427 | 5946 | ptrdiff_t src_stride = refp->ref->frame->linesize[c_idx]; | |
| 428 | 5946 | const int is_affine = pu->inter_affine_flag; | |
| 429 | 5946 | const int is_chroma = !!c_idx; | |
| 430 | 5946 | const int idx = av_log2(block_w) - 1; | |
| 431 | 5946 | const int8_t *hf = INTER_FILTER_SCALED(refp->scale[0]); | |
| 432 | 5946 | const int8_t *vf = INTER_FILTER_SCALED(refp->scale[1]); | |
| 433 | int x, y, dx, dy, src_height; | ||
| 434 | |||
| 435 | 5946 | scaled_ref_pos_and_step(lc, refp, mv, x_off, y_off, c_idx, &x, &y, &dx, &dy); | |
| 436 | 5946 | emulated_edge_scaled(lc, &src, &src_stride, &src_height, refp->ref, x, y, dx, dy, block_w, block_h, is_chroma); | |
| 437 | 5946 | fc->vvcdsp.inter.put_scaled[is_chroma][idx](dst, src, src_stride, src_height, x, y, dx, dy, block_h, hf, vf, block_w); | |
| 438 | 5946 | } | |
| 439 | |||
| 440 | 26757 | static void mc_uni_scaled(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, const VVCRefPic *refp, | |
| 441 | const MvField *mvf, const int x_off, const int y_off, const int block_w, const int block_h, const int c_idx) | ||
| 442 | { | ||
| 443 | 26757 | const VVCFrameContext *fc = lc->fc; | |
| 444 | 26757 | const PredictionUnit *pu = &lc->cu->pu; | |
| 445 | 26757 | const uint8_t *src = refp->ref->frame->data[c_idx]; | |
| 446 | 26757 | ptrdiff_t src_stride = refp->ref->frame->linesize[c_idx]; | |
| 447 | 26757 | const int lx = mvf->pred_flag - PF_L0; | |
| 448 | 26757 | const Mv *mv = &mvf->mv[lx]; | |
| 449 | 26757 | const int is_affine = pu->inter_affine_flag; | |
| 450 | 26757 | const int is_chroma = !!c_idx; | |
| 451 | 26757 | const int idx = av_log2(block_w) - 1; | |
| 452 | 26757 | const int8_t *hf = INTER_FILTER_SCALED(refp->scale[0]); | |
| 453 | 26757 | const int8_t *vf = INTER_FILTER_SCALED(refp->scale[1]); | |
| 454 | int denom, wx, ox, x, y, dx, dy, src_height; | ||
| 455 | |||
| 456 | 26757 | scaled_ref_pos_and_step(lc, refp, mv, x_off, y_off, c_idx, &x, &y, &dx, &dy); | |
| 457 | 26757 | emulated_edge_scaled(lc, &src, &src_stride, &src_height, refp->ref, x, y, dx, dy, block_w, block_h, is_chroma); | |
| 458 | |||
| 459 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 26757 times.
|
26757 | if (derive_weight_uni(&denom, &wx, &ox, lc, mvf, c_idx)) { |
| 460 | ✗ | fc->vvcdsp.inter.put_uni_w_scaled[is_chroma][idx](dst, dst_stride, src, src_stride, src_height, | |
| 461 | x, y, dx, dy, block_h, denom, wx, ox, hf, vf, block_w); | ||
| 462 | } else { | ||
| 463 | 26757 | fc->vvcdsp.inter.put_uni_scaled[is_chroma][idx](dst, dst_stride, src, src_stride, src_height, | |
| 464 | x, y, dx, dy, block_h, hf, vf, block_w); | ||
| 465 | } | ||
| 466 | 26757 | } | |
| 467 | |||
| 468 | 1086 | static void mc_bi_scaled(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, | |
| 469 | const VVCRefPic *refp0, const VVCRefPic *refp1, const MvField *mvf, | ||
| 470 | const int x_off, const int y_off, const int block_w, const int block_h, const int c_idx) | ||
| 471 | { | ||
| 472 | int denom, w0, w1, o0, o1; | ||
| 473 | 1086 | const VVCFrameContext *fc = lc->fc; | |
| 474 | 1086 | const int weight_flag = derive_weight(&denom, &w0, &w1, &o0, &o1, lc, mvf, c_idx, lc->cu->pu.dmvr_flag); | |
| 475 | 1086 | const VVCRefPic *refps[] = { refp0, refp1 }; | |
| 476 | 1086 | int16_t *tmp[] = { lc->tmp, lc->tmp1 }; | |
| 477 | |||
| 478 |
2/2✓ Branch 0 taken 2172 times.
✓ Branch 1 taken 1086 times.
|
3258 | for (int i = L0; i <= L1; i++) { |
| 479 | 2172 | const Mv *mv = mvf->mv + i; | |
| 480 | 2172 | const VVCRefPic *refp = refps[i]; | |
| 481 | |||
| 482 |
2/2✓ Branch 0 taken 2055 times.
✓ Branch 1 taken 117 times.
|
2172 | if (refp->is_scaled) |
| 483 | 2055 | mc_scaled(lc, tmp[i], refp, mv, x_off, y_off, block_w, block_h, c_idx); | |
| 484 | else | ||
| 485 | 117 | mc(lc, tmp[i], refp->ref, mv, x_off, y_off, block_w, block_h, c_idx); | |
| 486 | } | ||
| 487 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1086 times.
|
1086 | if (weight_flag) |
| 488 | ✗ | fc->vvcdsp.inter.w_avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h, denom, w0, w1, o0, o1); | |
| 489 | else | ||
| 490 | 1086 | fc->vvcdsp.inter.avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h); | |
| 491 | 1086 | } | |
| 492 | |||
| 493 | 2460088 | static void luma_prof_uni(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, | |
| 494 | const VVCFrame *ref, const MvField *mvf, int x_off, int y_off, const int block_w, const int block_h, | ||
| 495 | const int cb_prof_flag, const int16_t *diff_mv_x, const int16_t *diff_mv_y) | ||
| 496 | { | ||
| 497 | 2460088 | const VVCFrameContext *fc = lc->fc; | |
| 498 | 2460088 | const uint8_t *src = ref->frame->data[LUMA]; | |
| 499 | 2460088 | ptrdiff_t src_stride = ref->frame->linesize[LUMA]; | |
| 500 | 2460088 | uint16_t *prof_tmp = lc->tmp + PROF_TEMP_OFFSET; | |
| 501 | 2460088 | const int idx = av_log2(block_w) - 1; | |
| 502 | 2460088 | const int lx = mvf->pred_flag - PF_L0; | |
| 503 | 2460088 | const Mv *mv = mvf->mv + lx; | |
| 504 | 2460088 | const int mx = mv->x & 0xf; | |
| 505 | 2460088 | const int my = mv->y & 0xf; | |
| 506 | 2460088 | const int8_t *hf = ff_vvc_inter_luma_filters[VVC_INTER_LUMA_FILTER_TYPE_AFFINE][mx]; | |
| 507 | 2460088 | const int8_t *vf = ff_vvc_inter_luma_filters[VVC_INTER_LUMA_FILTER_TYPE_AFFINE][my]; | |
| 508 | int denom, wx, ox; | ||
| 509 | 2460088 | const int weight_flag = derive_weight_uni(&denom, &wx, &ox, lc, mvf, LUMA); | |
| 510 | 2460088 | const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag; | |
| 511 | 2460088 | const int is_chroma = 0; | |
| 512 | |||
| 513 | 2460088 | x_off += mv->x >> 4; | |
| 514 | 2460088 | y_off += mv->y >> 4; | |
| 515 | |||
| 516 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 2460088 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2460088 times.
|
2460088 | MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off); |
| 517 |
2/2✓ Branch 0 taken 2150840 times.
✓ Branch 1 taken 309248 times.
|
2460088 | if (cb_prof_flag) { |
| 518 | 2150840 | fc->vvcdsp.inter.put[LUMA][idx][!!my][!!mx](prof_tmp, src, src_stride, AFFINE_MIN_BLOCK_SIZE, hf, vf, AFFINE_MIN_BLOCK_SIZE); | |
| 519 | 2150840 | fc->vvcdsp.inter.fetch_samples(prof_tmp, src, src_stride, mx, my); | |
| 520 |
2/2✓ Branch 0 taken 2136508 times.
✓ Branch 1 taken 14332 times.
|
2150840 | if (!weight_flag) |
| 521 | 2136508 | fc->vvcdsp.inter.apply_prof_uni(dst, dst_stride, prof_tmp, diff_mv_x, diff_mv_y); | |
| 522 | else | ||
| 523 | 14332 | fc->vvcdsp.inter.apply_prof_uni_w(dst, dst_stride, prof_tmp, diff_mv_x, diff_mv_y, denom, wx, ox); | |
| 524 | } else { | ||
| 525 |
2/2✓ Branch 0 taken 179000 times.
✓ Branch 1 taken 130248 times.
|
309248 | if (!weight_flag) |
| 526 | 179000 | fc->vvcdsp.inter.put_uni[LUMA][idx][!!my][!!mx](dst, dst_stride, src, src_stride, block_h, hf, vf, block_w); | |
| 527 | else | ||
| 528 | 130248 | 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); | |
| 529 | } | ||
| 530 | 2460088 | } | |
| 531 | |||
| 532 | 2103336 | static void luma_prof(VVCLocalContext *lc, int16_t *dst, const VVCFrame *ref, | |
| 533 | const Mv *mv , const int x_off, const int y_off, const int block_w, const int block_h, const int lx) | ||
| 534 | { | ||
| 535 | 2103336 | const VVCFrameContext *fc = lc->fc; | |
| 536 | 2103336 | const PredictionUnit *pu = &lc->cu->pu; | |
| 537 | 2103336 | const int mx = mv->x & 0xf; | |
| 538 | 2103336 | const int my = mv->y & 0xf; | |
| 539 | 2103336 | const int ox = x_off + (mv->x >> 4); | |
| 540 | 2103336 | const int oy = y_off + (mv->y >> 4); | |
| 541 | 2103336 | const int idx = av_log2(block_w) - 1; | |
| 542 | 2103336 | const int is_chroma = 0; | |
| 543 | 2103336 | uint16_t *prof_tmp = lc->tmp2 + PROF_TEMP_OFFSET; | |
| 544 | 2103336 | ptrdiff_t src_stride = ref->frame->linesize[LUMA]; | |
| 545 | 2103336 | const uint8_t *src = ref->frame->data[LUMA]; | |
| 546 | 2103336 | const int8_t *hf = ff_vvc_inter_luma_filters[VVC_INTER_LUMA_FILTER_TYPE_AFFINE][mx]; | |
| 547 | 2103336 | const int8_t *vf = ff_vvc_inter_luma_filters[VVC_INTER_LUMA_FILTER_TYPE_AFFINE][my]; | |
| 548 | 2103336 | const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag; | |
| 549 | |||
| 550 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 2103336 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2103336 times.
|
2103336 | MC_EMULATED_EDGE(lc->edge_emu_buffer, &src, &src_stride, ox, oy); |
| 551 |
2/2✓ Branch 0 taken 692840 times.
✓ Branch 1 taken 1410496 times.
|
2103336 | if (!pu->cb_prof_flag[lx]) { |
| 552 | 692840 | fc->vvcdsp.inter.put[LUMA][idx][!!my][!!mx](dst, src, src_stride, block_h, hf, vf, block_w); | |
| 553 | } else { | ||
| 554 | 1410496 | fc->vvcdsp.inter.put[LUMA][idx][!!my][!!mx](prof_tmp, src, src_stride, AFFINE_MIN_BLOCK_SIZE, hf, vf, AFFINE_MIN_BLOCK_SIZE); | |
| 555 | 1410496 | fc->vvcdsp.inter.fetch_samples(prof_tmp, src, src_stride, mx, my); | |
| 556 | 1410496 | fc->vvcdsp.inter.apply_prof(dst, prof_tmp, pu->diff_mv_x[lx], pu->diff_mv_y[lx]); | |
| 557 | } | ||
| 558 | 2103336 | } | |
| 559 | |||
| 560 | 1053204 | static void luma_prof_bi(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_stride, | |
| 561 | const VVCRefPic *ref0, const VVCRefPic *ref1, const MvField *mvf, const int x_off, const int y_off, | ||
| 562 | const int block_w, const int block_h) | ||
| 563 | { | ||
| 564 | 1053204 | const VVCFrameContext *fc = lc->fc; | |
| 565 | 1053204 | const VVCRefPic *refps[] = { ref0, ref1 }; | |
| 566 | 1053204 | int16_t *tmp[] = { lc->tmp, lc->tmp1 }; | |
| 567 | int denom, w0, w1, o0, o1; | ||
| 568 | 1053204 | const int weight_flag = derive_weight(&denom, &w0, &w1, &o0, &o1, lc, mvf, LUMA, 0); | |
| 569 | |||
| 570 |
2/2✓ Branch 0 taken 2106408 times.
✓ Branch 1 taken 1053204 times.
|
3159612 | for (int i = L0; i <= L1; i++) { |
| 571 | 2106408 | const VVCRefPic *refp = refps[i]; | |
| 572 | 2106408 | const Mv *mv = mvf->mv + i; | |
| 573 | |||
| 574 |
2/2✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 2103336 times.
|
2106408 | if (refp->is_scaled) |
| 575 | 3072 | mc_scaled(lc, tmp[i], refp, mv, x_off, y_off, block_w, block_h, LUMA); | |
| 576 | else | ||
| 577 | 2103336 | luma_prof(lc, tmp[i], refp->ref, mv, x_off, y_off, block_w, block_h, i); | |
| 578 | } | ||
| 579 | |||
| 580 |
2/2✓ Branch 0 taken 286720 times.
✓ Branch 1 taken 766484 times.
|
1053204 | if (weight_flag) |
| 581 | 286720 | fc->vvcdsp.inter.w_avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h, denom, w0, w1, o0, o1); | |
| 582 | else | ||
| 583 | 766484 | fc->vvcdsp.inter.avg(dst, dst_stride, tmp[L0], tmp[L1], block_w, block_h); | |
| 584 | 1053204 | } | |
| 585 | |||
| 586 | 8568981 | static int pred_get_refs(const VVCLocalContext *lc, VVCRefPic *refp[2], const MvField *mv) | |
| 587 | { | ||
| 588 | 8568981 | RefPicList *rpl = lc->sc->rpl; | |
| 589 | |||
| 590 |
2/2✓ Branch 0 taken 17137962 times.
✓ Branch 1 taken 8568981 times.
|
25706943 | for (int mask = PF_L0; mask <= PF_L1; mask++) { |
| 591 |
2/2✓ Branch 0 taken 13046512 times.
✓ Branch 1 taken 4091450 times.
|
17137962 | if (mv->pred_flag & mask) { |
| 592 | 13046512 | const int lx = mask - PF_L0; | |
| 593 | 13046512 | refp[lx] = rpl[lx].refs + mv->ref_idx[lx]; | |
| 594 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13046512 times.
|
13046512 | if (!refp[lx]->ref) |
| 595 | ✗ | return AVERROR_INVALIDDATA; | |
| 596 | } | ||
| 597 | } | ||
| 598 | 8568981 | return 0; | |
| 599 | } | ||
| 600 | |||
| 601 | #define POS(c_idx, x, y) \ | ||
| 602 | &fc->frame->data[c_idx][((y) >> fc->ps.sps->vshift[c_idx]) * fc->frame->linesize[c_idx] + \ | ||
| 603 | (((x) >> fc->ps.sps->hshift[c_idx]) << fc->ps.sps->pixel_shift)] | ||
| 604 | |||
| 605 | 27594 | static void pred_gpm_blk(VVCLocalContext *lc) | |
| 606 | { | ||
| 607 | 27594 | const VVCFrameContext *fc = lc->fc; | |
| 608 | 27594 | const CodingUnit *cu = lc->cu; | |
| 609 | 27594 | const PredictionUnit *pu = &cu->pu; | |
| 610 | |||
| 611 | 27594 | const uint8_t angle_idx = ff_vvc_gpm_angle_idx[pu->gpm_partition_idx]; | |
| 612 | 27594 | const uint8_t weights_idx = ff_vvc_gpm_angle_to_weights_idx[angle_idx]; | |
| 613 | 27594 | const int w = av_log2(cu->cb_width) - 3; | |
| 614 | 27594 | const int h = av_log2(cu->cb_height) - 3; | |
| 615 | 27594 | const uint8_t off_x = ff_vvc_gpm_weights_offset_x[pu->gpm_partition_idx][h][w]; | |
| 616 | 27594 | const uint8_t off_y = ff_vvc_gpm_weights_offset_y[pu->gpm_partition_idx][h][w]; | |
| 617 | 27594 | const uint8_t mirror_type = ff_vvc_gpm_angle_to_mirror[angle_idx]; | |
| 618 | const uint8_t *weights; | ||
| 619 | |||
| 620 |
2/2✓ Branch 0 taken 25313 times.
✓ Branch 1 taken 2281 times.
|
27594 | const int c_end = fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1; |
| 621 | |||
| 622 | 27594 | int16_t *tmp[2] = {lc->tmp, lc->tmp1}; | |
| 623 | |||
| 624 |
2/2✓ Branch 0 taken 78220 times.
✓ Branch 1 taken 27594 times.
|
105814 | for (int c_idx = 0; c_idx < c_end; c_idx++) { |
| 625 | 78220 | const int hs = fc->ps.sps->hshift[c_idx]; | |
| 626 | 78220 | const int vs = fc->ps.sps->vshift[c_idx]; | |
| 627 | 78220 | const int x = lc->cu->x0 >> hs; | |
| 628 | 78220 | const int y = lc->cu->y0 >> vs; | |
| 629 | 78220 | const int width = cu->cb_width >> hs; | |
| 630 | 78220 | const int height = cu->cb_height >> vs; | |
| 631 | 78220 | uint8_t *dst = POS(c_idx, lc->cu->x0, lc->cu->y0); | |
| 632 | 78220 | ptrdiff_t dst_stride = fc->frame->linesize[c_idx]; | |
| 633 | |||
| 634 | 78220 | int step_x = 1 << hs; | |
| 635 | 78220 | int step_y = VVC_GPM_WEIGHT_SIZE << vs; | |
| 636 |
2/2✓ Branch 0 taken 49435 times.
✓ Branch 1 taken 28785 times.
|
78220 | if (!mirror_type) { |
| 637 | 49435 | weights = &ff_vvc_gpm_weights[weights_idx][off_y * VVC_GPM_WEIGHT_SIZE + off_x]; | |
| 638 |
2/2✓ Branch 0 taken 12311 times.
✓ Branch 1 taken 16474 times.
|
28785 | } else if (mirror_type == 1) { |
| 639 | 12311 | step_x = -step_x; | |
| 640 | 12311 | weights = &ff_vvc_gpm_weights[weights_idx][off_y * VVC_GPM_WEIGHT_SIZE + VVC_GPM_WEIGHT_SIZE - 1- off_x]; | |
| 641 | } else { | ||
| 642 | 16474 | step_y = -step_y; | |
| 643 | 16474 | weights = &ff_vvc_gpm_weights[weights_idx][(VVC_GPM_WEIGHT_SIZE - 1 - off_y) * VVC_GPM_WEIGHT_SIZE + off_x]; | |
| 644 | } | ||
| 645 | |||
| 646 |
2/2✓ Branch 0 taken 156440 times.
✓ Branch 1 taken 78220 times.
|
234660 | for (int i = 0; i < 2; i++) { |
| 647 | 156440 | const MvField *mv = pu->gpm_mv + i; | |
| 648 | 156440 | const int lx = mv->pred_flag - PF_L0; | |
| 649 | 156440 | VVCRefPic *refp = lc->sc->rpl[lx].refs + mv->ref_idx[lx]; | |
| 650 | |||
| 651 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 156440 times.
|
156440 | if (!refp->ref) |
| 652 | ✗ | return; | |
| 653 |
2/2✓ Branch 0 taken 819 times.
✓ Branch 1 taken 155621 times.
|
156440 | if (refp->is_scaled) |
| 654 | 819 | mc_scaled(lc, tmp[i], refp, mv->mv + lx, x, y, width, height, c_idx); | |
| 655 | else | ||
| 656 | 155621 | mc(lc, tmp[i], refp->ref, mv->mv + lx, x, y, width, height, c_idx); | |
| 657 | } | ||
| 658 | 78220 | fc->vvcdsp.inter.put_gpm(dst, dst_stride, width, height, tmp[0], tmp[1], weights, step_x, step_y); | |
| 659 | } | ||
| 660 | 27594 | return; | |
| 661 | } | ||
| 662 | |||
| 663 | 43833 | static int ciip_derive_intra_weight(const VVCLocalContext *lc, const int x0, const int y0, | |
| 664 | const int width, const int height) | ||
| 665 | { | ||
| 666 | 43833 | const VVCFrameContext *fc = lc->fc; | |
| 667 | 43833 | const VVCSPS *sps = fc->ps.sps; | |
| 668 | 43833 | const int x0b = av_zero_extend(x0, sps->ctb_log2_size_y); | |
| 669 | 43833 | const int y0b = av_zero_extend(y0, sps->ctb_log2_size_y); | |
| 670 |
4/4✓ Branch 0 taken 5187 times.
✓ Branch 1 taken 38646 times.
✓ Branch 2 taken 4249 times.
✓ Branch 3 taken 938 times.
|
43833 | const int available_l = lc->ctb_left_flag || x0b; |
| 671 |
4/4✓ Branch 0 taken 6832 times.
✓ Branch 1 taken 37001 times.
✓ Branch 2 taken 6016 times.
✓ Branch 3 taken 816 times.
|
43833 | const int available_u = lc->ctb_up_flag || y0b; |
| 672 | 43833 | const int min_pu_width = fc->ps.pps->min_pu_width; | |
| 673 | 43833 | int w = 1; | |
| 674 | |||
| 675 |
4/4✓ Branch 0 taken 43017 times.
✓ Branch 1 taken 816 times.
✓ Branch 2 taken 6198 times.
✓ Branch 3 taken 36819 times.
|
43833 | if (available_u &&fc->tab.mvf[((y0 - 1) >> MIN_PU_LOG2) * min_pu_width + ((x0 - 1 + width)>> MIN_PU_LOG2)].pred_flag == PF_INTRA) |
| 676 | 6198 | w++; | |
| 677 | |||
| 678 |
4/4✓ Branch 0 taken 42895 times.
✓ Branch 1 taken 938 times.
✓ Branch 2 taken 5922 times.
✓ Branch 3 taken 36973 times.
|
43833 | if (available_l && fc->tab.mvf[((y0 - 1 + height)>> MIN_PU_LOG2) * min_pu_width + ((x0 - 1) >> MIN_PU_LOG2)].pred_flag == PF_INTRA) |
| 679 | 5922 | w++; | |
| 680 | |||
| 681 | 43833 | return w; | |
| 682 | } | ||
| 683 | |||
| 684 | 3923387 | static void pred_regular(VVCLocalContext *lc, const MvField *mvf, const MvField *orig_mvf, | |
| 685 | const int x0, const int y0, const int sbw, const int sbh, const int sb_bdof_flag, const int c_start) | ||
| 686 | { | ||
| 687 | 3923387 | const VVCFrameContext *fc = lc->fc; | |
| 688 |
2/2✓ Branch 0 taken 3895100 times.
✓ Branch 1 taken 28287 times.
|
3923387 | const int c_end = fc->ps.sps->r->sps_chroma_format_idc ? CR : LUMA; |
| 689 | VVCRefPic *refp[2]; | ||
| 690 | |||
| 691 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3923387 times.
|
3923387 | if (pred_get_refs(lc, refp, mvf) < 0) |
| 692 | ✗ | return; | |
| 693 | |||
| 694 |
2/2✓ Branch 0 taken 10395538 times.
✓ Branch 1 taken 3923387 times.
|
14318925 | for (int c_idx = c_start; c_idx <= c_end; c_idx++) { |
| 695 | 10395538 | uint8_t *dst = POS(c_idx, x0, y0); | |
| 696 | 10395538 | const ptrdiff_t dst_stride = fc->frame->linesize[c_idx]; | |
| 697 | 10395538 | const int hs = fc->ps.sps->hshift[c_idx]; | |
| 698 | 10395538 | const int vs = fc->ps.sps->vshift[c_idx]; | |
| 699 | 10395538 | const int x = x0 >> hs; | |
| 700 | 10395538 | const int y = y0 >> vs; | |
| 701 | 10395538 | const int w = sbw >> hs; | |
| 702 | 10395538 | const int h = sbh >> vs; | |
| 703 | 10395538 | const int is_luma = !c_idx; | |
| 704 |
6/6✓ Branch 0 taken 48347 times.
✓ Branch 1 taken 10347191 times.
✓ Branch 2 taken 32020 times.
✓ Branch 3 taken 16327 times.
✓ Branch 4 taken 27506 times.
✓ Branch 5 taken 4514 times.
|
10395538 | const int do_ciip = lc->cu->ciip_flag && (is_luma || (w > 2)); |
| 705 |
2/2✓ Branch 0 taken 43833 times.
✓ Branch 1 taken 10351705 times.
|
10395538 | uint8_t *inter = do_ciip ? (uint8_t *)lc->ciip_tmp : dst; |
| 706 |
2/2✓ Branch 0 taken 10351705 times.
✓ Branch 1 taken 43833 times.
|
10395538 | const ptrdiff_t inter_stride = do_ciip ? (MAX_PB_SIZE * sizeof(uint16_t)) : dst_stride; |
| 707 |
4/4✓ Branch 0 taken 2605338 times.
✓ Branch 1 taken 7790200 times.
✓ Branch 2 taken 357550 times.
✓ Branch 3 taken 2247788 times.
|
10395538 | const int do_bdof = is_luma && sb_bdof_flag; |
| 708 | |||
| 709 |
2/2✓ Branch 0 taken 3991087 times.
✓ Branch 1 taken 6404451 times.
|
10395538 | if (mvf->pred_flag != PF_BI) { |
| 710 | 3991087 | const int lx = mvf->pred_flag - PF_L0; | |
| 711 | |||
| 712 |
2/2✓ Branch 0 taken 10749 times.
✓ Branch 1 taken 3980338 times.
|
3991087 | if (refp[lx]->is_scaled) { |
| 713 | 10749 | mc_uni_scaled(lc, inter, inter_stride, refp[lx], mvf, | |
| 714 | x, y, w, h, c_idx); | ||
| 715 | } else { | ||
| 716 | 3980338 | mc_uni(lc, inter, inter_stride, refp[lx]->ref, mvf, | |
| 717 | x, y, w, h, c_idx); | ||
| 718 | } | ||
| 719 | } else { | ||
| 720 |
4/4✓ Branch 0 taken 6403374 times.
✓ Branch 1 taken 1077 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 6403365 times.
|
6404451 | if (refp[L0]->is_scaled || refp[L1]->is_scaled) { |
| 721 | 1086 | mc_bi_scaled(lc, inter, inter_stride, refp[L0], refp[L1], mvf, | |
| 722 | x, y, w, h, c_idx); | ||
| 723 | } else { | ||
| 724 | 6403365 | mc_bi(lc, inter, inter_stride, refp[L0]->ref, refp[L1]->ref, mvf, orig_mvf, | |
| 725 | x, y, w, h, c_idx, do_bdof); | ||
| 726 | } | ||
| 727 | } | ||
| 728 |
2/2✓ Branch 0 taken 43833 times.
✓ Branch 1 taken 10351705 times.
|
10395538 | if (do_ciip) { |
| 729 | 43833 | const int intra_weight = ciip_derive_intra_weight(lc, x0, y0, sbw, sbh); | |
| 730 | 43833 | fc->vvcdsp.intra.intra_pred(lc, x0, y0, sbw, sbh, c_idx); | |
| 731 |
4/4✓ Branch 0 taken 16327 times.
✓ Branch 1 taken 27506 times.
✓ Branch 2 taken 8428 times.
✓ Branch 3 taken 7899 times.
|
43833 | if (!c_idx && lc->sc->sh.r->sh_lmcs_used_flag) |
| 732 | 8428 | fc->vvcdsp.lmcs.filter(inter, inter_stride, w, h, &fc->ps.lmcs.fwd_lut); | |
| 733 | 43833 | fc->vvcdsp.inter.put_ciip(dst, dst_stride, w, h, inter, inter_stride, intra_weight); | |
| 734 | } | ||
| 735 | } | ||
| 736 | } | ||
| 737 | |||
| 738 | // 8.5.3.5 Parametric motion vector refinement process | ||
| 739 | 514500 | static int parametric_mv_refine(const int *sad, const int stride) | |
| 740 | { | ||
| 741 | 514500 | const int sad_minus = sad[-stride]; | |
| 742 | 514500 | const int sad_center = sad[0]; | |
| 743 | 514500 | const int sad_plus = sad[stride]; | |
| 744 | int dmvc; | ||
| 745 | 514500 | int denom = (( sad_minus + sad_plus) - (sad_center << 1 ) ) << 3; | |
| 746 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 514500 times.
|
514500 | if (!denom) |
| 747 | ✗ | dmvc = 0; | |
| 748 | else { | ||
| 749 |
2/2✓ Branch 0 taken 58 times.
✓ Branch 1 taken 514442 times.
|
514500 | if (sad_minus == sad_center) |
| 750 | 58 | dmvc = -8; | |
| 751 |
2/2✓ Branch 0 taken 244 times.
✓ Branch 1 taken 514198 times.
|
514442 | else if (sad_plus == sad_center) |
| 752 | 244 | dmvc = 8; | |
| 753 | else { | ||
| 754 | 514198 | int num = ( sad_minus - sad_plus ) * (1 << 4); | |
| 755 | 514198 | int sign_num = 0; | |
| 756 | 514198 | int quotient = 0; | |
| 757 | 514198 | int counter = 3; | |
| 758 |
2/2✓ Branch 0 taken 260163 times.
✓ Branch 1 taken 254035 times.
|
514198 | if (num < 0 ) { |
| 759 | 260163 | num = - num; | |
| 760 | 260163 | sign_num = 1; | |
| 761 | } | ||
| 762 |
2/2✓ Branch 0 taken 1542594 times.
✓ Branch 1 taken 514198 times.
|
2056792 | while (counter > 0) { |
| 763 | 1542594 | counter = counter - 1; | |
| 764 | 1542594 | quotient = quotient << 1; | |
| 765 |
2/2✓ Branch 0 taken 445866 times.
✓ Branch 1 taken 1096728 times.
|
1542594 | if ( num >= denom ) { |
| 766 | 445866 | num = num - denom; | |
| 767 | 445866 | quotient = quotient + 1; | |
| 768 | } | ||
| 769 | 1542594 | denom = (denom >> 1); | |
| 770 | } | ||
| 771 |
2/2✓ Branch 0 taken 260163 times.
✓ Branch 1 taken 254035 times.
|
514198 | if (sign_num == 1 ) |
| 772 | 260163 | dmvc = -quotient; | |
| 773 | else | ||
| 774 | 254035 | dmvc = quotient; | |
| 775 | } | ||
| 776 | } | ||
| 777 | 514500 | return dmvc; | |
| 778 | } | ||
| 779 | |||
| 780 | #define SAD_ARRAY_SIZE 5 | ||
| 781 | //8.5.3 Decoder-side motion vector refinement process | ||
| 782 | 1116294 | static void dmvr_mv_refine(VVCLocalContext *lc, MvField *mvf, MvField *orig_mv, int *sb_bdof_flag, | |
| 783 | const VVCFrame *ref0, const VVCFrame *ref1, const int x_off, const int y_off, const int block_w, const int block_h) | ||
| 784 | { | ||
| 785 | 1116294 | const VVCFrameContext *fc = lc->fc; | |
| 786 | 1116294 | const int sr_range = 2; | |
| 787 | 1116294 | const VVCFrame *refs[] = { ref0, ref1 }; | |
| 788 | 1116294 | int16_t *tmp[] = { lc->tmp, lc->tmp1 }; | |
| 789 | int sad[SAD_ARRAY_SIZE][SAD_ARRAY_SIZE]; | ||
| 790 | int min_dx, min_dy, min_sad, dx, dy; | ||
| 791 | |||
| 792 | 1116294 | *orig_mv = *mvf; | |
| 793 | 1116294 | min_dx = min_dy = dx = dy = 2; | |
| 794 | |||
| 795 |
2/2✓ Branch 0 taken 2232588 times.
✓ Branch 1 taken 1116294 times.
|
3348882 | for (int i = L0; i <= L1; i++) { |
| 796 | 2232588 | const int pred_w = block_w + 2 * sr_range; | |
| 797 | 2232588 | const int pred_h = block_h + 2 * sr_range; | |
| 798 | 2232588 | const Mv *mv = mvf->mv + i; | |
| 799 | 2232588 | const int mx = mv->x & 0xf; | |
| 800 | 2232588 | const int my = mv->y & 0xf; | |
| 801 | 2232588 | const int ox = x_off + (mv->x >> 4) - sr_range; | |
| 802 | 2232588 | const int oy = y_off + (mv->y >> 4) - sr_range; | |
| 803 | 2232588 | const VVCFrame *ref = refs[i]; | |
| 804 | 2232588 | ptrdiff_t src_stride = ref->frame->linesize[LUMA]; | |
| 805 | 2232588 | const uint8_t *src = ref->frame->data[LUMA]; | |
| 806 | 2232588 | const int wrap_enabled = fc->ps.pps->r->pps_ref_wraparound_enabled_flag; | |
| 807 | |||
| 808 | 2232588 | MC_EMULATED_EDGE_BILINEAR(lc->edge_emu_buffer, &src, &src_stride, ox, oy); | |
| 809 | 2232588 | fc->vvcdsp.inter.dmvr[!!my][!!mx](tmp[i], src, src_stride, pred_h, mx, my, pred_w); | |
| 810 | } | ||
| 811 | |||
| 812 | 1116294 | min_sad = fc->vvcdsp.inter.sad(tmp[L0], tmp[L1], dx, dy, block_w, block_h); | |
| 813 | 1116294 | min_sad -= min_sad >> 2; | |
| 814 | 1116294 | sad[dy][dx] = min_sad; | |
| 815 | |||
| 816 |
2/2✓ Branch 0 taken 460533 times.
✓ Branch 1 taken 655761 times.
|
1116294 | if (min_sad >= block_w * block_h) { |
| 817 | int dmv[2]; | ||
| 818 | // 8.5.3.4 Array entry selection process | ||
| 819 |
2/2✓ Branch 0 taken 2302665 times.
✓ Branch 1 taken 460533 times.
|
2763198 | for (dy = 0; dy < SAD_ARRAY_SIZE; dy++) { |
| 820 |
2/2✓ Branch 0 taken 11513325 times.
✓ Branch 1 taken 2302665 times.
|
13815990 | for (dx = 0; dx < SAD_ARRAY_SIZE; dx++) { |
| 821 |
4/4✓ Branch 0 taken 2302665 times.
✓ Branch 1 taken 9210660 times.
✓ Branch 2 taken 1842132 times.
✓ Branch 3 taken 460533 times.
|
11513325 | if (dx != sr_range || dy != sr_range) { |
| 822 | 11052792 | sad[dy][dx] = fc->vvcdsp.inter.sad(lc->tmp, lc->tmp1, dx, dy, block_w, block_h); | |
| 823 |
2/2✓ Branch 0 taken 650256 times.
✓ Branch 1 taken 10402536 times.
|
11052792 | if (sad[dy][dx] < min_sad) { |
| 824 | 650256 | min_sad = sad[dy][dx]; | |
| 825 | 650256 | min_dx = dx; | |
| 826 | 650256 | min_dy = dy; | |
| 827 | } | ||
| 828 | } | ||
| 829 | } | ||
| 830 | } | ||
| 831 | 460533 | dmv[0] = (min_dx - sr_range) * (1 << 4); | |
| 832 | 460533 | dmv[1] = (min_dy - sr_range) * (1 << 4); | |
| 833 |
8/8✓ Branch 0 taken 382857 times.
✓ Branch 1 taken 77676 times.
✓ Branch 2 taken 317984 times.
✓ Branch 3 taken 64873 times.
✓ Branch 4 taken 265754 times.
✓ Branch 5 taken 52230 times.
✓ Branch 6 taken 257250 times.
✓ Branch 7 taken 8504 times.
|
460533 | if (min_dx != 0 && min_dx != 4 && min_dy != 0 && min_dy != 4) { |
| 834 | 257250 | dmv[0] += parametric_mv_refine(&sad[min_dy][min_dx], 1); | |
| 835 | 257250 | dmv[1] += parametric_mv_refine(&sad[min_dy][min_dx], SAD_ARRAY_SIZE); | |
| 836 | } | ||
| 837 | |||
| 838 |
2/2✓ Branch 0 taken 921066 times.
✓ Branch 1 taken 460533 times.
|
1381599 | for (int i = L0; i <= L1; i++) { |
| 839 | 921066 | Mv *mv = mvf->mv + i; | |
| 840 | 921066 | mv->x += (1 - 2 * i) * dmv[0]; | |
| 841 | 921066 | mv->y += (1 - 2 * i) * dmv[1]; | |
| 842 | 921066 | ff_vvc_clip_mv(mv); | |
| 843 | } | ||
| 844 | } | ||
| 845 |
2/2✓ Branch 0 taken 825554 times.
✓ Branch 1 taken 290740 times.
|
1116294 | if (min_sad < 2 * block_w * block_h) { |
| 846 | 825554 | *sb_bdof_flag = 0; | |
| 847 | } | ||
| 848 | 1116294 | } | |
| 849 | |||
| 850 | 1116294 | static void set_dmvr_info(VVCFrameContext *fc, const int x0, const int y0, | |
| 851 | const int width, const int height, const MvField *mvf) | ||
| 852 | |||
| 853 | { | ||
| 854 | 1116294 | const VVCPPS *pps = fc->ps.pps; | |
| 855 | |||
| 856 |
2/2✓ Branch 0 taken 4420952 times.
✓ Branch 1 taken 1116294 times.
|
5537246 | for (int y = y0; y < y0 + height; y += MIN_PU_SIZE) { |
| 857 |
2/2✓ Branch 0 taken 17546936 times.
✓ Branch 1 taken 4420952 times.
|
21967888 | for (int x = x0; x < x0 + width; x += MIN_PU_SIZE) { |
| 858 | 17546936 | const int idx = pps->min_pu_width * (y >> MIN_PU_LOG2) + (x >> MIN_PU_LOG2); | |
| 859 | 17546936 | fc->ref->tab_dmvr_mvf[idx] = *mvf; | |
| 860 | } | ||
| 861 | } | ||
| 862 | 1116294 | } | |
| 863 | |||
| 864 | 2605338 | static void derive_sb_mv(VVCLocalContext *lc, MvField *mv, MvField *orig_mv, int *sb_bdof_flag, | |
| 865 | const int x0, const int y0, const int sbw, const int sbh) | ||
| 866 | { | ||
| 867 | 2605338 | VVCFrameContext *fc = lc->fc; | |
| 868 | 2605338 | const PredictionUnit *pu = &lc->cu->pu; | |
| 869 | |||
| 870 | 2605338 | *orig_mv = *mv = *ff_vvc_get_mvf(fc, x0, y0); | |
| 871 |
2/2✓ Branch 0 taken 1183104 times.
✓ Branch 1 taken 1422234 times.
|
2605338 | if (pu->bdof_flag) |
| 872 | 1183104 | *sb_bdof_flag = 1; | |
| 873 |
2/2✓ Branch 0 taken 1116294 times.
✓ Branch 1 taken 1489044 times.
|
2605338 | if (pu->dmvr_flag) { |
| 874 | VVCRefPic *refp[2]; | ||
| 875 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1116294 times.
|
1116294 | if (pred_get_refs(lc, refp, mv) < 0) |
| 876 | ✗ | return; | |
| 877 | 1116294 | dmvr_mv_refine(lc, mv, orig_mv, sb_bdof_flag, refp[L0]->ref, refp[L1]->ref, x0, y0, sbw, sbh); | |
| 878 | 1116294 | set_dmvr_info(fc, x0, y0, sbw, sbh, mv); | |
| 879 | } | ||
| 880 | } | ||
| 881 | |||
| 882 | 413297 | static void pred_regular_blk(VVCLocalContext *lc, const int skip_ciip) | |
| 883 | { | ||
| 884 | 413297 | const CodingUnit *cu = lc->cu; | |
| 885 | 413297 | PredictionUnit *pu = &lc->cu->pu; | |
| 886 | 413297 | const MotionInfo *mi = &pu->mi; | |
| 887 | MvField mv, orig_mv; | ||
| 888 | 413297 | int sbw, sbh, sb_bdof_flag = 0; | |
| 889 | |||
| 890 |
4/4✓ Branch 0 taken 32654 times.
✓ Branch 1 taken 380643 times.
✓ Branch 2 taken 16327 times.
✓ Branch 3 taken 16327 times.
|
413297 | if (cu->ciip_flag && skip_ciip) |
| 891 | 16327 | return; | |
| 892 | |||
| 893 | 396970 | sbw = cu->cb_width / mi->num_sb_x; | |
| 894 | 396970 | sbh = cu->cb_height / mi->num_sb_y; | |
| 895 | |||
| 896 |
2/2✓ Branch 0 taken 660268 times.
✓ Branch 1 taken 396970 times.
|
1057238 | for (int sby = 0; sby < mi->num_sb_y; sby++) { |
| 897 |
2/2✓ Branch 0 taken 2605338 times.
✓ Branch 1 taken 660268 times.
|
3265606 | for (int sbx = 0; sbx < mi->num_sb_x; sbx++) { |
| 898 | 2605338 | const int x0 = cu->x0 + sbx * sbw; | |
| 899 | 2605338 | const int y0 = cu->y0 + sby * sbh; | |
| 900 | |||
| 901 |
2/2✓ Branch 0 taken 16327 times.
✓ Branch 1 taken 2589011 times.
|
2605338 | if (cu->ciip_flag) |
| 902 | 16327 | ff_vvc_set_neighbour_available(lc, x0, y0, sbw, sbh); | |
| 903 | |||
| 904 | 2605338 | derive_sb_mv(lc, &mv, &orig_mv, &sb_bdof_flag, x0, y0, sbw, sbh); | |
| 905 | 2605338 | pred_regular(lc, &mv, &orig_mv, x0, y0, sbw, sbh, sb_bdof_flag, LUMA); | |
| 906 | } | ||
| 907 | } | ||
| 908 | } | ||
| 909 | |||
| 910 | 1318049 | static void derive_affine_mvc(MvField *mvc, const VVCFrameContext *fc, const MvField *mv, | |
| 911 | const int x0, const int y0, const int sbw, const int sbh) | ||
| 912 | { | ||
| 913 | 1318049 | const int hs = fc->ps.sps->hshift[1]; | |
| 914 | 1318049 | const int vs = fc->ps.sps->vshift[1]; | |
| 915 | 1318049 | const MvField* mv2 = ff_vvc_get_mvf(fc, x0 + hs * sbw, y0 + vs * sbh); | |
| 916 | 1318049 | *mvc = *mv; | |
| 917 | |||
| 918 | // Due to different pred_flag, one of the motion vectors may have an invalid value. | ||
| 919 | // Cast them to an unsigned type to avoid undefined behavior. | ||
| 920 | 1318049 | mvc->mv[0].x += (unsigned int)mv2->mv[0].x; | |
| 921 | 1318049 | mvc->mv[0].y += (unsigned int)mv2->mv[0].y; | |
| 922 | 1318049 | mvc->mv[1].x += (unsigned int)mv2->mv[1].x; | |
| 923 | 1318049 | mvc->mv[1].y += (unsigned int)mv2->mv[1].y; | |
| 924 | 1318049 | ff_vvc_round_mv(mvc->mv + 0, 0, 1); | |
| 925 | 1318049 | ff_vvc_round_mv(mvc->mv + 1, 0, 1); | |
| 926 | 1318049 | } | |
| 927 | |||
| 928 | 35978 | static void pred_affine_blk(VVCLocalContext *lc) | |
| 929 | { | ||
| 930 | 35978 | const VVCFrameContext *fc = lc->fc; | |
| 931 | 35978 | const CodingUnit *cu = lc->cu; | |
| 932 | 35978 | const PredictionUnit *pu = &cu->pu; | |
| 933 | 35978 | const MotionInfo *mi = &pu->mi; | |
| 934 | 35978 | const int x0 = cu->x0; | |
| 935 | 35978 | const int y0 = cu->y0; | |
| 936 | 35978 | const int sbw = cu->cb_width / mi->num_sb_x; | |
| 937 | 35978 | const int sbh = cu->cb_height / mi->num_sb_y; | |
| 938 | 35978 | const int hs = fc->ps.sps->hshift[1]; | |
| 939 | 35978 | const int vs = fc->ps.sps->vshift[1]; | |
| 940 | 35978 | const int dst_stride = fc->frame->linesize[LUMA]; | |
| 941 | |||
| 942 |
2/2✓ Branch 0 taken 284286 times.
✓ Branch 1 taken 35978 times.
|
320264 | for (int sby = 0; sby < mi->num_sb_y; sby++) { |
| 943 |
2/2✓ Branch 0 taken 3529300 times.
✓ Branch 1 taken 284286 times.
|
3813586 | for (int sbx = 0; sbx < mi->num_sb_x; sbx++) { |
| 944 | 3529300 | const int x = x0 + sbx * sbw; | |
| 945 | 3529300 | const int y = y0 + sby * sbh; | |
| 946 | |||
| 947 | 3529300 | uint8_t *dst0 = POS(0, x, y); | |
| 948 | 3529300 | const MvField *mv = ff_vvc_get_mvf(fc, x, y); | |
| 949 | VVCRefPic *refp[2]; | ||
| 950 | |||
| 951 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3529300 times.
|
3529300 | if (pred_get_refs(lc, refp, mv) < 0) |
| 952 | ✗ | return; | |
| 953 | |||
| 954 |
2/2✓ Branch 0 taken 2476096 times.
✓ Branch 1 taken 1053204 times.
|
3529300 | if (mi->pred_flag != PF_BI) { |
| 955 | 2476096 | const int lx = mi->pred_flag - PF_L0; | |
| 956 |
2/2✓ Branch 0 taken 16008 times.
✓ Branch 1 taken 2460088 times.
|
2476096 | if (refp[lx]->is_scaled) { |
| 957 | 16008 | mc_uni_scaled(lc, dst0, dst_stride, refp[lx], mv, x, y, sbw, sbh, LUMA); | |
| 958 | } else { | ||
| 959 | 2460088 | luma_prof_uni(lc, dst0, dst_stride, refp[lx]->ref, | |
| 960 | 2460088 | mv, x, y, sbw, sbh, pu->cb_prof_flag[lx], | |
| 961 | 2460088 | pu->diff_mv_x[lx], pu->diff_mv_y[lx]); | |
| 962 | } | ||
| 963 | } else { | ||
| 964 | 1053204 | luma_prof_bi(lc, dst0, dst_stride, refp[L0], refp[L1], mv, x, y, sbw, sbh); | |
| 965 | } | ||
| 966 |
2/2✓ Branch 0 taken 3491192 times.
✓ Branch 1 taken 38108 times.
|
3529300 | if (fc->ps.sps->r->sps_chroma_format_idc) { |
| 967 |
4/4✓ Branch 0 taken 2042986 times.
✓ Branch 1 taken 1448206 times.
✓ Branch 2 taken 1318049 times.
✓ Branch 3 taken 724937 times.
|
3491192 | if (!av_zero_extend(sby, vs) && !av_zero_extend(sbx, hs)) { |
| 968 | MvField mvc; | ||
| 969 | |||
| 970 | 1318049 | derive_affine_mvc(&mvc, fc, mv, x, y, sbw, sbh); | |
| 971 | 1318049 | pred_regular(lc, &mvc, NULL, x, y, sbw << hs, sbh << vs, 0, CB); | |
| 972 | } | ||
| 973 | } | ||
| 974 | |||
| 975 | } | ||
| 976 | } | ||
| 977 | } | ||
| 978 | |||
| 979 | 460542 | static void predict_inter(VVCLocalContext *lc) | |
| 980 | { | ||
| 981 | 460542 | const VVCFrameContext *fc = lc->fc; | |
| 982 | 460542 | const CodingUnit *cu = lc->cu; | |
| 983 | 460542 | const PredictionUnit *pu = &cu->pu; | |
| 984 | |||
| 985 |
2/2✓ Branch 0 taken 27594 times.
✓ Branch 1 taken 432948 times.
|
460542 | if (pu->merge_gpm_flag) |
| 986 | 27594 | pred_gpm_blk(lc); | |
| 987 |
2/2✓ Branch 0 taken 35978 times.
✓ Branch 1 taken 396970 times.
|
432948 | else if (pu->inter_affine_flag) |
| 988 | 35978 | pred_affine_blk(lc); | |
| 989 | else | ||
| 990 | 396970 | pred_regular_blk(lc, 1); //intra block is not ready yet, skip ciip | |
| 991 | |||
| 992 |
4/4✓ Branch 0 taken 189745 times.
✓ Branch 1 taken 270797 times.
✓ Branch 2 taken 181317 times.
✓ Branch 3 taken 8428 times.
|
460542 | if (lc->sc->sh.r->sh_lmcs_used_flag && !cu->ciip_flag) { |
| 993 | 181317 | uint8_t* dst0 = POS(0, cu->x0, cu->y0); | |
| 994 | 181317 | fc->vvcdsp.lmcs.filter(dst0, fc->frame->linesize[LUMA], cu->cb_width, cu->cb_height, &fc->ps.lmcs.fwd_lut); | |
| 995 | } | ||
| 996 | 460542 | } | |
| 997 | |||
| 998 | 1344609 | static int has_inter_luma(const CodingUnit *cu) | |
| 999 | { | ||
| 1000 |
4/6✓ Branch 0 taken 884067 times.
✓ Branch 1 taken 460542 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 884067 times.
✓ Branch 4 taken 460542 times.
✗ Branch 5 not taken.
|
1344609 | return (cu->pred_mode == MODE_INTER || cu->pred_mode == MODE_SKIP) && cu->tree_type != DUAL_TREE_CHROMA; |
| 1001 | } | ||
| 1002 | |||
| 1003 | 53475 | int ff_vvc_predict_inter(VVCLocalContext *lc, const int rs) | |
| 1004 | { | ||
| 1005 | 53475 | const VVCFrameContext *fc = lc->fc; | |
| 1006 | 53475 | CodingUnit *cu = fc->tab.cus[rs]; | |
| 1007 | |||
| 1008 |
2/2✓ Branch 0 taken 1344609 times.
✓ Branch 1 taken 53475 times.
|
1398084 | while (cu) { |
| 1009 | 1344609 | lc->cu = cu; | |
| 1010 |
2/2✓ Branch 1 taken 460542 times.
✓ Branch 2 taken 884067 times.
|
1344609 | if (has_inter_luma(cu)) |
| 1011 | 460542 | predict_inter(lc); | |
| 1012 | 1344609 | cu = cu->next; | |
| 1013 | } | ||
| 1014 | |||
| 1015 | 53475 | return 0; | |
| 1016 | } | ||
| 1017 | |||
| 1018 | 16327 | void ff_vvc_predict_ciip(VVCLocalContext *lc) | |
| 1019 | { | ||
| 1020 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16327 times.
|
16327 | av_assert0(lc->cu->ciip_flag); |
| 1021 | |||
| 1022 | //todo: refact out ciip from pred_regular_blk | ||
| 1023 | 16327 | pred_regular_blk(lc, 0); | |
| 1024 | 16327 | } | |
| 1025 | |||
| 1026 | #undef POS | ||
| 1027 |