Skip to content

Commit

Permalink
Add research presets -2 and -3
Browse files Browse the repository at this point in the history
- Preset -2 (MRP) matches preset MR found in SVT-AV1 v1.8.0
- Preset -3 (MRS) matches preset MRS found in older SVT-AV1 versions
  • Loading branch information
juliobbv authored and gianni-rosato committed Mar 13, 2024
1 parent b7900a3 commit a8d88f3
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 26 deletions.
2 changes: 2 additions & 0 deletions Source/API/EbSvtAv1Enc.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ extern "C" {
#endif
#endif /* ATTRIBUTE_PACKED */
typedef enum ATTRIBUTE_PACKED {
ENC_MRS = -3, // Highest quality research mode (slowest)
ENC_MRP = -2, // Previous research mode with quality/speed tradeoffs found in v1.8.0
ENC_MR = -1, //Research mode with higher quality than M0
ENC_M0 = 0,
ENC_M1 = 1,
Expand Down
4 changes: 2 additions & 2 deletions Source/App/EncApp/EbAppConfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -2114,8 +2114,8 @@ uint32_t get_passes(int32_t argc, char *const argv[], EncPass enc_pass[MAX_ENC_P
}
if (find_token(argc, argv, PRESET_TOKEN, config_string) == 0) {
enc_mode = strtol(config_string, NULL, 0);
if (enc_mode > MAX_ENC_PRESET || enc_mode < -1) {
fprintf(stderr, "Error: EncoderMode must be in the range of [-1-%d]\n", MAX_ENC_PRESET);
if (enc_mode > MAX_ENC_PRESET || enc_mode < -3) {
fprintf(stderr, "Error: EncoderMode must be in the range of [-3-%d]\n", MAX_ENC_PRESET);
return 0;
}
}
Expand Down
5 changes: 5 additions & 0 deletions Source/Lib/Encoder/Codec/EbProductCodingLoop.c
Original file line number Diff line number Diff line change
Expand Up @@ -10263,6 +10263,11 @@ static void update_nsq_settings(SequenceControlSet *scs, PictureControlSet *pcs,
// Reset the NSQ setting if previous-SQ is_high_energy
svt_aom_set_nsq_search_ctrls(ctx, pcs->nsq_search_level, pcs->ppcs->input_resolution);

// Do not adjust NSQ settings for ENC_MRP and ENC_MRS
if (pcs->ppcs->enc_mode <= ENC_MRP) {
return;
}

// Derive area energy
uint32_t energy = ctx->blk_geom->sq_size < 64
? ctx->b32_satd[(ctx->blk_geom->org_x / 32) + ((ctx->blk_geom->org_y / 32) << 1)]
Expand Down
94 changes: 73 additions & 21 deletions Source/Lib/Encoder/Codec/EncModeConfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ uint8_t svt_aom_get_enable_me_16x16(EncMode enc_mode) {
uint8_t svt_aom_get_gm_core_level(EncMode enc_mode, bool super_res_off) {
uint8_t gm_level = 0;
if (super_res_off) {
if (enc_mode <= ENC_M0)
if (enc_mode <= ENC_MRP)
gm_level = 1;
else if (enc_mode <= ENC_M0)
gm_level = 2;
else if (enc_mode <= ENC_M2)
gm_level = 4;
Expand Down Expand Up @@ -92,7 +94,15 @@ static void set_hme_search_params(PictureParentControlSet *pcs, MeContext *me_ct
// Whether to modulate HME (w,h) using qp
uint8_t q_mult = 0;
// Set HME level 0 min and max search areas
if (pcs->enc_mode <= ENC_M0) {
if (pcs->enc_mode <= ENC_MRS) {
if (input_resolution < INPUT_SIZE_4K_RANGE) {
me_ctx->hme_l0_sa.sa_min = (SearchArea){128, 128};
me_ctx->hme_l0_sa.sa_max = (SearchArea){256, 256};
} else {
me_ctx->hme_l0_sa.sa_min = (SearchArea){240, 240};
me_ctx->hme_l0_sa.sa_max = (SearchArea){480, 480};
}
} else if (pcs->enc_mode <= ENC_M0) {
if (input_resolution < INPUT_SIZE_4K_RANGE) {
me_ctx->hme_l0_sa.sa_min = (SearchArea){32, 32};
me_ctx->hme_l0_sa.sa_max = (SearchArea){192, 192};
Expand Down Expand Up @@ -661,14 +671,18 @@ void svt_aom_sig_deriv_me(SequenceControlSet *scs, PictureParentControlSet *pcs,
uint8_t me_ref_prune_level = 0;

if (sc_class1) {
if (enc_mode <= ENC_M2)
if (enc_mode <= ENC_MRS)
me_ref_prune_level = 0;
else if (enc_mode <= ENC_M2)
me_ref_prune_level = 1;
else if (enc_mode <= ENC_M9)
me_ref_prune_level = 3;
else
me_ref_prune_level = 6;
} else {
if (enc_mode <= ENC_MR) {
if (enc_mode <= ENC_MRS) {
me_ref_prune_level = 0;
} else if (enc_mode <= ENC_MR) {
me_ref_prune_level = 1;
} else if (enc_mode <= ENC_M0) {
if (pcs->temporal_layer_index == 0)
Expand Down Expand Up @@ -702,6 +716,8 @@ void svt_aom_sig_deriv_me(SequenceControlSet *scs, PictureParentControlSet *pcs,
svt_aom_set_me_sr_adjustment_ctrls(me_ctx, 4);
else
svt_aom_set_me_sr_adjustment_ctrls(me_ctx, 5);
else if (enc_mode <= ENC_MRS)
svt_aom_set_me_sr_adjustment_ctrls(me_ctx, 0);
else if (enc_mode <= ENC_M0)
svt_aom_set_me_sr_adjustment_ctrls(me_ctx, 1);
else
Expand Down Expand Up @@ -1719,7 +1735,9 @@ static void set_palette_level(PictureParentControlSet *pcs, uint8_t palette_leve
uint16_t svt_aom_get_max_can_count(EncMode enc_mode) {
//NOTE: this is a memory feature and not a speed feature. it should not be have any speed/quality impact.
uint16_t mem_max_can_count;
if (enc_mode <= ENC_M1)
if (enc_mode <= ENC_MRS)
mem_max_can_count = 2500;
else if (enc_mode <= ENC_M1)
mem_max_can_count = 1225;
else if (enc_mode <= ENC_M2)
mem_max_can_count = 1000;
Expand Down Expand Up @@ -4458,8 +4476,11 @@ void svt_aom_set_wm_controls(ModeDecisionContext *ctx, uint8_t wm_level) {
uint8_t svt_aom_get_nic_level(EncMode enc_mode, uint8_t is_base, uint8_t hierarchical_levels, uint32_t qp,
bool rtc_tune) {
uint8_t nic_level;

if (enc_mode <= ENC_MR)
if (enc_mode <= ENC_MRS)
nic_level = 0;
else if (enc_mode <= ENC_MRP)
nic_level = 1;
else if (enc_mode <= ENC_MR)
nic_level = is_base ? 2 : 5;
else if (enc_mode <= ENC_M2) {
if (hierarchical_levels <= 3)
Expand Down Expand Up @@ -6869,7 +6890,9 @@ void svt_aom_sig_deriv_enc_dec_common(SequenceControlSet *scs, PictureControlSet
// Level 1: [-2, +2] depth refinement
// Level 2: [-1, +1] depth refinement
uint8_t depth_level = 0;
if (pcs->ppcs->sc_class1) {
if (enc_mode <= ENC_MRS)
depth_level = 1;
else if (pcs->ppcs->sc_class1) {
if (enc_mode <= ENC_M5)
depth_level = pcs->slice_type == I_SLICE ? 2 : 3;
else if (enc_mode <= ENC_M6)
Expand Down Expand Up @@ -7594,7 +7617,9 @@ void svt_aom_sig_deriv_enc_dec(SequenceControlSet *scs, PictureControlSet *pcs,
intra_level = (is_islice || ppcs->transition_present == 1) ? 1 : 6;
else
intra_level = (is_islice || ppcs->transition_present == 1) ? 4 : 6;
} else if (enc_mode <= ENC_M1)
} else if (enc_mode <= ENC_MRS)
intra_level = 1;
else if (enc_mode <= ENC_M1)
intra_level = is_base ? 1 : 2;
else if (enc_mode <= ENC_M2)
intra_level = is_base ? 1 : 3;
Expand Down Expand Up @@ -7651,7 +7676,9 @@ bool svt_aom_get_disallow_4x4(EncMode enc_mode, uint8_t is_base) {
}
uint8_t svt_aom_get_nsq_geom_level(EncMode enc_mode, uint8_t is_base, InputCoeffLvl coeff_lvl) {
uint8_t nsq_geom_level;
if (enc_mode <= ENC_M0) {
if (enc_mode <= ENC_MRP) {
nsq_geom_level = 1;
} else if (enc_mode <= ENC_M0) {
if (coeff_lvl == HIGH_LVL)
nsq_geom_level = 2;
else // regular or low
Expand Down Expand Up @@ -7687,7 +7714,11 @@ uint8_t svt_aom_get_nsq_geom_level(EncMode enc_mode, uint8_t is_base, InputCoeff
uint8_t svt_aom_get_nsq_search_level(EncMode enc_mode, uint8_t is_base, InputCoeffLvl coeff_lvl, uint32_t qp) {
uint8_t nsq_search_level;

if (enc_mode <= ENC_MR) {
if (enc_mode <= ENC_MRS) {
nsq_search_level = 1;
} else if (enc_mode <= ENC_MRP) {
nsq_search_level = 2;
} else if (enc_mode <= ENC_MR) {
if (coeff_lvl == HIGH_LVL)
nsq_search_level = is_base ? 3 : 5;
else // regular or low
Expand Down Expand Up @@ -7837,7 +7868,9 @@ uint8_t svt_aom_get_update_cdf_level(EncMode enc_mode, SliceType is_islice, uint

uint8_t svt_aom_get_chroma_level(EncMode enc_mode) {
uint8_t chroma_level = 0;
if (enc_mode <= ENC_MR)
if (enc_mode <= ENC_MRS)
chroma_level = 1;
else if (enc_mode <= ENC_MR)
chroma_level = 2;
else if (enc_mode <= ENC_M10)
chroma_level = 4;
Expand Down Expand Up @@ -7975,7 +8008,9 @@ static void set_pic_lpd0_lvl(PictureControlSet *pcs, EncMode enc_mode) {
}
uint8_t get_inter_compound_level(EncMode enc_mode) {
uint8_t comp_level;
if (enc_mode <= ENC_M0)
if (enc_mode <= ENC_MRS)
comp_level = 1;
else if (enc_mode <= ENC_M0)
comp_level = 3;
else if (enc_mode <= ENC_M2)
comp_level = 4;
Expand All @@ -7999,7 +8034,9 @@ uint8_t get_filter_intra_level(EncMode enc_mode) {

uint8_t svt_aom_get_inter_intra_level(EncMode enc_mode, uint8_t is_base, uint8_t transition_present) {
uint8_t inter_intra_level = 0;
if (enc_mode <= ENC_MR)
if (enc_mode <= ENC_MRS)
inter_intra_level = 1;
else if (enc_mode <= ENC_MR)
inter_intra_level = 2;
else if (enc_mode <= ENC_M3)
inter_intra_level = (transition_present || is_base) ? 2 : 0;
Expand Down Expand Up @@ -8296,7 +8333,9 @@ void svt_aom_sig_deriv_mode_decision_config(SequenceControlSet *scs, PictureCont
}
}
} else {
if (enc_mode <= ENC_M1)
if (enc_mode <= ENC_MRS)
pcs->txt_level = 1;
else if (enc_mode <= ENC_M1)
pcs->txt_level = 2;
else if (enc_mode <= ENC_M3) {
if (pcs->coeff_lvl == LOW_LVL) {
Expand Down Expand Up @@ -8362,7 +8401,9 @@ void svt_aom_sig_deriv_mode_decision_config(SequenceControlSet *scs, PictureCont
}
// Set the level the interpolation search
pcs->interpolation_search_level = 0;
if (enc_mode <= ENC_M8)
if (enc_mode <= ENC_MRS)
pcs->interpolation_search_level = 1;
else if (enc_mode <= ENC_M8)
pcs->interpolation_search_level = 4;
else {
pcs->interpolation_search_level = 4;
Expand Down Expand Up @@ -8407,19 +8448,26 @@ void svt_aom_sig_deriv_mode_decision_config(SequenceControlSet *scs, PictureCont
pcs->cfl_level = 0;
// Set the level for new/nearest/near injection
if (scs->new_nearest_comb_inject == DEFAULT)
pcs->new_nearest_near_comb_injection = 0;
if (enc_mode <= ENC_MRS)
pcs->new_nearest_near_comb_injection = 1;
else
pcs->new_nearest_near_comb_injection = 0;
else
pcs->new_nearest_near_comb_injection = scs->new_nearest_comb_inject;

// Set the level for unipred3x3 injection
if (enc_mode <= ENC_M1)
if (enc_mode <= ENC_MRS)
pcs->unipred3x3_injection = 1;
else if (enc_mode <= ENC_M1)
pcs->unipred3x3_injection = 2;
else
pcs->unipred3x3_injection = 0;

// Set the level for bipred3x3 injection
if (scs->bipred_3x3_inject == DEFAULT) {
if (enc_mode <= ENC_M2)
if (enc_mode <= ENC_MRS)
pcs->bipred3x3_injection = 1;
else if (enc_mode <= ENC_M2)
pcs->bipred3x3_injection = 2;
else if (enc_mode <= ENC_M4)
pcs->bipred3x3_injection = 4;
Expand All @@ -8434,7 +8482,9 @@ void svt_aom_sig_deriv_mode_decision_config(SequenceControlSet *scs, PictureCont

// Set the level for the distance-based red pruning
if (pcs->ppcs->ref_list0_count_try > 1 || pcs->ppcs->ref_list1_count_try > 1) {
if (enc_mode <= ENC_M1)
if (enc_mode <= ENC_MRS)
pcs->dist_based_ref_pruning = 1;
else if (enc_mode <= ENC_M1)
pcs->dist_based_ref_pruning = is_base ? 1 : 5;
else if (enc_mode <= ENC_M5)
pcs->dist_based_ref_pruning = is_base ? 2 : 5;
Expand Down Expand Up @@ -8471,7 +8521,9 @@ void svt_aom_sig_deriv_mode_decision_config(SequenceControlSet *scs, PictureCont
} else
pcs->inter_intra_level = 0;

if (enc_mode <= ENC_M2)
if (enc_mode <= ENC_MRS)
pcs->txs_level = 1;
else if (enc_mode <= ENC_M2)
pcs->txs_level = 2;
else if (enc_mode <= ENC_M7) {
if (is_islice)
Expand Down
5 changes: 4 additions & 1 deletion Source/Lib/Encoder/Globals/EbEncHandle.c
Original file line number Diff line number Diff line change
Expand Up @@ -4167,7 +4167,10 @@ static void set_param_based_on_input(SequenceControlSet *scs)
}
}
else {
if (scs->static_config.enc_mode <= ENC_M2) {
if (scs->static_config.enc_mode <= ENC_MRS) {
mrp_level = 1;
}
else if (scs->static_config.enc_mode <= ENC_M2) {
mrp_level = 2;
}
else if (scs->static_config.enc_mode <= ENC_M4) {
Expand Down
4 changes: 2 additions & 2 deletions Source/Lib/Encoder/Globals/EbEncSettings.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ EbErrorType svt_av1_verify_settings(SequenceControlSet *scs) {
EbErrorType return_error = EB_ErrorNone;
EbSvtAv1EncConfiguration *config = &scs->static_config;
unsigned int channel_number = config->channel_id;
if (config->enc_mode > MAX_ENC_PRESET || config->enc_mode < -1) {
SVT_ERROR("Instance %u: EncoderMode must be in the range of [-1-%d]\n", channel_number + 1, MAX_ENC_PRESET);
if (config->enc_mode > MAX_ENC_PRESET || config->enc_mode < -3) {
SVT_ERROR("Instance %u: EncoderMode must be in the range of [-3-%d]\n", channel_number + 1, MAX_ENC_PRESET);
return_error = EB_ErrorBadParameter;
}
if (config->enc_mode == MAX_ENC_PRESET) {
Expand Down

0 comments on commit a8d88f3

Please sign in to comment.