Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions av2/encoder/encodeframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -2038,6 +2038,22 @@ static void get_histogram(int32_t *hist, const YV12_BUFFER_CONFIG *buf,
}
}

// GOP-level BAWP pruning (sf->inter_sf.prune_bawp_by_gop_usage). Returns 1 if
// BAWP is to be turned off for the current frame: a frame at pyramid level
// >= 3 whose GOP's level-1 and level-2 frames used BAWP on average on at most
// half of their BAWP-eligible area. Intra and level-1 frames start a new GOP.
static int should_prune_bawp_by_gop_usage(AV2_COMP *const cpi) {
const AV2_COMMON *const cm = &cpi->common;
const unsigned int level = cm->current_frame.pyramid_level;
if (frame_is_intra_only(cm) || level == 1) {
cpi->bawp_gop_usage[0] = cpi->bawp_gop_usage[1] = -1;
return 0;
}
if (level < 3) return 0;
if (cpi->bawp_gop_usage[0] < 0 || cpi->bawp_gop_usage[1] < 0) return 0;
return cpi->bawp_gop_usage[0] + cpi->bawp_gop_usage[1] <= 1.0;
}

static int av2_set_on_bawp_picture_level(AV2_COMP *const cpi) {
int enable_curr_pic_bawp = 0;
assert(cpi->sf.inter_sf.enable_fast_bawp == 1);
Expand Down Expand Up @@ -2214,6 +2230,8 @@ static AVM_INLINE void encode_frame_internal(AV2_COMP *cpi) {
av2_zero(rdc->comp_pred_diff);
av2_zero(rdc->tx_type_used);
av2_zero(rdc->warped_used);
rdc->bawp_eligible_area = 0;
rdc->bawp_used_area = 0;

for (i = 0; i < CCSO_NUM_COMPONENTS; ++i) {
cm->ccso_info.ccso_frame_flag = 0;
Expand Down Expand Up @@ -2372,6 +2390,10 @@ static AVM_INLINE void encode_frame_internal(AV2_COMP *cpi) {
#endif
av2_compute_global_motion_facade(cpi);

// Called for every frame, so that the GOP state follows the coded frames.
if (cpi->sf.inter_sf.prune_bawp_by_gop_usage &&
should_prune_bawp_by_gop_usage(cpi))
features->enable_bawp = 0;
if (features->enable_bawp && cpi->sf.inter_sf.enable_fast_bawp)
features->enable_bawp = av2_set_on_bawp_picture_level(cpi);

Expand Down Expand Up @@ -2439,6 +2461,18 @@ static AVM_INLINE void encode_frame_internal(AV2_COMP *cpi) {
}
}

// BAWP usage of the GOP's level-1 and level-2 frames, for its later frames.
// A frame coded with BAWP off has no eligible area and counts as 0.
if (cpi->sf.inter_sf.prune_bawp_by_gop_usage && !frame_is_intra_only(cm)) {
const unsigned int level = cm->current_frame.pyramid_level;
if (level == 1 || level == 2) {
cpi->bawp_gop_usage[level - 1] =
rdc->bawp_eligible_area > 0
? (double)rdc->bawp_used_area / (double)rdc->bawp_eligible_area
: 0.0;
}
}

// If intrabc is allowed but never selected, reset the allow_intrabc flag.
if (features->allow_intrabc && !cpi->intrabc_used) {
features->allow_intrabc = 0;
Expand Down
3 changes: 3 additions & 0 deletions av2/encoder/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,9 @@ AV2_COMP *av2_create_compressor(AV2EncoderConfig *oxcf, BufferPool *const pool,
if (!cm) return NULL;

av2_zero(*cpi);
// Unknown until the first level-1 or level-2 frame is coded
// (sf->inter_sf.prune_bawp_by_gop_usage).
cpi->bawp_gop_usage[0] = cpi->bawp_gop_usage[1] = -1.0;

// The jmp_buf is valid only for the duration of the function that calls
// setjmp(). Therefore, this function must reset the 'setjmp' field to 0
Expand Down
11 changes: 11 additions & 0 deletions av2/encoder/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,10 @@ typedef struct RD_COUNTS {
int skip_mode_used_flag;
int tx_type_used[TX_SIZES_ALL][PRIMARY_TX_TYPES];
int warped_used[2];
// Luma area (in 4x4 units) of the final coded blocks that may use BAWP, and
// of those that use it. Used by sf->inter_sf.prune_bawp_by_gop_usage.
int64_t bawp_eligible_area;
int64_t bawp_used_area;
} RD_COUNTS;

typedef struct ThreadData {
Expand Down Expand Up @@ -2513,6 +2517,13 @@ typedef struct AV2_COMP {
*/
YV12_BUFFER_CONFIG *unfiltered_source;

/*!
* BAWP share of the BAWP-eligible area on the current GOP's level-1 and
* level-2 frames, or -1 while unknown. Used by
* sf->inter_sf.prune_bawp_by_gop_usage.
*/
double bawp_gop_usage[2];

/*!
* Parameters related to tpl.
*/
Expand Down
2 changes: 2 additions & 0 deletions av2/encoder/ethread.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ static AVM_INLINE void accumulate_rd_opt(ThreadData *td, ThreadData *td_t) {
for (int i = 0; i < 2; i++) {
td->rd_counts.warped_used[i] += td_t->rd_counts.warped_used[i];
}
td->rd_counts.bawp_eligible_area += td_t->rd_counts.bawp_eligible_area;
td->rd_counts.bawp_used_area += td_t->rd_counts.bawp_used_area;
}

void av2_row_mt_sync_read_dummy(AV2EncRowMultiThreadSync *row_mt_sync, int r,
Expand Down
9 changes: 9 additions & 0 deletions av2/encoder/partition_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,15 @@ static void encode_b(const AV2_COMP *const cpi, TileDataEnc *tile_data,
}

if (tile_data->allow_update_cdf) update_stats(&cpi->common, td);
if (cpi->sf.inter_sf.prune_bawp_by_gop_usage && !frame_is_intra_only(cm) &&
xd->tree_type != CHROMA_PART && is_inter_block(mbmi, xd->tree_type) &&
!is_intrabc_block(mbmi, xd->tree_type) && cm->features.enable_bawp &&
av2_allow_bawp(cm, mbmi, xd->mi_row, xd->mi_col)) {
const BLOCK_SIZE bs = mbmi->sb_type[PLANE_TYPE_Y];
const int64_t area = (block_size_wide[bs] * block_size_high[bs]) >> 4;
td->rd_counts.bawp_eligible_area += area;
if (mbmi->bawp_flag[0]) td->rd_counts.bawp_used_area += area;
}

// Gather warped motion count to update the probability.
if (cpi->sf.inter_sf.prune_warped_prob_thresh > 0 ||
Expand Down
2 changes: 2 additions & 0 deletions av2/encoder/speed_features.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ static void set_good_speed_features_framesize_independent(

sf->inter_sf.alt_ref_search_fp = 1;
sf->inter_sf.txfm_rd_gate_level = boosted ? 0 : 4;
sf->inter_sf.prune_bawp_by_gop_usage = 1;
sf->inter_sf.fast_warp_delta_decoupled_search = 1;

sf->inter_sf.prune_inter_modes_based_on_tpl = boosted ? 0 : 3;
Expand Down Expand Up @@ -996,6 +997,7 @@ static AVM_INLINE void init_inter_sf(INTER_MODE_SPEED_FEATURES *inter_sf) {
inter_sf->prune_comp_mode_eval_using_est_rd = false;
inter_sf->prune_warp_newmv_ref_mv_idx = false;
inter_sf->enable_fast_bawp = 0;
inter_sf->prune_bawp_by_gop_usage = 0;
inter_sf->limit_max_ref_mv_idx = false;
}

Expand Down
7 changes: 7 additions & 0 deletions av2/encoder/speed_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,13 @@ typedef struct INTER_MODE_SPEED_FEATURES {
// 1: enable histogram based frame level on/off
int enable_fast_bawp;

// GOP-level BAWP pruning: turn the frame-level BAWP flag off on frames at
// pyramid level >= 3 when, on the GOP's level-1 and level-2 frames, BAWP
// covered on average at most half of the BAWP-eligible area.
// 0: off
// 1: on
int prune_bawp_by_gop_usage;

// Limit the maximum number of reference MVs searched for single-DRL compound
// prediction modes. The cap is applicable for larger blocks and is not
// applied on key/golden/arf frames.
Expand Down
Loading