From: Marco Paniconi Date: Tue, 31 Mar 2020 17:31:32 +0000 (-0700) Subject: vp9-rtc: Refactor postencode for 1 pass X-Git-Tag: v1.9.0-rc1~48 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aae27c8f1e4ad38eff29ba9d35a772343c0ce5bf;p=libvpx vp9-rtc: Refactor postencode for 1 pass Move some code for 1 pass, that is not directly related to rate control, out of the postencode. This avoids the need of extra flag for the RC interface in: https://chromium-review.googlesource.com/c/webm/libvpx/+/2118915 Change-Id: I3992ea8255196a762c1174c35dd7dcc9b01d317e --- diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c index a5eeeaa23..b15d5f59c 100644 --- a/vp9/encoder/vp9_encoder.c +++ b/vp9/encoder/vp9_encoder.c @@ -5363,6 +5363,14 @@ static void encode_frame_to_data_rate( vp9_rc_postencode_update(cpi, *size); + if (oxcf->pass == 0 && !frame_is_intra_only(cm) && + (!cpi->use_svc || + (cpi->use_svc && + !cpi->svc.layer_context[cpi->svc.temporal_layer_id].is_key_frame && + cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1))) { + vp9_compute_frame_low_motion(cpi); + } + *size = VPXMAX(1, *size); #if 0 diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c index df4a07212..ef64cc6c5 100644 --- a/vp9/encoder/vp9_ratectrl.c +++ b/vp9/encoder/vp9_ratectrl.c @@ -1787,8 +1787,9 @@ static void update_altref_usage(VP9_COMP *const cpi) { } } -static void compute_frame_low_motion(VP9_COMP *const cpi) { +void vp9_compute_frame_low_motion(VP9_COMP *const cpi) { VP9_COMMON *const cm = &cpi->common; + SVC *const svc = &cpi->svc; int mi_row, mi_col; MODE_INFO **mi = cm->mi_grid_visible; RATE_CONTROL *const rc = &cpi->rc; @@ -1805,6 +1806,19 @@ static void compute_frame_low_motion(VP9_COMP *const cpi) { } cnt_zeromv = 100 * cnt_zeromv / (rows * cols); rc->avg_frame_low_motion = (3 * rc->avg_frame_low_motion + cnt_zeromv) >> 2; + + // For SVC: set avg_frame_low_motion (only computed on top spatial layer) + // to all lower spatial layers. + if (cpi->use_svc && svc->spatial_layer_id == svc->number_spatial_layers - 1) { + int i; + for (i = 0; i < svc->number_spatial_layers - 1; ++i) { + const int layer = LAYER_IDS_TO_IDX(i, svc->temporal_layer_id, + svc->number_temporal_layers); + LAYER_CONTEXT *const lc = &svc->layer_context[layer]; + RATE_CONTROL *const lrc = &lc->rc; + lrc->avg_frame_low_motion = rc->avg_frame_low_motion; + } + } } void vp9_rc_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) { @@ -1948,29 +1962,11 @@ void vp9_rc_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) { } if (oxcf->pass == 0) { - if (!frame_is_intra_only(cm) && - (!cpi->use_svc || - (cpi->use_svc && - !svc->layer_context[svc->temporal_layer_id].is_key_frame && - svc->spatial_layer_id == svc->number_spatial_layers - 1))) { - compute_frame_low_motion(cpi); + if (!frame_is_intra_only(cm)) if (cpi->sf.use_altref_onepass) update_altref_usage(cpi); - } - // For SVC: set avg_frame_low_motion (only computed on top spatial layer) - // to all lower spatial layers. - if (cpi->use_svc && - svc->spatial_layer_id == svc->number_spatial_layers - 1) { - int i; - for (i = 0; i < svc->number_spatial_layers - 1; ++i) { - const int layer = LAYER_IDS_TO_IDX(i, svc->temporal_layer_id, - svc->number_temporal_layers); - LAYER_CONTEXT *const lc = &svc->layer_context[layer]; - RATE_CONTROL *const lrc = &lc->rc; - lrc->avg_frame_low_motion = rc->avg_frame_low_motion; - } - } cpi->rc.last_frame_is_src_altref = cpi->rc.is_src_frame_alt_ref; } + if (!frame_is_intra_only(cm)) rc->reset_high_source_sad = 0; rc->last_avg_frame_bandwidth = rc->avg_frame_bandwidth; diff --git a/vp9/encoder/vp9_ratectrl.h b/vp9/encoder/vp9_ratectrl.h index 1fb8dae39..fa070f9be 100644 --- a/vp9/encoder/vp9_ratectrl.h +++ b/vp9/encoder/vp9_ratectrl.h @@ -330,6 +330,8 @@ void vp9_configure_buffer_updates(struct VP9_COMP *cpi, int gf_group_index); void vp9_estimate_qp_gop(struct VP9_COMP *cpi); +void vp9_compute_frame_low_motion(struct VP9_COMP *const cpi); + #ifdef __cplusplus } // extern "C" #endif