rtc: Refactor source_sad_nonrd with a new level kVeryLowSad
It also fixes the nightly_compile build failure.
BUG=aomedia:3311
Change-Id: I56a240d0070967b3877caef0331e6143d76f7639
diff --git a/av1/encoder/av1_temporal_denoiser.c b/av1/encoder/av1_temporal_denoiser.c
index 27a12cb..deb22ed 100644
--- a/av1/encoder/av1_temporal_denoiser.c
+++ b/av1/encoder/av1_temporal_denoiser.c
@@ -671,7 +671,8 @@
int64_t av1_scale_part_thresh(int64_t threshold, AV1_DENOISER_LEVEL noise_level,
CONTENT_STATE_SB content_state,
int temporal_layer_id) {
- if ((content_state.source_sad_nonrd == kLowSad &&
+ if (((content_state.source_sad_nonrd == kVeryLowSad ||
+ content_state.source_sad_nonrd == kLowSad) &&
content_state.low_sumdiff) ||
(content_state.source_sad_nonrd == kHighSad &&
content_state.low_sumdiff) ||
diff --git a/av1/encoder/block.h b/av1/encoder/block.h
index 9fb37e4..76b1883 100644
--- a/av1/encoder/block.h
+++ b/av1/encoder/block.h
@@ -801,15 +801,15 @@
/*!\cond */
typedef enum {
kZeroSad = 0,
- kLowSad = 1,
- kMedSad = 2,
- kHighSad = 3
+ kVeryLowSad = 1,
+ kLowSad = 2,
+ kMedSad = 3,
+ kHighSad = 4
} SOURCE_SAD;
typedef struct {
//! SAD levels in non-rd path
- //! 0: var-based part and inter-mode search, 1: blk-level mv pel precision
- SOURCE_SAD source_sad_nonrd[2];
+ SOURCE_SAD source_sad_nonrd;
//! SAD levels in rd-path for var-based part qindex thresholds
SOURCE_SAD source_sad_rd;
int lighting_change;
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 64cca4e..e918e15 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -800,8 +800,7 @@
if (!cpi->sf.rt_sf.check_scene_detection || cpi->rc.frame_source_sad > 0) {
calc_src_content = true;
} else {
- x->content_state_sb.source_sad_nonrd[0] = kZeroSad;
- x->content_state_sb.source_sad_nonrd[1] = kZeroSad;
+ x->content_state_sb.source_sad_nonrd = kZeroSad;
}
} else if ((cpi->sf.rt_sf.var_part_based_on_qidx >= 1) &&
(cm->width * cm->height <= 352 * 288)) {
@@ -893,8 +892,7 @@
x->color_sensitivity_sb_g[1] = 0;
x->color_sensitivity[0] = 0;
x->color_sensitivity[1] = 0;
- x->content_state_sb.source_sad_nonrd[0] = kMedSad;
- x->content_state_sb.source_sad_nonrd[1] = kMedSad;
+ x->content_state_sb.source_sad_nonrd = kMedSad;
x->content_state_sb.source_sad_rd = kMedSad;
x->content_state_sb.lighting_change = 0;
x->content_state_sb.low_sumdiff = 0;
diff --git a/av1/encoder/encodeframe_utils.c b/av1/encoder/encodeframe_utils.c
index a2eddd4..e3a606c 100644
--- a/av1/encoder/encodeframe_utils.c
+++ b/av1/encoder/encodeframe_utils.c
@@ -1321,9 +1321,9 @@
uint8_t *last_src_y = cpi->last_source->y_buffer;
int last_src_ystride = cpi->last_source->y_stride;
const int offset = cpi->source->y_stride * (mi_row << 2) + (mi_col << 2);
- uint64_t avg_source_sse_threshold_low[3] = { 100000, // ~5*5*(64*64)
- 36000, // ~3*3*(64*64)
- 10000 }; // ~1.5*1.5*(64*64)
+ uint64_t avg_source_sse_threshold_verylow = 10000; // ~1.5*1.5*(64*64)
+ uint64_t avg_source_sse_threshold_low[2] = { 100000, // ~5*5*(64*64)
+ 36000 }; // ~3*3*(64*64)
uint64_t avg_source_sse_threshold_high = 1000000; // ~15*15*(64*64)
uint64_t sum_sq_thresh = 10000; // sum = sqrt(thresh / 64*64)) ~1.5
@@ -1341,16 +1341,13 @@
// nonrd thresholds
if (tmp_sse == 0)
- x->content_state_sb.source_sad_nonrd[0] = kZeroSad;
+ x->content_state_sb.source_sad_nonrd = kZeroSad;
+ else if (tmp_sse < avg_source_sse_threshold_verylow)
+ x->content_state_sb.source_sad_nonrd = kVeryLowSad;
else if (tmp_sse < avg_source_sse_threshold_low[0])
- x->content_state_sb.source_sad_nonrd[0] = kLowSad;
+ x->content_state_sb.source_sad_nonrd = kLowSad;
else if (tmp_sse > avg_source_sse_threshold_high)
- x->content_state_sb.source_sad_nonrd[0] = kHighSad;
-
- if (tmp_sse == 0)
- x->content_state_sb.source_sad_nonrd[1] = kZeroSad;
- else if (tmp_sse < avg_source_sse_threshold_low[2])
- x->content_state_sb.source_sad_nonrd[1] = kLowSad;
+ x->content_state_sb.source_sad_nonrd = kHighSad;
// Detect large lighting change.
// Note: tmp_sse - tmp_variance = ((sum * sum) >> 12)
diff --git a/av1/encoder/nonrd_pickmode.c b/av1/encoder/nonrd_pickmode.c
index 1553186..5c3f1c4 100644
--- a/av1/encoder/nonrd_pickmode.c
+++ b/av1/encoder/nonrd_pickmode.c
@@ -224,7 +224,7 @@
// large areas
const int qband = x->qindex >> (QINDEX_BITS - 2);
assert(qband < 4);
- if (x->content_state_sb.source_sad_nonrd[1] <= kLowSad &&
+ if (x->content_state_sb.source_sad_nonrd <= kVeryLowSad &&
bsize > BLOCK_16X16 && qband != 0) {
if (x->source_variance < 500)
return FULL_PEL;
@@ -1312,8 +1312,7 @@
int left_mv_valid = 0;
int above_row = INVALID_MV_ROW_COL, above_col = INVALID_MV_ROW_COL;
int left_row = INVALID_MV_ROW_COL, left_col = INVALID_MV_ROW_COL;
- if (bsize >= BLOCK_64X64 &&
- content_state_sb.source_sad_nonrd[0] != kHighSad &&
+ if (bsize >= BLOCK_64X64 && content_state_sb.source_sad_nonrd != kHighSad &&
spatial_variance < 300 &&
(mv_row > 16 || mv_row < -16 || mv_col > 16 || mv_col < -16)) {
this_rdc->rdcost = this_rdc->rdcost << 2;
@@ -2096,7 +2095,7 @@
// capture case where only part of frame has high motion.
// Exclude screen content mode.
if (cpi->oxcf.tune_cfg.content != AOM_CONTENT_SCREEN &&
- x->content_state_sb.source_sad_nonrd[0] >= kHighSad &&
+ x->content_state_sb.source_sad_nonrd >= kHighSad &&
bsize <= BLOCK_32X32 && cpi->rc.frame_source_sad < 50000)
use_golden_ref_frame = 1;
}
@@ -2109,7 +2108,7 @@
// Skip golden reference if color is set, on flat blocks with motion.
if (x->source_variance < 500 &&
- x->content_state_sb.source_sad_nonrd[0] > kLowSad &&
+ x->content_state_sb.source_sad_nonrd > kLowSad &&
(x->color_sensitivity_sb_g[0] == 1 || x->color_sensitivity_sb_g[1] == 1))
use_golden_ref_frame = 0;
@@ -2225,18 +2224,19 @@
do_early_exit_rdthresh = 0;
}
if ((x->source_variance < AOMMAX(50, (spatial_var_thresh >> 1)) &&
- x->content_state_sb.source_sad_nonrd[0] >= kHighSad) ||
+ x->content_state_sb.source_sad_nonrd >= kHighSad) ||
(cpi->oxcf.tune_cfg.content == AOM_CONTENT_SCREEN &&
x->source_variance == 0 &&
((bsize >= BLOCK_32X32 &&
- x->content_state_sb.source_sad_nonrd[0] != kZeroSad) ||
+ x->content_state_sb.source_sad_nonrd != kZeroSad) ||
x->color_sensitivity[0] == 1 || x->color_sensitivity[1] == 1)))
force_intra_check = 1;
// For big blocks worth checking intra (since only DC will be checked),
// even if best_early_term is set.
if (bsize >= BLOCK_32X32) best_early_term = 0;
} else if (cpi->sf.rt_sf.source_metrics_sb_nonrd &&
- x->content_state_sb.source_sad_nonrd[0] == kLowSad) {
+ (x->content_state_sb.source_sad_nonrd == kVeryLowSad ||
+ x->content_state_sb.source_sad_nonrd == kLowSad)) {
perform_intra_pred = 0;
}
@@ -2294,7 +2294,7 @@
cpi->sf.rt_sf.source_metrics_sb_nonrd) {
// For spatially flat blocks with zero motion only check
// DC mode.
- if (x->content_state_sb.source_sad_nonrd[0] == kZeroSad &&
+ if (x->content_state_sb.source_sad_nonrd == kZeroSad &&
x->source_variance == 0 && this_mode != DC_PRED)
continue;
// Only test Intra for big blocks if spatial_variance is 0.
@@ -2361,7 +2361,7 @@
// Otherwise bias against intra for blocks with zero
// motion and no color, on non-scene/slide changes.
else if (!cpi->rc.high_source_sad && x->source_variance > 0 &&
- x->content_state_sb.source_sad_nonrd[0] == kZeroSad &&
+ x->content_state_sb.source_sad_nonrd == kZeroSad &&
x->color_sensitivity[0] == 0 && x->color_sensitivity[1] == 0)
this_rdc.rdcost = (3 * this_rdc.rdcost) >> 1;
}
@@ -2442,8 +2442,8 @@
return 1;
}
- if (content_state_sb.source_sad_nonrd[0] != kHighSad &&
- bsize >= BLOCK_64X64 && force_skip_low_temp_var && mode == NEWMV) {
+ if (content_state_sb.source_sad_nonrd != kHighSad && bsize >= BLOCK_64X64 &&
+ force_skip_low_temp_var && mode == NEWMV) {
return 1;
}
return 0;
@@ -2981,7 +2981,7 @@
use_modeled_non_rd_cost =
(quant_params->base_qindex > 120 && x->source_variance > 100 &&
bsize <= BLOCK_16X16 && !x->content_state_sb.lighting_change &&
- x->content_state_sb.source_sad_nonrd[0] != kHighSad);
+ x->content_state_sb.source_sad_nonrd != kHighSad);
}
#if COLLECT_PICK_MODE_STAT
@@ -3095,9 +3095,9 @@
// below after search_new_mv.
if (cpi->sf.rt_sf.source_metrics_sb_nonrd) {
if ((frame_mv[this_mode][ref_frame].as_int != 0 &&
- x->content_state_sb.source_sad_nonrd[0] == kZeroSad) ||
+ x->content_state_sb.source_sad_nonrd == kZeroSad) ||
(frame_mv[this_mode][ref_frame].as_int == 0 &&
- x->content_state_sb.source_sad_nonrd[0] != kZeroSad &&
+ x->content_state_sb.source_sad_nonrd != kZeroSad &&
((x->color_sensitivity[0] == 0 && x->color_sensitivity[1] == 0) ||
cpi->rc.high_source_sad) &&
x->source_variance == 0))
@@ -3191,7 +3191,7 @@
cpi->oxcf.tune_cfg.content == AOM_CONTENT_SCREEN &&
cpi->sf.rt_sf.source_metrics_sb_nonrd) {
if (frame_mv[this_mode][ref_frame].as_int == 0 &&
- x->content_state_sb.source_sad_nonrd[0] != kZeroSad &&
+ x->content_state_sb.source_sad_nonrd != kZeroSad &&
((x->color_sensitivity[0] == 0 && x->color_sensitivity[1] == 0) ||
cpi->rc.high_source_sad) &&
x->source_variance == 0)
diff --git a/av1/encoder/var_based_part.c b/av1/encoder/var_based_part.c
index f429190..69b061a 100644
--- a/av1/encoder/var_based_part.c
+++ b/av1/encoder/var_based_part.c
@@ -457,6 +457,8 @@
int64_t threshold_base = (int64_t)(threshold_multiplier * ac_q);
const int current_qindex = cm->quant_params.base_qindex;
const int threshold_left_shift = cpi->sf.rt_sf.var_part_split_threshold_shift;
+ const int low_blksad =
+ (source_sad_nonrd == kVeryLowSad || source_sad_nonrd == kLowSad);
if (is_key_frame) {
if (cpi->sf.rt_sf.force_large_partition_blocks_intra) {
@@ -588,7 +590,7 @@
thresholds[3] = INT32_MAX;
if (segment_id == 0) {
thresholds[1] <<= 2;
- thresholds[2] <<= (source_sad_nonrd == kLowSad) ? 5 : 4;
+ thresholds[2] <<= low_blksad ? 5 : 4;
} else {
thresholds[1] <<= 1;
thresholds[2] <<= 3;
@@ -619,11 +621,10 @@
thresholds[3] = INT32_MAX;
}
} else if (cpi->sf.rt_sf.prefer_large_partition_blocks >= 2) {
- thresholds[1] <<= (source_sad_nonrd == kLowSad) ? 2 : 0;
- thresholds[2] =
- (source_sad_nonrd == kLowSad) ? (3 * thresholds[2]) : thresholds[2];
+ thresholds[1] <<= low_blksad ? 2 : 0;
+ thresholds[2] = low_blksad ? (3 * thresholds[2]) : thresholds[2];
} else if (cpi->sf.rt_sf.prefer_large_partition_blocks >= 1) {
- const int fac = source_sad_nonrd == kLowSad ? 2 : 1;
+ const int fac = low_blksad ? 2 : 1;
tune_thresh_based_on_qindex_window(current_qindex, QINDEX_LARGE_BLOCK_THR,
45, fac, thresholds);
}
@@ -1128,7 +1129,7 @@
// For non-SVC GOLDEN is another temporal reference. Check if it should be
// used as reference for partitioning.
if (!cpi->ppi->use_svc && (cpi->ref_frame_flags & AOM_GOLD_FLAG) &&
- x->content_state_sb.source_sad_nonrd[0] != kZeroSad) {
+ x->content_state_sb.source_sad_nonrd != kZeroSad) {
yv12_g = get_ref_frame_yv12_buf(cm, GOLDEN_FRAME);
if (yv12_g && yv12_g != yv12) {
av1_setup_pre_planes(xd, 0, yv12_g, mi_row, mi_col,
@@ -1273,12 +1274,12 @@
const int q =
av1_get_qindex(&cm->seg, segment_id, cm->quant_params.base_qindex);
set_vbp_thresholds(cpi, thresholds, q, x->content_state_sb.low_sumdiff,
- x->content_state_sb.source_sad_nonrd[0],
+ x->content_state_sb.source_sad_nonrd,
x->content_state_sb.source_sad_rd, 1);
} else {
set_vbp_thresholds(cpi, thresholds, cm->quant_params.base_qindex,
x->content_state_sb.low_sumdiff,
- x->content_state_sb.source_sad_nonrd[0],
+ x->content_state_sb.source_sad_nonrd,
x->content_state_sb.source_sad_rd, 0);
}
@@ -1346,7 +1347,7 @@
cpi->oxcf.q_cfg.aq_mode == CYCLIC_REFRESH_AQ &&
cpi->cyclic_refresh->apply_cyclic_refresh &&
segment_id == CR_SEGMENT_ID_BASE &&
- x->content_state_sb.source_sad_nonrd[0] == kZeroSad &&
+ x->content_state_sb.source_sad_nonrd == kZeroSad &&
ref_frame_partition == LAST_FRAME && xd->mi[0]->mv[0].as_int == 0 &&
y_sad < thresh_exit_part && uv_sad[0]<(3 * thresh_exit_part)>> 2 &&
uv_sad[1]<(3 * thresh_exit_part)>> 2) {
@@ -1427,7 +1428,7 @@
(thresholds[2] >> 1) &&
maxvar_16x16[m][i] > thresholds[2]) ||
(cpi->sf.rt_sf.prefer_large_partition_blocks &&
- x->content_state_sb.source_sad_nonrd[0] > kLowSad &&
+ x->content_state_sb.source_sad_nonrd > kLowSad &&
cpi->rc.frame_source_sad < 20000 &&
maxvar_16x16[m][i] > (thresholds[2] >> 4) &&
maxvar_16x16[m][i] > (minvar_16x16[m][i] << 2)))) {