Change PVQ's skip symbols to use dyadic and ec_adapt adaptation

Change-Id: I4f7d37af84220971a839f4f8f42aafa1adeb04e4
This commit is contained in:
Yushin Cho 2017-02-21 10:38:16 -08:00
Родитель 4d5182ced2
Коммит 0077927b15
7 изменённых файлов: 33 добавлений и 15 удалений

Просмотреть файл

@ -27,6 +27,16 @@ void aom_cdf_init(uint16_t *cdf, int ncdfs, int nsyms, int val, int first) {
}
}
void aom_cdf_init_q15_1D(uint16_t *cdf, int nsyms, int cdf_size) {
int i;
for (i = 0; i < nsyms; i++)
cdf[i] = (i + 1)*32768/nsyms;
#if CONFIG_EC_ADAPT
cdf[cdf_size - 1] = 0;
#endif
}
/** Adapts a Q15 cdf after encoding/decoding a symbol. */
void aom_cdf_adapt_q15(int val, uint16_t *cdf, int n, int *count, int rate) {
int i;

Просмотреть файл

@ -49,8 +49,21 @@ void generic_model_init(generic_encoder *model);
#define OD_SINGLE_CDF_INIT_FIRST(cdf, val, first) aom_cdf_init(cdf, \
1, sizeof(cdf)/sizeof(cdf[0]), val, first)
// WARNING: DO NOT USE this init function,
// if the size of cdf is different from what is declared by code.
#define OD_CDFS_INIT_Q15(cdfs) \
{ int n_cdfs = sizeof(cdfs)/sizeof(cdfs[0]); \
int cdf_size = sizeof(cdfs[0])/sizeof(cdfs[0][0]); \
int nsyms = cdf_size - CONFIG_EC_ADAPT; \
int i_; \
for (i_ = 0; i_ < n_cdfs; i_++) \
aom_cdf_init_q15_1D(cdfs[i_], nsyms, cdf_size); \
}
void aom_cdf_init(uint16_t *cdf, int ncdfs, int nsyms, int val, int first);
void aom_cdf_init_q15_1D(uint16_t *cdf, int nsyms, int cdf_size);
void aom_cdf_adapt_q15(int val, uint16_t *cdf, int n, int *count, int rate);
void aom_encode_cdf_adapt_q15(aom_writer *w, int val, uint16_t *cdf, int n,

Просмотреть файл

@ -13,12 +13,11 @@
#include "av1/common/odintrin.h"
void od_adapt_ctx_reset(od_adapt_ctx *adapt, int is_keyframe) {
int i;
int pli;
od_adapt_pvq_ctx_reset(&adapt->pvq, is_keyframe);
adapt->skip_increment = 128;
OD_CDFS_INIT(adapt->skip_cdf, adapt->skip_increment >> 2);
OD_CDFS_INIT_Q15(adapt->skip_cdf);
for (pli = 0; pli < OD_NPLANES_MAX; pli++) {
int i;
generic_model_init(&adapt->model_dc[pli]);
for (i = 0; i < OD_TXSIZES; i++) {
int j;

Просмотреть файл

@ -34,8 +34,7 @@ struct od_adapt_ctx {
int ex_g[OD_NPLANES_MAX][OD_TXSIZES];
/* Joint skip flag for DC and AC */
uint16_t skip_cdf[OD_TXSIZES*2][4];
int skip_increment;
uint16_t skip_cdf[OD_TXSIZES*2][CDF_SIZE(4)];
};
struct od_state {

Просмотреть файл

@ -425,10 +425,10 @@ static PVQ_SKIP_TYPE read_pvq_skip(AV1_COMMON *cm, MACROBLOCKD *const xd,
// NOTE : we don't use 5 symbols for luma here in aom codebase,
// since block partition is taken care of by aom.
// So, only AC/DC skip info is coded
const int ac_dc_coded = aom_decode_cdf_adapt(
const int ac_dc_coded = aom_read_symbol(
xd->daala_dec.r,
xd->daala_dec.state.adapt.skip_cdf[2 * tx_size + (plane != 0)], 4,
xd->daala_dec.state.adapt.skip_increment, "skip");
"skip");
if (ac_dc_coded < 0 || ac_dc_coded > 3) {
aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM,
"Invalid PVQ Skip Type");

Просмотреть файл

@ -1057,9 +1057,8 @@ static void pack_pvq_tokens(aom_writer *w, MACROBLOCK *const x,
pvq = get_pvq_block(x->pvq_q);
// encode block skip info
aom_encode_cdf_adapt(w, pvq->ac_dc_coded,
adapt->skip_cdf[2 * tx_size + (plane != 0)], 4,
adapt->skip_increment);
aom_write_symbol(w, pvq->ac_dc_coded,
adapt->skip_cdf[2 * tx_size + (plane != 0)], 4);
// AC coeffs coded?
if (pvq->ac_dc_coded & AC_CODED) {
@ -1070,7 +1069,7 @@ static void pack_pvq_tokens(aom_writer *w, MACROBLOCK *const x,
pvq_encode_partition(
w, pvq->qg[i], pvq->theta[i], pvq->max_theta[i],
pvq->y + pvq->off[i], pvq->size[i], pvq->k[i], model, adapt,
exg + i, ext + i, nodesync,
exg + i, ext + i, nodesync || is_keyframe,
(plane != 0) * OD_TXSIZES * PVQ_MAX_PARTITIONS +
pvq->bs * PVQ_MAX_PARTITIONS + i,
is_keyframe, i == 0 && (i < pvq->nb_bands - 1), pvq->skip_rest,

Просмотреть файл

@ -884,8 +884,7 @@ PVQ_SKIP_TYPE od_pvq_encode(daala_enc_ctx *enc,
#error "CONFIG_PVQ currently requires CONFIG_DAALA_EC."
#endif
/* Code as if we're not skipping. */
aom_encode_cdf_adapt(&enc->w, 2 + (out[0] != 0), skip_cdf,
4, enc->state.adapt.skip_increment);
aom_write_symbol(&enc->w, 2 + (out[0] != 0), skip_cdf, 4);
ac_dc_coded = AC_CODED + (out[0] != 0);
cfl_encoded = 0;
skip_rest = 1;
@ -988,8 +987,7 @@ PVQ_SKIP_TYPE od_pvq_encode(daala_enc_ctx *enc,
}
/* We decide to skip, roll back everything as it was before. */
od_encode_rollback(enc, &buf);
aom_encode_cdf_adapt(&enc->w, out[0] != 0, skip_cdf,
4, enc->state.adapt.skip_increment);
aom_write_symbol(&enc->w, out[0] != 0, skip_cdf, 4);
ac_dc_coded = (out[0] != 0);
if (is_keyframe) for (i = 1; i < 1 << (2*bs + 4); i++) out[i] = 0;
else for (i = 1; i < 1 << (2*bs + 4); i++) out[i] = ref[i];