Commit 8781828b authored by Zoe Liu's avatar Zoe Liu

Unify binary symbol design for LAST/LAST2

Current encoding of single ref assigns bit 0 to LAST_FRAME and bit 1
to LAST2_frame, whereas the encoding of compound ref assigns bit 1 to
LAST_FRAME and bit 0 to LAST_FRAME. This patch unifies the design and
makes the binary symbol assignment for LAST/LAST2 consistent
regardless of the single/compound ref scenarios.

This patch incurs a small syntax change but should not have noticeable
coding performance impact. Once BUG 973 is fully addressed, default
cdfs for reference frame coding will be updated.

BUG=aomedia:973

Change-Id: I1f3027965c0bb2d343bc8ad873f7c0015123f151
parent 5568a01a
......@@ -602,10 +602,10 @@ int av1_get_pred_context_comp_ref_p1(const AV1_COMMON *cm,
const MB_MODE_INFO *edge_mbmi = above_intra ? left_mbmi : above_mbmi;
if (!has_second_ref(edge_mbmi)) // single pred (1/3)
pred_context = 1 + 2 * (edge_mbmi->ref_frame[0] != LAST_FRAME);
pred_context = 1 + 2 * (edge_mbmi->ref_frame[0] != LAST2_FRAME);
else // comp pred (1/3)
pred_context =
1 + 2 * (edge_mbmi->ref_frame[fwd_ref_sign_idx] != LAST_FRAME);
1 + 2 * (edge_mbmi->ref_frame[fwd_ref_sign_idx] != LAST2_FRAME);
} else { // inter/inter
const int l_sg = !has_second_ref(left_mbmi);
const int a_sg = !has_second_ref(above_mbmi);
......@@ -616,10 +616,10 @@ int av1_get_pred_context_comp_ref_p1(const AV1_COMMON *cm,
l_sg ? left_mbmi->ref_frame[0]
: left_mbmi->ref_frame[fwd_ref_sign_idx];
if (frfa == frfl && frfa == LAST_FRAME)
if (frfa == frfl && frfa == LAST2_FRAME)
pred_context = 0;
else if (l_sg && a_sg) { // single/single
if (frfa == LAST_FRAME || frfl == LAST_FRAME)
if (frfa == LAST2_FRAME || frfl == LAST2_FRAME)
pred_context = 1;
else if (CHECK_GOLDEN_OR_LAST3(frfa) || CHECK_GOLDEN_OR_LAST3(frfl))
pred_context = 2 + (frfa != frfl);
......@@ -632,15 +632,14 @@ int av1_get_pred_context_comp_ref_p1(const AV1_COMMON *cm,
const MV_REFERENCE_FRAME frfc = l_sg ? frfa : frfl;
const MV_REFERENCE_FRAME rfs = a_sg ? frfa : frfl;
if (frfc == LAST_FRAME && rfs != LAST_FRAME)
if (frfc == LAST2_FRAME && rfs != LAST2_FRAME)
pred_context = 1;
else if (rfs == LAST_FRAME && frfc != LAST_FRAME)
else if (rfs == LAST2_FRAME && frfc != LAST2_FRAME)
pred_context = 2;
else
pred_context =
3 + (frfc == LAST2_FRAME || CHECK_GOLDEN_OR_LAST3(rfs));
pred_context = 3 + (frfc == LAST_FRAME || CHECK_GOLDEN_OR_LAST3(rfs));
} else { // comp/comp
if (frfa == LAST_FRAME || frfl == LAST_FRAME)
if (frfa == LAST2_FRAME || frfl == LAST2_FRAME)
pred_context = 2;
else
pred_context =
......@@ -655,9 +654,9 @@ int av1_get_pred_context_comp_ref_p1(const AV1_COMMON *cm,
} else {
if (has_second_ref(edge_mbmi)) {
pred_context =
4 * (edge_mbmi->ref_frame[fwd_ref_sign_idx] != LAST_FRAME);
4 * (edge_mbmi->ref_frame[fwd_ref_sign_idx] != LAST2_FRAME);
} else {
if (edge_mbmi->ref_frame[0] == LAST_FRAME)
if (edge_mbmi->ref_frame[0] == LAST2_FRAME)
pred_context = 0;
else
pred_context = 2 + CHECK_GOLDEN_OR_LAST3(edge_mbmi->ref_frame[0]);
......
......@@ -1364,7 +1364,7 @@ static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd,
const int ctx1 = av1_get_pred_context_comp_ref_p1(cm, xd);
const int bit1 = READ_REF_BIT(comp_ref_p1);
if (counts) ++counts->comp_ref[ctx1][1][bit1];
ref_frame[!idx] = cm->comp_fwd_ref[bit1 ? 0 : 1];
ref_frame[!idx] = cm->comp_fwd_ref[bit1 ? 1 : 0];
} else {
const int ctx2 = av1_get_pred_context_comp_ref_p2(cm, xd);
const int bit2 = READ_REF_BIT(comp_ref_p2);
......
......@@ -745,7 +745,7 @@ static void write_ref_frames(const AV1_COMMON *cm, const MACROBLOCKD *xd,
WRITE_REF_BIT(bit, comp_ref_p);
if (!bit) {
const int bit1 = mbmi->ref_frame[0] == LAST_FRAME;
const int bit1 = mbmi->ref_frame[0] == LAST2_FRAME;
WRITE_REF_BIT(bit1, comp_ref_p1);
} else {
const int bit2 = mbmi->ref_frame[0] == GOLDEN_FRAME;
......
......@@ -1161,7 +1161,7 @@ static void update_stats(const AV1_COMMON *const cm, TileDataEnc *tile_data,
counts->comp_ref[av1_get_pred_context_comp_ref_p(cm, xd)][0][bit]++;
if (!bit) {
counts->comp_ref[av1_get_pred_context_comp_ref_p1(cm, xd)][1]
[ref0 == LAST_FRAME]++;
[ref0 == LAST2_FRAME]++;
} else {
counts->comp_ref[av1_get_pred_context_comp_ref_p2(cm, xd)][2]
[ref0 == GOLDEN_FRAME]++;
......
......@@ -6072,8 +6072,8 @@ static void estimate_ref_frame_costs(
ref_bicomp_costs[LAST3_FRAME] += av1_cost_bit(ref_comp_p, 1);
ref_bicomp_costs[GOLDEN_FRAME] += av1_cost_bit(ref_comp_p, 1);
ref_bicomp_costs[LAST_FRAME] += av1_cost_bit(ref_comp_p1, 1);
ref_bicomp_costs[LAST2_FRAME] += av1_cost_bit(ref_comp_p1, 0);
ref_bicomp_costs[LAST_FRAME] += av1_cost_bit(ref_comp_p1, 0);
ref_bicomp_costs[LAST2_FRAME] += av1_cost_bit(ref_comp_p1, 1);
ref_bicomp_costs[LAST3_FRAME] += av1_cost_bit(ref_comp_p2, 0);
ref_bicomp_costs[GOLDEN_FRAME] += av1_cost_bit(ref_comp_p2, 1);
......@@ -6127,8 +6127,8 @@ static void estimate_ref_frame_costs(
ref_costs_comp[LAST3_FRAME] += av1_cost_bit(ref_comp_p, 1);
ref_costs_comp[GOLDEN_FRAME] += av1_cost_bit(ref_comp_p, 1);
ref_costs_comp[LAST_FRAME] += av1_cost_bit(ref_comp_p1, 1);
ref_costs_comp[LAST2_FRAME] += av1_cost_bit(ref_comp_p1, 0);
ref_costs_comp[LAST_FRAME] += av1_cost_bit(ref_comp_p1, 0);
ref_costs_comp[LAST2_FRAME] += av1_cost_bit(ref_comp_p1, 1);
ref_costs_comp[LAST3_FRAME] += av1_cost_bit(ref_comp_p2, 0);
ref_costs_comp[GOLDEN_FRAME] += av1_cost_bit(ref_comp_p2, 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment