History

avcodec/vvcdec: refact out VVCRefPic from RefPicList

Nuo Mi committed 2 years ago

Commit 66c6bee1 parent 44bbafb8 files · +52 −47Browse files

Unified · Split

8 files
  1. libavcodec/vvc/ctu.c +5 −5
  2. libavcodec/vvc/dec.c +2 −2
  3. libavcodec/vvc/dec.h +7 −3
  4. libavcodec/vvc/filter.c +11 −11
  5. libavcodec/vvc/inter.c +2 −2
  6. libavcodec/vvc/mvs.c +18 −18
  7. libavcodec/vvc/refs.c +6 −5
  8. libavcodec/vvc/thread.c +1 −1
libavcodec/vvc/ctu.c+5−5
@@ -1263,8 +1263,8 @@ static void derive_mmvd(const VVCLocalContext *lc, MvField *mvf, const Mv *mmvd_ · 1262 unmodified lines
12631263 const RefPicList *rpl = sc->rpl;
12641264 const int poc = lc->fc->ps.ph.poc;
12651265 const int diff[] = {
1266− poc - rpl[0].list[mvf->ref_idx[0]],
1267− poc - rpl[1].list[mvf->ref_idx[1]]
1266+ poc - rpl[L0].refs[mvf->ref_idx[L0]].poc,
1267+ poc - rpl[L1].refs[mvf->ref_idx[L1]].poc
12681268 };
12691269 const int sign = FFSIGN(diff[0]) != FFSIGN(diff[1]);
12701270
@@ -1275,7 +1275,7 @@ static void derive_mmvd(const VVCLocalContext *lc, MvField *mvf, const Mv *mmvd_ · 4 unmodified lines
12751275 const int i = FFABS(diff[0]) < FFABS(diff[1]);
12761276 const int o = !i;
12771277 mmvd[i] = *mmvd_offset;
1278− if (!rpl[0].isLongTerm[mvf->ref_idx[0]] && !rpl[1].isLongTerm[mvf->ref_idx[1]]) {
1278+ if (!rpl[L0].refs[mvf->ref_idx[L0]].is_lt && !rpl[L1].refs[mvf->ref_idx[L1]].is_lt) {
12791279 ff_vvc_mv_scale(&mmvd[o], mmvd_offset, diff[i], diff[o]);
12801280 }
12811281 else {
@@ -1699,8 +1699,8 @@ static void derive_dmvr_bdof_flag(const VVCLocalContext *lc, PredictionUnit *pu) · 417 unmodified lines
16991699 pu->bdof_flag = 0;
17001700
17011701 if (mi->pred_flag == PF_BI &&
1702− (poc - rpl0->list[ref_idx[L0]] == rpl1->list[ref_idx[L1]] - poc) &&
1703− !rpl0->isLongTerm[ref_idx[L0]] && !rpl1->isLongTerm[ref_idx[L1]] &&
1702+ (poc - rpl0->refs[ref_idx[L0]].poc == rpl1->refs[ref_idx[L1]].poc - poc) &&
1703+ !rpl0->refs[ref_idx[L0]].is_lt && !rpl1->refs[ref_idx[L1]].is_lt &&
17041704 !cu->ciip_flag &&
17051705 !mi->bcw_idx &&
17061706 !w->weight_flag[L0][LUMA][mi->ref_idx[L0]] && !w->weight_flag[L1][LUMA][mi->ref_idx[L1]] &&
libavcodec/vvc/dec.c+2−2
@@ -403,8 +403,8 @@ static int8_t smvd_find(const VVCFrameContext *fc, const SliceContext *sc, int l · 402 unmodified lines
403403 int8_t idx = -1;
404404 int old_diff = -1;
405405 for (int i = 0; i < rsh->num_ref_idx_active[lx]; i++) {
406− if (!rpl->isLongTerm[i]) {
407− int diff = poc - rpl->list[i];
406+ if (!rpl->refs[i].is_lt) {
407+ int diff = poc - rpl->refs[i].poc;
408408 if (find(idx, diff, old_diff)) {
409409 idx = i;
410410 old_diff = diff;
libavcodec/vvc/dec.h+7−3
@@ -42,10 +42,14 @@ · 41 unmodified lines
4242 #define L0 0
4343 #define L1 1
4444
45+typedef struct VVCRefPic {
46+ struct VVCFrame *ref;
47+ int poc;
48+ int is_lt; // is long term reference
49+} VVCRefPic;
50+
4551 typedef struct RefPicList {
46− struct VVCFrame *ref[VVC_MAX_REF_ENTRIES];
47− int list[VVC_MAX_REF_ENTRIES];
48− int isLongTerm[VVC_MAX_REF_ENTRIES];
52+ VVCRefPic refs[VVC_MAX_REF_ENTRIES];
4953 int nb_refs;
5054 } RefPicList;
5155
libavcodec/vvc/filter.c+11−11
@@ -321,9 +321,9 @@ static int boundary_strength(const VVCLocalContext *lc, const MvField *curr, con · 320 unmodified lines
321321
322322 if (curr->pred_flag == PF_BI && neigh->pred_flag == PF_BI) {
323323 // same L0 and L1
324− if (rpl[0].list[curr->ref_idx[0]] == neigh_rpl[0].list[neigh->ref_idx[0]] &&
325− rpl[0].list[curr->ref_idx[0]] == rpl[1].list[curr->ref_idx[1]] &&
326− neigh_rpl[0].list[neigh->ref_idx[0]] == neigh_rpl[1].list[neigh->ref_idx[1]]) {
324+ if (rpl[L0].refs[curr->ref_idx[L0]].poc == neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc &&
325+ rpl[L0].refs[curr->ref_idx[L0]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc &&
326+ neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc) {
327327 if ((FFABS(neigh->mv[0].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 8 ||
328328 FFABS(neigh->mv[1].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[1].y) >= 8) &&
329329 (FFABS(neigh->mv[1].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[0].y) >= 8 ||
@@ -331,15 +331,15 @@ static int boundary_strength(const VVCLocalContext *lc, const MvField *curr, con · 1 unmodified line
331331 return 1;
332332 else
333333 return 0;
334− } else if (neigh_rpl[0].list[neigh->ref_idx[0]] == rpl[0].list[curr->ref_idx[0]] &&
335− neigh_rpl[1].list[neigh->ref_idx[1]] == rpl[1].list[curr->ref_idx[1]]) {
334+ } else if (neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == rpl[L0].refs[curr->ref_idx[L0]].poc &&
335+ neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc) {
336336 if (FFABS(neigh->mv[0].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[0].y) >= 8 ||
337337 FFABS(neigh->mv[1].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[1].y) >= 8)
338338 return 1;
339339 else
340340 return 0;
341− } else if (neigh_rpl[1].list[neigh->ref_idx[1]] == rpl[0].list[curr->ref_idx[0]] &&
342− neigh_rpl[0].list[neigh->ref_idx[0]] == rpl[1].list[curr->ref_idx[1]]) {
341+ } else if (neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc == rpl[L0].refs[curr->ref_idx[L0]].poc &&
342+ neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc == rpl[L1].refs[curr->ref_idx[L1]].poc) {
343343 if (FFABS(neigh->mv[1].x - curr->mv[0].x) >= 8 || FFABS(neigh->mv[1].y - curr->mv[0].y) >= 8 ||
344344 FFABS(neigh->mv[0].x - curr->mv[1].x) >= 8 || FFABS(neigh->mv[0].y - curr->mv[1].y) >= 8)
345345 return 1;
@@ -354,18 +354,18 @@ static int boundary_strength(const VVCLocalContext *lc, const MvField *curr, con · 8 unmodified lines
354354
355355 if (curr->pred_flag & 1) {
356356 A = curr->mv[0];
357− ref_A = rpl[0].list[curr->ref_idx[0]];
357+ ref_A = rpl[L0].refs[curr->ref_idx[L0]].poc;
358358 } else {
359359 A = curr->mv[1];
360− ref_A = rpl[1].list[curr->ref_idx[1]];
360+ ref_A = rpl[L1].refs[curr->ref_idx[L1]].poc;
361361 }
362362
363363 if (neigh->pred_flag & 1) {
364364 B = neigh->mv[0];
365− ref_B = neigh_rpl[0].list[neigh->ref_idx[0]];
365+ ref_B = neigh_rpl[L0].refs[neigh->ref_idx[L0]].poc;
366366 } else {
367367 B = neigh->mv[1];
368− ref_B = neigh_rpl[1].list[neigh->ref_idx[1]];
368+ ref_B = neigh_rpl[L1].refs[neigh->ref_idx[L1]].poc;
369369 }
370370
371371 if (ref_A == ref_B) {
libavcodec/vvc/inter.c+2−2
@@ -394,7 +394,7 @@ static int pred_get_refs(const VVCLocalContext *lc, VVCFrame *ref[2], const MvF · 393 unmodified lines
394394 for (int mask = PF_L0; mask <= PF_L1; mask++) {
395395 if (mv->pred_flag & mask) {
396396 const int lx = mask - PF_L0;
397− ref[lx] = rpl[lx].ref[mv->ref_idx[lx]];
397+ ref[lx] = rpl[lx].refs[mv->ref_idx[lx]].ref;
398398 if (!ref[lx])
399399 return AVERROR_INVALIDDATA;
400400 }
@@ -450,7 +450,7 @@ static void pred_gpm_blk(VVCLocalContext *lc) · 49 unmodified lines
450450 for (int i = 0; i < 2; i++) {
451451 const MvField *mv = pu->gpm_mv + i;
452452 const int lx = mv->pred_flag - PF_L0;
453− VVCFrame *ref = lc->sc->rpl[lx].ref[mv->ref_idx[lx]];
453+ VVCFrame *ref = lc->sc->rpl[lx].refs[mv->ref_idx[lx]].ref;
454454 if (!ref)
455455 return;
456456 mc(lc, tmp[i], ref->frame, mv->mv + lx, x, y, width, height, c_idx);
libavcodec/vvc/mvs.c+18−18
@@ -88,8 +88,8 @@ static int check_mvset(Mv *mvLXCol, Mv *mvCol, · 87 unmodified lines
8888 const RefPicList *refPicList, int X, int refIdxLx,
8989 const RefPicList *refPicList_col, int listCol, int refidxCol)
9090 {
91− int cur_lt = refPicList[X].isLongTerm[refIdxLx];
92− int col_lt = refPicList_col[listCol].isLongTerm[refidxCol];
91+ int cur_lt = refPicList[X].refs[refIdxLx].is_lt;
92+ int col_lt = refPicList_col[listCol].refs[refidxCol].is_lt;
9393 int col_poc_diff, cur_poc_diff;
9494
9595 if (cur_lt != col_lt) {
@@ -98,8 +98,8 @@ static int check_mvset(Mv *mvLXCol, Mv *mvCol, · 2 unmodified lines
9898 return 0;
9999 }
100100
101− col_poc_diff = colPic - refPicList_col[listCol].list[refidxCol];
102− cur_poc_diff = poc - refPicList[X].list[refIdxLx];
101+ col_poc_diff = colPic - refPicList_col[listCol].refs[refidxCol].poc;
102+ cur_poc_diff = poc - refPicList[X].refs[refIdxLx].poc;
103103
104104 mv_compression(mvCol);
105105 if (cur_lt || col_poc_diff == cur_poc_diff) {
@@ -126,7 +126,7 @@ int ff_vvc_no_backward_pred_flag(const VVCLocalContext *lc) · 20 unmodified lines
126126
127127 for (j = 0; j < 2; j++) {
128128 for (i = 0; i < lc->sc->sh.r->num_ref_idx_active[j]; i++) {
129− if (rpl[j].list[i] > lc->fc->ps.ph.poc) {
129+ if (rpl[j].refs[i].poc > lc->fc->ps.ph.poc) {
130130 check_diffpicount++;
131131 break;
132132 }
@@ -1059,9 +1059,9 @@ static int sb_temporal_luma_motion_data(const VVCLocalContext *lc, const MvField · 926 unmodified lines
10591059 colPic = ref->poc;
10601060
10611061 if (a1) {
1062− if ((a1->pred_flag & PF_L0) && colPic == rpl[0].list[a1->ref_idx[0]])
1062+ if ((a1->pred_flag & PF_L0) && colPic == rpl[L0].refs[a1->ref_idx[L0]].poc)
10631063 *temp_mv = a1->mv[0];
1064− else if ((a1->pred_flag & PF_L1) && colPic == rpl[1].list[a1->ref_idx[1]])
1064+ else if ((a1->pred_flag & PF_L1) && colPic == rpl[L1].refs[a1->ref_idx[L1]].poc)
10651065 *temp_mv = a1->mv[1];
10661066 ff_vvc_round_mv(temp_mv, 0, 4);
10671067 }
@@ -1418,16 +1418,16 @@ static int mvp_candidate(const VVCLocalContext *lc, const int x_cand, const int · 350 unmodified lines
14181418 const MvField* tab_mvf = fc->tab.mvf;
14191419 const MvField *mvf = &TAB_MVF(x_cand, y_cand);
14201420 const PredFlag maskx = lx + 1;
1421− const int poc = rpl[lx].list[ref_idx[lx]];
1421+ const int poc = rpl[lx].refs[ref_idx[lx]].poc;
14221422 int available = 0;
14231423
1424− if ((mvf->pred_flag & maskx) && rpl[lx].list[mvf->ref_idx[lx]] == poc) {
1424+ if ((mvf->pred_flag & maskx) && rpl[lx].refs[mvf->ref_idx[lx]].poc == poc) {
14251425 available = 1;
14261426 *mv = mvf->mv[lx];
14271427 } else {
14281428 const int ly = !lx;
14291429 const PredFlag masky = ly + 1;
1430− if ((mvf->pred_flag & masky) && rpl[ly].list[mvf->ref_idx[ly]] == poc) {
1430+ if ((mvf->pred_flag & masky) && rpl[ly].refs[mvf->ref_idx[ly]].poc == poc) {
14311431 available = 1;
14321432 *mv = mvf->mv[ly];
14331433 }
@@ -1450,15 +1450,15 @@ static int affine_mvp_candidate(const VVCLocalContext *lc, · 16 unmodified lines
14501450 const MvField *mvf = &TAB_MVF(x_nb, y_nb);
14511451 RefPicList* rpl = lc->sc->rpl;
14521452 const PredFlag maskx = lx + 1;
1453− const int poc = rpl[lx].list[ref_idx[lx]];
1453+ const int poc = rpl[lx].refs[ref_idx[lx]].poc;
14541454
1455− if ((mvf->pred_flag & maskx) && rpl[lx].list[mvf->ref_idx[lx]] == poc) {
1455+ if ((mvf->pred_flag & maskx) && rpl[lx].refs[mvf->ref_idx[lx]].poc == poc) {
14561456 available = 1;
14571457 affine_cps_from_nb(lc, x_nb, y_nb, nbw, nbh, lx, cps, num_cp);
14581458 } else {
14591459 const int ly = !lx;
14601460 const PredFlag masky = ly + 1;
1461− if ((mvf->pred_flag & masky) && rpl[ly].list[mvf->ref_idx[ly]] == poc) {
1461+ if ((mvf->pred_flag & masky) && rpl[ly].refs[mvf->ref_idx[ly]].poc == poc) {
14621462 available = 1;
14631463 affine_cps_from_nb(lc, x_nb, y_nb, nbw, nbh, ly, cps, num_cp);
14641464 }
@@ -1550,7 +1550,7 @@ static int mvp_history_candidates(const VVCLocalContext *lc, · 85 unmodified lines
15501550 {
15511551 const EntryPoint* ep = lc->ep;
15521552 const RefPicList* rpl = lc->sc->rpl;
1553− const int poc = rpl[lx].list[ref_idx];
1553+ const int poc = rpl[lx].refs[ref_idx].poc;
15541554
15551555 if (ep->num_hmvp == 0)
15561556 return 0;
@@ -1559,7 +1559,7 @@ static int mvp_history_candidates(const VVCLocalContext *lc, · 2 unmodified lines
15591559 for (int j = 0; j < 2; j++) {
15601560 const int ly = (j ? !lx : lx);
15611561 PredFlag mask = PF_L0 + ly;
1562− if ((h->pred_flag & mask) && poc == rpl[ly].list[h->ref_idx[ly]]) {
1562+ if ((h->pred_flag & mask) && poc == rpl[ly].refs[h->ref_idx[ly]].poc) {
15631563 if (mvp_lx_flag == num_cands) {
15641564 *mv = h->mv[ly];
15651565 ff_vvc_round_mv(mv, amvr_shift, amvr_shift);
@@ -1725,14 +1725,14 @@ static int affine_mvp_constructed_cp(NeighbourContext *ctx, · 159 unmodified lines
17251725 if (check_available(n, ctx->lc, 0)) {
17261726 const PredFlag maskx = lx + 1;
17271727 const MvField* mvf = &TAB_MVF(n->x, n->y);
1728− const int poc = rpl[lx].list[ref_idx];
1729− if ((mvf->pred_flag & maskx) && rpl[lx].list[mvf->ref_idx[lx]] == poc) {
1728+ const int poc = rpl[lx].refs[ref_idx].poc;
1729+ if ((mvf->pred_flag & maskx) && rpl[lx].refs[mvf->ref_idx[lx]].poc == poc) {
17301730 available = 1;
17311731 *cp = mvf->mv[lx];
17321732 } else {
17331733 const int ly = !lx;
17341734 const PredFlag masky = ly + 1;
1735− if ((mvf->pred_flag & masky) && rpl[ly].list[mvf->ref_idx[ly]] == poc) {
1735+ if ((mvf->pred_flag & masky) && rpl[ly].refs[mvf->ref_idx[ly]].poc == poc) {
17361736 available = 1;
17371737 *cp = mvf->mv[ly];
17381738 }
libavcodec/vvc/refs.c+6−5
@@ -352,7 +352,8 @@ static VVCFrame *generate_missing_ref(VVCContext *s, VVCFrameContext *fc, int po · 351 unmodified lines
352352 static int add_candidate_ref(VVCContext *s, VVCFrameContext *fc, RefPicList *list,
353353 int poc, int ref_flag, uint8_t use_msb)
354354 {
355− VVCFrame *ref = find_ref_idx(s, fc, poc, use_msb);
355+ VVCFrame *ref = find_ref_idx(s, fc, poc, use_msb);
356+ VVCRefPic *refp = &list->refs[list->nb_refs];
356357
357358 if (ref == fc->ref || list->nb_refs >= VVC_MAX_REF_ENTRIES)
358359 return AVERROR_INVALIDDATA;
@@ -363,9 +364,9 @@ static int add_candidate_ref(VVCContext *s, VVCFrameContext *fc, RefPicList *lis · 4 unmodified lines
363364 return AVERROR(ENOMEM);
364365 }
365366
366− list->list[list->nb_refs] = poc;
367− list->ref[list->nb_refs] = ref;
368− list->isLongTerm[list->nb_refs] = ref_flag & VVC_FRAME_FLAG_LONG_REF;
367+ refp->poc = poc;
368+ refp->ref = ref;
369+ refp->is_lt = ref_flag & VVC_FRAME_FLAG_LONG_REF;
369370 list->nb_refs++;
370371
371372 mark_ref(ref, ref_flag);
@@ -463,7 +464,7 @@ int ff_vvc_slice_rpl(VVCContext *s, VVCFrameContext *fc, SliceContext *sc) · 91 unmodified lines
463464 }
464465 if ((!rsh->sh_collocated_from_l0_flag) == lx &&
465466 rsh->sh_collocated_ref_idx < rpl->nb_refs)
466− fc->ref->collocated_ref = rpl->ref[rsh->sh_collocated_ref_idx];
467+ fc->ref->collocated_ref = rpl->refs[rsh->sh_collocated_ref_idx].ref;
467468 }
468469 return 0;
469470 }
libavcodec/vvc/thread.c+1−1
@@ -294,7 +294,7 @@ static void schedule_inter(VVCContext *s, VVCFrameContext *fc, const SliceContex · 293 unmodified lines
294294 for (int lx = 0; lx < 2; lx++) {
295295 for (int i = 0; i < sh->r->num_ref_idx_active[lx]; i++) {
296296 const int y = ctu->max_y[lx][i];
297− VVCFrame *ref = sc->rpl[lx].ref[i];
297+ VVCFrame *ref = sc->rpl[lx].refs[i].ref;
298298 if (ref && y >= 0)
299299 add_progress_listener(ref, &t->listener[lx][i], t, s, VVC_PROGRESS_PIXEL, y + LUMA_EXTRA_AFTER);
300300 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t