Moved zbin_over_quant to macroblock struct
Change-Id: I76fe20ade099573997404b8733cf7f79e82fb21e WIP: Fixing unsafe threading in VP8 encoder.
This commit is contained in:
parent
000c8414b5
commit
3a19eebe4d
@ -143,6 +143,8 @@ typedef struct macroblock
|
||||
unsigned int mbs_tested_so_far;
|
||||
unsigned int mode_test_hit_counts[MAX_MODES];
|
||||
|
||||
int last_zbin_over_quant;
|
||||
int zbin_over_quant;
|
||||
|
||||
void (*short_fdct4x4)(short *input, short *output, int pitch);
|
||||
void (*short_fdct8x4)(short *input, short *output, int pitch);
|
||||
|
@ -423,6 +423,8 @@ static void setup_mbby_copy(MACROBLOCK *mbdst, MACROBLOCK *mbsrc)
|
||||
vpx_memcpy(z->rd_threshes, x->rd_threshes, sizeof(x->rd_threshes));
|
||||
vpx_memcpy(z->rd_thresh_mult, x->rd_thresh_mult,
|
||||
sizeof(x->rd_thresh_mult));
|
||||
|
||||
z->zbin_over_quant = x->zbin_over_quant;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,7 +238,7 @@ static void save_layer_context(VP8_COMP *cpi)
|
||||
lc->rate_correction_factor = cpi->rate_correction_factor;
|
||||
lc->key_frame_rate_correction_factor = cpi->key_frame_rate_correction_factor;
|
||||
lc->gf_rate_correction_factor = cpi->gf_rate_correction_factor;
|
||||
lc->zbin_over_quant = cpi->zbin_over_quant;
|
||||
lc->zbin_over_quant = cpi->mb.zbin_over_quant;
|
||||
lc->inter_frame_target = cpi->inter_frame_target;
|
||||
lc->total_byte_count = cpi->total_byte_count;
|
||||
lc->filter_level = cpi->common.filter_level;
|
||||
@ -276,7 +276,7 @@ static void restore_layer_context(VP8_COMP *cpi, const int layer)
|
||||
cpi->rate_correction_factor = lc->rate_correction_factor;
|
||||
cpi->key_frame_rate_correction_factor = lc->key_frame_rate_correction_factor;
|
||||
cpi->gf_rate_correction_factor = lc->gf_rate_correction_factor;
|
||||
cpi->zbin_over_quant = lc->zbin_over_quant;
|
||||
cpi->mb.zbin_over_quant = lc->zbin_over_quant;
|
||||
cpi->inter_frame_target = lc->inter_frame_target;
|
||||
cpi->total_byte_count = lc->total_byte_count;
|
||||
cpi->common.filter_level = lc->filter_level;
|
||||
@ -3308,7 +3308,7 @@ static void encode_frame_to_data_rate
|
||||
cm->copy_buffer_to_arf = 0;
|
||||
|
||||
/* Clear zbin over-quant value and mode boost values. */
|
||||
cpi->zbin_over_quant = 0;
|
||||
cpi->mb.zbin_over_quant = 0;
|
||||
cpi->zbin_mode_boost = 0;
|
||||
|
||||
/* Enable or disable mode based tweaking of the zbin
|
||||
@ -4076,8 +4076,9 @@ static void encode_frame_to_data_rate
|
||||
q_low = (Q < q_high) ? (Q + 1) : q_high;
|
||||
|
||||
/* If we are using over quant do the same for zbin_oq_low */
|
||||
if (cpi->zbin_over_quant > 0)
|
||||
zbin_oq_low = (cpi->zbin_over_quant < zbin_oq_high) ? (cpi->zbin_over_quant + 1) : zbin_oq_high;
|
||||
if (cpi->mb.zbin_over_quant > 0)
|
||||
zbin_oq_low = (cpi->mb.zbin_over_quant < zbin_oq_high) ?
|
||||
(cpi->mb.zbin_over_quant + 1) : zbin_oq_high;
|
||||
|
||||
if (undershoot_seen)
|
||||
{
|
||||
@ -4093,11 +4094,13 @@ static void encode_frame_to_data_rate
|
||||
* is max)
|
||||
*/
|
||||
if (Q < MAXQ)
|
||||
cpi->zbin_over_quant = 0;
|
||||
cpi->mb.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;
|
||||
zbin_oq_low = (cpi->mb.zbin_over_quant < zbin_oq_high) ?
|
||||
(cpi->mb.zbin_over_quant + 1) : zbin_oq_high;
|
||||
cpi->mb.zbin_over_quant =
|
||||
(zbin_oq_high + zbin_oq_low) / 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -4110,7 +4113,9 @@ static void encode_frame_to_data_rate
|
||||
|
||||
Q = vp8_regulate_q(cpi, cpi->this_frame_target);
|
||||
|
||||
while (((Q < q_low) || (cpi->zbin_over_quant < zbin_oq_low)) && (Retries < 10))
|
||||
while (((Q < q_low) ||
|
||||
(cpi->mb.zbin_over_quant < zbin_oq_low)) &&
|
||||
(Retries < 10))
|
||||
{
|
||||
vp8_update_rate_correction_factors(cpi, 0);
|
||||
Q = vp8_regulate_q(cpi, cpi->this_frame_target);
|
||||
@ -4123,12 +4128,13 @@ static void encode_frame_to_data_rate
|
||||
/* Frame is too small */
|
||||
else
|
||||
{
|
||||
if (cpi->zbin_over_quant == 0)
|
||||
if (cpi->mb.zbin_over_quant == 0)
|
||||
/* Lower q_high if not using over quant */
|
||||
q_high = (Q > q_low) ? (Q - 1) : q_low;
|
||||
else
|
||||
/* else lower zbin_oq_high */
|
||||
zbin_oq_high = (cpi->zbin_over_quant > zbin_oq_low) ? (cpi->zbin_over_quant - 1) : zbin_oq_low;
|
||||
zbin_oq_high = (cpi->mb.zbin_over_quant > zbin_oq_low) ?
|
||||
(cpi->mb.zbin_over_quant - 1) : zbin_oq_low;
|
||||
|
||||
if (overshoot_seen)
|
||||
{
|
||||
@ -4144,9 +4150,10 @@ static void encode_frame_to_data_rate
|
||||
* is max)
|
||||
*/
|
||||
if (Q < MAXQ)
|
||||
cpi->zbin_over_quant = 0;
|
||||
cpi->mb.zbin_over_quant = 0;
|
||||
else
|
||||
cpi->zbin_over_quant = (zbin_oq_high + zbin_oq_low) / 2;
|
||||
cpi->mb.zbin_over_quant =
|
||||
(zbin_oq_high + zbin_oq_low) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -4169,7 +4176,9 @@ static void encode_frame_to_data_rate
|
||||
q_low = Q;
|
||||
}
|
||||
|
||||
while (((Q > q_high) || (cpi->zbin_over_quant > zbin_oq_high)) && (Retries < 10))
|
||||
while (((Q > q_high) ||
|
||||
(cpi->mb.zbin_over_quant > zbin_oq_high)) &&
|
||||
(Retries < 10))
|
||||
{
|
||||
vp8_update_rate_correction_factors(cpi, 0);
|
||||
Q = vp8_regulate_q(cpi, cpi->this_frame_target);
|
||||
@ -4187,7 +4196,9 @@ static void encode_frame_to_data_rate
|
||||
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;
|
||||
cpi->mb.zbin_over_quant = (cpi->mb.zbin_over_quant < zbin_oq_low) ?
|
||||
zbin_oq_low : (cpi->mb.zbin_over_quant > zbin_oq_high) ?
|
||||
zbin_oq_high : cpi->mb.zbin_over_quant;
|
||||
|
||||
Loop = Q != last_q;
|
||||
}
|
||||
|
@ -412,10 +412,8 @@ typedef struct VP8_COMP
|
||||
int ni_frames;
|
||||
int avg_frame_qindex;
|
||||
|
||||
int zbin_over_quant;
|
||||
int zbin_mode_boost;
|
||||
int zbin_mode_boost_enabled;
|
||||
int last_zbin_over_quant;
|
||||
int last_zbin_mode_boost;
|
||||
|
||||
int64_t total_byte_count;
|
||||
|
@ -587,19 +587,19 @@ void vp8cx_init_quantizer(VP8_COMP *cpi)
|
||||
|
||||
#define ZBIN_EXTRA_Y \
|
||||
(( cpi->common.Y1dequant[QIndex][1] * \
|
||||
( cpi->zbin_over_quant + \
|
||||
( x->zbin_over_quant + \
|
||||
cpi->zbin_mode_boost + \
|
||||
x->act_zbin_adj ) ) >> 7)
|
||||
|
||||
#define ZBIN_EXTRA_UV \
|
||||
(( cpi->common.UVdequant[QIndex][1] * \
|
||||
( cpi->zbin_over_quant + \
|
||||
( x->zbin_over_quant + \
|
||||
cpi->zbin_mode_boost + \
|
||||
x->act_zbin_adj ) ) >> 7)
|
||||
|
||||
#define ZBIN_EXTRA_Y2 \
|
||||
(( cpi->common.Y2dequant[QIndex][1] * \
|
||||
( (cpi->zbin_over_quant / 2) + \
|
||||
( (x->zbin_over_quant / 2) + \
|
||||
cpi->zbin_mode_boost + \
|
||||
x->act_zbin_adj ) ) >> 7)
|
||||
|
||||
@ -702,14 +702,14 @@ void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x, int ok_to_skip)
|
||||
/* save this macroblock QIndex for vp8_update_zbin_extra() */
|
||||
x->q_index = QIndex;
|
||||
|
||||
cpi->last_zbin_over_quant = cpi->zbin_over_quant;
|
||||
x->last_zbin_over_quant = x->zbin_over_quant;
|
||||
cpi->last_zbin_mode_boost = cpi->zbin_mode_boost;
|
||||
x->last_act_zbin_adj = x->act_zbin_adj;
|
||||
|
||||
|
||||
|
||||
}
|
||||
else if(cpi->last_zbin_over_quant != cpi->zbin_over_quant
|
||||
else if(x->last_zbin_over_quant != x->zbin_over_quant
|
||||
|| cpi->last_zbin_mode_boost != cpi->zbin_mode_boost
|
||||
|| x->last_act_zbin_adj != x->act_zbin_adj)
|
||||
{
|
||||
@ -729,7 +729,7 @@ void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x, int ok_to_skip)
|
||||
zbin_extra = ZBIN_EXTRA_Y2;
|
||||
x->block[24].zbin_extra = (short)zbin_extra;
|
||||
|
||||
cpi->last_zbin_over_quant = cpi->zbin_over_quant;
|
||||
x->last_zbin_over_quant = x->zbin_over_quant;
|
||||
cpi->last_zbin_mode_boost = cpi->zbin_mode_boost;
|
||||
x->last_act_zbin_adj = x->act_zbin_adj;
|
||||
}
|
||||
|
@ -1124,9 +1124,9 @@ void vp8_update_rate_correction_factors(VP8_COMP *cpi, int damp_var)
|
||||
projected_size_based_on_q = (int)(((.5 + rate_correction_factor * vp8_bits_per_mb[cpi->common.frame_type][Q]) * cpi->common.MBs) / (1 << BPER_MB_NORMBITS));
|
||||
|
||||
/* Make some allowance for cpi->zbin_over_quant */
|
||||
if (cpi->zbin_over_quant > 0)
|
||||
if (cpi->mb.zbin_over_quant > 0)
|
||||
{
|
||||
int Z = cpi->zbin_over_quant;
|
||||
int Z = cpi->mb.zbin_over_quant;
|
||||
double Factor = 0.99;
|
||||
double factor_adjustment = 0.01 / 256.0;
|
||||
|
||||
@ -1203,7 +1203,7 @@ int vp8_regulate_q(VP8_COMP *cpi, int target_bits_per_frame)
|
||||
int Q = cpi->active_worst_quality;
|
||||
|
||||
/* Reset Zbin OQ value */
|
||||
cpi->zbin_over_quant = 0;
|
||||
cpi->mb.zbin_over_quant = 0;
|
||||
|
||||
if (cpi->oxcf.fixed_q >= 0)
|
||||
{
|
||||
@ -1318,12 +1318,12 @@ int vp8_regulate_q(VP8_COMP *cpi, int target_bits_per_frame)
|
||||
* 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)
|
||||
while (cpi->mb.zbin_over_quant < zbin_oqmax)
|
||||
{
|
||||
cpi->zbin_over_quant ++;
|
||||
cpi->mb.zbin_over_quant ++;
|
||||
|
||||
if (cpi->zbin_over_quant > zbin_oqmax)
|
||||
cpi->zbin_over_quant = zbin_oqmax;
|
||||
if (cpi->mb.zbin_over_quant > zbin_oqmax)
|
||||
cpi->mb.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);
|
||||
|
@ -238,15 +238,15 @@ void vp8_initialize_rd_consts(VP8_COMP *cpi, MACROBLOCK *x, int Qvalue)
|
||||
cpi->RDMULT = (int)(rdconst * (capped_q * capped_q));
|
||||
|
||||
/* Extend rate multiplier along side quantizer zbin increases */
|
||||
if (cpi->zbin_over_quant > 0)
|
||||
if (cpi->mb.zbin_over_quant > 0)
|
||||
{
|
||||
double oq_factor;
|
||||
double modq;
|
||||
|
||||
/* 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
|
||||
* The units of cpi->mb.zbin_over_quant are 1/128 of Q bin size
|
||||
*/
|
||||
oq_factor = 1.0 + ((double)0.0015625 * cpi->zbin_over_quant);
|
||||
oq_factor = 1.0 + ((double)0.0015625 * cpi->mb.zbin_over_quant);
|
||||
modq = (int)((double)capped_q * oq_factor);
|
||||
cpi->RDMULT = (int)(rdconst * (modq * modq));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user