Skip to content

Commit

Permalink
vp9 rc: override GF_GROUP decisions using ext RC
Browse files Browse the repository at this point in the history
Bug: b/329483680
Change-Id: I2e02673f1bca56bfa24545b4e25d5e3fd3b0e863
  • Loading branch information
jeromejj committed Mar 28, 2024
1 parent 3f8f193 commit d550194
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
16 changes: 16 additions & 0 deletions test/vp9_ext_ratectrl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ class RateControllerForTest {
gop_decision.use_key_frame = current_gop_ == 0 ? 1 : 0;
gop_decision.use_alt_ref = 1;
gop_decision.gop_coding_frames = kFixedGOPSize;
// First frame is key frame
gop_decision.update_type[0] = VPX_RC_KF_UPDATE;
for (int i = 1; i < kFixedGOPSize; i++) {
gop_decision.update_type[i] = VPX_RC_LF_UPDATE;
gop_decision.update_ref_index[i] = 0;
gop_decision.ref_frame_list[i].index[0] = 0;
gop_decision.ref_frame_list[i].name[0] = VPX_RC_LAST_FRAME;
gop_decision.ref_frame_list[i].index[1] = 0;
gop_decision.ref_frame_list[i].name[1] = VPX_RC_GOLDEN_FRAME;
gop_decision.ref_frame_list[i].index[2] = 0;
gop_decision.ref_frame_list[i].name[1] = VPX_RC_ALTREF_FRAME;
}

// Second frame is altref
gop_decision.update_type[1] = VPX_RC_ARF_UPDATE;
gop_decision.update_ref_index[1] = 2;
return gop_decision;
}

Expand Down
40 changes: 39 additions & 1 deletion vp9/encoder/vp9_firstpass.c
Original file line number Diff line number Diff line change
Expand Up @@ -2302,6 +2302,44 @@ static void define_gf_group_structure(VP9_COMP *cpi) {
gf_group->gf_group_size = frame_index;
}

static void ext_rc_define_gf_group_structure(
VP9_COMP *cpi, vpx_rc_gop_decision_t *gop_decision) {
RATE_CONTROL *const rc = &cpi->rc;
TWO_PASS *const twopass = &cpi->twopass;
GF_GROUP *const gf_group = &twopass->gf_group;
const int key_frame = cpi->common.frame_type == KEY_FRAME;

if (!key_frame) {
set_gf_overlay_frame_type(gf_group, 0, rc->source_alt_ref_active);
}

for (int frame_index = 1; frame_index < gop_decision->gop_coding_frames;
frame_index++) {
const int ext_frame_index = key_frame ? frame_index : frame_index - 1;
const vpx_rc_frame_update_type_t update_type =
gop_decision->update_type[ext_frame_index];
gf_group->update_type[frame_index] = (FRAME_UPDATE_TYPE)update_type;
if (update_type == VPX_RC_ARF_UPDATE) {
gf_group->rf_level[frame_index] = GF_ARF_STD;
gf_group->layer_depth[frame_index] = 1;
gf_group->arf_src_offset[frame_index] =
(unsigned char)(rc->baseline_gf_interval - 1);
gf_group->frame_gop_index[frame_index] = rc->baseline_gf_interval;
} else if (update_type == VPX_RC_LF_UPDATE) {
gf_group->frame_gop_index[frame_index] = frame_index;
gf_group->arf_src_offset[frame_index] = 0;
gf_group->rf_level[frame_index] = INTER_NORMAL;
gf_group->layer_depth[frame_index] = 2;
} else if (update_type == VPX_RC_OVERLAY_UPDATE) {
set_gf_overlay_frame_type(gf_group, frame_index,
rc->source_alt_ref_pending);
gf_group->arf_src_offset[frame_index] = 0;
gf_group->frame_gop_index[frame_index] = rc->baseline_gf_interval;
}
}
gf_group->max_layer_depth = 2;
}

static void allocate_gf_group_bits(VP9_COMP *cpi, int64_t gf_group_bits,
int gf_arf_bits) {
VP9EncoderConfig *const oxcf = &cpi->oxcf;
Expand Down Expand Up @@ -3604,7 +3642,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
rc->baseline_gf_interval =
gop_decision.gop_coding_frames - rc->source_alt_ref_pending;
rc->frames_till_gf_update_due = rc->baseline_gf_interval;
define_gf_group_structure(cpi);
ext_rc_define_gf_group_structure(cpi, &gop_decision);
}
} else {
// Keyframe and section processing.
Expand Down

0 comments on commit d550194

Please sign in to comment.