FFmpeg  4.4.4
f_sendcmd.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Stefano Sabatini
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * 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  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * send commands filter
24  */
25 
26 #include "libavutil/avstring.h"
27 #include "libavutil/bprint.h"
28 #include "libavutil/eval.h"
29 #include "libavutil/file.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/parseutils.h"
32 #include "avfilter.h"
33 #include "internal.h"
34 #include "audio.h"
35 #include "video.h"
36 
37 #define COMMAND_FLAG_ENTER 1
38 #define COMMAND_FLAG_LEAVE 2
39 #define COMMAND_FLAG_EXPR 4
40 
41 static const char *const var_names[] = {
42  "N", /* frame number */
43  "T", /* frame time in seconds */
44  "POS", /* original position in the file of the frame */
45  "PTS", /* frame pts */
46  "TS", /* interval start time in seconds */
47  "TE", /* interval end time in seconds */
48  "TI", /* interval interpolated value: TI = (T - TS) / (TE - TS) */
49  NULL
50 };
51 
52 enum var_name {
61 };
62 
63 static inline char *make_command_flags_str(AVBPrint *pbuf, int flags)
64 {
65  static const char * const flag_strings[] = { "enter", "leave", "expr" };
66  int i, is_first = 1;
67 
69  for (i = 0; i < FF_ARRAY_ELEMS(flag_strings); i++) {
70  if (flags & 1<<i) {
71  if (!is_first)
72  av_bprint_chars(pbuf, '+', 1);
73  av_bprintf(pbuf, "%s", flag_strings[i]);
74  is_first = 0;
75  }
76  }
77 
78  return pbuf->str;
79 }
80 
81 typedef struct Command {
82  int flags;
83  char *target, *command, *arg;
84  int index;
85 } Command;
86 
87 typedef struct Interval {
88  int64_t start_ts; ///< start timestamp expressed as microseconds units
89  int64_t end_ts; ///< end timestamp expressed as microseconds units
90  int index; ///< unique index for these interval commands
93  int enabled; ///< current time detected inside this interval
94 } Interval;
95 
96 typedef struct SendCmdContext {
97  const AVClass *class;
100 
104 
105 #define OFFSET(x) offsetof(SendCmdContext, x)
106 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_VIDEO_PARAM
107 static const AVOption options[] = {
108  { "commands", "set commands", OFFSET(commands_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
109  { "c", "set commands", OFFSET(commands_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
110  { "filename", "set commands file", OFFSET(commands_filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
111  { "f", "set commands file", OFFSET(commands_filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
112  { NULL }
113 };
114 
115 #define SPACES " \f\t\n\r"
116 
117 static void skip_comments(const char **buf)
118 {
119  while (**buf) {
120  /* skip leading spaces */
121  *buf += strspn(*buf, SPACES);
122  if (**buf != '#')
123  break;
124 
125  (*buf)++;
126 
127  /* skip comment until the end of line */
128  *buf += strcspn(*buf, "\n");
129  if (**buf)
130  (*buf)++;
131  }
132 }
133 
134 #define COMMAND_DELIMS " \f\t\n\r,;"
135 
136 static int parse_command(Command *cmd, int cmd_count, int interval_count,
137  const char **buf, void *log_ctx)
138 {
139  int ret;
140 
141  memset(cmd, 0, sizeof(Command));
142  cmd->index = cmd_count;
143 
144  /* format: [FLAGS] target command arg */
145  *buf += strspn(*buf, SPACES);
146 
147  /* parse flags */
148  if (**buf == '[') {
149  (*buf)++; /* skip "[" */
150 
151  while (**buf) {
152  int len = strcspn(*buf, "|+]");
153 
154  if (!strncmp(*buf, "enter", strlen("enter"))) cmd->flags |= COMMAND_FLAG_ENTER;
155  else if (!strncmp(*buf, "leave", strlen("leave"))) cmd->flags |= COMMAND_FLAG_LEAVE;
156  else if (!strncmp(*buf, "expr", strlen("expr"))) cmd->flags |= COMMAND_FLAG_EXPR;
157  else {
158  char flag_buf[64];
159  av_strlcpy(flag_buf, *buf, sizeof(flag_buf));
160  av_log(log_ctx, AV_LOG_ERROR,
161  "Unknown flag '%s' in interval #%d, command #%d\n",
162  flag_buf, interval_count, cmd_count);
163  return AVERROR(EINVAL);
164  }
165  *buf += len;
166  if (**buf == ']')
167  break;
168  if (!strspn(*buf, "+|")) {
169  av_log(log_ctx, AV_LOG_ERROR,
170  "Invalid flags char '%c' in interval #%d, command #%d\n",
171  **buf, interval_count, cmd_count);
172  return AVERROR(EINVAL);
173  }
174  if (**buf)
175  (*buf)++;
176  }
177 
178  if (**buf != ']') {
179  av_log(log_ctx, AV_LOG_ERROR,
180  "Missing flag terminator or extraneous data found at the end of flags "
181  "in interval #%d, command #%d\n", interval_count, cmd_count);
182  return AVERROR(EINVAL);
183  }
184  (*buf)++; /* skip "]" */
185  } else {
186  cmd->flags = COMMAND_FLAG_ENTER;
187  }
188 
189  *buf += strspn(*buf, SPACES);
190  cmd->target = av_get_token(buf, COMMAND_DELIMS);
191  if (!cmd->target || !cmd->target[0]) {
192  av_log(log_ctx, AV_LOG_ERROR,
193  "No target specified in interval #%d, command #%d\n",
194  interval_count, cmd_count);
195  ret = AVERROR(EINVAL);
196  goto fail;
197  }
198 
199  *buf += strspn(*buf, SPACES);
200  cmd->command = av_get_token(buf, COMMAND_DELIMS);
201  if (!cmd->command || !cmd->command[0]) {
202  av_log(log_ctx, AV_LOG_ERROR,
203  "No command specified in interval #%d, command #%d\n",
204  interval_count, cmd_count);
205  ret = AVERROR(EINVAL);
206  goto fail;
207  }
208 
209  *buf += strspn(*buf, SPACES);
210  cmd->arg = av_get_token(buf, COMMAND_DELIMS);
211 
212  return 1;
213 
214 fail:
215  av_freep(&cmd->target);
216  av_freep(&cmd->command);
217  av_freep(&cmd->arg);
218  return ret;
219 }
220 
221 static int parse_commands(Command **cmds, int *nb_cmds, int interval_count,
222  const char **buf, void *log_ctx)
223 {
224  int cmd_count = 0;
225  int ret, n = 0;
226  AVBPrint pbuf;
227 
228  *cmds = NULL;
229  *nb_cmds = 0;
230 
231  while (**buf) {
232  Command cmd;
233 
234  if ((ret = parse_command(&cmd, cmd_count, interval_count, buf, log_ctx)) < 0)
235  return ret;
236  cmd_count++;
237 
238  /* (re)allocate commands array if required */
239  if (*nb_cmds == n) {
240  n = FFMAX(16, 2*n); /* first allocation = 16, or double the number */
241  *cmds = av_realloc_f(*cmds, n, 2*sizeof(Command));
242  if (!*cmds) {
243  av_log(log_ctx, AV_LOG_ERROR,
244  "Could not (re)allocate command array\n");
245  return AVERROR(ENOMEM);
246  }
247  }
248 
249  (*cmds)[(*nb_cmds)++] = cmd;
250 
251  *buf += strspn(*buf, SPACES);
252  if (**buf && **buf != ';' && **buf != ',') {
253  av_log(log_ctx, AV_LOG_ERROR,
254  "Missing separator or extraneous data found at the end of "
255  "interval #%d, in command #%d\n",
256  interval_count, cmd_count);
257  av_log(log_ctx, AV_LOG_ERROR,
258  "Command was parsed as: flags:[%s] target:%s command:%s arg:%s\n",
259  make_command_flags_str(&pbuf, cmd.flags), cmd.target, cmd.command, cmd.arg);
260  return AVERROR(EINVAL);
261  }
262  if (**buf == ';')
263  break;
264  if (**buf == ',')
265  (*buf)++;
266  }
267 
268  return 0;
269 }
270 
271 #define DELIMS " \f\t\n\r,;"
272 
273 static int parse_interval(Interval *interval, int interval_count,
274  const char **buf, void *log_ctx)
275 {
276  char *intervalstr;
277  int ret;
278 
279  *buf += strspn(*buf, SPACES);
280  if (!**buf)
281  return 0;
282 
283  /* reset data */
284  memset(interval, 0, sizeof(Interval));
285  interval->index = interval_count;
286 
287  /* format: INTERVAL COMMANDS */
288 
289  /* parse interval */
290  intervalstr = av_get_token(buf, DELIMS);
291  if (intervalstr && intervalstr[0]) {
292  char *start, *end;
293 
294  start = av_strtok(intervalstr, "-", &end);
295  if (!start) {
296  ret = AVERROR(EINVAL);
297  av_log(log_ctx, AV_LOG_ERROR,
298  "Invalid interval specification '%s' in interval #%d\n",
299  intervalstr, interval_count);
300  goto end;
301  }
302  if ((ret = av_parse_time(&interval->start_ts, start, 1)) < 0) {
303  av_log(log_ctx, AV_LOG_ERROR,
304  "Invalid start time specification '%s' in interval #%d\n",
305  start, interval_count);
306  goto end;
307  }
308 
309  if (end) {
310  if ((ret = av_parse_time(&interval->end_ts, end, 1)) < 0) {
311  av_log(log_ctx, AV_LOG_ERROR,
312  "Invalid end time specification '%s' in interval #%d\n",
313  end, interval_count);
314  goto end;
315  }
316  } else {
317  interval->end_ts = INT64_MAX;
318  }
319  if (interval->end_ts < interval->start_ts) {
320  av_log(log_ctx, AV_LOG_ERROR,
321  "Invalid end time '%s' in interval #%d: "
322  "cannot be lesser than start time '%s'\n",
323  end, interval_count, start);
324  ret = AVERROR(EINVAL);
325  goto end;
326  }
327  } else {
328  av_log(log_ctx, AV_LOG_ERROR,
329  "No interval specified for interval #%d\n", interval_count);
330  ret = AVERROR(EINVAL);
331  goto end;
332  }
333 
334  /* parse commands */
335  ret = parse_commands(&interval->commands, &interval->nb_commands,
336  interval_count, buf, log_ctx);
337 
338 end:
339  av_free(intervalstr);
340  return ret;
341 }
342 
343 static int parse_intervals(Interval **intervals, int *nb_intervals,
344  const char *buf, void *log_ctx)
345 {
346  int interval_count = 0;
347  int ret, n = 0;
348 
349  *intervals = NULL;
350  *nb_intervals = 0;
351 
352  if (!buf)
353  return 0;
354 
355  while (1) {
356  Interval interval;
357 
358  skip_comments(&buf);
359  if (!(*buf))
360  break;
361 
362  if ((ret = parse_interval(&interval, interval_count, &buf, log_ctx)) < 0)
363  return ret;
364 
365  buf += strspn(buf, SPACES);
366  if (*buf) {
367  if (*buf != ';') {
368  av_log(log_ctx, AV_LOG_ERROR,
369  "Missing terminator or extraneous data found at the end of interval #%d\n",
370  interval_count);
371  return AVERROR(EINVAL);
372  }
373  buf++; /* skip ';' */
374  }
375  interval_count++;
376 
377  /* (re)allocate commands array if required */
378  if (*nb_intervals == n) {
379  n = FFMAX(16, 2*n); /* first allocation = 16, or double the number */
380  *intervals = av_realloc_f(*intervals, n, 2*sizeof(Interval));
381  if (!*intervals) {
382  av_log(log_ctx, AV_LOG_ERROR,
383  "Could not (re)allocate intervals array\n");
384  return AVERROR(ENOMEM);
385  }
386  }
387 
388  (*intervals)[(*nb_intervals)++] = interval;
389  }
390 
391  return 0;
392 }
393 
394 static int cmp_intervals(const void *a, const void *b)
395 {
396  const Interval *i1 = a;
397  const Interval *i2 = b;
398  return 2 * FFDIFFSIGN(i1->start_ts, i2->start_ts) + FFDIFFSIGN(i1->index, i2->index);
399 }
400 
402 {
403  SendCmdContext *s = ctx->priv;
404  int ret, i, j;
405 
406  if ((!!s->commands_filename + !!s->commands_str) != 1) {
408  "One and only one of the filename or commands options must be specified\n");
409  return AVERROR(EINVAL);
410  }
411 
412  if (s->commands_filename) {
413  uint8_t *file_buf, *buf;
414  size_t file_bufsize;
415  ret = av_file_map(s->commands_filename,
416  &file_buf, &file_bufsize, 0, ctx);
417  if (ret < 0)
418  return ret;
419 
420  /* create a 0-terminated string based on the read file */
421  buf = av_malloc(file_bufsize + 1);
422  if (!buf) {
423  av_file_unmap(file_buf, file_bufsize);
424  return AVERROR(ENOMEM);
425  }
426  memcpy(buf, file_buf, file_bufsize);
427  buf[file_bufsize] = 0;
428  av_file_unmap(file_buf, file_bufsize);
429  s->commands_str = buf;
430  }
431 
432  if ((ret = parse_intervals(&s->intervals, &s->nb_intervals,
433  s->commands_str, ctx)) < 0)
434  return ret;
435 
436  if (s->nb_intervals == 0) {
437  av_log(ctx, AV_LOG_ERROR, "No commands were specified\n");
438  return AVERROR(EINVAL);
439  }
440 
441  qsort(s->intervals, s->nb_intervals, sizeof(Interval), cmp_intervals);
442 
443  av_log(ctx, AV_LOG_DEBUG, "Parsed commands:\n");
444  for (i = 0; i < s->nb_intervals; i++) {
445  AVBPrint pbuf;
446  Interval *interval = &s->intervals[i];
447  av_log(ctx, AV_LOG_VERBOSE, "start_time:%f end_time:%f index:%d\n",
448  (double)interval->start_ts/1000000, (double)interval->end_ts/1000000, interval->index);
449  for (j = 0; j < interval->nb_commands; j++) {
450  Command *cmd = &interval->commands[j];
452  " [%s] target:%s command:%s arg:%s index:%d\n",
453  make_command_flags_str(&pbuf, cmd->flags), cmd->target, cmd->command, cmd->arg, cmd->index);
454  }
455  }
456 
457  return 0;
458 }
459 
461 {
462  SendCmdContext *s = ctx->priv;
463  int i, j;
464 
465  for (i = 0; i < s->nb_intervals; i++) {
466  Interval *interval = &s->intervals[i];
467  for (j = 0; j < interval->nb_commands; j++) {
468  Command *cmd = &interval->commands[j];
469  av_freep(&cmd->target);
470  av_freep(&cmd->command);
471  av_freep(&cmd->arg);
472  }
473  av_freep(&interval->commands);
474  }
475  av_freep(&s->intervals);
476 }
477 
478 static int filter_frame(AVFilterLink *inlink, AVFrame *ref)
479 {
480  AVFilterContext *ctx = inlink->dst;
481  SendCmdContext *s = ctx->priv;
482  int64_t ts;
483  int i, j, ret;
484 
485  if (ref->pts == AV_NOPTS_VALUE)
486  goto end;
487 
488  ts = av_rescale_q(ref->pts, inlink->time_base, AV_TIME_BASE_Q);
489 
490 #define WITHIN_INTERVAL(ts, start_ts, end_ts) ((ts) >= (start_ts) && (ts) < (end_ts))
491 
492  for (i = 0; i < s->nb_intervals; i++) {
493  Interval *interval = &s->intervals[i];
494  int flags = 0;
495 
496  if (!interval->enabled && WITHIN_INTERVAL(ts, interval->start_ts, interval->end_ts)) {
498  interval->enabled = 1;
499  }
500  if (interval->enabled && !WITHIN_INTERVAL(ts, interval->start_ts, interval->end_ts)) {
502  interval->enabled = 0;
503  }
504  if (interval->enabled)
506 
507  if (flags) {
508  AVBPrint pbuf;
510  "[%s] interval #%d start_ts:%f end_ts:%f ts:%f\n",
511  make_command_flags_str(&pbuf, flags), interval->index,
512  (double)interval->start_ts/1000000, (double)interval->end_ts/1000000,
513  (double)ts/1000000);
514 
515  for (j = 0; flags && j < interval->nb_commands; j++) {
516  Command *cmd = &interval->commands[j];
517  char *cmd_arg = cmd->arg;
518  char buf[1024];
519 
520  if (cmd->flags & flags) {
521  if (cmd->flags & COMMAND_FLAG_EXPR) {
522  double var_values[VAR_VARS_NB], res;
523  double start = TS2T(interval->start_ts, AV_TIME_BASE_Q);
524  double end = TS2T(interval->end_ts, AV_TIME_BASE_Q);
525  double current = TS2T(ref->pts, inlink->time_base);
526 
527  var_values[VAR_N] = inlink->frame_count_in;
528  var_values[VAR_POS] = ref->pkt_pos == -1 ? NAN : ref->pkt_pos;
529  var_values[VAR_PTS] = TS2D(ref->pts);
530  var_values[VAR_T] = current;
531  var_values[VAR_TS] = start;
532  var_values[VAR_TE] = end;
533  var_values[VAR_TI] = (current - start) / (end - start);
534 
535  if ((ret = av_expr_parse_and_eval(&res, cmd->arg, var_names, var_values,
536  NULL, NULL, NULL, NULL, NULL, 0, NULL)) < 0) {
537  av_log(ctx, AV_LOG_ERROR, "Invalid expression '%s' for command argument.\n", cmd->arg);
538  av_frame_free(&ref);
539  return AVERROR(EINVAL);
540  }
541 
542  cmd_arg = av_asprintf("%g", res);
543  if (!cmd_arg) {
544  av_frame_free(&ref);
545  return AVERROR(ENOMEM);
546  }
547  }
549  "Processing command #%d target:%s command:%s arg:%s\n",
550  cmd->index, cmd->target, cmd->command, cmd_arg);
551  ret = avfilter_graph_send_command(inlink->graph,
552  cmd->target, cmd->command, cmd_arg,
553  buf, sizeof(buf),
556  "Command reply for command #%d: ret:%s res:%s\n",
557  cmd->index, av_err2str(ret), buf);
558  if (cmd->flags & COMMAND_FLAG_EXPR)
559  av_freep(&cmd_arg);
560  }
561  }
562  }
563  }
564 
565 end:
566  switch (inlink->type) {
567  case AVMEDIA_TYPE_VIDEO:
568  case AVMEDIA_TYPE_AUDIO:
569  return ff_filter_frame(inlink->dst->outputs[0], ref);
570  }
571 
572  return AVERROR(ENOSYS);
573 }
574 
575 #if CONFIG_SENDCMD_FILTER
576 
577 #define sendcmd_options options
578 AVFILTER_DEFINE_CLASS(sendcmd);
579 
580 static const AVFilterPad sendcmd_inputs[] = {
581  {
582  .name = "default",
583  .type = AVMEDIA_TYPE_VIDEO,
584  .filter_frame = filter_frame,
585  },
586  { NULL }
587 };
588 
589 static const AVFilterPad sendcmd_outputs[] = {
590  {
591  .name = "default",
592  .type = AVMEDIA_TYPE_VIDEO,
593  },
594  { NULL }
595 };
596 
598  .name = "sendcmd",
599  .description = NULL_IF_CONFIG_SMALL("Send commands to filters."),
600  .init = init,
601  .uninit = uninit,
602  .priv_size = sizeof(SendCmdContext),
603  .inputs = sendcmd_inputs,
604  .outputs = sendcmd_outputs,
605  .priv_class = &sendcmd_class,
606 };
607 
608 #endif
609 
610 #if CONFIG_ASENDCMD_FILTER
611 
612 #define asendcmd_options options
613 AVFILTER_DEFINE_CLASS(asendcmd);
614 
615 static const AVFilterPad asendcmd_inputs[] = {
616  {
617  .name = "default",
618  .type = AVMEDIA_TYPE_AUDIO,
619  .filter_frame = filter_frame,
620  },
621  { NULL }
622 };
623 
624 static const AVFilterPad asendcmd_outputs[] = {
625  {
626  .name = "default",
627  .type = AVMEDIA_TYPE_AUDIO,
628  },
629  { NULL }
630 };
631 
633  .name = "asendcmd",
634  .description = NULL_IF_CONFIG_SMALL("Send commands to filters."),
635  .init = init,
636  .uninit = uninit,
637  .priv_size = sizeof(SendCmdContext),
638  .inputs = asendcmd_inputs,
639  .outputs = asendcmd_outputs,
640  .priv_class = &asendcmd_class,
641 };
642 
643 #endif
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
AVFilter ff_af_asendcmd
AVFilter ff_vf_sendcmd
#define av_cold
Definition: attributes.h:88
uint8_t
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1096
Main libavfilter public API header.
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:113
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:94
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
Definition: bprint.c:140
#define AV_BPRINT_SIZE_AUTOMATIC
#define flags(name, subs,...)
Definition: cbs_av1.c:561
#define s(width, name)
Definition: cbs_vp9.c:257
#define fail()
Definition: checkasm.h:133
#define FFMAX(a, b)
Definition: common.h:103
#define FFDIFFSIGN(x, y)
Comparator.
Definition: common.h:101
#define NULL
Definition: coverity.c:32
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.
Definition: eval.c:776
simple arithmetic expression evaluator
#define WITHIN_INTERVAL(ts, start_ts, end_ts)
static int cmp_intervals(const void *a, const void *b)
Definition: f_sendcmd.c:394
@ VAR_TS
Definition: f_sendcmd.c:57
@ VAR_PTS
Definition: f_sendcmd.c:56
@ VAR_POS
Definition: f_sendcmd.c:55
@ VAR_TE
Definition: f_sendcmd.c:58
@ VAR_N
Definition: f_sendcmd.c:53
@ VAR_VARS_NB
Definition: f_sendcmd.c:60
@ VAR_TI
Definition: f_sendcmd.c:59
@ VAR_T
Definition: f_sendcmd.c:54
#define SPACES
Definition: f_sendcmd.c:115
static int parse_commands(Command **cmds, int *nb_cmds, int interval_count, const char **buf, void *log_ctx)
Definition: f_sendcmd.c:221
static const AVOption options[]
Definition: f_sendcmd.c:107
#define COMMAND_FLAG_LEAVE
Definition: f_sendcmd.c:38
#define COMMAND_FLAG_EXPR
Definition: f_sendcmd.c:39
#define COMMAND_FLAG_ENTER
Definition: f_sendcmd.c:37
#define FLAGS
Definition: f_sendcmd.c:106
static int filter_frame(AVFilterLink *inlink, AVFrame *ref)
Definition: f_sendcmd.c:478
#define COMMAND_DELIMS
Definition: f_sendcmd.c:134
static char * make_command_flags_str(AVBPrint *pbuf, int flags)
Definition: f_sendcmd.c:63
static const char *const var_names[]
Definition: f_sendcmd.c:41
static int parse_command(Command *cmd, int cmd_count, int interval_count, const char **buf, void *log_ctx)
Definition: f_sendcmd.c:136
static av_cold int init(AVFilterContext *ctx)
Definition: f_sendcmd.c:401
static av_cold void uninit(AVFilterContext *ctx)
Definition: f_sendcmd.c:460
#define DELIMS
Definition: f_sendcmd.c:271
static void skip_comments(const char **buf)
Definition: f_sendcmd.c:117
static int parse_interval(Interval *interval, int interval_count, const char **buf, void *log_ctx)
Definition: f_sendcmd.c:273
#define OFFSET(x)
Definition: f_sendcmd.c:105
static int parse_intervals(Interval **intervals, int *nb_intervals, const char *buf, void *log_ctx)
Definition: f_sendcmd.c:343
Misc file utilities.
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
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...
Definition: avfilter.h:701
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:119
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:210
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
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().
Definition: avstring.c:186
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.
Definition: avstring.c:83
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...
Definition: avstring.c:151
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
int i
Definition: input.c:407
#define TS2D(ts)
Definition: internal.h:208
#define TS2T(ts, tb)
Definition: internal.h:209
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:288
static const char *const cmds[]
Definition: jacosubdec.c:72
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
Definition: file.c:144
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...
Definition: file.c:53
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
#define NAN
Definition: mathematics.h:64
AVOptions.
int av_parse_time(int64_t *timeval, const char *timestr, int duration)
Parse timestr and return in *time a corresponding number of microseconds.
Definition: parseutils.c:587
misc parsing utilities
var_name
Definition: setts_bsf.c:50
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
Definition: log.h:67
An instance of a filter.
Definition: avfilter.h:341
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:353
A filter pad used for either input or output.
Definition: internal.h:54
const char * name
Pad name.
Definition: internal.h:60
Filter definition.
Definition: avfilter.h:145
const char * name
Filter name.
Definition: avfilter.h:149
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
AVOption.
Definition: opt.h:248
int index
Definition: f_sendcmd.c:84
char * command
Definition: f_sendcmd.c:83
int flags
Definition: f_sendcmd.c:82
char * target
Definition: f_sendcmd.c:83
char * arg
Definition: f_sendcmd.c:83
int nb_commands
Definition: f_sendcmd.c:92
int index
unique index for these interval commands
Definition: f_sendcmd.c:90
int64_t start_ts
start timestamp expressed as microseconds units
Definition: f_sendcmd.c:88
Command * commands
Definition: f_sendcmd.c:91
int enabled
current time detected inside this interval
Definition: f_sendcmd.c:93
int64_t end_ts
end timestamp expressed as microseconds units
Definition: f_sendcmd.c:89
char * commands_str
Definition: f_sendcmd.c:102
int nb_intervals
Definition: f_sendcmd.c:99
Interval * intervals
Definition: f_sendcmd.c:98
char * commands_filename
Definition: f_sendcmd.c:101
#define av_free(p)
#define av_realloc_f(p, o, n)
#define av_freep(p)
#define av_malloc(s)
#define av_log(a,...)
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
AVFormatContext * ctx
Definition: movenc.c:48
const char * b
Definition: vf_curves.c:118
int len