static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_factor, int frame_num){

    RateControlContext *rcc= &s->rc_context;

    AVCodecContext *a= s->avctx;

    double q, bits;

    const int pict_type= rce->new_pict_type;

    const double mb_num= s->mb_num;

    int i;



    double const_values[]={

        M_PI,

        M_E,

        rce->i_tex_bits*rce->qscale,

        rce->p_tex_bits*rce->qscale,

        (rce->i_tex_bits + rce->p_tex_bits)*(double)rce->qscale,

        rce->mv_bits/mb_num,

        rce->pict_type == B_TYPE ? (rce->f_code + rce->b_code)*0.5 : rce->f_code,

        rce->i_count/mb_num,

        rce->mc_mb_var_sum/mb_num,

        rce->mb_var_sum/mb_num,

        rce->pict_type == I_TYPE,

        rce->pict_type == P_TYPE,

        rce->pict_type == B_TYPE,

        rcc->qscale_sum[pict_type] / (double)rcc->frame_count[pict_type],

        a->qcompress,

/*        rcc->last_qscale_for[I_TYPE],

        rcc->last_qscale_for[P_TYPE],

        rcc->last_qscale_for[B_TYPE],

        rcc->next_non_b_qscale,*/

        rcc->i_cplx_sum[I_TYPE] / (double)rcc->frame_count[I_TYPE],

        rcc->i_cplx_sum[P_TYPE] / (double)rcc->frame_count[P_TYPE],

        rcc->p_cplx_sum[P_TYPE] / (double)rcc->frame_count[P_TYPE],

        rcc->p_cplx_sum[B_TYPE] / (double)rcc->frame_count[B_TYPE],

        (rcc->i_cplx_sum[pict_type] + rcc->p_cplx_sum[pict_type]) / (double)rcc->frame_count[pict_type],

        0

    };



    bits= ff_parse_eval(rcc->rc_eq_eval, const_values, rce);

    if (isnan(bits)) {

        av_log(s->avctx, AV_LOG_ERROR, "Error evaluating rc_eq \"%s\"\n", s->avctx->rc_eq);

        return -1;

    }



    rcc->pass1_rc_eq_output_sum+= bits;

    bits*=rate_factor;

    if(bits<0.0) bits=0.0;

    bits+= 1.0; //avoid 1/0 issues



    /* user override */

    for(i=0; i<s->avctx->rc_override_count; i++){

        RcOverride *rco= s->avctx->rc_override;

        if(rco[i].start_frame > frame_num) continue;

        if(rco[i].end_frame   < frame_num) continue;



        if(rco[i].qscale)

            bits= qp2bits(rce, rco[i].qscale); //FIXME move at end to really force it?

        else

            bits*= rco[i].quality_factor;

    }



    q= bits2qp(rce, bits);



    /* I/B difference */

    if     (pict_type==I_TYPE && s->avctx->i_quant_factor<0.0)

        q= -q*s->avctx->i_quant_factor + s->avctx->i_quant_offset;

    else if(pict_type==B_TYPE && s->avctx->b_quant_factor<0.0)

        q= -q*s->avctx->b_quant_factor + s->avctx->b_quant_offset;




    return q;

}
static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_factor, int frame_num){

    RateControlContext *rcc= &s->rc_context;

    AVCodecContext *a= s->avctx;

    double q, bits;

    const int pict_type= rce->new_pict_type;

    const double mb_num= s->mb_num;

    int i;



    double const_values[]={

        M_PI,

        M_E,

        rce->i_tex_bits*rce->qscale,

        rce->p_tex_bits*rce->qscale,

        (rce->i_tex_bits + rce->p_tex_bits)*(double)rce->qscale,

        rce->mv_bits/mb_num,

        rce->pict_type == B_TYPE ? (rce->f_code + rce->b_code)*0.5 : rce->f_code,

        rce->i_count/mb_num,

        rce->mc_mb_var_sum/mb_num,

        rce->mb_var_sum/mb_num,

        rce->pict_type == I_TYPE,

        rce->pict_type == P_TYPE,

        rce->pict_type == B_TYPE,

        rcc->qscale_sum[pict_type] / (double)rcc->frame_count[pict_type],

        a->qcompress,









        rcc->i_cplx_sum[I_TYPE] / (double)rcc->frame_count[I_TYPE],

        rcc->i_cplx_sum[P_TYPE] / (double)rcc->frame_count[P_TYPE],

        rcc->p_cplx_sum[P_TYPE] / (double)rcc->frame_count[P_TYPE],

        rcc->p_cplx_sum[B_TYPE] / (double)rcc->frame_count[B_TYPE],

        (rcc->i_cplx_sum[pict_type] + rcc->p_cplx_sum[pict_type]) / (double)rcc->frame_count[pict_type],

        0

    };



    bits= ff_parse_eval(rcc->rc_eq_eval, const_values, rce);

    if (isnan(bits)) {

        av_log(s->avctx, AV_LOG_ERROR, "Error evaluating rc_eq \"%s\"\n", s->avctx->rc_eq);

        return -1;

    }



    rcc->pass1_rc_eq_output_sum+= bits;

    bits*=rate_factor;

    if(bits<0.0) bits=0.0;

    bits+= 1.0; 



    

    for(i=0; i<s->avctx->rc_override_count; i++){

        RcOverride *rco= s->avctx->rc_override;

        if(rco[i].start_frame > frame_num) continue;

        if(rco[i].end_frame   < frame_num) continue;



        if(rco[i].qscale)

            bits= qp2bits(rce, rco[i].qscale); 

        else

            bits*= rco[i].quality_factor;

    }



    q= bits2qp(rce, bits);



    

    if     (pict_type==I_TYPE && s->avctx->i_quant_factor<0.0)

        q= -q*s->avctx->i_quant_factor + s->avctx->i_quant_offset;

    else if(pict_type==B_TYPE && s->avctx->b_quant_factor<0.0)

        q= -q*s->avctx->b_quant_factor + s->avctx->b_quant_offset;




    return q;

}
static double FUNC_0(MpegEncContext *VAR_0, RateControlEntry *VAR_1, double VAR_2, int VAR_3){

    RateControlContext *rcc= &VAR_0->rc_context;

    AVCodecContext *a= VAR_0->avctx;

    double VAR_4, VAR_5;

    const int VAR_6= VAR_1->new_pict_type;

    const double VAR_7= VAR_0->VAR_7;

    int VAR_8;



    double VAR_9[]={

        M_PI,

        M_E,

        VAR_1->i_tex_bits*VAR_1->qscale,

        VAR_1->p_tex_bits*VAR_1->qscale,

        (VAR_1->i_tex_bits + VAR_1->p_tex_bits)*(double)VAR_1->qscale,

        VAR_1->mv_bits/VAR_7,

        VAR_1->VAR_6 == B_TYPE ? (VAR_1->f_code + VAR_1->b_code)*0.5 : VAR_1->f_code,

        VAR_1->i_count/VAR_7,

        VAR_1->mc_mb_var_sum/VAR_7,

        VAR_1->mb_var_sum/VAR_7,

        VAR_1->VAR_6 == I_TYPE,

        VAR_1->VAR_6 == P_TYPE,

        VAR_1->VAR_6 == B_TYPE,

        rcc->qscale_sum[VAR_6] / (double)rcc->frame_count[VAR_6],

        a->qcompress,









        rcc->i_cplx_sum[I_TYPE] / (double)rcc->frame_count[I_TYPE],

        rcc->i_cplx_sum[P_TYPE] / (double)rcc->frame_count[P_TYPE],

        rcc->p_cplx_sum[P_TYPE] / (double)rcc->frame_count[P_TYPE],

        rcc->p_cplx_sum[B_TYPE] / (double)rcc->frame_count[B_TYPE],

        (rcc->i_cplx_sum[VAR_6] + rcc->p_cplx_sum[VAR_6]) / (double)rcc->frame_count[VAR_6],

        0

    };



    VAR_5= ff_parse_eval(rcc->rc_eq_eval, VAR_9, VAR_1);

    if (isnan(VAR_5)) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Error evaluating rc_eq \"%VAR_0\"\n", VAR_0->avctx->rc_eq);

        return -1;

    }



    rcc->pass1_rc_eq_output_sum+= VAR_5;

    VAR_5*=VAR_2;

    if(VAR_5<0.0) VAR_5=0.0;

    VAR_5+= 1.0; 



    

    for(VAR_8=0; VAR_8<VAR_0->avctx->rc_override_count; VAR_8++){

        RcOverride *rco= VAR_0->avctx->rc_override;

        if(rco[VAR_8].start_frame > VAR_3) continue;

        if(rco[VAR_8].end_frame   < VAR_3) continue;



        if(rco[VAR_8].qscale)

            VAR_5= qp2bits(VAR_1, rco[VAR_8].qscale); 

        else

            VAR_5*= rco[VAR_8].quality_factor;

    }



    VAR_4= bits2qp(VAR_1, VAR_5);



    

    if     (VAR_6==I_TYPE && VAR_0->avctx->i_quant_factor<0.0)

        VAR_4= -VAR_4*VAR_0->avctx->i_quant_factor + VAR_0->avctx->i_quant_offset;

    else if(VAR_6==B_TYPE && VAR_0->avctx->b_quant_factor<0.0)

        VAR_4= -VAR_4*VAR_0->avctx->b_quant_factor + VAR_0->avctx->b_quant_offset;




    return VAR_4;

}
static double FUNC_0(MpegEncContext *VAR_0, RateControlEntry *VAR_1, double VAR_2, int VAR_3){ RateControlContext *rcc= &VAR_0->rc_context; AVCodecContext *a= VAR_0->avctx; double VAR_4, VAR_5; const int VAR_6= VAR_1->new_pict_type; const double VAR_7= VAR_0->VAR_7; int VAR_8; double VAR_9[]={ M_PI,
M_E,
VAR_1->i_tex_bits*VAR_1->qscale,
VAR_1->p_tex_bits*VAR_1->qscale,
(VAR_1->i_tex_bits + VAR_1->p_tex_bits)*(double)VAR_1->qscale,
VAR_1->mv_bits/VAR_7,
VAR_1->VAR_6 == B_TYPE ? (VAR_1->f_code + VAR_1->b_code)*0.5 : VAR_1->f_code,
VAR_1->i_count/VAR_7,
VAR_1->mc_mb_var_sum/VAR_7,
VAR_1->mb_var_sum/VAR_7,
VAR_1->VAR_6 == I_TYPE,
VAR_1->VAR_6 == P_TYPE,
VAR_1->VAR_6 == B_TYPE,
rcc->qscale_sum[VAR_6] / (double)rcc->frame_count[VAR_6],
a->qcompress,
rcc->i_cplx_sum[I_TYPE] / (double)rcc->frame_count[I_TYPE],
rcc->i_cplx_sum[P_TYPE] / (double)rcc->frame_count[P_TYPE],
rcc->p_cplx_sum[P_TYPE] / (double)rcc->frame_count[P_TYPE],
rcc->p_cplx_sum[B_TYPE] / (double)rcc->frame_count[B_TYPE],
(rcc->i_cplx_sum[VAR_6] + rcc->p_cplx_sum[VAR_6]) / (double)rcc->frame_count[VAR_6],
0
}; VAR_5= ff_parse_eval(rcc->rc_eq_eval, VAR_9, VAR_1); if (isnan(VAR_5)) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Error evaluating rc_eq \"%VAR_0\"\n", VAR_0->avctx->rc_eq); return -1; } rcc->pass1_rc_eq_output_sum+= VAR_5; VAR_5*=VAR_2; if(VAR_5<0.0) VAR_5=0.0; VAR_5+= 1.0; for(VAR_8=0; VAR_8<VAR_0->avctx->rc_override_count; VAR_8++){ RcOverride *rco= VAR_0->avctx->rc_override; if(rco[VAR_8].start_frame > VAR_3) continue; if(rco[VAR_8].end_frame   < VAR_3) continue; if(rco[VAR_8].qscale)
VAR_5= qp2bits(VAR_1, rco[VAR_8].qscale); else
VAR_5*= rco[VAR_8].quality_factor; } VAR_4= bits2qp(VAR_1, VAR_5); if     (VAR_6==I_TYPE && VAR_0->avctx->i_quant_factor<0.0)
VAR_4= -VAR_4*VAR_0->avctx->i_quant_factor + VAR_0->avctx->i_quant_offset; else if(VAR_6==B_TYPE && VAR_0->avctx->b_quant_factor<0.0)
VAR_4= -VAR_4*VAR_0->avctx->b_quant_factor + VAR_0->avctx->b_quant_offset; return VAR_4; }