44 int nPbW,
int nPbH,
int log2_ctb_size)
53 (x0b + nPbW == 1 << log2_ctb_size) ?
66 int xCurr,
int yCurr,
int xN,
int yN)
68 #define MIN_TB_ADDR_ZS(x, y) \
69 pps->min_tb_addr_zs[(y) * (sps->tb_mask+2) + (x)]
71 int xCurr_ctb = xCurr >>
sps->log2_ctb_size;
72 int yCurr_ctb = yCurr >>
sps->log2_ctb_size;
73 int xN_ctb = xN >>
sps->log2_ctb_size;
74 int yN_ctb = yN >>
sps->log2_ctb_size;
75 if( yN_ctb < yCurr_ctb || xN_ctb < xCurr_ctb )
79 (yCurr >>
sps->log2_min_tb_size) &
sps->tb_mask);
81 (yN >>
sps->log2_min_tb_size) &
sps->tb_mask);
89 uint8_t plevel =
pps->log2_parallel_merge_level;
91 return xN >> plevel == xP >> plevel &&
92 yN >> plevel == yP >> plevel;
95 #define MATCH_MV(x) (AV_RN32A(&A.x) == AV_RN32A(&B.x))
96 #define MATCH(x) (A.x == B.x)
101 int a_pf =
A.pred_flag;
102 int b_pf =
B.pred_flag;
107 }
else if (a_pf ==
PF_L0) {
109 }
else if (a_pf ==
PF_L1) {
118 int tx, scale_factor;
122 tx = (0x4000 +
abs(td / 2)) / td;
125 (scale_factor *
src->x < 0)) >> 8);
127 (scale_factor *
src->y < 0)) >> 8);
133 const RefPicList *refPicList_col,
int listCol,
int refidxCol)
136 int col_lt = refPicList_col[listCol].
isLongTerm[refidxCol];
137 int col_poc_diff, cur_poc_diff;
139 if (cur_lt != col_lt) {
145 col_poc_diff = colPic - refPicList_col[listCol].
list[refidxCol];
146 cur_poc_diff = poc - refPicList[
X].
list[refIdxLx];
148 if (cur_lt || col_poc_diff == cur_poc_diff || !col_poc_diff) {
149 mvLXCol->
x = mvCol->
x;
150 mvLXCol->
y = mvCol->
y;
152 mv_scale(mvLXCol, mvCol, col_poc_diff, cur_poc_diff);
157 #define CHECK_MVSET(l) \
158 check_mvset(mvLXCol, temp_col.mv + l, \
160 refPicList, X, refIdxLx, \
161 refPicList_col, L ## l, temp_col.ref_idx[l])
165 int refIdxLx,
Mv *mvLXCol,
int X,
168 const RefPicList *refPicList =
s->cur_frame->refPicList;
178 int check_diffpicount = 0;
180 for (j = 0; j < 2; j++) {
182 if (refPicList[j].
list[
i] >
s->poc) {
188 if (!check_diffpicount) {
194 if (
s->sh.collocated_list ==
L1)
204 #define TAB_MVF(x, y) \
205 tab_mvf[(y) * min_pu_width + x]
207 #define TAB_MVF_PU(v) \
208 TAB_MVF(((x ## v) >> sps->log2_min_pu_size), \
209 ((y ## v) >> sps->log2_min_pu_size))
211 #define DERIVE_TEMPORAL_COLOCATED_MVS \
212 derive_temporal_colocated_mvs(s, temp_col, \
213 refIdxLx, mvLXCol, X, colPic, \
214 ff_hevc_get_ref_list(ref, x, y))
221 int nPbW,
int nPbH,
int refIdxLx,
226 int x, y, x_pu, y_pu;
227 int min_pu_width =
sps->min_pu_width;
228 int availableFlagLXCol = 0;
234 memset(mvLXCol, 0,
sizeof(*mvLXCol));
238 tab_mvf =
ref->tab_mvf;
246 (y0 >>
sps->log2_ctb_size) == (y >>
sps->log2_ctb_size) &&
253 x_pu = x >>
sps->log2_min_pu_size;
254 y_pu = y >>
sps->log2_min_pu_size;
255 temp_col =
TAB_MVF(x_pu, y_pu);
260 if (tab_mvf && !availableFlagLXCol) {
261 x = x0 + (nPbW >> 1);
262 y = y0 + (nPbH >> 1);
267 x_pu = x >>
sps->log2_min_pu_size;
268 y_pu = y >>
sps->log2_min_pu_size;
269 temp_col =
TAB_MVF(x_pu, y_pu);
272 return availableFlagLXCol;
275 #define AVAILABLE(cand, v) \
276 (cand && !(TAB_MVF_PU(v).pred_flag == PF_INTRA))
278 #define PRED_BLOCK_AVAILABLE(v) \
279 z_scan_block_avail(pps, sps, x0, y0, x ## v, y ## v)
281 #define COMPARE_MV_REFIDX(a, b) \
282 compare_mv_ref_idx(TAB_MVF_PU(a), TAB_MVF_PU(b))
292 int singleMCLFlag,
int part_idx,
294 struct MvField mergecandlist[])
296 const RefPicList *refPicList =
s->cur_frame->refPicList;
297 const MvField *tab_mvf =
s->cur_frame->tab_mvf;
299 const int min_pu_width =
sps->min_pu_width;
307 const int xA1 = x0 - 1;
308 const int yA1 = y0 + nPbH - 1;
310 const int xB1 = x0 + nPbW - 1;
311 const int yB1 = y0 - 1;
313 const int xB0 = x0 + nPbW;
314 const int yB0 = y0 - 1;
316 const int xA0 = x0 - 1;
317 const int yA0 = y0 + nPbH;
319 const int xB2 = x0 - 1;
320 const int yB2 = y0 - 1;
323 s->sh.nb_refs[0] :
FFMIN(
s->sh.nb_refs[0],
s->sh.nb_refs[1]);
327 int nb_merge_cand = 0;
328 int nb_orig_merge_cand = 0;
337 if (!singleMCLFlag && part_idx == 1 &&
345 if (is_available_a1) {
353 if (!singleMCLFlag && part_idx == 1 &&
361 if (is_available_b1 &&
364 if (merge_idx == nb_merge_cand)
376 if (is_available_b0 &&
379 if (merge_idx == nb_merge_cand)
385 is_available_a0 =
AVAILABLE(cand_bottom_left,
A0) &&
390 if (is_available_a0 &&
393 if (merge_idx == nb_merge_cand)
402 if (is_available_b2 &&
405 nb_merge_cand != 4) {
407 if (merge_idx == nb_merge_cand)
413 if (
s->sh.slice_temporal_mvp_enabled_flag &&
414 nb_merge_cand < s->sh.max_num_merge_cand) {
415 Mv mv_l0_col = { 0 }, mv_l1_col = { 0 };
420 0, &mv_l1_col, 1) : 0;
422 if (available_l0 || available_l1) {
423 mergecandlist[nb_merge_cand].
pred_flag = available_l0 + (available_l1 << 1);
424 AV_ZERO16(mergecandlist[nb_merge_cand].ref_idx);
425 mergecandlist[nb_merge_cand].
mv[0] = mv_l0_col;
426 mergecandlist[nb_merge_cand].
mv[1] = mv_l1_col;
428 if (merge_idx == nb_merge_cand)
434 nb_orig_merge_cand = nb_merge_cand;
437 if (
s->sh.slice_type ==
HEVC_SLICE_B && nb_orig_merge_cand > 1 &&
438 nb_orig_merge_cand < s->sh.max_num_merge_cand) {
441 for (comb_idx = 0; nb_merge_cand <
s->sh.max_num_merge_cand &&
442 comb_idx < nb_orig_merge_cand * (nb_orig_merge_cand - 1); comb_idx++) {
445 MvField l0_cand = mergecandlist[l0_cand_idx];
446 MvField l1_cand = mergecandlist[l1_cand_idx];
455 AV_COPY32(&mergecandlist[nb_merge_cand].
mv[0], &l0_cand.
mv[0]);
456 AV_COPY32(&mergecandlist[nb_merge_cand].
mv[1], &l1_cand.
mv[1]);
457 if (merge_idx == nb_merge_cand)
465 while (nb_merge_cand < s->sh.max_num_merge_cand) {
469 mergecandlist[nb_merge_cand].
ref_idx[0] = zero_idx < nb_refs ? zero_idx : 0;
470 mergecandlist[nb_merge_cand].
ref_idx[1] = zero_idx < nb_refs ? zero_idx : 0;
472 if (merge_idx == nb_merge_cand)
483 int x0,
int y0,
int nPbW,
484 int nPbH,
int log2_cb_size,
int part_idx,
489 int singleMCLFlag = 0;
490 int nCS = 1 << log2_cb_size;
495 if (
pps->log2_parallel_merge_level > 2 && nCS == 8) {
506 singleMCLFlag, part_idx,
507 merge_idx, mergecand_list);
509 if (mergecand_list[merge_idx].pred_flag ==
PF_BI &&
510 (nPbW2 + nPbH2) == 12) {
514 *
mv = mergecand_list[merge_idx];
518 int min_pu_width,
int x,
int y,
519 int elist,
int ref_idx_curr,
int ref_idx)
521 const RefPicList *refPicList =
s->cur_frame->refPicList;
522 const MvField *tab_mvf =
s->cur_frame->tab_mvf;
523 int ref_pic_elist = refPicList[elist].
list[
TAB_MVF(x, y).ref_idx[elist]];
524 int ref_pic_curr = refPicList[ref_idx_curr].
list[ref_idx];
526 if (ref_pic_elist != ref_pic_curr) {
527 int poc_diff =
s->poc - ref_pic_elist;
535 int x,
int y,
int pred_flag_index,
536 Mv *
mv,
int ref_idx_curr,
int ref_idx)
538 const MvField *tab_mvf =
s->cur_frame->tab_mvf;
539 int min_pu_width =
sps->min_pu_width;
541 const RefPicList *refPicList =
s->cur_frame->refPicList;
543 if (((
TAB_MVF(x, y).pred_flag) & (1 << pred_flag_index)) &&
544 refPicList[pred_flag_index].
list[
TAB_MVF(x, y).ref_idx[pred_flag_index]] == refPicList[ref_idx_curr].
list[ref_idx]) {
552 int x,
int y,
int pred_flag_index,
553 Mv *
mv,
int ref_idx_curr,
int ref_idx)
555 const MvField *tab_mvf =
s->cur_frame->tab_mvf;
556 int min_pu_width =
sps->min_pu_width;
558 const RefPicList *refPicList =
s->cur_frame->refPicList;
560 if ((
TAB_MVF(x, y).pred_flag) & (1 << pred_flag_index)) {
561 int currIsLongTerm = refPicList[ref_idx_curr].
isLongTerm[ref_idx];
564 refPicList[pred_flag_index].
isLongTerm[(
TAB_MVF(x, y).ref_idx[pred_flag_index])];
566 if (colIsLongTerm == currIsLongTerm) {
570 pred_flag_index, ref_idx_curr, ref_idx);
577 #define MP_MX(v, pred, mx) \
578 mv_mp_mode_mx(s, sps, \
579 (x ## v) >> sps->log2_min_pu_size, \
580 (y ## v) >> sps->log2_min_pu_size, \
581 pred, &mx, ref_idx_curr, ref_idx)
583 #define MP_MX_LT(v, pred, mx) \
584 mv_mp_mode_mx_lt(s, sps, \
585 (x ## v) >> sps->log2_min_pu_size, \
586 (y ## v) >> sps->log2_min_pu_size, \
587 pred, &mx, ref_idx_curr, ref_idx)
590 int x0,
int y0,
int nPbW,
591 int nPbH,
int log2_cb_size,
int part_idx,
593 int mvp_lx_flag,
int LX)
597 const MvField *
const tab_mvf =
s->cur_frame->tab_mvf;
598 int isScaledFlag_L0 = 0;
599 int availableFlagLXA0 = 1;
600 int availableFlagLXB0 = 1;
601 int numMVPCandLX = 0;
602 int min_pu_width =
sps->min_pu_width;
615 Mv mvpcand_list[2] = { { 0 } };
620 int pred_flag_index_l0;
621 int pred_flag_index_l1;
629 ref_idx =
mv->ref_idx[LX];
630 pred_flag_index_l0 = LX;
631 pred_flag_index_l1 = !LX;
637 is_available_a0 =
AVAILABLE(cand_bottom_left,
A0) &&
646 if (is_available_a0 || is_available_a1)
649 if (is_available_a0) {
650 if (
MP_MX(
A0, pred_flag_index_l0, mxA)) {
653 if (
MP_MX(
A0, pred_flag_index_l1, mxA)) {
658 if (is_available_a1) {
659 if (
MP_MX(
A1, pred_flag_index_l0, mxA)) {
662 if (
MP_MX(
A1, pred_flag_index_l1, mxA)) {
667 if (is_available_a0) {
676 if (is_available_a1) {
684 availableFlagLXA0 = 0;
707 if (is_available_b0) {
708 if (
MP_MX(
B0, pred_flag_index_l0, mxB)) {
711 if (
MP_MX(
B0, pred_flag_index_l1, mxB)) {
717 if (is_available_b1) {
718 if (
MP_MX(
B1, pred_flag_index_l0, mxB)) {
721 if (
MP_MX(
B1, pred_flag_index_l1, mxB)) {
727 if (is_available_b2) {
728 if (
MP_MX(
B2, pred_flag_index_l0, mxB)) {
731 if (
MP_MX(
B2, pred_flag_index_l1, mxB)) {
735 availableFlagLXB0 = 0;
738 if (!isScaledFlag_L0) {
739 if (availableFlagLXB0) {
740 availableFlagLXA0 = 1;
743 availableFlagLXB0 = 0;
746 if (is_available_b0) {
747 availableFlagLXB0 =
MP_MX_LT(
B0, pred_flag_index_l0, mxB);
748 if (!availableFlagLXB0)
749 availableFlagLXB0 =
MP_MX_LT(
B0, pred_flag_index_l1, mxB);
752 if (is_available_b1 && !availableFlagLXB0) {
753 availableFlagLXB0 =
MP_MX_LT(
B1, pred_flag_index_l0, mxB);
754 if (!availableFlagLXB0)
755 availableFlagLXB0 =
MP_MX_LT(
B1, pred_flag_index_l1, mxB);
758 if (is_available_b2 && !availableFlagLXB0) {
759 availableFlagLXB0 =
MP_MX_LT(
B2, pred_flag_index_l0, mxB);
760 if (!availableFlagLXB0)
761 availableFlagLXB0 =
MP_MX_LT(
B2, pred_flag_index_l1, mxB);
765 if (availableFlagLXA0)
766 mvpcand_list[numMVPCandLX++] = mxA;
768 if (availableFlagLXB0 && (!availableFlagLXA0 || mxA.
x != mxB.
x || mxA.
y != mxB.
y))
769 mvpcand_list[numMVPCandLX++] = mxB;
772 if (numMVPCandLX < 2 && s->sh.slice_temporal_mvp_enabled_flag &&
773 mvp_lx_flag == numMVPCandLX) {
779 mvpcand_list[numMVPCandLX++] = mv_col;
782 mv->mv[LX] = mvpcand_list[mvp_lx_flag];