From e1050bd3dc351096dd3a7b69d75bbb79b1241ed4 Mon Sep 17 00:00:00 2001 From: Paul Wilkins Date: Fri, 3 Feb 2012 17:08:37 +0000 Subject: [PATCH] Move update of ref frame probabilities in encode loop. The existing code updated the reference frame probabilities before the test to evaluate the impact of using updated probabilities in vp8_estimate_entropy_savings(). The estimate of cost and savings is still basic and does not reflect the new prediction code but this would require per MB costings and the benefit is probably marginal, as this is really just used for rate estimation in the loop. Change-Id: Id6ba88ae6e11c273b3159deff70980363ccd8ea1 --- vp8/encoder/bitstream.c | 31 +++++++++++++++++++---------- vp8/encoder/encodeframe.c | 42 --------------------------------------- 2 files changed, 20 insertions(+), 53 deletions(-) diff --git a/vp8/encoder/bitstream.c b/vp8/encoder/bitstream.c index e3be5a023..d027b03b4 100644 --- a/vp8/encoder/bitstream.c +++ b/vp8/encoder/bitstream.c @@ -2248,24 +2248,27 @@ int vp8_estimate_entropy_savings(VP8_COMP *cpi) const int *const rfct = cpi->count_mb_ref_frame_usage; const int rf_intra = rfct[INTRA_FRAME]; const int rf_inter = rfct[LAST_FRAME] + rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME]; - int new_intra, new_last, gf_last, oldtotal, newtotal; + int new_intra, new_last, new_gf_alt, oldtotal, newtotal; int ref_frame_cost[MAX_REF_FRAMES]; vp8_clear_system_state(); //__asm emms; + // Estimate reference frame cost savings. + // For now this is just based on projected overall frequency of + // each reference frame coded using an unpredicted coding tree. if (cpi->common.frame_type != KEY_FRAME) { -//#if CONFIG_SEGFEATURES new_intra = (rf_intra + rf_inter) ? rf_intra * 255 / (rf_intra + rf_inter) : 1; - - if (!new_intra) - new_intra = 1; + new_intra += !new_intra; new_last = rf_inter ? (rfct[LAST_FRAME] * 255) / rf_inter : 128; + new_last += !new_last; - gf_last = (rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME]) - ? (rfct[GOLDEN_FRAME] * 255) / (rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME]) : 128; + new_gf_alt = (rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME]) + ? (rfct[GOLDEN_FRAME] * 255) / + (rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME]) : 128; + new_gf_alt += !new_gf_alt; // new costs ref_frame_cost[INTRA_FRAME] = vp8_cost_zero(new_intra); @@ -2273,10 +2276,10 @@ int vp8_estimate_entropy_savings(VP8_COMP *cpi) + vp8_cost_zero(new_last); ref_frame_cost[GOLDEN_FRAME] = vp8_cost_one(new_intra) + vp8_cost_one(new_last) - + vp8_cost_zero(gf_last); + + vp8_cost_zero(new_gf_alt); ref_frame_cost[ALTREF_FRAME] = vp8_cost_one(new_intra) + vp8_cost_one(new_last) - + vp8_cost_one(gf_last); + + vp8_cost_one(new_gf_alt); newtotal = rfct[INTRA_FRAME] * ref_frame_cost[INTRA_FRAME] + @@ -2284,7 +2287,6 @@ int vp8_estimate_entropy_savings(VP8_COMP *cpi) rfct[GOLDEN_FRAME] * ref_frame_cost[GOLDEN_FRAME] + rfct[ALTREF_FRAME] * ref_frame_cost[ALTREF_FRAME]; - // old costs ref_frame_cost[INTRA_FRAME] = vp8_cost_zero(cm->prob_intra_coded); ref_frame_cost[LAST_FRAME] = vp8_cost_one(cm->prob_intra_coded) @@ -2303,8 +2305,15 @@ int vp8_estimate_entropy_savings(VP8_COMP *cpi) rfct[ALTREF_FRAME] * ref_frame_cost[ALTREF_FRAME]; savings += (oldtotal - newtotal) / 256; - } + // Update the reference frame probability numbers to reflect + // the observed counts in this frame. Doing this here insures + // that if there are multiple recode iterations the baseline + // probabilities used are updated in each iteration. + cm->prob_intra_coded = new_intra; + cm->prob_last_coded = new_last; + cm->prob_gf_coded = new_gf_alt; + } if (cpi->oxcf.error_resilient_mode & VPX_ERROR_RESILIENT_PARTITIONS) savings += independent_coef_context_savings(cpi); diff --git a/vp8/encoder/encodeframe.c b/vp8/encoder/encodeframe.c index c5e318d48..6b1a31f46 100644 --- a/vp8/encoder/encodeframe.c +++ b/vp8/encoder/encodeframe.c @@ -1435,48 +1435,6 @@ static void encode_frame_internal(VP8_COMP *cpi) } #endif - // Adjust the projected reference frame usage probability numbers to reflect - // what we have just seen. This may be usefull when we make multiple itterations - // of the recode loop rather than continuing to use values from the previous frame. - if ((cm->frame_type != KEY_FRAME) && !cm->refresh_alt_ref_frame && !cm->refresh_golden_frame) - { - const int *const rfct = cpi->count_mb_ref_frame_usage; - const int rf_intra = rfct[INTRA_FRAME]; - const int rf_inter = rfct[LAST_FRAME] + rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME]; - - if ((rf_intra + rf_inter) > 0) - { - cm->prob_intra_coded = (rf_intra * 255) / (rf_intra + rf_inter); - - if (cm->prob_intra_coded < 1) - cm->prob_intra_coded = 1; - - if ((cm->frames_since_golden > 0) || cpi->source_alt_ref_active) - { - cm->prob_last_coded = - rf_inter ? (rfct[LAST_FRAME] * 255) / rf_inter : 128; - - if (cm->prob_last_coded < 1) - cm->prob_last_coded = 1; - - cm->prob_gf_coded = - (rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME]) - ? (rfct[GOLDEN_FRAME] * 255) / - (rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME]) : 128; - - if (cm->prob_gf_coded < 1) - cm->prob_gf_coded = 1; - } - } -//#if CONFIG_SEGFEATURES - else - { - // Trap case where cpi->count_mb_ref_frame_usage[] blank. - cm->prob_intra_coded = 63; - cm->prob_last_coded = 128; - cm->prob_gf_coded = 128; - } - } #if 0 // Keep record of the total distortion this time around for future use cpi->last_frame_distortion = cpi->frame_distortion; -- 2.40.0