FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
filters.h
Go to the documentation of this file.
1 /*
2  * Filters implementation helper functions
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 License
8  * 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
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef AVFILTER_FILTERS_H
22 #define AVFILTER_FILTERS_H
23 
24 /**
25  * Filters implementation helper functions
26  */
27 
28 #include "avfilter.h"
29 #include "internal.h"
30 
31 /**
32  * Special return code when activate() did not do anything.
33  */
34 #define FFERROR_NOT_READY FFERRTAG('N','R','D','Y')
35 
36 /**
37  * Mark a filter ready and schedule it for activation.
38  *
39  * This is automatically done when something happens to the filter (queued
40  * frame, status change, request on output).
41  * Filters implementing the activate callback can call it directly to
42  * perform one more round of processing later.
43  * It is also useful for filters reacting to external or asynchronous
44  * events.
45  */
46 void ff_filter_set_ready(AVFilterContext *filter, unsigned priority);
47 
48 /**
49  * Process the commands queued in the link up to the time of the frame.
50  * Commands will trigger the process_command() callback.
51  * @return >= 0 or AVERROR code.
52  */
54 
55 /**
56  * Evaluate the timeline expression of the link for the time and properties
57  * of the frame.
58  * @return >0 if enabled, 0 if disabled
59  * @note It does not update link->dst->is_disabled.
60  */
62 
63 /**
64  * Test if a frame is available on the link.
65  * @return >0 if a frame is available
66  */
68 
69 /**
70  * Test if enough samples are available on the link.
71  * @return >0 if enough samples are available
72  * @note on EOF and error, min becomes 1
73  */
75 
76 /**
77  * Take a frame from the link's FIFO and update the link's stats.
78  *
79  * If ff_inlink_check_available_frame() was previously called, the
80  * preferred way of expressing it is "av_assert1(ret);" immediately after
81  * ff_inlink_consume_frame(). Negative error codes must still be checked.
82  *
83  * @note May trigger process_command() and/or update is_disabled.
84  * @return >0 if a frame is available,
85  * 0 and set rframe to NULL if no frame available,
86  * or AVERROR code
87  */
88 int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe);
89 
90 /**
91  * Take samples from the link's FIFO and update the link's stats.
92  *
93  * If ff_inlink_check_available_samples() was previously called, the
94  * preferred way of expressing it is "av_assert1(ret);" immediately after
95  * ff_inlink_consume_samples(). Negative error codes must still be checked.
96  *
97  * @note May trigger process_command() and/or update is_disabled.
98  * @return >0 if a frame is available,
99  * 0 and set rframe to NULL if no frame available,
100  * or AVERROR code
101  */
102 int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max,
103  AVFrame **rframe);
104 
105 /**
106  * Make sure a frame is writable.
107  * This is similar to av_frame_make_writable() except it uses the link's
108  * buffer allocation callback, and therefore allows direct rendering.
109  */
111 
112 /**
113  * Test and acknowledge the change of status on the link.
114  *
115  * Status means EOF or an error condition; a change from the normal (0)
116  * status to a non-zero status can be queued in a filter's input link, it
117  * becomes relevant after the frames queued in the link's FIFO are
118  * processed. This function tests if frames are still queued and if a queued
119  * status change has not yet been processed. In that case it performs basic
120  * treatment (updating the link's timestamp) and returns a positive value to
121  * let the filter do its own treatments (flushing...).
122  *
123  * Filters implementing the activate callback should call this function when
124  * they think it might succeed (usually after checking unsuccessfully for a
125  * queued frame).
126  * Filters implementing the filter_frame and request_frame callbacks do not
127  * need to call that since the same treatment happens in ff_filter_frame().
128  *
129  * @param[out] rstatus new or current status
130  * @param[out] rpts current timestamp of the link in link time base
131  * @return >0 if status changed, <0 if status already acked, 0 otherwise
132  */
133 int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts);
134 
135 /**
136  * Mark that a frame is wanted on the link.
137  * Unlike ff_filter_frame(), it must not be called when the link has a
138  * non-zero status, and thus does not acknowledge it.
139  * Also it cannot fail.
140  */
142 
143 /**
144  * Set the status on an input link.
145  * Also discard all frames in the link's FIFO.
146  */
147 void ff_inlink_set_status(AVFilterLink *link, int status);
148 
149 /**
150  * Test if a frame is wanted on an output link.
151  */
152 static inline int ff_outlink_frame_wanted(AVFilterLink *link)
153 {
154  return link->frame_wanted_out;
155 }
156 
157 /**
158  * Get the status on an output link.
159  */
161 
162 /**
163  * Set the status field of a link from the source filter.
164  * The pts should reflect the timestamp of the status change,
165  * in link time base and relative to the frames timeline.
166  * In particular, for AVERROR_EOF, it should reflect the
167  * end time of the last frame.
168  */
169 static inline void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
170 {
171  ff_avfilter_link_set_in_status(link, status, pts);
172 }
173 
174 /**
175  * Forward the status on an output link to an input link.
176  * If the status is set, it will discard all queued frames and this macro
177  * will return immediately.
178  */
179 #define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink) do { \
180  int ret = ff_outlink_get_status(outlink); \
181  if (ret) { \
182  ff_inlink_set_status(inlink, ret); \
183  return 0; \
184  } \
185 } while (0)
186 
187 /**
188  * Forward the status on an output link to all input links.
189  * If the status is set, it will discard all queued frames and this macro
190  * will return immediately.
191  */
192 #define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter) do { \
193  int ret = ff_outlink_get_status(outlink); \
194  if (ret) { \
195  unsigned i; \
196  for (i = 0; i < filter->nb_inputs; i++) \
197  ff_inlink_set_status(filter->inputs[i], ret); \
198  return 0; \
199  } \
200 } while (0)
201 
202 /**
203  * Acknowledge the status on an input link and forward it to an output link.
204  * If the status is set, this macro will return immediately.
205  */
206 #define FF_FILTER_FORWARD_STATUS(inlink, outlink) do { \
207  int status; \
208  int64_t pts; \
209  if (ff_inlink_acknowledge_status(inlink, &status, &pts)) { \
210  ff_outlink_set_status(outlink, status, pts); \
211  return 0; \
212  } \
213 } while (0)
214 
215 /**
216  * Acknowledge the status on an input link and forward it to an output link.
217  * If the status is set, this macro will return immediately.
218  */
219 #define FF_FILTER_FORWARD_STATUS_ALL(inlink, filter) do { \
220  int status; \
221  int64_t pts; \
222  if (ff_inlink_acknowledge_status(inlink, &status, &pts)) { \
223  unsigned i; \
224  for (i = 0; i < filter->nb_outputs; i++) \
225  ff_outlink_set_status(filter->outputs[i], status, pts); \
226  return 0; \
227  } \
228 } while (0)
229 
230 /**
231  * Forward the frame_wanted_out flag from an output link to an input link.
232  * If the flag is set, this macro will return immediately.
233  */
234 #define FF_FILTER_FORWARD_WANTED(outlink, inlink) do { \
235  if (ff_outlink_frame_wanted(outlink)) { \
236  ff_inlink_request_frame(inlink); \
237  return 0; \
238  } \
239 } while (0)
240 
241 #endif /* AVFILTER_FILTERS_H */
This structure describes decoded (raw) audio or video data.
Definition: frame.h:218
Main libavfilter public API header.
int ff_inlink_check_available_samples(AVFilterLink *link, unsigned min)
Test if enough samples are available on the link.
Definition: avfilter.c:1456
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
Definition: avfilter.c:193
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition: filters.h:169
static int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
Definition: filters.h:152
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, int clip)
Definition: cfhd.c:114
static AVFrame * frame
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:1471
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
Definition: avfilter.c:1436
int ff_outlink_get_status(AVFilterLink *link)
Get the status on an output link.
Definition: avfilter.c:1615
static int64_t pts
int ff_inlink_process_commands(AVFilterLink *link, const AVFrame *frame)
Process the commands queued in the link up to the time of the frame.
Definition: avfilter.c:1559
int ff_inlink_evaluate_timeline_at_frame(AVFilterLink *link, const AVFrame *frame)
Evaluate the timeline expression of the link for the time and properties of the frame.
Definition: avfilter.c:1574
int ff_inlink_make_frame_writable(AVFilterLink *link, AVFrame **rframe)
Make sure a frame is writable.
Definition: avfilter.c:1510
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1592
void ff_avfilter_link_set_in_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition: avfilter.c:211
An instance of a filter.
Definition: avfilter.h:338
internal API functions
float min
int ff_inlink_check_available_frame(AVFilterLink *link)
Test if a frame is available on the link.
Definition: avfilter.c:1451
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
Definition: avfilter.c:1490
void ff_inlink_set_status(AVFilterLink *link, int status)
Set the status on an input link.
Definition: avfilter.c:1600