libavfilter/internal.h
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 #ifndef AVFILTER_INTERNAL_H
20 #define AVFILTER_INTERNAL_H
21 
22 /**
23  * @file
24  * internal API functions
25  */
26 
27 #include "avfilter.h"
28 #include "avfiltergraph.h"
29 #include "formats.h"
30 #include "video.h"
31 
32 #define POOL_SIZE 32
33 typedef struct AVFilterPool {
34  AVFilterBufferRef *pic[POOL_SIZE];
35  int count;
36  int refcount;
37  int draining;
38 } AVFilterPool;
39 
40 typedef struct AVFilterCommand {
41  double time; ///< time expressed in seconds
42  char *command; ///< command
43  char *arg; ///< optional argument for the command
44  int flags;
47 
48 /**
49  * Update the position of a link in the age heap.
50  */
52 
53 #if !FF_API_AVFILTERPAD_PUBLIC
54 /**
55  * A filter pad used for either input or output.
56  */
57 struct AVFilterPad {
58  /**
59  * Pad name. The name is unique among inputs and among outputs, but an
60  * input may have the same name as an output. This may be NULL if this
61  * pad has no need to ever be referenced by name.
62  */
63  const char *name;
64 
65  /**
66  * AVFilterPad type.
67  */
69 
70  /**
71  * Callback function to get a video buffer. If NULL, the filter system will
72  * use ff_default_get_video_buffer().
73  *
74  * Input video pads only.
75  */
76  AVFrame *(*get_video_buffer)(AVFilterLink *link, int w, int h);
77 
78  /**
79  * Callback function to get an audio buffer. If NULL, the filter system will
80  * use ff_default_get_audio_buffer().
81  *
82  * Input audio pads only.
83  */
84  AVFrame *(*get_audio_buffer)(AVFilterLink *link, int nb_samples);
85 
86  /**
87  * Filtering callback. This is where a filter receives a frame with
88  * audio/video data and should do its processing.
89  *
90  * Input pads only.
91  *
92  * @return >= 0 on success, a negative AVERROR on error. This function
93  * must ensure that samplesref is properly unreferenced on error if it
94  * hasn't been passed on to another filter.
95  */
97 
98  /**
99  * Frame poll callback. This returns the number of immediately available
100  * samples. It should return a positive value if the next request_frame()
101  * is guaranteed to return one frame (with no delay).
102  *
103  * Defaults to just calling the source poll_frame() method.
104  *
105  * Output pads only.
106  */
108 
109  /**
110  * Frame request callback. A call to this should result in at least one
111  * frame being output over the given link. This should return zero on
112  * success, and another value on error.
113  *
114  * Output pads only.
115  */
117 
118  /**
119  * Link configuration callback.
120  *
121  * For output pads, this should set the link properties such as
122  * width/height. This should NOT set the format property - that is
123  * negotiated between filters by the filter system using the
124  * query_formats() callback before this function is called.
125  *
126  * For input pads, this should check the properties of the link, and update
127  * the filter's internal state as necessary.
128  *
129  * For both input and output filters, this should return zero on success,
130  * and another value on error.
131  */
133 
134  /**
135  * The filter expects a fifo to be inserted on its input link,
136  * typically because it has a delay.
137  *
138  * input pads only.
139  */
141 };
142 #endif
143 
144 /** default handler for freeing audio/video buffer when there are no references left */
145 void ff_avfilter_default_free_buffer(AVFilterBuffer *buf);
146 
147 /** Tell is a format is contained in the provided list terminated by -1. */
148 int ff_fmt_is_in(int fmt, const int *fmts);
149 
150 /**
151  * Return a copy of a list of integers terminated by -1, or NULL in
152  * case of copy failure.
153  */
154 int *ff_copy_int_list(const int * const list);
155 
156 /**
157  * Return a copy of a list of 64-bit integers, or NULL in case of
158  * copy failure.
159  */
160 int64_t *ff_copy_int64_list(const int64_t * const list);
161 
162 /* Functions to parse audio format arguments */
163 
164 /**
165  * Parse a pixel format.
166  *
167  * @param ret pixel format pointer to where the value should be written
168  * @param arg string to parse
169  * @param log_ctx log context
170  * @return 0 in case of success, a negative AVERROR code on error
171  */
172 int ff_parse_pixel_format(enum AVPixelFormat *ret, const char *arg, void *log_ctx);
173 
174 /**
175  * Parse a sample rate.
176  *
177  * @param ret unsigned integer pointer to where the value should be written
178  * @param arg string to parse
179  * @param log_ctx log context
180  * @return 0 in case of success, a negative AVERROR code on error
181  */
182 int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx);
183 
184 /**
185  * Parse a time base.
186  *
187  * @param ret unsigned AVRational pointer to where the value should be written
188  * @param arg string to parse
189  * @param log_ctx log context
190  * @return 0 in case of success, a negative AVERROR code on error
191  */
192 int ff_parse_time_base(AVRational *ret, const char *arg, void *log_ctx);
193 
194 /**
195  * Parse a sample format name or a corresponding integer representation.
196  *
197  * @param ret integer pointer to where the value should be written
198  * @param arg string to parse
199  * @param log_ctx log context
200  * @return 0 in case of success, a negative AVERROR code on error
201  */
202 int ff_parse_sample_format(int *ret, const char *arg, void *log_ctx);
203 
204 /**
205  * Parse a channel layout or a corresponding integer representation.
206  *
207  * @param ret 64bit integer pointer to where the value should be written.
208  * @param arg string to parse
209  * @param log_ctx log context
210  * @return 0 in case of success, a negative AVERROR code on error
211  */
212 int ff_parse_channel_layout(int64_t *ret, const char *arg, void *log_ctx);
213 
214 void ff_update_link_current_pts(AVFilterLink *link, int64_t pts);
215 
217 
218 /* misc trace functions */
219 
220 /* #define FF_AVFILTER_TRACE */
221 
222 #ifdef FF_AVFILTER_TRACE
223 # define ff_tlog(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
224 #else
225 # define ff_tlog(pctx, ...) do { if (0) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__); } while (0)
226 #endif
227 
228 #define FF_TPRINTF_START(ctx, func) ff_tlog(NULL, "%-16s: ", #func)
229 
230 char *ff_get_ref_perms_string(char *buf, size_t buf_size, int perms);
231 
232 void ff_tlog_ref(void *ctx, AVFrame *ref, int end);
233 
234 void ff_tlog_link(void *ctx, AVFilterLink *link, int end);
235 
236 /**
237  * Insert a new pad.
238  *
239  * @param idx Insertion point. Pad is inserted at the end if this point
240  * is beyond the end of the list of pads.
241  * @param count Pointer to the number of pads in the list
242  * @param padidx_off Offset within an AVFilterLink structure to the element
243  * to increment when inserting a new pad causes link
244  * numbering to change
245  * @param pads Pointer to the pointer to the beginning of the list of pads
246  * @param links Pointer to the pointer to the beginning of the list of links
247  * @param newpad The new pad to add. A copy is made when adding.
248  */
249 void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
250  AVFilterPad **pads, AVFilterLink ***links,
251  AVFilterPad *newpad);
252 
253 /** Insert a new input pad for the filter. */
254 static inline void ff_insert_inpad(AVFilterContext *f, unsigned index,
255  AVFilterPad *p)
256 {
257  ff_insert_pad(index, &f->nb_inputs, offsetof(AVFilterLink, dstpad),
258  &f->input_pads, &f->inputs, p);
259 #if FF_API_FOO_COUNT
260  f->input_count = f->nb_inputs;
261 #endif
262 }
263 
264 /** Insert a new output pad for the filter. */
265 static inline void ff_insert_outpad(AVFilterContext *f, unsigned index,
266  AVFilterPad *p)
267 {
268  ff_insert_pad(index, &f->nb_outputs, offsetof(AVFilterLink, srcpad),
269  &f->output_pads, &f->outputs, p);
270 #if FF_API_FOO_COUNT
271  f->output_count = f->nb_outputs;
272 #endif
273 }
274 
275 /**
276  * Poll a frame from the filter chain.
277  *
278  * @param link the input link
279  * @return the number of immediately available frames, a negative
280  * number in case of error
281  */
283 
284 /**
285  * Request an input frame from the filter at the other end of the link.
286  *
287  * @param link the input link
288  * @return zero on success
289  */
290 int ff_request_frame(AVFilterLink *link);
291 
292 #define AVFILTER_DEFINE_CLASS(fname) \
293  static const AVClass fname##_class = { \
294  .class_name = #fname, \
295  .item_name = av_default_item_name, \
296  .option = fname##_options, \
297  .version = LIBAVUTIL_VERSION_INT, \
298  .category = AV_CLASS_CATEGORY_FILTER, \
299  }
300 
301 AVFilterBufferRef *ff_copy_buffer_ref(AVFilterLink *outlink,
302  AVFilterBufferRef *ref);
303 
304 /**
305  * Find the index of a link.
306  *
307  * I.e. find i such that link == ctx->(in|out)puts[i]
308  */
309 #define FF_INLINK_IDX(link) ((int)((link)->dstpad - (link)->dst->input_pads))
310 #define FF_OUTLINK_IDX(link) ((int)((link)->srcpad - (link)->src->output_pads))
311 
312 int ff_buffersink_read_compat(AVFilterContext *ctx, AVFilterBufferRef **buf);
313 int ff_buffersink_read_samples_compat(AVFilterContext *ctx, AVFilterBufferRef **pbuf,
314  int nb_samples);
315 /**
316  * Send a frame of data to the next filter.
317  *
318  * @param link the output link over which the data is being sent
319  * @param frame a reference to the buffer of data being sent. The
320  * receiving filter will free this reference when it no longer
321  * needs it or pass it on to the next filter.
322  *
323  * @return >= 0 on success, a negative AVERROR on error. The receiving filter
324  * is responsible for unreferencing frame in case of error.
325  */
327 
328 /**
329  * Flags for AVFilterLink.flags.
330  */
331 enum {
332 
333  /**
334  * Frame requests may need to loop in order to be fulfilled.
335  * A filter must set this flags on an output link if it may return 0 in
336  * request_frame() without filtering a frame.
337  */
339 
340 };
341 
342 /**
343  * Allocate a new filter context and return it.
344  *
345  * @param filter what filter to create an instance of
346  * @param inst_name name to give to the new filter context
347  *
348  * @return newly created filter context or NULL on failure
349  */
350 AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name);
351 
352 /**
353  * Remove a filter from a graph;
354  */
356 
357 #endif /* AVFILTER_INTERNAL_H */
struct AVFilterCommand AVFilterCommand
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:964
FIXME Range Coding of cr are ref
Definition: snow.txt:367
const char * fmt
Definition: avisynth_c.h:669
external API header
Sinusoidal phase f
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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 list
output residual component w
void ff_avfilter_graph_update_heap(AVFilterGraph *graph, AVFilterLink *link)
Update the position of a link in the age heap.
const char * name
Pad name.
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:532
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:538
int ff_fmt_is_in(int fmt, const int *fmts)
Tell is a format is contained in the provided list terminated by -1.
Definition: formats.c:254
end end
static int poll_frame(AVFilterLink *link)
Definition: buffersrc.c:492
int ff_parse_pixel_format(enum AVPixelFormat *ret, const char *arg, void *log_ctx)
Parse a pixel format.
Definition: formats.c:579
#define POOL_SIZE
the mask is usually to keep the same permissions Filters should remove permissions on reference they give to output whenever necessary It can be automatically done by setting the rej_perms field on the output pad Here are a few guidelines corresponding to common 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
frame
Definition: stft.m:14
void ff_update_link_current_pts(AVFilterLink *link, int64_t pts)
Definition: avfilter.c:368
A filter pad used for either input or output.
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:531
int ff_parse_channel_layout(int64_t *ret, const char *arg, void *log_ctx)
Parse a channel layout or a corresponding integer representation.
Definition: formats.c:632
struct AVFilterPool AVFilterPool
unsigned nb_outputs
number of output pads
Definition: avfilter.h:543
int ff_parse_time_base(AVRational *ret, const char *arg, void *log_ctx)
Parse a time base.
Definition: formats.c:609
const char * arg
int64_t * ff_copy_int64_list(const int64_t *const list)
Return a copy of a list of 64-bit integers, or NULL in case of copy failure.
Definition: formats.c:284
void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off, AVFilterPad **pads, AVFilterLink ***links, AVFilterPad *newpad)
Insert a new pad.
Definition: avfilter.c:93
AVFilterBufferRef * ff_copy_buffer_ref(AVFilterLink *outlink, AVFilterBufferRef *ref)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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 link
static int config_props(AVFilterLink *link)
Definition: af_asyncts.c:83
static int request_frame(AVFilterLink *outlink)
Definition: af_amerge.c:172
unsigned nb_inputs
number of input pads
Definition: avfilter.h:536
struct AVFilterCommand * next
ret
Definition: avfilter.c:821
static void ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new output pad for the filter.
int ff_buffersink_read_compat(AVFilterContext *ctx, AVFilterBufferRef **buf)
void ff_command_queue_pop(AVFilterContext *filter)
Definition: avfilter.c:84
char * ff_get_ref_perms_string(char *buf, size_t buf_size, int perms)
void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter)
Remove a filter from a graph;.
Definition: avfiltergraph.c:62
void * buf
Definition: avisynth_c.h:594
Filter definition.
Definition: avfilter.h:436
int index
Definition: gxfenc.c:89
rational number numerator/denominator
Definition: rational.h:43
AVMediaType
Definition: avutil.h:141
AVFilterBufferRef * pic[POOL_SIZE]
#define type
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:539
int ff_buffersink_read_samples_compat(AVFilterContext *ctx, AVFilterBufferRef **pbuf, int nb_samples)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output links
void ff_avfilter_default_free_buffer(AVFilterBuffer *buf)
default handler for freeing audio/video buffer when there are no references left
int ff_parse_sample_format(int *ret, const char *arg, void *log_ctx)
Parse a sample format name or a corresponding integer representation.
Definition: formats.c:594
static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref)
Definition: af_aconvert.c:140
void ff_tlog_ref(void *ctx, AVFrame *ref, int end)
Definition: avfilter.c:40
void ff_tlog_link(void *ctx, AVFilterLink *link, int end)
Definition: avfilter.c:295
static void ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.
int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx)
Parse a sample rate.
Definition: formats.c:620
An instance of a filter.
Definition: avfilter.h:524
int ff_poll_frame(AVFilterLink *link)
Poll a frame from the filter chain.
Definition: avfilter.c:350
AVFilterContext * ff_filter_alloc(const AVFilter *filter, const char *inst_name)
Allocate a new filter context and return it.
Definition: avfilter.c:495
double time
time expressed in seconds
int needs_fifo
The filter expects a fifo to be inserted on its input link, typically because it has a delay...
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:319
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
Frame requests may need to loop in order to be fulfilled.
char * command
command
int * ff_copy_int_list(const int *const list)
Return a copy of a list of integers terminated by -1, or NULL in case of copy failure.
Definition: formats.c:277
char * arg
optional argument for the command