summaryrefslogtreecommitdiff
path: root/vp8/encoder
diff options
context:
space:
mode:
Diffstat (limited to 'vp8/encoder')
-rw-r--r--vp8/encoder/onyx_if.c65
-rw-r--r--vp8/encoder/ratectrl.c90
2 files changed, 53 insertions, 102 deletions
diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c
index d4a7de2b5..c7579e83a 100644
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -1459,10 +1459,6 @@ static void init_config(VP8_PTR ptr, VP8_CONFIG *oxcf)
cpi->avg_frame_qindex = cpi->oxcf.worst_allowed_q;
// Initialise the starting buffer levels
- cpi->oxcf.starting_buffer_level =
- rescale(cpi->oxcf.starting_buffer_level,
- cpi->oxcf.target_bandwidth, 1000);
-
cpi->buffer_level = cpi->oxcf.starting_buffer_level;
cpi->bits_off_target = cpi->oxcf.starting_buffer_level;
@@ -1635,6 +1631,10 @@ void vp8_change_config(VP8_PTR ptr, VP8_CONFIG *oxcf)
// Convert target bandwidth from Kbit/s to Bit/s
cpi->oxcf.target_bandwidth *= 1000;
+ cpi->oxcf.starting_buffer_level =
+ rescale(cpi->oxcf.starting_buffer_level,
+ cpi->oxcf.target_bandwidth, 1000);
+
// Set or reset optimal and maximum buffer levels.
if (cpi->oxcf.optimal_buffer_level == 0)
cpi->oxcf.optimal_buffer_level = cpi->oxcf.target_bandwidth / 8;
@@ -2659,16 +2659,17 @@ static int pick_frame_size(VP8_COMP *cpi)
if (cpi->pass == 2)
vp8_calc_auto_iframe_target_size(cpi);
- // 1 Pass there is no information on which to base size so use bandwidth per second * fixed fraction
else
#endif
- cpi->this_frame_target = cpi->oxcf.target_bandwidth / 2;
-
- // in error resilient mode the first frame is bigger since it likely contains
- // all the static background
- if (cpi->oxcf.error_resilient_mode == 1 || (cpi->compressor_speed == 2))
{
- cpi->this_frame_target *= 3; // 5;
+ /* 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
@@ -2702,6 +2703,19 @@ static int pick_frame_size(VP8_COMP *cpi)
}
}
+ /* 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;
}
@@ -5173,35 +5187,6 @@ int vp8_calc_ss_err(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest, const
}
-static int calc_low_ss_err(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest, const vp8_variance_rtcd_vtable_t *rtcd)
-{
- int i, j;
- int Total = 0;
-
- unsigned char *src = source->y_buffer;
- unsigned char *dst = dest->y_buffer;
- (void)rtcd;
-
- // Loop through the Y plane raw and reconstruction data summing (square differences)
- for (i = 0; i < source->y_height; i += 16)
- {
- for (j = 0; j < source->y_width; j += 16)
- {
- unsigned int sse;
- VARIANCE_INVOKE(rtcd, mse16x16)(src + j, source->y_stride, dst + j, dest->y_stride, &sse);
-
- if (sse < 8096)
- Total += sse;
- }
-
- src += 16 * source->y_stride;
- dst += 16 * dest->y_stride;
- }
-
- return Total;
-}
-
-
int vp8_get_quantizer(VP8_PTR c)
{
VP8_COMP *cpi = (VP8_COMP *) c;
diff --git a/vp8/encoder/ratectrl.c b/vp8/encoder/ratectrl.c
index 9c8e86bb4..09a69bc71 100644
--- a/vp8/encoder/ratectrl.c
+++ b/vp8/encoder/ratectrl.c
@@ -662,8 +662,6 @@ void vp8_calc_pframe_target_size(VP8_COMP *cpi)
int min_frame_target;
int Adjustment;
- // Set the min frame bandwidth.
- //min_frame_target = estimate_min_frame_size( cpi );
min_frame_target = 0;
if (cpi->pass == 2)
@@ -817,11 +815,6 @@ void vp8_calc_pframe_target_size(VP8_COMP *cpi)
}
}
- // Set a reduced data rate target for our initial Q calculation.
- // This should help to save bits during earier sections.
- if ((cpi->oxcf.under_shoot_pct > 0) && (cpi->oxcf.under_shoot_pct <= 100))
- cpi->this_frame_target = (cpi->this_frame_target * cpi->oxcf.under_shoot_pct) / 100;
-
// Sanity check that the total sum of adjustments is not above the maximum allowed
// That is that having allowed for KF and GF penalties we have not pushed the
// current interframe target to low. If the adjustment we apply here is not capable of recovering
@@ -858,11 +851,6 @@ void vp8_calc_pframe_target_size(VP8_COMP *cpi)
percent_low =
(cpi->oxcf.optimal_buffer_level - cpi->buffer_level) /
one_percent_bits;
-
- if (percent_low > 100)
- percent_low = 100;
- else if (percent_low < 0)
- percent_low = 0;
}
// Are we overshooting the long term clip data rate...
else if (cpi->bits_off_target < 0)
@@ -870,16 +858,16 @@ void vp8_calc_pframe_target_size(VP8_COMP *cpi)
// Adjust per frame data target downwards to compensate.
percent_low = (int)(100 * -cpi->bits_off_target /
(cpi->total_byte_count * 8));
-
- if (percent_low > 100)
- percent_low = 100;
- else if (percent_low < 0)
- percent_low = 0;
}
+ if (percent_low > cpi->oxcf.under_shoot_pct)
+ percent_low = cpi->oxcf.under_shoot_pct;
+ else if (percent_low < 0)
+ percent_low = 0;
+
// lower the target bandwidth for this frame.
- cpi->this_frame_target =
- (cpi->this_frame_target * (100 - (percent_low / 2))) / 100;
+ cpi->this_frame_target -= (cpi->this_frame_target * percent_low)
+ / 200;
// Are we using allowing control of active_worst_allowed_q
// according to buffer level.
@@ -950,20 +938,29 @@ void vp8_calc_pframe_target_size(VP8_COMP *cpi)
}
else
{
- int percent_high;
+ int percent_high = 0;
- if (cpi->bits_off_target > cpi->oxcf.optimal_buffer_level)
+ if ((cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)
+ && (cpi->buffer_level > cpi->oxcf.optimal_buffer_level))
{
- percent_high = (int)(100 * (cpi->bits_off_target - cpi->oxcf.optimal_buffer_level) / (cpi->total_byte_count * 8));
+ percent_high = (cpi->buffer_level
+ - cpi->oxcf.optimal_buffer_level)
+ / one_percent_bits;
+ }
+ else if (cpi->bits_off_target > cpi->oxcf.optimal_buffer_level)
+ {
+ percent_high = (int)((100 * cpi->bits_off_target)
+ / (cpi->total_byte_count * 8));
+ }
- if (percent_high > 100)
- percent_high = 100;
- else if (percent_high < 0)
- percent_high = 0;
+ if (percent_high > cpi->oxcf.over_shoot_pct)
+ percent_high = cpi->oxcf.over_shoot_pct;
+ else if (percent_high < 0)
+ percent_high = 0;
- cpi->this_frame_target = (cpi->this_frame_target * (100 + (percent_high / 2))) / 100;
+ cpi->this_frame_target += (cpi->this_frame_target *
+ percent_high) / 200;
- }
// Are we allowing control of active_worst_allowed_q according to bufferl level.
if (cpi->auto_worst_q)
@@ -1419,39 +1416,6 @@ int vp8_regulate_q(VP8_COMP *cpi, int target_bits_per_frame)
return Q;
}
-static int estimate_min_frame_size(VP8_COMP *cpi)
-{
- double correction_factor;
- int bits_per_mb_at_max_q;
-
- // This funtion returns a default value for the first few frames untill the correction factor has had time to adapt.
- if (cpi->common.current_video_frame < 10)
- {
- if (cpi->pass == 2)
- return (cpi->min_frame_bandwidth);
- else
- return cpi->per_frame_bandwidth / 3;
- }
-
- /* // Select the appropriate correction factor based upon type of frame.
- if ( cpi->common.frame_type == KEY_FRAME )
- correction_factor = cpi->key_frame_rate_correction_factor;
- else
- {
- if ( cpi->common.refresh_alt_ref_frame || cpi->common.refresh_golden_frame )
- correction_factor = cpi->gf_rate_correction_factor;
- else
- correction_factor = cpi->rate_correction_factor;
- }*/
-
- // We estimate at half the value we get from vp8_bits_per_mb
- correction_factor = cpi->rate_correction_factor / 2.0;
-
- bits_per_mb_at_max_q = (int)(.5 + correction_factor * vp8_bits_per_mb[cpi->common.frame_type][MAXQ]);
-
- return (bits_per_mb_at_max_q * cpi->common.MBs) >> BPER_MB_NORMBITS;
-}
-
static int estimate_keyframe_frequency(VP8_COMP *cpi)
{
@@ -1468,8 +1432,10 @@ static int estimate_keyframe_frequency(VP8_COMP *cpi)
/* Assume a default of 1 kf every 2 seconds, or the max kf interval,
* whichever is smaller.
*/
+ int key_freq = cpi->oxcf.key_freq>0 ? cpi->oxcf.key_freq : 1;
av_key_frame_frequency = (int)cpi->output_frame_rate * 2;
- if (av_key_frame_frequency > cpi->oxcf.key_freq)
+
+ if (cpi->oxcf.auto_key && av_key_frame_frequency > key_freq)
av_key_frame_frequency = cpi->oxcf.key_freq;
cpi->prior_key_frame_distance[KEY_FRAME_CONTEXT - 1]