h264_metadata: Add option to delete filler data
[libav.git] / libavfilter / internal.h
CommitLineData
9f0e31d2 1/*
2912e87a 2 * This file is part of Libav.
9f0e31d2 3 *
2912e87a 4 * Libav is free software; you can redistribute it and/or
9f0e31d2
SS
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 *
2912e87a 9 * Libav is distributed in the hope that it will be useful,
9f0e31d2
SS
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
2912e87a 15 * License along with Libav; if not, write to the Free Software
9f0e31d2
SS
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
7950e519 27#include "libavutil/internal.h"
9f0e31d2 28#include "avfilter.h"
129bb238 29#include "thread.h"
45dd1ae1 30#include "version.h"
4fcbb2af 31
9d0bfc50
AK
32/**
33 * A filter pad used for either input or output.
34 */
35struct AVFilterPad {
36 /**
37 * Pad name. The name is unique among inputs and among outputs, but an
38 * input may have the same name as an output. This may be NULL if this
39 * pad has no need to ever be referenced by name.
40 */
41 const char *name;
42
43 /**
44 * AVFilterPad type.
45 */
46 enum AVMediaType type;
47
48 /**
9d0bfc50
AK
49 * Callback function to get a video buffer. If NULL, the filter system will
50 * use avfilter_default_get_video_buffer().
51 *
52 * Input video pads only.
53 */
7e350379 54 AVFrame *(*get_video_buffer)(AVFilterLink *link, int w, int h);
9d0bfc50
AK
55
56 /**
57 * Callback function to get an audio buffer. If NULL, the filter system will
58 * use avfilter_default_get_audio_buffer().
59 *
60 * Input audio pads only.
61 */
7e350379 62 AVFrame *(*get_audio_buffer)(AVFilterLink *link, int nb_samples);
9d0bfc50
AK
63
64 /**
565e4993
AK
65 * Filtering callback. This is where a filter receives a frame with
66 * audio/video data and should do its processing.
9d0bfc50 67 *
565e4993 68 * Input pads only.
cd991462
AK
69 *
70 * @return >= 0 on success, a negative AVERROR on error. This function
71 * must ensure that samplesref is properly unreferenced on error if it
72 * hasn't been passed on to another filter.
9d0bfc50 73 */
7e350379 74 int (*filter_frame)(AVFilterLink *link, AVFrame *frame);
9d0bfc50
AK
75
76 /**
77 * Frame poll callback. This returns the number of immediately available
78 * samples. It should return a positive value if the next request_frame()
79 * is guaranteed to return one frame (with no delay).
80 *
81 * Defaults to just calling the source poll_frame() method.
82 *
83 * Output pads only.
84 */
85 int (*poll_frame)(AVFilterLink *link);
86
87 /**
88 * Frame request callback. A call to this should result in at least one
89 * frame being output over the given link. This should return zero on
90 * success, and another value on error.
91 *
92 * Output pads only.
93 */
94 int (*request_frame)(AVFilterLink *link);
95
96 /**
97 * Link configuration callback.
98 *
99 * For output pads, this should set the link properties such as
100 * width/height. This should NOT set the format property - that is
101 * negotiated between filters by the filter system using the
102 * query_formats() callback before this function is called.
103 *
104 * For input pads, this should check the properties of the link, and update
105 * the filter's internal state as necessary.
106 *
107 * For both input and output filters, this should return zero on success,
108 * and another value on error.
109 */
110 int (*config_props)(AVFilterLink *link);
58b049f2
AK
111
112 /**
113 * The filter expects a fifo to be inserted on its input link,
114 * typically because it has a delay.
115 *
116 * input pads only.
117 */
118 int needs_fifo;
5655732c
VG
119
120 /**
121 * The filter expects writable frames from its input link,
122 * duplicating data buffers if needed.
123 *
124 * input pads only.
125 */
126 int needs_writable;
9d0bfc50 127};
9d0bfc50 128
129bb238
AK
129struct AVFilterGraphInternal {
130 void *thread;
0767bfd1 131 avfilter_execute_func *thread_execute;
129bb238
AK
132};
133
134struct AVFilterInternal {
0767bfd1 135 avfilter_execute_func *execute;
129bb238
AK
136};
137
8fe0c527
SS
138/** Tell is a format is contained in the provided list terminated by -1. */
139int ff_fmt_is_in(int fmt, const int *fmts);
140
1a3eb042 141#define FF_DPRINTF_START(ctx, func) av_log(NULL, AV_LOG_TRACE, "%-16s: ", #func)
0b45334a
AK
142
143void ff_dlog_link(void *ctx, AVFilterLink *link, int end);
144
fa417fcd
AK
145/**
146 * Insert a new pad.
147 *
148 * @param idx Insertion point. Pad is inserted at the end if this point
149 * is beyond the end of the list of pads.
150 * @param count Pointer to the number of pads in the list
151 * @param padidx_off Offset within an AVFilterLink structure to the element
152 * to increment when inserting a new pad causes link
153 * numbering to change
154 * @param pads Pointer to the pointer to the beginning of the list of pads
155 * @param links Pointer to the pointer to the beginning of the list of links
156 * @param newpad The new pad to add. A copy is made when adding.
157 */
158void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
159 AVFilterPad **pads, AVFilterLink ***links,
160 AVFilterPad *newpad);
161
162/** Insert a new input pad for the filter. */
163static inline void ff_insert_inpad(AVFilterContext *f, unsigned index,
164 AVFilterPad *p)
165{
9baeff95 166 ff_insert_pad(index, &f->nb_inputs, offsetof(AVFilterLink, dstpad),
fa417fcd
AK
167 &f->input_pads, &f->inputs, p);
168}
169
170/** Insert a new output pad for the filter. */
171static inline void ff_insert_outpad(AVFilterContext *f, unsigned index,
172 AVFilterPad *p)
173{
9baeff95 174 ff_insert_pad(index, &f->nb_outputs, offsetof(AVFilterLink, srcpad),
fa417fcd
AK
175 &f->output_pads, &f->outputs, p);
176}
177
803391f7
AK
178/**
179 * Poll a frame from the filter chain.
180 *
181 * @param link the input link
182 * @return the number of immediately available frames, a negative
183 * number in case of error
184 */
185int ff_poll_frame(AVFilterLink *link);
186
187/**
188 * Request an input frame from the filter at the other end of the link.
189 *
190 * @param link the input link
191 * @return zero on success
192 */
193int ff_request_frame(AVFilterLink *link);
194
565e4993
AK
195/**
196 * Send a frame of data to the next filter.
197 *
198 * @param link the output link over which the data is being sent
199 * @param frame a reference to the buffer of data being sent. The
200 * receiving filter will free this reference when it no longer
201 * needs it or pass it on to the next filter.
202 *
203 * @return >= 0 on success, a negative AVERROR on error. The receiving filter
204 * is responsible for unreferencing frame in case of error.
205 */
7e350379 206int ff_filter_frame(AVFilterLink *link, AVFrame *frame);
565e4993 207
bc1a985b
AK
208/**
209 * Allocate a new filter context and return it.
210 *
211 * @param filter what filter to create an instance of
212 * @param inst_name name to give to the new filter context
213 *
214 * @return newly created filter context or NULL on failure
215 */
216AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name);
217
1565cbc6
AK
218/**
219 * Remove a filter from a graph;
220 */
221void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter);
222
e3fb74f7
MT
223/**
224 * The filter is aware of hardware frames, and any hardware frame context
225 * should not be automatically propagated through it.
226 */
227#define FF_FILTER_FLAG_HWFRAME_AWARE (1 << 0)
228
6d86cef0
MT
229/**
230 * Perform any additional setup required for hardware frames.
231 *
232 * link->hw_frames_ctx must be set before calling this function.
233 * Inside link->hw_frames_ctx, the fields format, sw_format, width and
234 * height must be set. If dynamically allocated pools are not supported,
235 * then initial_pool_size must also be set, to the minimum hardware frame
236 * pool size necessary for the filter to work (taking into account any
237 * frames which need to stored for use in operations as appropriate). If
238 * default_pool_size is nonzero, then it will be used as the pool size if
239 * no other modification takes place (this can be used to preserve
240 * compatibility).
241 */
242int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link,
243 int default_pool_size);
244
245
153382e1 246#endif /* AVFILTER_INTERNAL_H */