diff options
author | John Koleszar <jkoleszar@google.com> | 2011-04-25 15:02:54 -0400 |
---|---|---|
committer | John Koleszar <jkoleszar@google.com> | 2011-04-26 16:49:54 -0400 |
commit | 81d2206ff863fbac1da7a9496ec30512532e08eb (patch) | |
tree | 9b9d652f25aa3e3d7ecde674b3a1427656b9da4b /vp8/encoder/ratectrl.c | |
parent | 0da77a840b79c8037272687ba5fa8c3e01885572 (diff) | |
download | libvpx-81d2206ff863fbac1da7a9496ec30512532e08eb.tar libvpx-81d2206ff863fbac1da7a9496ec30512532e08eb.tar.gz libvpx-81d2206ff863fbac1da7a9496ec30512532e08eb.tar.bz2 libvpx-81d2206ff863fbac1da7a9496ec30512532e08eb.zip |
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
Diffstat (limited to 'vp8/encoder/ratectrl.c')
-rw-r--r-- | vp8/encoder/ratectrl.c | 86 |
1 files changed, 81 insertions, 5 deletions
diff --git a/vp8/encoder/ratectrl.c b/vp8/encoder/ratectrl.c index 09a69bc71..5b9712cf0 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; +} |