Commit 98c192ae authored by Ronald S. Bultje's avatar Ronald S. Bultje
Browse files

Merge all intra mode coding trees into a single one.

Also merge all counters. This removes a few unused probability updates
from the bitstream.

Change-Id: I20f58853e9dac84d8c0d9703ae012c55917516eb
parent c98bfcfb
......@@ -202,8 +202,6 @@ void vp9_create_common(VP9_COMMON *oci) {
vp9_init_mbmode_probs(oci);
vp9_default_bmode_probs(oci->fc.bmode_prob);
oci->txfm_mode = ONLY_4X4;
oci->comp_pred_mode = HYBRID_PREDICTION;
oci->no_lpf = 0;
......@@ -212,8 +210,6 @@ void vp9_create_common(VP9_COMMON *oci) {
// Initialize reference frame sign bias structure to defaults
vpx_memset(oci->ref_frame_sign_bias, 0, sizeof(oci->ref_frame_sign_bias));
oci->kf_ymode_probs_update = 0;
}
void vp9_remove_common(VP9_COMMON *oci) {
......
......@@ -89,7 +89,7 @@ const vp9_prob vp9_partition_probs[NUM_PARTITION_CONTEXTS]
};
/* Array indices are identical to previously-existing INTRAMODECONTEXTNODES. */
const vp9_tree_index vp9_bmode_tree[VP9_BINTRAMODES * 2 - 2] = {
const vp9_tree_index vp9_intra_mode_tree[VP9_BINTRAMODES * 2 - 2] = {
-DC_PRED, 2, /* 0 = DC_NODE */
-TM_PRED, 4, /* 1 = TM_NODE */
-V_PRED, 6, /* 2 = V_NODE */
......@@ -101,46 +101,6 @@ const vp9_tree_index vp9_bmode_tree[VP9_BINTRAMODES * 2 - 2] = {
-D153_PRED, -D27_PRED /* 8 = D153_NODE */
};
/* Again, these trees use the same probability indices as their
explicitly-programmed predecessors. */
const vp9_tree_index vp9_ymode_tree[VP9_YMODES * 2 - 2] = {
2, 14,
-DC_PRED, 4,
6, 8,
-D45_PRED, -D135_PRED,
10, 12,
-D117_PRED, -D153_PRED,
-D27_PRED, -D63_PRED,
16, 18,
-V_PRED, -H_PRED,
-TM_PRED, -I4X4_PRED
};
const vp9_tree_index vp9_kf_ymode_tree[VP9_YMODES * 2 - 2] = {
2, 14,
-DC_PRED, 4,
6, 8,
-D45_PRED, -D135_PRED,
10, 12,
-D117_PRED, -D153_PRED,
-D27_PRED, -D63_PRED,
16, 18,
-V_PRED, -H_PRED,
-TM_PRED, -I4X4_PRED
};
const vp9_tree_index vp9_uv_mode_tree[VP9_UV_MODES * 2 - 2] = {
2, 14,
-DC_PRED, 4,
6, 8,
-D45_PRED, -D135_PRED,
10, 12,
-D117_PRED, -D153_PRED,
-D27_PRED, -D63_PRED,
-V_PRED, 16,
-H_PRED, -TM_PRED
};
const vp9_tree_index vp9_sb_mv_ref_tree[6] = {
-ZEROMV, 2,
-NEARESTMV, 4,
......@@ -153,13 +113,7 @@ const vp9_tree_index vp9_partition_tree[6] = {
-PARTITION_VERT, -PARTITION_SPLIT
};
struct vp9_token vp9_bmode_encodings[VP9_BINTRAMODES];
struct vp9_token vp9_kf_bmode_encodings[VP9_BINTRAMODES];
struct vp9_token vp9_ymode_encodings[VP9_YMODES];
struct vp9_token vp9_sb_ymode_encodings[VP9_I32X32_MODES];
struct vp9_token vp9_sb_kf_ymode_encodings[VP9_I32X32_MODES];
struct vp9_token vp9_kf_ymode_encodings[VP9_YMODES];
struct vp9_token vp9_uv_mode_encodings[VP9_UV_MODES];
struct vp9_token vp9_intra_mode_encodings[VP9_BINTRAMODES];
struct vp9_token vp9_sb_mv_ref_encoding_array[VP9_MVREFS];
......@@ -169,22 +123,13 @@ void vp9_init_mbmode_probs(VP9_COMMON *x) {
unsigned int bct[VP9_YMODES][2]; // num Ymodes > num UV modes
int i;
vp9_tree_probs_from_distribution(vp9_ymode_tree, x->fc.ymode_prob,
bct, y_mode_cts, 0);
vp9_tree_probs_from_distribution(vp9_sb_ymode_tree, x->fc.sb_ymode_prob,
vp9_tree_probs_from_distribution(vp9_intra_mode_tree, x->fc.y_mode_prob,
bct, y_mode_cts, 0);
for (i = 0; i < 8; i++) {
vp9_tree_probs_from_distribution(vp9_kf_ymode_tree, x->kf_ymode_prob[i],
bct, kf_y_mode_cts[i], 0);
vp9_tree_probs_from_distribution(vp9_sb_kf_ymode_tree,
x->sb_kf_ymode_prob[i], bct,
kf_y_mode_cts[i], 0);
}
for (i = 0; i < VP9_YMODES; i++) {
vp9_tree_probs_from_distribution(vp9_uv_mode_tree, x->kf_uv_mode_prob[i],
vp9_tree_probs_from_distribution(vp9_intra_mode_tree, x->kf_uv_mode_prob[i],
bct, kf_uv_mode_cts[i], 0);
vp9_tree_probs_from_distribution(vp9_uv_mode_tree, x->fc.uv_mode_prob[i],
vp9_tree_probs_from_distribution(vp9_intra_mode_tree, x->fc.uv_mode_prob[i],
bct, uv_mode_cts[i], 0);
}
......@@ -199,19 +144,6 @@ void vp9_init_mbmode_probs(VP9_COMMON *x) {
x->ref_pred_probs[2] = DEFAULT_PRED_PROB_2;
}
static void intra_bmode_probs_from_distribution(
vp9_prob p[VP9_BINTRAMODES - 1],
unsigned int branch_ct[VP9_BINTRAMODES - 1][2],
const unsigned int events[VP9_BINTRAMODES]) {
vp9_tree_probs_from_distribution(vp9_bmode_tree, p, branch_ct, events, 0);
}
void vp9_default_bmode_probs(vp9_prob p[VP9_BINTRAMODES - 1]) {
unsigned int branch_ct[VP9_BINTRAMODES - 1][2];
intra_bmode_probs_from_distribution(p, branch_ct, bmode_cts);
}
#if VP9_SWITCHABLE_FILTERS == 3
const vp9_tree_index vp9_switchable_interp_tree[VP9_SWITCHABLE_FILTERS*2-2] = {
-0, 2,
......@@ -246,13 +178,7 @@ const int vp9_switchable_interp_map[SWITCHABLE+1] = {-1, 0, 1, -1, -1};
const int vp9_is_interpolating_filter[SWITCHABLE + 1] = {0, 1, 1, 1, -1};
void vp9_entropy_mode_init() {
vp9_tokens_from_tree(vp9_kf_bmode_encodings, vp9_bmode_tree);
vp9_tokens_from_tree(vp9_bmode_encodings, vp9_bmode_tree);
vp9_tokens_from_tree(vp9_ymode_encodings, vp9_ymode_tree);
vp9_tokens_from_tree(vp9_kf_ymode_encodings, vp9_kf_ymode_tree);
vp9_tokens_from_tree(vp9_sb_ymode_encodings, vp9_sb_ymode_tree);
vp9_tokens_from_tree(vp9_sb_kf_ymode_encodings, vp9_sb_kf_ymode_tree);
vp9_tokens_from_tree(vp9_uv_mode_encodings, vp9_uv_mode_tree);
vp9_tokens_from_tree(vp9_intra_mode_encodings, vp9_intra_mode_tree);
vp9_tokens_from_tree(vp9_switchable_interp_encodings,
vp9_switchable_interp_tree);
vp9_tokens_from_tree(vp9_partition_encodings, vp9_partition_tree);
......@@ -375,22 +301,15 @@ void vp9_adapt_mode_probs(VP9_COMMON *cm) {
printf("};\n");
#endif
update_mode_probs(VP9_YMODES, vp9_ymode_tree,
fc->ymode_counts, fc->pre_ymode_prob,
fc->ymode_prob, 0);
update_mode_probs(VP9_I32X32_MODES, vp9_sb_ymode_tree,
fc->sb_ymode_counts, fc->pre_sb_ymode_prob,
fc->sb_ymode_prob, 0);
update_mode_probs(VP9_YMODES, vp9_intra_mode_tree,
fc->y_mode_counts, fc->pre_y_mode_prob,
fc->y_mode_prob, 0);
for (i = 0; i < VP9_YMODES; ++i)
update_mode_probs(VP9_UV_MODES, vp9_uv_mode_tree,
update_mode_probs(VP9_UV_MODES, vp9_intra_mode_tree,
fc->uv_mode_counts[i], fc->pre_uv_mode_prob[i],
fc->uv_mode_prob[i], 0);
update_mode_probs(VP9_BINTRAMODES, vp9_bmode_tree,
fc->bmode_counts, fc->pre_bmode_prob,
fc->bmode_prob, 0);
for (i = 0; i < NUM_PARTITION_CONTEXTS; i++)
update_mode_probs(PARTITION_TYPES, vp9_partition_tree,
fc->partition_counts[i], fc->pre_partition_prob[i],
......@@ -428,8 +347,7 @@ void vp9_setup_past_independence(VP9_COMMON *cm, MACROBLOCKD *xd) {
vp9_default_coef_probs(cm);
vp9_init_mbmode_probs(cm);
vp9_default_bmode_probs(cm->fc.bmode_prob);
vpx_memcpy(cm->kf_bmode_prob, vp9_kf_default_bmode_probs,
vpx_memcpy(cm->kf_y_mode_prob, vp9_kf_default_bmode_probs,
sizeof(vp9_kf_default_bmode_probs));
vp9_init_mv_probs(cm);
......
......@@ -23,21 +23,10 @@ extern const vp9_prob vp9_kf_default_bmode_probs[VP9_BINTRAMODES]
[VP9_BINTRAMODES]
[VP9_BINTRAMODES -1 ];
extern const vp9_tree_index vp9_bmode_tree[];
extern const vp9_tree_index vp9_ymode_tree[];
extern const vp9_tree_index vp9_kf_ymode_tree[];
extern const vp9_tree_index vp9_uv_mode_tree[];
#define vp9_sb_ymode_tree vp9_uv_mode_tree
#define vp9_sb_kf_ymode_tree vp9_uv_mode_tree
extern const vp9_tree_index vp9_intra_mode_tree[];
extern const vp9_tree_index vp9_sb_mv_ref_tree[];
extern struct vp9_token vp9_bmode_encodings[VP9_BINTRAMODES];
extern struct vp9_token vp9_kf_bmode_encodings[VP9_BINTRAMODES];
extern struct vp9_token vp9_ymode_encodings[VP9_YMODES];
extern struct vp9_token vp9_sb_ymode_encodings[VP9_I32X32_MODES];
extern struct vp9_token vp9_sb_kf_ymode_encodings[VP9_I32X32_MODES];
extern struct vp9_token vp9_kf_ymode_encodings[VP9_YMODES];
extern struct vp9_token vp9_uv_mode_encodings[VP9_UV_MODES];
extern struct vp9_token vp9_intra_mode_encodings[VP9_BINTRAMODES];
/* Inter mode values do not start at zero */
......@@ -64,8 +53,6 @@ extern void vp9_accum_mv_refs(struct VP9Common *pc,
MB_PREDICTION_MODE m,
const int context);
void vp9_default_bmode_probs(vp9_prob dest[VP9_BINTRAMODES - 1]);
void vp9_adapt_mode_probs(struct VP9Common *);
#define VP9_SWITCHABLE_FILTERS 3 /* number of switchable filters */
......
......@@ -47,22 +47,16 @@ void vp9_initialize_common(void);
#define MAX_LAG_BUFFERS 25
typedef struct frame_contexts {
vp9_prob bmode_prob[VP9_BINTRAMODES - 1];
vp9_prob ymode_prob[VP9_YMODES - 1]; /* interframe intra mode probs */
vp9_prob sb_ymode_prob[VP9_I32X32_MODES - 1];
vp9_prob y_mode_prob[VP9_YMODES - 1]; /* interframe intra mode probs */
vp9_prob uv_mode_prob[VP9_YMODES][VP9_UV_MODES - 1];
vp9_prob partition_prob[NUM_PARTITION_CONTEXTS][PARTITION_TYPES - 1];
nmv_context nmvc;
nmv_context pre_nmvc;
vp9_prob pre_bmode_prob[VP9_BINTRAMODES - 1];
vp9_prob pre_ymode_prob[VP9_YMODES - 1]; /* interframe intra mode probs */
vp9_prob pre_sb_ymode_prob[VP9_I32X32_MODES - 1];
vp9_prob pre_y_mode_prob[VP9_YMODES - 1]; /* interframe intra mode probs */
vp9_prob pre_uv_mode_prob[VP9_YMODES][VP9_UV_MODES - 1];
vp9_prob pre_partition_prob[NUM_PARTITION_CONTEXTS][PARTITION_TYPES - 1];
unsigned int bmode_counts[VP9_BINTRAMODES];
unsigned int ymode_counts[VP9_YMODES]; /* interframe intra mode probs */
unsigned int sb_ymode_counts[VP9_I32X32_MODES];
unsigned int y_mode_counts[VP9_YMODES]; /* interframe intra mode probs */
unsigned int uv_mode_counts[VP9_YMODES][VP9_UV_MODES];
unsigned int partition_counts[NUM_PARTITION_CONTEXTS][PARTITION_TYPES];
......@@ -217,13 +211,9 @@ typedef struct VP9Common {
/* keyframe block modes are predicted by their above, left neighbors */
vp9_prob kf_bmode_prob[VP9_BINTRAMODES]
[VP9_BINTRAMODES]
[VP9_BINTRAMODES - 1];
vp9_prob kf_ymode_prob[8][VP9_YMODES - 1]; /* keyframe "" */
vp9_prob sb_kf_ymode_prob[8][VP9_I32X32_MODES - 1];
int kf_ymode_probs_index;
int kf_ymode_probs_update;
vp9_prob kf_y_mode_prob[VP9_BINTRAMODES]
[VP9_BINTRAMODES]
[VP9_BINTRAMODES - 1];
vp9_prob kf_uv_mode_prob[VP9_YMODES] [VP9_UV_MODES - 1];
vp9_prob prob_intra_coded;
......
......@@ -35,35 +35,11 @@ int dec_mvcount = 0;
extern int dec_debug;
#endif
static MB_PREDICTION_MODE read_bmode(vp9_reader *r, const vp9_prob *p) {
MB_PREDICTION_MODE m = treed_read(r, vp9_bmode_tree, p);
static MB_PREDICTION_MODE read_intra_mode(vp9_reader *r, const vp9_prob *p) {
MB_PREDICTION_MODE m = treed_read(r, vp9_intra_mode_tree, p);
return m;
}
static MB_PREDICTION_MODE read_kf_bmode(vp9_reader *r, const vp9_prob *p) {
return (MB_PREDICTION_MODE)treed_read(r, vp9_bmode_tree, p);
}
static MB_PREDICTION_MODE read_ymode(vp9_reader *r, const vp9_prob *p) {
return (MB_PREDICTION_MODE)treed_read(r, vp9_ymode_tree, p);
}
static MB_PREDICTION_MODE read_sb_ymode(vp9_reader *r, const vp9_prob *p) {
return (MB_PREDICTION_MODE)treed_read(r, vp9_sb_ymode_tree, p);
}
static MB_PREDICTION_MODE read_kf_sb_ymode(vp9_reader *r, const vp9_prob *p) {
return (MB_PREDICTION_MODE)treed_read(r, vp9_uv_mode_tree, p);
}
static MB_PREDICTION_MODE read_kf_mb_ymode(vp9_reader *r, const vp9_prob *p) {
return (MB_PREDICTION_MODE)treed_read(r, vp9_kf_ymode_tree, p);
}
static MB_PREDICTION_MODE read_uv_mode(vp9_reader *r, const vp9_prob *p) {
return (MB_PREDICTION_MODE)treed_read(r, vp9_uv_mode_tree, p);
}
static int read_mb_segid(vp9_reader *r, MACROBLOCKD *xd) {
return treed_read(r, vp9_segment_tree, xd->mb_segment_tree_probs);
}
......@@ -137,22 +113,18 @@ static void kfread_modes(VP9D_COMP *pbi, MODE_INFO *m,
}
// luma mode
m->mbmi.ref_frame = INTRA_FRAME;
if (m->mbmi.sb_type >= BLOCK_SIZE_SB8X8) {
const MB_PREDICTION_MODE A = above_block_mode(m, 0, mis);
const MB_PREDICTION_MODE L = xd->left_available ?
left_block_mode(m, 0) : DC_PRED;
m->mbmi.mode = read_kf_bmode(r, cm->kf_bmode_prob[A][L]);
m->mbmi.mode = read_intra_mode(r, cm->kf_y_mode_prob[A][L]);
} else {
m->mbmi.mode = I4X4_PRED;
}
m->mbmi.ref_frame = INTRA_FRAME;
if (m->mbmi.sb_type < BLOCK_SIZE_SB8X8) {
int idx, idy;
int bw = 1 << b_width_log2(m->mbmi.sb_type);
int bh = 1 << b_height_log2(m->mbmi.sb_type);
m->mbmi.mode = I4X4_PRED;
for (idy = 0; idy < 2; idy += bh) {
for (idx = 0; idx < 2; idx += bw) {
int ib = idy * 2 + idx;
......@@ -161,7 +133,7 @@ static void kfread_modes(VP9D_COMP *pbi, MODE_INFO *m,
const MB_PREDICTION_MODE L = (xd->left_available || idx) ?
left_block_mode(m, ib) : DC_PRED;
m->bmi[ib].as_mode.first =
read_kf_bmode(r, cm->kf_bmode_prob[A][L]);
read_intra_mode(r, cm->kf_y_mode_prob[A][L]);
for (k = 1; k < bh; ++k)
m->bmi[ib + k * 2].as_mode.first = m->bmi[ib].as_mode.first;
for (k = 1; k < bw; ++k)
......@@ -170,7 +142,7 @@ static void kfread_modes(VP9D_COMP *pbi, MODE_INFO *m,
}
}
m->mbmi.uv_mode = read_uv_mode(r, cm->kf_uv_mode_prob[m->mbmi.mode]);
m->mbmi.uv_mode = read_intra_mode(r, cm->kf_uv_mode_prob[m->mbmi.mode]);
}
static int read_mv_component(vp9_reader *r,
......@@ -390,10 +362,7 @@ static INLINE COMPPREDMODE_TYPE read_comp_pred_mode(vp9_reader *r) {
static void mb_mode_mv_init(VP9D_COMP *pbi, vp9_reader *r) {
VP9_COMMON *const cm = &pbi->common;
if (cm->frame_type == KEY_FRAME) {
if (!cm->kf_ymode_probs_update)
cm->kf_ymode_probs_index = vp9_read_literal(r, 3);
} else {
if (cm->frame_type != KEY_FRAME) {
nmv_context *const nmvc = &pbi->common.fc.nmvc;
MACROBLOCKD *const xd = &pbi->mb;
int i, j;
......@@ -418,12 +387,7 @@ static void mb_mode_mv_init(VP9D_COMP *pbi, vp9_reader *r) {
// VP9_YMODES
if (vp9_read_bit(r))
for (i = 0; i < VP9_YMODES - 1; ++i)
cm->fc.ymode_prob[i] = vp9_read_prob(r);
// VP9_I32X32_MODES
if (vp9_read_bit(r))
for (i = 0; i < VP9_I32X32_MODES - 1; ++i)
cm->fc.sb_ymode_prob[i] = vp9_read_prob(r);
cm->fc.y_mode_prob[i] = vp9_read_prob(r);
for (j = 0; j < NUM_PARTITION_CONTEXTS; ++j)
if (vp9_read_bit(r))
......@@ -805,21 +769,17 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
mv0->as_int = 0;
if (bsize >= BLOCK_SIZE_SB8X8) {
mbmi->mode = read_sb_ymode(r, cm->fc.sb_ymode_prob);
cm->fc.sb_ymode_counts[mbmi->mode]++;
mbmi->mode = read_intra_mode(r, cm->fc.y_mode_prob);
cm->fc.y_mode_counts[mbmi->mode]++;
} else {
mbmi->mode = I4X4_PRED;
}
// If MB mode is I4X4_PRED read the block modes
if (bsize < BLOCK_SIZE_SB8X8) {
int idx, idy;
mbmi->mode = I4X4_PRED;
for (idy = 0; idy < 2; idy += bh) {
for (idx = 0; idx < 2; idx += bw) {
int ib = idy * 2 + idx, k;
int m = read_sb_ymode(r, cm->fc.sb_ymode_prob);
int m = read_intra_mode(r, cm->fc.y_mode_prob);
mi->bmi[ib].as_mode.first = m;
cm->fc.sb_ymode_counts[m]++;
cm->fc.y_mode_counts[m]++;
for (k = 1; k < bh; ++k)
mi->bmi[ib + k * 2].as_mode.first = m;
for (k = 1; k < bw; ++k)
......@@ -828,7 +788,7 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
}
}
mbmi->uv_mode = read_uv_mode(r, cm->fc.uv_mode_prob[mbmi->mode]);
mbmi->uv_mode = read_intra_mode(r, cm->fc.uv_mode_prob[mbmi->mode]);
cm->fc.uv_mode_counts[mbmi->mode][mbmi->uv_mode]++;
}
}
......
......@@ -806,10 +806,8 @@ static void update_frame_context(FRAME_CONTEXT *fc) {
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_ymode_prob, fc->ymode_prob);
vp9_copy(fc->pre_sb_ymode_prob, fc->sb_ymode_prob);
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_bmode_prob, fc->bmode_prob);
vp9_copy(fc->pre_partition_prob, fc->partition_prob);
fc->pre_nmvc = fc->nmvc;
......@@ -818,10 +816,8 @@ static void update_frame_context(FRAME_CONTEXT *fc) {
vp9_zero(fc->coef_counts_16x16);
vp9_zero(fc->coef_counts_32x32);
vp9_zero(fc->eob_branch_counts);
vp9_zero(fc->ymode_counts);
vp9_zero(fc->sb_ymode_counts);
vp9_zero(fc->y_mode_counts);
vp9_zero(fc->uv_mode_counts);
vp9_zero(fc->bmode_counts);
vp9_zero(fc->NMVcount);
vp9_zero(fc->mv_ref_ct);
vp9_zero(fc->partition_counts);
......
......@@ -248,12 +248,9 @@ static void update_mbintra_mode_probs(VP9_COMP* const cpi,
vp9_prob pnew[VP9_YMODES - 1];
unsigned int bct[VP9_YMODES - 1][2];
update_mode(bc, VP9_YMODES, vp9_ymode_encodings, vp9_ymode_tree, pnew,
cm->fc.ymode_prob, bct, (unsigned int *)cpi->ymode_count);
update_mode(bc, VP9_I32X32_MODES, vp9_sb_ymode_encodings,
vp9_sb_ymode_tree, pnew, cm->fc.sb_ymode_prob, bct,
(unsigned int *)cpi->sb_ymode_count);
update_mode(bc, VP9_YMODES, vp9_intra_mode_encodings,
vp9_intra_mode_tree, pnew,
cm->fc.y_mode_prob, bct, (unsigned int *)cpi->y_mode_count);
}
void vp9_update_skip_probs(VP9_COMP *cpi) {
......@@ -350,28 +347,8 @@ static void update_inter_mode_probs(VP9_COMMON *cm,
}
}
static void write_ymode(vp9_writer *bc, int m, const vp9_prob *p) {
write_token(bc, vp9_ymode_tree, p, vp9_ymode_encodings + m);
}
static void kfwrite_ymode(vp9_writer *bc, int m, const vp9_prob *p) {
write_token(bc, vp9_kf_ymode_tree, p, vp9_kf_ymode_encodings + m);
}
static void write_sb_ymode(vp9_writer *bc, int m, const vp9_prob *p) {
write_token(bc, vp9_sb_ymode_tree, p, vp9_sb_ymode_encodings + m);
}
static void sb_kfwrite_ymode(vp9_writer *bc, int m, const vp9_prob *p) {
write_token(bc, vp9_uv_mode_tree, p, vp9_sb_kf_ymode_encodings + m);
}
static void write_uv_mode(vp9_writer *bc, int m, const vp9_prob *p) {
write_token(bc, vp9_uv_mode_tree, p, vp9_uv_mode_encodings + m);
}
static void write_kf_bmode(vp9_writer *bc, int m, const vp9_prob *p) {
write_token(bc, vp9_bmode_tree, p, vp9_kf_bmode_encodings + m);
static void write_intra_mode(vp9_writer *bc, int m, const vp9_prob *p) {
write_token(bc, vp9_intra_mode_tree, p, vp9_intra_mode_encodings + m);
}
static int prob_update_savings(const unsigned int *ct,
......@@ -716,20 +693,19 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, MODE_INFO *m,
active_section = 6;
#endif
if (m->mbmi.sb_type >= BLOCK_SIZE_SB8X8)
write_sb_ymode(bc, mode, pc->fc.sb_ymode_prob);
if (m->mbmi.sb_type < BLOCK_SIZE_SB8X8) {
if (m->mbmi.sb_type >= BLOCK_SIZE_SB8X8) {
write_intra_mode(bc, mode, pc->fc.y_mode_prob);
} else {
int idx, idy;
int bw = 1 << b_width_log2(mi->sb_type);
int bh = 1 << b_height_log2(mi->sb_type);
for (idy = 0; idy < 2; idy += bh)
for (idx = 0; idx < 2; idx += bw)
write_sb_ymode(bc, m->bmi[idy * 2 + idx].as_mode.first,
pc->fc.sb_ymode_prob);
write_intra_mode(bc, m->bmi[idy * 2 + idx].as_mode.first,
pc->fc.y_mode_prob);
}
write_uv_mode(bc, mi->uv_mode,
pc->fc.uv_mode_prob[mode]);
write_intra_mode(bc, mi->uv_mode,
pc->fc.uv_mode_prob[mode]);
} else {
vp9_prob mv_ref_p[VP9_MVREFS - 1];
......@@ -855,10 +831,8 @@ static void write_mb_modes_kf(const VP9_COMP *cpi,
const MB_PREDICTION_MODE A = above_block_mode(m, 0, mis);
const MB_PREDICTION_MODE L = xd->left_available ?
left_block_mode(m, 0) : DC_PRED;
write_kf_bmode(bc, ym, c->kf_bmode_prob[A][L]);
}
if (m->mbmi.sb_type < BLOCK_SIZE_SB8X8) {
write_intra_mode(bc, ym, c->kf_y_mode_prob[A][L]);
} else {
int idx, idy;
int bw = 1 << b_width_log2(m->mbmi.sb_type);
int bh = 1 << b_height_log2(m->mbmi.sb_type);
......@@ -872,12 +846,12 @@ static void write_mb_modes_kf(const VP9_COMP *cpi,
#ifdef ENTROPY_STATS
++intra_mode_stats[A][L][bm];
#endif
write_kf_bmode(bc, bm, c->kf_bmode_prob[A][L]);
write_intra_mode(bc, bm, c->kf_y_mode_prob[A][L]);
}
}
}
write_uv_mode(bc, m->mbmi.uv_mode, c->kf_uv_mode_prob[ym]);
write_intra_mode(bc, m->mbmi.uv_mode, c->kf_uv_mode_prob[ym]);
}
static void write_modes_b(VP9_COMP *cpi, MODE_INFO *m, vp9_writer *bc,
......@@ -1290,33 +1264,6 @@ static void update_coef_probs(VP9_COMP* const cpi, vp9_writer* const bc) {
}
}
static void decide_kf_ymode_entropy(VP9_COMP *cpi) {
int mode_cost[MB_MODE_COUNT];
int bestcost = INT_MAX;
int bestindex = 0;
int i, j;
for (i = 0; i < 8; i++) {
int cost = 0;
vp9_cost_tokens(mode_cost, cpi->common.kf_ymode_prob[i], vp9_kf_ymode_tree);
for (j = 0; j < VP9_YMODES; j++)
cost += mode_cost[j] * cpi->ymode_count[j];
vp9_cost_tokens(mode_cost, cpi->common.sb_kf_ymode_prob[i],
vp9_sb_ymode_tree);
for (j = 0; j < VP9_I32X32_MODES; j++)
cost += mode_cost[j] * cpi->sb_ymode_count[j];
if (cost < bestcost) {
bestindex = i;
bestcost = cost;
}
}
cpi->common.kf_ymode_probs_index = bestindex;
}
static void segment_reference_frames(VP9_COMP *cpi) {
VP9_COMMON *oci = &cpi->common;
MODE_INFO *mi = oci->mi;
......@@ -1734,10 +1681,8 @@ void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, unsigned long *size) {
vp9_copy(cpi->common.fc.pre_coef_probs_32x32,
cpi->common.fc.coef_probs_32x32);
vp9_copy(cpi->common.fc.pre_sb_ymode_prob, cpi->common.fc.sb_ymode_prob);
vp9_copy(cpi->common.fc.pre_ymode_prob, cpi->common.fc.ymode_prob);
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_bmode_prob, cpi->common.fc.bmode_prob);
vp9_copy(cpi->common.fc.pre_partition_prob, cpi->common.fc.partition_prob);
cpi->common.fc.pre_nmvc = cpi->common.fc.nmvc;
vp9_zero(cpi->common.fc.mv_ref_ct);
......@@ -1753,11 +1698,7 @@ void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, unsigned long *size) {
vp9_write_prob(&header_bc, pc->mbskip_pred_probs[i]);
}
if (pc->frame_type == KEY_FRAME) {
if (!pc->kf_ymode_probs_update) {
vp9_write_literal(&header_bc, pc->kf_ymode_probs_index, 3);
}
} else {
if (pc->frame_type != KEY_FRAME) {
// Update the probabilities used to encode reference frame data
update_ref_probs(cpi);
......@@ -1829,14 +1770,6 @@ void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, unsigned long *size) {
vp9_wb_write_literal(&first_partition_size_wb, header_bc.pos, 16);
*size = bytes_packed + header_bc.pos;
if (pc->frame_type == KEY_FRAME) {
decide_kf_ymode_entropy(cpi);
} else {
/* This is not required if the counts in cpi are consistent with the
* final packing pass */
// if (!cpi->dummy_packing) vp9_zero(cpi->NMVcount);
}
{
int tile_row, tile_col, total_size = 0;