FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/avfilter_internal.h
Date: 2026-10-31 18:41:55
Exec Total Coverage
Lines: 6 6 100.0%
Functions: 3 3 100.0%
Branches: 0 0 -%

Line Branch Exec Source
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 /*
20 * APIs internal to the generic filter(graph) layer.
21 *
22 * MUST NOT be included by individual filters.
23 */
24
25 #ifndef AVFILTER_AVFILTER_INTERNAL_H
26 #define AVFILTER_AVFILTER_INTERNAL_H
27
28 #include <stdint.h>
29
30 #include "libavutil/framepool.h"
31
32 #include "avfilter.h"
33 #include "filters.h"
34 #include "framequeue.h"
35
36 typedef struct FilterLinkInternal {
37 FilterLink l;
38
39 /**
40 * Pool of frames used for allocations.
41 */
42 FFFramePool frame_pool;
43
44 /**
45 * Queue of frames waiting to be filtered.
46 */
47 FFFrameQueue fifo;
48
49 /**
50 * Format and size of the video frames the link was configured with.
51 */
52 int cfg_format, cfg_w, cfg_h;
53
54 /**
55 * If set, the source filter can not generate a frame as is.
56 * The goal is to avoid repeatedly calling the request_frame() method on
57 * the same link.
58 */
59 int frame_blocked_in;
60
61 /**
62 * Link input status.
63 * If not zero, all attempts of filter_frame will fail with the
64 * corresponding code.
65 */
66 int status_in;
67
68 /**
69 * Timestamp of the input status change.
70 */
71 int64_t status_in_pts;
72
73 /**
74 * Link output status.
75 * If not zero, all attempts of request_frame will fail with the
76 * corresponding code.
77 */
78 int status_out;
79
80 /**
81 * True if a frame is currently wanted on the output of this filter.
82 * Set when ff_request_frame() is called by the output,
83 * cleared when a frame is filtered.
84 */
85 int frame_wanted_out;
86
87 /**
88 * Index in the age array.
89 */
90 int age_index;
91
92 /** stage of the initialization of the link properties (dimensions, etc) */
93 enum {
94 AVLINK_UNINIT = 0, ///< not started
95 AVLINK_STARTINIT, ///< started, but incomplete
96 AVLINK_INIT ///< complete
97 } init_state;
98 } FilterLinkInternal;
99
100 37879304 static inline FilterLinkInternal *ff_link_internal(AVFilterLink *link)
101 {
102 37879304 return (FilterLinkInternal*)link;
103 }
104
105 typedef struct FFFilterContext {
106 /**
107 * The public AVFilterContext. See avfilter.h for it.
108 */
109 AVFilterContext p;
110
111 avfilter_execute_func *execute;
112
113 // AV_CLASS_STATE_FLAG_*
114 unsigned state_flags;
115
116 /**
117 * Ready status of the filter.
118 * A non-0 value means that the filter needs activating;
119 * a higher value suggests a more urgent activation.
120 */
121 unsigned ready;
122
123 /// parsed expression
124 struct AVExpr *enable;
125 /// variable values for the enable expression
126 double *var_values;
127
128 struct AVFilterCommand *command_queue;
129 } FFFilterContext;
130
131 45619875 static inline FFFilterContext *fffilterctx(AVFilterContext *ctx)
132 {
133 45619875 return (FFFilterContext*)ctx;
134 }
135
136 typedef struct AVFilterCommand {
137 double time; ///< time expressed in seconds
138 char *command; ///< command
139 char *arg; ///< optional argument for the command
140 int flags;
141 struct AVFilterCommand *next;
142 } AVFilterCommand;
143
144 typedef struct FFFilterGraph {
145 /**
146 * The public AVFilterGraph. See avfilter.h for it.
147 */
148 AVFilterGraph p;
149
150 struct FilterLinkInternal **sink_links;
151 int sink_links_count;
152
153 unsigned disable_auto_convert;
154
155 void *thread;
156 avfilter_execute_func *thread_execute;
157 FFFrameQueueGlobal frame_queues[AVMEDIA_TYPE_NB];
158 /* set by avfilter_graph_set_max_buffered_frames() */
159 uint8_t max_queued_set[AVMEDIA_TYPE_NB];
160 } FFFilterGraph;
161
162 1119618 static inline FFFilterGraph *fffiltergraph(AVFilterGraph *graph)
163 {
164 1119618 return (FFFilterGraph*)graph;
165 }
166
167 /**
168 * Update the position of a link in the age heap.
169 */
170 void ff_avfilter_graph_update_heap(AVFilterGraph *graph,
171 struct FilterLinkInternal *li);
172
173 /**
174 * Allocate a new filter context and return it.
175 *
176 * @param filter what filter to create an instance of
177 * @param inst_name name to give to the new filter context
178 *
179 * @return newly created filter context or NULL on failure
180 */
181 AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name);
182
183 /**
184 * Remove a filter from a graph;
185 */
186 void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter);
187
188 int ff_filter_activate(AVFilterContext *filter);
189
190 /**
191 * Parse filter options into a dictionary.
192 *
193 * @param logctx context for logging
194 * @param priv_class a filter's private class for shorthand options or NULL
195 * @param options dictionary to store parsed options in
196 * @param args options string to parse
197 *
198 * @return a non-negative number on success, a negative error code on failure
199 */
200 int ff_filter_opt_parse(void *logctx, const AVClass *priv_class,
201 AVDictionary **options, const char *args);
202
203 int ff_graph_thread_init(FFFilterGraph *graph);
204
205 void ff_graph_thread_free(FFFilterGraph *graph);
206
207 /**
208 * Negotiate the media format, dimensions, etc of all inputs to a filter.
209 *
210 * @param filter the filter to negotiate the properties for its inputs
211 * @return zero on successful negotiation
212 */
213 int ff_filter_config_links(AVFilterContext *filter);
214
215 /* misc trace functions */
216
217 #define FF_TPRINTF_START(ctx, func) ff_tlog(NULL, "%-16s: ", #func)
218
219 #ifdef TRACE
220 void ff_tlog_link(void *ctx, AVFilterLink *link, int end);
221 #else
222 #define ff_tlog_link(ctx, link, end) do { } while(0)
223 #endif
224
225 /**
226 * Run one round of processing on a filter graph.
227 */
228 int ff_filter_graph_run_once(AVFilterGraph *graph);
229
230 /**
231 * Process the commands queued in the link up to the time of the frame.
232 * Commands will trigger the process_command() callback.
233 * @return >= 0 or AVERROR code.
234 */
235 int ff_inlink_process_commands(AVFilterLink *link, const AVFrame *frame);
236
237 #endif /* AVFILTER_AVFILTER_INTERNAL_H */
238