avcodec/ratecontrol: make (mc_)mb_var_sum(_last) 64bit

This avoids hypothetical integer overflows
This commit is contained in:
Michael Niedermayer 2014-03-21 18:25:36 +01:00
parent e92a78a409
commit b4356c9cc2
2 changed files with 10 additions and 9 deletions

View File

@ -207,7 +207,7 @@ av_cold int ff_rate_control_init(MpegEncContext *s)
assert(picture_number < rcc->num_entries);
rce = &rcc->entry[picture_number];
e += sscanf(p, " in:%*d out:%*d type:%d q:%f itex:%d ptex:%d mv:%d misc:%d fcode:%d bcode:%d mc-var:%d var:%d icount:%d skipcount:%d hbits:%d",
e += sscanf(p, " in:%*d out:%*d type:%d q:%f itex:%d ptex:%d mv:%d misc:%d fcode:%d bcode:%d mc-var:%"SCNd64" var:%"SCNd64" icount:%d skipcount:%d hbits:%d",
&rce->pict_type, &rce->qscale, &rce->i_tex_bits, &rce->p_tex_bits,
&rce->mv_bits, &rce->misc_bits,
&rce->f_code, &rce->b_code,
@ -754,7 +754,7 @@ float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run)
RateControlEntry local_rce, *rce;
double bits;
double rate_factor;
int var;
int64_t var;
const int pict_type = s->pict_type;
Picture * const pic = &s->current_picture;
emms_c();
@ -770,8 +770,9 @@ float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run)
fps = get_fps(s->avctx);
/* update predictors */
if (picture_number > 2 && !dry_run) {
const int last_var = s->last_pict_type == AV_PICTURE_TYPE_I ? rcc->last_mb_var_sum
: rcc->last_mc_mb_var_sum;
const int64_t last_var =
s->last_pict_type == AV_PICTURE_TYPE_I ? rcc->last_mb_var_sum
: rcc->last_mc_mb_var_sum;
av_assert1(s->frame_bits >= s->stuffing_bits);
update_predictor(&rcc->pred[s->last_pict_type],
rcc->last_qscale,
@ -818,7 +819,7 @@ float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run)
assert(pict_type == rce->new_pict_type);
q = rce->new_qscale / br_compensation;
av_dlog(s, "%f %f %f last:%d var:%d type:%d//\n", q, rce->new_qscale,
av_dlog(s, "%f %f %f last:%d var:%"PRId64" type:%d//\n", q, rce->new_qscale,
br_compensation, s->frame_bits, var, pict_type);
} else {
rce->pict_type =

View File

@ -49,8 +49,8 @@ typedef struct RateControlEntry{
uint64_t expected_bits;
int new_pict_type;
float new_qscale;
int mc_mb_var_sum;
int mb_var_sum;
int64_t mc_mb_var_sum;
int64_t mb_var_sum;
int i_count;
int skip_count;
int f_code;
@ -71,8 +71,8 @@ typedef struct RateControlContext{
double pass1_wanted_bits; ///< bits which should have been outputed by the pass1 code (including complexity init)
double last_qscale;
double last_qscale_for[5]; ///< last qscale for a specific pict type, used for max_diff & ipb factor stuff
int last_mc_mb_var_sum;
int last_mb_var_sum;
int64_t last_mc_mb_var_sum;
int64_t last_mb_var_sum;
uint64_t i_cplx_sum[5];
uint64_t p_cplx_sum[5];
uint64_t mv_bits_sum[5];