You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

669 lines
19KB

  1. /*
  2. * Copyright (c) 2002-2006 Michael Niedermayer <michaelni@gmx.at>
  3. * Copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * simple arithmetic expression evaluator.
  24. *
  25. * see http://joe.hotchkiss.com/programming/eval/eval.html
  26. */
  27. #include "avutil.h"
  28. #include "common.h"
  29. #include "eval.h"
  30. #include "log.h"
  31. #include "mathematics.h"
  32. typedef struct Parser {
  33. const AVClass *class;
  34. int stack_index;
  35. char *s;
  36. const double *const_values;
  37. const char * const *const_names; // NULL terminated
  38. double (* const *funcs1)(void *, double a); // NULL terminated
  39. const char * const *func1_names; // NULL terminated
  40. double (* const *funcs2)(void *, double a, double b); // NULL terminated
  41. const char * const *func2_names; // NULL terminated
  42. void *opaque;
  43. int log_offset;
  44. void *log_ctx;
  45. #define VARS 10
  46. double var[VARS];
  47. } Parser;
  48. static const AVClass class = { "Eval", av_default_item_name, NULL, LIBAVUTIL_VERSION_INT, offsetof(Parser,log_offset), offsetof(Parser,log_ctx) };
  49. static const int8_t si_prefixes['z' - 'E' + 1] = {
  50. ['y'-'E']= -24,
  51. ['z'-'E']= -21,
  52. ['a'-'E']= -18,
  53. ['f'-'E']= -15,
  54. ['p'-'E']= -12,
  55. ['n'-'E']= - 9,
  56. ['u'-'E']= - 6,
  57. ['m'-'E']= - 3,
  58. ['c'-'E']= - 2,
  59. ['d'-'E']= - 1,
  60. ['h'-'E']= 2,
  61. ['k'-'E']= 3,
  62. ['K'-'E']= 3,
  63. ['M'-'E']= 6,
  64. ['G'-'E']= 9,
  65. ['T'-'E']= 12,
  66. ['P'-'E']= 15,
  67. ['E'-'E']= 18,
  68. ['Z'-'E']= 21,
  69. ['Y'-'E']= 24,
  70. };
  71. double av_strtod(const char *numstr, char **tail)
  72. {
  73. double d;
  74. char *next;
  75. d = strtod(numstr, &next);
  76. /* if parsing succeeded, check for and interpret postfixes */
  77. if (next!=numstr) {
  78. if (*next >= 'E' && *next <= 'z') {
  79. int e= si_prefixes[*next - 'E'];
  80. if (e) {
  81. if (next[1] == 'i') {
  82. d*= pow( 2, e/0.3);
  83. next+=2;
  84. } else {
  85. d*= pow(10, e);
  86. next++;
  87. }
  88. }
  89. }
  90. if (*next=='B') {
  91. d*=8;
  92. next++;
  93. }
  94. }
  95. /* if requested, fill in tail with the position after the last parsed
  96. character */
  97. if (tail)
  98. *tail = next;
  99. return d;
  100. }
  101. #define IS_IDENTIFIER_CHAR(c) ((c) - '0' <= 9U || (c) - 'a' <= 25U || (c) - 'A' <= 25U || (c) == '_')
  102. static int strmatch(const char *s, const char *prefix)
  103. {
  104. int i;
  105. for (i=0; prefix[i]; i++) {
  106. if (prefix[i] != s[i]) return 0;
  107. }
  108. /* return 1 only if the s identifier is terminated */
  109. return !IS_IDENTIFIER_CHAR(s[i]);
  110. }
  111. struct AVExpr {
  112. enum {
  113. e_value, e_const, e_func0, e_func1, e_func2,
  114. e_squish, e_gauss, e_ld, e_isnan, e_isinf,
  115. e_mod, e_max, e_min, e_eq, e_gt, e_gte,
  116. e_pow, e_mul, e_div, e_add,
  117. e_last, e_st, e_while, e_floor, e_ceil, e_trunc,
  118. e_sqrt, e_not,
  119. } type;
  120. double value; // is sign in other types
  121. union {
  122. int const_index;
  123. double (*func0)(double);
  124. double (*func1)(void *, double);
  125. double (*func2)(void *, double, double);
  126. } a;
  127. struct AVExpr *param[2];
  128. };
  129. static double eval_expr(Parser *p, AVExpr *e)
  130. {
  131. switch (e->type) {
  132. case e_value: return e->value;
  133. case e_const: return e->value * p->const_values[e->a.const_index];
  134. case e_func0: return e->value * e->a.func0(eval_expr(p, e->param[0]));
  135. case e_func1: return e->value * e->a.func1(p->opaque, eval_expr(p, e->param[0]));
  136. case e_func2: return e->value * e->a.func2(p->opaque, eval_expr(p, e->param[0]), eval_expr(p, e->param[1]));
  137. case e_squish: return 1/(1+exp(4*eval_expr(p, e->param[0])));
  138. case e_gauss: { double d = eval_expr(p, e->param[0]); return exp(-d*d/2)/sqrt(2*M_PI); }
  139. case e_ld: return e->value * p->var[av_clip(eval_expr(p, e->param[0]), 0, VARS-1)];
  140. case e_isnan: return e->value * !!isnan(eval_expr(p, e->param[0]));
  141. case e_isinf: return e->value * !!isinf(eval_expr(p, e->param[0]));
  142. case e_floor: return e->value * floor(eval_expr(p, e->param[0]));
  143. case e_ceil : return e->value * ceil (eval_expr(p, e->param[0]));
  144. case e_trunc: return e->value * trunc(eval_expr(p, e->param[0]));
  145. case e_sqrt: return e->value * sqrt (eval_expr(p, e->param[0]));
  146. case e_not: return e->value * eval_expr(p, e->param[0]) == 0;
  147. case e_while: {
  148. double d = NAN;
  149. while (eval_expr(p, e->param[0]))
  150. d=eval_expr(p, e->param[1]);
  151. return d;
  152. }
  153. default: {
  154. double d = eval_expr(p, e->param[0]);
  155. double d2 = eval_expr(p, e->param[1]);
  156. switch (e->type) {
  157. case e_mod: return e->value * (d - floor(d/d2)*d2);
  158. case e_max: return e->value * (d > d2 ? d : d2);
  159. case e_min: return e->value * (d < d2 ? d : d2);
  160. case e_eq: return e->value * (d == d2 ? 1.0 : 0.0);
  161. case e_gt: return e->value * (d > d2 ? 1.0 : 0.0);
  162. case e_gte: return e->value * (d >= d2 ? 1.0 : 0.0);
  163. case e_pow: return e->value * pow(d, d2);
  164. case e_mul: return e->value * (d * d2);
  165. case e_div: return e->value * (d / d2);
  166. case e_add: return e->value * (d + d2);
  167. case e_last:return e->value * d2;
  168. case e_st : return e->value * (p->var[av_clip(d, 0, VARS-1)]= d2);
  169. }
  170. }
  171. }
  172. return NAN;
  173. }
  174. static int parse_expr(AVExpr **e, Parser *p);
  175. void av_expr_free(AVExpr *e)
  176. {
  177. if (!e) return;
  178. av_expr_free(e->param[0]);
  179. av_expr_free(e->param[1]);
  180. av_freep(&e);
  181. }
  182. static int parse_primary(AVExpr **e, Parser *p)
  183. {
  184. AVExpr *d = av_mallocz(sizeof(AVExpr));
  185. char *next = p->s, *s0 = p->s;
  186. int ret, i;
  187. if (!d)
  188. return AVERROR(ENOMEM);
  189. /* number */
  190. d->value = av_strtod(p->s, &next);
  191. if (next != p->s) {
  192. d->type = e_value;
  193. p->s= next;
  194. *e = d;
  195. return 0;
  196. }
  197. d->value = 1;
  198. /* named constants */
  199. for (i=0; p->const_names && p->const_names[i]; i++) {
  200. if (strmatch(p->s, p->const_names[i])) {
  201. p->s+= strlen(p->const_names[i]);
  202. d->type = e_const;
  203. d->a.const_index = i;
  204. *e = d;
  205. return 0;
  206. }
  207. }
  208. p->s= strchr(p->s, '(');
  209. if (p->s==NULL) {
  210. av_log(p, AV_LOG_ERROR, "Undefined constant or missing '(' in '%s'\n", s0);
  211. p->s= next;
  212. av_expr_free(d);
  213. return AVERROR(EINVAL);
  214. }
  215. p->s++; // "("
  216. if (*next == '(') { // special case do-nothing
  217. av_freep(&d);
  218. if ((ret = parse_expr(&d, p)) < 0)
  219. return ret;
  220. if (p->s[0] != ')') {
  221. av_log(p, AV_LOG_ERROR, "Missing ')' in '%s'\n", s0);
  222. av_expr_free(d);
  223. return AVERROR(EINVAL);
  224. }
  225. p->s++; // ")"
  226. *e = d;
  227. return 0;
  228. }
  229. if ((ret = parse_expr(&(d->param[0]), p)) < 0) {
  230. av_expr_free(d);
  231. return ret;
  232. }
  233. if (p->s[0]== ',') {
  234. p->s++; // ","
  235. parse_expr(&d->param[1], p);
  236. }
  237. if (p->s[0] != ')') {
  238. av_log(p, AV_LOG_ERROR, "Missing ')' or too many args in '%s'\n", s0);
  239. av_expr_free(d);
  240. return AVERROR(EINVAL);
  241. }
  242. p->s++; // ")"
  243. d->type = e_func0;
  244. if (strmatch(next, "sinh" )) d->a.func0 = sinh;
  245. else if (strmatch(next, "cosh" )) d->a.func0 = cosh;
  246. else if (strmatch(next, "tanh" )) d->a.func0 = tanh;
  247. else if (strmatch(next, "sin" )) d->a.func0 = sin;
  248. else if (strmatch(next, "cos" )) d->a.func0 = cos;
  249. else if (strmatch(next, "tan" )) d->a.func0 = tan;
  250. else if (strmatch(next, "atan" )) d->a.func0 = atan;
  251. else if (strmatch(next, "asin" )) d->a.func0 = asin;
  252. else if (strmatch(next, "acos" )) d->a.func0 = acos;
  253. else if (strmatch(next, "exp" )) d->a.func0 = exp;
  254. else if (strmatch(next, "log" )) d->a.func0 = log;
  255. else if (strmatch(next, "abs" )) d->a.func0 = fabs;
  256. else if (strmatch(next, "squish")) d->type = e_squish;
  257. else if (strmatch(next, "gauss" )) d->type = e_gauss;
  258. else if (strmatch(next, "mod" )) d->type = e_mod;
  259. else if (strmatch(next, "max" )) d->type = e_max;
  260. else if (strmatch(next, "min" )) d->type = e_min;
  261. else if (strmatch(next, "eq" )) d->type = e_eq;
  262. else if (strmatch(next, "gte" )) d->type = e_gte;
  263. else if (strmatch(next, "gt" )) d->type = e_gt;
  264. else if (strmatch(next, "lte" )) { AVExpr *tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gte; }
  265. else if (strmatch(next, "lt" )) { AVExpr *tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gt; }
  266. else if (strmatch(next, "ld" )) d->type = e_ld;
  267. else if (strmatch(next, "isnan" )) d->type = e_isnan;
  268. else if (strmatch(next, "isinf" )) d->type = e_isinf;
  269. else if (strmatch(next, "st" )) d->type = e_st;
  270. else if (strmatch(next, "while" )) d->type = e_while;
  271. else if (strmatch(next, "floor" )) d->type = e_floor;
  272. else if (strmatch(next, "ceil" )) d->type = e_ceil;
  273. else if (strmatch(next, "trunc" )) d->type = e_trunc;
  274. else if (strmatch(next, "sqrt" )) d->type = e_sqrt;
  275. else if (strmatch(next, "not" )) d->type = e_not;
  276. else {
  277. for (i=0; p->func1_names && p->func1_names[i]; i++) {
  278. if (strmatch(next, p->func1_names[i])) {
  279. d->a.func1 = p->funcs1[i];
  280. d->type = e_func1;
  281. *e = d;
  282. return 0;
  283. }
  284. }
  285. for (i=0; p->func2_names && p->func2_names[i]; i++) {
  286. if (strmatch(next, p->func2_names[i])) {
  287. d->a.func2 = p->funcs2[i];
  288. d->type = e_func2;
  289. *e = d;
  290. return 0;
  291. }
  292. }
  293. av_log(p, AV_LOG_ERROR, "Unknown function in '%s'\n", s0);
  294. av_expr_free(d);
  295. return AVERROR(EINVAL);
  296. }
  297. *e = d;
  298. return 0;
  299. }
  300. static AVExpr *new_eval_expr(int type, int value, AVExpr *p0, AVExpr *p1)
  301. {
  302. AVExpr *e = av_mallocz(sizeof(AVExpr));
  303. if (!e)
  304. return NULL;
  305. e->type =type ;
  306. e->value =value ;
  307. e->param[0] =p0 ;
  308. e->param[1] =p1 ;
  309. return e;
  310. }
  311. static int parse_pow(AVExpr **e, Parser *p, int *sign)
  312. {
  313. *sign= (*p->s == '+') - (*p->s == '-');
  314. p->s += *sign&1;
  315. return parse_primary(e, p);
  316. }
  317. static int parse_factor(AVExpr **e, Parser *p)
  318. {
  319. int sign, sign2, ret;
  320. AVExpr *e0, *e1, *e2;
  321. if ((ret = parse_pow(&e0, p, &sign)) < 0)
  322. return ret;
  323. while(p->s[0]=='^'){
  324. e1 = e0;
  325. p->s++;
  326. if ((ret = parse_pow(&e2, p, &sign2)) < 0) {
  327. av_expr_free(e1);
  328. return ret;
  329. }
  330. e0 = new_eval_expr(e_pow, 1, e1, e2);
  331. if (!e0) {
  332. av_expr_free(e1);
  333. av_expr_free(e2);
  334. return AVERROR(ENOMEM);
  335. }
  336. if (e0->param[1]) e0->param[1]->value *= (sign2|1);
  337. }
  338. if (e0) e0->value *= (sign|1);
  339. *e = e0;
  340. return 0;
  341. }
  342. static int parse_term(AVExpr **e, Parser *p)
  343. {
  344. int ret;
  345. AVExpr *e0, *e1, *e2;
  346. if ((ret = parse_factor(&e0, p)) < 0)
  347. return ret;
  348. while (p->s[0]=='*' || p->s[0]=='/') {
  349. int c= *p->s++;
  350. e1 = e0;
  351. if ((ret = parse_factor(&e2, p)) < 0) {
  352. av_expr_free(e1);
  353. return ret;
  354. }
  355. e0 = new_eval_expr(c == '*' ? e_mul : e_div, 1, e1, e2);
  356. if (!e0) {
  357. av_expr_free(e1);
  358. av_expr_free(e2);
  359. return AVERROR(ENOMEM);
  360. }
  361. }
  362. *e = e0;
  363. return 0;
  364. }
  365. static int parse_subexpr(AVExpr **e, Parser *p)
  366. {
  367. int ret;
  368. AVExpr *e0, *e1, *e2;
  369. if ((ret = parse_term(&e0, p)) < 0)
  370. return ret;
  371. while (*p->s == '+' || *p->s == '-') {
  372. e1 = e0;
  373. if ((ret = parse_term(&e2, p)) < 0) {
  374. av_expr_free(e1);
  375. return ret;
  376. }
  377. e0 = new_eval_expr(e_add, 1, e1, e2);
  378. if (!e0) {
  379. av_expr_free(e1);
  380. av_expr_free(e2);
  381. return AVERROR(ENOMEM);
  382. }
  383. };
  384. *e = e0;
  385. return 0;
  386. }
  387. static int parse_expr(AVExpr **e, Parser *p)
  388. {
  389. int ret;
  390. AVExpr *e0, *e1, *e2;
  391. if (p->stack_index <= 0) //protect against stack overflows
  392. return AVERROR(EINVAL);
  393. p->stack_index--;
  394. if ((ret = parse_subexpr(&e0, p)) < 0)
  395. return ret;
  396. while (*p->s == ';') {
  397. p->s++;
  398. e1 = e0;
  399. if ((ret = parse_subexpr(&e2, p)) < 0) {
  400. av_expr_free(e1);
  401. return ret;
  402. }
  403. e0 = new_eval_expr(e_last, 1, e1, e2);
  404. if (!e0) {
  405. av_expr_free(e1);
  406. av_expr_free(e2);
  407. return AVERROR(ENOMEM);
  408. }
  409. };
  410. p->stack_index++;
  411. *e = e0;
  412. return 0;
  413. }
  414. static int verify_expr(AVExpr *e)
  415. {
  416. if (!e) return 0;
  417. switch (e->type) {
  418. case e_value:
  419. case e_const: return 1;
  420. case e_func0:
  421. case e_func1:
  422. case e_squish:
  423. case e_ld:
  424. case e_gauss:
  425. case e_isnan:
  426. case e_isinf:
  427. case e_floor:
  428. case e_ceil:
  429. case e_trunc:
  430. case e_sqrt:
  431. case e_not:
  432. return verify_expr(e->param[0]);
  433. default: return verify_expr(e->param[0]) && verify_expr(e->param[1]);
  434. }
  435. }
  436. int av_expr_parse(AVExpr **expr, const char *s,
  437. const char * const *const_names,
  438. const char * const *func1_names, double (* const *funcs1)(void *, double),
  439. const char * const *func2_names, double (* const *funcs2)(void *, double, double),
  440. int log_offset, void *log_ctx)
  441. {
  442. Parser p = { 0 };
  443. AVExpr *e = NULL;
  444. char *w = av_malloc(strlen(s) + 1);
  445. char *wp = w;
  446. const char *s0 = s;
  447. int ret = 0;
  448. if (!w)
  449. return AVERROR(ENOMEM);
  450. while (*s)
  451. if (!isspace(*s++)) *wp++ = s[-1];
  452. *wp++ = 0;
  453. p.class = &class;
  454. p.stack_index=100;
  455. p.s= w;
  456. p.const_names = const_names;
  457. p.funcs1 = funcs1;
  458. p.func1_names = func1_names;
  459. p.funcs2 = funcs2;
  460. p.func2_names = func2_names;
  461. p.log_offset = log_offset;
  462. p.log_ctx = log_ctx;
  463. if ((ret = parse_expr(&e, &p)) < 0)
  464. goto end;
  465. if (*p.s) {
  466. av_expr_free(e);
  467. av_log(&p, AV_LOG_ERROR, "Invalid chars '%s' at the end of expression '%s'\n", p.s, s0);
  468. ret = AVERROR(EINVAL);
  469. goto end;
  470. }
  471. if (!verify_expr(e)) {
  472. av_expr_free(e);
  473. ret = AVERROR(EINVAL);
  474. goto end;
  475. }
  476. *expr = e;
  477. end:
  478. av_free(w);
  479. return ret;
  480. }
  481. double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
  482. {
  483. Parser p = { 0 };
  484. p.const_values = const_values;
  485. p.opaque = opaque;
  486. return eval_expr(&p, e);
  487. }
  488. int av_expr_parse_and_eval(double *d, const char *s,
  489. const char * const *const_names, const double *const_values,
  490. const char * const *func1_names, double (* const *funcs1)(void *, double),
  491. const char * const *func2_names, double (* const *funcs2)(void *, double, double),
  492. void *opaque, int log_offset, void *log_ctx)
  493. {
  494. AVExpr *e = NULL;
  495. int ret = av_expr_parse(&e, s, const_names, func1_names, funcs1, func2_names, funcs2, log_offset, log_ctx);
  496. if (ret < 0) {
  497. *d = NAN;
  498. return ret;
  499. }
  500. *d = av_expr_eval(e, const_values, opaque);
  501. av_expr_free(e);
  502. return isnan(*d) ? AVERROR(EINVAL) : 0;
  503. }
  504. #ifdef TEST
  505. #undef printf
  506. #include <string.h>
  507. static const double const_values[] = {
  508. M_PI,
  509. M_E,
  510. 0
  511. };
  512. static const char *const const_names[] = {
  513. "PI",
  514. "E",
  515. 0
  516. };
  517. int main(int argc, char **argv)
  518. {
  519. int i;
  520. double d;
  521. const char *const *expr;
  522. static const char *const exprs[] = {
  523. "",
  524. "1;2",
  525. "-20",
  526. "-PI",
  527. "+PI",
  528. "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
  529. "80G/80Gi",
  530. "1k",
  531. "1Gi",
  532. "1gi",
  533. "1GiFoo",
  534. "1k+1k",
  535. "1Gi*3foo",
  536. "foo",
  537. "foo(",
  538. "foo()",
  539. "foo)",
  540. "sin",
  541. "sin(",
  542. "sin()",
  543. "sin)",
  544. "sin 10",
  545. "sin(1,2,3)",
  546. "sin(1 )",
  547. "1",
  548. "1foo",
  549. "bar + PI + E + 100f*2 + foo",
  550. "13k + 12f - foo(1, 2)",
  551. "1gi",
  552. "1Gi",
  553. "st(0, 123)",
  554. "st(1, 123); ld(1)",
  555. "lte(0, 1)",
  556. "lte(1, 1)",
  557. "lte(1, 0)",
  558. "lt(0, 1)",
  559. "lt(1, 1)",
  560. "gt(1, 0)",
  561. "gt(2, 7)",
  562. "gte(122, 122)",
  563. /* compute 1+2+...+N */
  564. "st(0, 1); while(lte(ld(0), 100), st(1, ld(1)+ld(0));st(0, ld(0)+1)); ld(1)",
  565. /* compute Fib(N) */
  566. "st(1, 1); st(2, 2); st(0, 1); while(lte(ld(0),10), st(3, ld(1)+ld(2)); st(1, ld(2)); st(2, ld(3)); st(0, ld(0)+1)); ld(3)",
  567. "while(0, 10)",
  568. "st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))",
  569. "isnan(1)",
  570. "isnan(NAN)",
  571. "isnan(INF)",
  572. "isinf(1)",
  573. "isinf(NAN)",
  574. "isinf(INF)",
  575. "floor(NAN)",
  576. "floor(123.123)",
  577. "floor(-123.123)",
  578. "trunc(123.123)",
  579. "trunc(-123.123)",
  580. "ceil(123.123)",
  581. "ceil(-123.123)",
  582. "sqrt(1764)",
  583. "isnan(sqrt(-1))",
  584. "not(1)",
  585. "not(NAN)",
  586. "not(0)",
  587. NULL
  588. };
  589. for (expr = exprs; *expr; expr++) {
  590. printf("Evaluating '%s'\n", *expr);
  591. av_expr_parse_and_eval(&d, *expr,
  592. const_names, const_values,
  593. NULL, NULL, NULL, NULL, NULL, 0, NULL);
  594. if (isnan(d))
  595. printf("'%s' -> nan\n\n", *expr);
  596. else
  597. printf("'%s' -> %f\n\n", *expr, d);
  598. }
  599. av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
  600. const_names, const_values,
  601. NULL, NULL, NULL, NULL, NULL, 0, NULL);
  602. printf("%f == 12.7\n", d);
  603. av_expr_parse_and_eval(&d, "80G/80Gi",
  604. const_names, const_values,
  605. NULL, NULL, NULL, NULL, NULL, 0, NULL);
  606. printf("%f == 0.931322575\n", d);
  607. if (argc > 1 && !strcmp(argv[1], "-t")) {
  608. for (i = 0; i < 1050; i++) {
  609. START_TIMER;
  610. av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
  611. const_names, const_values,
  612. NULL, NULL, NULL, NULL, NULL, 0, NULL);
  613. STOP_TIMER("av_expr_parse_and_eval");
  614. }
  615. }
  616. return 0;
  617. }
  618. #endif