FFmpeg
avfilter_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 /*
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 "avfilter.h"
31 #include "filters.h"
32 #include "framequeue.h"
33 
34 typedef struct FilterLinkInternal {
36 
38 
39  /**
40  * Queue of frames waiting to be filtered.
41  */
43 
44  /**
45  * If set, the source filter can not generate a frame as is.
46  * The goal is to avoid repeatedly calling the request_frame() method on
47  * the same link.
48  */
50 
51  /**
52  * Link input status.
53  * If not zero, all attempts of filter_frame will fail with the
54  * corresponding code.
55  */
56  int status_in;
57 
58  /**
59  * Timestamp of the input status change.
60  */
62 
63  /**
64  * Link output status.
65  * If not zero, all attempts of request_frame will fail with the
66  * corresponding code.
67  */
69 
70  /**
71  * True if a frame is currently wanted on the output of this filter.
72  * Set when ff_request_frame() is called by the output,
73  * cleared when a frame is filtered.
74  */
76 
77  /**
78  * Index in the age array.
79  */
80  int age_index;
81 
82  /** stage of the initialization of the link properties (dimensions, etc) */
83  enum {
84  AVLINK_UNINIT = 0, ///< not started
85  AVLINK_STARTINIT, ///< started, but incomplete
86  AVLINK_INIT ///< complete
87  } init_state;
89 
91 {
92  return (FilterLinkInternal*)link;
93 }
94 
95 typedef struct FFFilterContext {
96  /**
97  * The public AVFilterContext. See avfilter.h for it.
98  */
100 
102 
103  // 1 when avfilter_init_*() was successfully called on this filter
104  // 0 otherwise
107 
109 {
110  return (FFFilterContext*)ctx;
111 }
112 
113 typedef struct AVFilterCommand {
114  double time; ///< time expressed in seconds
115  char *command; ///< command
116  char *arg; ///< optional argument for the command
117  int flags;
120 
121 typedef struct FFFilterGraph {
122  /**
123  * The public AVFilterGraph. See avfilter.h for it.
124  */
126 
129 
131 
132  void *thread;
135 } FFFilterGraph;
136 
138 {
139  return (FFFilterGraph*)graph;
140 }
141 
142 /**
143  * Update the position of a link in the age heap.
144  */
146  struct FilterLinkInternal *li);
147 
148 /**
149  * Allocate a new filter context and return it.
150  *
151  * @param filter what filter to create an instance of
152  * @param inst_name name to give to the new filter context
153  *
154  * @return newly created filter context or NULL on failure
155  */
156 AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name);
157 
158 /**
159  * Remove a filter from a graph;
160  */
162 
164 
165 /**
166  * Parse filter options into a dictionary.
167  *
168  * @param logctx context for logging
169  * @param priv_class a filter's private class for shorthand options or NULL
170  * @param options dictionary to store parsed options in
171  * @param args options string to parse
172  *
173  * @return a non-negative number on success, a negative error code on failure
174  */
175 int ff_filter_opt_parse(void *logctx, const AVClass *priv_class,
176  AVDictionary **options, const char *args);
177 
179 
181 
182 /**
183  * Negotiate the media format, dimensions, etc of all inputs to a filter.
184  *
185  * @param filter the filter to negotiate the properties for its inputs
186  * @return zero on successful negotiation
187  */
189 
190 /* misc trace functions */
191 
192 #define FF_TPRINTF_START(ctx, func) ff_tlog(NULL, "%-16s: ", #func)
193 
194 #ifdef TRACE
195 void ff_tlog_link(void *ctx, AVFilterLink *link, int end);
196 #else
197 #define ff_tlog_link(ctx, link, end) do { } while(0)
198 #endif
199 
200 /**
201  * Run one round of processing on a filter graph.
202  */
204 
205 /**
206  * Process the commands queued in the link up to the time of the frame.
207  * Commands will trigger the process_command() callback.
208  * @return >= 0 or AVERROR code.
209  */
211 
212 /**
213  * Evaluate the timeline expression of the link for the time and properties
214  * of the frame.
215  * @return >0 if enabled, 0 if disabled
216  * @note It does not update link->dst->is_disabled.
217  */
219 
220 #endif /* AVFILTER_AVFILTER_INTERNAL_H */
ff_filter_graph_run_once
int ff_filter_graph_run_once(AVFilterGraph *graph)
Run one round of processing on a filter graph.
Definition: avfiltergraph.c:1471
ff_link_internal
static FilterLinkInternal * ff_link_internal(AVFilterLink *link)
Definition: avfilter_internal.h:90
ff_filter_opt_parse
int ff_filter_opt_parse(void *logctx, const AVClass *priv_class, AVDictionary **options, const char *args)
Parse filter options into a dictionary.
Definition: avfilter.c:841
int64_t
long long int64_t
Definition: coverity.c:34
FFFilterGraph
Definition: avfilter_internal.h:121
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
FFFilterGraph::sink_links
struct FilterLinkInternal ** sink_links
Definition: avfilter_internal.h:127
FilterLinkInternal::l
FilterLink l
Definition: avfilter_internal.h:35
filter
void(* filter)(uint8_t *src, int stride, int qscale)
Definition: h263dsp.c:29
AVDictionary
Definition: dict.c:34
FilterLinkInternal::AVLINK_STARTINIT
@ AVLINK_STARTINIT
started, but incomplete
Definition: avfilter_internal.h:85
FilterLinkInternal
Definition: avfilter_internal.h:34
FFFramePool
Frame pool.
Definition: framepool.c:31
AVFilterCommand::flags
int flags
Definition: avfilter_internal.h:117
FFFilterContext::p
AVFilterContext p
The public AVFilterContext.
Definition: avfilter_internal.h:99
FFFilterGraph::sink_links_count
int sink_links_count
Definition: avfilter_internal.h:128
FFFilterGraph::thread_execute
avfilter_execute_func * thread_execute
Definition: avfilter_internal.h:133
FFFilterContext::initialized
int initialized
Definition: avfilter_internal.h:105
FFFrameQueueGlobal
Structure to hold global options and statistics for frame queues.
Definition: framequeue.h:46
ff_filter_config_links
int ff_filter_config_links(AVFilterContext *filter)
Negotiate the media format, dimensions, etc of all inputs to a filter.
Definition: avfilter.c:332
filters.h
ctx
AVFormatContext * ctx
Definition: movenc.c:49
FilterLinkInternal::AVLINK_INIT
@ AVLINK_INIT
complete
Definition: avfilter_internal.h:86
link
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame 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
Definition: filter_design.txt:23
ff_avfilter_graph_update_heap
void ff_avfilter_graph_update_heap(AVFilterGraph *graph, struct FilterLinkInternal *li)
Update the position of a link in the age heap.
Definition: avfiltergraph.c:1416
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
framequeue.h
fffiltergraph
static FFFilterGraph * fffiltergraph(AVFilterGraph *graph)
Definition: avfilter_internal.h:137
ff_filter_alloc
AVFilterContext * ff_filter_alloc(const AVFilter *filter, const char *inst_name)
Allocate a new filter context and return it.
Definition: avfilter.c:694
AVFilterGraph
Definition: avfilter.h:760
FilterLinkInternal::status_out
int status_out
Link output status.
Definition: avfilter_internal.h:68
ff_filter_activate
int ff_filter_activate(AVFilterContext *filter)
Definition: avfilter.c:1383
FFFrameQueue
Queue of AVFrame pointers.
Definition: framequeue.h:53
options
const OptionDef options[]
FilterLinkInternal::age_index
int age_index
Index in the age array.
Definition: avfilter_internal.h:80
avfilter_execute_func
int() avfilter_execute_func(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
A function executing multiple jobs, possibly in parallel.
Definition: avfilter.h:757
AVFilterCommand::next
struct AVFilterCommand * next
Definition: avfilter_internal.h:118
ff_inlink_process_commands
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:1538
FFFilterGraph::frame_queues
FFFrameQueueGlobal frame_queues
Definition: avfilter_internal.h:134
FilterLinkInternal::frame_blocked_in
int frame_blocked_in
If set, the source filter can not generate a frame as is.
Definition: avfilter_internal.h:49
FFFilterGraph::thread
void * thread
Definition: avfilter_internal.h:132
ff_tlog_link
#define ff_tlog_link(ctx, link, end)
Definition: avfilter_internal.h:197
FFFilterGraph::disable_auto_convert
unsigned disable_auto_convert
Definition: avfilter_internal.h:130
fffilterctx
static FFFilterContext * fffilterctx(AVFilterContext *ctx)
Definition: avfilter_internal.h:108
AVFilterCommand
Definition: avfilter_internal.h:113
FilterLinkInternal::status_in
int status_in
Link input status.
Definition: avfilter_internal.h:56
FilterLinkInternal::init_state
enum FilterLinkInternal::@307 init_state
stage of the initialization of the link properties (dimensions, etc)
FilterLinkInternal::frame_wanted_out
int frame_wanted_out
True if a frame is currently wanted on the output of this filter.
Definition: avfilter_internal.h:75
AVFilter
Filter definition.
Definition: avfilter.h:201
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
ff_inlink_evaluate_timeline_at_frame
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:1553
ff_filter_graph_remove_filter
void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter)
Remove a filter from a graph;.
Definition: avfiltergraph.c:99
FFFilterContext::execute
avfilter_execute_func * execute
Definition: avfilter_internal.h:101
avfilter.h
AVFilterCommand::command
char * command
command
Definition: avfilter_internal.h:115
FFFilterContext
Definition: avfilter_internal.h:95
AVFilterCommand::arg
char * arg
optional argument for the command
Definition: avfilter_internal.h:116
FFFilterGraph::p
AVFilterGraph p
The public AVFilterGraph.
Definition: avfilter_internal.h:125
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
ff_graph_thread_free
void ff_graph_thread_free(FFFilterGraph *graph)
Definition: avfiltergraph.c:71
ff_graph_thread_init
int ff_graph_thread_init(FFFilterGraph *graph)
Definition: avfiltergraph.c:75
FilterLinkInternal::frame_pool
struct FFFramePool * frame_pool
Definition: avfilter_internal.h:37
FilterLinkInternal::fifo
FFFrameQueue fifo
Queue of frames waiting to be filtered.
Definition: avfilter_internal.h:42
FilterLinkInternal::status_in_pts
int64_t status_in_pts
Timestamp of the input status change.
Definition: avfilter_internal.h:61
FilterLinkInternal::AVLINK_UNINIT
@ AVLINK_UNINIT
not started
Definition: avfilter_internal.h:84
AVFilterCommand::time
double time
time expressed in seconds
Definition: avfilter_internal.h:114