~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavutil/eval.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-01-12 22:23:28 UTC
  • mfrom: (0.4.7 sid)
  • mto: This revision was merged to the branch mainline in revision 76.
  • Revision ID: package-import@ubuntu.com-20120112222328-8jqdyodym3p84ygu
Tags: 2:1.0~rc4.dfsg1+svn34540-1
* New upstream snapshot
* upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
#include "avutil.h"
30
30
#include "eval.h"
 
31
#include "log.h"
31
32
 
32
33
typedef struct Parser {
33
34
    const AVClass *class;
122
123
        e_mod, e_max, e_min, e_eq, e_gt, e_gte,
123
124
        e_pow, e_mul, e_div, e_add,
124
125
        e_last, e_st, e_while, e_floor, e_ceil, e_trunc,
 
126
        e_sqrt, e_not,
125
127
    } type;
126
128
    double value; // is sign in other types
127
129
    union {
148
150
        case e_floor:  return e->value * floor(eval_expr(p, e->param[0]));
149
151
        case e_ceil :  return e->value * ceil (eval_expr(p, e->param[0]));
150
152
        case e_trunc:  return e->value * trunc(eval_expr(p, e->param[0]));
 
153
        case e_sqrt:   return e->value * sqrt (eval_expr(p, e->param[0]));
 
154
        case e_not:    return e->value * eval_expr(p, e->param[0]) == 0;
151
155
        case e_while: {
152
156
            double d = NAN;
153
157
            while (eval_expr(p, e->param[0]))
282
286
    else if (strmatch(next, "floor" )) d->type = e_floor;
283
287
    else if (strmatch(next, "ceil"  )) d->type = e_ceil;
284
288
    else if (strmatch(next, "trunc" )) d->type = e_trunc;
 
289
    else if (strmatch(next, "sqrt"  )) d->type = e_sqrt;
 
290
    else if (strmatch(next, "not"   )) d->type = e_not;
285
291
    else {
286
292
        for (i=0; p->func1_names && p->func1_names[i]; i++) {
287
293
            if (strmatch(next, p->func1_names[i])) {
449
455
        case e_floor:
450
456
        case e_ceil:
451
457
        case e_trunc:
 
458
        case e_sqrt:
 
459
        case e_not:
452
460
            return verify_expr(e->param[0]);
453
461
        default: return verify_expr(e->param[0]) && verify_expr(e->param[1]);
454
462
    }
460
468
                  const char * const *func2_names, double (* const *funcs2)(void *, double, double),
461
469
                  int log_offset, void *log_ctx)
462
470
{
463
 
    Parser p;
 
471
    Parser p = { 0 };
464
472
    AVExpr *e = NULL;
465
473
    char *w = av_malloc(strlen(s) + 1);
466
474
    char *wp = w;
488
496
    if ((ret = parse_expr(&e, &p)) < 0)
489
497
        goto end;
490
498
    if (*p.s) {
 
499
        av_expr_free(e);
491
500
        av_log(&p, AV_LOG_ERROR, "Invalid chars '%s' at the end of expression '%s'\n", p.s, s0);
492
501
        ret = AVERROR(EINVAL);
493
502
        goto end;
505
514
 
506
515
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
507
516
{
508
 
    Parser p;
 
517
    Parser p = { 0 };
509
518
 
510
519
    p.const_values = const_values;
511
520
    p.opaque     = opaque;
532
541
 
533
542
#ifdef TEST
534
543
#undef printf
 
544
#include <string.h>
 
545
 
535
546
static double const_values[] = {
536
547
    M_PI,
537
548
    M_E,
544
555
    0
545
556
};
546
557
 
547
 
int main(void)
 
558
int main(int argc, char **argv)
548
559
{
549
560
    int i;
550
561
    double d;
555
566
        "-PI",
556
567
        "+PI",
557
568
        "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
558
 
        "80G/80Gi"
 
569
        "80G/80Gi",
559
570
        "1k",
560
571
        "1Gi",
561
572
        "1gi",
596
607
        "trunc(-123.123)",
597
608
        "ceil(123.123)",
598
609
        "ceil(-123.123)",
 
610
        "sqrt(1764)",
 
611
        "isnan(sqrt(-1))",
 
612
        "not(1)",
 
613
        "not(NAN)",
 
614
        "not(0)",
599
615
        NULL
600
616
    };
601
617
 
616
632
                           NULL, NULL, NULL, NULL, NULL, 0, NULL);
617
633
    printf("%f == 0.931322575\n", d);
618
634
 
619
 
    for (i=0; i<1050; i++) {
620
 
        START_TIMER
 
635
    if (argc > 1 && !strcmp(argv[1], "-t")) {
 
636
        for (i = 0; i < 1050; i++) {
 
637
            START_TIMER;
621
638
            av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
622
639
                                   const_names, const_values,
623
640
                                   NULL, NULL, NULL, NULL, NULL, 0, NULL);
624
 
        STOP_TIMER("av_expr_parse_and_eval")
 
641
            STOP_TIMER("av_expr_parse_and_eval");
 
642
        }
625
643
    }
 
644
 
626
645
    return 0;
627
646
}
628
647
#endif