Skip to content

Commit 40561f5

Browse files
committed
vp9/encoder: remove SOURCE_VAR_BASED_PARTITION
This partition search type has been unused since: 0ce51d8 experimental : partition using 1/8 x 1/8 image This also removes the related `search_type_check_frequency` and `frames_till_next_var_check` which are set, but unused. This fixes a clang-tidy warning: bugprone-sizeof-expression. If the code is restored and needs to be fixed, the change required is `sizeof(cpi->source_diff_var)` -> `sizeof(*cpi->source_diff_var)`. Bug: 437631372 Change-Id: I7a185fefcabfae9fe399770bcfb9f0f98fb69b99
1 parent fdf1db6 commit 40561f5

File tree

7 files changed

+2
-285
lines changed

7 files changed

+2
-285
lines changed

vp9/encoder/vp9_block.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@
1919
extern "C" {
2020
#endif
2121

22-
typedef struct {
23-
unsigned int sse;
24-
int sum;
25-
unsigned int var;
26-
} Diff;
27-
2822
struct macroblock_plane {
2923
DECLARE_ALIGNED(16, int16_t, src_diff[64 * 64]);
3024
tran_low_t *qcoeff;

vp9/encoder/vp9_encodeframe.c

Lines changed: 0 additions & 244 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,120 +2386,6 @@ static void set_fixed_partitioning(VP9_COMP *cpi, const TileInfo *const tile,
23862386
}
23872387
}
23882388

2389-
static const struct {
2390-
int row;
2391-
int col;
2392-
} coord_lookup[16] = {
2393-
// 32x32 index = 0
2394-
{ 0, 0 },
2395-
{ 0, 2 },
2396-
{ 2, 0 },
2397-
{ 2, 2 },
2398-
// 32x32 index = 1
2399-
{ 0, 4 },
2400-
{ 0, 6 },
2401-
{ 2, 4 },
2402-
{ 2, 6 },
2403-
// 32x32 index = 2
2404-
{ 4, 0 },
2405-
{ 4, 2 },
2406-
{ 6, 0 },
2407-
{ 6, 2 },
2408-
// 32x32 index = 3
2409-
{ 4, 4 },
2410-
{ 4, 6 },
2411-
{ 6, 4 },
2412-
{ 6, 6 },
2413-
};
2414-
2415-
static void set_source_var_based_partition(VP9_COMP *cpi,
2416-
const TileInfo *const tile,
2417-
MACROBLOCK *const x,
2418-
MODE_INFO **mi_8x8, int mi_row,
2419-
int mi_col) {
2420-
VP9_COMMON *const cm = &cpi->common;
2421-
const int mis = cm->mi_stride;
2422-
const int row8x8_remaining = tile->mi_row_end - mi_row;
2423-
const int col8x8_remaining = tile->mi_col_end - mi_col;
2424-
MODE_INFO *mi_upper_left = cm->mi + mi_row * mis + mi_col;
2425-
2426-
vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col);
2427-
2428-
assert((row8x8_remaining > 0) && (col8x8_remaining > 0));
2429-
2430-
// In-image SB64
2431-
if ((col8x8_remaining >= MI_BLOCK_SIZE) &&
2432-
(row8x8_remaining >= MI_BLOCK_SIZE)) {
2433-
int i, j;
2434-
int index;
2435-
Diff d32[4];
2436-
const int offset = (mi_row >> 1) * cm->mb_cols + (mi_col >> 1);
2437-
int is_larger_better = 0;
2438-
int use32x32 = 0;
2439-
unsigned int thr = cpi->source_var_thresh;
2440-
2441-
memset(d32, 0, sizeof(d32));
2442-
2443-
for (i = 0; i < 4; i++) {
2444-
Diff *d16[4];
2445-
2446-
for (j = 0; j < 4; j++) {
2447-
int b_mi_row = coord_lookup[i * 4 + j].row;
2448-
int b_mi_col = coord_lookup[i * 4 + j].col;
2449-
int boffset = b_mi_row / 2 * cm->mb_cols + b_mi_col / 2;
2450-
2451-
d16[j] = cpi->source_diff_var + offset + boffset;
2452-
2453-
index = b_mi_row * mis + b_mi_col;
2454-
mi_8x8[index] = mi_upper_left + index;
2455-
mi_8x8[index]->sb_type = BLOCK_16X16;
2456-
2457-
// TODO(yunqingwang): If d16[j].var is very large, use 8x8 partition
2458-
// size to further improve quality.
2459-
}
2460-
2461-
is_larger_better = (d16[0]->var < thr) && (d16[1]->var < thr) &&
2462-
(d16[2]->var < thr) && (d16[3]->var < thr);
2463-
2464-
// Use 32x32 partition
2465-
if (is_larger_better) {
2466-
use32x32 += 1;
2467-
2468-
for (j = 0; j < 4; j++) {
2469-
d32[i].sse += d16[j]->sse;
2470-
d32[i].sum += d16[j]->sum;
2471-
}
2472-
2473-
d32[i].var =
2474-
(unsigned int)(d32[i].sse -
2475-
(unsigned int)(((int64_t)d32[i].sum * d32[i].sum) >>
2476-
10));
2477-
2478-
index = coord_lookup[i * 4].row * mis + coord_lookup[i * 4].col;
2479-
mi_8x8[index] = mi_upper_left + index;
2480-
mi_8x8[index]->sb_type = BLOCK_32X32;
2481-
}
2482-
}
2483-
2484-
if (use32x32 == 4) {
2485-
thr <<= 1;
2486-
is_larger_better = (d32[0].var < thr) && (d32[1].var < thr) &&
2487-
(d32[2].var < thr) && (d32[3].var < thr);
2488-
2489-
// Use 64x64 partition
2490-
if (is_larger_better) {
2491-
mi_8x8[0] = mi_upper_left;
2492-
mi_8x8[0]->sb_type = BLOCK_64X64;
2493-
}
2494-
}
2495-
} else { // partial in-image SB64
2496-
int bh = num_8x8_blocks_high_lookup[BLOCK_16X16];
2497-
int bw = num_8x8_blocks_wide_lookup[BLOCK_16X16];
2498-
set_partial_b64x64_partition(mi_upper_left, mis, bh, bw, row8x8_remaining,
2499-
col8x8_remaining, BLOCK_16X16, mi_8x8);
2500-
}
2501-
}
2502-
25032389
static void update_state_rt(VP9_COMP *cpi, ThreadData *td,
25042390
PICK_MODE_CONTEXT *ctx, int mi_row, int mi_col,
25052391
int bsize) {
@@ -5420,11 +5306,6 @@ static void encode_nonrd_sb_row(VP9_COMP *cpi, ThreadData *td,
54205306
BLOCK_64X64, &dummy_rdc, 1, INT64_MAX,
54215307
td->pc_root);
54225308
break;
5423-
case SOURCE_VAR_BASED_PARTITION:
5424-
set_source_var_based_partition(cpi, tile_info, x, mi, mi_row, mi_col);
5425-
nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col,
5426-
BLOCK_64X64, 1, &dummy_rdc, td->pc_root);
5427-
break;
54285309
case FIXED_PARTITION:
54295310
if (!seg_skip) bsize = sf->always_this_block_size;
54305311
set_fixed_partitioning(cpi, tile_info, mi, mi_row, mi_col, bsize);
@@ -5483,128 +5364,6 @@ static void encode_nonrd_sb_row(VP9_COMP *cpi, ThreadData *td,
54835364
}
54845365
// end RTC play code
54855366

