summaryrefslogtreecommitdiff
path: root/libavcodec/ratecontrol.c
diff options
context:
space:
mode:
authorOded Shimon <ods15@ods15.dyndns.org>2006-10-27 20:16:26 +0000
committerOded Shimon <ods15@ods15.dyndns.org>2006-10-27 20:16:26 +0000
commitbb0f1ea72fc046c4203909ff04cd682dbc8cab23 (patch)
treec94ba5f1d9f5f586f8e46884f3b67dbd2cbec86f /libavcodec/ratecontrol.c
parentce459e12da901ae37604f83f040411f33fa0d424 (diff)
update ratecontrol to new ff_eval API
Originally committed as revision 6808 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/ratecontrol.c')
-rw-r--r--libavcodec/ratecontrol.c115
1 files changed, 61 insertions, 54 deletions
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index 1b61a1b64c..d96c837e6c 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -48,12 +48,70 @@ void ff_write_pass1_stats(MpegEncContext *s){
s->f_code, s->b_code, s->current_picture.mc_mb_var_sum, s->current_picture.mb_var_sum, s->i_count, s->skip_count, s->header_bits);
}
+static inline double qp2bits(RateControlEntry *rce, double qp){
+ if(qp<=0.0){
+ av_log(NULL, AV_LOG_ERROR, "qp<=0.0\n");
+ }
+ return rce->qscale * (double)(rce->i_tex_bits + rce->p_tex_bits+1)/ qp;
+}
+
+static inline double bits2qp(RateControlEntry *rce, double bits){
+ if(bits<0.9){
+ av_log(NULL, AV_LOG_ERROR, "bits<0.9\n");
+ }
+ return rce->qscale * (double)(rce->i_tex_bits + rce->p_tex_bits+1)/ bits;
+}
+
int ff_rate_control_init(MpegEncContext *s)
{
RateControlContext *rcc= &s->rc_context;
int i;
+ char *error = NULL;
+ static const char *const_names[]={
+ "PI",
+ "E",
+ "iTex",
+ "pTex",
+ "tex",
+ "mv",
+ "fCode",
+ "iCount",
+ "mcVar",
+ "var",
+ "isI",
+ "isP",
+ "isB",
+ "avgQP",
+ "qComp",
+/* "lastIQP",
+ "lastPQP",
+ "lastBQP",
+ "nextNonBQP",*/
+ "avgIITex",
+ "avgPITex",
+ "avgPPTex",
+ "avgBPTex",
+ "avgTex",
+ NULL
+ };
+ static double (*func1[])(void *, double)={
+ (void *)bits2qp,
+ (void *)qp2bits,
+ NULL
+ };
+ static const char *func1_names[]={
+ "bits2qp",
+ "qp2bits",
+ NULL
+ };
emms_c();
+ rcc->rc_eq_eval = ff_parse(s->avctx->rc_eq, const_names, func1, func1_names, NULL, NULL, &error);
+ if (!rcc->rc_eq_eval) {
+ av_log(s->avctx, AV_LOG_ERROR, "Error parsing rc_eq \"%s\": %s\n", s->avctx->rc_eq, error? error : "");
+ return -1;
+ }
+
for(i=0; i<5; i++){
rcc->pred[i].coeff= FF_QP2LAMBDA * 7.0;
rcc->pred[i].count= 1.0;
@@ -195,6 +253,7 @@ void ff_rate_control_uninit(MpegEncContext *s)
RateControlContext *rcc= &s->rc_context;
emms_c();
+ ff_eval_free(rcc->rc_eq_eval);
av_freep(&rcc->entry);
#ifdef CONFIG_XVID
@@ -203,20 +262,6 @@ void ff_rate_control_uninit(MpegEncContext *s)
#endif
}
-static inline double qp2bits(RateControlEntry *rce, double qp){
- if(qp<=0.0){
- av_log(NULL, AV_LOG_ERROR, "qp<=0.0\n");
- }
- return rce->qscale * (double)(rce->i_tex_bits + rce->p_tex_bits+1)/ qp;
-}
-
-static inline double bits2qp(RateControlEntry *rce, double bits){
- if(bits<0.9){
- av_log(NULL, AV_LOG_ERROR, "bits<0.9\n");
- }
- return rce->qscale * (double)(rce->i_tex_bits + rce->p_tex_bits+1)/ bits;
-}
-
int ff_vbv_update(MpegEncContext *s, int frame_size){
RateControlContext *rcc= &s->rc_context;
const double fps= 1/av_q2d(s->avctx->time_base);
@@ -263,7 +308,6 @@ static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_f
const int pict_type= rce->new_pict_type;
const double mb_num= s->mb_num;
int i;
- char *error = NULL;
double const_values[]={
M_PI,
@@ -292,47 +336,10 @@ static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_f
(rcc->i_cplx_sum[pict_type] + rcc->p_cplx_sum[pict_type]) / (double)rcc->frame_count[pict_type],
0
};
- static const char *const_names[]={
- "PI",
- "E",
- "iTex",
- "pTex",
- "tex",
- "mv",
- "fCode",
- "iCount",
- "mcVar",
- "var",
- "isI",
- "isP",
- "isB",
- "avgQP",
- "qComp",
-/* "lastIQP",
- "lastPQP",
- "lastBQP",
- "nextNonBQP",*/
- "avgIITex",
- "avgPITex",
- "avgPPTex",
- "avgBPTex",
- "avgTex",
- NULL
- };
- static double (*func1[])(void *, double)={
- (void *)bits2qp,
- (void *)qp2bits,
- NULL
- };
- static const char *func1_names[]={
- "bits2qp",
- "qp2bits",
- NULL
- };
- bits= ff_eval2(s->avctx->rc_eq, const_values, const_names, func1, func1_names, NULL, NULL, rce, &error);
+ 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\": %s\n", s->avctx->rc_eq, error? error : "");
+ av_log(s->avctx, AV_LOG_ERROR, "Error evaluating rc_eq \"%s\"\n", s->avctx->rc_eq);
return -1;
}