Statistics
| Branch: | Revision:

ffmpeg / libavutil / eval.h @ 5d6e4c16

History | View | Annotate | Download (6.43 KB)

1 b2f86c17 Panagiotis Issaris
/*
2
 * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
3
 *
4 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
5
 *
6
 * FFmpeg is free software; you can redistribute it and/or
7 b2f86c17 Panagiotis Issaris
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
10 b2f86c17 Panagiotis Issaris
 *
11 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
12 b2f86c17 Panagiotis Issaris
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
18 b2f86c17 Panagiotis Issaris
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20
21
/**
22 ba87f080 Diego Biurrun
 * @file
23 8c216473 Stefano Sabatini
 * simple arithmetic expression evaluator
24 b2f86c17 Panagiotis Issaris
 */
25
26 0b99215c Stefano Sabatini
#ifndef AVUTIL_EVAL_H
27
#define AVUTIL_EVAL_H
28 b2f86c17 Panagiotis Issaris
29 d2af7205 Stefano Sabatini
#include "avutil.h"
30
31 a3731cad Stefano Sabatini
typedef struct AVExpr AVExpr;
32 5fccafdb Stefano Sabatini
33 21d4d5da Michael Niedermayer
/**
34 49bd8e4b Måns Rullgård
 * Parse and evaluate an expression.
35 d2af7205 Stefano Sabatini
 * Note, this is significantly slower than av_expr_eval().
36 f54978f1 Stefano Sabatini
 *
37 9ace13b4 Stefano Sabatini
 * @param res a pointer to a double where is put the result value of
38
 * the expression, or NAN in case of error
39 94f49823 Stefano Sabatini
 * @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)"
40
 * @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}
41
 * @param const_values a zero terminated array of values for the identifiers from const_names
42
 * @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers
43 9711439b Stefano Sabatini
 * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument
44 94f49823 Stefano Sabatini
 * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers
45 9711439b Stefano Sabatini
 * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments
46
 * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2
47 2b65bb45 Michael Niedermayer
 * @param log_ctx parent logging context
48 9ace13b4 Stefano Sabatini
 * @return 0 in case of success, a negative value corresponding to an
49
 * AVERROR code otherwise
50 21d4d5da Michael Niedermayer
 */
51 d2af7205 Stefano Sabatini
int av_expr_parse_and_eval(double *res, const char *s,
52 9711439b Stefano Sabatini
                           const char * const *const_names, const double *const_values,
53
                           const char * const *func1_names, double (* const *funcs1)(void *, double),
54
                           const char * const *func2_names, double (* const *funcs2)(void *, double, double),
55 b851dd9e Stefano Sabatini
                           void *opaque, int log_offset, void *log_ctx);
56 b2f86c17 Panagiotis Issaris
57 21d4d5da Michael Niedermayer
/**
58 49bd8e4b Måns Rullgård
 * Parse an expression.
59 f54978f1 Stefano Sabatini
 *
60 9ace13b4 Stefano Sabatini
 * @param expr a pointer where is put an AVExpr containing the parsed
61
 * value in case of successfull parsing, or NULL otherwise.
62 d2af7205 Stefano Sabatini
 * The pointed to AVExpr must be freed with av_expr_free() by the user
63 9ace13b4 Stefano Sabatini
 * when it is not needed anymore.
64 94f49823 Stefano Sabatini
 * @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)"
65
 * @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}
66
 * @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers
67 9711439b Stefano Sabatini
 * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument
68 94f49823 Stefano Sabatini
 * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers
69 9711439b Stefano Sabatini
 * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments
70 2b65bb45 Michael Niedermayer
 * @param log_ctx parent logging context
71 9ace13b4 Stefano Sabatini
 * @return 0 in case of success, a negative value corresponding to an
72
 * AVERROR code otherwise
73 21d4d5da Michael Niedermayer
 */
