Add PVQ frame context in common and tiles.
In preparation for enabling backward updates of contexts for PVQ. 1. Default prob setting for PVQ, which is based on flat probabilities at the moment. 2. At the end of encoding a frame, average probablities and expected values of PVQ are copied to the frame context. Change-Id: I1d087b98e6b0d55ebf8aef696dd986f88197cedf
This commit is contained in:
Родитель
1238137c3c
Коммит
b188ea1402
|
@ -5790,4 +5790,68 @@ void av1_average_tile_inter_cdfs(AV1_COMMON *cm, FRAME_CONTEXT *fc,
|
|||
AVERAGE_TILE_CDFS(switchable_interp_cdf)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_PVQ
|
||||
// Averaging PVQ's expected values for symbol coding
|
||||
static void av1_average_pvq_ex(int *cxt_ptr[], int *fc_cxt_ptr, int cxt_size,
|
||||
const int num_tiles) {
|
||||
int i, j;
|
||||
for (i = 0; i < cxt_size; ++i) {
|
||||
int sum = 0;
|
||||
for (j = 0; j < num_tiles; ++j) sum += cxt_ptr[j][i];
|
||||
fc_cxt_ptr[i] = sum / num_tiles;
|
||||
}
|
||||
}
|
||||
|
||||
#define AVERAGE_TILE_PVQ_EX(cname) \
|
||||
for (i = 0; i < num_tiles; ++i) cxt_ptr[i] = (int *)&ec_ctxs[i]->cname; \
|
||||
fc_cxt_ptr = (int *)&fc->cname; \
|
||||
cxt_size = (int)sizeof(fc->cname) / sizeof(int); \
|
||||
av1_average_pvq_ex(cxt_ptr, fc_cxt_ptr, cxt_size, num_tiles);
|
||||
|
||||
void av1_default_pvq_probs(AV1_COMMON *cm) {
|
||||
od_adapt_ctx *adapt = &cm->fc->pvq_context;
|
||||
|
||||
// Init with flat probabilities.
|
||||
od_adapt_ctx_reset(adapt, 0);
|
||||
|
||||
// TODO(yushin): Prepare offline cdf and context table for PVQ,
|
||||
// i.e. od_adapt_ctx, then load them from table,
|
||||
// for example od_adapt_ctx default_pvq_context.
|
||||
// Then do sth like this:
|
||||
// av1_copy(cm->fc->pvq_context, default_pvq_context);
|
||||
}
|
||||
|
||||
void av1_average_tile_pvq_cdfs(FRAME_CONTEXT *fc, FRAME_CONTEXT *ec_ctxs[],
|
||||
const int num_tiles) {
|
||||
int i, j, cdf_size, cxt_size;
|
||||
|
||||
aom_cdf_prob *cdf_ptr[MAX_TILE_ROWS * MAX_TILE_COLS];
|
||||
aom_cdf_prob *fc_cdf_ptr;
|
||||
int *cxt_ptr[MAX_TILE_ROWS * MAX_TILE_COLS];
|
||||
int *fc_cxt_ptr;
|
||||
|
||||
AVERAGE_TILE_PVQ_EX(pvq_context.ex_dc)
|
||||
AVERAGE_TILE_PVQ_EX(pvq_context.ex_g)
|
||||
|
||||
for (j = 0; j < OD_NPLANES_MAX; j++) {
|
||||
AVERAGE_TILE_CDFS(pvq_context.model_dc[j].cdf)
|
||||
}
|
||||
|
||||
AVERAGE_TILE_CDFS(pvq_context.skip_cdf)
|
||||
|
||||
AVERAGE_TILE_PVQ_EX(pvq_context.pvq.pvq_codeword_ctx.pvq_adapt)
|
||||
AVERAGE_TILE_CDFS(pvq_context.pvq.pvq_codeword_ctx.pvq_k1_cdf)
|
||||
AVERAGE_TILE_CDFS(pvq_context.pvq.pvq_codeword_ctx.pvq_split_cdf)
|
||||
|
||||
for (j = 0; j < 3; j++) {
|
||||
AVERAGE_TILE_CDFS(pvq_context.pvq.pvq_param_model[j].cdf)
|
||||
}
|
||||
|
||||
AVERAGE_TILE_PVQ_EX(pvq_context.pvq.pvq_ext)
|
||||
AVERAGE_TILE_PVQ_EX(pvq_context.pvq.pvq_exg)
|
||||
AVERAGE_TILE_CDFS(pvq_context.pvq.pvq_gaintheta_cdf)
|
||||
AVERAGE_TILE_CDFS(pvq_context.pvq.pvq_skip_dir_cdf)
|
||||
}
|
||||
#endif // CONFIG_PVQ
|
||||
#endif // CONFIG_EC_ADAPT
|
||||
|
|
|
@ -415,7 +415,13 @@ void av1_average_tile_inter_cdfs(struct AV1Common *cm,
|
|||
struct frame_contexts *fc,
|
||||
struct frame_contexts *ec_ctxs[],
|
||||
aom_cdf_prob *cdf_ptrs[], const int num_tiles);
|
||||
#endif
|
||||
#if CONFIG_PVQ
|
||||
void av1_default_pvq_probs(struct AV1Common *cm);
|
||||
void av1_average_tile_pvq_cdfs(struct frame_contexts *fc,
|
||||
struct frame_contexts *ec_ctxs[],
|
||||
const int num_tiles);
|
||||
#endif // CONFIG_PVQ
|
||||
#endif // CONFIG_EC_ADAPT
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
|
|
@ -3261,6 +3261,9 @@ void av1_setup_past_independence(AV1_COMMON *cm) {
|
|||
av1_default_coef_probs(cm);
|
||||
init_mode_probs(cm->fc);
|
||||
av1_init_mv_probs(cm);
|
||||
#if CONFIG_PVQ
|
||||
av1_default_pvq_probs(cm);
|
||||
#endif // CONFIG_PVQ
|
||||
#if CONFIG_ADAPT_SCAN
|
||||
av1_init_scan_order(cm);
|
||||
#endif
|
||||
|
|
|
@ -18,6 +18,12 @@
|
|||
#include "av1/common/seg_common.h"
|
||||
#include "aom_dsp/aom_filter.h"
|
||||
|
||||
#if CONFIG_PVQ
|
||||
#include "av1/common/pvq.h"
|
||||
#include "av1/common/pvq_state.h"
|
||||
#include "av1/common/generic_code.h"
|
||||
#endif // CONFIG_PVQ
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -277,6 +283,11 @@ typedef struct frame_contexts {
|
|||
#if CONFIG_DELTA_Q
|
||||
aom_prob delta_q_prob[DELTA_Q_PROBS];
|
||||
#endif
|
||||
#if CONFIG_PVQ
|
||||
// TODO(any): If PVQ is enabled, most of coefficient related cdf,
|
||||
// such as coef_cdfs[], coef_tail_cdfs[], and coef_heaf_cdfs[] can be removed.
|
||||
od_adapt_ctx pvq_context;
|
||||
#endif // CONFIG_PVQ
|
||||
} FRAME_CONTEXT;
|
||||
|
||||
typedef struct FRAME_COUNTS {
|
||||
|
|
|
@ -4970,7 +4970,11 @@ void av1_decode_frame(AV1Decoder *pbi, const uint8_t *data,
|
|||
cm->tile_rows * cm->tile_cols);
|
||||
av1_average_tile_intra_cdfs(pbi->common.fc, tile_ctxs, cdf_ptrs,
|
||||
cm->tile_rows * cm->tile_cols);
|
||||
#endif
|
||||
#if CONFIG_PVQ
|
||||
av1_average_tile_pvq_cdfs(pbi->common.fc, tile_ctxs,
|
||||
cm->tile_rows * cm->tile_cols);
|
||||
#endif // CONFIG_PVQ
|
||||
#endif // CONFIG_EC_ADAPT
|
||||
#if CONFIG_ADAPT_SCAN
|
||||
av1_adapt_scan_order(cm);
|
||||
#endif // CONFIG_ADAPT_SCAN
|
||||
|
|
|
@ -4964,7 +4964,11 @@ static void encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size,
|
|||
cm->tile_rows * cm->tile_cols);
|
||||
av1_average_tile_intra_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs,
|
||||
cm->tile_rows * cm->tile_cols);
|
||||
#endif
|
||||
#if CONFIG_PVQ
|
||||
av1_average_tile_pvq_cdfs(cpi->common.fc, tile_ctxs,
|
||||
cm->tile_rows * cm->tile_cols);
|
||||
#endif // CONFIG_PVQ
|
||||
#endif // CONFIG_EC_ADAPT
|
||||
#if CONFIG_ADAPT_SCAN
|
||||
av1_adapt_scan_order(cm);
|
||||
#endif // CONFIG_ADAPT_SCAN
|
||||
|
|
Загрузка…
Ссылка в новой задаче