Path: blob/master/dep/ffmpeg/include/libavutil/eval.h
4216 views
/*1* Copyright (c) 2002 Michael Niedermayer <[email protected]>2*3* This file is part of FFmpeg.4*5* FFmpeg is free software; you can redistribute it and/or6* modify it under the terms of the GNU Lesser General Public7* License as published by the Free Software Foundation; either8* version 2.1 of the License, or (at your option) any later version.9*10* FFmpeg is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU13* Lesser General Public License for more details.14*15* You should have received a copy of the GNU Lesser General Public16* License along with FFmpeg; if not, write to the Free Software17* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA18*/1920/**21* @file22* simple arithmetic expression evaluator23*/2425#ifndef AVUTIL_EVAL_H26#define AVUTIL_EVAL_H2728typedef struct AVExpr AVExpr;2930/**31* Parse and evaluate an expression.32* Note, this is significantly slower than av_expr_eval().33*34* @param res a pointer to a double where is put the result value of35* the expression, or NAN in case of error36* @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)"37* @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}38* @param const_values a zero terminated array of values for the identifiers from const_names39* @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers40* @param funcs1 NULL terminated array of function pointers for functions which take 1 argument41* @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers42* @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments43* @param opaque a pointer which will be passed to all functions from funcs1 and funcs244* @param log_offset log level offset, can be used to silence error messages45* @param log_ctx parent logging context46* @return >= 0 in case of success, a negative value corresponding to an47* AVERROR code otherwise48*/49int av_expr_parse_and_eval(double *res, const char *s,50const char * const *const_names, const double *const_values,51const char * const *func1_names, double (* const *funcs1)(void *, double),52const char * const *func2_names, double (* const *funcs2)(void *, double, double),53void *opaque, int log_offset, void *log_ctx);5455/**56* Parse an expression.57*58* @param expr a pointer where is put an AVExpr containing the parsed59* value in case of successful parsing, or NULL otherwise.60* The pointed to AVExpr must be freed with av_expr_free() by the user61* when it is not needed anymore.62* @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)"63* @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}64* @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers65* @param funcs1 NULL terminated array of function pointers for functions which take 1 argument66* @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers67* @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments68* @param log_offset log level offset, can be used to silence error messages69* @param log_ctx parent logging context70* @return >= 0 in case of success, a negative value corresponding to an71* AVERROR code otherwise72*/73int av_expr_parse(AVExpr **expr, const char *s,74const char * const *const_names,75const char * const *func1_names, double (* const *funcs1)(void *, double),76const char * const *func2_names, double (* const *funcs2)(void *, double, double),77int log_offset, void *log_ctx);7879/**80* Evaluate a previously parsed expression.81*82* @param e the AVExpr to evaluate83* @param const_values a zero terminated array of values for the identifiers from av_expr_parse() const_names84* @param opaque a pointer which will be passed to all functions from funcs1 and funcs285* @return the value of the expression86*/87double av_expr_eval(AVExpr *e, const double *const_values, void *opaque);8889/**90* Track the presence of variables and their number of occurrences in a parsed expression91*92* @param e the AVExpr to track variables in93* @param counter a zero-initialized array where the count of each variable will be stored94* @param size size of array95* @return 0 on success, a negative value indicates that no expression or array was passed96* or size was zero97*/98int av_expr_count_vars(AVExpr *e, unsigned *counter, int size);99100/**101* Track the presence of user provided functions and their number of occurrences102* in a parsed expression.103*104* @param e the AVExpr to track user provided functions in105* @param counter a zero-initialized array where the count of each function will be stored106* if you passed 5 functions with 2 arguments to av_expr_parse()107* then for arg=2 this will use up to 5 entries.108* @param size size of array109* @param arg number of arguments the counted functions have110* @return 0 on success, a negative value indicates that no expression or array was passed111* or size was zero112*/113int av_expr_count_func(AVExpr *e, unsigned *counter, int size, int arg);114115/**116* Free a parsed expression previously created with av_expr_parse().117*/118void av_expr_free(AVExpr *e);119120/**121* Parse the string in numstr and return its value as a double. If122* the string is empty, contains only whitespaces, or does not contain123* an initial substring that has the expected syntax for a124* floating-point number, no conversion is performed. In this case,125* returns a value of zero and the value returned in tail is the value126* of numstr.127*128* @param numstr a string representing a number, may contain one of129* the International System number postfixes, for example 'K', 'M',130* 'G'. If 'i' is appended after the postfix, powers of 2 are used131* instead of powers of 10. The 'B' postfix multiplies the value by132* 8, and can be appended after another postfix or used alone. This133* allows using for example 'KB', 'MiB', 'G' and 'B' as postfix.134* @param tail if non-NULL puts here the pointer to the char next135* after the last parsed character136*/137double av_strtod(const char *numstr, char **tail);138139#endif /* AVUTIL_EVAL_H */140141142