summaryrefslogtreecommitdiff
path: root/vp9/encoder
diff options
context:
space:
mode:
Diffstat (limited to 'vp9/encoder')
-rw-r--r--vp9/encoder/vp9_bitstream.c236
-rw-r--r--vp9/encoder/vp9_block.h2
-rw-r--r--vp9/encoder/vp9_encodeframe.c13
-rw-r--r--vp9/encoder/vp9_encodemb.c272
-rw-r--r--vp9/encoder/vp9_encodemb.h24
-rw-r--r--vp9/encoder/vp9_onyx_if.c104
-rw-r--r--vp9/encoder/vp9_onyx_int.h23
-rw-r--r--vp9/encoder/vp9_ratectrl.c10
-rw-r--r--vp9/encoder/vp9_rdopt.c135
-rw-r--r--vp9/encoder/vp9_tokenize.c62
-rw-r--r--vp9/encoder/vp9_tokenize.h5
11 files changed, 271 insertions, 615 deletions
diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c
index 7d250b346..95e9a7df0 100644
--- a/vp9/encoder/vp9_bitstream.c
+++ b/vp9/encoder/vp9_bitstream.c
@@ -43,10 +43,7 @@ unsigned __int64 Sectionbits[500];
int intra_mode_stats[VP9_INTRA_MODES]
[VP9_INTRA_MODES]
[VP9_INTRA_MODES];
-vp9_coeff_stats tree_update_hist_4x4[BLOCK_TYPES];
-vp9_coeff_stats tree_update_hist_8x8[BLOCK_TYPES];
-vp9_coeff_stats tree_update_hist_16x16[BLOCK_TYPES];
-vp9_coeff_stats tree_update_hist_32x32[BLOCK_TYPES];
+vp9_coeff_stats tree_update_hist[TX_SIZE_MAX_SB][BLOCK_TYPES];
extern unsigned int active_section;
#endif
@@ -1014,24 +1011,16 @@ static void print_prob_tree(vp9_coeff_probs *coef_probs, int block_types) {
fclose(f);
}
-static void build_tree_distribution(vp9_coeff_probs_model *coef_probs,
- vp9_coeff_count *coef_counts,
- unsigned int (*eob_branch_ct)[REF_TYPES]
- [COEF_BANDS]
- [PREV_COEF_CONTEXTS],
-#ifdef ENTROPY_STATS
- VP9_COMP *cpi,
- vp9_coeff_accum *context_counters,
-#endif
- vp9_coeff_stats *coef_branch_ct,
- int block_types) {
- int i, j, k, l;
-#ifdef ENTROPY_STATS
- int t = 0;
-#endif
+static void build_tree_distribution(VP9_COMP *cpi, TX_SIZE txfm_size) {
+ vp9_coeff_probs_model *coef_probs = cpi->frame_coef_probs[txfm_size];
+ vp9_coeff_count *coef_counts = cpi->coef_counts[txfm_size];
+ unsigned int (*eob_branch_ct)[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS] =
+ cpi->common.fc.eob_branch_counts[txfm_size];
+ vp9_coeff_stats *coef_branch_ct = cpi->frame_branch_ct[txfm_size];
vp9_prob full_probs[ENTROPY_NODES];
+ int i, j, k, l;
- 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) {
for (l = 0; l < PREV_COEF_CONTEXTS; ++l) {
@@ -1058,9 +1047,11 @@ static void build_tree_distribution(vp9_coeff_probs_model *coef_probs,
#endif
#ifdef ENTROPY_STATS
if (!cpi->dummy_packing) {
+ int t;
for (t = 0; t < MAX_ENTROPY_TOKENS; ++t)
- context_counters[i][j][k][l][t] += coef_counts[i][j][k][l][t];
- context_counters[i][j][k][l][MAX_ENTROPY_TOKENS] +=
+ context_counters[txfm_size][i][j][k][l][t] +=
+ coef_counts[i][j][k][l][t];
+ context_counters[txfm_size][i][j][k][l][MAX_ENTROPY_TOKENS] +=
eob_branch_ct[i][j][k][l];
}
#endif
@@ -1071,46 +1062,17 @@ static void build_tree_distribution(vp9_coeff_probs_model *coef_probs,
}
static void build_coeff_contexts(VP9_COMP *cpi) {
- build_tree_distribution(cpi->frame_coef_probs_4x4,
- cpi->coef_counts_4x4,
- cpi->common.fc.eob_branch_counts[TX_4X4],
-#ifdef ENTROPY_STATS
- cpi, context_counters_4x4,
-#endif
- cpi->frame_branch_ct_4x4, BLOCK_TYPES);
- build_tree_distribution(cpi->frame_coef_probs_8x8,
- cpi->coef_counts_8x8,
- cpi->common.fc.eob_branch_counts[TX_8X8],
-#ifdef ENTROPY_STATS
- cpi, context_counters_8x8,
-#endif
- cpi->frame_branch_ct_8x8, BLOCK_TYPES);
- build_tree_distribution(cpi->frame_coef_probs_16x16,
- cpi->coef_counts_16x16,
- cpi->common.fc.eob_branch_counts[TX_16X16],
-#ifdef ENTROPY_STATS
- cpi, context_counters_16x16,
-#endif
- cpi->frame_branch_ct_16x16, BLOCK_TYPES);
- build_tree_distribution(cpi->frame_coef_probs_32x32,
- cpi->coef_counts_32x32,
- cpi->common.fc.eob_branch_counts[TX_32X32],
-#ifdef ENTROPY_STATS
- cpi, context_counters_32x32,
-#endif
- cpi->frame_branch_ct_32x32, BLOCK_TYPES);
+ TX_SIZE t;
+ for (t = TX_4X4; t <= TX_32X32; t++)
+ build_tree_distribution(cpi, t);
}
-static void update_coef_probs_common(
- vp9_writer* const bc,
- VP9_COMP *cpi,
-#ifdef ENTROPY_STATS
- vp9_coeff_stats *tree_update_hist,
-#endif
- vp9_coeff_probs_model *new_frame_coef_probs,
- vp9_coeff_probs_model *old_frame_coef_probs,
- vp9_coeff_stats *frame_branch_ct,
- TX_SIZE tx_size) {
+static void update_coef_probs_common(vp9_writer* const bc, VP9_COMP *cpi,
+ TX_SIZE tx_size) {
+ vp9_coeff_probs_model *new_frame_coef_probs = cpi->frame_coef_probs[tx_size];
+ vp9_coeff_probs_model *old_frame_coef_probs =
+ cpi->common.fc.coef_probs[tx_size];
+ vp9_coeff_stats *frame_branch_ct = cpi->frame_branch_ct[tx_size];
int i, j, k, l, t;
int update[2] = {0, 0};
int savings;
@@ -1188,7 +1150,7 @@ static void update_coef_probs_common(
vp9_write(bc, u, upd);
#ifdef ENTROPY_STATS
if (!cpi->dummy_packing)
- ++tree_update_hist[i][j][k][l][t][u];
+ ++tree_update_hist[tx_size][i][j][k][l][t][u];
#endif
if (u) {
/* send/use new probability */
@@ -1208,51 +1170,19 @@ static void update_coef_probs(VP9_COMP* const cpi, vp9_writer* const bc) {
// Build the cofficient contexts based on counts collected in encode loop
build_coeff_contexts(cpi);
- update_coef_probs_common(bc,
- cpi,
-#ifdef ENTROPY_STATS
- tree_update_hist_4x4,
-#endif
- cpi->frame_coef_probs_4x4,
- cpi->common.fc.coef_probs_4x4,
- cpi->frame_branch_ct_4x4,
- TX_4X4);
+ update_coef_probs_common(bc, cpi, TX_4X4);
/* do not do this if not even allowed */
if (cpi->common.txfm_mode != ONLY_4X4) {
- update_coef_probs_common(bc,
- cpi,
-#ifdef ENTROPY_STATS
- tree_update_hist_8x8,
-#endif
- cpi->frame_coef_probs_8x8,
- cpi->common.fc.coef_probs_8x8,
- cpi->frame_branch_ct_8x8,
- TX_8X8);
+ update_coef_probs_common(bc, cpi, TX_8X8);
}
if (cpi->common.txfm_mode > ALLOW_8X8) {
- update_coef_probs_common(bc,
- cpi,
-#ifdef ENTROPY_STATS
- tree_update_hist_16x16,
-#endif
- cpi->frame_coef_probs_16x16,
- cpi->common.fc.coef_probs_16x16,
- cpi->frame_branch_ct_16x16,
- TX_16X16);
+ update_coef_probs_common(bc, cpi, TX_16X16);
}
if (cpi->common.txfm_mode > ALLOW_16X16) {
- update_coef_probs_common(bc,
- cpi,
-#ifdef ENTROPY_STATS
- tree_update_hist_32x32,
-#endif
- cpi->frame_coef_probs_32x32,
- cpi->common.fc.coef_probs_32x32,
- cpi->frame_branch_ct_32x32,
- TX_32X32);
+ update_coef_probs_common(bc, cpi, TX_32X32);
}
}
@@ -1364,9 +1294,6 @@ static void encode_segmentation(VP9_COMP *cpi, vp9_writer *w) {
// Segmentation map
vp9_write_bit(w, xd->update_mb_segmentation_map);
-#if CONFIG_IMPLICIT_SEGMENTATION
- vp9_write_bit(w, xd->allow_implicit_segment_update);
-#endif
if (xd->update_mb_segmentation_map) {
// Select the coding strategy (temporal or spatial)
vp9_choose_segmap_coding_method(cpi);
@@ -1429,6 +1356,49 @@ static void encode_segmentation(VP9_COMP *cpi, vp9_writer *w) {
}
}
+
+static void encode_txfm(VP9_COMP *cpi, vp9_writer *w) {
+ VP9_COMMON *const cm = &cpi->common;
+
+ // Mode
+ vp9_write_literal(w, MIN(cm->txfm_mode, ALLOW_32X32), 2);
+ if (cm->txfm_mode >= ALLOW_32X32)
+ vp9_write_bit(w, cm->txfm_mode == TX_MODE_SELECT);
+
+ // Probabilities
+ if (cm->txfm_mode == TX_MODE_SELECT) {
+ cm->prob_tx[0] = get_prob(cpi->txfm_count_32x32p[TX_4X4] +
+ cpi->txfm_count_16x16p[TX_4X4] +
+ cpi->txfm_count_8x8p[TX_4X4],
+ cpi->txfm_count_32x32p[TX_4X4] +
+ cpi->txfm_count_32x32p[TX_8X8] +
+ cpi->txfm_count_32x32p[TX_16X16] +
+ cpi->txfm_count_32x32p[TX_32X32] +
+ cpi->txfm_count_16x16p[TX_4X4] +
+ cpi->txfm_count_16x16p[TX_8X8] +
+ cpi->txfm_count_16x16p[TX_16X16] +
+ cpi->txfm_count_8x8p[TX_4X4] +
+ cpi->txfm_count_8x8p[TX_8X8]);
+ cm->prob_tx[1] = get_prob(cpi->txfm_count_32x32p[TX_8X8] +
+ cpi->txfm_count_16x16p[TX_8X8],
+ cpi->txfm_count_32x32p[TX_8X8] +
+ cpi->txfm_count_32x32p[TX_16X16] +
+ cpi->txfm_count_32x32p[TX_32X32] +
+ cpi->txfm_count_16x16p[TX_8X8] +
+ cpi->txfm_count_16x16p[TX_16X16]);
+ cm->prob_tx[2] = get_prob(cpi->txfm_count_32x32p[TX_16X16],
+ cpi->txfm_count_32x32p[TX_16X16] +
+ cpi->txfm_count_32x32p[TX_32X32]);
+ vp9_write_prob(w, cm->prob_tx[0]);
+ vp9_write_prob(w, cm->prob_tx[1]);
+ vp9_write_prob(w, cm->prob_tx[2]);
+ } else {
+ cm->prob_tx[0] = 128;
+ cm->prob_tx[1] = 128;
+ cm->prob_tx[2] = 128;
+ }
+}
+
void write_uncompressed_header(VP9_COMMON *cm,
struct vp9_write_bit_buffer *wb) {
const int scaling_active = cm->width != cm->display_width ||
@@ -1594,47 +1564,10 @@ void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, unsigned long *size) {
}
}
- if (cpi->mb.e_mbd.lossless) {
+ if (xd->lossless)
pc->txfm_mode = ONLY_4X4;
- } else {
- if (pc->txfm_mode == TX_MODE_SELECT) {
- pc->prob_tx[0] = get_prob(cpi->txfm_count_32x32p[TX_4X4] +
- cpi->txfm_count_16x16p[TX_4X4] +
- cpi->txfm_count_8x8p[TX_4X4],
- cpi->txfm_count_32x32p[TX_4X4] +
- cpi->txfm_count_32x32p[TX_8X8] +
- cpi->txfm_count_32x32p[TX_16X16] +
- cpi->txfm_count_32x32p[TX_32X32] +
- cpi->txfm_count_16x16p[TX_4X4] +
- cpi->txfm_count_16x16p[TX_8X8] +
- cpi->txfm_count_16x16p[TX_16X16] +
- cpi->txfm_count_8x8p[TX_4X4] +
- cpi->txfm_count_8x8p[TX_8X8]);
- pc->prob_tx[1] = get_prob(cpi->txfm_count_32x32p[TX_8X8] +
- cpi->txfm_count_16x16p[TX_8X8],
- cpi->txfm_count_32x32p[TX_8X8] +
- cpi->txfm_count_32x32p[TX_16X16] +
- cpi->txfm_count_32x32p[TX_32X32] +
- cpi->txfm_count_16x16p[TX_8X8] +
- cpi->txfm_count_16x16p[TX_16X16]);
- pc->prob_tx[2] = get_prob(cpi->txfm_count_32x32p[TX_16X16],
- cpi->txfm_count_32x32p[TX_16X16] +
- cpi->txfm_count_32x32p[TX_32X32]);
- } else {
- pc->prob_tx[0] = 128;
- pc->prob_tx[1] = 128;
- pc->prob_tx[2] = 128;
- }
- vp9_write_literal(&header_bc, pc->txfm_mode <= 3 ? pc->txfm_mode : 3, 2);
- if (pc->txfm_mode > ALLOW_16X16) {
- vp9_write_bit(&header_bc, pc->txfm_mode == TX_MODE_SELECT);
- }
- if (pc->txfm_mode == TX_MODE_SELECT) {
- vp9_write_prob(&header_bc, pc->prob_tx[0]);
- vp9_write_prob(&header_bc, pc->prob_tx[1]);
- vp9_write_prob(&header_bc, pc->prob_tx[2]);
- }
- }
+ else
+ encode_txfm(cpi, &header_bc);
// If appropriate update the inter mode probability context and code the
// changes in the bitstream.
@@ -1668,15 +1601,7 @@ void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, unsigned long *size) {
vp9_clear_system_state(); // __asm emms;
- vp9_copy(cpi->common.fc.pre_coef_probs_4x4,
- cpi->common.fc.coef_probs_4x4);
- vp9_copy(cpi->common.fc.pre_coef_probs_8x8,
- cpi->common.fc.coef_probs_8x8);
- vp9_copy(cpi->common.fc.pre_coef_probs_16x16,
- cpi->common.fc.coef_probs_16x16);
- vp9_copy(cpi->common.fc.pre_coef_probs_32x32,
- cpi->common.fc.coef_probs_32x32);
-
+ vp9_copy(cpi->common.fc.pre_coef_probs, cpi->common.fc.coef_probs);
vp9_copy(cpi->common.fc.pre_y_mode_prob, cpi->common.fc.y_mode_prob);
vp9_copy(cpi->common.fc.pre_uv_mode_prob, cpi->common.fc.uv_mode_prob);
vp9_copy(cpi->common.fc.pre_partition_prob, cpi->common.fc.partition_prob);
@@ -1842,21 +1767,18 @@ void print_tree_update_probs() {
FILE *f = fopen("coefupdprob.h", "w");
fprintf(f, "\n/* Update probabilities for token entropy tree. */\n\n");
- print_tree_update_for_type(f, tree_update_hist_4x4, BLOCK_TYPES,
+ print_tree_update_for_type(f, tree_update_hist[TX_4X4], BLOCK_TYPES,
"vp9_coef_update_probs_4x4[BLOCK_TYPES]");
- print_tree_update_for_type(f, tree_update_hist_8x8, BLOCK_TYPES,
+ print_tree_update_for_type(f, tree_update_hist[TX_8X8], BLOCK_TYPES,
"vp9_coef_update_probs_8x8[BLOCK_TYPES]");
- print_tree_update_for_type(f, tree_update_hist_16x16, BLOCK_TYPES,
+ print_tree_update_for_type(f, tree_update_hist[TX_16X16], BLOCK_TYPES,
"vp9_coef_update_probs_16x16[BLOCK_TYPES]");
- print_tree_update_for_type(f, tree_update_hist_32x32, BLOCK_TYPES,
+ print_tree_update_for_type(f, tree_update_hist[TX_32X32], BLOCK_TYPES,
"vp9_coef_update_probs_32x32[BLOCK_TYPES]");
fclose(f);
f = fopen("treeupdate.bin", "wb");
- fwrite(tree_update_hist_4x4, sizeof(tree_update_hist_4x4), 1, f);
- fwrite(tree_update_hist_8x8, sizeof(tree_update_hist_8x8), 1, f);
- fwrite(tree_update_hist_16x16, sizeof(tree_update_hist_16x16), 1, f);
- fwrite(tree_update_hist_32x32, sizeof(tree_update_hist_32x32), 1, f);
+ fwrite(tree_update_hist, sizeof(tree_update_hist), 1, f);
fclose(f);
}
#endif
diff --git a/vp9/encoder/vp9_block.h b/vp9/encoder/vp9_block.h
index e6d36cdf8..e78f54eb4 100644
--- a/vp9/encoder/vp9_block.h
+++ b/vp9/encoder/vp9_block.h
@@ -135,9 +135,7 @@ struct macroblock {
// note that token_costs is the cost when eob node is skipped
vp9_coeff_count token_costs[TX_SIZE_MAX_SB][BLOCK_TYPES];
-#if CONFIG_BALANCED_COEFTREE
vp9_coeff_count token_costs_noskip[TX_SIZE_MAX_SB][BLOCK_TYPES];
-#endif
int optimize;
diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c
index c219f1f00..714a1bf5c 100644
--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -558,7 +558,10 @@ static void set_offsets(VP9_COMP *cpi,
x->partition_info = x->pi + idx_str;
xd->mode_info_context = cm->mi + idx_str;
mbmi = &xd->mode_info_context->mbmi;
- xd->prev_mode_info_context = cm->prev_mi + idx_str;
+ // Special case: if prev_mi is NULL, the previous mode info context
+ // cannot be used.
+ xd->prev_mode_info_context = cm->prev_mi ?
+ cm->prev_mi + idx_str : NULL;
// Set up destination pointers
setup_dst_planes(xd, &cm->yv12_fb[dst_fb_idx], mi_row, mi_col);
@@ -1534,10 +1537,7 @@ static void encode_frame_internal(VP9_COMP *cpi) {
xd->prev_mode_info_context = cm->prev_mi;
vp9_zero(cpi->NMVcount);
- vp9_zero(cpi->coef_counts_4x4);
- vp9_zero(cpi->coef_counts_8x8);
- vp9_zero(cpi->coef_counts_16x16);
- vp9_zero(cpi->coef_counts_32x32);
+ vp9_zero(cpi->coef_counts);
vp9_zero(cm->fc.eob_branch_counts);
cpi->mb.e_mbd.lossless = cm->base_qindex == 0 &&
@@ -1571,6 +1571,8 @@ static void encode_frame_internal(VP9_COMP *cpi) {
vpx_memset(cpi->rd_tx_select_diff, 0, sizeof(cpi->rd_tx_select_diff));
vpx_memset(cpi->rd_tx_select_threshes, 0, sizeof(cpi->rd_tx_select_threshes));
+ set_prev_mi(cm);
+
{
struct vpx_usec_timer emr_timer;
vpx_usec_timer_start(&emr_timer);
@@ -1833,6 +1835,7 @@ void vp9_encode_frame(VP9_COMP *cpi) {
if (txfm_type != TX_MODE_SELECT) {
cpi->common.prob_tx[0] = 128;
cpi->common.prob_tx[1] = 128;
+ cpi->common.prob_tx[2] = 128;
}
cpi->common.comp_pred_mode = pred_type;
encode_frame_internal(cpi);
diff --git a/vp9/encoder/vp9_encodemb.c b/vp9/encoder/vp9_encodemb.c
index 98ea98031..389c5d860 100644
--- a/vp9/encoder/vp9_encodemb.c
+++ b/vp9/encoder/vp9_encodemb.c
@@ -41,15 +41,15 @@ void vp9_subtract_block(int rows, int cols,
static void subtract_plane(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize, int plane) {
- const MACROBLOCKD * const xd = &x->e_mbd;
- const int bw = 4 << (b_width_log2(bsize) - xd->plane[plane].subsampling_x);
- const int bh = 4 << (b_height_log2(bsize) - xd->plane[plane].subsampling_y);
- const uint8_t *src = x->plane[plane].src.buf;
- const int src_stride = x->plane[plane].src.stride;
-
- vp9_subtract_block(bh, bw,
- x->plane[plane].src_diff, bw, src, src_stride,
- xd->plane[plane].dst.buf, xd->plane[plane].dst.stride);
+ struct macroblock_plane *const p = &x->plane[plane];
+ const MACROBLOCKD *const xd = &x->e_mbd;
+ const struct macroblockd_plane *const pd = &xd->plane[plane];
+ const int bw = plane_block_width(bsize, pd);
+ const int bh = plane_block_height(bsize, pd);
+
+ vp9_subtract_block(bh, bw, p->src_diff, bw,
+ p->src.buf, p->src.stride,
+ pd->dst.buf, pd->dst.stride);
}
void vp9_subtract_sby(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize) {
@@ -215,21 +215,12 @@ static void optimize_b(VP9_COMMON *const cm, MACROBLOCK *mb,
band = get_coef_band(band_translate, i + 1);
pt = trellis_get_coeff_context(scan, nb, i, t0, token_cache,
pad, default_eob);
-#if CONFIG_BALANCED_COEFTREE
rate0 +=
mb->token_costs_noskip[tx_size][type][ref][band][pt]
[tokens[next][0].token];
rate1 +=
mb->token_costs_noskip[tx_size][type][ref][band][pt]
[tokens[next][1].token];
-#else
- rate0 +=
- mb->token_costs[tx_size][type][ref][band][pt]
- [tokens[next][0].token];
- rate1 +=
- mb->token_costs[tx_size][type][ref][band][pt]
- [tokens[next][1].token];
-#endif
}
UPDATE_RD_COST();
/* And pick the best. */
@@ -277,32 +268,22 @@ static void optimize_b(VP9_COMMON *const cm, MACROBLOCK *mb,
if (t0 != DCT_EOB_TOKEN) {
pt = trellis_get_coeff_context(scan, nb, i, t0, token_cache,
pad, default_eob);
-#if CONFIG_BALANCED_COEFTREE
if (!x)
rate0 += mb->token_costs[tx_size][type][ref][band][pt][
tokens[next][0].token];
else
rate0 += mb->token_costs_noskip[tx_size][type][ref][band][pt][
tokens[next][0].token];
-#else
- rate0 += mb->token_costs[tx_size][type][ref][band][pt][
- tokens[next][0].token];
-#endif
}
if (t1 != DCT_EOB_TOKEN) {
pt = trellis_get_coeff_context(scan, nb, i, t1, token_cache,
pad, default_eob);
-#if CONFIG_BALANCED_COEFTREE
if (!x)
rate1 += mb->token_costs[tx_size][type][ref][band][pt][
tokens[next][1].token];
else
rate1 += mb->token_costs_noskip[tx_size][type][ref][band][pt][
tokens[next][1].token];
-#else
- rate1 += mb->token_costs[tx_size][type][ref][band][pt][
- tokens[next][1].token];
-#endif
}
}
@@ -355,13 +336,8 @@ static void optimize_b(VP9_COMMON *const cm, MACROBLOCK *mb,
error1 = tokens[next][1].error;
t0 = tokens[next][0].token;
t1 = tokens[next][1].token;
-#if CONFIG_BALANCED_COEFTREE
rate0 += mb->token_costs_noskip[tx_size][type][ref][band][pt][t0];
rate1 += mb->token_costs_noskip[tx_size][type][ref][band][pt][t1];
-#else
- rate0 += mb->token_costs[tx_size][type][ref][band][pt][t0];
- rate1 += mb->token_costs[tx_size][type][ref][band][pt][t1];
-#endif
UPDATE_RD_COST();
best = rd_cost1 < rd_cost0;
final_eob = i0 - 1;
@@ -394,15 +370,14 @@ struct optimize_block_args {
void vp9_optimize_b(int plane, int block, BLOCK_SIZE_TYPE bsize,
int ss_txfrm_size, VP9_COMMON *cm, MACROBLOCK *mb,
struct optimize_ctx *ctx) {
- MACROBLOCKD* const xd = &mb->e_mbd;
+ MACROBLOCKD *const xd = &mb->e_mbd;
int x, y;
// find current entropy context
txfrm_block_to_raster_xy(xd, bsize, plane, block, ss_txfrm_size, &x, &y);
optimize_b(cm, mb, plane, block, bsize,
- &ctx->ta[plane][x], &ctx->tl[plane][y],
- ss_txfrm_size / 2);
+ &ctx->ta[plane][x], &ctx->tl[plane][y], ss_txfrm_size / 2);
}
static void optimize_block(int plane, int block, BLOCK_SIZE_TYPE bsize,
@@ -441,13 +416,11 @@ void vp9_optimize_init(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize,
}
}
-void vp9_optimize_sby(VP9_COMMON *const cm, MACROBLOCK *x,
- BLOCK_SIZE_TYPE bsize) {
+void vp9_optimize_sby(VP9_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE_TYPE bsize) {
struct optimize_ctx ctx;
struct optimize_block_args arg = {cm, x, &ctx};
vp9_optimize_init(&x->e_mbd, bsize, &ctx);
- foreach_transformed_block_in_plane(&x->e_mbd, bsize, 0,
- optimize_block, &arg);
+ foreach_transformed_block_in_plane(&x->e_mbd, bsize, 0, optimize_block, &arg);
}
void vp9_optimize_sbuv(VP9_COMMON *const cm, MACROBLOCK *x,
@@ -469,55 +442,39 @@ static void xform_quant(int plane, int block, BLOCK_SIZE_TYPE bsize,
struct encode_b_args* const args = arg;
MACROBLOCK* const x = args->x;
MACROBLOCKD* const xd = &x->e_mbd;
- const int bw = 4 << (b_width_log2(bsize) - xd->plane[plane].subsampling_x);
+ const int bw = plane_block_width(bsize, &xd->plane[plane]);
const int raster_block = txfrm_block_to_raster_block(xd, bsize, plane,
block, ss_txfrm_size);
- int16_t* const src_diff = raster_block_offset_int16(xd, bsize, plane,
+ int16_t *const coeff = BLOCK_OFFSET(x->plane[plane].coeff, block, 16);
+ int16_t *const src_diff = raster_block_offset_int16(xd, bsize, plane,
raster_block,
x->plane[plane].src_diff);
TX_TYPE tx_type = DCT_DCT;
switch (ss_txfrm_size / 2) {
case TX_32X32:
- vp9_short_fdct32x32(src_diff,
- BLOCK_OFFSET(x->plane[plane].coeff, block, 16),
- bw * 2);
+ vp9_short_fdct32x32(src_diff, coeff, bw * 2);
break;
case TX_16X16:
tx_type = plane == 0 ? get_tx_type_16x16(xd, raster_block) : DCT_DCT;
- if (tx_type != DCT_DCT) {
- vp9_short_fht16x16(src_diff,
- BLOCK_OFFSET(x->plane[plane].coeff, block, 16),
- bw, tx_type);
- } else {
- x->fwd_txm16x16(src_diff,
- BLOCK_OFFSET(x->plane[plane].coeff, block, 16),
- bw * 2);
- }
+ if (tx_type != DCT_DCT)
+ vp9_short_fht16x16(src_diff, coeff, bw, tx_type);
+ else
+ x->fwd_txm16x16(src_diff, coeff, bw * 2);
break;
case TX_8X8:
tx_type = plane == 0 ? get_tx_type_8x8(xd, raster_block) : DCT_DCT;
- if (tx_type != DCT_DCT) {
- vp9_short_fht8x8(src_diff,
- BLOCK_OFFSET(x->plane[plane].coeff, block, 16),
- bw, tx_type);
- } else {
- x->fwd_txm8x8(src_diff,
- BLOCK_OFFSET(x->plane[plane].coeff, block, 16),
- bw * 2);
- }
+ if (tx_type != DCT_DCT)
+ vp9_short_fht8x8(src_diff, coeff, bw, tx_type);
+ else
+ x->fwd_txm8x8(src_diff, coeff, bw * 2);
break;
case TX_4X4:
tx_type = plane == 0 ? get_tx_type_4x4(xd, raster_block) : DCT_DCT;
- if (tx_type != DCT_DCT) {
- vp9_short_fht4x4(src_diff,
- BLOCK_OFFSET(x->plane[plane].coeff, block, 16),
- bw, tx_type);
- } else {
- x->fwd_txm4x4(src_diff,
- BLOCK_OFFSET(x->plane[plane].coeff, block, 16),
- bw * 2);
- }
+ if (tx_type != DCT_DCT)
+ vp9_short_fht4x4(src_diff, coeff, bw, tx_type);
+ else
+ x->fwd_txm4x4(src_diff, coeff, bw * 2);
break;
default:
assert(0);
@@ -528,15 +485,16 @@ static void xform_quant(int plane, int block, BLOCK_SIZE_TYPE bsize,
static void encode_block(int plane, int block, BLOCK_SIZE_TYPE bsize,
int ss_txfrm_size, void *arg) {
- struct encode_b_args* const args = arg;
- MACROBLOCK* const x = args->x;
- MACROBLOCKD* const xd = &x->e_mbd;
+ struct encode_b_args *const args = arg;
+ MACROBLOCK *const x = args->x;
+ MACROBLOCKD *const xd = &x->e_mbd;
const int raster_block = txfrm_block_to_raster_block(xd, bsize, plane,
block, ss_txfrm_size);
- uint8_t* const dst = raster_block_offset_uint8(xd, bsize, plane,
+ struct macroblockd_plane *const pd = &xd->plane[plane];
+ int16_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block, 16);
+ uint8_t *const dst = raster_block_offset_uint8(xd, bsize, plane,
raster_block,
- xd->plane[plane].dst.buf,
- xd->plane[plane].dst.stride);
+ pd->dst.buf, pd->dst.stride);
TX_TYPE tx_type = DCT_DCT;
xform_quant(plane, block, bsize, ss_txfrm_size, arg);
@@ -546,67 +504,53 @@ static void encode_block(int plane, int block, BLOCK_SIZE_TYPE bsize,
switch (ss_txfrm_size / 2) {
case TX_32X32:
- vp9_short_idct32x32_add(BLOCK_OFFSET(xd->plane[plane].dqcoeff,
- block, 16), dst, xd->plane[plane].dst.stride);
+ vp9_short_idct32x32_add(dqcoeff, dst, pd->dst.stride);
break;
case TX_16X16:
tx_type = plane == 0 ? get_tx_type_16x16(xd, raster_block) : DCT_DCT;
- if (tx_type == DCT_DCT) {
- vp9_short_idct16x16_add(BLOCK_OFFSET(xd->plane[plane].dqcoeff,
- block, 16), dst, xd->plane[plane].dst.stride);
- } else {
- vp9_short_iht16x16_add(BLOCK_OFFSET(xd->plane[plane].dqcoeff,
- block, 16), dst, xd->plane[plane].dst.stride,
- tx_type);
- }
+ if (tx_type == DCT_DCT)
+ vp9_short_idct16x16_add(dqcoeff, dst, pd->dst.stride);
+ else
+ vp9_short_iht16x16_add(dqcoeff, dst, pd->dst.stride, tx_type);
break;
case TX_8X8:
tx_type = plane == 0 ? get_tx_type_8x8(xd, raster_block) : DCT_DCT;
- if (tx_type == DCT_DCT) {
- vp9_short_idct8x8_add(BLOCK_OFFSET(xd->plane[plane].dqcoeff,
- block, 16), dst, xd->plane[plane].dst.stride);
- } else {
- vp9_short_iht8x8_add(BLOCK_OFFSET(xd->plane[plane].dqcoeff,
- block, 16), dst, xd->plane[plane].dst.stride,
- tx_type);
- }
+ if (tx_type == DCT_DCT)
+ vp9_short_idct8x8_add(dqcoeff, dst, pd->dst.stride);
+ else
+ vp9_short_iht8x8_add(dqcoeff, dst, pd->dst.stride, tx_type);
break;
case TX_4X4:
tx_type = plane == 0 ? get_tx_type_4x4(xd, raster_block) : DCT_DCT;
- if (tx_type == DCT_DCT) {
+ if (tx_type == DCT_DCT)
// this is like vp9_short_idct4x4 but has a special case around eob<=1
// which is significant (not just an optimization) for the lossless
// case.
- vp9_inverse_transform_b_4x4_add(xd, xd->plane[plane].eobs[block],
- BLOCK_OFFSET(xd->plane[plane].dqcoeff, block, 16), dst,
- xd->plane[plane].dst.stride);
- } else {
- vp9_short_iht4x4_add(BLOCK_OFFSET(xd->plane[plane].dqcoeff, block, 16),
- dst, xd->plane[plane].dst.stride, tx_type);
- }
+ vp9_inverse_transform_b_4x4_add(xd, pd->eobs[block], dqcoeff,
+ dst, pd->dst.stride);
+ else
+ vp9_short_iht4x4_add(dqcoeff, dst, pd->dst.stride, tx_type);
break;
}
}
-void vp9_xform_quant_sby(VP9_COMMON *const cm, MACROBLOCK *x,
- BLOCK_SIZE_TYPE bsize) {
+void vp9_xform_quant_sby(VP9_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE_TYPE bsize) {
MACROBLOCKD* const xd = &x->e_mbd;
struct encode_b_args arg = {cm, x, NULL};
foreach_transformed_block_in_plane(xd, bsize, 0, xform_quant, &arg);
}
-void vp9_xform_quant_sbuv(VP9_COMMON *const cm, MACROBLOCK *x,
- BLOCK_SIZE_TYPE bsize) {
+void vp9_xform_quant_sbuv(VP9_COMMON *cm, MACROBLOCK *x,
+ BLOCK_SIZE_TYPE bsize) {
MACROBLOCKD* const xd = &x->e_mbd;
struct encode_b_args arg = {cm, x, NULL};
foreach_transformed_block_uv(xd, bsize, xform_quant, &arg);
}
-void vp9_encode_sby(VP9_COMMON *const cm, MACROBLOCK *x,
- BLOCK_SIZE_TYPE bsize) {
- MACROBLOCKD* const xd = &x->e_mbd;
+void vp9_encode_sby(VP9_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE_TYPE bsize) {
+ MACROBLOCKD *const xd = &x->e_mbd;
struct optimize_ctx ctx;
struct encode_b_args arg = {cm, x, &ctx};
@@ -617,9 +561,8 @@ void vp9_encode_sby(VP9_COMMON *const cm, MACROBLOCK *x,
foreach_transformed_block_in_plane(xd, bsize, 0, encode_block, &arg);
}
-void vp9_encode_sbuv(VP9_COMMON *const cm, MACROBLOCK *x,
- BLOCK_SIZE_TYPE bsize) {
- MACROBLOCKD* const xd = &x->e_mbd;
+void vp9_encode_sbuv(VP9_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE_TYPE bsize) {
+ MACROBLOCKD *const xd = &x->e_mbd;
struct optimize_ctx ctx;
struct encode_b_args arg = {cm, x, &ctx};
@@ -630,9 +573,8 @@ void vp9_encode_sbuv(VP9_COMMON *const cm, MACROBLOCK *x,
foreach_transformed_block_uv(xd, bsize, encode_block, &arg);
}
-void vp9_encode_sb(VP9_COMMON *const cm, MACROBLOCK *x,
- BLOCK_SIZE_TYPE bsize) {
- MACROBLOCKD* const xd = &x->e_mbd;
+void vp9_encode_sb(VP9_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE_TYPE bsize) {
+ MACROBLOCKD *const xd = &x->e_mbd;
struct optimize_ctx ctx;
struct encode_b_args arg = {cm, x, &ctx};
@@ -646,24 +588,24 @@ void vp9_encode_sb(VP9_COMMON *const cm, MACROBLOCK *x,
static void encode_block_intra(int plane, int block, BLOCK_SIZE_TYPE bsize,
int ss_txfrm_size, void *arg) {
struct encode_b_args* const args = arg;
- MACROBLOCK* const x = args->x;
- MACROBLOCKD* const xd = &x->e_mbd;
- MB_MODE_INFO* const mbmi = &xd->mode_info_context->mbmi;
+ MACROBLOCK *const x = args->x;
+ MACROBLOCKD *const xd = &x->e_mbd;
+ MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi;
const TX_SIZE tx_size = (TX_SIZE)(ss_txfrm_size / 2);
- const int bw = 4 << (b_width_log2(bsize) - xd->plane[plane].subsampling_x);
+ struct macroblock_plane *const p = &x->plane[plane];
+ struct macroblockd_plane *const pd = &xd->plane[plane];
+ int16_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block, 16);
+ const int bw = plane_block_width(bsize, pd);
const int raster_block = txfrm_block_to_raster_block(xd, bsize, plane,
block, ss_txfrm_size);
- uint8_t* const src =
- raster_block_offset_uint8(xd, bsize, plane, raster_block,
- x->plane[plane].src.buf,
- x->plane[plane].src.stride);
- uint8_t* const dst =
- raster_block_offset_uint8(xd, bsize, plane, raster_block,
- xd->plane[plane].dst.buf,
- xd->plane[plane].dst.stride);
- int16_t* const src_diff =
- raster_block_offset_int16(xd, bsize, plane,
- raster_block, x->plane[plane].src_diff);
+
+ uint8_t *const src = raster_block_offset_uint8(xd, bsize, plane, raster_block,
+ p->src.buf, p->src.stride);
+ uint8_t *const dst = raster_block_offset_uint8(xd, bsize, plane, raster_block,
+ pd->dst.buf, pd->dst.stride);
+ int16_t *const src_diff = raster_block_offset_int16(xd, bsize, plane,
+ raster_block,
+ p->src_diff);
const int txfm_b_size = 4 << tx_size;
int ib = raster_block;
@@ -674,7 +616,8 @@ static void encode_block_intra(int plane, int block, BLOCK_SIZE_TYPE bsize,
int mode, b_mode;
mode = plane == 0? mbmi->mode: mbmi->uv_mode;
- if (mbmi->sb_type < BLOCK_SIZE_SB8X8 && plane == 0 &&
+ if (plane == 0 &&
+ mbmi->sb_type < BLOCK_SIZE_SB8X8 &&
mbmi->ref_frame == INTRA_FRAME)
b_mode = xd->mode_info_context->bmi[ib].as_mode.first;
else
@@ -682,65 +625,52 @@ static void encode_block_intra(int plane, int block, BLOCK_SIZE_TYPE bsize,
assert(b_mode >= DC_PRED && b_mode <= TM_PRED);
- plane_b_size = b_width_log2(bsize) - xd->plane[plane].subsampling_x;
+ plane_b_size = b_width_log2(bsize) - pd->subsampling_x;
vp9_predict_intra_block(xd, tx_ib, plane_b_size, tx_size, b_mode,
- dst, xd->plane[plane].dst.stride);
- vp9_subtract_block(txfm_b_size, txfm_b_size,
- src_diff, bw,
- src, x->plane[plane].src.stride,
- dst, xd->plane[plane].dst.stride);
+ dst, pd->dst.stride);
+ vp9_subtract_block(txfm_b_size, txfm_b_size, src_diff, bw,
+ src, p->src.stride, dst, pd->dst.stride);
xform_quant(plane, block, bsize, ss_txfrm_size, arg);
- /*
- if (x->optimize)
- vp9_optimize_b(plane, block, bsize, ss_txfrm_size, args->cm, x, args->ctx);
- */
+
+ // if (x->optimize)
+ // vp9_optimize_b(plane, block, bsize, ss_txfrm_size,
+ // args->cm, x, args->ctx);
+
switch (ss_txfrm_size / 2) {
case TX_32X32:
- vp9_short_idct32x32_add(BLOCK_OFFSET(xd->plane[plane].dqcoeff,
- block, 16), dst, xd->plane[plane].dst.stride);
+ vp9_short_idct32x32_add(dqcoeff, dst, pd->dst.stride);
break;
case TX_16X16:
tx_type = plane == 0 ? get_tx_type_16x16(xd, raster_block) : DCT_DCT;
- if (tx_type == DCT_DCT) {
- vp9_short_idct16x16_add(BLOCK_OFFSET(xd->plane[plane].dqcoeff,
- block, 16), dst, xd->plane[plane].dst.stride);
- } else {
- vp9_short_iht16x16_add(BLOCK_OFFSET(xd->plane[plane].dqcoeff,
- block, 16), dst, xd->plane[plane].dst.stride,
- tx_type);
- }
+ if (tx_type == DCT_DCT)
+ vp9_short_idct16x16_add(dqcoeff, dst, pd->dst.stride);
+ else
+ vp9_short_iht16x16_add(dqcoeff, dst, pd->dst.stride, tx_type);
break;
case TX_8X8:
tx_type = plane == 0 ? get_tx_type_8x8(xd, raster_block) : DCT_DCT;
- if (tx_type == DCT_DCT) {
- vp9_short_idct8x8_add(BLOCK_OFFSET(xd->plane[plane].dqcoeff,
- block, 16), dst, xd->plane[plane].dst.stride);
- } else {
- vp9_short_iht8x8_add(BLOCK_OFFSET(xd->plane[plane].dqcoeff,
- block, 16), dst, xd->plane[plane].dst.stride,
- tx_type);
- }
+ if (tx_type == DCT_DCT)
+ vp9_short_idct8x8_add(dqcoeff, dst, pd->dst.stride);
+ else
+ vp9_short_iht8x8_add(dqcoeff, dst, pd->dst.stride, tx_type);
break;
case TX_4X4:
tx_type = plane == 0 ? get_tx_type_4x4(xd, raster_block) : DCT_DCT;
- if (tx_type == DCT_DCT) {
+ if (tx_type == DCT_DCT)
// this is like vp9_short_idct4x4 but has a special case around eob<=1
// which is significant (not just an optimization) for the lossless
// case.
- vp9_inverse_transform_b_4x4_add(xd, xd->plane[plane].eobs[block],
- BLOCK_OFFSET(xd->plane[plane].dqcoeff, block, 16), dst,
- xd->plane[plane].dst.stride);
- } else {
- vp9_short_iht4x4_add(BLOCK_OFFSET(xd->plane[plane].dqcoeff, block, 16),
- dst, xd->plane[plane].dst.stride, tx_type);
- }
+ vp9_inverse_transform_b_4x4_add(xd, pd->eobs[block], dqcoeff,
+ dst, pd->dst.stride);
+ else
+ vp9_short_iht4x4_add(dqcoeff, dst, pd->dst.stride, tx_type);
break;
}
}
-void vp9_encode_intra_block_y(VP9_COMMON *const cm, MACROBLOCK *x,
+void vp9_encode_intra_block_y(VP9_COMMON *cm, MACROBLOCK *x,
BLOCK_SIZE_TYPE bsize) {
MACROBLOCKD* const xd = &x->e_mbd;
struct optimize_ctx ctx;
@@ -749,7 +679,7 @@ void vp9_encode_intra_block_y(VP9_COMMON *const cm, MACROBLOCK *x,
foreach_transformed_block_in_plane(xd, bsize, 0,
encode_block_intra, &arg);
}
-void vp9_encode_intra_block_uv(VP9_COMMON *const cm, MACROBLOCK *x,
+void vp9_encode_intra_block_uv(VP9_COMMON *cm, MACROBLOCK *x,
BLOCK_SIZE_TYPE bsize) {
MACROBLOCKD* const xd = &x->e_mbd;
struct optimize_ctx ctx;
diff --git a/vp9/encoder/vp9_encodemb.h b/vp9/encoder/vp9_encodemb.h
index afbe4466b..579690346 100644
--- a/vp9/encoder/vp9_encodemb.h
+++ b/vp9/encoder/vp9_encodemb.h
@@ -26,25 +26,21 @@ struct optimize_ctx {
ENTROPY_CONTEXT ta[MAX_MB_PLANE][16];
ENTROPY_CONTEXT tl[MAX_MB_PLANE][16];
};
+
void vp9_optimize_init(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize,
struct optimize_ctx *ctx);
void vp9_optimize_b(int plane, int block, BLOCK_SIZE_TYPE bsize,
int ss_txfrm_size, VP9_COMMON *cm, MACROBLOCK *x,
struct optimize_ctx *ctx);
-void vp9_optimize_sby(VP9_COMMON *const cm, MACROBLOCK *x,
- BLOCK_SIZE_TYPE bsize);
-void vp9_optimize_sbuv(VP9_COMMON *const cm, MACROBLOCK *x,
- BLOCK_SIZE_TYPE bsize);
-
-void vp9_encode_sb(VP9_COMMON *const cm, MACROBLOCK *x, BLOCK_SIZE_TYPE bsize);
-void vp9_encode_sby(VP9_COMMON *const cm, MACROBLOCK *x, BLOCK_SIZE_TYPE bsize);
-void vp9_encode_sbuv(VP9_COMMON *const cm, MACROBLOCK *x,
- BLOCK_SIZE_TYPE bsize);
-
-void vp9_xform_quant_sby(VP9_COMMON *const cm, MACROBLOCK *x,
- BLOCK_SIZE_TYPE bsize);
-void vp9_xform_quant_sbuv(VP9_COMMON *const cm, MACROBLOCK *x,
- BLOCK_SIZE_TYPE bsize);
+void vp9_optimize_sby(VP9_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE_TYPE bsize);
+void vp9_optimize_sbuv(VP9_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE_TYPE bsize);
+
+void vp9_encode_sb(VP9_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE_TYPE bsize);
+void vp9_encode_sby(VP9_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE_TYPE bsize);
+void vp9_encode_sbuv(VP9_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE_TYPE bsize);
+
+void vp9_xform_quant_sby(VP9_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE_TYPE bsize);
+void vp9_xform_quant_sbuv(VP9_COMMON *cm, MACROBLOCK *x, BLOCK_SIZE_TYPE bsize);
void vp9_subtract_block(int rows, int cols,
int16_t *diff_ptr, int diff_stride,
diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c
index e61d212d7..a5659d628 100644
--- a/vp9/encoder/vp9_onyx_if.c
+++ b/vp9/encoder/vp9_onyx_if.c
@@ -267,9 +267,6 @@ static void setup_features(VP9_COMP *cpi) {
xd->update_mb_segmentation_map = 0;
xd->update_mb_segmentation_data = 0;
-#if CONFIG_IMPLICIT_SEGMENTATION
- xd->allow_implicit_segment_update = 0;
-#endif
vpx_memset(xd->mb_segment_tree_probs, 255, sizeof(xd->mb_segment_tree_probs));
vp9_clearall_segfeatures(xd);
@@ -354,9 +351,6 @@ static void configure_static_seg_features(VP9_COMP *cpi) {
vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
xd->update_mb_segmentation_map = 0;
xd->update_mb_segmentation_data = 0;
-#if CONFIG_IMPLICIT_SEGMENTATION
- xd->allow_implicit_segment_update = 0;
-#endif
cpi->static_mb_pct = 0;
// Disable segmentation
@@ -370,9 +364,6 @@ static void configure_static_seg_features(VP9_COMP *cpi) {
vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
xd->update_mb_segmentation_map = 0;
xd->update_mb_segmentation_data = 0;
-#if CONFIG_IMPLICIT_SEGMENTATION
- xd->allow_implicit_segment_update = 0;
-#endif
cpi->static_mb_pct = 0;
// Disable segmentation and individual segment features by default
@@ -471,59 +462,12 @@ static void configure_static_seg_features(VP9_COMP *cpi) {
}
}
-#if CONFIG_IMPLICIT_SEGMENTATION
-static double implict_seg_q_modifiers[MAX_MB_SEGMENTS] =
- {1.0, 0.95, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
-static void configure_implicit_segmentation(VP9_COMP *cpi, int frame_qindex) {
- VP9_COMMON *cm = &cpi->common;
- MACROBLOCKD *xd = &cpi->mb.e_mbd;
- int i;
- int qi_delta;
- double q_baseline = vp9_convert_qindex_to_q(frame_qindex);
-
- // Set the flags to allow implicit segment update but disallow explicit update
- xd->segmentation_enabled = 1;
- xd->allow_implicit_segment_update = 1;
- xd->update_mb_segmentation_map = 0;
-
- // For key frames clear down the segment map to a default state.
- if (cm->frame_type == KEY_FRAME) {
- // Clear down the global segmentation map
- vpx_memset(cpi->segmentation_map, 0, (cm->mb_rows * cm->mb_cols));
-
- // Clear down the segment features.
- vp9_clearall_segfeatures(xd);
-
- xd->update_mb_segmentation_data = 0;
-
- // Update the segment data if it is an arf or non overlay gf.
- } else if (cpi->refresh_alt_ref_frame ||
- (cpi->refresh_golden_frame && !cpi->is_src_frame_alt_ref)) {
- xd->update_mb_segmentation_data = 1;
-
- // Enable use of q deltas on segments 1 and up
- // Segment 0 is treated as a neutral segment with no changes
- for (i = 1; i < MAX_MB_SEGMENTS; ++i) {
- qi_delta = compute_qdelta(cpi, q_baseline,
- implict_seg_q_modifiers[i] * q_baseline);
- vp9_set_segdata(xd, i, SEG_LVL_ALT_Q, qi_delta);
- vp9_enable_segfeature(xd, i, SEG_LVL_ALT_Q);
- }
-
- // Where relevant assume segment data is delta data
- xd->mb_segment_abs_delta = SEGMENT_DELTADATA;
- } else {
- xd->update_mb_segmentation_data = 0;
- }
-}
-#endif
-
#ifdef ENTROPY_STATS
void vp9_update_mode_context_stats(VP9_COMP *cpi) {
VP9_COMMON *cm = &cpi->common;
int i, j;
- unsigned int (*mv_ref_ct)[4][2] = cm->fc.mv_ref_ct;
- int64_t (*mv_ref_stats)[4][2] = cpi->mv_ref_stats;
+ unsigned int (*mv_ref_ct)[VP9_MVREFS - 1][2] = cm->fc.mv_ref_ct;
+ int64_t (*mv_ref_stats)[VP9_MVREFS - 1][2] = cpi->mv_ref_stats;
FILE *f;
// Read the past stats counters
@@ -799,12 +743,8 @@ void vp9_set_speed_features(VP9_COMP *cpi) {
// Switch segmentation off.
sf->static_segmentation = 0;
#else
-#if CONFIG_IMPLICIT_SEGMENTATION
- sf->static_segmentation = 0;
-#else
sf->static_segmentation = 0;
#endif
-#endif
sf->mb16_breakout = 0;
switch (mode) {
@@ -817,13 +757,16 @@ void vp9_set_speed_features(VP9_COMP *cpi) {
// Switch segmentation off.
sf->static_segmentation = 0;
#else
-#if CONFIG_IMPLICIT_SEGMENTATION
- sf->static_segmentation = 0;
-#else
sf->static_segmentation = 0;
#endif
-#endif
sf->mb16_breakout = 0;
+
+ if (speed > 0) {
+ sf->optimize_coefficients = 0;
+ sf->no_skip_block4x4_search = 0;
+ sf->comp_inter_joint_search = 0;
+ sf->first_step = 1;
+ }
break;
}; /* switch */
@@ -2479,7 +2422,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
unsigned int *frame_flags) {
VP9_COMMON *cm = &cpi->common;
MACROBLOCKD *xd = &cpi->mb.e_mbd;
-
+ TX_SIZE t;
int q;
int frame_over_shoot_limit;
int frame_under_shoot_limit;
@@ -2907,12 +2850,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
}
}
-#if CONFIG_IMPLICIT_SEGMENTATION
- if (!cm->error_resilient_mode && !cpi->sf.static_segmentation) {
- configure_implicit_segmentation(cpi, q);
- }
-#endif
-
// transform / motion compensation build reconstruction frame
vp9_encode_frame(cpi);
@@ -3156,29 +3093,16 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
cpi->dummy_packing = 0;
vp9_pack_bitstream(cpi, dest, size);
-#if CONFIG_IMPLICIT_SEGMENTATION
- // Should we allow implicit update of the segment map.
- if (xd->allow_implicit_segment_update && !cm->error_resilient_mode) {
- vp9_implicit_segment_map_update(cm);
- // or has there been an explicit update
- } else if (xd->update_mb_segmentation_map) {
-#else
if (xd->update_mb_segmentation_map) {
-#endif
update_reference_segmentation_map(cpi);
}
release_scaled_references(cpi);
update_reference_frames(cpi);
- vp9_full_to_model_counts(cpi->common.fc.coef_counts_4x4,
- cpi->coef_counts_4x4);
- vp9_full_to_model_counts(cpi->common.fc.coef_counts_8x8,
- cpi->coef_counts_8x8);
- vp9_full_to_model_counts(cpi->common.fc.coef_counts_16x16,
- cpi->coef_counts_16x16);
- vp9_full_to_model_counts(cpi->common.fc.coef_counts_32x32,
- cpi->coef_counts_32x32);
+ for (t = TX_4X4; t <= TX_32X32; t++)
+ vp9_full_to_model_counts(cpi->common.fc.coef_counts[t],
+ cpi->coef_counts[t]);
if (!cpi->common.error_resilient_mode &&
!cpi->common.frame_parallel_decoding_mode) {
vp9_adapt_coef_probs(&cpi->common);
@@ -3516,6 +3440,8 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
cm->mode_info_stride * (cm->mi_rows + 1) *
sizeof(MODE_INFO));
}
+ // restore prev_mi
+ cm->prev_mi = cm->prev_mip + cm->mode_info_stride + 1;
}
static void Pass2Encode(VP9_COMP *cpi, unsigned long *size,
diff --git a/vp9/encoder/vp9_onyx_int.h b/vp9/encoder/vp9_onyx_int.h
index 9e259762d..dece45791 100644
--- a/vp9/encoder/vp9_onyx_int.h
+++ b/vp9/encoder/vp9_onyx_int.h
@@ -76,10 +76,7 @@ typedef struct {
// 0 = I4X4_PRED, ZERO_MV, MV, SPLIT
signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS];
- vp9_coeff_probs_model coef_probs_4x4[BLOCK_TYPES];
- vp9_coeff_probs_model coef_probs_8x8[BLOCK_TYPES];
- vp9_coeff_probs_model coef_probs_16x16[BLOCK_TYPES];
- vp9_coeff_probs_model coef_probs_32x32[BLOCK_TYPES];
+ vp9_coeff_probs_model coef_probs[TX_SIZE_MAX_SB][BLOCK_TYPES];
vp9_prob y_mode_prob[VP9_INTRA_MODES - 1]; /* interframe intra mode probs */
vp9_prob uv_mode_prob[VP9_INTRA_MODES][VP9_INTRA_MODES - 1];
@@ -414,21 +411,9 @@ typedef struct VP9_COMP {
nmv_context_counts NMVcount;
- vp9_coeff_count coef_counts_4x4[BLOCK_TYPES];
- vp9_coeff_probs_model frame_coef_probs_4x4[BLOCK_TYPES];
- vp9_coeff_stats frame_branch_ct_4x4[BLOCK_TYPES];
-
- vp9_coeff_count coef_counts_8x8[BLOCK_TYPES];
- vp9_coeff_probs_model frame_coef_probs_8x8[BLOCK_TYPES];
- vp9_coeff_stats frame_branch_ct_8x8[BLOCK_TYPES];
-
- vp9_coeff_count coef_counts_16x16[BLOCK_TYPES];
- vp9_coeff_probs_model frame_coef_probs_16x16[BLOCK_TYPES];
- vp9_coeff_stats frame_branch_ct_16x16[BLOCK_TYPES];
-
- vp9_coeff_count coef_counts_32x32[BLOCK_TYPES];
- vp9_coeff_probs_model frame_coef_probs_32x32[BLOCK_TYPES];
- vp9_coeff_stats frame_branch_ct_32x32[BLOCK_TYPES];
+ vp9_coeff_count coef_counts[TX_SIZE_MAX_SB][BLOCK_TYPES];
+ vp9_coeff_probs_model frame_coef_probs[TX_SIZE_MAX_SB][BLOCK_TYPES];
+ vp9_coeff_stats frame_branch_ct[TX_SIZE_MAX_SB][BLOCK_TYPES];
int gfu_boost;
int last_boost;
diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c
index f4426adaa..748c3a8d1 100644
--- a/vp9/encoder/vp9_ratectrl.c
+++ b/vp9/encoder/vp9_ratectrl.c
@@ -139,10 +139,7 @@ void vp9_save_coding_context(VP9_COMP *cpi) {
vp9_copy(cc->last_ref_lf_deltas, xd->last_ref_lf_deltas);
vp9_copy(cc->last_mode_lf_deltas, xd->last_mode_lf_deltas);
- vp9_copy(cc->coef_probs_4x4, cm->fc.coef_probs_4x4);
- vp9_copy(cc->coef_probs_8x8, cm->fc.coef_probs_8x8);
- vp9_copy(cc->coef_probs_16x16, cm->fc.coef_probs_16x16);
- vp9_copy(cc->coef_probs_32x32, cm->fc.coef_probs_32x32);
+ vp9_copy(cc->coef_probs, cm->fc.coef_probs);
vp9_copy(cc->switchable_interp_prob, cm->fc.switchable_interp_prob);
}
@@ -177,10 +174,7 @@ void vp9_restore_coding_context(VP9_COMP *cpi) {
vp9_copy(xd->last_ref_lf_deltas, cc->last_ref_lf_deltas);
vp9_copy(xd->last_mode_lf_deltas, cc->last_mode_lf_deltas);
- vp9_copy(cm->fc.coef_probs_4x4, cc->coef_probs_4x4);
- vp9_copy(cm->fc.coef_probs_8x8, cc->coef_probs_8x8);
- vp9_copy(cm->fc.coef_probs_16x16, cc->coef_probs_16x16);
- vp9_copy(cm->fc.coef_probs_32x32, cc->coef_probs_32x32);
+ vp9_copy(cm->fc.coef_probs, cc->coef_probs);
vp9_copy(cm->fc.switchable_interp_prob, cc->switchable_interp_prob);
}
diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c
index 22bd2d191..6a6473a56 100644
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -111,42 +111,33 @@ const MODE_DEFINITION vp9_mode_order[MAX_MODES] = {
{SPLITMV, GOLDEN_FRAME, ALTREF_FRAME},
};
-#if CONFIG_BALANCED_COEFTREE
-static void fill_token_costs(vp9_coeff_count *c,
- vp9_coeff_count *cnoskip,
- vp9_coeff_probs_model *p,
- TX_SIZE tx_size) {
+static void fill_token_costs(vp9_coeff_count (*c)[BLOCK_TYPES],
+ vp9_coeff_count (*cnoskip)[BLOCK_TYPES],
+ vp9_coeff_probs_model (*p)[BLOCK_TYPES]) {
int i, j, k, l;
- 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++) {
- vp9_prob probs[ENTROPY_NODES];
- vp9_model_to_full_probs(p[i][j][k][l], probs);
- vp9_cost_tokens((int *)cnoskip[i][j][k][l], probs,
- vp9_coef_tree);
- // Replace the eob node prob with a very small value so that the
- // cost approximately equals the cost without the eob node
- probs[1] = 1;
- vp9_cost_tokens((int *)c[i][j][k][l], probs, vp9_coef_tree);
- }
-}
+ TX_SIZE t;
+ for (t = TX_4X4; t <= TX_32X32; t++)
+ 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++) {
+ vp9_prob probs[ENTROPY_NODES];
+ vp9_model_to_full_probs(p[t][i][j][k][l], probs);
+ vp9_cost_tokens((int *)cnoskip[t][i][j][k][l], probs,
+ vp9_coef_tree);
+#if CONFIG_BALANCED_COEFTREE
+ // Replace the eob node prob with a very small value so that the
+ // cost approximately equals the cost without the eob node
+ probs[1] = 1;
+ vp9_cost_tokens((int *)c[t][i][j][k][l], probs, vp9_coef_tree);
#else
-static void fill_token_costs(vp9_coeff_count *c,
- vp9_coeff_probs_model *p,
- TX_SIZE tx_size) {
- int i, j, k, l;
- 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++) {
- vp9_prob probs[ENTROPY_NODES];
- vp9_model_to_full_probs(p[i][j][k][l], probs);
- vp9_cost_tokens_skip((int *)c[i][j][k][l], probs,
- vp9_coef_tree);
- }
-}
+ vp9_cost_tokens_skip((int *)c[t][i][j][k][l], probs,
+ vp9_coef_tree);
+ assert(c[t][i][j][k][l][DCT_EOB_TOKEN] ==
+ cnoskip[t][i][j][k][l][DCT_EOB_TOKEN]);
#endif
+ }
+}
static int rd_iifactor[32] = { 4, 4, 3, 2, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
@@ -237,29 +228,9 @@ void vp9_initialize_rd_consts(VP9_COMP *cpi, int qindex) {
}
}
-#if CONFIG_BALANCED_COEFTREE
- fill_token_costs(cpi->mb.token_costs[TX_4X4],
- cpi->mb.token_costs_noskip[TX_4X4],
- cpi->common.fc.coef_probs_4x4, TX_4X4);
- fill_token_costs(cpi->mb.token_costs[TX_8X8],
- cpi->mb.token_costs_noskip[TX_8X8],
- cpi->common.fc.coef_probs_8x8, TX_8X8);
- fill_token_costs(cpi->mb.token_costs[TX_16X16],
- cpi->mb.token_costs_noskip[TX_16X16],
- cpi->common.fc.coef_probs_16x16, TX_16X16);
- fill_token_costs(cpi->mb.token_costs[TX_32X32],
- cpi->mb.token_costs_noskip[TX_32X32],
- cpi->common.fc.coef_probs_32x32, TX_32X32);
-#else
- fill_token_costs(cpi->mb.token_costs[TX_4X4],
- cpi->common.fc.coef_probs_4x4, TX_4X4);
- fill_token_costs(cpi->mb.token_costs[TX_8X8],
- cpi->common.fc.coef_probs_8x8, TX_8X8);
- fill_token_costs(cpi->mb.token_costs[TX_16X16],
- cpi->common.fc.coef_probs_16x16, TX_16X16);
- fill_token_costs(cpi->mb.token_costs[TX_32X32],
- cpi->common.fc.coef_probs_32x32, TX_32X32);
-#endif
+ fill_token_costs(cpi->mb.token_costs,
+ cpi->mb.token_costs_noskip,
+ cpi->common.fc.coef_probs);
for (i = 0; i < NUM_PARTITION_CONTEXTS; i++)
vp9_cost_tokens(cpi->mb.partition_cost[i],
@@ -312,12 +283,8 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb,
TX_TYPE tx_type = DCT_DCT;
const int segment_id = xd->mode_info_context->mbmi.segment_id;
-#if CONFIG_BALANCED_COEFTREE
unsigned int (*token_costs_noskip)[PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS] =
mb->token_costs_noskip[tx_size][type][ref];
-#else
- vp9_prob coef_probs[COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES];
-#endif
int seg_eob, default_eob;
uint8_t token_cache[1024];
@@ -338,10 +305,6 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb,
get_tx_type_4x4(xd, block) : DCT_DCT;
above_ec = A[0] != 0;
left_ec = L[0] != 0;
-#if !CONFIG_BALANCED_COEFTREE
- vp9_model_to_full_probs_sb(cm->fc.coef_probs_4x4[type][ref],
- coef_probs);
-#endif
seg_eob = 16;
scan = get_scan_4x4(tx_type);
band_translate = vp9_coefband_trans_4x4;
@@ -356,10 +319,6 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb,
above_ec = (A[0] + A[1]) != 0;
left_ec = (L[0] + L[1]) != 0;
scan = get_scan_8x8(tx_type);
-#if !CONFIG_BALANCED_COEFTREE
- vp9_model_to_full_probs_sb(cm->fc.coef_probs_8x8[type][ref],
- coef_probs);
-#endif
seg_eob = 64;
band_translate = vp9_coefband_trans_8x8plus;
break;
@@ -371,10 +330,6 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb,
TX_TYPE tx_type = (type == PLANE_TYPE_Y_WITH_DC) ?
get_tx_type_16x16(xd, y + (x >> 2)) : DCT_DCT;
scan = get_scan_16x16(tx_type);
-#if !CONFIG_BALANCED_COEFTREE
- vp9_model_to_full_probs_sb(cm->fc.coef_probs_16x16[type][ref],
- coef_probs);
-#endif
seg_eob = 256;
above_ec = (A[0] + A[1] + A[2] + A[3]) != 0;
left_ec = (L[0] + L[1] + L[2] + L[3]) != 0;
@@ -383,10 +338,6 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb,
}
case TX_32X32:
scan = vp9_default_scan_32x32;
-#if !CONFIG_BALANCED_COEFTREE
- vp9_model_to_full_probs_sb(cm->fc.coef_probs_32x32[type][ref],
- coef_probs);
-#endif
seg_eob = 1024;
above_ec = (A[0] + A[1] + A[2] + A[3] + A[4] + A[5] + A[6] + A[7]) != 0;
left_ec = (L[0] + L[1] + L[2] + L[3] + L[4] + L[5] + L[6] + L[7]) != 0;
@@ -417,30 +368,18 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb,
if (c)
pt = vp9_get_coef_context(scan, nb, pad, token_cache, c, default_eob);
-#if CONFIG_BALANCED_COEFTREE
if (!c || token_cache[scan[c - 1]]) // do not skip eob
cost += token_costs_noskip[band][pt][t] + vp9_dct_value_cost_ptr[v];
else
cost += token_costs[band][pt][t] + vp9_dct_value_cost_ptr[v];
-#else
- cost += token_costs[band][pt][t] + vp9_dct_value_cost_ptr[v];
- if (!c || token_cache[scan[c - 1]])
- cost += vp9_cost_bit(coef_probs[band][pt][0], 1);
-#endif
token_cache[scan[c]] = vp9_pt_energy_class[t];
}
if (c < seg_eob) {
if (c)
pt = vp9_get_coef_context(scan, nb, pad, token_cache, c, default_eob);
-#if CONFIG_BALANCED_COEFTREE
cost += mb->token_costs_noskip[tx_size][type][ref]
[get_coef_band(band_translate, c)]
[pt][DCT_EOB_TOKEN];
-#else
- cost += mb->token_costs[tx_size][type][ref]
- [get_coef_band(band_translate, c)]
- [pt][DCT_EOB_TOKEN];
-#endif
}
}
@@ -1833,7 +1772,6 @@ static void setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x,
YV12_BUFFER_CONFIG *yv12 = &cm->yv12_fb[cpi->common.ref_frame_map[idx]];
MACROBLOCKD *const xd = &x->e_mbd;
MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi;
- int use_prev_in_find_mv_refs;
// set up scaling factors
scale[frame_type] = cpi->common.active_ref_scale[frame_type - 1];
@@ -1850,11 +1788,8 @@ static void setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x,
&scale[frame_type], &scale[frame_type]);
// Gets an initial list of candidate vectors from neighbours and orders them
- use_prev_in_find_mv_refs = cm->width == cm->last_width &&
- cm->height == cm->last_height &&
- !cpi->common.error_resilient_mode;
vp9_find_mv_refs(&cpi->common, xd, xd->mode_info_context,
- use_prev_in_find_mv_refs ? xd->prev_mode_info_context : NULL,
+ xd->prev_mode_info_context,
frame_type,
mbmi->ref_mvs[frame_type],
cpi->common.ref_frame_sign_bias);
@@ -1919,9 +1854,8 @@ static void model_rd_from_var_lapndz(int var, int n, int qstep,
static enum BlockSize get_plane_block_size(BLOCK_SIZE_TYPE bsize,
struct macroblockd_plane *pd) {
- const int bwl = b_width_log2(bsize) - pd->subsampling_x;
- const int bhl = b_height_log2(bsize) - pd->subsampling_y;
- return get_block_size(4 << bwl, 4 << bhl);
+ return get_block_size(plane_block_width(bsize, pd),
+ plane_block_height(bsize, pd));
}
static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE_TYPE bsize,
@@ -1938,14 +1872,13 @@ static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE_TYPE bsize,
struct macroblockd_plane *const pd = &xd->plane[i];
// TODO(dkovalev) the same code in get_plane_block_size
- const int bwl = b_width_log2(bsize) - pd->subsampling_x;
- const int bhl = b_height_log2(bsize) - pd->subsampling_y;
- const enum BlockSize bs = get_block_size(4 << bwl, 4 << bhl);
+ const int bw = plane_block_width(bsize, pd);
+ const int bh = plane_block_height(bsize, pd);
+ const enum BlockSize bs = get_block_size(bw, bh);
int rate, dist;
var = cpi->fn_ptr[bs].vf(p->src.buf, p->src.stride,
pd->dst.buf, pd->dst.stride, &sse);
- model_rd_from_var_lapndz(var, 16 << (bwl + bhl),
- pd->dequant[1] >> 3, &rate, &dist);
+ model_rd_from_var_lapndz(var, bw * bh, pd->dequant[1] >> 3, &rate, &dist);
rate_sum += rate;
dist_sum += dist;
diff --git a/vp9/encoder/vp9_tokenize.c b/vp9/encoder/vp9_tokenize.c
index 79f72bb4b..3d8390b08 100644
--- a/vp9/encoder/vp9_tokenize.c
+++ b/vp9/encoder/vp9_tokenize.c
@@ -25,15 +25,8 @@
compressions, then generating vp9_context.c = initial stats. */
#ifdef ENTROPY_STATS
-vp9_coeff_accum context_counters_4x4[BLOCK_TYPES];
-vp9_coeff_accum context_counters_8x8[BLOCK_TYPES];
-vp9_coeff_accum context_counters_16x16[BLOCK_TYPES];
-vp9_coeff_accum context_counters_32x32[BLOCK_TYPES];
-
-extern vp9_coeff_stats tree_update_hist_4x4[BLOCK_TYPES];
-extern vp9_coeff_stats tree_update_hist_8x8[BLOCK_TYPES];
-extern vp9_coeff_stats tree_update_hist_16x16[BLOCK_TYPES];
-extern vp9_coeff_stats tree_update_hist_32x32[BLOCK_TYPES];
+vp9_coeff_accum context_counters[TX_SIZE_MAX_SB][BLOCK_TYPES];
+extern vp9_coeff_stats tree_update_hist[TX_SIZE_MAX_SB][BLOCK_TYPES];
#endif /* ENTROPY_STATS */
DECLARE_ALIGNED(16, extern const uint8_t,
@@ -143,6 +136,8 @@ static void tokenize_b(int plane, int block, BLOCK_SIZE_TYPE bsize,
const uint8_t * band_translate;
assert((!type && !plane) || (type && plane));
+ counts = cpi->coef_counts[tx_size];
+ coef_probs = cpi->common.fc.coef_probs[tx_size];
switch (tx_size) {
default:
case TX_4X4: {
@@ -152,8 +147,6 @@ static void tokenize_b(int plane, int block, BLOCK_SIZE_TYPE bsize,
left_ec = L[0] != 0;
seg_eob = 16;
scan = get_scan_4x4(tx_type);
- counts = cpi->coef_counts_4x4;
- coef_probs = cpi->common.fc.coef_probs_4x4;
band_translate = vp9_coefband_trans_4x4;
break;
}
@@ -166,8 +159,6 @@ static void tokenize_b(int plane, int block, BLOCK_SIZE_TYPE bsize,
left_ec = (L[0] + L[1]) != 0;
seg_eob = 64;
scan = get_scan_8x8(tx_type);
- counts = cpi->coef_counts_8x8;
- coef_probs = cpi->common.fc.coef_probs_8x8;
band_translate = vp9_coefband_trans_8x8plus;
break;
}
@@ -180,8 +171,6 @@ static void tokenize_b(int plane, int block, BLOCK_SIZE_TYPE bsize,
left_ec = (L[0] + L[1] + L[2] + L[3]) != 0;
seg_eob = 256;
scan = get_scan_16x16(tx_type);
- counts = cpi->coef_counts_16x16;
- coef_probs = cpi->common.fc.coef_probs_16x16;
band_translate = vp9_coefband_trans_8x8plus;
break;
}
@@ -190,8 +179,6 @@ static void tokenize_b(int plane, int block, BLOCK_SIZE_TYPE bsize,
left_ec = (L[0] + L[1] + L[2] + L[3] + L[4] + L[5] + L[6] + L[7]) != 0;
seg_eob = 1024;
scan = vp9_default_scan_32x32;
- counts = cpi->coef_counts_32x32;
- coef_probs = cpi->common.fc.coef_probs_32x32;
band_translate = vp9_coefband_trans_8x8plus;
break;
}
@@ -322,29 +309,17 @@ void vp9_tokenize_sb(VP9_COMP *cpi,
void init_context_counters(void) {
FILE *f = fopen("context.bin", "rb");
if (!f) {
- vpx_memset(context_counters_4x4, 0, sizeof(context_counters_4x4));
- vpx_memset(context_counters_8x8, 0, sizeof(context_counters_8x8));
- vpx_memset(context_counters_16x16, 0, sizeof(context_counters_16x16));
- vpx_memset(context_counters_32x32, 0, sizeof(context_counters_32x32));
+ vp9_zero(context_counters);
} else {
- fread(context_counters_4x4, sizeof(context_counters_4x4), 1, f);
- fread(context_counters_8x8, sizeof(context_counters_8x8), 1, f);
- fread(context_counters_16x16, sizeof(context_counters_16x16), 1, f);
- fread(context_counters_32x32, sizeof(context_counters_32x32), 1, f);
+ fread(context_counters, sizeof(context_counters), 1, f);
fclose(f);
}
f = fopen("treeupdate.bin", "rb");
if (!f) {
- vpx_memset(tree_update_hist_4x4, 0, sizeof(tree_update_hist_4x4));
- vpx_memset(tree_update_hist_8x8, 0, sizeof(tree_update_hist_8x8));
- vpx_memset(tree_update_hist_16x16, 0, sizeof(tree_update_hist_16x16));
- vpx_memset(tree_update_hist_32x32, 0, sizeof(tree_update_hist_32x32));
+ vpx_memset(tree_update_hist, 0, sizeof(tree_update_hist));
} else {
- fread(tree_update_hist_4x4, sizeof(tree_update_hist_4x4), 1, f);
- fread(tree_update_hist_8x8, sizeof(tree_update_hist_8x8), 1, f);
- fread(tree_update_hist_16x16, sizeof(tree_update_hist_16x16), 1, f);
- fread(tree_update_hist_32x32, sizeof(tree_update_hist_32x32), 1, f);
+ fread(tree_update_hist, sizeof(tree_update_hist), 1, f);
fclose(f);
}
}
@@ -446,32 +421,29 @@ void print_context_counters() {
fprintf(f, "\n/* *** GENERATED FILE: DO NOT EDIT *** */\n\n");
/* print counts */
- print_counter(f, context_counters_4x4, BLOCK_TYPES,
+ print_counter(f, context_counters[TX_4X4], BLOCK_TYPES,
"vp9_default_coef_counts_4x4[BLOCK_TYPES]");
- print_counter(f, context_counters_8x8, BLOCK_TYPES,
+ print_counter(f, context_counters[TX_8X8], BLOCK_TYPES,
"vp9_default_coef_counts_8x8[BLOCK_TYPES]");
- print_counter(f, context_counters_16x16, BLOCK_TYPES,
+ print_counter(f, context_counters[TX_16X16], BLOCK_TYPES,
"vp9_default_coef_counts_16x16[BLOCK_TYPES]");
- print_counter(f, context_counters_32x32, BLOCK_TYPES,
+ print_counter(f, context_counters[TX_32X32], BLOCK_TYPES,
"vp9_default_coef_counts_32x32[BLOCK_TYPES]");
/* print coefficient probabilities */
- print_probs(f, context_counters_4x4, BLOCK_TYPES,
+ print_probs(f, context_counters[TX_4X4], BLOCK_TYPES,
"default_coef_probs_4x4[BLOCK_TYPES]");
- print_probs(f, context_counters_8x8, BLOCK_TYPES,
+ print_probs(f, context_counters[TX_8X8], BLOCK_TYPES,
"default_coef_probs_8x8[BLOCK_TYPES]");
- print_probs(f, context_counters_16x16, BLOCK_TYPES,
+ print_probs(f, context_counters[TX_16X16], BLOCK_TYPES,
"default_coef_probs_16x16[BLOCK_TYPES]");
- print_probs(f, context_counters_32x32, BLOCK_TYPES,
+ print_probs(f, context_counters[TX_32X32], BLOCK_TYPES,
"default_coef_probs_32x32[BLOCK_TYPES]");
fclose(f);
f = fopen("context.bin", "wb");
- fwrite(context_counters_4x4, sizeof(context_counters_4x4), 1, f);
- fwrite(context_counters_8x8, sizeof(context_counters_8x8), 1, f);
- fwrite(context_counters_16x16, sizeof(context_counters_16x16), 1, f);
- fwrite(context_counters_32x32, sizeof(context_counters_32x32), 1, f);
+ fwrite(context_counters, sizeof(context_counters), 1, f);
fclose(f);
}
#endif
diff --git a/vp9/encoder/vp9_tokenize.h b/vp9/encoder/vp9_tokenize.h
index 08236c429..e7f90c96c 100644
--- a/vp9/encoder/vp9_tokenize.h
+++ b/vp9/encoder/vp9_tokenize.h
@@ -43,10 +43,7 @@ void vp9_tokenize_sb(struct VP9_COMP *cpi, MACROBLOCKD *xd,
void init_context_counters();
void print_context_counters();
-extern vp9_coeff_accum context_counters_4x4[BLOCK_TYPES];
-extern vp9_coeff_accum context_counters_8x8[BLOCK_TYPES];
-extern vp9_coeff_accum context_counters_16x16[BLOCK_TYPES];
-extern vp9_coeff_accum context_counters_32x32[BLOCK_TYPES];
+extern vp9_coeff_accum context_counters[TX_SIZE_MAX_SB][BLOCK_TYPES];
#endif
extern const int *vp9_dct_value_cost_ptr;