summaryrefslogtreecommitdiff
path: root/vp9
diff options
context:
space:
mode:
Diffstat (limited to 'vp9')
-rw-r--r--vp9/common/vp9_blockd.h46
-rw-r--r--vp9/common/vp9_entropy.c49
-rw-r--r--vp9/common/vp9_entropymode.c2
-rw-r--r--vp9/common/vp9_findnearmv.c8
-rw-r--r--vp9/common/vp9_onyxc_int.h26
-rw-r--r--vp9/common/vp9_reconinter.c31
-rw-r--r--vp9/common/vp9_reconintra.c21
-rw-r--r--vp9/common/vp9_seg_common.c79
-rw-r--r--vp9/common/vp9_seg_common.h5
-rw-r--r--vp9/decoder/vp9_decodemv.c15
-rw-r--r--vp9/decoder/vp9_decodframe.c45
-rw-r--r--vp9/decoder/vp9_detokenize.c10
-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
23 files changed, 372 insertions, 851 deletions
diff --git a/vp9/common/vp9_blockd.h b/vp9/common/vp9_blockd.h
index 1b6ed68d8..bc3416ec2 100644
--- a/vp9/common/vp9_blockd.h
+++ b/vp9/common/vp9_blockd.h
@@ -243,12 +243,9 @@ struct scale_factors {
int (*scale_value_x)(int val, const struct scale_factors *scale);
int (*scale_value_y)(int val, const struct scale_factors *scale);
void (*set_scaled_offsets)(struct scale_factors *scale, int row, int col);
- int_mv32 (*scale_motion_vector_q3_to_q4)(const int_mv *src_mv,
- const struct scale_factors *scale);
- int32_t (*scale_motion_vector_component_q4)(int mv_q4,
- int num,
- int den,
- int offset_q4);
+ int_mv32 (*scale_mv_q3_to_q4)(const int_mv *src_mv,
+ const struct scale_factors *scale);
+ int32_t (*scale_mv_component_q4)(int mv_q4, int num, int den, int offset_q4);
convolve_fn_t predict[2][2][2]; // horiz, vert, avg
};
@@ -306,10 +303,6 @@ typedef struct macroblockd {
/* 0 (do not update) 1 (update) the macroblock segmentation map. */
unsigned char update_mb_segmentation_map;
-#if CONFIG_IMPLICIT_SEGMENTATION
- unsigned char allow_implicit_segment_update;
-#endif
-
/* 0 (do not update) 1 (update) the macroblock segmentation feature data. */
unsigned char update_mb_segmentation_data;
@@ -615,6 +608,16 @@ static INLINE struct plane_block_idx plane_block_idx(int y_blocks,
return res;
}
+static INLINE int plane_block_width(BLOCK_SIZE_TYPE bsize,
+ const struct macroblockd_plane* plane) {
+ return 4 << (b_width_log2(bsize) - plane->subsampling_x);
+}
+
+static INLINE int plane_block_height(BLOCK_SIZE_TYPE bsize,
+ const struct macroblockd_plane* plane) {
+ return 4 << (b_height_log2(bsize) - plane->subsampling_y);
+}
+
typedef void (*foreach_transformed_block_visitor)(int plane, int block,
BLOCK_SIZE_TYPE bsize,
int ss_txfrm_size,
@@ -685,8 +688,8 @@ static INLINE void foreach_predicted_block_in_plane(
// block sizes in number of 4x4 blocks log 2 ("*_b")
// 4x4=0, 8x8=2, 16x16=4, 32x32=6, 64x64=8
// subsampled size of the block
- const int bw = b_width_log2(bsize) - xd->plane[plane].subsampling_x;
- const int bh = b_height_log2(bsize) - xd->plane[plane].subsampling_y;
+ const int bwl = b_width_log2(bsize) - xd->plane[plane].subsampling_x;
+ const int bhl = b_height_log2(bsize) - xd->plane[plane].subsampling_y;
// size of the predictor to use.
int pred_w, pred_h;
@@ -696,21 +699,20 @@ static INLINE void foreach_predicted_block_in_plane(
pred_w = 0;
pred_h = 0;
} else {
- pred_w = bw;
- pred_h = bh;
+ pred_w = bwl;
+ pred_h = bhl;
}
- assert(pred_w <= bw);
- assert(pred_h <= bh);
+ assert(pred_w <= bwl);
+ assert(pred_h <= bhl);
// visit each subblock in raster order
i = 0;
- for (y = 0; y < 1 << bh; y += 1 << pred_h) {
- for (x = 0; x < 1 << bw; x += 1 << pred_w) {
+ for (y = 0; y < 1 << bhl; y += 1 << pred_h) {
+ for (x = 0; x < 1 << bwl; x += 1 << pred_w) {
visit(plane, i, bsize, pred_w, pred_h, arg);
i += 1 << pred_w;
}
- i -= 1 << bw;
- i += 1 << (bw + pred_h);
+ i += (1 << (bwl + pred_h)) - (1 << bwl);
}
}
static INLINE void foreach_predicted_block(
@@ -740,8 +742,7 @@ static int raster_block_offset(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize,
static int16_t* raster_block_offset_int16(MACROBLOCKD *xd,
BLOCK_SIZE_TYPE bsize,
int plane, int block, int16_t *base) {
- const int bw = b_width_log2(bsize) - xd->plane[plane].subsampling_x;
- const int stride = 4 << bw;
+ const int stride = plane_block_width(bsize, &xd->plane[plane]);
return base + raster_block_offset(xd, bsize, plane, block, stride);
}
static uint8_t* raster_block_offset_uint8(MACROBLOCKD *xd,
@@ -778,5 +779,4 @@ static void txfrm_block_to_raster_xy(MACROBLOCKD *xd,
*x = (raster_mb & (tx_cols - 1)) << (txwl);
*y = raster_mb >> tx_cols_lg2 << (txwl);
}
-
#endif // VP9_COMMON_VP9_BLOCKD_H_
diff --git a/vp9/common/vp9_entropy.c b/vp9/common/vp9_entropy.c
index 5a1e91a9d..1dceb9d65 100644
--- a/vp9/common/vp9_entropy.c
+++ b/vp9/common/vp9_entropy.c
@@ -483,14 +483,14 @@ int vp9_get_coef_context(const int *scan, const int *neighbors,
};
void vp9_default_coef_probs(VP9_COMMON *pc) {
- vpx_memcpy(pc->fc.coef_probs_4x4, default_coef_probs_4x4,
- sizeof(pc->fc.coef_probs_4x4));
- vpx_memcpy(pc->fc.coef_probs_8x8, default_coef_probs_8x8,
- sizeof(pc->fc.coef_probs_8x8));
- vpx_memcpy(pc->fc.coef_probs_16x16, default_coef_probs_16x16,
- sizeof(pc->fc.coef_probs_16x16));
- vpx_memcpy(pc->fc.coef_probs_32x32, default_coef_probs_32x32,
- sizeof(pc->fc.coef_probs_32x32));
+ vpx_memcpy(pc->fc.coef_probs[TX_4X4], default_coef_probs_4x4,
+ sizeof(pc->fc.coef_probs[TX_4X4]));
+ vpx_memcpy(pc->fc.coef_probs[TX_8X8], default_coef_probs_8x8,
+ sizeof(pc->fc.coef_probs[TX_8X8]));
+ vpx_memcpy(pc->fc.coef_probs[TX_16X16], default_coef_probs_16x16,
+ sizeof(pc->fc.coef_probs[TX_16X16]));
+ vpx_memcpy(pc->fc.coef_probs[TX_32X32], default_coef_probs_32x32,
+ sizeof(pc->fc.coef_probs[TX_32X32]));
}
// Neighborhood 5-tuples for various scans and blocksizes,
@@ -677,13 +677,13 @@ void vp9_full_to_model_counts(
}
}
-static void adapt_coef_probs(
- vp9_coeff_probs_model *dst_coef_probs,
- vp9_coeff_probs_model *pre_coef_probs,
- vp9_coeff_count_model *coef_counts,
- unsigned int (*eob_branch_count)[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS],
- int count_sat,
- int update_factor) {
+static void adapt_coef_probs(VP9_COMMON *cm, TX_SIZE txfm_size,
+ int count_sat, int update_factor) {
+ vp9_coeff_probs_model *dst_coef_probs = cm->fc.coef_probs[txfm_size];
+ vp9_coeff_probs_model *pre_coef_probs = cm->fc.pre_coef_probs[txfm_size];
+ vp9_coeff_count_model *coef_counts = cm->fc.coef_counts[txfm_size];
+ unsigned int (*eob_branch_count)[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS] =
+ cm->fc.eob_branch_counts[txfm_size];
int t, i, j, k, l, count;
int factor;
unsigned int branch_ct[UNCONSTRAINED_NODES][2];
@@ -719,6 +719,7 @@ static void adapt_coef_probs(
}
void vp9_adapt_coef_probs(VP9_COMMON *cm) {
+ TX_SIZE t;
int count_sat;
int update_factor; /* denominator 256 */
@@ -732,20 +733,6 @@ void vp9_adapt_coef_probs(VP9_COMMON *cm) {
update_factor = COEF_MAX_UPDATE_FACTOR;
count_sat = COEF_COUNT_SAT;
}
- adapt_coef_probs(cm->fc.coef_probs_4x4, cm->fc.pre_coef_probs_4x4,
- cm->fc.coef_counts_4x4,
- cm->fc.eob_branch_counts[TX_4X4],
- count_sat, update_factor);
- adapt_coef_probs(cm->fc.coef_probs_8x8, cm->fc.pre_coef_probs_8x8,
- cm->fc.coef_counts_8x8,
- cm->fc.eob_branch_counts[TX_8X8],
- count_sat, update_factor);
- adapt_coef_probs(cm->fc.coef_probs_16x16, cm->fc.pre_coef_probs_16x16,
- cm->fc.coef_counts_16x16,
- cm->fc.eob_branch_counts[TX_16X16],
- count_sat, update_factor);
- adapt_coef_probs(cm->fc.coef_probs_32x32, cm->fc.pre_coef_probs_32x32,
- cm->fc.coef_counts_32x32,
- cm->fc.eob_branch_counts[TX_32X32],
- count_sat, update_factor);
+ for (t = TX_4X4; t <= TX_32X32; t++)
+ adapt_coef_probs(cm, t, count_sat, update_factor);
}
diff --git a/vp9/common/vp9_entropymode.c b/vp9/common/vp9_entropymode.c
index c823bf4c9..0274b4d05 100644
--- a/vp9/common/vp9_entropymode.c
+++ b/vp9/common/vp9_entropymode.c
@@ -205,7 +205,7 @@ void vp9_adapt_mode_context(VP9_COMMON *pc) {
int (*mode_context)[VP9_MVREFS - 1] = pc->fc.vp9_mode_contexts;
for (j = 0; j < INTER_MODE_CONTEXTS; j++) {
- for (i = 0; i < 4; i++) {
+ for (i = 0; i < VP9_MVREFS - 1; i++) {
int count = mv_ref_ct[j][i][0] + mv_ref_ct[j][i][1], factor;
count = count > MVREF_COUNT_SAT ? MVREF_COUNT_SAT : count;
diff --git a/vp9/common/vp9_findnearmv.c b/vp9/common/vp9_findnearmv.c
index cf54bc158..9df6ce141 100644
--- a/vp9/common/vp9_findnearmv.c
+++ b/vp9/common/vp9_findnearmv.c
@@ -53,18 +53,12 @@ void vp9_append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd,
int_mv mv_list[MAX_MV_REF_CANDIDATES];
MODE_INFO *mi = xd->mode_info_context;
MB_MODE_INFO *const mbmi = &mi->mbmi;
- int use_prev_in_find_mv_refs;
assert(ref_idx == 0 || ref_idx == 1);
assert(MAX_MV_REF_CANDIDATES == 2); // makes code here slightly easier
- use_prev_in_find_mv_refs = cm->width == cm->last_width &&
- cm->height == cm->last_height &&
- !cm->error_resilient_mode &&
- cm->last_show_frame;
vp9_find_mv_refs_idx(cm, xd, xd->mode_info_context,
- use_prev_in_find_mv_refs ?
- xd->prev_mode_info_context : NULL,
+ xd->prev_mode_info_context,
ref_idx ? mbmi->second_ref_frame : mbmi->ref_frame,
mv_list, cm->ref_frame_sign_bias, block_idx);
diff --git a/vp9/common/vp9_onyxc_int.h b/vp9/common/vp9_onyxc_int.h
index 3800884e0..cbe010a12 100644
--- a/vp9/common/vp9_onyxc_int.h
+++ b/vp9/common/vp9_onyxc_int.h
@@ -62,18 +62,9 @@ typedef struct frame_contexts {
unsigned int uv_mode_counts[VP9_INTRA_MODES][VP9_INTRA_MODES];
unsigned int partition_counts[NUM_PARTITION_CONTEXTS][PARTITION_TYPES];
- 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 pre_coef_probs_4x4[BLOCK_TYPES];
- vp9_coeff_probs_model pre_coef_probs_8x8[BLOCK_TYPES];
- vp9_coeff_probs_model pre_coef_probs_16x16[BLOCK_TYPES];
- vp9_coeff_probs_model pre_coef_probs_32x32[BLOCK_TYPES];
- vp9_coeff_count_model coef_counts_4x4[BLOCK_TYPES];
- vp9_coeff_count_model coef_counts_8x8[BLOCK_TYPES];
- vp9_coeff_count_model coef_counts_16x16[BLOCK_TYPES];
- vp9_coeff_count_model coef_counts_32x32[BLOCK_TYPES];
+ vp9_coeff_probs_model coef_probs[TX_SIZE_MAX_SB][BLOCK_TYPES];
+ vp9_coeff_probs_model pre_coef_probs[TX_SIZE_MAX_SB][BLOCK_TYPES];
+ vp9_coeff_count_model coef_counts[TX_SIZE_MAX_SB][BLOCK_TYPES];
unsigned int eob_branch_counts[TX_SIZE_MAX_SB][BLOCK_TYPES][REF_TYPES]
[COEF_BANDS][PREV_COEF_CONTEXTS];
@@ -327,4 +318,15 @@ static int get_mi_col(const MACROBLOCKD *xd) {
static int get_token_alloc(int mb_rows, int mb_cols) {
return mb_rows * mb_cols * (48 * 16 + 4);
}
+
+static void set_prev_mi(VP9_COMMON *cm) {
+ const int use_prev_in_find_mv_refs = cm->width == cm->last_width &&
+ cm->height == cm->last_height &&
+ !cm->error_resilient_mode &&
+ cm->last_show_frame;
+ // Special case: set prev_mi to NULL when the previous mode info
+ // context cannot be used.
+ cm->prev_mi = use_prev_in_find_mv_refs ?
+ cm->prev_mip + cm->mode_info_stride + 1 : NULL;
+}
#endif // VP9_COMMON_VP9_ONYXC_INT_H_
diff --git a/vp9/common/vp9_reconinter.c b/vp9/common/vp9_reconinter.c
index 2bc9c10a2..679cc7d48 100644
--- a/vp9/common/vp9_reconinter.c
+++ b/vp9/common/vp9_reconinter.c
@@ -106,14 +106,14 @@ void vp9_setup_scale_factors_for_frame(struct scale_factors *scale,
scale->scale_value_x = unscaled_value;
scale->scale_value_y = unscaled_value;
scale->set_scaled_offsets = set_offsets_without_scaling;
- scale->scale_motion_vector_q3_to_q4 = mv_q3_to_q4_without_scaling;
- scale->scale_motion_vector_component_q4 = mv_component_q4_without_scaling;
+ scale->scale_mv_q3_to_q4 = mv_q3_to_q4_without_scaling;
+ scale->scale_mv_component_q4 = mv_component_q4_without_scaling;
} else {
scale->scale_value_x = scale_value_x_with_scaling;
scale->scale_value_y = scale_value_y_with_scaling;
scale->set_scaled_offsets = set_offsets_with_scaling;
- scale->scale_motion_vector_q3_to_q4 = mv_q3_to_q4_with_scaling;
- scale->scale_motion_vector_component_q4 = mv_component_q4_with_scaling;
+ scale->scale_mv_q3_to_q4 = mv_q3_to_q4_with_scaling;
+ scale->scale_mv_component_q4 = mv_component_q4_with_scaling;
}
// TODO(agrange): Investigate the best choice of functions to use here
@@ -287,7 +287,7 @@ void vp9_build_inter_predictor(const uint8_t *src, int src_stride,
const struct scale_factors *scale,
int w, int h, int weight,
const struct subpix_fn_table *subpix) {
- int_mv32 mv = scale->scale_motion_vector_q3_to_q4(mv_q3, scale);
+ int_mv32 mv = scale->scale_mv_q3_to_q4(mv_q3, scale);
src += (mv.as_mv.row >> 4) * src_stride + (mv.as_mv.col >> 4);
scale->predict[!!(mv.as_mv.col & 15)][!!(mv.as_mv.row & 15)][weight](
src, src_stride, dst, dst_stride,
@@ -302,14 +302,14 @@ void vp9_build_inter_predictor_q4(const uint8_t *src, int src_stride,
const struct scale_factors *scale,
int w, int h, int weight,
const struct subpix_fn_table *subpix) {
- const int scaled_mv_row_q4 =
- scale->scale_motion_vector_component_q4(mv_q4->as_mv.row,
- scale->y_num, scale->y_den,
- scale->y_offset_q4);
- const int scaled_mv_col_q4 =
- scale->scale_motion_vector_component_q4(mv_q4->as_mv.col,
- scale->x_num, scale->x_den,
- scale->x_offset_q4);
+ const int scaled_mv_row_q4 = scale->scale_mv_component_q4(mv_q4->as_mv.row,
+ scale->y_num,
+ scale->y_den,
+ scale->y_offset_q4);
+ const int scaled_mv_col_q4 = scale->scale_mv_component_q4(mv_q4->as_mv.col,
+ scale->x_num,
+ scale->x_den,
+ scale->x_offset_q4);
const int subpel_x = scaled_mv_col_q4 & 15;
const int subpel_y = scaled_mv_row_q4 & 15;
@@ -384,9 +384,8 @@ static void build_inter_predictors(int plane, int block,
MACROBLOCKD * const xd = arg->xd;
const int bwl = b_width_log2(bsize) - xd->plane[plane].subsampling_x;
const int bhl = b_height_log2(bsize) - xd->plane[plane].subsampling_y;
- const int bh = 4 << bhl, bw = 4 << bwl;
- const int x_idx = block & ((1 << bwl) - 1), y_idx = block >> bwl;
- const int x = x_idx * 4, y = y_idx * 4;
+ const int bh = 4 << bhl, bw = 4 << bwl;
+ const int x = 4 * (block & ((1 << bwl) - 1)), y = 4 * (block >> bwl);
const int use_second_ref = xd->mode_info_context->mbmi.second_ref_frame > 0;
int which_mv;
diff --git a/vp9/common/vp9_reconintra.c b/vp9/common/vp9_reconintra.c
index b1f327b43..4a4634b63 100644
--- a/vp9/common/vp9_reconintra.c
+++ b/vp9/common/vp9_reconintra.c
@@ -362,14 +362,13 @@ void vp9_build_intra_predictors(uint8_t *src, int src_stride,
void vp9_build_intra_predictors_sby_s(MACROBLOCKD *xd,
BLOCK_SIZE_TYPE bsize) {
- const int bwl = b_width_log2(bsize), bw = 4 << bwl;
- const int bhl = b_height_log2(bsize), bh = 4 << bhl;
-
- vp9_build_intra_predictors(xd->plane[0].dst.buf, xd->plane[0].dst.stride,
- xd->plane[0].dst.buf, xd->plane[0].dst.stride,
+ const struct macroblockd_plane* const pd = &xd->plane[0];
+ const int bw = plane_block_width(bsize, pd);
+ const int bh = plane_block_height(bsize, pd);
+ vp9_build_intra_predictors(pd->dst.buf, pd->dst.stride,
+ pd->dst.buf, pd->dst.stride,
xd->mode_info_context->mbmi.mode,
- bw, bh,
- xd->up_available, xd->left_available,
+ bw, bh, xd->up_available, xd->left_available,
0 /*xd->right_available*/);
}
@@ -398,11 +397,9 @@ void vp9_predict_intra_block(MACROBLOCKD *xd,
uint8_t *predictor, int pre_stride) {
const int bwl = bwl_in - tx_size;
const int wmask = (1 << bwl) - 1;
- const int have_top =
- (block_idx >> bwl) || xd->up_available;
- const int have_left =
- (block_idx & wmask) || xd->left_available;
- int have_right = ((block_idx & wmask) != wmask);
+ const int have_top = (block_idx >> bwl) || xd->up_available;
+ const int have_left = (block_idx & wmask) || xd->left_available;
+ const int have_right = ((block_idx & wmask) != wmask);
const int txfm_block_size = 4 << tx_size;
assert(bwl >= 0);
diff --git a/vp9/common/vp9_seg_common.c b/vp9/common/vp9_seg_common.c
index e5511a123..67dfeaed6 100644
--- a/vp9/common/vp9_seg_common.c
+++ b/vp9/common/vp9_seg_common.c
@@ -86,85 +86,6 @@ int vp9_check_segref(const MACROBLOCKD *xd, int segment_id,
}
-#if CONFIG_IMPLICIT_SEGMENTATION
-// This function defines an implicit segmentation for the next frame based
-// on predcition and transform decisions in the current frame.
-// For test purposes at the moment it uses ref frame and prediction size
-void vp9_implicit_segment_map_update(VP9_COMMON * cm) {
- int row, col;
- MODE_INFO *mi, *mi_ptr = cm->mi;
- unsigned char * map_ptr = cm->last_frame_seg_map;
-
- for (row = 0; row < cm->mb_rows; row++) {
- mi = mi_ptr;
-
- for (col = 0; col < cm->mb_cols; ++col, ++mi) {
- // Inter prediction
- if (mi->mbmi.ref_frame != INTRA_FRAME) {
- // Zero motion and prediction block size >= 16
- if ((mi->mbmi.sb_type >= BLOCK_SIZE_MB16X16) &&
- (mi->mbmi.mv[0].as_int == 0))
- map_ptr[col] = 1;
- else if (mi->mbmi.sb_type >= BLOCK_SIZE_SB32X32)
- map_ptr[col] = 2;
- else if (mi->mbmi.sb_type >= BLOCK_SIZE_MB16X16)
- map_ptr[col] = 3;
- else
- map_ptr[col] = 6;
-
- // Intra prediction
- } else {
- if (mi->mbmi.sb_type >= BLOCK_SIZE_SB32X32)
- map_ptr[col] = 4;
- else if (mi->mbmi.sb_type >= BLOCK_SIZE_MB16X16)
- map_ptr[col] = 5;
- else
- map_ptr[col] = 7;
- }
- }
- mi_ptr += cm->mode_info_stride;
- map_ptr += cm->mb_cols;
- }
-}
-
-// This function defines an implicit segmentation for the next frame based
-// on predcition and transform decisions in the current frame.
-// For test purposes at the moment only TX size is used.
-void vp9_implicit_segment_map_update_tx(VP9_COMMON * cm) {
- int row, col;
- MODE_INFO *mi, *mi_ptr = cm->mi;
- unsigned char * map_ptr = cm->last_frame_seg_map;
-
- for (row = 0; row < cm->mb_rows; row++) {
- mi = mi_ptr;
- for (col = 0; col < cm->mb_cols; ++col, ++mi) {
- // Intra modes
- if (mi->mbmi.ref_frame == INTRA_FRAME) {
- if (mi->mbmi.txfm_size == TX_4X4)
- map_ptr[col] = 7;
- else if (mi->mbmi.txfm_size <= TX_16X16)
- map_ptr[col] = 5;
- else
- map_ptr[col] = 4;
- } else {
- // Inter Modes
- if (mi->mbmi.txfm_size == TX_4X4)
- map_ptr[col] = 6;
- else if (mi->mbmi.txfm_size == TX_8X8)
- map_ptr[col] = 3;
- else if (mi->mbmi.txfm_size == TX_16X16)
- map_ptr[col] = 2;
- else
- map_ptr[col] = 1;
- }
- }
- mi_ptr += cm->mode_info_stride;
- map_ptr += cm->mb_cols;
- }
-}
-#endif
-
-
const vp9_tree_index vp9_segment_tree[14] = {
2, 4, 6, 8, 10, 12,
0, -1, -2, -3, -4, -5, -6, -7
diff --git a/vp9/common/vp9_seg_common.h b/vp9/common/vp9_seg_common.h
index 53d22a385..c424a57f4 100644
--- a/vp9/common/vp9_seg_common.h
+++ b/vp9/common/vp9_seg_common.h
@@ -55,11 +55,6 @@ int vp9_check_segref(const MACROBLOCKD *xd,
int segment_id,
MV_REFERENCE_FRAME ref_frame);
-#if CONFIG_IMPLICIT_SEGMENTATION
-void vp9_implicit_segment_map_update(VP9_COMMON * cm);
-#endif
-
-
extern const vp9_tree_index vp9_segment_tree[14];
#endif // VP9_COMMON_VP9_SEG_COMMON_H_
diff --git a/vp9/decoder/vp9_decodemv.c b/vp9/decoder/vp9_decodemv.c
index 8843c6b97..efd852b7a 100644
--- a/vp9/decoder/vp9_decodemv.c
+++ b/vp9/decoder/vp9_decodemv.c
@@ -490,11 +490,6 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
int bw = 1 << b_width_log2(bsize);
int bh = 1 << b_height_log2(bsize);
- const int use_prev_in_find_mv_refs = cm->width == cm->last_width &&
- cm->height == cm->last_height &&
- !cm->error_resilient_mode &&
- cm->last_show_frame;
-
int mb_to_left_edge, mb_to_right_edge, mb_to_top_edge, mb_to_bottom_edge;
int j, idx, idy;
@@ -559,10 +554,8 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
printf("%d %d\n", xd->mode_info_context->mbmi.mv[0].as_mv.row,
xd->mode_info_context->mbmi.mv[0].as_mv.col);
#endif
- vp9_find_mv_refs(cm, xd, mi, use_prev_in_find_mv_refs ?
- xd->prev_mode_info_context : NULL,
- ref_frame, mbmi->ref_mvs[ref_frame],
- cm->ref_frame_sign_bias);
+ vp9_find_mv_refs(cm, xd, mi, xd->prev_mode_info_context, ref_frame,
+ mbmi->ref_mvs[ref_frame], cm->ref_frame_sign_bias);
vp9_mv_ref_probs(cm, mv_ref_p, mbmi->mb_mode_context[ref_frame]);
@@ -610,9 +603,7 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
if (mbmi->second_ref_frame > 0) {
const MV_REFERENCE_FRAME second_ref_frame = mbmi->second_ref_frame;
- vp9_find_mv_refs(cm, xd, mi,
- use_prev_in_find_mv_refs ?
- xd->prev_mode_info_context : NULL,
+ vp9_find_mv_refs(cm, xd, mi, xd->prev_mode_info_context,
second_ref_frame, mbmi->ref_mvs[second_ref_frame],
cm->ref_frame_sign_bias);
diff --git a/vp9/decoder/vp9_decodframe.c b/vp9/decoder/vp9_decodframe.c
index a1cfba73b..d4b789899 100644
--- a/vp9/decoder/vp9_decodframe.c
+++ b/vp9/decoder/vp9_decodframe.c
@@ -406,7 +406,10 @@ static void set_offsets(VP9D_COMP *pbi, BLOCK_SIZE_TYPE bsize,
xd->mode_info_context = cm->mi + mi_idx;
xd->mode_info_context->mbmi.sb_type = bsize;
- xd->prev_mode_info_context = cm->prev_mi + mi_idx;
+ // 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 + mi_idx : NULL;
for (i = 0; i < MAX_MB_PLANE; i++) {
xd->plane[i].above_context = cm->above_context[i] +
@@ -577,11 +580,10 @@ static void init_frame(VP9D_COMP *pbi) {
xd->mode_info_stride = pc->mode_info_stride;
}
-static void read_coef_probs_common(
- vp9_coeff_probs_model *coef_probs,
- TX_SIZE tx_size,
- vp9_reader *r) {
+static void read_coef_probs_common(FRAME_CONTEXT *fc, TX_SIZE tx_size,
+ vp9_reader *r) {
const int entropy_nodes_update = UNCONSTRAINED_NODES;
+ vp9_coeff_probs_model *coef_probs = fc->coef_probs[tx_size];
int i, j, k, l, m;
@@ -612,16 +614,16 @@ static void read_coef_probs(VP9D_COMP *pbi, vp9_reader *r) {
const TXFM_MODE mode = pbi->common.txfm_mode;
FRAME_CONTEXT *const fc = &pbi->common.fc;
- read_coef_probs_common(fc->coef_probs_4x4, TX_4X4, r);
+ read_coef_probs_common(fc, TX_4X4, r);
if (mode > ONLY_4X4)
- read_coef_probs_common(fc->coef_probs_8x8, TX_8X8, r);
+ read_coef_probs_common(fc, TX_8X8, r);
if (mode > ALLOW_8X8)
- read_coef_probs_common(fc->coef_probs_16x16, TX_16X16, r);
+ read_coef_probs_common(fc, TX_16X16, r);
if (mode > ALLOW_16X16)
- read_coef_probs_common(fc->coef_probs_32x32, TX_32X32, r);
+ read_coef_probs_common(fc, TX_32X32, r);
}
static void setup_segmentation(VP9_COMMON *pc, MACROBLOCKD *xd, vp9_reader *r) {
@@ -629,9 +631,6 @@ static void setup_segmentation(VP9_COMMON *pc, MACROBLOCKD *xd, vp9_reader *r) {
xd->update_mb_segmentation_map = 0;
xd->update_mb_segmentation_data = 0;
-#if CONFIG_IMPLICIT_SEGMENTATION
- xd->allow_implicit_segment_update = 0;
-#endif
xd->segmentation_enabled = vp9_read_bit(r);
if (!xd->segmentation_enabled)
@@ -639,9 +638,6 @@ static void setup_segmentation(VP9_COMMON *pc, MACROBLOCKD *xd, vp9_reader *r) {
// Segmentation map update
xd->update_mb_segmentation_map = vp9_read_bit(r);
-#if CONFIG_IMPLICIT_SEGMENTATION
- xd->allow_implicit_segment_update = vp9_read_bit(r);
-#endif
if (xd->update_mb_segmentation_map) {
for (i = 0; i < MB_SEG_TREE_PROBS; i++)
xd->mb_segment_tree_probs[i] = vp9_read_bit(r) ? vp9_read_prob(r)
@@ -804,19 +800,13 @@ static void setup_frame_size(VP9D_COMP *pbi, int scaling_active,
}
static void update_frame_context(FRAME_CONTEXT *fc) {
- vp9_copy(fc->pre_coef_probs_4x4, fc->coef_probs_4x4);
- vp9_copy(fc->pre_coef_probs_8x8, fc->coef_probs_8x8);
- vp9_copy(fc->pre_coef_probs_16x16, fc->coef_probs_16x16);
- vp9_copy(fc->pre_coef_probs_32x32, fc->coef_probs_32x32);
+ vp9_copy(fc->pre_coef_probs, fc->coef_probs);
vp9_copy(fc->pre_y_mode_prob, fc->y_mode_prob);
vp9_copy(fc->pre_uv_mode_prob, fc->uv_mode_prob);
vp9_copy(fc->pre_partition_prob, fc->partition_prob);
fc->pre_nmvc = fc->nmvc;
- vp9_zero(fc->coef_counts_4x4);
- vp9_zero(fc->coef_counts_8x8);
- vp9_zero(fc->coef_counts_16x16);
- vp9_zero(fc->coef_counts_32x32);
+ vp9_zero(fc->coef_counts);
vp9_zero(fc->eob_branch_counts);
vp9_zero(fc->y_mode_counts);
vp9_zero(fc->uv_mode_counts);
@@ -1101,6 +1091,8 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) {
for (i = 0; i < MAX_MB_PLANE; ++i)
vp9_zero(xd->plane[i].qcoeff);
+ set_prev_mi(pc);
+
vp9_decode_mode_mvs_init(pbi, &header_bc);
decode_tiles(pbi, data, first_partition_size, &header_bc, &residual_bc);
@@ -1129,13 +1121,6 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) {
}
}
-#if CONFIG_IMPLICIT_SEGMENTATION
- // If signalled at the frame level apply implicit updates to the segment map.
- if (!pc->error_resilient_mode && xd->allow_implicit_segment_update) {
- vp9_implicit_segment_map_update(pc);
- }
-#endif
-
if (pc->refresh_frame_context)
pc->frame_contexts[pc->frame_context_idx] = pc->fc;
diff --git a/vp9/decoder/vp9_detokenize.c b/vp9/decoder/vp9_detokenize.c
index 6f6c88a27..b20807226 100644
--- a/vp9/decoder/vp9_detokenize.c
+++ b/vp9/decoder/vp9_detokenize.c
@@ -120,6 +120,8 @@ static int decode_coefs(VP9D_COMP *dx, const MACROBLOCKD *xd,
int skip_eob_node = 0;
#endif
+ coef_probs = fc->coef_probs[txfm_size][type][ref];
+ coef_counts = fc->coef_counts[txfm_size];
switch (txfm_size) {
default:
case TX_4X4: {
@@ -128,8 +130,6 @@ static int decode_coefs(VP9D_COMP *dx, const MACROBLOCKD *xd,
scan = get_scan_4x4(tx_type);
above_ec = A[0] != 0;
left_ec = L[0] != 0;
- coef_probs = fc->coef_probs_4x4[type][ref];
- coef_counts = fc->coef_counts_4x4;
default_eob = 16;
band_translate = vp9_coefband_trans_4x4;
break;
@@ -142,8 +142,6 @@ static int decode_coefs(VP9D_COMP *dx, const MACROBLOCKD *xd,
tx_type = (type == PLANE_TYPE_Y_WITH_DC) ?
get_tx_type_8x8(xd, y + (x >> 1)) : DCT_DCT;
scan = get_scan_8x8(tx_type);
- coef_probs = fc->coef_probs_8x8[type][ref];
- coef_counts = fc->coef_counts_8x8;
above_ec = (A[0] + A[1]) != 0;
left_ec = (L[0] + L[1]) != 0;
default_eob = 64;
@@ -158,8 +156,6 @@ static int decode_coefs(VP9D_COMP *dx, const MACROBLOCKD *xd,
tx_type = (type == PLANE_TYPE_Y_WITH_DC) ?
get_tx_type_16x16(xd, y + (x >> 2)) : DCT_DCT;
scan = get_scan_16x16(tx_type);
- coef_probs = fc->coef_probs_16x16[type][ref];
- coef_counts = fc->coef_counts_16x16;
above_ec = (A[0] + A[1] + A[2] + A[3]) != 0;
left_ec = (L[0] + L[1] + L[2] + L[3]) != 0;
default_eob = 256;
@@ -168,8 +164,6 @@ static int decode_coefs(VP9D_COMP *dx, const MACROBLOCKD *xd,
}
case TX_32X32:
scan = vp9_default_scan_32x32;
- coef_probs = fc->coef_probs_32x32[type][ref];
- coef_counts = fc->coef_counts_32x32;
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;
default_eob = 1024;
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;