Commit 6675be0a authored by Nathan E. Egge's avatar Nathan E. Egge

Replace od_ec_enc with aom_writer in daala_enc_ctx.

Use the generic AOM entropy encoder in the daala_enc_ctx struct.
This is done in preparation for migrating other entropy coder calls to
 use the more generic entropy coding API.

Change-Id: Id627d12402a397bcb21d48d896c0de249d4d8657
parent c98d2863
......@@ -12,11 +12,19 @@
#include "encint.h"
void od_encode_checkpoint(const daala_enc_ctx *enc, od_rollback_buffer *rbuf) {
od_ec_enc_checkpoint(&rbuf->ec, &enc->ec);
#if CONFIG_DAALA_EC
od_ec_enc_checkpoint(&rbuf->ec, &enc->w.ec);
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
OD_COPY(&rbuf->adapt, &enc->state.adapt, 1);
}
void od_encode_rollback(daala_enc_ctx *enc, const od_rollback_buffer *rbuf) {
od_ec_enc_rollback(&enc->ec, &rbuf->ec);
#if CONFIG_DAALA_EC
od_ec_enc_rollback(&enc->w.ec, &rbuf->ec);
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
OD_COPY(&enc->state.adapt, &rbuf->adapt, 1);
}
......@@ -24,8 +24,8 @@ typedef struct od_rollback_buffer od_rollback_buffer;
struct daala_enc_ctx{
/* Stores context-adaptive CDFs for PVQ. */
od_state state;
/* Daala entropy encoder. */
od_ec_enc ec;
/* AOM entropy encoder. */
aom_writer w;
int use_activity_masking;
/* Mode of quantization matrice : FLAT (0) or HVS (1) */
int qm;
......
......@@ -4700,10 +4700,19 @@ void av1_encode_tile(AV1_COMP *cpi, ThreadData *td, int tile_row,
}
}
od_ec_enc_init(&td->mb.daala_enc.ec, 65025);
#if CONFIG_DAALA_EC
od_ec_enc_init(&td->mb.daala_enc.w.ec, 65025);
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
adapt = &td->mb.daala_enc.state.adapt;
od_ec_enc_reset(&td->mb.daala_enc.ec);
#if CONFIG_DAALA_EC
od_ec_enc_reset(&td->mb.daala_enc.w.ec);
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
od_adapt_ctx_reset(adapt, 0);
#endif // #if CONFIG_PVQ
......@@ -4716,7 +4725,11 @@ void av1_encode_tile(AV1_COMP *cpi, ThreadData *td, int tile_row,
(unsigned int)(tok - cpi->tile_tok[tile_row][tile_col]);
assert(cpi->tok_count[tile_row][tile_col] <= allocated_tokens(*tile_info));
#if CONFIG_PVQ
od_ec_enc_clear(&td->mb.daala_enc.ec);
#if CONFIG_DAALA_EC
od_ec_enc_clear(&td->mb.daala_enc.w.ec);
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
td->mb.pvq_q->last_pos = td->mb.pvq_q->curr_pos;
// rewind current position so that bitstream can be written
......
......@@ -13,6 +13,7 @@
#include "./aom_config.h"
#include "./aom_dsp_rtcd.h"
#include "aom_dsp/bitwriter.h"
#include "aom_dsp/quantize.h"
#include "aom_mem/aom_mem.h"
#include "aom_ports/mem.h"
......@@ -1137,7 +1138,11 @@ int av1_pvq_encode_helper(daala_enc_ctx *daala_enc, tran_low_t *const coeff,
*eob = 0;
tell = od_ec_enc_tell_frac(&daala_enc->ec);
#if CONFIG_DAALA_EC
tell = od_ec_enc_tell_frac(&daala_enc->w.ec);
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
// Change coefficient ordering for pvq encoding.
od_raster_to_coding_order(coeff_pvq, tx_blk_size, tx_type, coeff,
......@@ -1181,12 +1186,16 @@ int av1_pvq_encode_helper(daala_enc_ctx *daala_enc, tran_low_t *const coeff,
// Encode residue of DC coeff, if required.
if (!has_dc_skip || out_int32[0]) {
generic_encode(&daala_enc->ec, &daala_enc->state.adapt.model_dc[plane],
#if CONFIG_DAALA_EC
generic_encode(&daala_enc->w.ec, &daala_enc->state.adapt.model_dc[plane],
abs(out_int32[0]) - has_dc_skip, -1,
&daala_enc->state.adapt.ex_dc[plane][tx_size][0], 2);
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
}
if (out_int32[0]) {
od_ec_enc_bits(&daala_enc->ec, out_int32[0] < 0, 1);
aom_write_bit(&daala_enc->w, out_int32[0] < 0);
skip = 0;
}
......@@ -1206,8 +1215,12 @@ int av1_pvq_encode_helper(daala_enc_ctx *daala_enc, tran_low_t *const coeff,
*eob = tx_blk_size * tx_blk_size;
*rate = (od_ec_enc_tell_frac(&daala_enc->ec) - tell)
#if CONFIG_DAALA_EC
*rate = (od_ec_enc_tell_frac(&daala_enc->w.ec) - tell)
<< (AV1_PROB_COST_SHIFT - OD_BITRES);
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
assert(*rate >= 0);
#if PVQ_CHROMA_RD
if (plane != 0) daala_enc->pvq_norm_lambda = save_pvq_lambda;
......
......@@ -561,10 +561,18 @@ void av1_first_pass(AV1_COMP *cpi, const struct lookahead_entry *source) {
od_init_qm(x->daala_enc.state.qm, x->daala_enc.state.qm_inv,
x->daala_enc.qm == OD_HVS_QM ? OD_QM8_Q4_HVS : OD_QM8_Q4_FLAT);
od_ec_enc_init(&x->daala_enc.ec, 65025);
#if CONFIG_DAALA_EC
od_ec_enc_init(&x->daala_enc.w.ec, 65025);
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
adapt = &x->daala_enc.state.adapt;
od_ec_enc_reset(&x->daala_enc.ec);
#if CONFIG_DAALA_EC
od_ec_enc_reset(&x->daala_enc.w.ec);
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
od_adapt_ctx_reset(adapt, 0);
}
#endif
......@@ -972,7 +980,11 @@ void av1_first_pass(AV1_COMP *cpi, const struct lookahead_entry *source) {
}
#if CONFIG_PVQ
od_ec_enc_clear(&x->daala_enc.ec);
#if CONFIG_DAALA_EC
od_ec_enc_clear(&x->daala_enc.w.ec);
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
x->pvq_q->last_pos = x->pvq_q->curr_pos;
x->pvq_q->curr_pos = 0;
......
......@@ -731,9 +731,13 @@ void od_encode_quantizer_scaling(daala_enc_ctx *enc, int q_scaling,
: 0;
left = sbx > 0 ? enc->state.sb_q_scaling[sby*enc->state.nhsb + (sbx - 1)]
: 0;
od_encode_cdf_adapt(&enc->ec, q_scaling,
#if CONFIG_DAALA_EC
od_encode_cdf_adapt(&enc->w.ec, q_scaling,
enc->state.adapt.q_cdf[above + left*4], 4,
enc->state.adapt.q_increment);
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
}
}
#endif
......@@ -888,11 +892,19 @@ int od_pvq_encode(daala_enc_ctx *enc,
(double)(skip_cdf[2] - skip_cdf[1]));
dc_rate += 1;
tell2 = od_ec_enc_tell_frac(&enc->ec);
#if CONFIG_DAALA_EC
tell2 = od_ec_enc_tell_frac(&enc->w.ec);
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
od_encode_checkpoint(enc, &dc_buf);
generic_encode(&enc->ec, &enc->state.adapt.model_dc[pli],
#if CONFIG_DAALA_EC
generic_encode(&enc->w.ec, &enc->state.adapt.model_dc[pli],
n - 1, -1, &enc->state.adapt.ex_dc[pli][bs][0], 2);
tell2 = od_ec_enc_tell_frac(&enc->ec) - tell2;
tell2 = od_ec_enc_tell_frac(&enc->w.ec) - tell2;
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
dc_rate += tell2/8.0;
od_encode_rollback(enc, &dc_buf);
......@@ -900,10 +912,18 @@ int od_pvq_encode(daala_enc_ctx *enc,
enc->pvq_norm_lambda);
}
}
tell = od_ec_enc_tell_frac(&enc->ec);
#if CONFIG_DAALA_EC
tell = od_ec_enc_tell_frac(&enc->w.ec);
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
/* Code as if we're not skipping. */
od_encode_cdf_adapt(&enc->ec, 2 + (out[0] != 0), skip_cdf,
#if CONFIG_DAALA_EC
od_encode_cdf_adapt(&enc->w.ec, 2 + (out[0] != 0), skip_cdf,
4, enc->state.adapt.skip_increment);
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
if (pvq_info)
pvq_info->ac_dc_coded = 2 + (out[0] != 0);
#if OD_SIGNAL_Q_SCALING
......@@ -944,20 +964,32 @@ int od_pvq_encode(daala_enc_ctx *enc,
/* Encode CFL flip bit just after the first time it's used. */
encode_flip = pli != 0 && is_keyframe && theta[i] != -1 && !cfl_encoded;
if (i == 0 || (!skip_rest && !(skip_dir & (1 << ((i - 1)%3))))) {
pvq_encode_partition(&enc->ec, qg[i], theta[i], max_theta[i], y + off[i],
size[i], k[i], model, &enc->state.adapt, exg + i, ext + i,
#if CONFIG_DAALA_EC
pvq_encode_partition(&enc->w.ec, qg[i], theta[i], max_theta[i],
y + off[i], size[i], k[i], model, &enc->state.adapt, exg + i, ext + i,
robust || is_keyframe, (pli != 0)*OD_TXSIZES*PVQ_MAX_PARTITIONS
+ bs*PVQ_MAX_PARTITIONS + i, is_keyframe, i == 0 && (i < nb_bands - 1),
skip_rest, encode_flip, flip);
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
}
if (i == 0 && !skip_rest && bs > 0) {
od_encode_cdf_adapt(&enc->ec, skip_dir,
#if CONFIG_DAALA_EC
od_encode_cdf_adapt(&enc->w.ec, skip_dir,
&enc->state.adapt.pvq.pvq_skip_dir_cdf[(pli != 0) + 2*(bs - 1)][0], 7,
enc->state.adapt.pvq.pvq_skip_dir_increment);
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
}
if (encode_flip) cfl_encoded = 1;
}
tell = od_ec_enc_tell_frac(&enc->ec) - tell;
#if CONFIG_DAALA_EC
tell = od_ec_enc_tell_frac(&enc->w.ec) - tell;
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
/* Account for the rate of skipping the AC, based on the same DC decision
we made when trying to not skip AC. */
{
......@@ -991,11 +1023,19 @@ int od_pvq_encode(daala_enc_ctx *enc,
(double)skip_cdf[0]);
dc_rate += 1;
tell2 = od_ec_enc_tell_frac(&enc->ec);
#if CONFIG_DAALA_EC
tell2 = od_ec_enc_tell_frac(&enc->w.ec);
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
od_encode_checkpoint(enc, &dc_buf);
generic_encode(&enc->ec, &enc->state.adapt.model_dc[pli],
#if CONFIG_DAALA_EC
generic_encode(&enc->w.ec, &enc->state.adapt.model_dc[pli],
n - 1, -1, &enc->state.adapt.ex_dc[pli][bs][0], 2);
tell2 = od_ec_enc_tell_frac(&enc->ec) - tell2;
tell2 = od_ec_enc_tell_frac(&enc->w.ec) - tell2;
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
dc_rate += tell2/8.0;
od_encode_rollback(enc, &dc_buf);
......@@ -1005,8 +1045,12 @@ int od_pvq_encode(daala_enc_ctx *enc,
}
/* We decide to skip, roll back everything as it was before. */
od_encode_rollback(enc, &buf);
od_encode_cdf_adapt(&enc->ec, out[0] != 0, skip_cdf,
#if CONFIG_DAALA_EC
od_encode_cdf_adapt(&enc->w.ec, out[0] != 0, skip_cdf,
4, enc->state.adapt.skip_increment);
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
if (pvq_info)
pvq_info->ac_dc_coded = (out[0] != 0);
#if OD_SIGNAL_Q_SCALING
......
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