Commit 21401942 authored by Deb Mukherjee's avatar Deb Mukherjee
Browse files

Coding tx-size selection by use of spatial context

Adds coding of transform size within a frame by use of context
of transform sizes selected in left and above blocks.

Also incorporates code for generating stats.

TODO: generate and incorporate new default stats

Change-Id: I6a7af099f6ad61d448521d9a51167aedaf638ed6
parent 869a39ba
......@@ -124,12 +124,10 @@ typedef enum {
#define TX_SIZE_PROBS 6 // (TX_SIZE_MAX_SB * (TX_SIZE_MAX_SB - 1) / 2)
#if TX_SIZE_PROBS == 6
#define get_tx_probs_offset(b) ((b) < BLOCK_SIZE_MB16X16 ? 0 : \
(b) < BLOCK_SIZE_SB32X32 ? 1 : 3)
#else
#define get_tx_probs_offset(b) 0
#endif
#define get_tx_probs(c, b) ((b) < BLOCK_SIZE_MB16X16 ? \
(c)->fc.tx_probs_8x8p : \
(b) < BLOCK_SIZE_SB32X32 ? \
(c)->fc.tx_probs_16x16p : (c)->fc.tx_probs_32x32p)
/* For keyframes, intra block modes are predicted by the (already decoded)
modes for the Y blocks to the left and above us; for interframes, there
......
......@@ -149,53 +149,52 @@ static const vp9_prob default_single_ref_p[REF_CONTEXTS][2] = {
{ 235, 248 },
};
void tx_counts_to_branch_counts(unsigned int *tx_count_32x32p,
unsigned int *tx_count_16x16p,
unsigned int *tx_count_8x8p,
unsigned int (*ct)[2]) {
#if TX_SIZE_PROBS == 6
ct[0][0] = tx_count_8x8p[TX_4X4];
ct[0][1] = tx_count_8x8p[TX_8X8];
ct[1][0] = tx_count_16x16p[TX_4X4];
ct[1][1] = tx_count_16x16p[TX_8X8] + tx_count_16x16p[TX_16X16];
ct[2][0] = tx_count_16x16p[TX_8X8];
ct[2][1] = tx_count_16x16p[TX_16X16];
ct[3][0] = tx_count_32x32p[TX_4X4];
ct[3][1] = tx_count_32x32p[TX_8X8] + tx_count_32x32p[TX_16X16] +
tx_count_32x32p[TX_32X32];
ct[4][0] = tx_count_32x32p[TX_8X8];
ct[4][1] = tx_count_32x32p[TX_16X16] + tx_count_32x32p[TX_32X32];
ct[5][0] = tx_count_32x32p[TX_16X16];
ct[5][1] = tx_count_32x32p[TX_32X32];
#else
ct[0][0] = tx_count_32x32p[TX_4X4] +
tx_count_16x16p[TX_4X4] +
tx_count_8x8p[TX_4X4];
ct[0][1] = tx_count_32x32p[TX_8X8] +
tx_count_32x32p[TX_16X16] +
tx_count_32x32p[TX_32X32] +
tx_count_16x16p[TX_8X8] +
tx_count_16x16p[TX_16X16] +
tx_count_8x8p[TX_8X8];
ct[1][0] = tx_count_32x32p[TX_8X8] +
tx_count_16x16p[TX_8X8];
ct[1][1] = tx_count_32x32p[TX_16X16] +
tx_count_32x32p[TX_32X32] +
tx_count_16x16p[TX_16X16];
ct[2][0] = tx_count_32x32p[TX_16X16];
ct[2][1] = tx_count_32x32p[TX_32X32];
#endif
}
#if TX_SIZE_PROBS == 6
const vp9_prob vp9_default_tx_probs[TX_SIZE_PROBS] = {
96, 96, 96, 96, 96, 96
const vp9_prob vp9_default_tx_probs_32x32p[TX_SIZE_MAX_SB]
[TX_SIZE_MAX_SB - 1] = {
{ 16, 64, 96, },
{ 32, 64, 96, },
{ 32, 64, 96, },
{ 32, 64, 96, },
};
#else
const vp9_prob vp9_default_tx_probs[TX_SIZE_PROBS] = {
96, 96, 96
const vp9_prob vp9_default_tx_probs_16x16p[TX_SIZE_MAX_SB - 1]
[TX_SIZE_MAX_SB - 2] = {
{ 32, 96, },
{ 64, 96, },
{ 64, 96, },
};
#endif
const vp9_prob vp9_default_tx_probs_8x8p[TX_SIZE_MAX_SB - 2]
[TX_SIZE_MAX_SB - 3] = {
{ 96, },
{ 96, },
};
void tx_counts_to_branch_counts_32x32(unsigned int *tx_count_32x32p,
unsigned int (*ct_32x32p)[2]) {
ct_32x32p[0][0] = tx_count_32x32p[TX_4X4];
ct_32x32p[0][1] = tx_count_32x32p[TX_8X8] +
tx_count_32x32p[TX_16X16] +
tx_count_32x32p[TX_32X32];
ct_32x32p[1][0] = tx_count_32x32p[TX_8X8];
ct_32x32p[1][1] = tx_count_32x32p[TX_16X16] +
tx_count_32x32p[TX_32X32];
ct_32x32p[2][0] = tx_count_32x32p[TX_16X16];
ct_32x32p[2][1] = tx_count_32x32p[TX_32X32];
}
void tx_counts_to_branch_counts_16x16(unsigned int *tx_count_16x16p,
unsigned int (*ct_16x16p)[2]) {
ct_16x16p[0][0] = tx_count_16x16p[TX_4X4];
ct_16x16p[0][1] = tx_count_16x16p[TX_8X8] +
tx_count_16x16p[TX_16X16];
ct_16x16p[1][0] = tx_count_16x16p[TX_8X8];
ct_16x16p[1][1] = tx_count_16x16p[TX_16X16];
}
void tx_counts_to_branch_counts_8x8(unsigned int *tx_count_8x8p,
unsigned int (*ct_8x8p)[2]) {
ct_8x8p[0][0] = tx_count_8x8p[TX_4X4];
ct_8x8p[0][1] = tx_count_8x8p[TX_8X8];
}
const vp9_prob vp9_default_mbskip_probs[MBSKIP_CONTEXTS] = {
192, 128, 64
......@@ -223,8 +222,12 @@ void vp9_init_mbmode_probs(VP9_COMMON *x) {
sizeof(default_comp_ref_p));
vpx_memcpy(x->fc.single_ref_prob, default_single_ref_p,
sizeof(default_single_ref_p));
vpx_memcpy(x->fc.tx_probs, vp9_default_tx_probs,
sizeof(vp9_default_tx_probs));
vpx_memcpy(x->fc.tx_probs_32x32p, vp9_default_tx_probs_32x32p,
sizeof(vp9_default_tx_probs_32x32p));
vpx_memcpy(x->fc.tx_probs_16x16p, vp9_default_tx_probs_16x16p,
sizeof(vp9_default_tx_probs_16x16p));
vpx_memcpy(x->fc.tx_probs_8x8p, vp9_default_tx_probs_8x8p,
sizeof(vp9_default_tx_probs_8x8p));
vpx_memcpy(x->fc.mbskip_probs, vp9_default_mbskip_probs,
sizeof(vp9_default_mbskip_probs));
}
......@@ -431,17 +434,51 @@ void vp9_adapt_mode_probs(VP9_COMMON *cm) {
}
}
if (cm->txfm_mode == TX_MODE_SELECT) {
unsigned int branch_ct[TX_SIZE_PROBS][2];
tx_counts_to_branch_counts(cm->fc.tx_count_32x32p,
cm->fc.tx_count_16x16p,
cm->fc.tx_count_8x8p, branch_ct);
for (i = 0; i < TX_SIZE_PROBS; ++i) {
int factor;
int count = branch_ct[i][0] + branch_ct[i][1];
vp9_prob prob = get_binary_prob(branch_ct[i][0], branch_ct[i][1]);
count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT);
cm->fc.tx_probs[i] = weighted_prob(cm->fc.pre_tx_probs[i], prob, factor);
int j;
unsigned int branch_ct_8x8p[TX_SIZE_MAX_SB - 3][2];
unsigned int branch_ct_16x16p[TX_SIZE_MAX_SB - 2][2];
unsigned int branch_ct_32x32p[TX_SIZE_MAX_SB - 1][2];
for (i = 0; i < TX_SIZE_MAX_SB - 2; ++i) {
tx_counts_to_branch_counts_8x8(cm->fc.tx_count_8x8p[i],
branch_ct_8x8p);
for (j = 0; j < TX_SIZE_MAX_SB - 3; ++j) {
int factor;
int count = branch_ct_8x8p[j][0] + branch_ct_8x8p[j][1];
vp9_prob prob = get_binary_prob(branch_ct_8x8p[j][0],
branch_ct_8x8p[j][1]);
count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT);
cm->fc.tx_probs_8x8p[i][j] = weighted_prob(
cm->fc.pre_tx_probs_8x8p[i][j], prob, factor);
}
}
for (i = 0; i < TX_SIZE_MAX_SB - 1; ++i) {
tx_counts_to_branch_counts_16x16(cm->fc.tx_count_16x16p[i],
branch_ct_16x16p);
for (j = 0; j < TX_SIZE_MAX_SB - 2; ++j) {
int factor;
int count = branch_ct_16x16p[j][0] + branch_ct_16x16p[j][1];
vp9_prob prob = get_binary_prob(branch_ct_16x16p[j][0],
branch_ct_16x16p[j][1]);
count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT);
cm->fc.tx_probs_16x16p[i][j] = weighted_prob(
cm->fc.pre_tx_probs_16x16p[i][j], prob, factor);
}
}
for (i = 0; i < TX_SIZE_MAX_SB; ++i) {
tx_counts_to_branch_counts_32x32(cm->fc.tx_count_32x32p[i],
branch_ct_32x32p);
for (j = 0; j < TX_SIZE_MAX_SB - 1; ++j) {
int factor;
int count = branch_ct_32x32p[j][0] + branch_ct_32x32p[j][1];
vp9_prob prob = get_binary_prob(branch_ct_32x32p[j][0],
branch_ct_32x32p[j][1]);
count = count > MODE_COUNT_SAT ? MODE_COUNT_SAT : count;
factor = (MODE_MAX_UPDATE_FACTOR * count / MODE_COUNT_SAT);
cm->fc.tx_probs_32x32p[i][j] = weighted_prob(
cm->fc.pre_tx_probs_32x32p[i][j], prob, factor);
}
}
}
for (i = 0; i < MBSKIP_CONTEXTS; ++i)
......
......@@ -16,6 +16,8 @@
#define SUBMVREF_COUNT 5
// #define MODE_STATS
extern int vp9_mv_cont(const int_mv *l, const int_mv *a);
......@@ -75,11 +77,17 @@ extern struct vp9_token vp9_switchable_interp_encodings[VP9_SWITCHABLE_FILTERS];
extern const vp9_prob vp9_switchable_interp_prob[VP9_SWITCHABLE_FILTERS + 1]
[VP9_SWITCHABLE_FILTERS - 1];
extern const vp9_prob vp9_default_tx_probs[TX_SIZE_PROBS];
extern void tx_counts_to_branch_counts(unsigned int *tx_count_32x32p,
unsigned int *tx_count_16x16p,
unsigned int *tx_count_8x8p,
unsigned int (*ct)[2]);
extern const vp9_prob vp9_default_tx_probs_32x32p[TX_SIZE_MAX_SB]
[TX_SIZE_MAX_SB - 1];
extern const vp9_prob vp9_default_tx_probs_16x16p[TX_SIZE_MAX_SB - 1]
[TX_SIZE_MAX_SB - 2];
extern const vp9_prob vp9_default_tx_probs_8x8p[TX_SIZE_MAX_SB - 2]
[TX_SIZE_MAX_SB - 3];
extern void tx_counts_to_branch_counts_32x32(unsigned int *tx_count_32x32p,
unsigned int (*ct_32x32p)[2]);
extern void tx_counts_to_branch_counts_16x16(unsigned int *tx_count_16x16p,
unsigned int (*ct_16x16p)[2]);
extern void tx_counts_to_branch_counts_8x8(unsigned int *tx_count_8x8p,
unsigned int (*ct_8x8p)[2]);
#endif // VP9_COMMON_VP9_ENTROPYMODE_H_
......@@ -89,11 +89,16 @@ typedef struct frame_contexts {
unsigned int comp_inter_count[COMP_INTER_CONTEXTS][2];
unsigned int single_ref_count[REF_CONTEXTS][2][2];
unsigned int comp_ref_count[REF_CONTEXTS][2];
vp9_prob tx_probs[TX_SIZE_PROBS];
vp9_prob pre_tx_probs[TX_SIZE_PROBS];
unsigned int tx_count_32x32p[TX_SIZE_MAX_SB];
unsigned int tx_count_16x16p[TX_SIZE_MAX_SB - 1];
unsigned int tx_count_8x8p[TX_SIZE_MAX_SB - 2];
vp9_prob tx_probs_32x32p[TX_SIZE_MAX_SB][TX_SIZE_MAX_SB - 1];
vp9_prob tx_probs_16x16p[TX_SIZE_MAX_SB - 1][TX_SIZE_MAX_SB - 2];
vp9_prob tx_probs_8x8p[TX_SIZE_MAX_SB - 2][TX_SIZE_MAX_SB - 3];
vp9_prob pre_tx_probs_32x32p[TX_SIZE_MAX_SB][TX_SIZE_MAX_SB - 1];
vp9_prob pre_tx_probs_16x16p[TX_SIZE_MAX_SB - 1][TX_SIZE_MAX_SB - 2];
vp9_prob pre_tx_probs_8x8p[TX_SIZE_MAX_SB - 2][TX_SIZE_MAX_SB - 3];
unsigned int tx_count_32x32p[TX_SIZE_MAX_SB][TX_SIZE_MAX_SB];
unsigned int tx_count_16x16p[TX_SIZE_MAX_SB - 1][TX_SIZE_MAX_SB - 1];
unsigned int tx_count_8x8p[TX_SIZE_MAX_SB - 2][TX_SIZE_MAX_SB - 2];
vp9_prob mbskip_probs[MBSKIP_CONTEXTS];
vp9_prob pre_mbskip_probs[MBSKIP_CONTEXTS];
......
......@@ -348,6 +348,37 @@ unsigned char vp9_get_pred_context(const VP9_COMMON *const cm,
break;
}
case PRED_TX_SIZE: {
int above_context = TX_16X16, left_context = TX_16X16;
int max_tx_size;
if (mi->mbmi.sb_type < BLOCK_SIZE_SB8X8)
max_tx_size = TX_4X4;
else if (mi->mbmi.sb_type < BLOCK_SIZE_MB16X16)
max_tx_size = TX_8X8;
else if (mi->mbmi.sb_type < BLOCK_SIZE_SB32X32)
max_tx_size = TX_16X16;
else
max_tx_size = TX_32X32;
if (xd->up_available) {
above_context = (above_mi->mbmi.mb_skip_coeff ?
max_tx_size : above_mi->mbmi.txfm_size);
}
if (xd->left_available) {
left_context = (left_mi->mbmi.mb_skip_coeff ?
max_tx_size : left_mi->mbmi.txfm_size);
}
if (!xd->left_available) {
left_context = above_context;
}
if (!xd->up_available) {
above_context = left_context;
}
pred_context = (above_context + left_context + 1) >> 1;
if (pred_context > max_tx_size)
pred_context = max_tx_size;
break;
}
default:
assert(0);
pred_context = 0; // *** add error trap code.
......@@ -390,11 +421,21 @@ vp9_prob vp9_get_pred_prob(const VP9_COMMON *const cm,
const vp9_prob *vp9_get_pred_probs(const VP9_COMMON *const cm,
const MACROBLOCKD *const xd,
PRED_ID pred_id) {
const MODE_INFO *const mi = xd->mode_info_context;
const int pred_context = vp9_get_pred_context(cm, xd, pred_id);
switch (pred_id) {
case PRED_SWITCHABLE_INTERP:
return &cm->fc.switchable_interp_prob[pred_context][0];
case PRED_TX_SIZE:
if (mi->mbmi.sb_type < BLOCK_SIZE_MB16X16)
return cm->fc.tx_probs_8x8p[pred_context];
else if (mi->mbmi.sb_type < BLOCK_SIZE_SB32X32)
return cm->fc.tx_probs_16x16p[pred_context];
else
return cm->fc.tx_probs_32x32p[pred_context];
default:
assert(0);
return NULL; // *** add error trap code.
......
......@@ -24,6 +24,7 @@ typedef enum {
PRED_SINGLE_REF_P1 = 5,
PRED_SINGLE_REF_P2 = 6,
PRED_COMP_REF_P = 7,
PRED_TX_SIZE = 8
} PRED_ID;
unsigned char vp9_get_pred_context(const VP9_COMMON *const cm,
......
......@@ -63,21 +63,22 @@ static void set_segment_id(VP9_COMMON *cm, MB_MODE_INFO *mbmi,
}
}
static TX_SIZE select_txfm_size(VP9_COMMON *cm, vp9_reader *r,
BLOCK_SIZE_TYPE bsize) {
int tx_probs_offset = get_tx_probs_offset(bsize);
TX_SIZE txfm_size = vp9_read(r, cm->fc.tx_probs[tx_probs_offset]);
static TX_SIZE select_txfm_size(VP9_COMMON *cm, MACROBLOCKD *xd,
vp9_reader *r, BLOCK_SIZE_TYPE bsize) {
const int context = vp9_get_pred_context(cm, xd, PRED_TX_SIZE);
const vp9_prob *tx_probs = vp9_get_pred_probs(cm, xd, PRED_TX_SIZE);
TX_SIZE txfm_size = vp9_read(r, tx_probs[0]);
if (txfm_size != TX_4X4 && bsize >= BLOCK_SIZE_MB16X16) {
txfm_size += vp9_read(r, cm->fc.tx_probs[tx_probs_offset + 1]);
txfm_size += vp9_read(r, tx_probs[1]);
if (txfm_size != TX_8X8 && bsize >= BLOCK_SIZE_SB32X32)
txfm_size += vp9_read(r, cm->fc.tx_probs[tx_probs_offset + 2]);
txfm_size += vp9_read(r, tx_probs[2]);
}
if (bsize >= BLOCK_SIZE_SB32X32) {
cm->fc.tx_count_32x32p[txfm_size]++;
cm->fc.tx_count_32x32p[context][txfm_size]++;
} else if (bsize >= BLOCK_SIZE_MB16X16) {
cm->fc.tx_count_16x16p[txfm_size]++;
cm->fc.tx_count_16x16p[context][txfm_size]++;
} else {
cm->fc.tx_count_8x8p[txfm_size]++;
cm->fc.tx_count_8x8p[context][txfm_size]++;
}
return txfm_size;
}
......@@ -107,7 +108,7 @@ static void kfread_modes(VP9D_COMP *pbi, MODE_INFO *m,
if (cm->txfm_mode == TX_MODE_SELECT &&
m->mbmi.sb_type >= BLOCK_SIZE_SB8X8) {
m->mbmi.txfm_size = select_txfm_size(cm, r, m->mbmi.sb_type);
m->mbmi.txfm_size = select_txfm_size(cm, xd, r, m->mbmi.sb_type);
} else if (cm->txfm_mode >= ALLOW_32X32 &&
m->mbmi.sb_type >= BLOCK_SIZE_SB32X32) {
m->mbmi.txfm_size = TX_32X32;
......@@ -544,7 +545,7 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
if (cm->txfm_mode == TX_MODE_SELECT &&
(mbmi->mb_skip_coeff == 0 || mbmi->ref_frame[0] == INTRA_FRAME) &&
bsize >= BLOCK_SIZE_SB8X8) {
mbmi->txfm_size = select_txfm_size(cm, r, bsize);
mbmi->txfm_size = select_txfm_size(cm, xd, r, bsize);
} else if (bsize >= BLOCK_SIZE_SB32X32 &&
cm->txfm_mode >= ALLOW_32X32) {
mbmi->txfm_size = TX_32X32;
......
......@@ -58,15 +58,35 @@ static void setup_txfm_mode(VP9_COMMON *pc, int lossless, vp9_reader *r) {
if (pc->txfm_mode == ALLOW_32X32)
pc->txfm_mode += vp9_read_bit(r);
if (pc->txfm_mode == TX_MODE_SELECT) {
int i;
for (i = 0; i < TX_SIZE_PROBS; ++i) {
if (vp9_read(r, VP9_DEF_UPDATE_PROB))
pc->fc.tx_probs[i] =
vp9_read_prob_diff_update(r, pc->fc.tx_probs[i]);
int i, j;
for (i = 0; i < TX_SIZE_MAX_SB - 2; ++i) {
for (j = 0; j < TX_SIZE_MAX_SB - 3; ++j) {
if (vp9_read(r, VP9_DEF_UPDATE_PROB))
pc->fc.tx_probs_8x8p[i][j] =
vp9_read_prob_diff_update(r, pc->fc.tx_probs_8x8p[i][j]);
}
}
for (i = 0; i < TX_SIZE_MAX_SB - 1; ++i) {
for (j = 0; j < TX_SIZE_MAX_SB - 2; ++j) {
if (vp9_read(r, VP9_DEF_UPDATE_PROB))
pc->fc.tx_probs_16x16p[i][j] =
vp9_read_prob_diff_update(r, pc->fc.tx_probs_16x16p[i][j]);
}
}
for (i = 0; i < TX_SIZE_MAX_SB; ++i) {
for (j = 0; j < TX_SIZE_MAX_SB - 1; ++j) {
if (vp9_read(r, VP9_DEF_UPDATE_PROB))
pc->fc.tx_probs_32x32p[i][j] =
vp9_read_prob_diff_update(r, pc->fc.tx_probs_32x32p[i][j]);
}
}
} else {
vpx_memcpy(pc->fc.tx_probs, vp9_default_tx_probs,
sizeof(vp9_default_tx_probs));
vpx_memcpy(pc->fc.tx_probs_8x8p, vp9_default_tx_probs_8x8p,
sizeof(vp9_default_tx_probs_8x8p));
vpx_memcpy(pc->fc.tx_probs_16x16p, vp9_default_tx_probs_16x16p,
sizeof(vp9_default_tx_probs_16x16p));
vpx_memcpy(pc->fc.tx_probs_32x32p, vp9_default_tx_probs_32x32p,
sizeof(vp9_default_tx_probs_32x32p));
}
}
}
......@@ -793,7 +813,9 @@ static void update_frame_context(FRAME_CONTEXT *fc) {
fc->pre_nmvc = fc->nmvc;
vp9_copy(fc->pre_switchable_interp_prob, fc->switchable_interp_prob);
vp9_copy(fc->pre_inter_mode_probs, fc->inter_mode_probs);
vp9_copy(fc->pre_tx_probs, fc->tx_probs);
vp9_copy(fc->pre_tx_probs_8x8p, fc->tx_probs_8x8p);
vp9_copy(fc->pre_tx_probs_16x16p, fc->tx_probs_16x16p);
vp9_copy(fc->pre_tx_probs_32x32p, fc->tx_probs_32x32p);
vp9_copy(fc->pre_mbskip_probs, fc->mbskip_probs);
vp9_zero(fc->coef_counts);
......
......@@ -51,6 +51,74 @@ extern unsigned int active_section;
#define vp9_cost_upd ((int)(vp9_cost_one(upd) - vp9_cost_zero(upd)) >> 8)
#define vp9_cost_upd256 ((int)(vp9_cost_one(upd) - vp9_cost_zero(upd)))
#ifdef MODE_STATS
int64_t tx_count_32x32p_stats[TX_SIZE_MAX_SB][TX_SIZE_MAX_SB];
int64_t tx_count_16x16p_stats[TX_SIZE_MAX_SB - 1][TX_SIZE_MAX_SB - 1];
int64_t tx_count_8x8p_stats[TX_SIZE_MAX_SB - 2][TX_SIZE_MAX_SB - 2];
void init_tx_count_stats() {
vp9_zero(tx_count_32x32p_stats);
vp9_zero(tx_count_16x16p_stats);
vp9_zero(tx_count_8x8p_stats);
}
static void update_tx_count_stats(VP9_COMMON *cm) {
int i, j;
for (i = 0; i < TX_SIZE_MAX_SB; i++) {
for (j = 0; j < TX_SIZE_MAX_SB; j++) {
tx_count_32x32p_stats[i][j] += cm->fc.tx_count_32x32p[i][j];
}
}
for (i = 0; i < TX_SIZE_MAX_SB - 1; i++) {
for (j = 0; j < TX_SIZE_MAX_SB - 1; j++) {
tx_count_16x16p_stats[i][j] += cm->fc.tx_count_16x16p[i][j];
}
}
for (i = 0; i < TX_SIZE_MAX_SB - 2; i++) {
for (j = 0; j < TX_SIZE_MAX_SB - 2; j++) {
tx_count_8x8p_stats[i][j] += cm->fc.tx_count_8x8p[i][j];
}
}
}
void write_tx_count_stats() {
int i, j;
FILE *fp = fopen("tx_count.bin", "wb");
fwrite(tx_count_32x32p_stats, sizeof(tx_count_32x32p_stats), 1, fp);
fwrite(tx_count_16x16p_stats, sizeof(tx_count_16x16p_stats), 1, fp);
fwrite(tx_count_8x8p_stats, sizeof(tx_count_8x8p_stats), 1, fp);
fclose(fp);
printf("vp9_default_tx_count_32x32p[TX_SIZE_MAX_SB][TX_SIZE_MAX_SB] = {\n");
for (i = 0; i < TX_SIZE_MAX_SB; i++) {
printf("{ ");
for (j = 0; j < TX_SIZE_MAX_SB; j++) {
printf("%"PRId64", ", tx_count_32x32p_stats[i][j]);
}
printf("},\n");
}
printf("};\n");
printf("vp9_default_tx_count_16x16p[TX_SIZE_MAX_SB-1][TX_SIZE_MAX_SB-1] = {\n");
for (i = 0; i < TX_SIZE_MAX_SB - 1; i++) {
printf("{ ");
for (j = 0; j < TX_SIZE_MAX_SB - 1; j++) {
printf("%"PRId64", ", tx_count_16x16p_stats[i][j]);
}
printf("},\n");
}
printf("};\n");
printf("vp9_default_tx_count_8x8p[TX_SIZE_MAX_SB-2][TX_SIZE_MAX_SB-2] = {\n");
for (i = 0; i < TX_SIZE_MAX_SB - 2; i++) {
printf("{ ");
for (j = 0; j < TX_SIZE_MAX_SB - 2; j++) {
printf("%"PRId64", ", tx_count_8x8p_stats[i][j]);
}
printf("},\n");
}
printf("};\n");
}
#endif
static int update_bits[255];
static INLINE void write_le32(uint8_t *p, int value) {
......@@ -574,12 +642,12 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, MODE_INFO *m,
!(rf != INTRA_FRAME &&
(skip_coeff || vp9_segfeature_active(xd, segment_id, SEG_LVL_SKIP)))) {
TX_SIZE sz = mi->txfm_size;
int tx_probs_offset = get_tx_probs_offset(mi->sb_type);
vp9_write(bc, sz != TX_4X4, pc->fc.tx_probs[tx_probs_offset]);
const vp9_prob *tx_probs = vp9_get_pred_probs(pc, xd, PRED_TX_SIZE);
vp9_write(bc, sz != TX_4X4, tx_probs[0]);
if (mi->sb_type >= BLOCK_SIZE_MB16X16 && sz != TX_4X4) {
vp9_write(bc, sz != TX_8X8, pc->fc.tx_probs[tx_probs_offset + 1]);
vp9_write(bc, sz != TX_8X8, tx_probs[1]);
if (mi->sb_type >= BLOCK_SIZE_SB32X32 && sz != TX_8X8)
vp9_write(bc, sz != TX_16X16, pc->fc.tx_probs[tx_probs_offset + 2]);
vp9_write(bc, sz != TX_16X16, tx_probs[2]);
}
}
......@@ -663,10 +731,6 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, MODE_INFO *m,
}
}
}
#ifdef MODE_STATS
++count_mb_seg[mi->partitioning];
#endif
} else if (mode == NEWMV) {
#ifdef ENTROPY_STATS
active_section = 5;
......@@ -705,12 +769,12 @@ static void write_mb_modes_kf(const VP9_COMP *cpi,
if (m->mbmi.sb_type >= BLOCK_SIZE_SB8X8 && c->txfm_mode == TX_MODE_SELECT) {
TX_SIZE sz = m->mbmi.txfm_size;
int tx_probs_offset = get_tx_probs_offset(m->mbmi.sb_type);
vp9_write(bc, sz != TX_4X4, c->fc.tx_probs[tx_probs_offset]);
const vp9_prob *tx_probs = vp9_get_pred_probs(c, xd, PRED_TX_SIZE);
vp9_write(bc, sz != TX_4X4, tx_probs[0]);
if (m->mbmi.sb_type >= BLOCK_SIZE_MB16X16 && sz != TX_4X4) {
vp9_write(bc, sz != TX_8X8, c->fc.tx_probs[tx_probs_offset + 1]);
vp9_write(bc, sz != TX_8X8, tx_probs[1]);
if (m->mbmi.sb_type >= BLOCK_SIZE_SB32X32 && sz != TX_8X8)
vp9_write(bc, sz != TX_16X16, c->fc.tx_probs[tx_probs_offset + 2]);
vp9_write(bc, sz != TX_16X16, tx_probs[2]);
}
}
......@@ -1226,19 +1290,46 @@ static void encode_txfm_probs(VP9_COMP *cpi, vp9_writer *w) {
// Probabilities
if (cm->txfm_mode == TX_MODE_SELECT) {
int i;
unsigned int ct[TX_SIZE_PROBS][2];
tx_counts_to_branch_counts(cm->fc.tx_count_32x32p,
cm->fc.tx_count_16x16p,
cm->fc.tx_count_8x8p, ct);
for (i = 0; i < TX_SIZE_PROBS; i++) {
vp9_cond_prob_diff_update(w, &cm->fc.tx_probs[i],
VP9_DEF_UPDATE_PROB, ct[i]);
int i, j;
unsigned int ct_8x8p[TX_SIZE_MAX_SB - 3][2];
unsigned int ct_16x16p[TX_SIZE_MAX_SB - 2][2];
unsigned int ct_32x32p[TX_SIZE_MAX_SB - 1][2];
for (i = 0; i < TX_SIZE_MAX_SB - 2; i++) {
tx_counts_to_branch_counts_8x8(cm->fc.tx_count_8x8p[i],
ct_8x8p);
for (j = 0; j < TX_SIZE_MAX_SB - 3; j++) {
vp9_cond_prob_diff_update(w, &cm->fc.tx_probs_8x8p[i][j],
VP9_DEF_UPDATE_PROB, ct_8x8p[j]);
}
}
for (i = 0; i < TX_SIZE_MAX_SB - 1; i++) {
tx_counts_to_branch_counts_16x16(cm->fc.tx_count_16x16p[i],
ct_16x16p);
for (j = 0; j < TX_SIZE_MAX_SB - 2; j++) {
vp9_cond_prob_diff_update(w, &cm->fc.tx_probs_16x16p[i][j],
VP9_DEF_UPDATE_PROB, ct_16x16p[j]);
}
}
for (i = 0; i < TX_SIZE_MAX_SB; i++) {
tx_counts_to_branch_counts_32x32(cm->fc.tx_count_32x32p[i],
ct_32x32p);
for (j = 0; j < TX_SIZE_MAX_SB - 1; j++) {
vp9_cond_prob_diff_update(w, &cm->fc.tx_probs_32x32p[i][j],
VP9_DEF_UPDATE_PROB, ct_32x32p[j]);
}