History

avfilter/f_graphmonitor: add several more flags

Paul B Mahol committed 4 years ago

Commit aede8421 parent 34836e92 files · +105 −9Browse files

Unified · Split

2 files
  1. doc/filters.texi +12 −0
  2. libavfilter/f_graphmonitor.c +93 −9
doc/filters.texi+12−0
@@ -13432,12 +13432,21 @@ Display number of frames taken from filter. · 13431 unmodified lines
1343213432 @item frame_count_out
1343313433 Display number of frames given out from filter.
1343413434
13435+@item frame_count_delta
13436+Display delta number of frames between above two values.
13437+
1343513438 @item pts
1343613439 Display current filtered frame pts.
1343713440
13441+@item pts_delta
13442+Display pts delta between current and previous frame.
13443+
1343813444 @item time
1343913445 Display current filtered frame time.
1344013446
13447+@item time_delta
13448+Display time delta between current and previous frame.
13449+
1344113450 @item timebase
1344213451 Display time base for filter link.
1344313452
@@ -13458,6 +13467,9 @@ Display number of samples taken from filter. · 14 unmodified lines
1345813467
1345913468 @item sample_count_out
1346013469 Display number of samples given out from filter.
13470+
13471+@item sample_count_delta
13472+Display delta number of samples between above two values.
1346113473 @end table
1346213474
1346313475 @item rate, r
libavfilter/f_graphmonitor.c+93−9
@@ -32,6 +32,10 @@ · 31 unmodified lines
3232 #include "internal.h"
3333 #include "video.h"
3434
35+typedef struct CacheItem {
36+ int64_t previous_pts_us;
37+} CacheItem;
38+
3539 typedef struct GraphMonitorContext {
3640 const AVClass *class;
3741
@@ -49,6 +53,10 @@ typedef struct GraphMonitorContext { · 11 unmodified lines
4953 uint8_t green[4];
5054 uint8_t blue[4];
5155 uint8_t bg[4];
56+
57+ CacheItem *cache;
58+ unsigned int cache_size;
59+ unsigned int cache_index;
5260 } GraphMonitorContext;
5361
5462 enum {
@@ -64,6 +72,10 @@ enum { · 9 unmodified lines
6472 MODE_EOF = 1 << 9,
6573 MODE_SCIN = 1 << 10,
6674 MODE_SCOUT = 1 << 11,
75+ MODE_PTS_DELTA = 1 << 12,
76+ MODE_TIME_DELTA = 1 << 13,
77+ MODE_FC_DELTA = 1 << 14,
78+ MODE_SC_DELTA = 1 << 15,
6779 };
6880
6981 #define OFFSET(x) offsetof(GraphMonitorContext, x)
@@ -83,8 +95,11 @@ static const AVOption graphmonitor_options[] = { · 13 unmodified lines
8395 { "queue", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_QUEUE}, 0, 0, VF, "flags" },
8496 { "frame_count_in", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_FCOUT}, 0, 0, VF, "flags" },
8597 { "frame_count_out", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_FCIN}, 0, 0, VF, "flags" },
98+ { "frame_count_delta",NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_FC_DELTA},0, 0, VF, "flags" },
8699 { "pts", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_PTS}, 0, 0, VF, "flags" },
100+ { "pts_delta", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_PTS_DELTA},0,0, VF, "flags" },
87101 { "time", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_TIME}, 0, 0, VF, "flags" },
102+ { "time_delta", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_TIME_DELTA},0,0,VF, "flags" },
88103 { "timebase", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_TB}, 0, 0, VF, "flags" },
89104 { "format", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_FMT}, 0, 0, VF, "flags" },
90105 { "size", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_SIZE}, 0, 0, VF, "flags" },
@@ -92,11 +107,24 @@ static const AVOption graphmonitor_options[] = { · 1 unmodified line
92107 { "eof", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_EOF}, 0, 0, VF, "flags" },
93108 { "sample_count_in", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_SCOUT}, 0, 0, VF, "flags" },
94109 { "sample_count_out", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MODE_SCIN}, 0, 0, VF, "flags" },
110+ { "sample_count_delta",NULL,0, AV_OPT_TYPE_CONST, {.i64=MODE_SC_DELTA},0, 0, VF, "flags" },
95111 { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, VF },
96112 { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, VF },
97113 { NULL }
98114 };
99115
116+static av_cold int init(AVFilterContext *ctx)
117+{
118+ GraphMonitorContext *s = ctx->priv;
119+
120+ s->cache = av_fast_realloc(NULL, &s->cache_size,
121+ 8192 * sizeof(*(s->cache)));
122+ if (!s->cache)
123+ return AVERROR(ENOMEM);
124+
125+ return 0;
126+}
127+
100128 static int query_formats(AVFilterContext *ctx)
101129 {
102130 AVFilterLink *outlink = ctx->outputs[0];
@@ -173,12 +201,14 @@ static int filter_have_queued(AVFilterContext *filter) · 70 unmodified lines
173201 return 0;
174202 }
175203
176−static void draw_items(AVFilterContext *ctx, AVFrame *out,
177− int xpos, int ypos,
178− AVFilterLink *l,
179− size_t frames)
204+static int draw_items(AVFilterContext *ctx, AVFrame *out,
205+ int xpos, int ypos,
206+ AVFilterLink *l,
207+ size_t frames)
180208 {
181209 GraphMonitorContext *s = ctx->priv;
210+ int64_t previous_pts_us = s->cache[s->cache_index].previous_pts_us;
211+ int64_t current_pts_us = l->current_pts_us;
182212 char buffer[1024] = { 0 };
183213
184214 if (s->flags & MODE_FMT) {
@@ -233,6 +263,11 @@ static void draw_items(AVFilterContext *ctx, AVFrame *out, · 48 unmodified lines
233263 drawtext(out, xpos, ypos, buffer, s->white);
234264 xpos += strlen(buffer) * 8;
235265 }
266+ if (s->flags & MODE_FC_DELTA) {
267+ snprintf(buffer, sizeof(buffer)-1, " | delta: %"PRId64, l->frame_count_in - l->frame_count_out);
268+ drawtext(out, xpos, ypos, buffer, s->white);
269+ xpos += strlen(buffer) * 8;
270+ }
236271 if (s->flags & MODE_SCIN) {
237272 snprintf(buffer, sizeof(buffer)-1, " | sin: %"PRId64, l->sample_count_in);
238273 drawtext(out, xpos, ypos, buffer, s->white);
@@ -243,13 +278,28 @@ static void draw_items(AVFilterContext *ctx, AVFrame *out, · 4 unmodified lines
243278 drawtext(out, xpos, ypos, buffer, s->white);
244279 xpos += strlen(buffer) * 8;
245280 }
281+ if (s->flags & MODE_SC_DELTA) {
282+ snprintf(buffer, sizeof(buffer)-1, " | sdelta: %"PRId64, l->sample_count_in - l->sample_count_out);
283+ drawtext(out, xpos, ypos, buffer, s->white);
284+ xpos += strlen(buffer) * 8;
285+ }
246286 if (s->flags & MODE_PTS) {
247− snprintf(buffer, sizeof(buffer)-1, " | pts: %s", av_ts2str(l->current_pts_us));
287+ snprintf(buffer, sizeof(buffer)-1, " | pts: %s", av_ts2str(current_pts_us));
288+ drawtext(out, xpos, ypos, buffer, s->white);
289+ xpos += strlen(buffer) * 8;
290+ }
291+ if (s->flags & MODE_PTS_DELTA) {
292+ snprintf(buffer, sizeof(buffer)-1, " | pts_delta: %s", av_ts2str(current_pts_us - previous_pts_us));
248293 drawtext(out, xpos, ypos, buffer, s->white);
249294 xpos += strlen(buffer) * 8;
250295 }
251296 if (s->flags & MODE_TIME) {
252− snprintf(buffer, sizeof(buffer)-1, " | time: %s", av_ts2timestr(l->current_pts_us, &AV_TIME_BASE_Q));
297+ snprintf(buffer, sizeof(buffer)-1, " | time: %s", av_ts2timestr(current_pts_us, &AV_TIME_BASE_Q));
298+ drawtext(out, xpos, ypos, buffer, s->white);
299+ xpos += strlen(buffer) * 8;
300+ }
301+ if (s->flags & MODE_TIME_DELTA) {
302+ snprintf(buffer, sizeof(buffer)-1, " | time_delta: %s", av_ts2timestr(current_pts_us - previous_pts_us, &AV_TIME_BASE_Q));
253303 drawtext(out, xpos, ypos, buffer, s->white);
254304 xpos += strlen(buffer) * 8;
255305 }
@@ -258,6 +308,19 @@ static void draw_items(AVFilterContext *ctx, AVFrame *out, · 2 unmodified lines
258308 drawtext(out, xpos, ypos, buffer, s->blue);
259309 xpos += strlen(buffer) * 8;
260310 }
311+
312+ s->cache[s->cache_index].previous_pts_us = l->current_pts_us;
313+
314+ if (s->cache_index + 1 >= s->cache_size / sizeof(*(s->cache))) {
315+ void *ptr = av_fast_realloc(s->cache, &s->cache_size, s->cache_size * 2);
316+
317+ if (!ptr)
318+ return AVERROR(ENOMEM);
319+ s->cache = ptr;
320+ }
321+ s->cache_index++;
322+
323+ return 0;
261324 }
262325
263326 static int create_frame(AVFilterContext *ctx, int64_t pts)
@@ -265,7 +328,7 @@ static int create_frame(AVFilterContext *ctx, int64_t pts) · 1 unmodified line
265328 GraphMonitorContext *s = ctx->priv;
266329 AVFilterLink *outlink = ctx->outputs[0];
267330 AVFrame *out;
268− int xpos, ypos = 0;
331+ int ret, xpos, ypos = 0;
269332
270333 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
271334 if (!out)
@@ -273,6 +336,8 @@ static int create_frame(AVFilterContext *ctx, int64_t pts) · 1 unmodified line
273336
274337 clear_image(s, out, outlink);
275338
339+ s->cache_index = 0;
340+
276341 for (int i = 0; i < ctx->graph->nb_filters; i++) {
277342 AVFilterContext *filter = ctx->graph->filters[i];
278343 char buffer[1024] = { 0 };
@@ -298,7 +363,9 @@ static int create_frame(AVFilterContext *ctx, int64_t pts) · 19 unmodified lines
298363 xpos += strlen(buffer) * 8;
299364 drawtext(out, xpos, ypos, l->src->name, s->white);
300365 xpos += strlen(l->src->name) * 8 + 10;
301− draw_items(ctx, out, xpos, ypos, l, frames);
366+ ret = draw_items(ctx, out, xpos, ypos, l, frames);
367+ if (ret < 0)
368+ goto error;
302369 ypos += 10;
303370 }
304371
@@ -316,7 +383,9 @@ static int create_frame(AVFilterContext *ctx, int64_t pts) · 11 unmodified lines
316383 xpos += strlen(buffer) * 8;
317384 drawtext(out, xpos, ypos, l->dst->name, s->white);
318385 xpos += strlen(l->dst->name) * 8 + 10;
319− draw_items(ctx, out, xpos, ypos, l, frames);
386+ ret = draw_items(ctx, out, xpos, ypos, l, frames);
387+ if (ret < 0)
388+ goto error;
320389 ypos += 10;
321390 }
322391 ypos += 5;
@@ -325,6 +394,9 @@ static int create_frame(AVFilterContext *ctx, int64_t pts) · 2 unmodified lines
325394 out->pts = pts;
326395 s->pts = pts + 1;
327396 return ff_filter_frame(outlink, out);
397+error:
398+ av_frame_free(&out);
399+ return ret;
328400 }
329401
330402 static int activate(AVFilterContext *ctx)
@@ -386,6 +458,14 @@ static int config_output(AVFilterLink *outlink) · 55 unmodified lines
386458 return 0;
387459 }
388460
461+static av_cold void uninit(AVFilterContext *ctx)
462+{
463+ GraphMonitorContext *s = ctx->priv;
464+
465+ av_freep(&s->cache);
466+ s->cache_size = s->cache_index = 0;
467+}
468+
389469 AVFILTER_DEFINE_CLASS_EXT(graphmonitor, "(a)graphmonitor", graphmonitor_options);
390470
391471 #if CONFIG_GRAPHMONITOR_FILTER
@@ -410,6 +490,8 @@ const AVFilter ff_vf_graphmonitor = { · 18 unmodified lines
410490 .description = NULL_IF_CONFIG_SMALL("Show various filtergraph stats."),
411491 .priv_size = sizeof(GraphMonitorContext),
412492 .priv_class = &graphmonitor_class,
493+ .init = init,
494+ .uninit = uninit,
413495 .activate = activate,
414496 FILTER_INPUTS(graphmonitor_inputs),
415497 FILTER_OUTPUTS(graphmonitor_outputs),
@@ -440,6 +522,8 @@ const AVFilter ff_avf_agraphmonitor = { · 24 unmodified lines
440522 .description = NULL_IF_CONFIG_SMALL("Show various filtergraph stats."),
441523 .priv_class = &graphmonitor_class,
442524 .priv_size = sizeof(GraphMonitorContext),
525+ .init = init,
526+ .uninit = uninit,
443527 .activate = activate,
444528 FILTER_INPUTS(agraphmonitor_inputs),
445529 FILTER_OUTPUTS(agraphmonitor_outputs),

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t