37 char *
name,
unsigned argc,
char **argv)
39 void *log_ctx = expand_text->
log_ctx;
46 if (argc < functions[
i].argc_min) {
48 name, functions[
i].argc_min);
51 if (argc > functions[
i].argc_max) {
53 name, functions[
i].argc_max);
63 return functions[
i].
func(log_ctx, bp,
name, argc, argv);
85 void *log_ctx = expand_text->
log_ctx;
86 const char *text = *rtext;
87 char *argv[16] = {
NULL };
119 for (
i = 0;
i < argc;
i++)
133 if (*text ==
'\\' && text[1]) {
136 }
else if (*text ==
'%') {
151 const char *fmt,
const char *strftime_fmt)
164 if (!strcmp(fmt,
"flt")) {
166 }
else if (!strcmp(fmt,
"hms") ||
167 !strcmp(fmt,
"hms24hh")) {
177 if (!strcmp(fmt,
"hms24hh")) {
179 ms %= 24 * 60 * 60 * 1000;
182 (
int)(ms / (60 * 60 * 1000)),
183 (
int)(ms / (60 * 1000)) % 60,
184 (
int)(ms / 1000) % 60,
187 }
else if (!strcmp(fmt,
"localtime") ||
188 !strcmp(fmt,
"gmtime")) {
190 time_t ms = (time_t)
pts;
191 if (!strcmp(fmt,
"localtime"))
204 const char *strftime_fmt,
char localtime)
206 const char *fmt =
av_x_if_null(strftime_fmt,
"%Y-%m-%d %H:%M:%S");
207 const char *fmt_begin = fmt;
220 now = unow / 1000000;
228 while ((begin = strchr(begin,
'%'))) {
250 num_digits =
av_clip(*(begin + 1) -
'0', 1, 6);
251 }
else if (
len > 1) {
252 av_log(log_ctx,
AV_LOG_WARNING,
"Invalid number of decimals for %%N, using default of %i\n", num_digits);
257 div = pow(10, 6 - num_digits);
259 av_bprintf(&fmt_bp,
"%.*s%0*d", (
int)(begin - fmt_begin), fmt_begin, num_digits, (
int)(unow % 1000000) / div);
284 const char *
const *fun_names,
const ff_eval_func2 *fun_values,
285 const char *
const *
var_names,
const double *var_values,
293 eval_ctx, 0, log_ctx);
296 "Text expansion expression '%s' is not valid\n",
306 const char *
const *fun_names,
const ff_eval_func2 *fun_values,
307 const char *
const *
var_names,
const double *var_values,
314 char fmt_str[30] =
"%";
318 eval_ctx, 0, log_ctx);
321 "Text expansion expression '%s' is not valid\n",
326 if (!strchr(
"xXdu",
format)) {
328 " allowed values: 'x', 'X', 'd', 'u'\n",
format);
332 feclearexcept(FE_ALL_EXCEPT);
334#if defined(FE_INVALID) && defined(FE_OVERFLOW) && defined(FE_UNDERFLOW)
335 if ((ret = fetestexcept(FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW))) {
336 av_log(log_ctx,
AV_LOG_ERROR,
"Conversion of floating-point result to int failed. Control register: 0x%08x. Conversion result: %d\n", ret, intval);
355 unsigned char **text,
size_t *text_size)
362 if ((err =
av_file_map(textfile, &textbuf, &textbuf_size, 0, log_ctx)) < 0) {
364 "The text file '%s' could not be read or is empty\n",
369 if (textbuf_size > 0 && ff_is_newline(textbuf[textbuf_size - 1]))
371 if (textbuf_size > SIZE_MAX - 1 || !(
tmp =
av_realloc(*text, textbuf_size + 1))) {
376 memcpy(*text, textbuf, textbuf_size);
377 (*text)[textbuf_size] = 0;
379 *text_size = textbuf_size;
static const char *const format[]
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Convenience header that includes libavutil's core.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_UNLIMITED
#define i(width, name, range_min, range_max)
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_strftime(AVBPrint *buf, const char *fmt, const struct tm *tm)
Append a formatted date and time to a print buffer.
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
static av_const int av_isdigit(int c)
Locale-independent conversion of ASCII isdigit.
char * av_get_token(const char **buf, const char *term)
Unescape the given string until a non escaped terminating char, and return the token corresponding to...
#define AV_TIME_BASE
Internal time base represented as integer.
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, int log_offset, void *log_ctx)
Read the file with name filename, and put its content in a newly allocated buffer or map it with mmap...
Memory handling functions.
static const char *const var_names[]
int av_parse_time(int64_t *timeval, const char *timestr, int duration)
Parse timestr and return in *time a corresponding number of microseconds.
#define FF_ARRAY_ELEMS(a)
Text expander context, used to encapsulate the logic to expand a given text template.
unsigned int functions_nb
number of functions
void * log_ctx
log context to pass to the function, used for logging and for accessing the context for the function
const FFExpandTextFunction * functions
list of functions to use to expand sequences in the format FUNCTION_NAME{PARAMS}
Function used to expand a template sequence in the format %{FUNCTION_NAME[:PARAMS]}...
int(* func)(void *ctx, AVBPrint *bp, const char *function_name, unsigned argc, char **args)
actual function used to perform the expansion
int ff_print_pts(void *log_ctx, AVBPrint *bp, double pts, const char *delta, const char *fmt, const char *strftime_fmt)
int ff_load_textfile(void *log_ctx, const char *textfile, unsigned char **text, size_t *text_size)
int ff_expand_text(FFExpandTextContext *expand_text, const char *text, AVBPrint *bp)
Expand text template.
int ff_print_time(void *log_ctx, AVBPrint *bp, const char *strftime_fmt, char localtime)
static int ff_expand_text_function(FFExpandTextContext *expand_text, AVBPrint *bp, const char **rtext)
Expand text template pointed to by *rtext.
int ff_print_formatted_eval_expr(void *log_ctx, AVBPrint *bp, const char *expr, const char *const *fun_names, const ff_eval_func2 *fun_values, const char *const *var_names, const double *var_values, void *eval_ctx, const char format, int positions)
int ff_print_eval_expr(void *log_ctx, AVBPrint *bp, const char *expr, const char *const *fun_names, const ff_eval_func2 *fun_values, const char *const *var_names, const double *var_values, void *eval_ctx)
static int ff_expand_text_function_internal(FFExpandTextContext *expand_text, AVBPrint *bp, char *name, unsigned argc, char **argv)
int64_t av_gettime(void)
Get the current time in microseconds.
static const uint16_t positions[][14][3]