5486-
static INLINE uint32_t variance(const Diff *const d) {
5487-
return d->sse - (uint32_t)(((int64_t)d->sum * d->sum) >> 8);
5488-
}
5489-
5490-
#if CONFIG_VP9_HIGHBITDEPTH
5491-
static INLINE uint32_t variance_highbd(Diff *const d) {
5492-
const int64_t var = (int64_t)d->sse - (((int64_t)d->sum * d->sum) >> 8);
5493-
return (var >= 0) ? (uint32_t)var : 0;
5494-
}
5495-
#endif // CONFIG_VP9_HIGHBITDEPTH
5496-
5497-
static int set_var_thresh_from_histogram(VP9_COMP *cpi) {
5498-
const SPEED_FEATURES *const sf = &cpi->sf;
5499-
const VP9_COMMON *const cm = &cpi->common;
5500-
5501-
const uint8_t *src = cpi->Source->y_buffer;
5502-
const uint8_t *last_src = cpi->Last_Source->y_buffer;
5503-
const int src_stride = cpi->Source->y_stride;
5504-
const int last_stride = cpi->Last_Source->y_stride;
5505-
5506-
// Pick cutoff threshold
5507-
const int cutoff = (VPXMIN(cm->width, cm->height) >= 720)
5508-
? (cm->MBs * VAR_HIST_LARGE_CUT_OFF / 100)
5509-
: (cm->MBs * VAR_HIST_SMALL_CUT_OFF / 100);
5510-
DECLARE_ALIGNED(16, int, hist[VAR_HIST_BINS]);
5511-
Diff *var16 = cpi->source_diff_var;
5512-
5513-
int sum = 0;
5514-
int i, j;
5515-
5516-
memset(hist, 0, VAR_HIST_BINS * sizeof(hist[0]));
5517-
5518-
for (i = 0; i < cm->mb_rows; i++) {
5519-
for (j = 0; j < cm->mb_cols; j++) {
5520-
#if CONFIG_VP9_HIGHBITDEPTH
5521-
if (cm->use_highbitdepth) {
5522-
switch (cm->bit_depth) {
5523-
case VPX_BITS_8:
5524-
vpx_highbd_8_get16x16var(src, src_stride, last_src, last_stride,
5525-
&var16->sse, &var16->sum);
5526-
var16->var = variance(var16);
5527-
break;
5528-
case VPX_BITS_10:
5529-
vpx_highbd_10_get16x16var(src, src_stride, last_src, last_stride,
5530-
&var16->sse, &var16->sum);
5531-
var16->var = variance_highbd(var16);
5532-
break;
5533-
default:
5534-
assert(cm->bit_depth == VPX_BITS_12);
5535-
vpx_highbd_12_get16x16var(src, src_stride, last_src, last_stride,
5536-
&var16->sse, &var16->sum);
5537-
var16->var = variance_highbd(var16);
5538-
break;
5539-
}
5540-
} else {
5541-
vpx_get16x16var(src, src_stride, last_src, last_stride, &var16->sse,
5542-
&var16->sum);
5543-
var16->var = variance(var16);
5544-
}
5545-
#else
5546-
vpx_get16x16var(src, src_stride, last_src, last_stride, &var16->sse,
5547-
&var16->sum);
5548-
var16->var = variance(var16);
5549-
#endif // CONFIG_VP9_HIGHBITDEPTH
5550-
5551-
if (var16->var >= VAR_HIST_MAX_BG_VAR)
5552-
hist[VAR_HIST_BINS - 1]++;
5553-
else
5554-
hist[var16->var / VAR_HIST_FACTOR]++;
5555-
5556-
src += 16;
5557-
last_src += 16;
5558-
var16++;
5559-
}
5560-
5561-
src = src - cm->mb_cols * 16 + 16 * src_stride;
5562-
last_src = last_src - cm->mb_cols * 16 + 16 * last_stride;
5563-
}
5564-
5565-
cpi->source_var_thresh = 0;
5566-
5567-
if (hist[VAR_HIST_BINS - 1] < cutoff) {
5568-
for (i = 0; i < VAR_HIST_BINS - 1; i++) {
5569-
sum += hist[i];
5570-
5571-
if (sum > cutoff) {
5572-
cpi->source_var_thresh = (i + 1) * VAR_HIST_FACTOR;
5573-
return 0;
5574-
}
5575-
}
5576-
}
5577-
5578-
return sf->search_type_check_frequency;
5579-
}
5580-
5581-
static void source_var_based_partition_search_method(VP9_COMP *cpi) {
5582-
VP9_COMMON *const cm = &cpi->common;
5583-
SPEED_FEATURES *const sf = &cpi->sf;
5584-
5585-
if (cm->frame_type == KEY_FRAME) {
5586-
// For key frame, use SEARCH_PARTITION.
5587-
sf->partition_search_type = SEARCH_PARTITION;
5588-
} else if (cm->intra_only) {
5589-
sf->partition_search_type = FIXED_PARTITION;
5590-
} else {
5591-
if (cm->last_width != cm->width || cm->last_height != cm->height) {
5592-
if (cpi->source_diff_var) vpx_free(cpi->source_diff_var);
5593-
5594-
CHECK_MEM_ERROR(&cm->error, cpi->source_diff_var,
5595-
vpx_calloc(cm->MBs, sizeof(cpi->source_diff_var)));
5596-
}
5597-
5598-
if (!cpi->frames_till_next_var_check)
5599-
cpi->frames_till_next_var_check = set_var_thresh_from_histogram(cpi);
5600-
5601-
if (cpi->frames_till_next_var_check > 0) {
5602-
sf->partition_search_type = FIXED_PARTITION;
5603-
cpi->frames_till_next_var_check--;
5604-
}
5605-
}
5606-
}
5607-
56085367
static int get_skip_encode_frame(const VP9_COMMON *cm, ThreadData *const td) {
56095368
unsigned int intra_count = 0, inter_count = 0;
56105369
int j;
@@ -5912,9 +5671,6 @@ static void encode_frame_internal(VP9_COMP *cpi) {
59125671
!(cpi->oxcf.lag_in_frames > 0 && cpi->oxcf.rc_mode == VPX_VBR) &&
59135672
!cpi->use_svc)
59145673
cpi->ref_frame_flags &= (~VP9_GOLD_FLAG);
5915-
5916-
if (sf->partition_search_type == SOURCE_VAR_BASED_PARTITION)
5917-
source_var_based_partition_search_method(cpi);
59185674
} else if (gf_group_index && gf_group_index < MAX_ARF_GOP_SIZE &&
59195675
cpi->sf.enable_tpl_model) {
59205676
TplDepFrame *tpl_frame = &cpi->tpl_stats[cpi->twopass.gf_group.index];

vp9/encoder/vp9_encodeframe.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ struct yv12_buffer_config;
2222
struct VP9_COMP;
2323
struct ThreadData;
2424

25-
// Constants used in SOURCE_VAR_BASED_PARTITION
26-
#define VAR_HIST_MAX_BG_VAR 1000
27-
#define VAR_HIST_FACTOR 10
28-
#define VAR_HIST_BINS (VAR_HIST_MAX_BG_VAR / VAR_HIST_FACTOR + 1)
29-
#define VAR_HIST_LARGE_CUT_OFF 75
30-
#define VAR_HIST_SMALL_CUT_OFF 45
31-
3225
void vp9_setup_src_planes(struct macroblock *x,
3326
const struct yv12_buffer_config *src, int mi_row,
3427
int mi_col);

vp9/encoder/vp9_encoder.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,11 +1060,6 @@ static void dealloc_compressor_data(VP9_COMP *cpi) {
10601060
lc->rc_twopass_stats_in.sz = 0;
10611061
}
10621062

1063-
if (cpi->source_diff_var != NULL) {
1064-
vpx_free(cpi->source_diff_var);
1065-
cpi->source_diff_var = NULL;
1066-
}
1067-
10681063
for (i = 0; i < MAX_LAG_BUFFERS; ++i) {
10691064
vpx_free_frame_buffer(&cpi->svc.scaled_frames[i]);
10701065
}
@@ -2652,11 +2647,6 @@ VP9_COMP *vp9_create_compressor(const VP9EncoderConfig *oxcf,
26522647
cpi->tpl_stats[i].tpl_stats_ptr = NULL;
26532648
}
26542649

2655-
// Allocate memory to store variances for a frame.
2656-
CHECK_MEM_ERROR(&cm->error, cpi->source_diff_var,
2657-
vpx_calloc(cm->MBs, sizeof(cpi->source_diff_var)));
2658-
cpi->source_var_thresh = 0;
2659-
cpi->frames_till_next_var_check = 0;
26602650
#define BFP(BT, SDF, SDSF, SDAF, VF, SVF, SVAF, SDX4DF, SDSX4DF) \
26612651
cpi->fn_ptr[BT].sdf = SDF; \
26622652
cpi->fn_ptr[BT].sdsf = SDSF; \
@@ -4084,14 +4074,12 @@ static int encode_without_recode_loop(VP9_COMP *cpi, size_t *size,
40844074
}
40854075

40864076
// Avoid scaling last_source unless its needed.
4087-
// Last source is needed if avg_source_sad() is used, or if
4088-
// partition_search_type == SOURCE_VAR_BASED_PARTITION, or if noise
4089-
// estimation is enabled.
4077+
// Last source is needed if avg_source_sad() is used, or if noise estimation
4078+
// is enabled.
40904079
if (cpi->unscaled_last_source != NULL &&
40914080
(cpi->oxcf.content == VP9E_CONTENT_SCREEN ||
40924081
(cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == VPX_VBR &&
40934082
cpi->oxcf.mode == REALTIME && cpi->oxcf.speed >= 5) ||
4094-
cpi->sf.partition_search_type == SOURCE_VAR_BASED_PARTITION ||
40954083
(cpi->noise_estimate.enabled && !cpi->oxcf.noise_sensitivity) ||
40964084
cpi->compute_source_sad_onepass))
40974085
cpi->Last_Source = vp9_scale_if_required(

vp9/encoder/vp9_encoder.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -802,12 +802,6 @@ typedef struct VP9_COMP {
802802

803803
SVC svc;
804804

805-
// Store frame variance info in SOURCE_VAR_BASED_PARTITION search type.
806-
Diff *source_diff_var;
807-
// The threshold used in SOURCE_VAR_BASED_PARTITION search type.
808-
unsigned int source_var_thresh;
809-
int frames_till_next_var_check;
810-
811805
int frame_flags;
812806

813807
search_site_config ss_cfg;

vp9/encoder/vp9_speed_features.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,6 @@ void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi, int speed) {
10011001
// This setting only takes effect when partition_search_type is set
10021002
// to FIXED_PARTITION.
10031003
sf->always_this_block_size = BLOCK_16X16;
1004-
sf->search_type_check_frequency = 50;
10051004
sf->encode_breakout_thresh = 0;
10061005
// Recode loop tolerance %.
10071006
sf->recode_tolerance_low = 12;

vp9/encoder/vp9_speed_features.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,6 @@ typedef enum {
148148
// a 64X64 SB.
149149
VAR_BASED_PARTITION,
150150

151-
// Use non-fixed partitions based on source variance.
152-
SOURCE_VAR_BASED_PARTITION,
153-
154151
// Make partition decisions with machine learning models.
155152
ML_BASED_PARTITION
156153
} PARTITION_SEARCH_TYPE;
@@ -517,10 +514,6 @@ typedef struct SPEED_FEATURES {
517514
// TODO(aconverse): Fold this into one of the other many mode skips
518515
BLOCK_SIZE max_intra_bsize;
519516

520-
// The frequency that we check if SOURCE_VAR_BASED_PARTITION or
521-
// FIXED_PARTITION search type should be used.
522-
int search_type_check_frequency;
523-
524517
// When partition is pre-set, the inter prediction result from pick_inter_mode
525518
// can be reused in final block encoding process. It is enabled only for real-
526519
// time mode speed 6.

0 commit comments

Comments
 (0)