46 int x0b = av_mod_uintp2(x0,
s->ps.sps->log2_ctb_size);
47 int y0b = av_mod_uintp2(y0,
s->ps.sps->log2_ctb_size);
53 ((x0b + nPbW) == (1 <<
s->ps.sps->log2_ctb_size)) ?
67 #define MIN_TB_ADDR_ZS(x, y) \
68 s->ps.pps->min_tb_addr_zs[(y) * (s->ps.sps->tb_mask+2) + (x)]
70 int xCurr_ctb = xCurr >>
s->ps.sps->log2_ctb_size;
71 int yCurr_ctb = yCurr >>
s->ps.sps->log2_ctb_size;
72 int xN_ctb = xN >>
s->ps.sps->log2_ctb_size;
73 int yN_ctb = yN >>
s->ps.sps->log2_ctb_size;
74 if( yN_ctb < yCurr_ctb || xN_ctb < xCurr_ctb )
77 int Curr =
MIN_TB_ADDR_ZS((xCurr >>
s->ps.sps->log2_min_tb_size) &
s->ps.sps->tb_mask,
78 (yCurr >>
s->ps.sps->log2_min_tb_size) &
s->ps.sps->tb_mask);
80 (yN >>
s->ps.sps->log2_min_tb_size) &
s->ps.sps->tb_mask);
88 uint8_t plevel =
s->ps.pps->log2_parallel_merge_level;
90 return xN >> plevel == xP >> plevel &&
91 yN >> plevel == yP >> plevel;
94 #define MATCH_MV(x) (AV_RN32A(&A.x) == AV_RN32A(&B.x))
95 #define MATCH(x) (A.x == B.x)
100 int a_pf =
A.pred_flag;
101 int b_pf =
B.pred_flag;
106 }
else if (a_pf ==
PF_L0) {
108 }
else if (a_pf ==
PF_L1) {
117 int tx, scale_factor;
119 td = av_clip_int8(
td);
120 tb = av_clip_int8(
tb);
121 tx = (0x4000 +
abs(
td / 2)) /
td;
122 scale_factor = av_clip_intp2((
tb * tx + 32) >> 6, 12);
123 dst->
x = av_clip_int16((scale_factor *
src->x + 127 +
124 (scale_factor *
src->x < 0)) >> 8);
125 dst->
y = av_clip_int16((scale_factor *
src->y + 127 +
126 (scale_factor *
src->y < 0)) >> 8);
132 RefPicList *refPicList_col,
int listCol,
int refidxCol)
135 int col_lt = refPicList_col[listCol].
isLongTerm[refidxCol];
136 int col_poc_diff, cur_poc_diff;
138 if (cur_lt != col_lt) {
144 col_poc_diff = colPic - refPicList_col[listCol].
list[refidxCol];
145 cur_poc_diff = poc - refPicList[
X].
list[refIdxLx];
147 if (cur_lt || col_poc_diff == cur_poc_diff || !col_poc_diff) {
148 mvLXCol->
x = mvCol->
x;
149 mvLXCol->
y = mvCol->
y;
151 mv_scale(mvLXCol, mvCol, col_poc_diff, cur_poc_diff);
156 #define CHECK_MVSET(l) \
157 check_mvset(mvLXCol, temp_col.mv + l, \
159 refPicList, X, refIdxLx, \
160 refPicList_col, L ## l, temp_col.ref_idx[l])
164 int refIdxLx,
Mv *mvLXCol,
int X,
177 int check_diffpicount = 0;
179 for (j = 0; j < 2; j++) {
181 if (refPicList[j].
list[
i] >
s->poc) {
187 if (!check_diffpicount) {
193 if (
s->sh.collocated_list ==
L1)
203 #define TAB_MVF(x, y) \
204 tab_mvf[(y) * min_pu_width + x]
206 #define TAB_MVF_PU(v) \
207 TAB_MVF(((x ## v) >> s->ps.sps->log2_min_pu_size), \
208 ((y ## v) >> s->ps.sps->log2_min_pu_size))
210 #define DERIVE_TEMPORAL_COLOCATED_MVS \
211 derive_temporal_colocated_mvs(s, temp_col, \
212 refIdxLx, mvLXCol, X, colPic, \
213 ff_hevc_get_ref_list(s, ref, x, y))
219 int nPbW,
int nPbH,
int refIdxLx,
224 int x, y, x_pu, y_pu;
225 int min_pu_width =
s->ps.sps->min_pu_width;
226 int availableFlagLXCol = 0;
232 memset(mvLXCol, 0,
sizeof(*mvLXCol));
236 tab_mvf =
ref->tab_mvf;
244 (y0 >>
s->ps.sps->log2_ctb_size) == (y >>
s->ps.sps->log2_ctb_size) &&
245 y < s->ps.sps->height &&
246 x < s->ps.sps->width) {
251 x_pu = x >>
s->ps.sps->log2_min_pu_size;
252 y_pu = y >>
s->ps.sps->log2_min_pu_size;
253 temp_col =
TAB_MVF(x_pu, y_pu);
258 if (tab_mvf && !availableFlagLXCol) {
259 x = x0 + (nPbW >> 1);
260 y = y0 + (nPbH >> 1);
265 x_pu = x >>
s->ps.sps->log2_min_pu_size;
266 y_pu = y >>
s->ps.sps->log2_min_pu_size;
267 temp_col =
TAB_MVF(x_pu, y_pu);
270 return availableFlagLXCol;
273 #define AVAILABLE(cand, v) \
274 (cand && !(TAB_MVF_PU(v).pred_flag == PF_INTRA))
276 #define PRED_BLOCK_AVAILABLE(v) \
277 z_scan_block_avail(s, x0, y0, x ## v, y ## v)
279 #define COMPARE_MV_REFIDX(a, b) \
280 compare_mv_ref_idx(TAB_MVF_PU(a), TAB_MVF_PU(b))
288 int singleMCLFlag,
int part_idx,
290 struct MvField mergecandlist[])
296 const int min_pu_width =
s->ps.sps->min_pu_width;
304 const int xA1 = x0 - 1;
305 const int yA1 = y0 + nPbH - 1;
307 const int xB1 = x0 + nPbW - 1;
308 const int yB1 = y0 - 1;
310 const int xB0 = x0 + nPbW;
311 const int yB0 = y0 - 1;
313 const int xA0 = x0 - 1;
314 const int yA0 = y0 + nPbH;
316 const int xB2 = x0 - 1;
317 const int yB2 = y0 - 1;
320 s->sh.nb_refs[0] :
FFMIN(
s->sh.nb_refs[0],
s->sh.nb_refs[1]);
324 int nb_merge_cand = 0;
325 int nb_orig_merge_cand = 0;
334 if (!singleMCLFlag && part_idx == 1 &&
342 if (is_available_a1) {
350 if (!singleMCLFlag && part_idx == 1 &&
358 if (is_available_b1 &&
361 if (merge_idx == nb_merge_cand)
369 xB0 <
s->ps.sps->width &&
373 if (is_available_b0 &&
376 if (merge_idx == nb_merge_cand)
382 is_available_a0 =
AVAILABLE(cand_bottom_left, A0) &&
383 yA0 <
s->ps.sps->height &&
387 if (is_available_a0 &&
389 mergecandlist[nb_merge_cand] =
TAB_MVF_PU(A0);
390 if (merge_idx == nb_merge_cand)
399 if (is_available_b2 &&
402 nb_merge_cand != 4) {
404 if (merge_idx == nb_merge_cand)
410 if (
s->sh.slice_temporal_mvp_enabled_flag &&
411 nb_merge_cand < s->sh.max_num_merge_cand) {
412 Mv mv_l0_col = { 0 }, mv_l1_col = { 0 };
417 0, &mv_l1_col, 1) : 0;
419 if (available_l0 || available_l1) {
420 mergecandlist[nb_merge_cand].
pred_flag = available_l0 + (available_l1 << 1);
421 AV_ZERO16(mergecandlist[nb_merge_cand].ref_idx);
422 mergecandlist[nb_merge_cand].
mv[0] = mv_l0_col;
423 mergecandlist[nb_merge_cand].
mv[1] = mv_l1_col;
425 if (merge_idx == nb_merge_cand)
431 nb_orig_merge_cand = nb_merge_cand;
434 if (
s->sh.slice_type ==
HEVC_SLICE_B && nb_orig_merge_cand > 1 &&
435 nb_orig_merge_cand < s->sh.max_num_merge_cand) {
438 for (comb_idx = 0; nb_merge_cand <
s->sh.max_num_merge_cand &&
439 comb_idx < nb_orig_merge_cand * (nb_orig_merge_cand - 1); comb_idx++) {
442 MvField l0_cand = mergecandlist[l0_cand_idx];
443 MvField l1_cand = mergecandlist[l1_cand_idx];
452 AV_COPY32(&mergecandlist[nb_merge_cand].
mv[0], &l0_cand.
mv[0]);
453 AV_COPY32(&mergecandlist[nb_merge_cand].
mv[1], &l1_cand.
mv[1]);
454 if (merge_idx == nb_merge_cand)
462 while (nb_merge_cand < s->sh.max_num_merge_cand) {
466 mergecandlist[nb_merge_cand].
ref_idx[0] = zero_idx < nb_refs ? zero_idx : 0;
467 mergecandlist[nb_merge_cand].
ref_idx[1] = zero_idx < nb_refs ? zero_idx : 0;
469 if (merge_idx == nb_merge_cand)
480 int nPbH,
int log2_cb_size,
int part_idx,
483 int singleMCLFlag = 0;
484 int nCS = 1 << log2_cb_size;
490 if (
s->ps.pps->log2_parallel_merge_level > 2 && nCS == 8) {
501 singleMCLFlag, part_idx,
502 merge_idx, mergecand_list);
504 if (mergecand_list[merge_idx].pred_flag ==
PF_BI &&
505 (nPbW2 + nPbH2) == 12) {
509 *
mv = mergecand_list[merge_idx];
513 int min_pu_width,
int x,
int y,
514 int elist,
int ref_idx_curr,
int ref_idx)
518 int ref_pic_elist = refPicList[elist].
list[
TAB_MVF(x, y).ref_idx[elist]];
519 int ref_pic_curr = refPicList[ref_idx_curr].
list[ref_idx];
521 if (ref_pic_elist != ref_pic_curr) {
522 int poc_diff =
s->poc - ref_pic_elist;
530 Mv *
mv,
int ref_idx_curr,
int ref_idx)
533 int min_pu_width =
s->ps.sps->min_pu_width;
537 if (((
TAB_MVF(x, y).pred_flag) & (1 << pred_flag_index)) &&
538 refPicList[pred_flag_index].
list[
TAB_MVF(x, y).ref_idx[pred_flag_index]] == refPicList[ref_idx_curr].
list[ref_idx]) {
546 Mv *
mv,
int ref_idx_curr,
int ref_idx)
549 int min_pu_width =
s->ps.sps->min_pu_width;
553 if ((
TAB_MVF(x, y).pred_flag) & (1 << pred_flag_index)) {
554 int currIsLongTerm = refPicList[ref_idx_curr].
isLongTerm[ref_idx];
557 refPicList[pred_flag_index].
isLongTerm[(
TAB_MVF(x, y).ref_idx[pred_flag_index])];
559 if (colIsLongTerm == currIsLongTerm) {
563 pred_flag_index, ref_idx_curr, ref_idx);
570 #define MP_MX(v, pred, mx) \
572 (x ## v) >> s->ps.sps->log2_min_pu_size, \
573 (y ## v) >> s->ps.sps->log2_min_pu_size, \
574 pred, &mx, ref_idx_curr, ref_idx)
576 #define MP_MX_LT(v, pred, mx) \
577 mv_mp_mode_mx_lt(s, \
578 (x ## v) >> s->ps.sps->log2_min_pu_size, \
579 (y ## v) >> s->ps.sps->log2_min_pu_size, \
580 pred, &mx, ref_idx_curr, ref_idx)
583 int nPbH,
int log2_cb_size,
int part_idx,
585 int mvp_lx_flag,
int LX)
589 int isScaledFlag_L0 = 0;
590 int availableFlagLXA0 = 1;
591 int availableFlagLXB0 = 1;
592 int numMVPCandLX = 0;
593 int min_pu_width =
s->ps.sps->min_pu_width;
606 Mv mvpcand_list[2] = { { 0 } };
611 int pred_flag_index_l0;
612 int pred_flag_index_l1;
620 ref_idx =
mv->ref_idx[LX];
621 pred_flag_index_l0 = LX;
622 pred_flag_index_l1 = !LX;
628 is_available_a0 =
AVAILABLE(cand_bottom_left, A0) &&
629 yA0 <
s->ps.sps->height &&
637 if (is_available_a0 || is_available_a1)
640 if (is_available_a0) {
641 if (
MP_MX(A0, pred_flag_index_l0, mxA)) {
644 if (
MP_MX(A0, pred_flag_index_l1, mxA)) {
649 if (is_available_a1) {
650 if (
MP_MX(
A1, pred_flag_index_l0, mxA)) {
653 if (
MP_MX(
A1, pred_flag_index_l1, mxA)) {
658 if (is_available_a0) {
659 if (
MP_MX_LT(A0, pred_flag_index_l0, mxA)) {
662 if (
MP_MX_LT(A0, pred_flag_index_l1, mxA)) {
667 if (is_available_a1) {
675 availableFlagLXA0 = 0;
684 xB0 <
s->ps.sps->width &&
698 if (is_available_b0) {
699 if (
MP_MX(
B0, pred_flag_index_l0, mxB)) {
702 if (
MP_MX(
B0, pred_flag_index_l1, mxB)) {
708 if (is_available_b1) {
709 if (
MP_MX(
B1, pred_flag_index_l0, mxB)) {
712 if (
MP_MX(
B1, pred_flag_index_l1, mxB)) {
718 if (is_available_b2) {
719 if (
MP_MX(
B2, pred_flag_index_l0, mxB)) {
722 if (
MP_MX(
B2, pred_flag_index_l1, mxB)) {
726 availableFlagLXB0 = 0;
729 if (!isScaledFlag_L0) {
730 if (availableFlagLXB0) {
731 availableFlagLXA0 = 1;
734 availableFlagLXB0 = 0;
737 if (is_available_b0) {
738 availableFlagLXB0 =
MP_MX_LT(
B0, pred_flag_index_l0, mxB);
739 if (!availableFlagLXB0)
740 availableFlagLXB0 =
MP_MX_LT(
B0, pred_flag_index_l1, mxB);
743 if (is_available_b1 && !availableFlagLXB0) {
744 availableFlagLXB0 =
MP_MX_LT(
B1, pred_flag_index_l0, mxB);
745 if (!availableFlagLXB0)
746 availableFlagLXB0 =
MP_MX_LT(
B1, pred_flag_index_l1, mxB);
749 if (is_available_b2 && !availableFlagLXB0) {
750 availableFlagLXB0 =
MP_MX_LT(
B2, pred_flag_index_l0, mxB);
751 if (!availableFlagLXB0)
752 availableFlagLXB0 =
MP_MX_LT(
B2, pred_flag_index_l1, mxB);
756 if (availableFlagLXA0)
757 mvpcand_list[numMVPCandLX++] = mxA;
759 if (availableFlagLXB0 && (!availableFlagLXA0 || mxA.
x != mxB.
x || mxA.
y != mxB.
y))
760 mvpcand_list[numMVPCandLX++] = mxB;
763 if (numMVPCandLX < 2 && s->sh.slice_temporal_mvp_enabled_flag &&
764 mvp_lx_flag == numMVPCandLX) {
770 mvpcand_list[numMVPCandLX++] = mv_col;
773 mv->mv[LX] = mvpcand_list[mvp_lx_flag];