From 81d2206ff863fbac1da7a9496ec30512532e08eb Mon Sep 17 00:00:00 2001 From: John Koleszar Date: Mon, 25 Apr 2011 15:02:54 -0400 Subject: [PATCH] Move pick_frame_size() to ratectrl.c This is a first step in cleaning up the redundancies between vp8_calc_{auto_,}iframe_target_size. The pick_frame_size() function is moved to ratectrl.c, and made to be the primary interface. This means that the various calc_*_target_size functions can be made private. Change-Id: I66a9a62a5f9c23c818015e03f92f3757bf3bb5c8 --- vp8/encoder/onyx_if.c | 82 ++++------------------------------------------- vp8/encoder/ratectrl.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++--- vp8/encoder/ratectrl.h | 5 +-- 3 files changed, 90 insertions(+), 83 deletions(-) diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c index c7579e8..1011598 100644 --- a/vp8/encoder/onyx_if.c +++ b/vp8/encoder/onyx_if.c @@ -56,7 +56,6 @@ extern void vp8_loop_filter_frame(VP8_COMMON *cm, MACROBLOCKD *mbd, int filt extern void vp8_loop_filter_frame_yonly(VP8_COMMON *cm, MACROBLOCKD *mbd, int filt_val, int sharpness_lvl); extern void vp8_dmachine_specific_config(VP8_COMP *cpi); extern void vp8_cmachine_specific_config(VP8_COMP *cpi); -extern void vp8_calc_auto_iframe_target_size(VP8_COMP *cpi); extern void vp8_deblock_frame(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *post, int filt_lvl, int low_var_thresh, int flag); extern void print_parms(VP8_CONFIG *ocf, char *filenam); extern unsigned int vp8_get_processor_freq(); @@ -2646,78 +2645,7 @@ static void resize_key_frame(VP8_COMP *cpi) #endif } -// return of 0 means drop frame -static int pick_frame_size(VP8_COMP *cpi) -{ - VP8_COMMON *cm = &cpi->common; - - // First Frame is a special case - if (cm->current_video_frame == 0) - { -#if !(CONFIG_REALTIME_ONLY) - - if (cpi->pass == 2) - vp8_calc_auto_iframe_target_size(cpi); - - else -#endif - { - /* 1 Pass there is no information on which to base size so use - * bandwidth per second * fraction of the initial buffer - * level - */ - cpi->this_frame_target = cpi->oxcf.starting_buffer_level / 2; - - if(cpi->this_frame_target > cpi->oxcf.target_bandwidth * 3 / 2) - cpi->this_frame_target = cpi->oxcf.target_bandwidth * 3 / 2; - } - - // Key frame from VFW/auto-keyframe/first frame - cm->frame_type = KEY_FRAME; - - } - // Special case for forced key frames - // The frame sizing here is still far from ideal for 2 pass. - else if (cm->frame_flags & FRAMEFLAGS_KEY) - { - cm->frame_type = KEY_FRAME; - resize_key_frame(cpi); - vp8_calc_iframe_target_size(cpi); - } - else if (cm->frame_type == KEY_FRAME) - { - vp8_calc_auto_iframe_target_size(cpi); - } - else - { - // INTER frame: compute target frame size - cm->frame_type = INTER_FRAME; - vp8_calc_pframe_target_size(cpi); - // Check if we're dropping the frame: - if (cpi->drop_frame) - { - cpi->drop_frame = FALSE; - cpi->drop_count++; - return 0; - } - } - - /* Apply limits on keyframe target. - * - * TODO: move this after consolidating - * vp8_calc_iframe_target_size() and vp8_calc_auto_iframe_target_size() - */ - if (cm->frame_type == KEY_FRAME && cpi->oxcf.rc_max_intra_bitrate_pct) - { - unsigned int max_rate = cpi->av_per_frame_bandwidth - * cpi->oxcf.rc_max_intra_bitrate_pct / 100; - - if (cpi->this_frame_target > max_rate) - cpi->this_frame_target = max_rate; - } - return 1; -} static void set_quantizer(VP8_COMP *cpi, int Q) { @@ -3506,7 +3434,7 @@ static void encode_frame_to_data_rate } // Decide how big to make the frame - if (!pick_frame_size(cpi)) + if (!vp8_pick_frame_size(cpi)) { cm->current_video_frame++; cpi->frames_since_key++; @@ -3834,7 +3762,10 @@ static void encode_frame_to_data_rate } if (cm->frame_type == KEY_FRAME) + { + resize_key_frame(cpi); vp8_setup_key_frame(cpi); + } // transform / motion compensation build reconstruction frame vp8_encode_frame(cpi); @@ -3858,11 +3789,11 @@ static void encode_frame_to_data_rate #else if (decide_key_frame(cpi)) { - vp8_calc_auto_iframe_target_size(cpi); - // Reset all our sizing numbers and recode cm->frame_type = KEY_FRAME; + vp8_pick_frame_size(cpi); + // Clear the Alt reference frame active flag when we have a key frame cpi->source_alt_ref_active = FALSE; @@ -3891,7 +3822,6 @@ static void encode_frame_to_data_rate loop_count++; Loop = TRUE; - resize_key_frame(cpi); continue; } #endif diff --git a/vp8/encoder/ratectrl.c b/vp8/encoder/ratectrl.c index 09a69bc..5b9712c 100644 --- a/vp8/encoder/ratectrl.c +++ b/vp8/encoder/ratectrl.c @@ -329,7 +329,11 @@ void vp8_setup_key_frame(VP8_COMP *cpi) cpi->common.refresh_alt_ref_frame = TRUE; } -void vp8_calc_auto_iframe_target_size(VP8_COMP *cpi) + +static void calc_iframe_target_size(VP8_COMP *cpi); + + +static void calc_auto_iframe_target_size(VP8_COMP *cpi) { // boost defaults to half second int kf_boost; @@ -339,7 +343,7 @@ void vp8_calc_auto_iframe_target_size(VP8_COMP *cpi) if (cpi->oxcf.fixed_q >= 0) { - vp8_calc_iframe_target_size(cpi); + calc_iframe_target_size(cpi); return; } @@ -579,7 +583,8 @@ static int baseline_bits_at_q(int frame_kind, int Q, int MBs) return (Bpm * MBs) >> BPER_MB_NORMBITS; } -void vp8_calc_iframe_target_size(VP8_COMP *cpi) + +static void calc_iframe_target_size(VP8_COMP *cpi) { int Q; int Boost = 100; @@ -656,8 +661,7 @@ void vp8_calc_iframe_target_size(VP8_COMP *cpi) } - -void vp8_calc_pframe_target_size(VP8_COMP *cpi) +static void calc_pframe_target_size(VP8_COMP *cpi) { int min_frame_target; int Adjustment; @@ -1569,3 +1573,75 @@ void vp8_compute_frame_size_bounds(VP8_COMP *cpi, int *frame_under_shoot_limit, } } } + + +// return of 0 means drop frame +int vp8_pick_frame_size(VP8_COMP *cpi) +{ + VP8_COMMON *cm = &cpi->common; + + // First Frame is a special case + if (cm->current_video_frame == 0) + { +#if !(CONFIG_REALTIME_ONLY) + + if (cpi->pass == 2) + calc_auto_iframe_target_size(cpi); + + else +#endif + { + /* 1 Pass there is no information on which to base size so use + * bandwidth per second * fraction of the initial buffer + * level + */ + cpi->this_frame_target = cpi->oxcf.starting_buffer_level / 2; + + if(cpi->this_frame_target > cpi->oxcf.target_bandwidth * 3 / 2) + cpi->this_frame_target = cpi->oxcf.target_bandwidth * 3 / 2; + } + + // Key frame from VFW/auto-keyframe/first frame + cm->frame_type = KEY_FRAME; + + } + // Special case for forced key frames + // The frame sizing here is still far from ideal for 2 pass. + else if (cm->frame_flags & FRAMEFLAGS_KEY) + { + calc_iframe_target_size(cpi); + } + else if (cm->frame_type == KEY_FRAME) + { + calc_auto_iframe_target_size(cpi); + } + else + { + // INTER frame: compute target frame size + cm->frame_type = INTER_FRAME; + calc_pframe_target_size(cpi); + + // Check if we're dropping the frame: + if (cpi->drop_frame) + { + cpi->drop_frame = FALSE; + cpi->drop_count++; + return 0; + } + } + + /* Apply limits on keyframe target. + * + * TODO: move this after consolidating + * calc_iframe_target_size() and calc_auto_iframe_target_size() + */ + if (cm->frame_type == KEY_FRAME && cpi->oxcf.rc_max_intra_bitrate_pct) + { + unsigned int max_rate = cpi->av_per_frame_bandwidth + * cpi->oxcf.rc_max_intra_bitrate_pct / 100; + + if (cpi->this_frame_target > max_rate) + cpi->this_frame_target = max_rate; + } + return 1; +} diff --git a/vp8/encoder/ratectrl.h b/vp8/encoder/ratectrl.h index 766dfdf..d4f7796 100644 --- a/vp8/encoder/ratectrl.h +++ b/vp8/encoder/ratectrl.h @@ -17,11 +17,12 @@ extern void vp8_save_coding_context(VP8_COMP *cpi); extern void vp8_restore_coding_context(VP8_COMP *cpi); extern void vp8_setup_key_frame(VP8_COMP *cpi); -extern void vp8_calc_iframe_target_size(VP8_COMP *cpi); -extern void vp8_calc_pframe_target_size(VP8_COMP *cpi); extern void vp8_update_rate_correction_factors(VP8_COMP *cpi, int damp_var); extern int vp8_regulate_q(VP8_COMP *cpi, int target_bits_per_frame); extern void vp8_adjust_key_frame_context(VP8_COMP *cpi); extern void vp8_compute_frame_size_bounds(VP8_COMP *cpi, int *frame_under_shoot_limit, int *frame_over_shoot_limit); +// return of 0 means drop frame +extern int vp8_pick_frame_size(VP8_COMP *cpi); + #endif -- 2.7.4