FFmpeg
Loading...
Searching...
No Matches
f_latency.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 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 "audio.h"
24#include "avfilter.h"
25#include "filters.h"
26#include "video.h"
27
33
35{
36 LatencyContext *s = ctx->priv;
37
38 s->min_latency = INT64_MAX;
39 s->max_latency = INT64_MIN;
40
41 return 0;
42}
43
45{
46 LatencyContext *s = ctx->priv;
47 AVFilterLink *inlink = ctx->inputs[0];
48 FilterLink *inl = ff_filter_link(inlink);
49 AVFilterLink *outlink = ctx->outputs[0];
50
51 FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
52
53 if (!ctx->is_disabled && ctx->inputs[0]->src &&
54 ctx->inputs[0]->src->nb_inputs > 0) {
55 AVFilterLink *prevlink = ctx->inputs[0]->src->inputs[0];
56 FilterLink *prevl = ff_filter_link(prevlink);
57 int64_t delta = 0;
58
59 switch (prevlink->type) {
62 break;
64 delta = prevl->frame_count_in - inl->frame_count_out;
65 break;
66 }
67
68 if (delta > 0) {
69 s->min_latency = FFMIN(s->min_latency, delta);
70 s->max_latency = FFMAX(s->max_latency, delta);
71 }
72 }
73
74 if (ff_inlink_queued_frames(inlink)) {
76 int ret;
77
78 ret = ff_inlink_consume_frame(inlink, &frame);
79 if (ret < 0)
80 return ret;
81 if (ret > 0)
82 return ff_filter_frame(outlink, frame);
83 }
84
85 FF_FILTER_FORWARD_STATUS(inlink, outlink);
86 FF_FILTER_FORWARD_WANTED(outlink, inlink);
87
88 return FFERROR_NOT_READY;
89}
90
92{
93 LatencyContext *s = ctx->priv;
94
95 if (s->min_latency != INT64_MAX)
96 av_log(ctx, AV_LOG_INFO, "Min latency: %"PRId64"\n", s->min_latency);
97 if (s->max_latency != INT64_MIN)
98 av_log(ctx, AV_LOG_INFO, "Max latency: %"PRId64"\n", s->max_latency);
99}
100
101#if CONFIG_LATENCY_FILTER
102
103const FFFilter ff_vf_latency = {
104 .p.name = "latency",
105 .p.description = NULL_IF_CONFIG_SMALL("Report video filtering latency."),
108 .priv_size = sizeof(LatencyContext),
109 .init = init,
110 .uninit = uninit,
114};
115
116#endif // CONFIG_LATENCY_FILTER
117
118#if CONFIG_ALATENCY_FILTER
119
120const FFFilter ff_af_alatency = {
121 .p.name = "alatency",
122 .p.description = NULL_IF_CONFIG_SMALL("Report audio filtering latency."),
124 .priv_size = sizeof(LatencyContext),
125 .init = init,
126 .uninit = uninit,
130};
131#endif // CONFIG_ALATENCY_FILTER
const FFFilter ff_af_alatency
const FFFilter ff_vf_latency
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
size_t ff_inlink_queued_frames(AVFilterLink *link)
Get the number of frames available on the link.
Definition avfilter.c:1483
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:1520
Main libavfilter public API header.
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static AVFrame * frame
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
static int activate(AVFilterContext *ctx)
Definition f_latency.c:44
static av_cold void uninit(AVFilterContext *ctx)
Definition f_latency.c:91
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
Definition avfilter.h:204
#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
#define AV_LOG_INFO
Standard information.
Definition log.h:221
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define FF_FILTER_FORWARD_WANTED(outlink, inlink)
Forward the frame_wanted_out flag from an output link to an input link.
Definition filters.h:694
#define FF_FILTER_FORWARD_STATUS(inlink, outlink)
Acknowledge the status on an input link and forward it to an output link.
Definition filters.h:666
#define FFERROR_NOT_READY
Filters implementation helper functions and internal structures.
Definition filters.h:34
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
Definition filters.h:639
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition filters.h:199
#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
An instance of a filter.
Definition avfilter.h:273
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
int64_t max_latency
Definition f_latency.c:30
int64_t sum
Definition f_latency.c:31
int64_t min_latency
Definition f_latency.c:29
#define av_log(a,...)
static AVFormatContext * ctx
Definition movenc.c:49
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
float delta