74 d2af7205 Stefano Sabatini
int av_expr_parse(AVExpr **expr, const char *s,
75 9711439b Stefano Sabatini
                  const char * const *const_names,
76
                  const char * const *func1_names, double (* const *funcs1)(void *, double),
77
                  const char * const *func2_names, double (* const *funcs2)(void *, double, double),
78 b851dd9e Stefano Sabatini
                  int log_offset, void *log_ctx);
79 f54978f1 Stefano Sabatini
80 21d4d5da Michael Niedermayer
/**
81 49bd8e4b Måns Rullgård
 * Evaluate a previously parsed expression.
82 f54978f1 Stefano Sabatini
 *
83 d2af7205 Stefano Sabatini
 * @param const_values a zero terminated array of values for the identifiers from av_expr_parse() const_names
84 9711439b Stefano Sabatini
 * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2
85 21d4d5da Michael Niedermayer
 * @return the value of the expression
86
 */
87 d2af7205 Stefano Sabatini
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque);
88
89
/**
90
 * Free a parsed expression previously created with av_expr_parse().
91
 */
92
void av_expr_free(AVExpr *e);
93
94
#if FF_API_OLD_EVAL_NAMES
95
/**
96
 * @deprecated Deprecated in favor of av_expr_parse_and_eval().
97
 */
98
attribute_deprecated
99
int av_parse_and_eval_expr(double *res, const char *s,
100
                           const char * const *const_names, const double *const_values,
101
                           const char * const *func1_names, double (* const *funcs1)(void *, double),
102
                           const char * const *func2_names, double (* const *funcs2)(void *, double, double),
103
                           void *opaque, int log_offset, void *log_ctx);
104
105
/**
106
 * @deprecated Deprecated in favor of av_expr_parse().
107
 */
108
attribute_deprecated
109
int av_parse_expr(AVExpr **expr, const char *s,
110
                  const char * const *const_names,
111
                  const char * const *func1_names, double (* const *funcs1)(void *, double),
112
                  const char * const *func2_names, double (* const *funcs2)(void *, double, double),
113
                  int log_offset, void *log_ctx);
114
/**
115
 * @deprecated Deprecated in favor of av_expr_eval().
116
 */
117
attribute_deprecated
118 0b99215c Stefano Sabatini
double av_eval_expr(AVExpr *e, const double *const_values, void *opaque);
119 f8fea468 Stefano Sabatini
120 80ed7014 Stefano Sabatini
/**
121 d2af7205 Stefano Sabatini
 * @deprecated Deprecated in favor of av_expr_free().
122 80ed7014 Stefano Sabatini
 */
123 d2af7205 Stefano Sabatini
attribute_deprecated
124 0b99215c Stefano Sabatini
void av_free_expr(AVExpr *e);
125 d2af7205 Stefano Sabatini
#endif /* FF_API_OLD_EVAL_NAMES */
126 85b4eb08 Oded Shimon
127 d171a651 Stefano Sabatini
/**
128 49bd8e4b Måns Rullgård
 * Parse the string in numstr and return its value as a double. If
129 d171a651 Stefano Sabatini
 * the string is empty, contains only whitespaces, or does not contain
130
 * an initial substring that has the expected syntax for a
131
 * floating-point number, no conversion is performed. In this case,
132
 * returns a value of zero and the value returned in tail is the value
133
 * of numstr.
134
 *
135
 * @param numstr a string representing a number, may contain one of
136
 * the International System number postfixes, for example 'K', 'M',
137
 * 'G'. If 'i' is appended after the postfix, powers of 2 are used
138
 * instead of powers of 10. The 'B' postfix multiplies the value for
139
 * 8, and can be appended after another postfix or used alone. This
140
 * allows using for example 'KB', 'MiB', 'G' and 'B' as postfix.
141
 * @param tail if non-NULL puts here the pointer to the char next
142
 * after the last parsed character
143 1c2744d1 Stefano Sabatini
 */
144
double av_strtod(const char *numstr, char **tail);
145
146 0b99215c Stefano Sabatini
#endif /* AVUTIL_EVAL_H */