Commit d6ee8a8c authored by Thomas Davies's avatar Thomas Davies

Add a CDF for coding delta_q.

Also remove forward updates for delta_q when EC_ADAPT
is enabled.

Change-Id: Idf71b57bfe7763bc60595bc45768e624dd7b67bd
parent 73126c08
...@@ -627,6 +627,11 @@ static const aom_prob default_obmc_prob[BLOCK_SIZES] = { ...@@ -627,6 +627,11 @@ static const aom_prob default_obmc_prob[BLOCK_SIZES] = {
#if CONFIG_DELTA_Q #if CONFIG_DELTA_Q
static const aom_prob default_delta_q_probs[DELTA_Q_PROBS] = { 220, 220, 220 }; static const aom_prob default_delta_q_probs[DELTA_Q_PROBS] = { 220, 220, 220 };
#if CONFIG_EC_MULTISYMBOL
static const aom_cdf_prob default_delta_q_cdf[CDF_SIZE(DELTA_Q_PROBS + 1)] = {
28160, 32120, 32677, 32768, 0
};
#endif
#endif #endif
#if CONFIG_EC_MULTISYMBOL #if CONFIG_EC_MULTISYMBOL
int av1_intra_mode_ind[INTRA_MODES]; int av1_intra_mode_ind[INTRA_MODES];
...@@ -1827,6 +1832,9 @@ static void init_mode_probs(FRAME_CONTEXT *fc) { ...@@ -1827,6 +1832,9 @@ static void init_mode_probs(FRAME_CONTEXT *fc) {
#endif #endif
#if CONFIG_DELTA_Q #if CONFIG_DELTA_Q
av1_copy(fc->delta_q_prob, default_delta_q_probs); av1_copy(fc->delta_q_prob, default_delta_q_probs);
#if CONFIG_EC_MULTISYMBOL
av1_copy(fc->delta_q_cdf, default_delta_q_cdf);
#endif
#endif #endif
} }
......
...@@ -254,6 +254,9 @@ typedef struct frame_contexts { ...@@ -254,6 +254,9 @@ typedef struct frame_contexts {
aom_cdf_prob kf_y_cdf[INTRA_MODES][INTRA_MODES][CDF_SIZE(INTRA_MODES)]; aom_cdf_prob kf_y_cdf[INTRA_MODES][INTRA_MODES][CDF_SIZE(INTRA_MODES)];
aom_cdf_prob tx_size_cdf[MAX_TX_DEPTH][TX_SIZE_CONTEXTS] aom_cdf_prob tx_size_cdf[MAX_TX_DEPTH][TX_SIZE_CONTEXTS]
[CDF_SIZE(MAX_TX_DEPTH + 1)]; [CDF_SIZE(MAX_TX_DEPTH + 1)];
#if CONFIG_DELTA_Q
aom_cdf_prob delta_q_cdf[CDF_SIZE(DELTA_Q_PROBS + 1)];
#endif
#if !CONFIG_EXT_TX #if !CONFIG_EXT_TX
aom_cdf_prob intra_ext_tx_cdf[EXT_TX_SIZES][TX_TYPES][CDF_SIZE(TX_TYPES)]; aom_cdf_prob intra_ext_tx_cdf[EXT_TX_SIZES][TX_TYPES][CDF_SIZE(TX_TYPES)];
aom_cdf_prob inter_ext_tx_cdf[EXT_TX_SIZES][CDF_SIZE(TX_TYPES)]; aom_cdf_prob inter_ext_tx_cdf[EXT_TX_SIZES][CDF_SIZE(TX_TYPES)];
......
...@@ -4609,7 +4609,7 @@ static int read_compressed_header(AV1Decoder *pbi, const uint8_t *data, ...@@ -4609,7 +4609,7 @@ static int read_compressed_header(AV1Decoder *pbi, const uint8_t *data,
for (k = 0; k < SKIP_CONTEXTS; ++k) for (k = 0; k < SKIP_CONTEXTS; ++k)
av1_diff_update_prob(&r, &fc->skip_probs[k], ACCT_STR); av1_diff_update_prob(&r, &fc->skip_probs[k], ACCT_STR);
#if CONFIG_DELTA_Q #if CONFIG_DELTA_Q && !CONFIG_EC_ADAPT
for (k = 0; k < DELTA_Q_PROBS; ++k) for (k = 0; k < DELTA_Q_PROBS; ++k)
av1_diff_update_prob(&r, &fc->delta_q_prob[k], ACCT_STR); av1_diff_update_prob(&r, &fc->delta_q_prob[k], ACCT_STR);
#endif #endif
......
...@@ -67,16 +67,33 @@ static int read_delta_qindex(AV1_COMMON *cm, MACROBLOCKD *xd, aom_reader *r, ...@@ -67,16 +67,33 @@ static int read_delta_qindex(AV1_COMMON *cm, MACROBLOCKD *xd, aom_reader *r,
const int b_col = mi_col & MAX_MIB_MASK; const int b_col = mi_col & MAX_MIB_MASK;
const int b_row = mi_row & MAX_MIB_MASK; const int b_row = mi_row & MAX_MIB_MASK;
const int read_delta_q_flag = (b_col == 0 && b_row == 0); const int read_delta_q_flag = (b_col == 0 && b_row == 0);
int rem_bits, thr, bit = 1; int rem_bits, thr;
int i, smallval;
#if CONFIG_EC_ADAPT
FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
(void)cm;
#else
FRAME_CONTEXT *ec_ctx = cm->fc;
#endif
if ((bsize != BLOCK_64X64 || mbmi->skip == 0) && read_delta_q_flag) { if ((bsize != BLOCK_64X64 || mbmi->skip == 0) && read_delta_q_flag) {
#if !CONFIG_EC_MULTISYMBOL
int bit = 1;
abs = 0; abs = 0;
while (abs < DELTA_Q_SMALL && bit) { while (abs < DELTA_Q_SMALL && bit) {
bit = aom_read(r, cm->fc->delta_q_prob[abs], ACCT_STR); bit = aom_read(r, ec_ctx->delta_q_prob[abs], ACCT_STR);
if (counts) counts->delta_q[abs][bit]++;
abs += bit; abs += bit;
} }
if (abs == DELTA_Q_SMALL) { #else
abs = aom_read_symbol(r, ec_ctx->delta_q_cdf, DELTA_Q_PROBS + 1, ACCT_STR);
#endif
smallval = (abs < DELTA_Q_SMALL);
if (counts) {
for (i = 0; i < abs; ++i) counts->delta_q[i][1]++;
if (smallval) counts->delta_q[abs][0]++;
}
if (!smallval) {
rem_bits = aom_read_literal(r, 3, ACCT_STR); rem_bits = aom_read_literal(r, 3, ACCT_STR);
thr = (1 << rem_bits) + 1; thr = (1 << rem_bits) + 1;
abs = aom_read_literal(r, rem_bits, ACCT_STR) + thr; abs = aom_read_literal(r, rem_bits, ACCT_STR) + thr;
......
...@@ -556,18 +556,31 @@ static void write_motion_mode(const AV1_COMMON *cm, const MB_MODE_INFO *mbmi, ...@@ -556,18 +556,31 @@ static void write_motion_mode(const AV1_COMMON *cm, const MB_MODE_INFO *mbmi,
#endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION #endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
#if CONFIG_DELTA_Q #if CONFIG_DELTA_Q
static void write_delta_qindex(const AV1_COMMON *cm, int delta_qindex, static void write_delta_qindex(const AV1_COMMON *cm, const MACROBLOCKD *xd,
aom_writer *w) { int delta_qindex, aom_writer *w) {
int sign = delta_qindex < 0; int sign = delta_qindex < 0;
int abs = sign ? -delta_qindex : delta_qindex; int abs = sign ? -delta_qindex : delta_qindex;
int rem_bits, thr, i = 0; int rem_bits, thr;
int smallval = abs < DELTA_Q_SMALL ? 1 : 0; int smallval = abs < DELTA_Q_SMALL ? 1 : 0;
#if CONFIG_EC_ADAPT
FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
(void)cm;
#else
FRAME_CONTEXT *ec_ctx = cm->fc;
(void)xd;
#endif
#if CONFIG_EC_MULTISYMBOL
aom_write_symbol(w, AOMMIN(abs, DELTA_Q_SMALL), ec_ctx->delta_q_cdf,
DELTA_Q_PROBS + 1);
#else
int i = 0;
while (i < DELTA_Q_SMALL && i <= abs) { while (i < DELTA_Q_SMALL && i <= abs) {
int bit = (i < abs); int bit = (i < abs);
aom_write(w, bit, cm->fc->delta_q_prob[i]); aom_write(w, bit, ec_ctx->delta_q_prob[i]);
i++; i++;
} }
#endif
if (!smallval) { if (!smallval) {
rem_bits = OD_ILOG_NZ(abs - 1) - 1; rem_bits = OD_ILOG_NZ(abs - 1) - 1;
...@@ -580,6 +593,7 @@ static void write_delta_qindex(const AV1_COMMON *cm, int delta_qindex, ...@@ -580,6 +593,7 @@ static void write_delta_qindex(const AV1_COMMON *cm, int delta_qindex,
} }
} }
#if !CONFIG_EC_ADAPT
static void update_delta_q_probs(AV1_COMMON *cm, aom_writer *w, static void update_delta_q_probs(AV1_COMMON *cm, aom_writer *w,
FRAME_COUNTS *counts) { FRAME_COUNTS *counts) {
int k; int k;
...@@ -593,7 +607,8 @@ static void update_delta_q_probs(AV1_COMMON *cm, aom_writer *w, ...@@ -593,7 +607,8 @@ static void update_delta_q_probs(AV1_COMMON *cm, aom_writer *w,
probwt); probwt);
} }
} }
#endif #endif // CONFIG_EC_ADAPT
#endif // CONFIG_DELTA_Q
static void update_skip_probs(AV1_COMMON *cm, aom_writer *w, static void update_skip_probs(AV1_COMMON *cm, aom_writer *w,
FRAME_COUNTS *counts) { FRAME_COUNTS *counts) {
...@@ -1534,7 +1549,7 @@ static void pack_inter_mode_mvs(AV1_COMP *cpi, const MODE_INFO *mi, ...@@ -1534,7 +1549,7 @@ static void pack_inter_mode_mvs(AV1_COMP *cpi, const MODE_INFO *mi,
if ((bsize != BLOCK_64X64 || skip == 0) && super_block_upper_left) { if ((bsize != BLOCK_64X64 || skip == 0) && super_block_upper_left) {
int reduced_delta_qindex = int reduced_delta_qindex =
(mbmi->current_q_index - xd->prev_qindex) / cm->delta_q_res; (mbmi->current_q_index - xd->prev_qindex) / cm->delta_q_res;
write_delta_qindex(cm, reduced_delta_qindex, w); write_delta_qindex(cm, xd, reduced_delta_qindex, w);
xd->prev_qindex = mbmi->current_q_index; xd->prev_qindex = mbmi->current_q_index;
} }
} }
...@@ -1916,7 +1931,7 @@ static void write_mb_modes_kf(AV1_COMMON *cm, const MACROBLOCKD *xd, ...@@ -1916,7 +1931,7 @@ static void write_mb_modes_kf(AV1_COMMON *cm, const MACROBLOCKD *xd,
if ((bsize != BLOCK_64X64 || skip == 0) && super_block_upper_left) { if ((bsize != BLOCK_64X64 || skip == 0) && super_block_upper_left) {
int reduced_delta_qindex = int reduced_delta_qindex =
(mbmi->current_q_index - xd->prev_qindex) / cm->delta_q_res; (mbmi->current_q_index - xd->prev_qindex) / cm->delta_q_res;
write_delta_qindex(cm, reduced_delta_qindex, w); write_delta_qindex(cm, xd, reduced_delta_qindex, w);
xd->prev_qindex = mbmi->current_q_index; xd->prev_qindex = mbmi->current_q_index;
} }
} }
...@@ -4720,7 +4735,7 @@ static uint32_t write_compressed_header(AV1_COMP *cpi, uint8_t *data) { ...@@ -4720,7 +4735,7 @@ static uint32_t write_compressed_header(AV1_COMP *cpi, uint8_t *data) {
#endif #endif
update_skip_probs(cm, header_bc, counts); update_skip_probs(cm, header_bc, counts);
#if CONFIG_DELTA_Q #if !CONFIG_EC_ADAPT && CONFIG_DELTA_Q
update_delta_q_probs(cm, header_bc, counts); update_delta_q_probs(cm, header_bc, counts);
#endif #endif
#if !CONFIG_EC_ADAPT #if !CONFIG_EC_ADAPT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment