26#include "config_components.h"
40#define COMMAND_FLAG_ENTER 1
41#define COMMAND_FLAG_LEAVE 2
42#define COMMAND_FLAG_EXPR 4
70 static const char *
const flag_strings[] = {
"enter",
"leave",
"expr" };
110#define OFFSET(x) offsetof(SendCmdContext, x)
111#define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_VIDEO_PARAM
120#define SPACES " \f\t\n\r"
126 *buf += strspn(*buf,
SPACES);
133 *buf += strcspn(*buf,
"\n");
139#define COMMAND_DELIMS " \f\t\n\r,;"
154 const char **buf,
void *log_ctx)
158 memset(cmd, 0,
sizeof(
Command));
159 cmd->index = cmd_count;
162 *buf += strspn(*buf,
SPACES);
169 int len = strcspn(*buf,
"|+]");
173 else if (!strncmp(*buf,
"expr", strlen(
"expr"))) cmd->flags |=
COMMAND_FLAG_EXPR;
178 "Unknown flag '%s' in interval #%d, command #%d\n",
179 flag_buf, interval_count, cmd_count);
185 if (!strspn(*buf,
"+|")) {
187 "Invalid flags char '%c' in interval #%d, command #%d\n",
188 **buf, interval_count, cmd_count);
197 "Missing flag terminator or extraneous data found at the end of flags "
198 "in interval #%d, command #%d\n", interval_count, cmd_count);
206 *buf += strspn(*buf,
SPACES);
208 if (!cmd->target || !cmd->target[0]) {
210 "No target specified in interval #%d, command #%d\n",
211 interval_count, cmd_count);
216 *buf += strspn(*buf,
SPACES);
218 if (!cmd->command || !cmd->command[0]) {
220 "No command specified in interval #%d, command #%d\n",
221 interval_count, cmd_count);
226 *buf += strspn(*buf,
SPACES);
237 const char **buf,
void *log_ctx)
249 if ((ret =
parse_command(&cmd, cmd_count, interval_count, buf, log_ctx)) < 0)
259 "Could not (re)allocate command array\n");
265 (*cmds)[(*nb_cmds)++] = cmd;
267 *buf += strspn(*buf,
SPACES);
268 if (**buf && **buf !=
';' && **buf !=
',') {
270 "Missing separator or extraneous data found at the end of "
271 "interval #%d, in command #%d\n",
272 interval_count, cmd_count);
274 "Command was parsed as: flags:[%s] target:%s command:%s arg:%s\n",
287#define DELIMS " \f\t\n\r,;"
290 const char **buf,
void *log_ctx)
295 *buf += strspn(*buf,
SPACES);
300 memset(interval, 0,
sizeof(
Interval));
301 interval->
index = interval_count;
307 if (intervalstr && intervalstr[0]) {
310 start =
av_strtok(intervalstr,
"-", &end);
314 "Invalid interval specification '%s' in interval #%d\n",
315 intervalstr, interval_count);
320 "Invalid start time specification '%s' in interval #%d\n",
321 start, interval_count);
328 "Invalid end time specification '%s' in interval #%d\n",
329 end, interval_count);
333 interval->
end_ts = INT64_MAX;
337 "Invalid end time '%s' in interval #%d: "
338 "cannot be lesser than start time '%s'\n",
339 end, interval_count, start);
345 "No interval specified for interval #%d\n", interval_count);
352 interval_count, buf, log_ctx);
360 const char *buf,
void *log_ctx)
362 int interval_count = 0;
378 if ((ret =
parse_interval(&interval, interval_count, &buf, log_ctx)) < 0)
381 buf += strspn(buf,
SPACES);
385 "Missing terminator or extraneous data found at the end of interval #%d\n",
394 if (*nb_intervals == n) {
399 "Could not (re)allocate intervals array\n");
404 (*intervals)[(*nb_intervals)++] = interval;
422 if ((!!
s->commands_filename + !!
s->commands_str) != 1) {
424 "One and only one of the filename or commands options must be specified\n");
428 if (
s->commands_filename) {
429 uint8_t *file_buf, *buf;
432 &file_buf, &file_bufsize, 0,
ctx);
442 memcpy(buf, file_buf, file_bufsize);
443 buf[file_bufsize] = 0;
445 s->commands_str = buf;
449 s->commands_str,
ctx)) < 0)
452 if (
s->nb_intervals == 0) {
460 for (
i = 0;
i <
s->nb_intervals;
i++) {
468 " [%s] target:%s command:%s arg:%s index:%d\n",
481 for (
i = 0;
i <
s->nb_intervals;
i++) {
505#define WITHIN_INTERVAL(ts, start_ts, end_ts) ((ts) >= (start_ts) && (ts) < (end_ts))
507 for (
i = 0;
i <
s->nb_intervals;
i++) {
525 "[%s] interval #%d start_ts:%f end_ts:%f ts:%f\n",
527 (
double)interval->
start_ts/1000000, (
double)interval->
end_ts/1000000,
532 char *cmd_arg = cmd->
arg;
535 if (cmd->flags &
flags) {
545 var_values[
VAR_TS] = start;
565 "Processing command #%d target:%s command:%s arg:%s\n",
566 cmd->index, cmd->target, cmd->command, cmd_arg);
568 cmd->target, cmd->command, cmd_arg,
572 "Command reply for command #%d: ret:%s res:%s\n",
582 switch (inlink->
type) {
593#if CONFIG_SENDCMD_FILTER
607 .p.priv_class = &sendcmd_class,
617#if CONFIG_ASENDCMD_FILTER
628 .p.name =
"asendcmd",
630 .p.priv_class = &sendcmd_class,
const FFFilter ff_af_asendcmd
const FFFilter ff_vf_sendcmd
static AVFormatContext * ctx
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Main libavfilter public API header.
char * av_asprintf(const char *fmt,...)
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_AUTOMATIC
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
int(* init)(AVBSFContext *ctx)
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.
simple arithmetic expression evaluator
static struct @111144215057303131116103221376075045141373005341 current
#define WITHIN_INTERVAL(ts, start_ts, end_ts)
static int cmp_intervals(const void *a, const void *b)
static void clear_command(Command *cmd)
Clears fields and frees the buffers used by cmd.
static int parse_commands(Command **cmds, int *nb_cmds, int interval_count, const char **buf, void *log_ctx)
#define COMMAND_FLAG_LEAVE
#define COMMAND_FLAG_EXPR
static char * make_command_flags_str(AVBPrint *pbuf, int flags)
#define COMMAND_FLAG_ENTER
static int filter_frame(AVFilterLink *inlink, AVFrame *ref)
static int parse_command(Command *cmd, int cmd_count, int interval_count, const char **buf, void *log_ctx)
static av_cold void uninit(AVFilterContext *ctx)
static void skip_comments(const char **buf)
static int parse_interval(Interval *interval, int interval_count, const char **buf, void *log_ctx)
static int parse_intervals(Interval **intervals, int *nb_intervals, const char *buf, void *log_ctx)
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags)
Send a command to one or more filter instances.
#define AVFILTER_CMD_FLAG_ONE
Stop once a filter understood the command (for target=all for example), fast filters are favored auto...
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
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_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define AVFILTER_DEFINE_CLASS_EXT(name, desc, options)
static FilterLink * ff_filter_link(AVFilterLink *link)
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...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FFDIFFSIGN(x, y)
Comparator.
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)
Describe the class of an AVClass context structure.
AVFilterLink ** outputs
array of pointers to output links
A link between two filters.
enum AVMediaType type
filter media type
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
Link properties exposed to filter code, but not external callers.
int64_t frame_count_in
Number of past frames sent through the link.
struct AVFilterGraph * graph
Graph the filter belongs to.
int index
unique index for these interval commands
int64_t start_ts
start timestamp expressed as microseconds units
int enabled
current time detected inside this interval
int64_t end_ts
end timestamp expressed as microseconds units
#define av_realloc_f(p, o, n)
static int ref[MAX_W *MAX_W]
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.