FFmpeg
Loading...
Searching...
No Matches
f_bench.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include "config_components.h"
20
21#include "libavutil/opt.h"
22#include "libavutil/time.h"
23#include "audio.h"
24#include "avfilter.h"
25#include "filters.h"
26#include "video.h"
27
33
34typedef struct BenchContext {
35 const AVClass *class;
36 int action;
39 int n;
41
42#define OFFSET(x) offsetof(BenchContext, x)
43#define DEFINE_OPTIONS(filt_name, FLAGS) \
44static const AVOption filt_name##_options[] = { \
45 { "action", "set action", OFFSET(action), AV_OPT_TYPE_INT, {.i64=ACTION_START}, 0, NB_ACTION-1, FLAGS, .unit = "action" }, \
46 { "start", "start timer", 0, AV_OPT_TYPE_CONST, {.i64=ACTION_START}, INT_MIN, INT_MAX, FLAGS, .unit = "action" }, \
47 { "stop", "stop timer", 0, AV_OPT_TYPE_CONST, {.i64=ACTION_STOP}, INT_MIN, INT_MAX, FLAGS, .unit = "action" }, \
48 { NULL } \
49}
50
51#define START_TIME_KEY "lavfi.bench.start_time"
52#define T2F(v) ((v) / 1000000.)
53
55{
56 BenchContext *s = ctx->priv;
57 s->min = INT64_MAX;
58 s->max = INT64_MIN;
59 return 0;
60}
61
62static int filter_frame(AVFilterLink *inlink, AVFrame *in)
63{
64 AVFilterContext *ctx = inlink->dst;
65 BenchContext *s = ctx->priv;
66 AVFilterLink *outlink = ctx->outputs[0];
67 const int64_t t = av_gettime();
68
69 if (t < 0)
70 return ff_filter_frame(outlink, in);
71
72 if (s->action == ACTION_START) {
74 } else if (s->action == ACTION_STOP) {
76 if (e) {
77 const int64_t start = strtoll(e->value, NULL, 0);
78 const int64_t diff = t - start;
79 s->sum += diff;
80 s->n++;
81 s->min = FFMIN(s->min, diff);
82 s->max = FFMAX(s->max, diff);
83 av_log(ctx, AV_LOG_INFO, "t:%f avg:%f max:%f min:%f\n",
84 T2F(diff), T2F(s->sum / s->n), T2F(s->max), T2F(s->min));
85 }
87 }
88
89 return ff_filter_frame(outlink, in);
90}
91
92#if CONFIG_BENCH_FILTER
95
96static const AVFilterPad bench_inputs[] = {
97 {
98 .name = "default",
99 .type = AVMEDIA_TYPE_VIDEO,
100 .filter_frame = filter_frame,
101 },
102};
103
104const FFFilter ff_vf_bench = {
105 .p.name = "bench",
106 .p.description = NULL_IF_CONFIG_SMALL("Benchmark part of a filtergraph."),
107 .p.priv_class = &bench_class,
109 .priv_size = sizeof(BenchContext),
110 .init = init,
111 FILTER_INPUTS(bench_inputs),
113};
114#endif /* CONFIG_BENCH_FILTER */
115
116#if CONFIG_ABENCH_FILTER
119
120static const AVFilterPad abench_inputs[] = {
121 {
122 .name = "default",
123 .type = AVMEDIA_TYPE_AUDIO,
124 .filter_frame = filter_frame,
125 },
126};
127
128const FFFilter ff_af_abench = {
129 .p.name = "abench",
130 .p.description = NULL_IF_CONFIG_SMALL("Benchmark part of a filtergraph."),
131 .p.priv_class = &abench_class,
133 .priv_size = sizeof(BenchContext),
134 .init = init,
135 FILTER_INPUTS(abench_inputs),
137};
138#endif /* CONFIG_ABENCH_FILTER */
const FFFilter ff_af_abench
const FFFilter ff_vf_bench
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.
Definition audio.c:34
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1068
Main libavfilter public API header.
#define s(width, name)
Definition cbs_vp9.c:198
#define bench(...)
Definition checkasm.h:138
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition f_bench.c:62
#define T2F(v)
Definition f_bench.c:52
BenchAction
Definition f_bench.c:28
@ NB_ACTION
Definition f_bench.c:31
@ ACTION_STOP
Definition f_bench.c:30
@ ACTION_START
Definition f_bench.c:29
#define DEFINE_OPTIONS(filt_name, FLAGS)
Definition f_bench.c:43
#define START_TIME_KEY
Definition f_bench.c:51
#define AV_OPT_FLAG_FILTERING_PARAM
A generic parameter which can be set by the user for filtering.
Definition opt.h:380
#define AV_OPT_FLAG_AUDIO_PARAM
Definition opt.h:356
#define AV_OPT_FLAG_VIDEO_PARAM
Definition opt.h:357
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
Definition avfilter.h:182
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition dict.c:60
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition dict.c:86
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
Definition dict.c:177
#define AV_LOG_INFO
Standard information.
Definition log.h:221
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define AVFILTER_DEFINE_CLASS(fname)
Definition filters.h:478
#define av_cold
Definition attributes.h:117
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
AVOptions.
Describe the class of an AVClass context structure.
Definition log.h:76
char * value
Definition dict.h:92
An instance of a filter.
Definition avfilter.h:273
A filter pad used for either input or output.
Definition filters.h:40
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
AVDictionary * metadata
metadata.
Definition frame.h:750
int64_t max
Definition f_bench.c:37
int64_t sum
Definition f_bench.c:38
int64_t min
Definition f_bench.c:37
#define av_log(a,...)
int64_t av_gettime(void)
Get the current time in microseconds.
Definition time.c:40
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition video.c:37