Commit 760c27f1 authored by Nathan E. Egge's avatar Nathan E. Egge

Use aom_writer with generic_encode().

Change the generic_encode() function to take an aom_writer struct
 instead of an od_ec_enc struct.

Change-Id: Icb447fe5ada27aba45fbaea08b28e9fe42c5a404
parent 6b0b4a90
......@@ -69,7 +69,7 @@ void od_encode_cdf_adapt(od_ec_enc *ec, int val, uint16_t *cdf, int n,
int od_decode_cdf_adapt_(od_ec_dec *ec, uint16_t *cdf, int n,
int increment OD_ACC_STR);
void generic_encode(od_ec_enc *enc, generic_encoder *model, int x, int max,
void generic_encode(aom_writer *w, generic_encoder *model, int x, int max,
int *ex_q16, int integration);
double generic_encode_cost(generic_encoder *model, int x, int max,
int *ex_q16);
......
......@@ -2149,7 +2149,7 @@ static void write_modes_b(AV1_COMP *cpi, const TileInfo *const tile,
}
// Encode residue of DC coeff, if exist.
if (!has_dc_skip || (pvq->ac_dc_coded & 1)) { // DC coded?
generic_encode(&w->ec, &adapt->model_dc[plane],
generic_encode(w, &adapt->model_dc[plane],
abs(pvq->dq_dc_residue) - has_dc_skip, -1,
&adapt->ex_dc[plane][pvq->bs][0], 2);
}
......
......@@ -1186,13 +1186,9 @@ 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]) {
#if CONFIG_DAALA_EC
generic_encode(&daala_enc->w.ec, &daala_enc->state.adapt.model_dc[plane],
generic_encode(&daala_enc->w, &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]) {
aom_write_bit(&daala_enc->w, out_int32[0] < 0);
......
......@@ -77,7 +77,7 @@ void od_encode_cdf_adapt(od_ec_enc *ec, int val, uint16_t *cdf, int n,
* distribution is one-sided (zero and up), has a single mode, and decays
* exponentially past the model.
*
* @param [in,out] enc range encoder
* @param [in,out] w multi-symbol entropy encoder
* @param [in,out] model generic probability model
* @param [in] x variable being encoded
* @param [in] max largest value possible
......@@ -85,7 +85,7 @@ void od_encode_cdf_adapt(od_ec_enc *ec, int val, uint16_t *cdf, int n,
* @param [in] integration integration period of ExQ16 (leaky average over
* 1<<integration samples)
*/
void generic_encode(od_ec_enc *enc, generic_encoder *model, int x, int max,
void generic_encode(aom_writer *w, generic_encoder *model, int x, int max,
int *ex_q16, int integration) {
int lg_q1;
int shift;
......@@ -107,9 +107,9 @@ void generic_encode(od_ec_enc *enc, generic_encoder *model, int x, int max,
xs = (x + (1 << shift >> 1)) >> shift;
ms = (max + (1 << shift >> 1)) >> shift;
OD_ASSERT(max == -1 || xs <= ms);
if (max == -1) od_ec_encode_cdf_unscaled(enc, OD_MINI(15, xs), cdf, 16);
if (max == -1) aom_write_symbol_unscaled(w, OD_MINI(15, xs), cdf, 16);
else {
od_ec_encode_cdf_unscaled(enc, OD_MINI(15, xs), cdf, OD_MINI(ms + 1, 16));
aom_write_symbol_unscaled(w, OD_MINI(15, xs), cdf, OD_MINI(ms + 1, 16));
}
if (xs >= 15) {
int e;
......@@ -122,7 +122,12 @@ void generic_encode(od_ec_enc *enc, generic_encoder *model, int x, int max,
e = ((2**ex_q16 >> 8) + (1 << shift >> 1)) >> shift;
decay = OD_MAXI(2, OD_MINI(254, 256*e/(e + 256)));
/* Encode the tail of the distribution assuming exponential decay. */
od_laplace_encode_special(enc, xs - 15, decay, (max == -1) ? -1 : ms - 15);
#if CONFIG_DAALA_EC
od_laplace_encode_special(&w->ec, xs - 15, decay,
(max == -1) ? -1 : ms - 15);
#else
# error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
}
if (shift != 0) {
int special;
......@@ -130,8 +135,12 @@ void generic_encode(od_ec_enc *enc, generic_encoder *model, int x, int max,
for xs=0. */
special = xs == 0;
if (shift - special > 0) {
od_ec_enc_bits(enc, x - (xs << shift) + (!special << (shift - 1)),
#if CONFIG_DAALA_EC
od_ec_enc_bits(&w->ec, x - (xs << shift) + (!special << (shift - 1)),
shift - special);
#else
# error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
}
}
generic_model_update(model, ex_q16, x, xs, id, integration);
......
......@@ -683,22 +683,14 @@ void pvq_encode_partition(aom_writer *w,
if (qg > 0) {
int tmp;
tmp = *exg;
#if CONFIG_DAALA_EC
generic_encode(&w->ec, &model[!noref], qg - 1, -1, &tmp, 2);
#else
# error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
generic_encode(w, &model[!noref], qg - 1, -1, &tmp, 2);
OD_IIR_DIADIC(*exg, qg << 16, 2);
}
if (theta > 1 && (nodesync || max_theta > 3)) {
int tmp;
tmp = *ext;
#if CONFIG_DAALA_EC
generic_encode(&w->ec, &model[2], theta - 2, nodesync ? -1 : max_theta - 3,
generic_encode(w, &model[2], theta - 2, nodesync ? -1 : max_theta - 3,
&tmp, 2);
#else
# error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
OD_IIR_DIADIC(*ext, theta << 16, 2);
}
#if CONFIG_DAALA_EC
......@@ -914,9 +906,9 @@ int od_pvq_encode(daala_enc_ctx *enc,
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
od_encode_checkpoint(enc, &dc_buf);
#if CONFIG_DAALA_EC
generic_encode(&enc->w.ec, &enc->state.adapt.model_dc[pli],
generic_encode(&enc->w, &enc->state.adapt.model_dc[pli],
n - 1, -1, &enc->state.adapt.ex_dc[pli][bs][0], 2);
#if CONFIG_DAALA_EC
tell2 = od_ec_enc_tell_frac(&enc->w.ec) - tell2;
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
......@@ -1041,9 +1033,9 @@ int od_pvq_encode(daala_enc_ctx *enc,
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
od_encode_checkpoint(enc, &dc_buf);
#if CONFIG_DAALA_EC
generic_encode(&enc->w.ec, &enc->state.adapt.model_dc[pli],
generic_encode(&enc->w, &enc->state.adapt.model_dc[pli],
n - 1, -1, &enc->state.adapt.ex_dc[pli][bs][0], 2);
#if CONFIG_DAALA_EC
tell2 = od_ec_enc_tell_frac(&enc->w.ec) - tell2;
#else
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
......
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