66 #define MIN_TB_ADDR_ZS(x, y) \
67 s->pps->min_tb_addr_zs[(y) * s->sps->min_tb_width + (x)]
72 if ((xN < 0) || (yN < 0) ||
85 int x0,
int y0,
int nPbW,
int nPbH,
86 int xA1,
int yA1,
int partIdx)
88 return !(nPbW << 1 == 1 << log2_cb_size &&
89 nPbH << 1 == 1 << log2_cb_size && partIdx == 1 &&
90 lc->
cu.
x + nPbW > xA1 &&
91 lc->
cu.
y + nPbH <= yA1);
98 int x0,
int y0,
int nPbW,
int nPbH,
99 int xA1,
int yA1,
int partIdx)
103 if (lc->
cu.
x < xA1 && lc->
cu.
y < yA1 &&
104 (lc->
cu.
x + (1 << log2_cb_size)) > xA1 &&
105 (lc->
cu.
y + (1 << log2_cb_size)) > yA1)
107 nPbW, nPbH, xA1, yA1, partIdx);
117 return xN >> plevel == xP >> plevel &&
118 yN >> plevel == yP >> plevel;
121 #define MATCH(x) (A.x == B.x)
141 int tx, scale_factor;
145 tx = (0x4000 + abs(td / 2)) / td;
146 scale_factor =
av_clip_c((tb * tx + 32) >> 6, -4096, 4095);
148 (scale_factor * src->
x < 0)) >> 8);
150 (scale_factor * src->
y < 0)) >> 8);
156 RefPicList *refPicList_col,
int listCol,
int refidxCol)
158 int cur_lt = refPicList[X].
isLongTerm[refIdxLx];
159 int col_lt = refPicList_col[listCol].
isLongTerm[refidxCol];
160 int col_poc_diff, cur_poc_diff;
162 if (cur_lt != col_lt) {
168 col_poc_diff = colPic - refPicList_col[listCol].
list[refidxCol];
169 cur_poc_diff = poc - refPicList[X].
list[refIdxLx];
174 if (cur_lt || col_poc_diff == cur_poc_diff) {
175 mvLXCol->
x = mvCol->
x;
176 mvLXCol->
y = mvCol->
y;
178 mv_scale(mvLXCol, mvCol, col_poc_diff, cur_poc_diff);
183 #define CHECK_MVSET(l) \
184 check_mvset(mvLXCol, temp_col.mv + l, \
186 refPicList, X, refIdxLx, \
187 refPicList_col, L##l, temp_col.ref_idx[l])
191 int refIdxLx,
Mv* mvLXCol,
int X,
207 int check_diffpicount = 0;
209 for (i = 0; i < refPicList[0].
nb_refs; i++) {
210 if (refPicList[0].list[i] > s->
poc)
213 for (i = 0; i < refPicList[1].
nb_refs; i++) {
214 if (refPicList[1].list[i] > s->
poc)
217 if (check_diffpicount == 0 && X == 0)
219 else if (check_diffpicount == 0 && X == 1)
232 #define TAB_MVF(x, y) \
233 tab_mvf[(y) * min_pu_width + x]
235 #define TAB_MVF_PU(v) \
236 TAB_MVF(x##v##_pu, y##v##_pu)
238 #define DERIVE_TEMPORAL_COLOCATED_MVS \
239 derive_temporal_colocated_mvs(s, temp_col, \
240 refIdxLx, mvLXCol, X, colPic, \
241 ff_hevc_get_ref_list(s, ref, x, y))
247 int nPbW,
int nPbH,
int refIdxLx,
255 int availableFlagLXCol = 0;
274 y < s->sps->height &&
280 temp_col =
TAB_MVF(x_pu, y_pu);
285 if (tab_mvf && !availableFlagLXCol) {
286 x = x0 + (nPbW >> 1);
287 y = y0 + (nPbH >> 1);
292 temp_col =
TAB_MVF(x_pu, y_pu);
295 return availableFlagLXCol;
298 #define AVAILABLE(cand, v) \
299 (cand && !TAB_MVF_PU(v).is_intra)
301 #define PRED_BLOCK_AVAILABLE(v) \
302 check_prediction_block_available(s, log2_cb_size, \
303 x0, y0, nPbW, nPbH, \
304 x##v, y##v, part_idx)
306 #define COMPARE_MV_REFIDX(a, b) \
307 compareMVrefidx(TAB_MVF_PU(a), TAB_MVF_PU(b))
313 int nPbW,
int nPbH,
int log2_cb_size,
314 int singleMCLFlag,
int part_idx,
315 struct MvField mergecandlist[])
329 const int xA1 = x0 - 1;
330 const int yA1 = y0 + nPbH - 1;
334 const int xB1 = x0 + nPbW - 1;
335 const int yB1 = y0 - 1;
339 const int xB0 = x0 + nPbW;
340 const int yB0 = y0 - 1;
344 const int xA0 = x0 - 1;
345 const int yA0 = y0 + nPbH;
349 const int xB2 = x0 - 1;
350 const int yB2 = y0 - 1;
361 int nb_merge_cand = 0;
362 int nb_orig_merge_cand = 0;
375 if (!singleMCLFlag && part_idx == 1 &&
389 if (!singleMCLFlag && part_idx == 1 &&
397 if (is_available_a1 && is_available_b1)
400 if (is_available_b1 && check_MER)
407 is_available_b0 = check_B0 &&
AVAILABLE(cand_up_right,
B0);
412 if (is_available_b1 && is_available_b0)
415 if (is_available_b0 && check_MER)
422 is_available_a0 = check_A0 &&
AVAILABLE(cand_bottom_left, A0);
427 if (is_available_a1 && is_available_a0)
430 if (is_available_a0 && check_MER)
431 mergecandlist[nb_merge_cand++] =
TAB_MVF_PU(A0);
441 if (is_available_a1 && is_available_b2)
444 if (is_available_b1 && is_available_b2)
447 if (is_available_b2 && check_MER && check_MER_1 && nb_merge_cand != 4)
452 nb_merge_cand < s->sh.max_num_merge_cand) {
453 Mv mv_l0_col, mv_l1_col;
458 0, &mv_l1_col, 1) : 0;
460 if (available_l0 || available_l1) {
461 mergecandlist[nb_merge_cand].
is_intra = 0;
462 mergecandlist[nb_merge_cand].
pred_flag[0] = available_l0;
463 mergecandlist[nb_merge_cand].
pred_flag[1] = available_l1;
465 mergecandlist[nb_merge_cand].
mv[0] = mv_l0_col;
466 mergecandlist[nb_merge_cand].
ref_idx[0] = 0;
469 mergecandlist[nb_merge_cand].
mv[1] = mv_l1_col;
470 mergecandlist[nb_merge_cand].
ref_idx[1] = 0;
476 nb_orig_merge_cand = nb_merge_cand;
480 nb_orig_merge_cand < s->sh.max_num_merge_cand) {
484 comb_idx < nb_orig_merge_cand * (nb_orig_merge_cand - 1); comb_idx++) {
487 MvField l0_cand = mergecandlist[l0_cand_idx];
488 MvField l1_cand = mergecandlist[l1_cand_idx];
493 l0_cand.
mv[0].
x != l1_cand.
mv[1].
x ||
494 l0_cand.
mv[0].
y != l1_cand.
mv[1].
y)) {
497 mergecandlist[nb_merge_cand].
pred_flag[0] = 1;
498 mergecandlist[nb_merge_cand].
pred_flag[1] = 1;
499 mergecandlist[nb_merge_cand].
mv[0].
x = l0_cand.
mv[0].
x;
500 mergecandlist[nb_merge_cand].
mv[0].
y = l0_cand.
mv[0].
y;
501 mergecandlist[nb_merge_cand].
mv[1].
x = l1_cand.
mv[1].
x;
502 mergecandlist[nb_merge_cand].
mv[1].
y = l1_cand.
mv[1].
y;
503 mergecandlist[nb_merge_cand].
is_intra = 0;
510 while (nb_merge_cand < s->sh.max_num_merge_cand) {
511 mergecandlist[nb_merge_cand].
pred_flag[0] = 1;
513 mergecandlist[nb_merge_cand].
mv[0].
x = 0;
514 mergecandlist[nb_merge_cand].
mv[0].
y = 0;
515 mergecandlist[nb_merge_cand].
mv[1].
x = 0;
516 mergecandlist[nb_merge_cand].
mv[1].
y = 0;
517 mergecandlist[nb_merge_cand].
is_intra = 0;
518 mergecandlist[nb_merge_cand].
ref_idx[0] = (zero_idx < nb_refs) ? zero_idx : 0;
519 mergecandlist[nb_merge_cand].
ref_idx[1] = (zero_idx < nb_refs) ? zero_idx : 0;
530 int nPbH,
int log2_cb_size,
int part_idx,
533 int singleMCLFlag = 0;
534 int nCS = 1 << log2_cb_size;
535 struct MvField mergecand_list[MRG_MAX_NUM_CANDS] = { { { { 0 } } } };
551 singleMCLFlag, part_idx, mergecand_list);
553 if (mergecand_list[merge_idx].
pred_flag[0] == 1 &&
554 mergecand_list[merge_idx].
pred_flag[1] == 1 &&
555 (nPbW2 + nPbH2) == 12) {
556 mergecand_list[merge_idx].
ref_idx[1] = -1;
557 mergecand_list[merge_idx].
pred_flag[1] = 0;
560 *mv = mergecand_list[merge_idx];
564 int min_pu_width,
int x,
int y,
565 int elist,
int ref_idx_curr,
int ref_idx)
569 int ref_pic_elist = refPicList[elist].
list[
TAB_MVF(x, y).ref_idx[elist]];
570 int ref_pic_curr = refPicList[ref_idx_curr].
list[
ref_idx];
572 if (ref_pic_elist != ref_pic_curr)
585 refPicList[pred_flag_index].list[
TAB_MVF(x, y).ref_idx[pred_flag_index]] == refPicList[ref_idx_curr].list[ref_idx]) {
586 *mv =
TAB_MVF(x, y).mv[pred_flag_index];
603 refPicList[pred_flag_index].
isLongTerm[(
TAB_MVF(x, y).ref_idx[pred_flag_index])];
605 if (
TAB_MVF(x, y).pred_flag[pred_flag_index] && colIsLongTerm == currIsLongTerm) {
606 *mv =
TAB_MVF(x, y).mv[pred_flag_index];
608 dist_scale(s, mv, min_pu_width, x, y, pred_flag_index, ref_idx_curr, ref_idx);
614 #define MP_MX(v, pred, mx) \
615 mv_mp_mode_mx(s, x##v##_pu, y##v##_pu, pred, &mx, ref_idx_curr, ref_idx)
617 #define MP_MX_LT(v, pred, mx) \
618 mv_mp_mode_mx_lt(s, x##v##_pu, y##v##_pu, pred, &mx, ref_idx_curr, ref_idx)
621 int nPbH,
int log2_cb_size,
int part_idx,
623 int mvp_lx_flag,
int LX)
627 int isScaledFlag_L0 = 0;
628 int availableFlagLXA0 = 0;
629 int availableFlagLXB0 = 0;
630 int numMVPCandLX = 0;
646 int xB1_pu = 0, yB1_pu = 0;
647 int is_available_b1 = 0;
650 int xB2_pu = 0, yB2_pu = 0;
651 int is_available_b2 = 0;
652 Mv mvpcand_list[2] = { { 0 } };
655 int ref_idx_curr = 0;
657 int pred_flag_index_l0;
658 int pred_flag_index_l1;
670 int cand_bottom_left = (y0 + nPbH >= lc->
end_of_tiles_y) ? 0 : cand_left;
674 pred_flag_index_l0 = LX;
675 pred_flag_index_l1 = !LX;
692 if (is_available_a0 || is_available_a1) {
696 if (is_available_a0) {
697 availableFlagLXA0 =
MP_MX(A0, pred_flag_index_l0, mxA);
698 if (!availableFlagLXA0)
699 availableFlagLXA0 =
MP_MX(A0, pred_flag_index_l1, mxA);
702 if (is_available_a1 && !availableFlagLXA0) {
703 availableFlagLXA0 =
MP_MX(
A1, pred_flag_index_l0, mxA);
704 if (!availableFlagLXA0)
705 availableFlagLXA0 =
MP_MX(
A1, pred_flag_index_l1, mxA);
708 if (is_available_a0 && !availableFlagLXA0) {
709 availableFlagLXA0 =
MP_MX_LT(A0, pred_flag_index_l0, mxA);
710 if (!availableFlagLXA0)
711 availableFlagLXA0 =
MP_MX_LT(A0, pred_flag_index_l1, mxA);
714 if (is_available_a1 && !availableFlagLXA0) {
715 availableFlagLXA0 =
MP_MX_LT(
A1, pred_flag_index_l0, mxA);
716 if (!availableFlagLXA0)
717 availableFlagLXA0 =
MP_MX_LT(
A1, pred_flag_index_l1, mxA);
729 if (is_available_b0) {
730 availableFlagLXB0 =
MP_MX(
B0, pred_flag_index_l0, mxB);
731 if (!availableFlagLXB0)
732 availableFlagLXB0 =
MP_MX(
B0, pred_flag_index_l1, mxB);
735 if (!availableFlagLXB0) {
744 if (is_available_b1) {
745 availableFlagLXB0 =
MP_MX(
B1, pred_flag_index_l0, mxB);
746 if (!availableFlagLXB0)
747 availableFlagLXB0 =
MP_MX(
B1, pred_flag_index_l1, mxB);
751 if (!availableFlagLXB0) {
759 if (is_available_b2) {
760 availableFlagLXB0 =
MP_MX(
B2, pred_flag_index_l0, mxB);
761 if (!availableFlagLXB0)
762 availableFlagLXB0 =
MP_MX(
B2, pred_flag_index_l1, mxB);
766 if (isScaledFlag_L0 == 0) {
767 if (availableFlagLXB0) {
768 availableFlagLXA0 = 1;
771 availableFlagLXB0 = 0;
774 if (is_available_b0) {
775 availableFlagLXB0 =
MP_MX_LT(
B0, pred_flag_index_l0, mxB);
776 if (!availableFlagLXB0)
777 availableFlagLXB0 =
MP_MX_LT(
B0, pred_flag_index_l1, mxB);
780 if (is_available_b1 && !availableFlagLXB0) {
781 availableFlagLXB0 =
MP_MX_LT(
B1, pred_flag_index_l0, mxB);
782 if (!availableFlagLXB0)
783 availableFlagLXB0 =
MP_MX_LT(
B1, pred_flag_index_l1, mxB);
786 if (is_available_b2 && !availableFlagLXB0) {
787 availableFlagLXB0 =
MP_MX_LT(
B2, pred_flag_index_l0, mxB);
788 if (!availableFlagLXB0)
789 availableFlagLXB0 =
MP_MX_LT(
B2, pred_flag_index_l1, mxB);
793 if (availableFlagLXA0)
794 mvpcand_list[numMVPCandLX++] = mxA;
796 if (availableFlagLXB0 && (!availableFlagLXA0 || mxA.
x != mxB.
x || mxA.
y != mxB.
y))
797 mvpcand_list[numMVPCandLX++] = mxB;
800 if (numMVPCandLX < 2 && s->sh.slice_temporal_mvp_enabled_flag) {
803 nPbH, ref_idx, &mv_col, LX);
805 mvpcand_list[numMVPCandLX++] = mv_col;
809 while (numMVPCandLX < 2)
810 mvpcand_list[numMVPCandLX++] = (
Mv){ 0, 0 };
812 mv->
mv[LX].
x = mvpcand_list[mvp_lx_flag].
x;
813 mv->
mv[LX].
y = mvpcand_list[mvp_lx_flag].
y;