FFmpeg
f_graphmonitor.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Paul B Mahol
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 #include "config_components.h"
22 
23 #include "float.h"
24 
25 #include "libavutil/pixdesc.h"
26 #include "libavutil/eval.h"
27 #include "libavutil/intreadwrite.h"
28 #include "libavutil/opt.h"
29 #include "libavutil/timestamp.h"
31 #include "avfilter.h"
32 #include "filters.h"
33 #include "formats.h"
34 #include "internal.h"
35 #include "video.h"
36 
37 typedef struct CacheItem {
38  int64_t previous_pts_us;
39 } CacheItem;
40 
41 typedef struct GraphMonitorContext {
42  const AVClass *class;
43 
44  int w, h;
45  float opacity;
46  int mode;
47  int flags;
49 
50  int eof;
52  int64_t pts;
53  int64_t next_pts;
54  uint8_t white[4];
55  uint8_t yellow[4];
56  uint8_t red[4];
57  uint8_t green[4];
58  uint8_t blue[4];
59  uint8_t gray[4];
60  uint8_t bg[4];
61 
63  unsigned int cache_size;
64  unsigned int cache_index;
66 
67 enum {
68  MODE_FULL = 0,
73  MODE_MAX = 15
74 };
75 
76 enum {
77  FLAG_NONE = 0 << 0,
78  FLAG_QUEUE = 1 << 0,
79  FLAG_FCIN = 1 << 1,
80  FLAG_FCOUT = 1 << 2,
81  FLAG_PTS = 1 << 3,
82  FLAG_TIME = 1 << 4,
83  FLAG_TB = 1 << 5,
84  FLAG_FMT = 1 << 6,
85  FLAG_SIZE = 1 << 7,
86  FLAG_RATE = 1 << 8,
87  FLAG_EOF = 1 << 9,
88  FLAG_SCIN = 1 << 10,
89  FLAG_SCOUT = 1 << 11,
90  FLAG_PTS_DELTA = 1 << 12,
91  FLAG_TIME_DELTA = 1 << 13,
92  FLAG_FC_DELTA = 1 << 14,
93  FLAG_SC_DELTA = 1 << 15,
94  FLAG_DISABLED = 1 << 16,
95 };
96 
97 #define OFFSET(x) offsetof(GraphMonitorContext, x)
98 #define VF AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
99 #define VFR AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
100 
101 static const AVOption graphmonitor_options[] = {
102  { "size", "set monitor size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="hd720"}, 0, 0, VF },
103  { "s", "set monitor size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="hd720"}, 0, 0, VF },
104  { "opacity", "set video opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=.9}, 0, 1, VFR },
105  { "o", "set video opacity", OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=.9}, 0, 1, VFR },
106  { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_FLAGS, {.i64=0}, 0, MODE_MAX, VFR, "mode" },
107  { "m", "set mode", OFFSET(mode), AV_OPT_TYPE_FLAGS, {.i64=0}, 0, MODE_MAX, VFR, "mode" },
108  { "full", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_FULL}, 0, 0, VFR, "mode" },
109  { "compact", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_COMPACT},0, 0, VFR, "mode" },
110  { "nozero", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_NOZERO}, 0, 0, VFR, "mode" },
111  { "noeof", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_NOEOF}, 0, 0, VFR, "mode" },
112  { "nodisabled",NULL,0,AV_OPT_TYPE_CONST, {.i64=MODE_NODISABLED},0,0,VFR,"mode" },
113  { "flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=FLAG_QUEUE}, 0, INT_MAX, VFR, "flags" },
114  { "f", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=FLAG_QUEUE}, 0, INT_MAX, VFR, "flags" },
115  { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAG_NONE}, 0, 0, VFR, "flags" },
116  { "all", NULL, 0, AV_OPT_TYPE_CONST, {.i64=INT_MAX}, 0, 0, VFR, "flags" },
117  { "queue", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAG_QUEUE}, 0, 0, VFR, "flags" },
118  { "frame_count_in", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAG_FCOUT}, 0, 0, VFR, "flags" },
119  { "frame_count_out", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAG_FCIN}, 0, 0, VFR, "flags" },
120  { "frame_count_delta",NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAG_FC_DELTA},0, 0, VFR, "flags" },
121  { "pts", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAG_PTS}, 0, 0, VFR, "flags" },
122  { "pts_delta", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAG_PTS_DELTA},0,0, VFR, "flags" },
123  { "time", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAG_TIME}, 0, 0, VFR, "flags" },
124  { "time_delta", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAG_TIME_DELTA},0,0,VFR, "flags" },
125  { "timebase", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAG_TB}, 0, 0, VFR, "flags" },
126  { "format", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAG_FMT}, 0, 0, VFR, "flags" },
127  { "size", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAG_SIZE}, 0, 0, VFR, "flags" },
128  { "rate", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAG_RATE}, 0, 0, VFR, "flags" },
129  { "eof", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAG_EOF}, 0, 0, VFR, "flags" },
130  { "sample_count_in", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAG_SCOUT}, 0, 0, VFR, "flags" },
131  { "sample_count_out", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAG_SCIN}, 0, 0, VFR, "flags" },
132  { "sample_count_delta",NULL,0, AV_OPT_TYPE_CONST, {.i64=FLAG_SC_DELTA},0, 0, VFR, "flags" },
133  { "disabled", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FLAG_DISABLED},0, 0, VFR, "flags" },
134  { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, VF },
135  { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, VF },
136  { NULL }
137 };
138 
140 {
141  GraphMonitorContext *s = ctx->priv;
142 
143  s->cache = av_fast_realloc(NULL, &s->cache_size,
144  8192 * sizeof(*(s->cache)));
145  if (!s->cache)
146  return AVERROR(ENOMEM);
147 
148  return 0;
149 }
150 
152 {
153  AVFilterLink *outlink = ctx->outputs[0];
154  static const enum AVPixelFormat pix_fmts[] = {
157  };
158  int ret;
159 
161  if ((ret = ff_formats_ref(fmts_list, &outlink->incfg.formats)) < 0)
162  return ret;
163 
164  return 0;
165 }
166 
168 {
169  const int h = out->height;
170  const int w = out->width;
171  uint8_t *dst = out->data[0];
172  int bg = AV_RN32(s->bg);
173 
174  for (int j = 0; j < w; j++)
175  AV_WN32(dst + j * 4, bg);
176  dst += out->linesize[0];
177  for (int i = 1; i < h; i++) {
178  memcpy(dst, out->data[0], w * 4);
179  dst += out->linesize[0];
180  }
181 }
182 
183 static void drawtext(AVFrame *pic, int x, int y, const char *txt,
184  const int len, uint8_t *color)
185 {
186  const uint8_t *font;
187  int font_height;
188  int i;
189 
190  font = avpriv_cga_font, font_height = 8;
191 
192  if (y + 8 >= pic->height ||
193  x + len * 8 >= pic->width)
194  return;
195 
196  for (i = 0; txt[i]; i++) {
197  int char_y, mask;
198 
199  uint8_t *p = pic->data[0] + y*pic->linesize[0] + (x + i*8)*4;
200  for (char_y = 0; char_y < font_height; char_y++) {
201  for (mask = 0x80; mask; mask >>= 1) {
202  if (font[txt[i] * font_height + char_y] & mask) {
203  p[0] = color[0];
204  p[1] = color[1];
205  p[2] = color[2];
206  }
207  p += 4;
208  }
209  p += pic->linesize[0] - 8 * 4;
210  }
211  }
212 }
213 
215 {
216  for (int j = 0; j < filter->nb_inputs; j++) {
217  AVFilterLink *l = filter->inputs[j];
218 
219  if (!ff_outlink_get_status(l))
220  return 0;
221  }
222 
223  for (int j = 0; j < filter->nb_outputs; j++) {
224  AVFilterLink *l = filter->outputs[j];
225 
226  if (!ff_outlink_get_status(l))
227  return 0;
228  }
229 
230  return 1;
231 }
232 
234 {
235  for (int j = 0; j < filter->nb_inputs; j++) {
236  AVFilterLink *l = filter->inputs[j];
237  size_t frames = ff_inlink_queued_frames(l);
238 
239  if (frames)
240  return 1;
241  }
242 
243  for (int j = 0; j < filter->nb_outputs; j++) {
244  AVFilterLink *l = filter->outputs[j];
245  size_t frames = ff_inlink_queued_frames(l);
246 
247  if (frames)
248  return 1;
249  }
250 
251  return 0;
252 }
253 
256  AVFrame *out,
257  int xpos, int ypos,
258  AVFilterLink *l,
259  size_t frames)
260 {
261  GraphMonitorContext *s = ctx->priv;
262  int64_t previous_pts_us = s->cache[s->cache_index].previous_pts_us;
263  int64_t current_pts_us = l->current_pts_us;
264  const int flags = s->flags;
265  const int mode = s->mode;
266  char buffer[1024] = { 0 };
267  int len = 0;
268 
269  if (flags & FLAG_FMT) {
270  if (l->type == AVMEDIA_TYPE_VIDEO) {
271  len = snprintf(buffer, sizeof(buffer)-1, " | format: %s",
273  } else if (l->type == AVMEDIA_TYPE_AUDIO) {
274  len = snprintf(buffer, sizeof(buffer)-1, " | format: %s",
276  }
277  drawtext(out, xpos, ypos, buffer, len, s->white);
278  xpos += len * 8;
279  }
280  if (flags & FLAG_SIZE) {
281  if (l->type == AVMEDIA_TYPE_VIDEO) {
282  len = snprintf(buffer, sizeof(buffer)-1, " | size: %dx%d", l->w, l->h);
283  } else if (l->type == AVMEDIA_TYPE_AUDIO) {
284  len = snprintf(buffer, sizeof(buffer)-1, " | channels: %d", l->ch_layout.nb_channels);
285  }
286  drawtext(out, xpos, ypos, buffer, len, s->white);
287  xpos += len * 8;
288  }
289  if (flags & FLAG_RATE) {
290  if (l->type == AVMEDIA_TYPE_VIDEO) {
291  len = snprintf(buffer, sizeof(buffer)-1, " | fps: %d/%d", l->frame_rate.num, l->frame_rate.den);
292  } else if (l->type == AVMEDIA_TYPE_AUDIO) {
293  len = snprintf(buffer, sizeof(buffer)-1, " | samplerate: %d", l->sample_rate);
294  }
295  drawtext(out, xpos, ypos, buffer, len, s->white);
296  xpos += len * 8;
297  }
298  if (flags & FLAG_TB) {
299  len = snprintf(buffer, sizeof(buffer)-1, " | tb: %d/%d", l->time_base.num, l->time_base.den);
300  drawtext(out, xpos, ypos, buffer, len, s->white);
301  xpos += len * 8;
302  }
303  if ((flags & FLAG_QUEUE) && (!(mode & MODE_NOZERO) || frames)) {
304  len = snprintf(buffer, sizeof(buffer)-1, " | queue: ");
305  drawtext(out, xpos, ypos, buffer, len, s->white);
306  xpos += len * 8;
307  len = snprintf(buffer, sizeof(buffer)-1, "%"SIZE_SPECIFIER, frames);
308  drawtext(out, xpos, ypos, buffer, len, frames > 0 ? frames >= 10 ? frames >= 50 ? s->red : s->yellow : s->green : s->white);
309  xpos += len * 8;
310  }
311  if ((flags & FLAG_FCIN) && (!(mode & MODE_NOZERO) || l->frame_count_in)) {
312  len = snprintf(buffer, sizeof(buffer)-1, " | in: %"PRId64, l->frame_count_in);
313  drawtext(out, xpos, ypos, buffer, len, s->white);
314  xpos += len * 8;
315  }
316  if ((flags & FLAG_FCOUT) && (!(mode & MODE_NOZERO) || l->frame_count_out)) {
317  len = snprintf(buffer, sizeof(buffer)-1, " | out: %"PRId64, l->frame_count_out);
318  drawtext(out, xpos, ypos, buffer, len, s->white);
319  xpos += len * 8;
320  }
321  if ((flags & FLAG_FC_DELTA) && (!(mode & MODE_NOZERO) || (l->frame_count_in - l->frame_count_out))) {
322  len = snprintf(buffer, sizeof(buffer)-1, " | delta: %"PRId64, l->frame_count_in - l->frame_count_out);
323  drawtext(out, xpos, ypos, buffer, len, s->white);
324  xpos += len * 8;
325  }
326  if ((flags & FLAG_SCIN) && (!(mode & MODE_NOZERO) || l->sample_count_in)) {
327  len = snprintf(buffer, sizeof(buffer)-1, " | sin: %"PRId64, l->sample_count_in);
328  drawtext(out, xpos, ypos, buffer, len, s->white);
329  xpos += len * 8;
330  }
331  if ((flags & FLAG_SCOUT) && (!(mode & MODE_NOZERO) || l->sample_count_out)) {
332  len = snprintf(buffer, sizeof(buffer)-1, " | sout: %"PRId64, l->sample_count_out);
333  drawtext(out, xpos, ypos, buffer, len, s->white);
334  xpos += len * 8;
335  }
336  if ((flags & FLAG_SC_DELTA) && (!(mode & MODE_NOZERO) || (l->sample_count_in - l->sample_count_out))) {
337  len = snprintf(buffer, sizeof(buffer)-1, " | sdelta: %"PRId64, l->sample_count_in - l->sample_count_out);
338  drawtext(out, xpos, ypos, buffer, len, s->white);
339  xpos += len * 8;
340  }
341  if ((flags & FLAG_PTS) && (!(mode & MODE_NOZERO) || current_pts_us)) {
342  len = snprintf(buffer, sizeof(buffer)-1, " | pts: %s", av_ts2str(current_pts_us));
343  drawtext(out, xpos, ypos, buffer, len, s->white);
344  xpos += len * 8;
345  }
346  if ((flags & FLAG_PTS_DELTA) && (!(mode & MODE_NOZERO) || (current_pts_us - previous_pts_us))) {
347  len = snprintf(buffer, sizeof(buffer)-1, " | pts_delta: %s", av_ts2str(current_pts_us - previous_pts_us));
348  drawtext(out, xpos, ypos, buffer, len, s->white);
349  xpos += len * 8;
350  }
351  if ((flags & FLAG_TIME) && (!(mode & MODE_NOZERO) || current_pts_us)) {
352  len = snprintf(buffer, sizeof(buffer)-1, " | time: %s", av_ts2timestr(current_pts_us, &AV_TIME_BASE_Q));
353  drawtext(out, xpos, ypos, buffer, len, s->white);
354  xpos += len * 8;
355  }
356  if ((flags & FLAG_TIME_DELTA) && (!(mode & MODE_NOZERO) || (current_pts_us - previous_pts_us))) {
357  len = snprintf(buffer, sizeof(buffer)-1, " | time_delta: %s", av_ts2timestr(current_pts_us - previous_pts_us, &AV_TIME_BASE_Q));
358  drawtext(out, xpos, ypos, buffer, len, s->white);
359  xpos += len * 8;
360  }
361  if ((flags & FLAG_EOF) && ff_outlink_get_status(l)) {
362  len = snprintf(buffer, sizeof(buffer)-1, " | eof");
363  drawtext(out, xpos, ypos, buffer, len, s->blue);
364  xpos += len * 8;
365  }
366  if ((flags & FLAG_DISABLED) && filter->is_disabled) {
367  len = snprintf(buffer, sizeof(buffer)-1, " | off");
368  drawtext(out, xpos, ypos, buffer, len, s->gray);
369  xpos += len * 8;
370  }
371 
372  s->cache[s->cache_index].previous_pts_us = l->current_pts_us;
373 
374  if (s->cache_index + 1 >= s->cache_size / sizeof(*(s->cache))) {
375  void *ptr = av_fast_realloc(s->cache, &s->cache_size, s->cache_size * 2);
376 
377  if (!ptr)
378  return AVERROR(ENOMEM);
379  s->cache = ptr;
380  }
381  s->cache_index++;
382 
383  return 0;
384 }
385 
386 static int create_frame(AVFilterContext *ctx, int64_t pts)
387 {
388  GraphMonitorContext *s = ctx->priv;
389  AVFilterLink *outlink = ctx->outputs[0];
390  int ret, len, xpos, ypos = 0;
391  char buffer[1024];
392  AVFrame *out;
393 
394  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
395  if (!out)
396  return AVERROR(ENOMEM);
397 
398  s->bg[3] = 255 * s->opacity;
399  clear_image(s, out, outlink);
400 
401  s->cache_index = 0;
402 
403  for (int i = 0; i < ctx->graph->nb_filters; i++) {
404  AVFilterContext *filter = ctx->graph->filters[i];
405 
406  if ((s->mode & MODE_COMPACT) && !filter_have_queued(filter))
407  continue;
408 
409  if ((s->mode & MODE_NOEOF) && filter_have_eof(filter))
410  continue;
411 
412  if ((s->mode & MODE_NODISABLED) && filter->is_disabled)
413  continue;
414 
415  xpos = 0;
416  len = strlen(filter->name);
417  drawtext(out, xpos, ypos, filter->name, len, s->white);
418  xpos += len * 8 + 10;
419  len = strlen(filter->filter->name);
420  drawtext(out, xpos, ypos, filter->filter->name, len, s->white);
421  ypos += 10;
422  for (int j = 0; j < filter->nb_inputs; j++) {
423  AVFilterLink *l = filter->inputs[j];
424  size_t frames = ff_inlink_queued_frames(l);
425 
426  if ((s->mode & MODE_COMPACT) && !frames)
427  continue;
428 
429  if ((s->mode & MODE_NOEOF) && ff_outlink_get_status(l))
430  continue;
431 
432  xpos = 10;
433  len = snprintf(buffer, sizeof(buffer)-1, "in%d: ", j);
434  drawtext(out, xpos, ypos, buffer, len, s->white);
435  xpos += len * 8;
436  len = strlen(l->src->name);
437  drawtext(out, xpos, ypos, l->src->name, len, s->white);
438  xpos += len * 8 + 10;
439  ret = draw_items(ctx, filter, out, xpos, ypos, l, frames);
440  if (ret < 0)
441  goto error;
442  ypos += 10;
443  }
444 
445  ypos += 2;
446  for (int j = 0; j < filter->nb_outputs; j++) {
447  AVFilterLink *l = filter->outputs[j];
448  size_t frames = ff_inlink_queued_frames(l);
449 
450  if ((s->mode & MODE_COMPACT) && !frames)
451  continue;
452 
453  if ((s->mode & MODE_NOEOF) && ff_outlink_get_status(l))
454  continue;
455 
456  xpos = 10;
457  len = snprintf(buffer, sizeof(buffer)-1, "out%d: ", j);
458  drawtext(out, xpos, ypos, buffer, len, s->white);
459  xpos += len * 8;
460  len = strlen(l->dst->name);
461  drawtext(out, xpos, ypos, l->dst->name, len, s->white);
462  xpos += len * 8 + 10;
463  ret = draw_items(ctx, filter, out, xpos, ypos, l, frames);
464  if (ret < 0)
465  goto error;
466  ypos += 10;
467  }
468  ypos += 5;
469  }
470 
471  out->pts = pts;
472  out->duration = 1;
473  s->pts = pts + 1;
474  if (s->eof_frames)
475  s->eof_frames = 0;
476  return ff_filter_frame(outlink, out);
477 error:
478  av_frame_free(&out);
479  return ret;
480 }
481 
483 {
484  GraphMonitorContext *s = ctx->priv;
485  AVFilterLink *inlink = ctx->inputs[0];
486  AVFilterLink *outlink = ctx->outputs[0];
487  int64_t pts = AV_NOPTS_VALUE;
488  int status;
489 
491 
492  if (!s->eof && ff_inlink_queued_frames(inlink)) {
493  AVFrame *frame = NULL;
494  int ret;
495 
497  if (ret < 0)
498  return ret;
499  if (ret > 0) {
500  pts = frame->pts;
502  }
503  }
504 
505  if (pts != AV_NOPTS_VALUE) {
506  pts = av_rescale_q(pts, inlink->time_base, outlink->time_base);
507  if (s->pts == AV_NOPTS_VALUE)
508  s->pts = pts;
509  s->next_pts = pts;
510  } else if (s->eof) {
511  s->next_pts = s->pts + 1;
512  }
513 
514  if (s->eof && s->eof_frames == 0) {
515  ff_outlink_set_status(outlink, AVERROR_EOF, s->next_pts);
516  return 0;
517  }
518 
519  if (s->eof || (s->pts < s->next_pts && ff_outlink_frame_wanted(outlink)))
520  return create_frame(ctx, s->pts);
521 
522  if (!s->eof && ff_inlink_acknowledge_status(inlink, &status, &pts)) {
523  s->eof = 1;
524  s->eof_frames = 1;
525  ff_filter_set_ready(ctx, 100);
526  return 0;
527  }
528 
529  if (!s->eof) {
531  } else {
532  ff_filter_set_ready(ctx, 100);
533  return 0;
534  }
535 
536  return FFERROR_NOT_READY;
537 }
538 
539 static int config_output(AVFilterLink *outlink)
540 {
541  GraphMonitorContext *s = outlink->src->priv;
542 
543  s->white[0] = s->white[1] = s->white[2] = 255;
544  s->yellow[0] = s->yellow[1] = 255;
545  s->red[0] = 255;
546  s->green[1] = 255;
547  s->blue[2] = 255;
548  s->gray[0] = s->gray[1] = s->gray[2] = 128;
549  s->pts = AV_NOPTS_VALUE;
550  s->next_pts = AV_NOPTS_VALUE;
551  outlink->w = s->w;
552  outlink->h = s->h;
553  outlink->sample_aspect_ratio = (AVRational){1,1};
554  outlink->frame_rate = s->frame_rate;
555  outlink->time_base = av_inv_q(s->frame_rate);
556 
557  return 0;
558 }
559 
561 {
562  GraphMonitorContext *s = ctx->priv;
563 
564  av_freep(&s->cache);
565  s->cache_size = s->cache_index = 0;
566 }
567 
568 AVFILTER_DEFINE_CLASS_EXT(graphmonitor, "(a)graphmonitor", graphmonitor_options);
569 
570 #if CONFIG_GRAPHMONITOR_FILTER
571 
572 static const AVFilterPad graphmonitor_inputs[] = {
573  {
574  .name = "default",
575  .type = AVMEDIA_TYPE_VIDEO,
576  },
577 };
578 
579 static const AVFilterPad graphmonitor_outputs[] = {
580  {
581  .name = "default",
582  .type = AVMEDIA_TYPE_VIDEO,
583  .config_props = config_output,
584  },
585 };
586 
588  .name = "graphmonitor",
589  .description = NULL_IF_CONFIG_SMALL("Show various filtergraph stats."),
590  .priv_size = sizeof(GraphMonitorContext),
591  .priv_class = &graphmonitor_class,
592  .init = init,
593  .uninit = uninit,
594  .activate = activate,
595  FILTER_INPUTS(graphmonitor_inputs),
596  FILTER_OUTPUTS(graphmonitor_outputs),
598  .process_command = ff_filter_process_command,
599 };
600 
601 #endif // CONFIG_GRAPHMONITOR_FILTER
602 
603 #if CONFIG_AGRAPHMONITOR_FILTER
604 
605 static const AVFilterPad agraphmonitor_inputs[] = {
606  {
607  .name = "default",
608  .type = AVMEDIA_TYPE_AUDIO,
609  },
610 };
611 
612 static const AVFilterPad agraphmonitor_outputs[] = {
613  {
614  .name = "default",
615  .type = AVMEDIA_TYPE_VIDEO,
616  .config_props = config_output,
617  },
618 };
619 
621  .name = "agraphmonitor",
622  .description = NULL_IF_CONFIG_SMALL("Show various filtergraph stats."),
623  .priv_class = &graphmonitor_class,
624  .priv_size = sizeof(GraphMonitorContext),
625  .init = init,
626  .uninit = uninit,
627  .activate = activate,
628  FILTER_INPUTS(agraphmonitor_inputs),
629  FILTER_OUTPUTS(agraphmonitor_outputs),
631  .process_command = ff_filter_process_command,
632 };
633 #endif // CONFIG_AGRAPHMONITOR_FILTER
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
GraphMonitorContext::mode
int mode
Definition: f_graphmonitor.c:46
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:101
FLAG_TIME_DELTA
@ FLAG_TIME_DELTA
Definition: f_graphmonitor.c:91
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
status
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
CacheItem::previous_pts_us
int64_t previous_pts_us
Definition: f_graphmonitor.c:38
GraphMonitorContext::gray
uint8_t gray[4]
Definition: f_graphmonitor.c:59
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
drawtext
static void drawtext(AVFrame *pic, int x, int y, const char *txt, const int len, uint8_t *color)
Definition: f_graphmonitor.c:183
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:401
out
FILE * out
Definition: movenc.c:54
color
Definition: vf_paletteuse.c:509
MODE_NOEOF
@ MODE_NOEOF
Definition: f_graphmonitor.c:71
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:971
FLAG_TB
@ FLAG_TB
Definition: f_graphmonitor.c:83
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
FFERROR_NOT_READY
return FFERROR_NOT_READY
Definition: filter_design.txt:204
AV_OPT_TYPE_VIDEO_RATE
@ AV_OPT_TYPE_VIDEO_RATE
offset must point to AVRational
Definition: opt.h:238
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
FLAG_SCOUT
@ FLAG_SCOUT
Definition: f_graphmonitor.c:89
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:100
GraphMonitorContext::opacity
float opacity
Definition: f_graphmonitor.c:45
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
pixdesc.h
AVFrame::width
int width
Definition: frame.h:402
w
uint8_t w
Definition: llviddspenc.c:38
OFFSET
#define OFFSET(x)
Definition: f_graphmonitor.c:97
AVOption
AVOption.
Definition: opt.h:251
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:171
float.h
filter
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
Definition: filter_design.txt:228
FLAG_FCIN
@ FLAG_FCIN
Definition: f_graphmonitor.c:79
GraphMonitorContext::cache_index
unsigned int cache_index
Definition: f_graphmonitor.c:64
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: f_graphmonitor.c:560
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:311
video.h
FF_FILTER_FORWARD_STATUS_BACK
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
Definition: filters.h:199
create_frame
static int create_frame(AVFilterContext *ctx, int64_t pts)
Definition: f_graphmonitor.c:386
draw_items
static int draw_items(AVFilterContext *ctx, AVFilterContext *filter, AVFrame *out, int xpos, int ypos, AVFilterLink *l, size_t frames)
Definition: f_graphmonitor.c:254
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:351
GraphMonitorContext::cache
CacheItem * cache
Definition: f_graphmonitor.c:62
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
ff_avf_agraphmonitor
const AVFilter ff_avf_agraphmonitor
ff_inlink_consume_frame
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Definition: avfilter.c:1374
GraphMonitorContext::bg
uint8_t bg[4]
Definition: f_graphmonitor.c:60
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:412
MODE_NOZERO
@ MODE_NOZERO
Definition: f_graphmonitor.c:70
frames
if it could not because there are no more frames
Definition: filter_design.txt:266
pts
static int64_t pts
Definition: transcode_aac.c:643
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: f_graphmonitor.c:151
AVRational::num
int num
Numerator.
Definition: rational.h:59
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:49
GraphMonitorContext::green
uint8_t green[4]
Definition: f_graphmonitor.c:57
FLAG_RATE
@ FLAG_RATE
Definition: f_graphmonitor.c:86
av_cold
#define av_cold
Definition: attributes.h:90
mask
static const uint16_t mask[17]
Definition: lzw.c:38
GraphMonitorContext::eof
int eof
Definition: f_graphmonitor.c:50
ff_outlink_set_status
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition: filters.h:189
av_fast_realloc
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
Definition: mem.c:495
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:256
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
FLAG_FMT
@ FLAG_FMT
Definition: f_graphmonitor.c:84
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:617
FLAG_QUEUE
@ FLAG_QUEUE
Definition: f_graphmonitor.c:78
filters.h
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:297
GraphMonitorContext::white
uint8_t white[4]
Definition: f_graphmonitor.c:54
ctx
AVFormatContext * ctx
Definition: movenc.c:48
av_rescale_q
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
av_get_sample_fmt_name
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:51
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:194
GraphMonitorContext::pts
int64_t pts
Definition: f_graphmonitor.c:52
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
FLAG_SCIN
@ FLAG_SCIN
Definition: f_graphmonitor.c:88
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
GraphMonitorContext::red
uint8_t red[4]
Definition: f_graphmonitor.c:56
FLAG_DISABLED
@ FLAG_DISABLED
Definition: f_graphmonitor.c:94
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
Definition: opt.h:235
AV_RN32
#define AV_RN32(p)
Definition: intreadwrite.h:364
AVFilterContext::name
char * name
name of this filter instance
Definition: avfilter.h:402
VF
#define VF
Definition: f_graphmonitor.c:98
ff_inlink_acknowledge_status
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
Definition: avfilter.c:1328
ff_inlink_queued_frames
size_t ff_inlink_queued_frames(AVFilterLink *link)
Get the number of frames available on the link.
Definition: avfilter.c:1343
activate
static int activate(AVFilterContext *ctx)
Definition: f_graphmonitor.c:482
MODE_FULL
@ MODE_FULL
Definition: f_graphmonitor.c:68
eval.h
FLAG_FC_DELTA
@ FLAG_FC_DELTA
Definition: f_graphmonitor.c:92
av_ts2timestr
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:76
GraphMonitorContext::next_pts
int64_t next_pts
Definition: f_graphmonitor.c:53
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:114
AV_WN32
#define AV_WN32(p, v)
Definition: intreadwrite.h:376
init
static av_cold int init(AVFilterContext *ctx)
Definition: f_graphmonitor.c:139
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
MODE_NODISABLED
@ MODE_NODISABLED
Definition: f_graphmonitor.c:72
GraphMonitorContext
Definition: f_graphmonitor.c:41
ff_filter_process_command
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Definition: avfilter.c:844
FLAG_EOF
@ FLAG_EOF
Definition: f_graphmonitor.c:87
FF_FILTER_FORWARD_WANTED
FF_FILTER_FORWARD_WANTED(outlink, inlink)
xga_font_data.h
FLAG_SIZE
@ FLAG_SIZE
Definition: f_graphmonitor.c:85
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
GraphMonitorContext::cache_size
unsigned int cache_size
Definition: f_graphmonitor.c:63
filter_have_eof
static int filter_have_eof(AVFilterContext *filter)
Definition: f_graphmonitor.c:214
GraphMonitorContext::blue
uint8_t blue[4]
Definition: f_graphmonitor.c:58
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
CacheItem
Definition: f_graphmonitor.c:37
graphmonitor_options
static const AVOption graphmonitor_options[]
Definition: f_graphmonitor.c:101
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
len
int len
Definition: vorbis_enc_data.h:426
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:55
MODE_MAX
@ MODE_MAX
Definition: f_graphmonitor.c:73
GraphMonitorContext::frame_rate
AVRational frame_rate
Definition: f_graphmonitor.c:48
FLAG_NONE
@ FLAG_NONE
Definition: f_graphmonitor.c:77
AVFilter
Filter definition.
Definition: avfilter.h:166
FLAG_FCOUT
@ FLAG_FCOUT
Definition: f_graphmonitor.c:80
ret
ret
Definition: filter_design.txt:187
filter_have_queued
static int filter_have_queued(AVFilterContext *filter)
Definition: f_graphmonitor.c:233
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
GraphMonitorContext::w
int w
Definition: f_graphmonitor.c:44
VFR
#define VFR
Definition: f_graphmonitor.c:99
clear_image
static void clear_image(GraphMonitorContext *s, AVFrame *out, AVFilterLink *outlink)
Definition: f_graphmonitor.c:167
config_output
static int config_output(AVFilterLink *outlink)
Definition: f_graphmonitor.c:539
SIZE_SPECIFIER
#define SIZE_SPECIFIER
Definition: internal.h:149
AVFrame::height
int height
Definition: frame.h:402
FLAG_SC_DELTA
@ FLAG_SC_DELTA
Definition: f_graphmonitor.c:93
GraphMonitorContext::h
int h
Definition: f_graphmonitor.c:44
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
AVRational::den
int den
Denominator.
Definition: rational.h:60
mode
mode
Definition: ebur128.h:83
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
avfilter.h
ff_outlink_get_status
int ff_outlink_get_status(AVFilterLink *link)
Get the status on an output link.
Definition: avfilter.c:1520
AVFilterContext
An instance of a filter.
Definition: avfilter.h:397
FLAG_PTS
@ FLAG_PTS
Definition: f_graphmonitor.c:81
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVFilterFormatsConfig::formats
AVFilterFormats * formats
List of supported formats (pixel or sample).
Definition: avfilter.h:505
GraphMonitorContext::flags
int flags
Definition: f_graphmonitor.c:47
avpriv_cga_font
const uint8_t avpriv_cga_font[2048]
Definition: xga_font_data.c:29
GraphMonitorContext::eof_frames
int eof_frames
Definition: f_graphmonitor.c:51
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:195
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Definition: opt.h:224
timestamp.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:375
FLAG_PTS_DELTA
@ FLAG_PTS_DELTA
Definition: f_graphmonitor.c:90
av_ts2str
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:54
h
h
Definition: vp9dsp_template.c:2038
ff_outlink_frame_wanted
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
GraphMonitorContext::yellow
uint8_t yellow[4]
Definition: f_graphmonitor.c:55
AVFILTER_DEFINE_CLASS_EXT
AVFILTER_DEFINE_CLASS_EXT(graphmonitor, "(a)graphmonitor", graphmonitor_options)
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
snprintf
#define snprintf
Definition: snprintf.h:34
ff_vf_graphmonitor
const AVFilter ff_vf_graphmonitor
FLAG_TIME
@ FLAG_TIME
Definition: f_graphmonitor.c:82
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2856
ff_filter_set_ready
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
Definition: avfilter.c:204
MODE_COMPACT
@ MODE_COMPACT
Definition: f_graphmonitor.c:69