2013-10-12 09:55:48 +00:00
|
|
|
/*
|
2013-11-02 10:59:02 +00:00
|
|
|
* HEVC video decoder
|
2013-10-12 09:55:48 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2012 - 2013 Guillaume Martres
|
|
|
|
* Copyright (C) 2013 Anand Meher Kotra
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2016-10-18 19:14:18 +00:00
|
|
|
#include "hevc.h"
|
2016-08-21 15:14:24 +00:00
|
|
|
#include "hevcdec.h"
|
2013-10-12 09:55:48 +00:00
|
|
|
|
|
|
|
static const uint8_t l0_l1_cand_idx[12][2] = {
|
|
|
|
{ 0, 1, },
|
|
|
|
{ 1, 0, },
|
|
|
|
{ 0, 2, },
|
|
|
|
{ 2, 0, },
|
|
|
|
{ 1, 2, },
|
|
|
|
{ 2, 1, },
|
|
|
|
{ 0, 3, },
|
|
|
|
{ 3, 0, },
|
|
|
|
{ 1, 3, },
|
|
|
|
{ 3, 1, },
|
|
|
|
{ 2, 3, },
|
|
|
|
{ 3, 2, },
|
|
|
|
};
|
|
|
|
|
2013-11-01 23:31:49 +00:00
|
|
|
void ff_hevc_set_neighbour_available(HEVCContext *s, int x0, int y0,
|
|
|
|
int nPbW, int nPbH)
|
2013-10-12 09:55:48 +00:00
|
|
|
{
|
2013-10-21 09:49:35 +00:00
|
|
|
HEVCLocalContext *lc = s->HEVClc;
|
2015-07-12 20:06:21 +00:00
|
|
|
int x0b = av_mod_uintp2(x0, s->ps.sps->log2_ctb_size);
|
|
|
|
int y0b = av_mod_uintp2(y0, s->ps.sps->log2_ctb_size);
|
2013-10-12 09:55:48 +00:00
|
|
|
|
|
|
|
lc->na.cand_up = (lc->ctb_up_flag || y0b);
|
|
|
|
lc->na.cand_left = (lc->ctb_left_flag || x0b);
|
|
|
|
lc->na.cand_up_left = (!x0b && !y0b) ? lc->ctb_up_left_flag : lc->na.cand_left && lc->na.cand_up;
|
|
|
|
lc->na.cand_up_right_sap =
|
2015-07-09 12:22:43 +00:00
|
|
|
((x0b + nPbW) == (1 << s->ps.sps->log2_ctb_size)) ?
|
2013-10-12 09:55:48 +00:00
|
|
|
lc->ctb_up_right_flag && !y0b : lc->na.cand_up;
|
|
|
|
lc->na.cand_up_right =
|
2014-07-18 23:38:06 +00:00
|
|
|
lc->na.cand_up_right_sap
|
2013-10-12 09:55:48 +00:00
|
|
|
&& (x0 + nPbW) < lc->end_of_tiles_x;
|
|
|
|
lc->na.cand_bottom_left = ((y0 + nPbH) >= lc->end_of_tiles_y) ? 0 : lc->na.cand_left;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 6.4.1 Derivation process for z-scan order block availability
|
|
|
|
*/
|
2014-07-18 23:39:09 +00:00
|
|
|
static av_always_inline int z_scan_block_avail(HEVCContext *s, int xCurr, int yCurr,
|
2013-10-12 09:55:48 +00:00
|
|
|
int xN, int yN)
|
|
|
|
{
|
|
|
|
#define MIN_TB_ADDR_ZS(x, y) \
|
2015-07-12 20:06:21 +00:00
|
|
|
s->ps.pps->min_tb_addr_zs[(y) * (s->ps.sps->tb_mask+2) + (x)]
|
2014-06-24 06:27:16 +00:00
|
|
|
|
2015-07-12 20:06:21 +00:00
|
|
|
int xCurr_ctb = xCurr >> s->ps.sps->log2_ctb_size;
|
|
|
|
int yCurr_ctb = yCurr >> s->ps.sps->log2_ctb_size;
|
|
|
|
int xN_ctb = xN >> s->ps.sps->log2_ctb_size;
|
|
|
|
int yN_ctb = yN >> s->ps.sps->log2_ctb_size;
|
2014-06-24 06:27:16 +00:00
|
|
|
if( yN_ctb < yCurr_ctb || xN_ctb < xCurr_ctb )
|
|
|
|
return 1;
|
|
|
|
else {
|
2015-07-12 20:06:21 +00:00
|
|
|
int Curr = MIN_TB_ADDR_ZS((xCurr >> s->ps.sps->log2_min_tb_size) & s->ps.sps->tb_mask,
|
|
|
|
(yCurr >> s->ps.sps->log2_min_tb_size) & s->ps.sps->tb_mask);
|
|
|
|
int N = MIN_TB_ADDR_ZS((xN >> s->ps.sps->log2_min_tb_size) & s->ps.sps->tb_mask,
|
|
|
|
(yN >> s->ps.sps->log2_min_tb_size) & s->ps.sps->tb_mask);
|
2014-06-24 06:27:16 +00:00
|
|
|
return N <= Curr;
|
|
|
|
}
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
|
2016-04-27 17:45:23 +00:00
|
|
|
//check if the two luma locations belong to the same motion estimation region
|
2014-07-18 23:39:09 +00:00
|
|
|
static av_always_inline int is_diff_mer(HEVCContext *s, int xN, int yN, int xP, int yP)
|
2013-10-12 09:55:48 +00:00
|
|
|
{
|
2015-07-09 12:22:43 +00:00
|
|
|
uint8_t plevel = s->ps.pps->log2_parallel_merge_level;
|
2013-10-12 09:55:48 +00:00
|
|
|
|
|
|
|
return xN >> plevel == xP >> plevel &&
|
|
|
|
yN >> plevel == yP >> plevel;
|
|
|
|
}
|
|
|
|
|
2014-07-12 14:51:09 +00:00
|
|
|
#define MATCH_MV(x) (AV_RN32A(&A.x) == AV_RN32A(&B.x))
|
2013-10-12 09:55:48 +00:00
|
|
|
#define MATCH(x) (A.x == B.x)
|
|
|
|
|
|
|
|
// check if the mv's and refidx are the same between A and B
|
2014-07-18 23:39:09 +00:00
|
|
|
static av_always_inline int compare_mv_ref_idx(struct MvField A, struct MvField B)
|
2013-10-12 09:55:48 +00:00
|
|
|
{
|
2014-04-26 13:35:23 +00:00
|
|
|
int a_pf = A.pred_flag;
|
|
|
|
int b_pf = B.pred_flag;
|
|
|
|
if (a_pf == b_pf) {
|
|
|
|
if (a_pf == PF_BI) {
|
2014-07-12 14:51:09 +00:00
|
|
|
return MATCH(ref_idx[0]) && MATCH_MV(mv[0]) &&
|
|
|
|
MATCH(ref_idx[1]) && MATCH_MV(mv[1]);
|
2014-04-26 13:35:23 +00:00
|
|
|
} else if (a_pf == PF_L0) {
|
2014-07-12 14:51:09 +00:00
|
|
|
return MATCH(ref_idx[0]) && MATCH_MV(mv[0]);
|
2014-04-26 13:35:23 +00:00
|
|
|
} else if (a_pf == PF_L1) {
|
2014-07-12 14:51:09 +00:00
|
|
|
return MATCH(ref_idx[1]) && MATCH_MV(mv[1]);
|
2014-04-26 13:35:23 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-12 09:55:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static av_always_inline void mv_scale(Mv *dst, Mv *src, int td, int tb)
|
|
|
|
{
|
|
|
|
int tx, scale_factor;
|
|
|
|
|
2014-04-26 13:35:23 +00:00
|
|
|
td = av_clip_int8(td);
|
|
|
|
tb = av_clip_int8(tb);
|
2013-10-12 09:55:48 +00:00
|
|
|
tx = (0x4000 + abs(td / 2)) / td;
|
2015-02-21 19:40:17 +00:00
|
|
|
scale_factor = av_clip_intp2((tb * tx + 32) >> 6, 12);
|
2014-04-26 13:35:23 +00:00
|
|
|
dst->x = av_clip_int16((scale_factor * src->x + 127 +
|
|
|
|
(scale_factor * src->x < 0)) >> 8);
|
|
|
|
dst->y = av_clip_int16((scale_factor * src->y + 127 +
|
|
|
|
(scale_factor * src->y < 0)) >> 8);
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int check_mvset(Mv *mvLXCol, Mv *mvCol,
|
|
|
|
int colPic, int poc,
|
|
|
|
RefPicList *refPicList, int X, int refIdxLx,
|
|
|
|
RefPicList *refPicList_col, int listCol, int refidxCol)
|
|
|
|
{
|
|
|
|
int cur_lt = refPicList[X].isLongTerm[refIdxLx];
|
|
|
|
int col_lt = refPicList_col[listCol].isLongTerm[refidxCol];
|
|
|
|
int col_poc_diff, cur_poc_diff;
|
|
|
|
|
|
|
|
if (cur_lt != col_lt) {
|
|
|
|
mvLXCol->x = 0;
|
|
|
|
mvLXCol->y = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
col_poc_diff = colPic - refPicList_col[listCol].list[refidxCol];
|
|
|
|
cur_poc_diff = poc - refPicList[X].list[refIdxLx];
|
|
|
|
|
2014-04-26 13:35:23 +00:00
|
|
|
if (cur_lt || col_poc_diff == cur_poc_diff || !col_poc_diff) {
|
2013-10-12 09:55:48 +00:00
|
|
|
mvLXCol->x = mvCol->x;
|
|
|
|
mvLXCol->y = mvCol->y;
|
|
|
|
} else {
|
|
|
|
mv_scale(mvLXCol, mvCol, col_poc_diff, cur_poc_diff);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-11-01 23:31:49 +00:00
|
|
|
#define CHECK_MVSET(l) \
|
|
|
|
check_mvset(mvLXCol, temp_col.mv + l, \
|
|
|
|
colPic, s->poc, \
|
|
|
|
refPicList, X, refIdxLx, \
|
|
|
|
refPicList_col, L ## l, temp_col.ref_idx[l])
|
2013-10-12 09:55:48 +00:00
|
|
|
|
|
|
|
// derive the motion vectors section 8.5.3.1.8
|
|
|
|
static int derive_temporal_colocated_mvs(HEVCContext *s, MvField temp_col,
|
2013-11-01 23:31:49 +00:00
|
|
|
int refIdxLx, Mv *mvLXCol, int X,
|
|
|
|
int colPic, RefPicList *refPicList_col)
|
2013-10-12 09:55:48 +00:00
|
|
|
{
|
|
|
|
RefPicList *refPicList = s->ref->refPicList;
|
|
|
|
|
2014-04-26 13:35:23 +00:00
|
|
|
if (temp_col.pred_flag == PF_INTRA)
|
2013-10-12 09:55:48 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-04-26 13:35:23 +00:00
|
|
|
if (!(temp_col.pred_flag & PF_L0))
|
2013-10-12 09:55:48 +00:00
|
|
|
return CHECK_MVSET(1);
|
2014-04-26 13:35:23 +00:00
|
|
|
else if (temp_col.pred_flag == PF_L0)
|
2013-10-12 09:55:48 +00:00
|
|
|
return CHECK_MVSET(0);
|
2014-04-26 13:35:23 +00:00
|
|
|
else if (temp_col.pred_flag == PF_BI) {
|
2013-10-12 09:55:48 +00:00
|
|
|
int check_diffpicount = 0;
|
2014-07-18 22:51:42 +00:00
|
|
|
int i, j;
|
|
|
|
for (j = 0; j < 2; j++) {
|
|
|
|
for (i = 0; i < refPicList[j].nb_refs; i++) {
|
|
|
|
if (refPicList[j].list[i] > s->poc) {
|
|
|
|
check_diffpicount++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
2014-07-18 22:51:42 +00:00
|
|
|
if (!check_diffpicount) {
|
|
|
|
if (X==0)
|
|
|
|
return CHECK_MVSET(0);
|
|
|
|
else
|
|
|
|
return CHECK_MVSET(1);
|
|
|
|
} else {
|
2013-10-12 09:55:48 +00:00
|
|
|
if (s->sh.collocated_list == L1)
|
|
|
|
return CHECK_MVSET(0);
|
|
|
|
else
|
|
|
|
return CHECK_MVSET(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-01 23:31:49 +00:00
|
|
|
#define TAB_MVF(x, y) \
|
2013-10-27 11:56:48 +00:00
|
|
|
tab_mvf[(y) * min_pu_width + x]
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2013-11-01 23:31:49 +00:00
|
|
|
#define TAB_MVF_PU(v) \
|
2015-07-12 20:06:21 +00:00
|
|
|
TAB_MVF(((x ## v) >> s->ps.sps->log2_min_pu_size), \
|
|
|
|
((y ## v) >> s->ps.sps->log2_min_pu_size))
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2013-11-01 23:31:49 +00:00
|
|
|
#define DERIVE_TEMPORAL_COLOCATED_MVS \
|
|
|
|
derive_temporal_colocated_mvs(s, temp_col, \
|
|
|
|
refIdxLx, mvLXCol, X, colPic, \
|
2013-10-27 15:50:20 +00:00
|
|
|
ff_hevc_get_ref_list(s, ref, x, y))
|
2013-10-12 09:55:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 8.5.3.1.7 temporal luma motion vector prediction
|
|
|
|
*/
|
|
|
|
static int temporal_luma_motion_vector(HEVCContext *s, int x0, int y0,
|
|
|
|
int nPbW, int nPbH, int refIdxLx,
|
2013-11-01 23:31:49 +00:00
|
|
|
Mv *mvLXCol, int X)
|
2013-10-12 09:55:48 +00:00
|
|
|
{
|
|
|
|
MvField *tab_mvf;
|
|
|
|
MvField temp_col;
|
2013-11-02 10:59:02 +00:00
|
|
|
int x, y, x_pu, y_pu;
|
2015-07-09 12:22:43 +00:00
|
|
|
int min_pu_width = s->ps.sps->min_pu_width;
|
2013-10-12 09:55:48 +00:00
|
|
|
int availableFlagLXCol = 0;
|
|
|
|
int colPic;
|
|
|
|
|
|
|
|
HEVCFrame *ref = s->ref->collocated_ref;
|
|
|
|
|
2014-09-29 16:16:50 +00:00
|
|
|
if (!ref) {
|
|
|
|
memset(mvLXCol, 0, sizeof(*mvLXCol));
|
2013-10-12 09:55:48 +00:00
|
|
|
return 0;
|
2014-09-29 16:16:50 +00:00
|
|
|
}
|
2013-10-12 09:55:48 +00:00
|
|
|
|
|
|
|
tab_mvf = ref->tab_mvf;
|
|
|
|
colPic = ref->poc;
|
|
|
|
|
|
|
|
//bottom right collocated motion vector
|
2013-10-27 15:50:20 +00:00
|
|
|
x = x0 + nPbW;
|
|
|
|
y = y0 + nPbH;
|
2013-10-12 09:55:48 +00:00
|
|
|
|
|
|
|
if (tab_mvf &&
|
2015-07-09 12:22:43 +00:00
|
|
|
(y0 >> s->ps.sps->log2_ctb_size) == (y >> s->ps.sps->log2_ctb_size) &&
|
|
|
|
y < s->ps.sps->height &&
|
|
|
|
x < s->ps.sps->width) {
|
2014-07-10 06:47:55 +00:00
|
|
|
x &= ~15;
|
|
|
|
y &= ~15;
|
2014-07-20 07:34:58 +00:00
|
|
|
if (s->threads_type == FF_THREAD_FRAME)
|
|
|
|
ff_thread_await_progress(&ref->tf, y, 0);
|
2015-07-09 12:22:43 +00:00
|
|
|
x_pu = x >> s->ps.sps->log2_min_pu_size;
|
|
|
|
y_pu = y >> s->ps.sps->log2_min_pu_size;
|
2013-11-01 23:31:49 +00:00
|
|
|
temp_col = TAB_MVF(x_pu, y_pu);
|
2013-10-27 15:50:20 +00:00
|
|
|
availableFlagLXCol = DERIVE_TEMPORAL_COLOCATED_MVS;
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// derive center collocated motion vector
|
2013-10-27 15:50:20 +00:00
|
|
|
if (tab_mvf && !availableFlagLXCol) {
|
2013-11-01 23:31:49 +00:00
|
|
|
x = x0 + (nPbW >> 1);
|
|
|
|
y = y0 + (nPbH >> 1);
|
2014-07-10 06:47:55 +00:00
|
|
|
x &= ~15;
|
|
|
|
y &= ~15;
|
2014-07-20 07:34:58 +00:00
|
|
|
if (s->threads_type == FF_THREAD_FRAME)
|
|
|
|
ff_thread_await_progress(&ref->tf, y, 0);
|
2015-07-09 12:22:43 +00:00
|
|
|
x_pu = x >> s->ps.sps->log2_min_pu_size;
|
|
|
|
y_pu = y >> s->ps.sps->log2_min_pu_size;
|
2013-11-01 23:31:49 +00:00
|
|
|
temp_col = TAB_MVF(x_pu, y_pu);
|
2013-10-27 15:50:20 +00:00
|
|
|
availableFlagLXCol = DERIVE_TEMPORAL_COLOCATED_MVS;
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
return availableFlagLXCol;
|
|
|
|
}
|
|
|
|
|
2013-11-01 23:31:49 +00:00
|
|
|
#define AVAILABLE(cand, v) \
|
2014-04-26 13:35:23 +00:00
|
|
|
(cand && !(TAB_MVF_PU(v).pred_flag == PF_INTRA))
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2013-11-01 23:31:49 +00:00
|
|
|
#define PRED_BLOCK_AVAILABLE(v) \
|
2014-07-18 23:03:20 +00:00
|
|
|
z_scan_block_avail(s, x0, y0, x ## v, y ## v)
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2013-11-01 23:31:49 +00:00
|
|
|
#define COMPARE_MV_REFIDX(a, b) \
|
2014-07-18 23:39:09 +00:00
|
|
|
compare_mv_ref_idx(TAB_MVF_PU(a), TAB_MVF_PU(b))
|
2013-10-12 09:55:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 8.5.3.1.2 Derivation process for spatial merging candidates
|
|
|
|
*/
|
|
|
|
static void derive_spatial_merge_candidates(HEVCContext *s, int x0, int y0,
|
2013-11-01 23:31:49 +00:00
|
|
|
int nPbW, int nPbH,
|
|
|
|
int log2_cb_size,
|
2013-10-12 09:55:48 +00:00
|
|
|
int singleMCLFlag, int part_idx,
|
2014-07-10 06:47:52 +00:00
|
|
|
int merge_idx,
|
2013-10-12 09:55:48 +00:00
|
|
|
struct MvField mergecandlist[])
|
|
|
|
{
|
2013-10-27 15:50:20 +00:00
|
|
|
HEVCLocalContext *lc = s->HEVClc;
|
2013-10-12 09:55:48 +00:00
|
|
|
RefPicList *refPicList = s->ref->refPicList;
|
2013-10-27 15:50:20 +00:00
|
|
|
MvField *tab_mvf = s->ref->tab_mvf;
|
|
|
|
|
2015-07-09 12:22:43 +00:00
|
|
|
const int min_pu_width = s->ps.sps->min_pu_width;
|
2013-10-27 15:50:20 +00:00
|
|
|
|
|
|
|
const int cand_bottom_left = lc->na.cand_bottom_left;
|
|
|
|
const int cand_left = lc->na.cand_left;
|
|
|
|
const int cand_up_left = lc->na.cand_up_left;
|
|
|
|
const int cand_up = lc->na.cand_up;
|
|
|
|
const int cand_up_right = lc->na.cand_up_right_sap;
|
|
|
|
|
|
|
|
const int xA1 = x0 - 1;
|
|
|
|
const int yA1 = y0 + nPbH - 1;
|
|
|
|
|
|
|
|
const int xB1 = x0 + nPbW - 1;
|
|
|
|
const int yB1 = y0 - 1;
|
|
|
|
|
|
|
|
const int xB0 = x0 + nPbW;
|
|
|
|
const int yB0 = y0 - 1;
|
|
|
|
|
|
|
|
const int xA0 = x0 - 1;
|
|
|
|
const int yA0 = y0 + nPbH;
|
|
|
|
|
|
|
|
const int xB2 = x0 - 1;
|
|
|
|
const int yB2 = y0 - 1;
|
|
|
|
|
2016-10-18 19:14:18 +00:00
|
|
|
const int nb_refs = (s->sh.slice_type == HEVC_SLICE_P) ?
|
2013-10-27 15:50:20 +00:00
|
|
|
s->sh.nb_refs[0] : FFMIN(s->sh.nb_refs[0], s->sh.nb_refs[1]);
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2013-10-27 15:50:20 +00:00
|
|
|
int zero_idx = 0;
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2013-10-27 15:50:20 +00:00
|
|
|
int nb_merge_cand = 0;
|
|
|
|
int nb_orig_merge_cand = 0;
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2013-10-27 15:50:20 +00:00
|
|
|
int is_available_a0;
|
|
|
|
int is_available_a1;
|
|
|
|
int is_available_b0;
|
2013-10-12 09:55:48 +00:00
|
|
|
int is_available_b1;
|
2013-10-27 15:50:20 +00:00
|
|
|
int is_available_b2;
|
2013-10-12 09:55:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (!singleMCLFlag && part_idx == 1 &&
|
|
|
|
(lc->cu.part_mode == PART_Nx2N ||
|
|
|
|
lc->cu.part_mode == PART_nLx2N ||
|
|
|
|
lc->cu.part_mode == PART_nRx2N) ||
|
2014-07-18 23:39:09 +00:00
|
|
|
is_diff_mer(s, xA1, yA1, x0, y0)) {
|
2013-10-12 09:55:48 +00:00
|
|
|
is_available_a1 = 0;
|
2014-07-18 23:12:24 +00:00
|
|
|
} else {
|
|
|
|
is_available_a1 = AVAILABLE(cand_left, A1);
|
|
|
|
if (is_available_a1) {
|
|
|
|
mergecandlist[nb_merge_cand] = TAB_MVF_PU(A1);
|
2014-08-12 14:27:17 +00:00
|
|
|
if (merge_idx == 0)
|
|
|
|
return;
|
2014-07-18 23:12:24 +00:00
|
|
|
nb_merge_cand++;
|
|
|
|
}
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!singleMCLFlag && part_idx == 1 &&
|
|
|
|
(lc->cu.part_mode == PART_2NxN ||
|
|
|
|
lc->cu.part_mode == PART_2NxnU ||
|
|
|
|
lc->cu.part_mode == PART_2NxnD) ||
|
2014-07-18 23:39:09 +00:00
|
|
|
is_diff_mer(s, xB1, yB1, x0, y0)) {
|
2013-10-12 09:55:48 +00:00
|
|
|
is_available_b1 = 0;
|
2014-07-18 23:12:24 +00:00
|
|
|
} else {
|
|
|
|
is_available_b1 = AVAILABLE(cand_up, B1);
|
|
|
|
if (is_available_b1 &&
|
|
|
|
!(is_available_a1 && COMPARE_MV_REFIDX(B1, A1))) {
|
|
|
|
mergecandlist[nb_merge_cand] = TAB_MVF_PU(B1);
|
2014-08-12 14:27:17 +00:00
|
|
|
if (merge_idx == nb_merge_cand)
|
|
|
|
return;
|
2014-07-18 23:12:24 +00:00
|
|
|
nb_merge_cand++;
|
|
|
|
}
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// above right spatial merge candidate
|
2014-07-18 23:03:20 +00:00
|
|
|
is_available_b0 = AVAILABLE(cand_up_right, B0) &&
|
2015-07-12 20:06:21 +00:00
|
|
|
xB0 < s->ps.sps->width &&
|
2014-07-18 23:12:24 +00:00
|
|
|
PRED_BLOCK_AVAILABLE(B0) &&
|
2014-07-18 23:39:09 +00:00
|
|
|
!is_diff_mer(s, xB0, yB0, x0, y0);
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2014-07-18 23:12:24 +00:00
|
|
|
if (is_available_b0 &&
|
|
|
|
!(is_available_b1 && COMPARE_MV_REFIDX(B0, B1))) {
|
2014-07-10 06:47:52 +00:00
|
|
|
mergecandlist[nb_merge_cand] = TAB_MVF_PU(B0);
|
2014-08-08 18:21:01 +00:00
|
|
|
if (merge_idx == nb_merge_cand)
|
|
|
|
return;
|
2014-07-10 06:47:52 +00:00
|
|
|
nb_merge_cand++;
|
|
|
|
}
|
2013-10-12 09:55:48 +00:00
|
|
|
|
|
|
|
// left bottom spatial merge candidate
|
2014-07-18 23:03:20 +00:00
|
|
|
is_available_a0 = AVAILABLE(cand_bottom_left, A0) &&
|
2015-07-12 20:06:21 +00:00
|
|
|
yA0 < s->ps.sps->height &&
|
2014-07-18 23:12:24 +00:00
|
|
|
PRED_BLOCK_AVAILABLE(A0) &&
|
2014-07-18 23:39:09 +00:00
|
|
|
!is_diff_mer(s, xA0, yA0, x0, y0);
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2014-07-18 23:12:24 +00:00
|
|
|
if (is_available_a0 &&
|
|
|
|
!(is_available_a1 && COMPARE_MV_REFIDX(A0, A1))) {
|
2014-07-10 06:47:52 +00:00
|
|
|
mergecandlist[nb_merge_cand] = TAB_MVF_PU(A0);
|
2014-08-08 18:21:01 +00:00
|
|
|
if (merge_idx == nb_merge_cand)
|
|
|
|
return;
|
2014-07-10 06:47:52 +00:00
|
|
|
nb_merge_cand++;
|
|
|
|
}
|
2013-10-12 09:55:48 +00:00
|
|
|
|
|
|
|
// above left spatial merge candidate
|
2014-07-18 23:12:24 +00:00
|
|
|
is_available_b2 = AVAILABLE(cand_up_left, B2) &&
|
2014-07-18 23:39:09 +00:00
|
|
|
!is_diff_mer(s, xB2, yB2, x0, y0);
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2014-07-18 23:12:24 +00:00
|
|
|
if (is_available_b2 &&
|
|
|
|
!(is_available_a1 && COMPARE_MV_REFIDX(B2, A1)) &&
|
|
|
|
!(is_available_b1 && COMPARE_MV_REFIDX(B2, B1)) &&
|
|
|
|
nb_merge_cand != 4) {
|
2014-07-10 06:47:52 +00:00
|
|
|
mergecandlist[nb_merge_cand] = TAB_MVF_PU(B2);
|
2014-08-08 18:21:01 +00:00
|
|
|
if (merge_idx == nb_merge_cand)
|
|
|
|
return;
|
2014-07-10 06:47:52 +00:00
|
|
|
nb_merge_cand++;
|
|
|
|
}
|
2013-10-12 09:55:48 +00:00
|
|
|
|
|
|
|
// temporal motion vector candidate
|
2013-10-27 15:50:20 +00:00
|
|
|
if (s->sh.slice_temporal_mvp_enabled_flag &&
|
|
|
|
nb_merge_cand < s->sh.max_num_merge_cand) {
|
2014-11-09 07:48:39 +00:00
|
|
|
Mv mv_l0_col = { 0 }, mv_l1_col = { 0 };
|
2013-10-27 15:50:20 +00:00
|
|
|
int available_l0 = temporal_luma_motion_vector(s, x0, y0, nPbW, nPbH,
|
|
|
|
0, &mv_l0_col, 0);
|
2016-10-18 19:14:18 +00:00
|
|
|
int available_l1 = (s->sh.slice_type == HEVC_SLICE_B) ?
|
2013-10-27 15:50:20 +00:00
|
|
|
temporal_luma_motion_vector(s, x0, y0, nPbW, nPbH,
|
|
|
|
0, &mv_l1_col, 1) : 0;
|
|
|
|
|
|
|
|
if (available_l0 || available_l1) {
|
2014-04-26 13:35:23 +00:00
|
|
|
mergecandlist[nb_merge_cand].pred_flag = available_l0 + (available_l1 << 1);
|
2014-09-29 16:25:14 +00:00
|
|
|
AV_ZERO16(mergecandlist[nb_merge_cand].ref_idx);
|
|
|
|
mergecandlist[nb_merge_cand].mv[0] = mv_l0_col;
|
|
|
|
mergecandlist[nb_merge_cand].mv[1] = mv_l1_col;
|
|
|
|
|
2014-08-08 18:21:01 +00:00
|
|
|
if (merge_idx == nb_merge_cand)
|
|
|
|
return;
|
2013-10-27 15:50:20 +00:00
|
|
|
nb_merge_cand++;
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-27 15:50:20 +00:00
|
|
|
nb_orig_merge_cand = nb_merge_cand;
|
2013-10-12 09:55:48 +00:00
|
|
|
|
|
|
|
// combined bi-predictive merge candidates (applies for B slices)
|
2016-10-18 19:14:18 +00:00
|
|
|
if (s->sh.slice_type == HEVC_SLICE_B && nb_orig_merge_cand > 1 &&
|
2013-10-27 15:50:20 +00:00
|
|
|
nb_orig_merge_cand < s->sh.max_num_merge_cand) {
|
|
|
|
int comb_idx = 0;
|
|
|
|
|
|
|
|
for (comb_idx = 0; nb_merge_cand < s->sh.max_num_merge_cand &&
|
|
|
|
comb_idx < nb_orig_merge_cand * (nb_orig_merge_cand - 1); comb_idx++) {
|
|
|
|
int l0_cand_idx = l0_l1_cand_idx[comb_idx][0];
|
|
|
|
int l1_cand_idx = l0_l1_cand_idx[comb_idx][1];
|
|
|
|
MvField l0_cand = mergecandlist[l0_cand_idx];
|
|
|
|
MvField l1_cand = mergecandlist[l1_cand_idx];
|
|
|
|
|
2014-04-26 13:35:23 +00:00
|
|
|
if ((l0_cand.pred_flag & PF_L0) && (l1_cand.pred_flag & PF_L1) &&
|
2013-10-27 15:50:20 +00:00
|
|
|
(refPicList[0].list[l0_cand.ref_idx[0]] !=
|
|
|
|
refPicList[1].list[l1_cand.ref_idx[1]] ||
|
2014-07-12 14:51:09 +00:00
|
|
|
AV_RN32A(&l0_cand.mv[0]) != AV_RN32A(&l1_cand.mv[1]))) {
|
2013-10-27 15:50:20 +00:00
|
|
|
mergecandlist[nb_merge_cand].ref_idx[0] = l0_cand.ref_idx[0];
|
|
|
|
mergecandlist[nb_merge_cand].ref_idx[1] = l1_cand.ref_idx[1];
|
2014-04-26 13:35:23 +00:00
|
|
|
mergecandlist[nb_merge_cand].pred_flag = PF_BI;
|
2014-07-12 14:51:09 +00:00
|
|
|
AV_COPY32(&mergecandlist[nb_merge_cand].mv[0], &l0_cand.mv[0]);
|
|
|
|
AV_COPY32(&mergecandlist[nb_merge_cand].mv[1], &l1_cand.mv[1]);
|
2014-08-08 18:21:01 +00:00
|
|
|
if (merge_idx == nb_merge_cand)
|
|
|
|
return;
|
2013-10-27 15:50:20 +00:00
|
|
|
nb_merge_cand++;
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-27 15:50:20 +00:00
|
|
|
// append Zero motion vector candidates
|
|
|
|
while (nb_merge_cand < s->sh.max_num_merge_cand) {
|
2017-03-23 23:02:11 +00:00
|
|
|
mergecandlist[nb_merge_cand].pred_flag = PF_L0 + ((s->sh.slice_type == HEVC_SLICE_B) << 1);
|
2014-08-08 18:21:02 +00:00
|
|
|
AV_ZERO32(mergecandlist[nb_merge_cand].mv + 0);
|
|
|
|
AV_ZERO32(mergecandlist[nb_merge_cand].mv + 1);
|
2013-11-02 10:59:02 +00:00
|
|
|
mergecandlist[nb_merge_cand].ref_idx[0] = zero_idx < nb_refs ? zero_idx : 0;
|
|
|
|
mergecandlist[nb_merge_cand].ref_idx[1] = zero_idx < nb_refs ? zero_idx : 0;
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2014-08-08 18:21:01 +00:00
|
|
|
if (merge_idx == nb_merge_cand)
|
|
|
|
return;
|
2013-10-27 15:50:20 +00:00
|
|
|
nb_merge_cand++;
|
|
|
|
zero_idx++;
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 8.5.3.1.1 Derivation process of luma Mvs for merge mode
|
|
|
|
*/
|
|
|
|
void ff_hevc_luma_mv_merge_mode(HEVCContext *s, int x0, int y0, int nPbW,
|
|
|
|
int nPbH, int log2_cb_size, int part_idx,
|
|
|
|
int merge_idx, MvField *mv)
|
|
|
|
{
|
|
|
|
int singleMCLFlag = 0;
|
|
|
|
int nCS = 1 << log2_cb_size;
|
2017-03-29 10:43:40 +00:00
|
|
|
MvField mergecand_list[MRG_MAX_NUM_CANDS];
|
2013-10-12 09:55:48 +00:00
|
|
|
int nPbW2 = nPbW;
|
|
|
|
int nPbH2 = nPbH;
|
2013-10-21 09:49:35 +00:00
|
|
|
HEVCLocalContext *lc = s->HEVClc;
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2015-07-09 12:22:43 +00:00
|
|
|
if (s->ps.pps->log2_parallel_merge_level > 2 && nCS == 8) {
|
2013-10-12 09:55:48 +00:00
|
|
|
singleMCLFlag = 1;
|
2013-11-01 23:31:49 +00:00
|
|
|
x0 = lc->cu.x;
|
|
|
|
y0 = lc->cu.y;
|
|
|
|
nPbW = nCS;
|
|
|
|
nPbH = nCS;
|
|
|
|
part_idx = 0;
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ff_hevc_set_neighbour_available(s, x0, y0, nPbW, nPbH);
|
|
|
|
derive_spatial_merge_candidates(s, x0, y0, nPbW, nPbH, log2_cb_size,
|
2014-07-10 06:47:52 +00:00
|
|
|
singleMCLFlag, part_idx,
|
|
|
|
merge_idx, mergecand_list);
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2014-04-26 13:35:23 +00:00
|
|
|
if (mergecand_list[merge_idx].pred_flag == PF_BI &&
|
2013-10-12 09:55:48 +00:00
|
|
|
(nPbW2 + nPbH2) == 12) {
|
2014-04-26 13:35:23 +00:00
|
|
|
mergecand_list[merge_idx].pred_flag = PF_L0;
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*mv = mergecand_list[merge_idx];
|
|
|
|
}
|
|
|
|
|
2013-11-01 23:31:49 +00:00
|
|
|
static av_always_inline void dist_scale(HEVCContext *s, Mv *mv,
|
2013-10-27 11:56:48 +00:00
|
|
|
int min_pu_width, int x, int y,
|
2013-10-12 09:55:48 +00:00
|
|
|
int elist, int ref_idx_curr, int ref_idx)
|
|
|
|
{
|
|
|
|
RefPicList *refPicList = s->ref->refPicList;
|
2013-11-01 23:31:49 +00:00
|
|
|
MvField *tab_mvf = s->ref->tab_mvf;
|
|
|
|
int ref_pic_elist = refPicList[elist].list[TAB_MVF(x, y).ref_idx[elist]];
|
|
|
|
int ref_pic_curr = refPicList[ref_idx_curr].list[ref_idx];
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2014-02-08 05:10:27 +00:00
|
|
|
if (ref_pic_elist != ref_pic_curr) {
|
|
|
|
int poc_diff = s->poc - ref_pic_elist;
|
|
|
|
if (!poc_diff)
|
|
|
|
poc_diff = 1;
|
|
|
|
mv_scale(mv, mv, poc_diff, s->poc - ref_pic_curr);
|
|
|
|
}
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mv_mp_mode_mx(HEVCContext *s, int x, int y, int pred_flag_index,
|
|
|
|
Mv *mv, int ref_idx_curr, int ref_idx)
|
|
|
|
{
|
|
|
|
MvField *tab_mvf = s->ref->tab_mvf;
|
2015-07-09 12:22:43 +00:00
|
|
|
int min_pu_width = s->ps.sps->min_pu_width;
|
2013-10-12 09:55:48 +00:00
|
|
|
|
|
|
|
RefPicList *refPicList = s->ref->refPicList;
|
|
|
|
|
2014-04-26 13:35:23 +00:00
|
|
|
if (((TAB_MVF(x, y).pred_flag) & (1 << pred_flag_index)) &&
|
2013-10-12 09:55:48 +00:00
|
|
|
refPicList[pred_flag_index].list[TAB_MVF(x, y).ref_idx[pred_flag_index]] == refPicList[ref_idx_curr].list[ref_idx]) {
|
|
|
|
*mv = TAB_MVF(x, y).mv[pred_flag_index];
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mv_mp_mode_mx_lt(HEVCContext *s, int x, int y, int pred_flag_index,
|
|
|
|
Mv *mv, int ref_idx_curr, int ref_idx)
|
|
|
|
{
|
|
|
|
MvField *tab_mvf = s->ref->tab_mvf;
|
2015-07-09 12:22:43 +00:00
|
|
|
int min_pu_width = s->ps.sps->min_pu_width;
|
2013-10-12 09:55:48 +00:00
|
|
|
|
|
|
|
RefPicList *refPicList = s->ref->refPicList;
|
|
|
|
|
2014-04-26 13:35:23 +00:00
|
|
|
if ((TAB_MVF(x, y).pred_flag) & (1 << pred_flag_index)) {
|
|
|
|
int currIsLongTerm = refPicList[ref_idx_curr].isLongTerm[ref_idx];
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2014-04-26 13:35:23 +00:00
|
|
|
int colIsLongTerm =
|
|
|
|
refPicList[pred_flag_index].isLongTerm[(TAB_MVF(x, y).ref_idx[pred_flag_index])];
|
|
|
|
|
|
|
|
if (colIsLongTerm == currIsLongTerm) {
|
|
|
|
*mv = TAB_MVF(x, y).mv[pred_flag_index];
|
|
|
|
if (!currIsLongTerm)
|
|
|
|
dist_scale(s, mv, min_pu_width, x, y,
|
|
|
|
pred_flag_index, ref_idx_curr, ref_idx);
|
|
|
|
return 1;
|
|
|
|
}
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-01 23:31:49 +00:00
|
|
|
#define MP_MX(v, pred, mx) \
|
2014-07-18 23:23:36 +00:00
|
|
|
mv_mp_mode_mx(s, \
|
2015-07-12 20:06:21 +00:00
|
|
|
(x ## v) >> s->ps.sps->log2_min_pu_size, \
|
|
|
|
(y ## v) >> s->ps.sps->log2_min_pu_size, \
|
2014-07-18 23:23:36 +00:00
|
|
|
pred, &mx, ref_idx_curr, ref_idx)
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2013-11-01 23:31:49 +00:00
|
|
|
#define MP_MX_LT(v, pred, mx) \
|
2014-07-18 23:23:36 +00:00
|
|
|
mv_mp_mode_mx_lt(s, \
|
2015-07-12 20:06:21 +00:00
|
|
|
(x ## v) >> s->ps.sps->log2_min_pu_size, \
|
|
|
|
(y ## v) >> s->ps.sps->log2_min_pu_size, \
|
2014-07-18 23:23:36 +00:00
|
|
|
pred, &mx, ref_idx_curr, ref_idx)
|
2013-10-12 09:55:48 +00:00
|
|
|
|
|
|
|
void ff_hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0, int nPbW,
|
|
|
|
int nPbH, int log2_cb_size, int part_idx,
|
|
|
|
int merge_idx, MvField *mv,
|
|
|
|
int mvp_lx_flag, int LX)
|
|
|
|
{
|
2013-10-21 09:49:35 +00:00
|
|
|
HEVCLocalContext *lc = s->HEVClc;
|
2013-10-12 09:55:48 +00:00
|
|
|
MvField *tab_mvf = s->ref->tab_mvf;
|
|
|
|
int isScaledFlag_L0 = 0;
|
2014-07-18 23:23:36 +00:00
|
|
|
int availableFlagLXA0 = 1;
|
|
|
|
int availableFlagLXB0 = 1;
|
2013-10-12 09:55:48 +00:00
|
|
|
int numMVPCandLX = 0;
|
2015-07-09 12:22:43 +00:00
|
|
|
int min_pu_width = s->ps.sps->min_pu_width;
|
2013-10-12 09:55:48 +00:00
|
|
|
|
|
|
|
int xA0, yA0;
|
|
|
|
int is_available_a0;
|
|
|
|
int xA1, yA1;
|
|
|
|
int is_available_a1;
|
|
|
|
int xB0, yB0;
|
|
|
|
int is_available_b0;
|
|
|
|
int xB1, yB1;
|
2014-07-18 23:23:36 +00:00
|
|
|
int is_available_b1;
|
2013-10-12 09:55:48 +00:00
|
|
|
int xB2, yB2;
|
2014-07-18 23:23:36 +00:00
|
|
|
int is_available_b2;
|
|
|
|
|
2013-10-12 09:55:48 +00:00
|
|
|
Mv mvpcand_list[2] = { { 0 } };
|
2014-04-26 13:35:23 +00:00
|
|
|
Mv mxA;
|
|
|
|
Mv mxB;
|
2014-08-15 22:47:45 +00:00
|
|
|
int ref_idx_curr;
|
2013-10-12 09:55:48 +00:00
|
|
|
int ref_idx = 0;
|
|
|
|
int pred_flag_index_l0;
|
|
|
|
int pred_flag_index_l1;
|
|
|
|
|
2014-07-18 23:23:36 +00:00
|
|
|
const int cand_bottom_left = lc->na.cand_bottom_left;
|
|
|
|
const int cand_left = lc->na.cand_left;
|
|
|
|
const int cand_up_left = lc->na.cand_up_left;
|
|
|
|
const int cand_up = lc->na.cand_up;
|
|
|
|
const int cand_up_right = lc->na.cand_up_right_sap;
|
2013-10-12 09:55:48 +00:00
|
|
|
ref_idx_curr = LX;
|
|
|
|
ref_idx = mv->ref_idx[LX];
|
|
|
|
pred_flag_index_l0 = LX;
|
|
|
|
pred_flag_index_l1 = !LX;
|
|
|
|
|
|
|
|
// left bottom spatial candidate
|
|
|
|
xA0 = x0 - 1;
|
|
|
|
yA0 = y0 + nPbH;
|
|
|
|
|
2014-07-18 23:03:20 +00:00
|
|
|
is_available_a0 = AVAILABLE(cand_bottom_left, A0) &&
|
2015-07-12 20:06:21 +00:00
|
|
|
yA0 < s->ps.sps->height &&
|
2014-07-18 23:03:20 +00:00
|
|
|
PRED_BLOCK_AVAILABLE(A0);
|
2013-10-12 09:55:48 +00:00
|
|
|
|
|
|
|
//left spatial merge candidate
|
2013-11-01 23:31:49 +00:00
|
|
|
xA1 = x0 - 1;
|
|
|
|
yA1 = y0 + nPbH - 1;
|
2013-10-12 09:55:48 +00:00
|
|
|
|
|
|
|
is_available_a1 = AVAILABLE(cand_left, A1);
|
2013-11-02 10:59:02 +00:00
|
|
|
if (is_available_a0 || is_available_a1)
|
2013-10-12 09:55:48 +00:00
|
|
|
isScaledFlag_L0 = 1;
|
|
|
|
|
|
|
|
if (is_available_a0) {
|
2014-07-18 23:23:36 +00:00
|
|
|
if (MP_MX(A0, pred_flag_index_l0, mxA)) {
|
|
|
|
goto b_candidates;
|
|
|
|
}
|
|
|
|
if (MP_MX(A0, pred_flag_index_l1, mxA)) {
|
|
|
|
goto b_candidates;
|
|
|
|
}
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
|
2014-07-18 23:23:36 +00:00
|
|
|
if (is_available_a1) {
|
|
|
|
if (MP_MX(A1, pred_flag_index_l0, mxA)) {
|
|
|
|
goto b_candidates;
|
|
|
|
}
|
|
|
|
if (MP_MX(A1, pred_flag_index_l1, mxA)) {
|
|
|
|
goto b_candidates;
|
|
|
|
}
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
|
2014-07-18 23:23:36 +00:00
|
|
|
if (is_available_a0) {
|
|
|
|
if (MP_MX_LT(A0, pred_flag_index_l0, mxA)) {
|
|
|
|
goto b_candidates;
|
|
|
|
}
|
|
|
|
if (MP_MX_LT(A0, pred_flag_index_l1, mxA)) {
|
|
|
|
goto b_candidates;
|
|
|
|
}
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
|
2014-07-18 23:23:36 +00:00
|
|
|
if (is_available_a1) {
|
|
|
|
if (MP_MX_LT(A1, pred_flag_index_l0, mxA)) {
|
|
|
|
goto b_candidates;
|
|
|
|
}
|
|
|
|
if (MP_MX_LT(A1, pred_flag_index_l1, mxA)) {
|
|
|
|
goto b_candidates;
|
|
|
|
}
|
2014-07-10 06:47:53 +00:00
|
|
|
}
|
2014-07-18 23:23:36 +00:00
|
|
|
availableFlagLXA0 = 0;
|
2014-07-10 06:47:53 +00:00
|
|
|
|
2014-07-18 23:23:36 +00:00
|
|
|
b_candidates:
|
2013-10-12 09:55:48 +00:00
|
|
|
// B candidates
|
|
|
|
// above right spatial merge candidate
|
2013-11-01 23:31:49 +00:00
|
|
|
xB0 = x0 + nPbW;
|
|
|
|
yB0 = y0 - 1;
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2014-07-18 23:23:36 +00:00
|
|
|
is_available_b0 = AVAILABLE(cand_up_right, B0) &&
|
2015-07-12 20:06:21 +00:00
|
|
|
xB0 < s->ps.sps->width &&
|
2014-07-18 23:23:36 +00:00
|
|
|
PRED_BLOCK_AVAILABLE(B0);
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2014-08-10 13:02:36 +00:00
|
|
|
// above spatial merge candidate
|
|
|
|
xB1 = x0 + nPbW - 1;
|
|
|
|
yB1 = y0 - 1;
|
|
|
|
is_available_b1 = AVAILABLE(cand_up, B1);
|
|
|
|
|
|
|
|
// above left spatial merge candidate
|
|
|
|
xB2 = x0 - 1;
|
|
|
|
yB2 = y0 - 1;
|
|
|
|
is_available_b2 = AVAILABLE(cand_up_left, B2);
|
|
|
|
|
|
|
|
// above right spatial merge candidate
|
2013-10-12 09:55:48 +00:00
|
|
|
if (is_available_b0) {
|
2014-07-18 23:23:36 +00:00
|
|
|
if (MP_MX(B0, pred_flag_index_l0, mxB)) {
|
|
|
|
goto scalef;
|
|
|
|
}
|
|
|
|
if (MP_MX(B0, pred_flag_index_l1, mxB)) {
|
|
|
|
goto scalef;
|
|
|
|
}
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
|
2014-07-18 23:23:36 +00:00
|
|
|
// above spatial merge candidate
|
|
|
|
if (is_available_b1) {
|
|
|
|
if (MP_MX(B1, pred_flag_index_l0, mxB)) {
|
|
|
|
goto scalef;
|
|
|
|
}
|
|
|
|
if (MP_MX(B1, pred_flag_index_l1, mxB)) {
|
|
|
|
goto scalef;
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-18 23:23:36 +00:00
|
|
|
// above left spatial merge candidate
|
|
|
|
if (is_available_b2) {
|
|
|
|
if (MP_MX(B2, pred_flag_index_l0, mxB)) {
|
|
|
|
goto scalef;
|
|
|
|
}
|
|
|
|
if (MP_MX(B2, pred_flag_index_l1, mxB)) {
|
|
|
|
goto scalef;
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-18 23:23:36 +00:00
|
|
|
availableFlagLXB0 = 0;
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2014-07-18 23:23:36 +00:00
|
|
|
scalef:
|
|
|
|
if (!isScaledFlag_L0) {
|
2013-10-12 09:55:48 +00:00
|
|
|
if (availableFlagLXB0) {
|
|
|
|
availableFlagLXA0 = 1;
|
|
|
|
mxA = mxB;
|
|
|
|
}
|
|
|
|
availableFlagLXB0 = 0;
|
|
|
|
|
|
|
|
// XB0 and L1
|
|
|
|
if (is_available_b0) {
|
|
|
|
availableFlagLXB0 = MP_MX_LT(B0, pred_flag_index_l0, mxB);
|
|
|
|
if (!availableFlagLXB0)
|
|
|
|
availableFlagLXB0 = MP_MX_LT(B0, pred_flag_index_l1, mxB);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_available_b1 && !availableFlagLXB0) {
|
|
|
|
availableFlagLXB0 = MP_MX_LT(B1, pred_flag_index_l0, mxB);
|
|
|
|
if (!availableFlagLXB0)
|
|
|
|
availableFlagLXB0 = MP_MX_LT(B1, pred_flag_index_l1, mxB);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_available_b2 && !availableFlagLXB0) {
|
|
|
|
availableFlagLXB0 = MP_MX_LT(B2, pred_flag_index_l0, mxB);
|
|
|
|
if (!availableFlagLXB0)
|
|
|
|
availableFlagLXB0 = MP_MX_LT(B2, pred_flag_index_l1, mxB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-27 15:50:20 +00:00
|
|
|
if (availableFlagLXA0)
|
|
|
|
mvpcand_list[numMVPCandLX++] = mxA;
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2013-10-27 15:50:20 +00:00
|
|
|
if (availableFlagLXB0 && (!availableFlagLXA0 || mxA.x != mxB.x || mxA.y != mxB.y))
|
|
|
|
mvpcand_list[numMVPCandLX++] = mxB;
|
2013-10-12 09:55:48 +00:00
|
|
|
|
2013-10-27 15:50:20 +00:00
|
|
|
//temporal motion vector prediction candidate
|
2014-07-23 16:27:44 +00:00
|
|
|
if (numMVPCandLX < 2 && s->sh.slice_temporal_mvp_enabled_flag &&
|
|
|
|
mvp_lx_flag == numMVPCandLX) {
|
2013-10-27 15:50:20 +00:00
|
|
|
Mv mv_col;
|
|
|
|
int available_col = temporal_luma_motion_vector(s, x0, y0, nPbW,
|
2013-11-01 23:31:49 +00:00
|
|
|
nPbH, ref_idx,
|
|
|
|
&mv_col, LX);
|
2013-10-27 15:50:20 +00:00
|
|
|
if (available_col)
|
|
|
|
mvpcand_list[numMVPCandLX++] = mv_col;
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|
|
|
|
|
2014-04-26 13:35:23 +00:00
|
|
|
mv->mv[LX] = mvpcand_list[mvp_lx_flag];
|
2013-10-12 09:55:48 +00:00
|
|
|
}
|