Commit b5f3cb6e authored by Paul Wilkins's avatar Paul Wilkins Committed by Gerrit Code Review
Browse files

Merge "Experimental removal of over quant code" into experimental

parents 5a18106f dbf49420
...@@ -2551,8 +2551,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, ...@@ -2551,8 +2551,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
int q_low; int q_low;
int q_high; int q_high;
int zbin_oq_high;
int zbin_oq_low = 0;
int top_index; int top_index;
int bottom_index; int bottom_index;
...@@ -2565,11 +2563,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, ...@@ -2565,11 +2563,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
#if RESET_FOREACH_FILTER #if RESET_FOREACH_FILTER
int q_low0; int q_low0;
int q_high0; int q_high0;
int zbin_oq_high0;
int zbin_oq_low0 = 0;
int Q0; int Q0;
int last_zbin_oq;
int last_zbin_oq0;
int active_best_quality0; int active_best_quality0;
int active_worst_quality0; int active_worst_quality0;
double rate_correction_factor0; double rate_correction_factor0;
...@@ -2603,7 +2597,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, ...@@ -2603,7 +2597,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
} }
// Clear zbin over-quant value and mode boost values. // Clear zbin over-quant value and mode boost values.
cpi->zbin_over_quant = 0;
cpi->zbin_mode_boost = 0; cpi->zbin_mode_boost = 0;
// Enable or disable mode based tweaking of the zbin // Enable or disable mode based tweaking of the zbin
...@@ -2794,18 +2787,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, ...@@ -2794,18 +2787,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
// Determine initial Q to try // Determine initial Q to try
Q = vp9_regulate_q(cpi, cpi->this_frame_target); Q = vp9_regulate_q(cpi, cpi->this_frame_target);
} }
#if RESET_FOREACH_FILTER
last_zbin_oq = cpi->zbin_over_quant;
#endif
// Set highest allowed value for Zbin over quant
if (cm->frame_type == KEY_FRAME)
zbin_oq_high = 0; // ZBIN_OQ_MAX/16
else if (cpi->refresh_alt_ref_frame
|| (cpi->refresh_golden_frame && !cpi->source_alt_ref_active))
zbin_oq_high = 16;
else
zbin_oq_high = ZBIN_OQ_MAX;
vp9_compute_frame_size_bounds(cpi, &frame_under_shoot_limit, vp9_compute_frame_size_bounds(cpi, &frame_under_shoot_limit,
&frame_over_shoot_limit); &frame_over_shoot_limit);
...@@ -2888,9 +2869,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, ...@@ -2888,9 +2869,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
q_low0 = q_low; q_low0 = q_low;
q_high0 = q_high; q_high0 = q_high;
Q0 = Q; Q0 = Q;
zbin_oq_low0 = zbin_oq_low;
zbin_oq_high0 = zbin_oq_high;
last_zbin_oq0 = last_zbin_oq;
rate_correction_factor0 = cpi->rate_correction_factor; rate_correction_factor0 = cpi->rate_correction_factor;
gf_rate_correction_factor0 = cpi->gf_rate_correction_factor; gf_rate_correction_factor0 = cpi->gf_rate_correction_factor;
active_best_quality0 = cpi->active_best_quality; active_best_quality0 = cpi->active_best_quality;
...@@ -3049,23 +3027,12 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, ...@@ -3049,23 +3027,12 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
if (cpi->projected_frame_size > cpi->this_frame_target) { if (cpi->projected_frame_size > cpi->this_frame_target) {
q_low = (Q < q_high) ? (Q + 1) : q_high; // Raise Qlow as to at least the current value q_low = (Q < q_high) ? (Q + 1) : q_high; // Raise Qlow as to at least the current value
if (cpi->zbin_over_quant > 0) // If we are using over quant do the same for zbin_oq_low
zbin_oq_low = (cpi->zbin_over_quant < zbin_oq_high) ? (cpi->zbin_over_quant + 1) : zbin_oq_high;
if (undershoot_seen || (loop_count > 1)) { if (undershoot_seen || (loop_count > 1)) {
// Update rate_correction_factor unless cpi->active_worst_quality has changed. // Update rate_correction_factor unless cpi->active_worst_quality has changed.
if (!active_worst_qchanged) if (!active_worst_qchanged)
vp9_update_rate_correction_factors(cpi, 1); vp9_update_rate_correction_factors(cpi, 1);
Q = (q_high + q_low + 1) / 2; Q = (q_high + q_low + 1) / 2;
// Adjust cpi->zbin_over_quant (only allowed when Q is max)
if (Q < MAXQ)
cpi->zbin_over_quant = 0;
else {
zbin_oq_low = (cpi->zbin_over_quant < zbin_oq_high) ? (cpi->zbin_over_quant + 1) : zbin_oq_high;
cpi->zbin_over_quant = (zbin_oq_high + zbin_oq_low) / 2;
}
} else { } else {
// Update rate_correction_factor unless cpi->active_worst_quality has changed. // Update rate_correction_factor unless cpi->active_worst_quality has changed.
if (!active_worst_qchanged) if (!active_worst_qchanged)
...@@ -3073,7 +3040,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, ...@@ -3073,7 +3040,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
Q = vp9_regulate_q(cpi, cpi->this_frame_target); Q = vp9_regulate_q(cpi, cpi->this_frame_target);
while (((Q < q_low) || (cpi->zbin_over_quant < zbin_oq_low)) && (Retries < 10)) { while ((Q < q_low) && (Retries < 10)) {
vp9_update_rate_correction_factors(cpi, 0); vp9_update_rate_correction_factors(cpi, 0);
Q = vp9_regulate_q(cpi, cpi->this_frame_target); Q = vp9_regulate_q(cpi, cpi->this_frame_target);
Retries++; Retries++;
...@@ -3084,10 +3051,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, ...@@ -3084,10 +3051,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
} }
// Frame is too small // Frame is too small
else { else {
if (cpi->zbin_over_quant == 0) q_high = (Q > q_low) ? (Q - 1) : q_low;
q_high = (Q > q_low) ? (Q - 1) : q_low; // Lower q_high if not using over quant
else // else lower zbin_oq_high
zbin_oq_high = (cpi->zbin_over_quant > zbin_oq_low) ? (cpi->zbin_over_quant - 1) : zbin_oq_low;
if (overshoot_seen || (loop_count > 1)) { if (overshoot_seen || (loop_count > 1)) {
// Update rate_correction_factor unless cpi->active_worst_quality has changed. // Update rate_correction_factor unless cpi->active_worst_quality has changed.
...@@ -3095,12 +3059,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, ...@@ -3095,12 +3059,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
vp9_update_rate_correction_factors(cpi, 1); vp9_update_rate_correction_factors(cpi, 1);
Q = (q_high + q_low) / 2; Q = (q_high + q_low) / 2;
// Adjust cpi->zbin_over_quant (only allowed when Q is max)
if (Q < MAXQ)
cpi->zbin_over_quant = 0;
else
cpi->zbin_over_quant = (zbin_oq_high + zbin_oq_low) / 2;
} else { } else {
// Update rate_correction_factor unless cpi->active_worst_quality has changed. // Update rate_correction_factor unless cpi->active_worst_quality has changed.
if (!active_worst_qchanged) if (!active_worst_qchanged)
...@@ -3117,7 +3075,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, ...@@ -3117,7 +3075,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
q_low = Q; q_low = Q;
} }
while (((Q > q_high) || (cpi->zbin_over_quant > zbin_oq_high)) && (Retries < 10)) { while ((Q > q_high) && (Retries < 10)) {
vp9_update_rate_correction_factors(cpi, 0); vp9_update_rate_correction_factors(cpi, 0);
Q = vp9_regulate_q(cpi, cpi->this_frame_target); Q = vp9_regulate_q(cpi, cpi->this_frame_target);
Retries++; Retries++;
...@@ -3133,16 +3091,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, ...@@ -3133,16 +3091,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
else if (Q < q_low) else if (Q < q_low)
Q = q_low; Q = q_low;
// Clamp cpi->zbin_over_quant
cpi->zbin_over_quant = (cpi->zbin_over_quant < zbin_oq_low) ?
zbin_oq_low : (cpi->zbin_over_quant > zbin_oq_high) ?
zbin_oq_high : cpi->zbin_over_quant;
// Loop = ((Q != last_q) || (last_zbin_oq != cpi->zbin_over_quant)) ? TRUE : FALSE;
Loop = ((Q != last_q)) ? TRUE : FALSE; Loop = ((Q != last_q)) ? TRUE : FALSE;
#if RESET_FOREACH_FILTER
last_zbin_oq = cpi->zbin_over_quant;
#endif
} else } else
Loop = FALSE; Loop = FALSE;
...@@ -3186,12 +3135,9 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, ...@@ -3186,12 +3135,9 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
if (Loop == TRUE) { if (Loop == TRUE) {
overshoot_seen = FALSE; overshoot_seen = FALSE;
undershoot_seen = FALSE; undershoot_seen = FALSE;
zbin_oq_low = zbin_oq_low0;
zbin_oq_high = zbin_oq_high0;
q_low = q_low0; q_low = q_low0;
q_high = q_high0; q_high = q_high0;
Q = Q0; Q = Q0;
cpi->zbin_over_quant = last_zbin_oq = last_zbin_oq0;
cpi->rate_correction_factor = rate_correction_factor0; cpi->rate_correction_factor = rate_correction_factor0;
cpi->gf_rate_correction_factor = gf_rate_correction_factor0; cpi->gf_rate_correction_factor = gf_rate_correction_factor0;
cpi->active_best_quality = active_best_quality0; cpi->active_best_quality = active_best_quality0;
...@@ -3440,8 +3386,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, ...@@ -3440,8 +3386,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
cpi->avg_q, cpi->avg_q,
vp9_convert_qindex_to_q(cpi->ni_av_qi), vp9_convert_qindex_to_q(cpi->ni_av_qi),
vp9_convert_qindex_to_q(cpi->cq_target_quality), vp9_convert_qindex_to_q(cpi->cq_target_quality),
cpi->zbin_over_quant,
// cpi->avg_frame_qindex, cpi->zbin_over_quant,
cpi->refresh_golden_frame, cpi->refresh_alt_ref_frame, cpi->refresh_golden_frame, cpi->refresh_alt_ref_frame,
cm->frame_type, cpi->gfu_boost, cm->frame_type, cpi->gfu_boost,
cpi->twopass.est_max_qcorrection_factor, cpi->twopass.est_max_qcorrection_factor,
...@@ -3454,7 +3398,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, ...@@ -3454,7 +3398,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
else else
fprintf(f, "%10d %10d %10d %10d %10d %10d %10d %10d" fprintf(f, "%10d %10d %10d %10d %10d %10d %10d %10d"
"%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f" "%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f"
"%6d %5d %5d %5d %8d %8.2f %10d %10.3f" "%5d %5d %8d %8.2f %10d %10.3f"
"%8d %10d %10d %10d\n", "%8d %10d %10d %10d\n",
cpi->common.current_video_frame, cpi->common.current_video_frame,
cpi->this_frame_target, cpi->projected_frame_size, cpi->this_frame_target, cpi->projected_frame_size,
...@@ -3470,8 +3414,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, ...@@ -3470,8 +3414,6 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
cpi->avg_q, cpi->avg_q,
vp9_convert_qindex_to_q(cpi->ni_av_qi), vp9_convert_qindex_to_q(cpi->ni_av_qi),
vp9_convert_qindex_to_q(cpi->cq_target_quality), vp9_convert_qindex_to_q(cpi->cq_target_quality),
cpi->zbin_over_quant,
// cpi->avg_frame_qindex, cpi->zbin_over_quant,
cpi->refresh_golden_frame, cpi->refresh_alt_ref_frame, cpi->refresh_golden_frame, cpi->refresh_alt_ref_frame,
cm->frame_type, cpi->gfu_boost, cm->frame_type, cpi->gfu_boost,
cpi->twopass.est_max_qcorrection_factor, cpi->twopass.est_max_qcorrection_factor,
......
...@@ -53,7 +53,6 @@ ...@@ -53,7 +53,6 @@
#define GF_ZEROMV_ZBIN_BOOST 12 #define GF_ZEROMV_ZBIN_BOOST 12
#define LF_ZEROMV_ZBIN_BOOST 6 #define LF_ZEROMV_ZBIN_BOOST 6
#define MV_ZBIN_BOOST 4 #define MV_ZBIN_BOOST 4
#define ZBIN_OQ_MAX 192
#define VP9_TEMPORAL_ALT_REF 1 #define VP9_TEMPORAL_ALT_REF 1
...@@ -421,7 +420,6 @@ typedef struct VP9_COMP { ...@@ -421,7 +420,6 @@ typedef struct VP9_COMP {
double tot_q; double tot_q;
double avg_q; double avg_q;
int zbin_over_quant;
int zbin_mode_boost; int zbin_mode_boost;
int zbin_mode_boost_enabled; int zbin_mode_boost_enabled;
......
...@@ -484,8 +484,7 @@ void vp9_mb_init_quantizer(VP9_COMP *cpi, MACROBLOCK *x) { ...@@ -484,8 +484,7 @@ void vp9_mb_init_quantizer(VP9_COMP *cpi, MACROBLOCK *x) {
// Y // Y
zbin_extra = (cpi->common.Y1dequant[QIndex][1] * zbin_extra = (cpi->common.Y1dequant[QIndex][1] *
(cpi->zbin_over_quant + (cpi->zbin_mode_boost +
cpi->zbin_mode_boost +
x->act_zbin_adj)) >> 7; x->act_zbin_adj)) >> 7;
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
...@@ -504,8 +503,7 @@ void vp9_mb_init_quantizer(VP9_COMP *cpi, MACROBLOCK *x) { ...@@ -504,8 +503,7 @@ void vp9_mb_init_quantizer(VP9_COMP *cpi, MACROBLOCK *x) {
// UV // UV
zbin_extra = (cpi->common.UVdequant[QIndex][1] * zbin_extra = (cpi->common.UVdequant[QIndex][1] *
(cpi->zbin_over_quant + (cpi->zbin_mode_boost +
cpi->zbin_mode_boost +
x->act_zbin_adj)) >> 7; x->act_zbin_adj)) >> 7;
for (i = 16; i < 24; i++) { for (i = 16; i < 24; i++) {
...@@ -533,8 +531,7 @@ void vp9_update_zbin_extra(VP9_COMP *cpi, MACROBLOCK *x) { ...@@ -533,8 +531,7 @@ void vp9_update_zbin_extra(VP9_COMP *cpi, MACROBLOCK *x) {
// Y // Y
zbin_extra = (cpi->common.Y1dequant[QIndex][1] * zbin_extra = (cpi->common.Y1dequant[QIndex][1] *
(cpi->zbin_over_quant + (cpi->zbin_mode_boost +
cpi->zbin_mode_boost +
x->act_zbin_adj)) >> 7; x->act_zbin_adj)) >> 7;
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
x->block[i].zbin_extra = (int16_t)zbin_extra; x->block[i].zbin_extra = (int16_t)zbin_extra;
...@@ -542,8 +539,7 @@ void vp9_update_zbin_extra(VP9_COMP *cpi, MACROBLOCK *x) { ...@@ -542,8 +539,7 @@ void vp9_update_zbin_extra(VP9_COMP *cpi, MACROBLOCK *x) {
// UV // UV
zbin_extra = (cpi->common.UVdequant[QIndex][1] * zbin_extra = (cpi->common.UVdequant[QIndex][1] *
(cpi->zbin_over_quant + (cpi->zbin_mode_boost +
cpi->zbin_mode_boost +
x->act_zbin_adj)) >> 7; x->act_zbin_adj)) >> 7;
for (i = 16; i < 24; i++) { for (i = 16; i < 24; i++) {
......
...@@ -410,23 +410,6 @@ void vp9_update_rate_correction_factors(VP9_COMP *cpi, int damp_var) { ...@@ -410,23 +410,6 @@ void vp9_update_rate_correction_factors(VP9_COMP *cpi, int damp_var) {
vp9_bits_per_mb(cpi->common.frame_type, Q)) * vp9_bits_per_mb(cpi->common.frame_type, Q)) *
cpi->common.MBs) / (1 << BPER_MB_NORMBITS)); cpi->common.MBs) / (1 << BPER_MB_NORMBITS));
// Make some allowance for cpi->zbin_over_quant
if (cpi->zbin_over_quant > 0) {
int Z = cpi->zbin_over_quant;
double Factor = 0.99;
double factor_adjustment = 0.01 / 256.0; // (double)ZBIN_OQ_MAX;
while (Z > 0) {
Z--;
projected_size_based_on_q =
(int)(Factor * projected_size_based_on_q);
Factor += factor_adjustment;
if (Factor >= 0.999)
Factor = 0.999;
}
}
// Work out a size correction factor. // Work out a size correction factor.
// if ( cpi->this_frame_target > 0 ) // if ( cpi->this_frame_target > 0 )
// correction_factor = (100 * cpi->projected_frame_size) / cpi->this_frame_target; // correction_factor = (100 * cpi->projected_frame_size) / cpi->this_frame_target;
...@@ -488,9 +471,6 @@ int vp9_regulate_q(VP9_COMP *cpi, int target_bits_per_frame) { ...@@ -488,9 +471,6 @@ int vp9_regulate_q(VP9_COMP *cpi, int target_bits_per_frame) {
int bits_per_mb_at_this_q; int bits_per_mb_at_this_q;
double correction_factor; double correction_factor;
// Reset Zbin OQ value
cpi->zbin_over_quant = 0;
// Select the appropriate correction factor based upon type of frame. // Select the appropriate correction factor based upon type of frame.
if (cpi->common.frame_type == KEY_FRAME) if (cpi->common.frame_type == KEY_FRAME)
correction_factor = cpi->key_frame_rate_correction_factor; correction_factor = cpi->key_frame_rate_correction_factor;
...@@ -525,46 +505,6 @@ int vp9_regulate_q(VP9_COMP *cpi, int target_bits_per_frame) { ...@@ -525,46 +505,6 @@ int vp9_regulate_q(VP9_COMP *cpi, int target_bits_per_frame) {
last_error = bits_per_mb_at_this_q - target_bits_per_mb; last_error = bits_per_mb_at_this_q - target_bits_per_mb;
} while (++i <= cpi->active_worst_quality); } while (++i <= cpi->active_worst_quality);
// If we are at MAXQ then enable Q over-run which seeks to claw back additional bits through things like
// the RD multiplier and zero bin size.
if (Q >= MAXQ) {
int zbin_oqmax;
double Factor = 0.99;
double factor_adjustment = 0.01 / 256.0; // (double)ZBIN_OQ_MAX;
if (cpi->common.frame_type == KEY_FRAME)
zbin_oqmax = 0; // ZBIN_OQ_MAX/16
else if (cpi->refresh_alt_ref_frame
|| (cpi->refresh_golden_frame && !cpi->source_alt_ref_active))
zbin_oqmax = 16;
else
zbin_oqmax = ZBIN_OQ_MAX;
// Each incrment in the zbin is assumed to have a fixed effect on bitrate. This is not of course true.
// The effect will be highly clip dependent and may well have sudden steps.
// The idea here is to acheive higher effective quantizers than the normal maximum by expanding the zero
// bin and hence decreasing the number of low magnitude non zero coefficients.
while (cpi->zbin_over_quant < zbin_oqmax) {
cpi->zbin_over_quant++;
if (cpi->zbin_over_quant > zbin_oqmax)
cpi->zbin_over_quant = zbin_oqmax;
// Adjust bits_per_mb_at_this_q estimate
bits_per_mb_at_this_q = (int)(Factor * bits_per_mb_at_this_q);
Factor += factor_adjustment;
if (Factor >= 0.999)
Factor = 0.999;
if (bits_per_mb_at_this_q <= target_bits_per_mb) // Break out if we get down to the target rate
break;
}
}
return Q; return Q;
} }
......
...@@ -217,16 +217,6 @@ void vp9_initialize_rd_consts(VP9_COMP *cpi, int QIndex) { ...@@ -217,16 +217,6 @@ void vp9_initialize_rd_consts(VP9_COMP *cpi, int QIndex) {
cpi->RDMULT = compute_rd_mult(QIndex); cpi->RDMULT = compute_rd_mult(QIndex);
// Extend rate multiplier along side quantizer zbin increases
if (cpi->zbin_over_quant > 0) {
double oq_factor;
// Experimental code using the same basic equation as used for Q above
// The units of cpi->zbin_over_quant are 1/128 of Q bin size
oq_factor = 1.0 + ((double)0.0015625 * cpi->zbin_over_quant);
cpi->RDMULT = (int)((double)cpi->RDMULT * oq_factor * oq_factor);
}
if (cpi->pass == 2 && (cpi->common.frame_type != KEY_FRAME)) { if (cpi->pass == 2 && (cpi->common.frame_type != KEY_FRAME)) {
if (cpi->twopass.next_iiratio > 31) if (cpi->twopass.next_iiratio > 31)
cpi->RDMULT += (cpi->RDMULT * rd_iifactor[31]) >> 4; cpi->RDMULT += (cpi->RDMULT * rd_iifactor[31]) >> 4;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment