Commit 6160df29 authored by Fangwen Fu's avatar Fangwen Fu

Extend delta q with segments

This is the first patch for ext_delta_q experiment.
* Allow delta q to work with segment features

Change-Id: I9455ebb3b5b23b41daa4afa1149672a20d3a3f2c
parent 697597b4
......@@ -503,6 +503,18 @@ enum aome_enc_control_id {
*/
AV1E_SET_TILE_LOOPFILTER,
/*!\brief Codec control function to set the delta q mode
*
* AV1 has a segment based feature that allows encoder to adaptively change
* quantization parameter for each segment within a frame to improve the
* subjective quality. the delta q mode is added on top of segment based
* feature, and allows control per 64x64 q and lf delta.This control makes
* encoder operate in one of the several DELTA_Q_modes supported.
*
* By default, encoder operates with DELTAQ_Mode 0(deltaq signaling off).
*/
AV1E_SET_DELTAQ_MODE,
/*!\brief Codec control function to set the tile encoding mode to 0 or 1.
*
* 0 means that the tile encoding mode is TILE_NORMAL, and 1 means that the
......@@ -670,6 +682,9 @@ AOM_CTRL_USE_TYPE(AV1E_SET_FRAME_PARALLEL_DECODING, unsigned int)
AOM_CTRL_USE_TYPE(AV1E_SET_AQ_MODE, unsigned int)
#define AOM_CTRL_AV1E_SET_AQ_MODE
AOM_CTRL_USE_TYPE(AV1E_SET_DELTAQ_MODE, unsigned int)
#define AOM_CTRL_AV1E_SET_DELTAQ_MODE
AOM_CTRL_USE_TYPE(AV1E_SET_FRAME_PERIODIC_BOOST, unsigned int)
#define AOM_CTRL_AV1E_SET_FRAME_PERIODIC_BOOST
......
......@@ -412,7 +412,7 @@ static const arg_def_t frame_parallel_decoding =
ARG_DEF(NULL, "frame-parallel", 1,
"Enable frame parallel decodability features "
"(0: false (default), 1: true)");
#if CONFIG_DELTA_Q
#if CONFIG_DELTA_Q && !CONFIG_EXT_DELTA_Q
static const arg_def_t aq_mode = ARG_DEF(
NULL, "aq-mode", 1,
"Adaptive quantization mode (0: off (default), 1: variance 2: complexity, "
......@@ -423,6 +423,11 @@ static const arg_def_t aq_mode = ARG_DEF(
"Adaptive quantization mode (0: off (default), 1: variance 2: complexity, "
"3: cyclic refresh)");
#endif
#if CONFIG_EXT_DELTA_Q
static const arg_def_t deltaq_mode = ARG_DEF(
NULL, "deltaq-mode", 1,
"Delta qindex mode (0: off (default), 1: deltaq 2: deltaq + deltalf)");
#endif
static const arg_def_t frame_periodic_boost =
ARG_DEF(NULL, "frame-boost", 1,
"Enable frame periodic boost (0: off (default), 1: on)");
......@@ -505,6 +510,9 @@ static const arg_def_t *av1_args[] = { &cpu_used_av1,
#endif
&frame_parallel_decoding,
&aq_mode,
#if CONFIG_EXT_DELTA_Q
&deltaq_mode,
#endif
&frame_periodic_boost,
&noise_sens,
&tune_content,
......@@ -556,6 +564,9 @@ static const int av1_arg_ctrl_map[] = { AOME_SET_CPUUSED,
#endif
AV1E_SET_FRAME_PARALLEL_DECODING,
AV1E_SET_AQ_MODE,
#if CONFIG_EXT_DELTA_Q
AV1E_SET_DELTAQ_MODE,
#endif
AV1E_SET_FRAME_PERIODIC_BOOST,
AV1E_SET_NOISE_SENSITIVITY,
AV1E_SET_TUNE_CONTENT,
......
......@@ -64,6 +64,9 @@ struct av1_extracfg {
#endif
unsigned int frame_parallel_decoding_mode;
AQ_MODE aq_mode;
#if CONFIG_EXT_DELTA_Q
DELTAQ_MODE deltaq_mode;
#endif
unsigned int frame_periodic_boost;
aom_bit_depth_t bit_depth;
aom_tune_content content;
......@@ -124,8 +127,11 @@ static struct av1_extracfg default_extra_cfg = {
#if CONFIG_TEMPMV_SIGNALING
0, // disable temporal mv prediction
#endif
1, // frame_parallel_decoding_mode
NO_AQ, // aq_mode
1, // frame_parallel_decoding_mode
NO_AQ, // aq_mode
#if CONFIG_EXT_DELTA_Q
NO_DELTA_Q, // deltaq_mode
#endif
CONFIG_XIPHRC, // frame_periodic_delta_q
AOM_BITS_8, // Bit depth
AOM_CONTENT_DEFAULT, // content
......@@ -214,6 +220,9 @@ static aom_codec_err_t validate_config(aom_codec_alg_priv_t *ctx,
RANGE_CHECK_HI(cfg, rc_min_quantizer, cfg->rc_max_quantizer);
RANGE_CHECK_BOOL(extra_cfg, lossless);
RANGE_CHECK(extra_cfg, aq_mode, 0, AQ_MODE_COUNT - 1);
#if CONFIG_EXT_DELTA_Q
RANGE_CHECK(extra_cfg, deltaq_mode, 0, DELTAQ_MODE_COUNT - 1);
#endif
RANGE_CHECK_HI(extra_cfg, frame_periodic_boost, 1);
RANGE_CHECK_HI(cfg, g_threads, 64);
RANGE_CHECK_HI(cfg, g_lag_in_frames, MAX_LAG_BUFFERS);
......@@ -544,6 +553,9 @@ static aom_codec_err_t set_encoder_config(
oxcf->frame_parallel_decoding_mode = extra_cfg->frame_parallel_decoding_mode;
oxcf->aq_mode = extra_cfg->aq_mode;
#if CONFIG_EXT_DELTA_Q
oxcf->deltaq_mode = extra_cfg->deltaq_mode;
#endif
oxcf->frame_periodic_boost = extra_cfg->frame_periodic_boost;
......@@ -846,6 +858,14 @@ static aom_codec_err_t ctrl_set_aq_mode(aom_codec_alg_priv_t *ctx,
return update_extra_cfg(ctx, &extra_cfg);
}
#if CONFIG_EXT_DELTA_Q
static aom_codec_err_t ctrl_set_deltaq_mode(aom_codec_alg_priv_t *ctx,
va_list args) {
struct av1_extracfg extra_cfg = ctx->extra_cfg;
extra_cfg.deltaq_mode = CAST(AV1E_SET_DELTAQ_MODE, args);
return update_extra_cfg(ctx, &extra_cfg);
}
#endif
static aom_codec_err_t ctrl_set_min_gf_interval(aom_codec_alg_priv_t *ctx,
va_list args) {
struct av1_extracfg extra_cfg = ctx->extra_cfg;
......@@ -1454,6 +1474,9 @@ static aom_codec_ctrl_fn_map_t encoder_ctrl_maps[] = {
#endif
{ AV1E_SET_FRAME_PARALLEL_DECODING, ctrl_set_frame_parallel_decoding_mode },
{ AV1E_SET_AQ_MODE, ctrl_set_aq_mode },
#if CONFIG_EXT_DELTA_Q
{ AV1E_SET_DELTAQ_MODE, ctrl_set_deltaq_mode },
#endif
{ AV1E_SET_FRAME_PERIODIC_BOOST, ctrl_set_frame_periodic_boost },
{ AV1E_SET_TUNE_CONTENT, ctrl_set_tune_content },
{ AV1E_SET_COLOR_SPACE, ctrl_set_color_space },
......
......@@ -1546,6 +1546,25 @@ static void decode_token_and_recon_block(AV1Decoder *const pbi,
if (cm->delta_q_present_flag) {
int i;
for (i = 0; i < MAX_SEGMENTS; i++) {
#if CONFIG_EXT_DELTA_Q
xd->plane[0].seg_dequant[i][0] =
av1_dc_quant(av1_get_qindex(&cm->seg, i, xd->current_qindex),
cm->y_dc_delta_q, cm->bit_depth);
xd->plane[0].seg_dequant[i][1] = av1_ac_quant(
av1_get_qindex(&cm->seg, i, xd->current_qindex), 0, cm->bit_depth);
xd->plane[1].seg_dequant[i][0] =
av1_dc_quant(av1_get_qindex(&cm->seg, i, xd->current_qindex),
cm->uv_dc_delta_q, cm->bit_depth);
xd->plane[1].seg_dequant[i][1] =
av1_ac_quant(av1_get_qindex(&cm->seg, i, xd->current_qindex),
cm->uv_ac_delta_q, cm->bit_depth);
xd->plane[2].seg_dequant[i][0] =
av1_dc_quant(av1_get_qindex(&cm->seg, i, xd->current_qindex),
cm->uv_dc_delta_q, cm->bit_depth);
xd->plane[2].seg_dequant[i][1] =
av1_ac_quant(av1_get_qindex(&cm->seg, i, xd->current_qindex),
cm->uv_ac_delta_q, cm->bit_depth);
#else
xd->plane[0].seg_dequant[i][0] =
av1_dc_quant(xd->current_qindex, cm->y_dc_delta_q, cm->bit_depth);
xd->plane[0].seg_dequant[i][1] =
......@@ -1558,6 +1577,7 @@ static void decode_token_and_recon_block(AV1Decoder *const pbi,
av1_dc_quant(xd->current_qindex, cm->uv_dc_delta_q, cm->bit_depth);
xd->plane[2].seg_dequant[i][1] =
av1_ac_quant(xd->current_qindex, cm->uv_ac_delta_q, cm->bit_depth);
#endif
}
}
#endif
......@@ -4574,8 +4594,10 @@ static int read_compressed_header(AV1Decoder *pbi, const uint8_t *data,
av1_diff_update_prob(&r, &fc->skip_probs[k], ACCT_STR);
#if CONFIG_DELTA_Q && !CONFIG_EC_ADAPT
for (k = 0; k < DELTA_Q_PROBS; ++k)
av1_diff_update_prob(&r, &fc->delta_q_prob[k], ACCT_STR);
if (cm->delta_q_present_flag) {
for (k = 0; k < DELTA_Q_PROBS; ++k)
av1_diff_update_prob(&r, &fc->delta_q_prob[k], ACCT_STR);
}
#endif
#if !CONFIG_EC_ADAPT
......
......@@ -1801,10 +1801,17 @@ void av1_init_plane_quantizers(const AV1_COMP *cpi, MACROBLOCK *x,
const QUANTS *const quants = &cpi->quants;
#if CONFIG_DELTA_Q
#if CONFIG_EXT_DELTA_Q
int current_q_index = AOMMAX(
0, AOMMIN(QINDEX_RANGE - 1, cpi->oxcf.deltaq_mode != NO_DELTA_Q
? cm->base_qindex + xd->delta_qindex
: cm->base_qindex));
#else
int current_q_index = AOMMAX(
0, AOMMIN(QINDEX_RANGE - 1, cm->delta_q_present_flag
? cm->base_qindex + xd->delta_qindex
: cm->base_qindex));
#endif
const int qindex = av1_get_qindex(&cm->seg, segment_id, current_q_index);
#else
const int qindex = av1_get_qindex(&cm->seg, segment_id, cm->base_qindex);
......
......@@ -626,6 +626,9 @@ static void update_delta_q_probs(AV1_COMMON *cm, aom_writer *w,
#else
const int probwt = 1;
#endif
#if CONFIG_EXT_DELTA_Q
if (!cm->delta_q_present_flag) return;
#endif // CONFIG_EXT_DELTA_Q
for (k = 0; k < DELTA_Q_PROBS; ++k) {
av1_cond_prob_diff_update(w, &cm->fc->delta_q_prob[k], counts->delta_q[k],
probwt);
......
......@@ -1195,7 +1195,7 @@ static void update_state(const AV1_COMP *const cpi, ThreadData *td,
xd->mi[x_idx + y * mis] = mi_addr;
}
#if CONFIG_DELTA_Q
#if CONFIG_DELTA_Q && !CONFIG_EXT_DELTA_Q
if (cpi->oxcf.aq_mode > NO_AQ && cpi->oxcf.aq_mode < DELTA_AQ)
av1_init_plane_quantizers(cpi, x, xd->mi[0]->mbmi.segment_id);
#else
......@@ -4698,10 +4698,12 @@ static void encode_rd_sb_row(AV1_COMP *cpi, ThreadData *td,
xd->delta_qindex = current_qindex - cm->base_qindex;
set_offsets(cpi, tile_info, x, mi_row, mi_col, BLOCK_64X64);
xd->mi[0]->mbmi.current_q_index = current_qindex;
#if !CONFIG_EXT_DELTA_Q
xd->mi[0]->mbmi.segment_id = 0;
#endif // CONFIG_EXT_DELTA_Q
av1_init_plane_quantizers(cpi, x, xd->mi[0]->mbmi.segment_id);
}
#endif
#endif // CONFIG_DELTA_Q
x->source_variance = UINT_MAX;
if (sf->partition_search_type == FIXED_PARTITION || seg_skip) {
......@@ -5294,9 +5296,13 @@ static void encode_frame_internal(AV1_COMP *cpi) {
#if CONFIG_DELTA_Q
// Fix delta q resolution for the moment
cm->delta_q_res = DEFAULT_DELTA_Q_RES;
// Set delta_q_present_flag before it is used for the first time
// Set delta_q_present_flag before it is used for the first time
#if CONFIG_EXT_DELTA_Q
cm->delta_q_present_flag &= cm->base_qindex > 0;
#else
cm->delta_q_present_flag =
cpi->oxcf.aq_mode == DELTA_AQ && cm->base_qindex > 0;
#endif // CONFIG_EXT_DELTA_Q
#endif
av1_frame_init_quantizer(cpi);
......
......@@ -557,7 +557,17 @@ int av1_optimize_b(const AV1_COMMON *cm, MACROBLOCK *mb, int plane, int block,
int shortcut = 0;
int next_shortcut = 0;
#if CONFIG_EXT_DELTA_Q
const int qindex = cm->seg.enabled
? av1_get_qindex(&cm->seg, xd->mi[0]->mbmi.segment_id,
cm->base_qindex)
: cm->base_qindex;
if (qindex == 0) {
assert((qindex == 0) ^ (xd->lossless[xd->mi[0]->mbmi.segment_id] == 0));
}
#else
assert((mb->qindex == 0) ^ (xd->lossless[xd->mi[0]->mbmi.segment_id] == 0));
#endif
token_costs += band;
......
......@@ -4897,6 +4897,10 @@ static void encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size,
}
#endif
#if CONFIG_EXT_DELTA_Q
cm->delta_q_present_flag = cpi->oxcf.deltaq_mode != NO_DELTA_Q;
#endif
if (cpi->sf.recode_loop == DISALLOW_RECODE) {
encode_without_recode_loop(cpi);
} else {
......
......@@ -118,12 +118,19 @@ typedef enum {
VARIANCE_AQ = 1,
COMPLEXITY_AQ = 2,
CYCLIC_REFRESH_AQ = 3,
#if CONFIG_DELTA_Q
#if CONFIG_DELTA_Q && !CONFIG_EXT_DELTA_Q
DELTA_AQ = 4,
#endif
AQ_MODE_COUNT // This should always be the last member of the enum
} AQ_MODE;
#if CONFIG_EXT_DELTA_Q
typedef enum {
NO_DELTA_Q = 0,
DELTA_Q_ONLY = 1,
DELTA_Q_LF = 2,
DELTAQ_MODE_COUNT // This should always be the last member of the enum
} DELTAQ_MODE;
#endif
typedef enum {
RESIZE_NONE = 0, // No frame resizing allowed.
RESIZE_FIXED = 1, // All frames are coded at the specified dimension.
......@@ -182,6 +189,9 @@ typedef struct AV1EncoderConfig {
int best_allowed_q;
int cq_level;
AQ_MODE aq_mode; // Adaptive Quantization mode
#if CONFIG_EXT_DELTA_Q
DELTAQ_MODE deltaq_mode;
#endif
#if CONFIG_AOM_QM
int using_qm;
int qm_minlevel;
......
......@@ -296,6 +296,7 @@ EXPERIMENT_LIST="
chroma_2x2
frame_size
delta_q
ext_delta_q
adapt_scan
filter_7bit
parallel_deblocking
......@@ -510,6 +511,7 @@ post_process_cmdline() {
enabled ec_multisymbol && ! enabled ans && soft_enable daala_ec
enabled ec_multisymbol && ! enabled daala_ec && soft_enable ans
enabled palette_throughput && soft_enable palette
enabled ext_delta_q && soft_enable delta_q
enabled txk_sel && soft_enable lv_map
enabled compound_round && soft_enable convolve_round
if enabled rawbits && ! enabled daala_ec; then
......
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