]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/eval.c
decode adts aac streams
[ffmpeg] / libavcodec / eval.c
index 4e1e8a3a34d025097bf4136fd631b06a16ede478..5b0e51d627e248de3aafa5aa534ab183ceea65d2 100644 (file)
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  *
  */
 
@@ -75,7 +75,7 @@ static double evalPrimary(Parser *p){
         p->s= next;
         return d;
     }
-    
+
     /* named constants */
     for(i=0; p->const_name && p->const_name[i]; i++){
         if(strmatch(p->s, p->const_name[i])){
@@ -83,7 +83,7 @@ static double evalPrimary(Parser *p){
             return p->const_value[i];
         }
     }
-    
+
     p->s= strchr(p->s, '(');
     if(p->s==NULL){
         av_log(NULL, AV_LOG_ERROR, "Parser: missing ( in \"%s\"\n", next);
@@ -100,7 +100,7 @@ static double evalPrimary(Parser *p){
         return NAN;
     }
     p->s++; // ")"
-    
+
          if( strmatch(next, "sinh"  ) ) d= sinh(d);
     else if( strmatch(next, "cosh"  ) ) d= cosh(d);
     else if( strmatch(next, "tanh"  ) ) d= tanh(d);
@@ -140,16 +140,12 @@ static double evalPrimary(Parser *p){
     }
 
     return d;
-}      
-       
+}
+
 static double evalPow(Parser *p){
-    if(p->s[0]=='+') p->s++;
-       
-    if(p->s[0]=='-'){ 
-        p->s++;
-        return -evalPrimary(p);
-    }else
-        return  evalPrimary(p);
+    int sign= (*p->s == '+') - (*p->s == '-');
+    p->s += sign&1;
+    return (sign|1) * evalPrimary(p);
 }
 
 static double evalFactor(Parser *p){
@@ -171,17 +167,15 @@ static double evalTerm(Parser *p){
 }
 
 static double evalExpression(Parser *p){
-    double ret;
+    double ret= 0;
 
     if(p->stack_index <= 0) //protect against stack overflows
         return NAN;
     p->stack_index--;
 
-    ret= evalTerm(p);
-    while(p->s[0]=='+' || p->s[0]=='-'){
-        if(*p->s++ == '+') ret+= evalTerm(p);
-        else               ret-= evalTerm(p);
-    }
+    do{
+        ret += evalTerm(p);
+    }while(*p->s == '+' || *p->s == '-');
 
     p->stack_index++;
 
@@ -193,7 +187,7 @@ double ff_eval(char *s, double *const_value, const char **const_name,
                double (**func2)(void *, double, double), char **func2_name,
                void *opaque){
     Parser p;
-    
+
     p.stack_index=100;
     p.s= s;
     p.const_value= const_value;
@@ -203,12 +197,12 @@ double ff_eval(char *s, double *const_value, const char **const_name,
     p.func2      = func2;
     p.func2_name = func2_name;
     p.opaque     = opaque;
-    
+
     return evalExpression(&p);
 }
 
 #ifdef TEST
-#undef printf 
+#undef printf
 static double const_values[]={
     M_PI,
     M_E,
@@ -220,6 +214,13 @@ static const char *const_names[]={
     0
 };
 main(){
+    int i;
     printf("%f == 12.7\n", ff_eval("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL));
+
+    for(i=0; i<1050; i++){
+        START_TIMER
+            ff_eval("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL);
+        STOP_TIMER("ff_eval")
+    }
 }
 #endif