summaryrefslogtreecommitdiff
path: root/vp9/encoder
diff options
context:
space:
mode:
Diffstat (limited to 'vp9/encoder')
-rw-r--r--vp9/encoder/vp9_bitstream.c95
-rw-r--r--vp9/encoder/vp9_encodeframe.c6
-rw-r--r--vp9/encoder/vp9_encodemb.c9
-rw-r--r--vp9/encoder/vp9_rdopt.c66
-rw-r--r--vp9/encoder/vp9_tokenize.c59
5 files changed, 126 insertions, 109 deletions
diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c
index 7128b70c8..18fc45e7d 100644
--- a/vp9/encoder/vp9_bitstream.c
+++ b/vp9/encoder/vp9_bitstream.c
@@ -1087,14 +1087,18 @@ static void write_mb_modes_kf(const VP9_COMP *cpi,
}
#if CONFIG_CODE_NONZEROCOUNT
-static void write_nzc(VP9_COMMON *const cm,
+static void write_nzc(VP9_COMP *const cpi,
uint16_t nzc,
int nzc_context,
TX_SIZE tx_size,
int ref,
int type,
vp9_writer* const bc) {
+ VP9_COMMON *const cm = &cpi->common;
int c, e;
+ // if (!cpi->dummy_packing && cm->current_video_frame == 27)
+ // printf("nzc: %d, tx_size: %d\n", nzc, tx_size);
+ if (!get_nzc_used(tx_size)) return;
c = codenzc(nzc);
if (tx_size == TX_32X32) {
write_token(bc, vp9_nzc32x32_tree,
@@ -1152,44 +1156,44 @@ static void write_nzcs_sb64(VP9_COMP *cpi,
case TX_32X32:
for (j = 0; j < 256; j += 64) {
nzc_context = vp9_get_nzc_context_y_sb64(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_32X32, ref, 0, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_32X32, ref, 0, bc);
}
for (j = 256; j < 384; j += 64) {
nzc_context = vp9_get_nzc_context_uv_sb64(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_32X32, ref, 1, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_32X32, ref, 1, bc);
}
break;
case TX_16X16:
for (j = 0; j < 256; j += 16) {
nzc_context = vp9_get_nzc_context_y_sb64(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 0, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 0, bc);
}
for (j = 256; j < 384; j += 16) {
nzc_context = vp9_get_nzc_context_uv_sb64(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 1, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 1, bc);
}
break;
case TX_8X8:
for (j = 0; j < 256; j += 4) {
nzc_context = vp9_get_nzc_context_y_sb64(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 0, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 0, bc);
}
for (j = 256; j < 384; j += 4) {
nzc_context = vp9_get_nzc_context_uv_sb64(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 1, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 1, bc);
}
break;
case TX_4X4:
for (j = 0; j < 256; ++j) {
nzc_context = vp9_get_nzc_context_y_sb64(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 0, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 0, bc);
}
for (j = 256; j < 384; ++j) {
nzc_context = vp9_get_nzc_context_uv_sb64(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 1, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 1, bc);
}
break;
@@ -1219,44 +1223,44 @@ static void write_nzcs_sb32(VP9_COMP *cpi,
case TX_32X32:
for (j = 0; j < 64; j += 64) {
nzc_context = vp9_get_nzc_context_y_sb32(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_32X32, ref, 0, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_32X32, ref, 0, bc);
}
for (j = 64; j < 96; j += 16) {
nzc_context = vp9_get_nzc_context_uv_sb32(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 1, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 1, bc);
}
break;
case TX_16X16:
for (j = 0; j < 64; j += 16) {
nzc_context = vp9_get_nzc_context_y_sb32(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 0, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 0, bc);
}
for (j = 64; j < 96; j += 16) {
nzc_context = vp9_get_nzc_context_uv_sb32(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 1, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 1, bc);
}
break;
case TX_8X8:
for (j = 0; j < 64; j += 4) {
nzc_context = vp9_get_nzc_context_y_sb32(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 0, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 0, bc);
}
for (j = 64; j < 96; j += 4) {
nzc_context = vp9_get_nzc_context_uv_sb32(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 1, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 1, bc);
}
break;
case TX_4X4:
for (j = 0; j < 64; ++j) {
nzc_context = vp9_get_nzc_context_y_sb32(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 0, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 0, bc);
}
for (j = 64; j < 96; ++j) {
nzc_context = vp9_get_nzc_context_uv_sb32(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 1, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 1, bc);
}
break;
@@ -1286,28 +1290,28 @@ static void write_nzcs_mb16(VP9_COMP *cpi,
case TX_16X16:
for (j = 0; j < 16; j += 16) {
nzc_context = vp9_get_nzc_context_y_mb16(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 0, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_16X16, ref, 0, bc);
}
for (j = 16; j < 24; j += 4) {
nzc_context = vp9_get_nzc_context_uv_mb16(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 1, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 1, bc);
}
break;
case TX_8X8:
for (j = 0; j < 16; j += 4) {
nzc_context = vp9_get_nzc_context_y_mb16(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 0, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 0, bc);
}
if (mi->mode == I8X8_PRED || mi->mode == SPLITMV) {
for (j = 16; j < 24; ++j) {
nzc_context = vp9_get_nzc_context_uv_mb16(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 1, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 1, bc);
}
} else {
for (j = 16; j < 24; j += 4) {
nzc_context = vp9_get_nzc_context_uv_mb16(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 1, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_8X8, ref, 1, bc);
}
}
break;
@@ -1315,11 +1319,11 @@ static void write_nzcs_mb16(VP9_COMP *cpi,
case TX_4X4:
for (j = 0; j < 16; ++j) {
nzc_context = vp9_get_nzc_context_y_mb16(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 0, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 0, bc);
}
for (j = 16; j < 24; ++j) {
nzc_context = vp9_get_nzc_context_uv_mb16(cm, m, mb_row, mb_col, j);
- write_nzc(cm, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 1, bc);
+ write_nzc(cpi, m->mbmi.nzcs[j], nzc_context, TX_4X4, ref, 1, bc);
}
break;
@@ -1838,7 +1842,7 @@ static void build_coeff_contexts(VP9_COMP *cpi) {
#if CONFIG_CODE_NONZEROCOUNT
static void update_nzc_probs_common(VP9_COMP* cpi,
vp9_writer* const bc,
- int block_size) {
+ TX_SIZE tx_size) {
VP9_COMMON *cm = &cpi->common;
int c, r, b, t;
int update[2] = {0, 0};
@@ -1851,7 +1855,8 @@ static void update_nzc_probs_common(VP9_COMP* cpi,
unsigned int (*nzc_branch_ct)[2];
vp9_prob upd;
- if (block_size == 32) {
+ if (!get_nzc_used(tx_size)) return;
+ if (tx_size == TX_32X32) {
tokens = NZC32X32_TOKENS;
nzc_tree = vp9_nzc32x32_tree;
old_nzc_probs = cm->fc.nzc_probs_32x32[0][0][0];
@@ -1859,7 +1864,7 @@ static void update_nzc_probs_common(VP9_COMP* cpi,
nzc_counts = cm->fc.nzc_counts_32x32[0][0][0];
nzc_branch_ct = cpi->frame_nzc_branch_ct_32x32[0][0][0];
upd = NZC_UPDATE_PROB_32X32;
- } else if (block_size == 16) {
+ } else if (tx_size == TX_16X16) {
tokens = NZC16X16_TOKENS;
nzc_tree = vp9_nzc16x16_tree;
old_nzc_probs = cm->fc.nzc_probs_16x16[0][0][0];
@@ -1867,7 +1872,7 @@ static void update_nzc_probs_common(VP9_COMP* cpi,
nzc_counts = cm->fc.nzc_counts_16x16[0][0][0];
nzc_branch_ct = cpi->frame_nzc_branch_ct_16x16[0][0][0];
upd = NZC_UPDATE_PROB_16X16;
- } else if (block_size == 8) {
+ } else if (tx_size == TX_8X8) {
tokens = NZC8X8_TOKENS;
nzc_tree = vp9_nzc8x8_tree;
old_nzc_probs = cm->fc.nzc_probs_8x8[0][0][0];
@@ -1974,6 +1979,9 @@ static void update_nzc_pcat_probs(VP9_COMP *cpi, vp9_writer* const bc) {
int update[2] = {0, 0};
int savings = 0;
vp9_prob upd = NZC_UPDATE_PROB_PCAT;
+ if (!(get_nzc_used(TX_4X4) || get_nzc_used(TX_8X8) ||
+ get_nzc_used(TX_16X16) || get_nzc_used(TX_32X32)))
+ return;
for (c = 0; c < MAX_NZC_CONTEXTS; ++c) {
for (t = 0; t < NZC_TOKENS_EXTRA; ++t) {
int bits = vp9_extranzcbits[t + NZC_TOKENS_NOEXTRA];
@@ -2040,13 +2048,13 @@ static void update_nzc_pcat_probs(VP9_COMP *cpi, vp9_writer* const bc) {
static void update_nzc_probs(VP9_COMP* cpi,
vp9_writer* const bc) {
- update_nzc_probs_common(cpi, bc, 4);
+ update_nzc_probs_common(cpi, bc, TX_4X4);
if (cpi->common.txfm_mode != ONLY_4X4)
- update_nzc_probs_common(cpi, bc, 8);
+ update_nzc_probs_common(cpi, bc, TX_8X8);
if (cpi->common.txfm_mode > ALLOW_8X8)
- update_nzc_probs_common(cpi, bc, 16);
+ update_nzc_probs_common(cpi, bc, TX_16X16);
if (cpi->common.txfm_mode > ALLOW_16X16)
- update_nzc_probs_common(cpi, bc, 32);
+ update_nzc_probs_common(cpi, bc, TX_32X32);
#ifdef NZC_PCAT_UPDATE
update_nzc_pcat_probs(cpi, bc);
#endif
@@ -2065,7 +2073,7 @@ static void update_coef_probs_common(vp9_writer* const bc,
vp9_coeff_probs *new_frame_coef_probs,
vp9_coeff_probs *old_frame_coef_probs,
vp9_coeff_stats *frame_branch_ct,
- int block_types) {
+ TX_SIZE tx_size) {
int i, j, k, l, t;
int update[2] = {0, 0};
int savings;
@@ -2076,14 +2084,19 @@ static void update_coef_probs_common(vp9_writer* const bc,
#endif
// vp9_prob bestupd = find_coef_update_prob(cpi);
+#if CONFIG_CODE_NONZEROCOUNT
+ const int tstart = get_nzc_used(tx_size);
+#else
+ const int tstart = 0;
+#endif
/* dry run to see if there is any udpate at all needed */
savings = 0;
- for (i = 0; i < block_types; ++i) {
+ for (i = 0; i < BLOCK_TYPES; ++i) {
for (j = 0; j < REF_TYPES; ++j) {
for (k = 0; k < COEF_BANDS; ++k) {
// int prev_coef_savings[ENTROPY_NODES] = {0};
for (l = 0; l < PREV_COEF_CONTEXTS; ++l) {
- for (t = CONFIG_CODE_NONZEROCOUNT; t < entropy_nodes_update; ++t) {
+ for (t = tstart; t < entropy_nodes_update; ++t) {
vp9_prob newp = new_frame_coef_probs[i][j][k][l][t];
const vp9_prob oldp = old_frame_coef_probs[i][j][k][l][t];
const vp9_prob upd = vp9_coef_update_prob[t];
@@ -2131,13 +2144,13 @@ static void update_coef_probs_common(vp9_writer* const bc,
return;
}
vp9_write_bit(bc, 1);
- for (i = 0; i < block_types; ++i) {
+ for (i = 0; i < BLOCK_TYPES; ++i) {
for (j = 0; j < REF_TYPES; ++j) {
for (k = 0; k < COEF_BANDS; ++k) {
// int prev_coef_savings[ENTROPY_NODES] = {0};
for (l = 0; l < PREV_COEF_CONTEXTS; ++l) {
// calc probs and branch cts for this frame only
- for (t = CONFIG_CODE_NONZEROCOUNT; t < entropy_nodes_update; ++t) {
+ for (t = tstart; t < entropy_nodes_update; ++t) {
vp9_prob newp = new_frame_coef_probs[i][j][k][l][t];
vp9_prob *oldp = old_frame_coef_probs[i][j][k][l] + t;
const vp9_prob upd = vp9_coef_update_prob[t];
@@ -2201,7 +2214,7 @@ static void update_coef_probs(VP9_COMP* const cpi, vp9_writer* const bc) {
cpi->frame_coef_probs_4x4,
cpi->common.fc.coef_probs_4x4,
cpi->frame_branch_ct_4x4,
- BLOCK_TYPES);
+ TX_4X4);
/* do not do this if not even allowed */
if (cpi->common.txfm_mode != ONLY_4X4) {
@@ -2213,7 +2226,7 @@ static void update_coef_probs(VP9_COMP* const cpi, vp9_writer* const bc) {
cpi->frame_coef_probs_8x8,
cpi->common.fc.coef_probs_8x8,
cpi->frame_branch_ct_8x8,
- BLOCK_TYPES);
+ TX_8X8);
}
if (cpi->common.txfm_mode > ALLOW_8X8) {
@@ -2225,7 +2238,7 @@ static void update_coef_probs(VP9_COMP* const cpi, vp9_writer* const bc) {
cpi->frame_coef_probs_16x16,
cpi->common.fc.coef_probs_16x16,
cpi->frame_branch_ct_16x16,
- BLOCK_TYPES);
+ TX_16X16);
}
if (cpi->common.txfm_mode > ALLOW_16X16) {
@@ -2237,7 +2250,7 @@ static void update_coef_probs(VP9_COMP* const cpi, vp9_writer* const bc) {
cpi->frame_coef_probs_32x32,
cpi->common.fc.coef_probs_32x32,
cpi->frame_branch_ct_32x32,
- BLOCK_TYPES);
+ TX_32X32);
}
}
diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c
index f2a13de99..89e2558a8 100644
--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -1960,9 +1960,10 @@ static void gather_nzcs_mb16(VP9_COMMON *const cm,
static void gather_nzcs_sb32(VP9_COMMON *const cm,
MACROBLOCKD *xd) {
- int i, j;
MODE_INFO *m = xd->mode_info_context;
int mis = cm->mode_info_stride;
+ int i, j;
+
vpx_memset(m->mbmi.nzcs, 0,
384 * sizeof(xd->mode_info_context->mbmi.nzcs[0]));
switch (xd->mode_info_context->mbmi.txfm_size) {
@@ -2004,9 +2005,10 @@ static void gather_nzcs_sb32(VP9_COMMON *const cm,
static void gather_nzcs_sb64(VP9_COMMON *const cm,
MACROBLOCKD *xd) {
- int i, j;
MODE_INFO *m = xd->mode_info_context;
int mis = cm->mode_info_stride;
+ int i, j;
+
vpx_memset(xd->mode_info_context->mbmi.nzcs, 0,
384 * sizeof(xd->mode_info_context->mbmi.nzcs[0]));
switch (xd->mode_info_context->mbmi.txfm_size) {
diff --git a/vp9/encoder/vp9_encodemb.c b/vp9/encoder/vp9_encodemb.c
index 3ad429a9e..27015773f 100644
--- a/vp9/encoder/vp9_encodemb.c
+++ b/vp9/encoder/vp9_encodemb.c
@@ -573,6 +573,7 @@ static void optimize_b(VP9_COMMON *const cm,
// The current implementation uses a suboptimal approach to account for
// the nzc rates somewhat, but in reality the optimization approach needs
// to change substantially.
+ const int nzc_used = get_nzc_used(tx_size);
uint16_t nzc = xd->nzcs[ib];
uint16_t nzc0, nzc1;
uint16_t final_nzc = 0, final_nzc_exp;
@@ -649,7 +650,7 @@ static void optimize_b(VP9_COMMON *const cm,
memset(best_index, 0, sizeof(best_index));
/* Initialize the sentinel node of the trellis. */
#if CONFIG_CODE_NONZEROCOUNT
- tokens[eob][0].rate = nzc_cost[nzc];
+ tokens[eob][0].rate = nzc_used ? nzc_cost[nzc] : 0;
#else
tokens[eob][0].rate = 0;
#endif
@@ -734,8 +735,10 @@ static void optimize_b(VP9_COMMON *const cm,
#if CONFIG_CODE_NONZEROCOUNT
// Account for rate drop because of the nzc change.
// TODO(debargha): Find a better solution
- rate0 -= nzc_cost[nzc0] - nzc_cost[nzc0 - 1];
- rate1 -= nzc_cost[nzc1] - nzc_cost[nzc1 - 1];
+ if (nzc_used) {
+ rate0 -= nzc_cost[nzc0] - nzc_cost[nzc0 - 1];
+ rate1 -= nzc_cost[nzc1] - nzc_cost[nzc1 - 1];
+ }
#endif
} else {
t0 = t1 = (vp9_dct_value_tokens_ptr + x)->Token;
diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c
index 0083e8ae1..71dd6b80b 100644
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -149,10 +149,10 @@ const MODE_DEFINITION vp9_mode_order[MAX_MODES] = {
static void fill_token_costs(vp9_coeff_count *c,
vp9_coeff_probs *p,
- int block_type_counts) {
+ TX_SIZE tx_size) {
int i, j, k, l;
- for (i = 0; i < block_type_counts; i++)
+ for (i = 0; i < BLOCK_TYPES; i++)
for (j = 0; j < REF_TYPES; j++)
for (k = 0; k < COEF_BANDS; k++)
for (l = 0; l < PREV_COEF_CONTEXTS; l++) {
@@ -163,26 +163,26 @@ static void fill_token_costs(vp9_coeff_count *c,
}
#if CONFIG_CODE_NONZEROCOUNT
-static void fill_nzc_costs(VP9_COMP *cpi, int block_size) {
+static void fill_nzc_costs(VP9_COMP *cpi, TX_SIZE tx_size) {
int nzc_context, r, b, nzc, values;
int cost[16];
- values = block_size * block_size + 1;
+ values = (16 << (2 * tx_size)) + 1;
for (nzc_context = 0; nzc_context < MAX_NZC_CONTEXTS; ++nzc_context) {
for (r = 0; r < REF_TYPES; ++r) {
for (b = 0; b < BLOCK_TYPES; ++b) {
unsigned int *nzc_costs;
- if (block_size == 4) {
+ if (tx_size == TX_4X4) {
vp9_cost_tokens(cost,
cpi->common.fc.nzc_probs_4x4[nzc_context][r][b],
vp9_nzc4x4_tree);
nzc_costs = cpi->mb.nzc_costs_4x4[nzc_context][r][b];
- } else if (block_size == 8) {
+ } else if (tx_size == TX_8X8) {
vp9_cost_tokens(cost,
cpi->common.fc.nzc_probs_8x8[nzc_context][r][b],
vp9_nzc8x8_tree);
nzc_costs = cpi->mb.nzc_costs_8x8[nzc_context][r][b];
- } else if (block_size == 16) {
+ } else if (tx_size == TX_16X16) {
vp9_cost_tokens(cost,
cpi->common.fc.nzc_probs_16x16[nzc_context][r][b],
vp9_nzc16x16_tree);
@@ -308,18 +308,18 @@ void vp9_initialize_rd_consts(VP9_COMP *cpi, int qindex) {
}
fill_token_costs(cpi->mb.token_costs[TX_4X4],
- cpi->common.fc.coef_probs_4x4, BLOCK_TYPES);
+ cpi->common.fc.coef_probs_4x4, TX_4X4);
fill_token_costs(cpi->mb.token_costs[TX_8X8],
- cpi->common.fc.coef_probs_8x8, BLOCK_TYPES);
+ cpi->common.fc.coef_probs_8x8, TX_8X8);
fill_token_costs(cpi->mb.token_costs[TX_16X16],
- cpi->common.fc.coef_probs_16x16, BLOCK_TYPES);
+ cpi->common.fc.coef_probs_16x16, TX_16X16);
fill_token_costs(cpi->mb.token_costs[TX_32X32],
- cpi->common.fc.coef_probs_32x32, BLOCK_TYPES);
+ cpi->common.fc.coef_probs_32x32, TX_32X32);
#if CONFIG_CODE_NONZEROCOUNT
- fill_nzc_costs(cpi, 4);
- fill_nzc_costs(cpi, 8);
- fill_nzc_costs(cpi, 16);
- fill_nzc_costs(cpi, 32);
+ fill_nzc_costs(cpi, TX_4X4);
+ fill_nzc_costs(cpi, TX_8X8);
+ fill_nzc_costs(cpi, TX_16X16);
+ fill_nzc_costs(cpi, TX_32X32);
#endif
/*rough estimate for costing*/
@@ -449,13 +449,13 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb,
sizeof(ENTROPY_CONTEXT_PLANES)/sizeof(ENTROPY_CONTEXT);
#if CONFIG_CODE_NONZEROCOUNT
+ const int nzc_used = get_nzc_used(tx_size);
int nzc_context = vp9_get_nzc_context(cm, xd, ib);
unsigned int *nzc_cost;
-#else
+#endif
const int segment_id = xd->mode_info_context->mbmi.segment_id;
vp9_prob (*coef_probs)[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
[ENTROPY_NODES];
-#endif
int seg_eob, default_eob;
uint8_t token_cache[1024];
@@ -475,9 +475,8 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb,
l_ec = *l;
#if CONFIG_CODE_NONZEROCOUNT
nzc_cost = mb->nzc_costs_4x4[nzc_context][ref][type];
-#else
- coef_probs = cm->fc.coef_probs_4x4;
#endif
+ coef_probs = cm->fc.coef_probs_4x4;
seg_eob = 16;
if (tx_type == ADST_DCT) {
scan = vp9_row_scan_4x4;
@@ -504,9 +503,8 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb,
}
#if CONFIG_CODE_NONZEROCOUNT
nzc_cost = mb->nzc_costs_8x8[nzc_context][ref][type];
-#else
- coef_probs = cm->fc.coef_probs_8x8;
#endif
+ coef_probs = cm->fc.coef_probs_8x8;
seg_eob = 64;
break;
}
@@ -524,9 +522,8 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb,
}
#if CONFIG_CODE_NONZEROCOUNT
nzc_cost = mb->nzc_costs_16x16[nzc_context][ref][type];
-#else
- coef_probs = cm->fc.coef_probs_16x16;
#endif
+ coef_probs = cm->fc.coef_probs_16x16;
seg_eob = 256;
if (type == PLANE_TYPE_UV) {
a_ec = (a[0] + a[1] + a1[0] + a1[1]) != 0;
@@ -541,9 +538,8 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb,
scan = vp9_default_zig_zag1d_32x32;
#if CONFIG_CODE_NONZEROCOUNT
nzc_cost = mb->nzc_costs_32x32[nzc_context][ref][type];
-#else
- coef_probs = cm->fc.coef_probs_32x32;
#endif
+ coef_probs = cm->fc.coef_probs_32x32;
seg_eob = 1024;
if (type == PLANE_TYPE_UV) {
ENTROPY_CONTEXT *a2, *a3, *l2, *l3;
@@ -571,10 +567,11 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb,
nb = vp9_get_coef_neighbors_handle(scan, &pad);
default_eob = seg_eob;
-#if CONFIG_CODE_NONZEROCOUNT == 0
- if (vp9_segfeature_active(xd, segment_id, SEG_LVL_SKIP))
- seg_eob = 0;
+#if CONFIG_CODE_NONZEROCOUNT
+ if (!nzc_used)
#endif
+ if (vp9_segfeature_active(xd, segment_id, SEG_LVL_SKIP))
+ seg_eob = 0;
{
#if CONFIG_CODE_NONZEROCOUNT
@@ -598,13 +595,14 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb,
pt = vp9_get_coef_context(scan, nb, pad, token_cache, c + 1, default_eob);
}
#if CONFIG_CODE_NONZEROCOUNT
- cost += nzc_cost[nzc];
-#else
- if (c < seg_eob)
- cost += mb->token_costs[tx_size][type][ref]
- [get_coef_band(scan, tx_size, c)]
- [pt][DCT_EOB_TOKEN];
+ if (nzc_used)
+ cost += nzc_cost[nzc];
+ else
#endif
+ if (c < seg_eob)
+ cost += mb->token_costs[tx_size][type][ref]
+ [get_coef_band(scan, tx_size, c)]
+ [pt][DCT_EOB_TOKEN];
}
// is eob first coefficient;
diff --git a/vp9/encoder/vp9_tokenize.c b/vp9/encoder/vp9_tokenize.c
index 21401d175..8f9e9da69 100644
--- a/vp9/encoder/vp9_tokenize.c
+++ b/vp9/encoder/vp9_tokenize.c
@@ -134,7 +134,8 @@ static void tokenize_b(VP9_COMP *cpi,
ENTROPY_CONTEXT *a, *l, *a1, *l1, *a2, *l2, *a3, *l3, a_ec, l_ec;
uint8_t token_cache[1024];
#if CONFIG_CODE_NONZEROCOUNT
- int zerosleft, nzc = 0;
+ const int nzc_used = get_nzc_used(tx_size);
+ int zerosleft = 0, nzc = 0;
if (eob == 0)
assert(xd->nzcs[ib] == 0);
#endif
@@ -255,7 +256,8 @@ static void tokenize_b(VP9_COMP *cpi,
int token;
int v = 0;
#if CONFIG_CODE_NONZEROCOUNT
- zerosleft = seg_eob - xd->nzcs[ib] - c + nzc;
+ if (nzc_used)
+ zerosleft = seg_eob - xd->nzcs[ib] - c + nzc;
#endif
if (c < eob) {
const int rc = scan[c];
@@ -266,20 +268,22 @@ static void tokenize_b(VP9_COMP *cpi,
token = vp9_dct_value_tokens_ptr[v].Token;
} else {
#if CONFIG_CODE_NONZEROCOUNT
- break;
-#else
- token = DCT_EOB_TOKEN;
+ if (nzc_used)
+ break;
+ else
#endif
+ token = DCT_EOB_TOKEN;
}
t->Token = token;
t->context_tree = probs[type][ref][band][pt];
#if CONFIG_CODE_NONZEROCOUNT
// Skip zero node if there are no zeros left
- t->skip_eob_node = 1 + (zerosleft == 0);
-#else
- t->skip_eob_node = (c > 0) && (token_cache[c - 1] == 0);
+ if (nzc_used)
+ t->skip_eob_node = 1 + (zerosleft == 0);
+ else
#endif
+ t->skip_eob_node = (c > 0) && (token_cache[c - 1] == 0);
assert(vp9_coef_encodings[t->Token].Len - t->skip_eob_node > 0);
if (!dry_run) {
++counts[type][ref][band][pt][token];
@@ -975,14 +979,15 @@ static void stuff_b(VP9_COMP *cpi,
int dry_run) {
MB_MODE_INFO *mbmi = &xd->mode_info_context->mbmi;
const BLOCK_SIZE_TYPE sb_type = mbmi->sb_type;
-#if CONFIG_CODE_NONZEROCOUNT == 0
vp9_coeff_count *counts;
vp9_coeff_probs *probs;
int pt, band;
TOKENEXTRA *t = *tp;
const int ref = mbmi->ref_frame != INTRA_FRAME;
-#endif
ENTROPY_CONTEXT *a, *l, *a1, *l1, *a2, *l2, *a3, *l3, a_ec, l_ec;
+#if CONFIG_CODE_NONZEROCOUNT
+ const int nzc_used = get_nzc_used(tx_size);
+#endif
if (sb_type == BLOCK_SIZE_SB32X32) {
a = (ENTROPY_CONTEXT *)xd->above_context +
@@ -1011,18 +1016,14 @@ static void stuff_b(VP9_COMP *cpi,
case TX_4X4:
a_ec = a[0];
l_ec = l[0];
-#if CONFIG_CODE_NONZEROCOUNT == 0
counts = cpi->coef_counts_4x4;
probs = cpi->common.fc.coef_probs_4x4;
-#endif
break;
case TX_8X8:
a_ec = (a[0] + a[1]) != 0;
l_ec = (l[0] + l[1]) != 0;
-#if CONFIG_CODE_NONZEROCOUNT == 0
counts = cpi->coef_counts_8x8;
probs = cpi->common.fc.coef_probs_8x8;
-#endif
break;
case TX_16X16:
if (type != PLANE_TYPE_UV) {
@@ -1032,10 +1033,8 @@ static void stuff_b(VP9_COMP *cpi,
a_ec = (a[0] + a[1] + a1[0] + a1[1]) != 0;
l_ec = (l[0] + l[1] + l1[0] + l1[1]) != 0;
}
-#if CONFIG_CODE_NONZEROCOUNT == 0
counts = cpi->coef_counts_16x16;
probs = cpi->common.fc.coef_probs_16x16;
-#endif
break;
case TX_32X32:
if (type != PLANE_TYPE_UV) {
@@ -1049,26 +1048,28 @@ static void stuff_b(VP9_COMP *cpi,
l_ec = (l[0] + l[1] + l1[0] + l1[1] +
l2[0] + l2[1] + l3[0] + l3[1]) != 0;
}
-#if CONFIG_CODE_NONZEROCOUNT == 0
counts = cpi->coef_counts_32x32;
probs = cpi->common.fc.coef_probs_32x32;
-#endif
break;
}
-#if CONFIG_CODE_NONZEROCOUNT == 0
- VP9_COMBINEENTROPYCONTEXTS(pt, a_ec, l_ec);
- band = 0;
- t->Token = DCT_EOB_TOKEN;
- t->context_tree = probs[type][ref][band][pt];
- t->skip_eob_node = 0;
- ++t;
- *tp = t;
- if (!dry_run) {
- ++counts[type][ref][band][pt][DCT_EOB_TOKEN];
+#if CONFIG_CODE_NONZEROCOUNT
+ if (!nzc_used) {
+#endif
+ VP9_COMBINEENTROPYCONTEXTS(pt, a_ec, l_ec);
+ band = 0;
+ t->Token = DCT_EOB_TOKEN;
+ t->context_tree = probs[type][ref][band][pt];
+ t->skip_eob_node = 0;
+ ++t;
+ *tp = t;
+ if (!dry_run) {
+ ++counts[type][ref][band][pt][DCT_EOB_TOKEN];
+ }
+#if CONFIG_CODE_NONZEROCOUNT
}
#endif
- *a = *l = 0;
+ *a = *l = 0;
if (tx_size == TX_8X8) {
a[1] = 0;
l[1] = 0;