changeset 4084:90e848a24c70 libavcodec

update ratecontrol to new ff_eval API
author ods15
date Fri, 27 Oct 2006 20:16:26 +0000
parents 065ee7dd69ca
children 16b88d6b3546
files ratecontrol.c ratecontrol.h
diffstat 2 files changed, 64 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/ratecontrol.c	Fri Oct 27 19:53:41 2006 +0000
+++ b/ratecontrol.c	Fri Oct 27 20:16:26 2006 +0000
@@ -48,12 +48,70 @@
             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 @@
     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 @@
 #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 @@
     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 @@
         (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;
     }
 
--- a/ratecontrol.h	Fri Oct 27 19:53:41 2006 +0000
+++ b/ratecontrol.h	Fri Oct 27 20:16:26 2006 +0000
@@ -28,6 +28,8 @@
  * ratecontrol header.
  */
 
+#include "eval.h"
+
 typedef struct Predictor{
     double coeff;
     double count;
@@ -80,6 +82,7 @@
     void *non_lavc_opaque;        ///< context for non lavc rc code (for example xvid)
     float dry_run_qscale;         ///< for xvid rc
     int last_picture_number;      ///< for xvid rc
+    AVEvalExpr * rc_eq_eval;
 }RateControlContext;
 
 struct MpegEncContext;