FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/ffmpeg_filter.h
Date: 2025-06-01 09:29:47
Exec Total Coverage
Lines: 8 8 100.0%
Functions: 4 4 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 #ifndef FFTOOLS_FFMPEG_FILTER_H
20 #define FFTOOLS_FFMPEG_FILTER_H
21
22 #include "ffmpeg.h"
23
24 #include <stdint.h>
25
26 #include "ffmpeg_sched.h"
27 #include "sync_queue.h"
28
29 #include "libavfilter/avfilter.h"
30
31 #include "libavutil/avutil.h"
32 #include "libavutil/dict.h"
33 #include "libavutil/fifo.h"
34 #include "libavutil/pixfmt.h"
35 #include "libavutil/rational.h"
36 #include "libavutil/bprint.h"
37 #include "libavutil/channel_layout.h"
38 #include "libavutil/downmix_info.h"
39
40 typedef struct FilterGraphPriv {
41 FilterGraph fg;
42
43 // name used for logging
44 char log_name[32];
45
46 int is_simple;
47 // true when the filtergraph contains only meta filters
48 // that do not modify the frame data
49 int is_meta;
50 // source filters are present in the graph
51 int have_sources;
52 int disable_conversions;
53
54 unsigned nb_outputs_done;
55
56 const char *graph_desc;
57
58 int nb_threads;
59
60 // frame for temporarily holding output from the filtergraph
61 AVFrame *frame;
62 // frame for sending output to the encoder
63 AVFrame *frame_enc;
64
65 Scheduler *sch;
66 unsigned sch_idx;
67
68 AVBPrint graph_print_buf;
69
70 } FilterGraphPriv;
71
72 1624140 static inline FilterGraphPriv *fgp_from_fg(FilterGraph *fg)
73 {
74 1624140 return (FilterGraphPriv*)fg;
75 }
76
77 37436 static inline const FilterGraphPriv *cfgp_from_cfg(const FilterGraph *fg)
78 {
79 37436 return (const FilterGraphPriv*)fg;
80 }
81
82 typedef struct InputFilterPriv {
83 InputFilter ifilter;
84
85 InputFilterOptions opts;
86
87 int index;
88
89 AVFilterContext *filter;
90
91 // used to hold submitted input
92 AVFrame *frame;
93
94 /* for filters that are not yet bound to an input stream,
95 * this stores the input linklabel, if any */
96 uint8_t *linklabel;
97
98 // filter data type
99 enum AVMediaType type;
100 // source data type: AVMEDIA_TYPE_SUBTITLE for sub2video,
101 // same as type otherwise
102 enum AVMediaType type_src;
103
104 int eof;
105 int bound;
106 int drop_warned;
107 uint64_t nb_dropped;
108
109 // parameters configured for this input
110 int format;
111
112 int width, height;
113 AVRational sample_aspect_ratio;
114 enum AVColorSpace color_space;
115 enum AVColorRange color_range;
116
117 int sample_rate;
118 AVChannelLayout ch_layout;
119
120 AVRational time_base;
121
122 AVFrameSideData **side_data;
123 int nb_side_data;
124
125 AVFifo *frame_queue;
126
127 AVBufferRef *hw_frames_ctx;
128
129 int displaymatrix_present;
130 int displaymatrix_applied;
131 int32_t displaymatrix[9];
132
133 int downmixinfo_present;
134 AVDownmixInfo downmixinfo;
135
136 struct {
137 AVFrame *frame;
138
139 int64_t last_pts;
140 int64_t end_pts;
141
142 /// marks if sub2video_update should force an initialization
143 unsigned int initialize;
144 } sub2video;
145 } InputFilterPriv;
146
147 1187252 static inline InputFilterPriv *ifp_from_ifilter(InputFilter *ifilter)
148 {
149 1187252 return (InputFilterPriv*)ifilter;
150 }
151
152 typedef struct FPSConvContext {
153 AVFrame *last_frame;
154 /* number of frames emitted by the video-encoding sync code */
155 int64_t frame_number;
156 /* history of nb_frames_prev, i.e. the number of times the
157 * previous frame was duplicated by vsync code in recent
158 * do_video_out() calls */
159 int64_t frames_prev_hist[3];
160
161 uint64_t dup_warning;
162
163 int last_dropped;
164 int dropped_keyframe;
165
166 enum VideoSyncMethod vsync_method;
167
168 AVRational framerate;
169 AVRational framerate_max;
170 const AVRational *framerate_supported;
171 int framerate_clip;
172 } FPSConvContext;
173
174
175 typedef struct OutputFilterPriv {
176 OutputFilter ofilter;
177
178 int index;
179
180 void *log_parent;
181 char log_name[32];
182
183 char *name;
184
185 AVFilterContext *filter;
186
187 /* desired output stream properties */
188 int format;
189 int width, height;
190 int sample_rate;
191 AVChannelLayout ch_layout;
192 enum AVColorSpace color_space;
193 enum AVColorRange color_range;
194
195 AVFrameSideData **side_data;
196 int nb_side_data;
197
198 // time base in which the output is sent to our downstream
199 // does not need to match the filtersink's timebase
200 AVRational tb_out;
201 // at least one frame with the above timebase was sent
202 // to our downstream, so it cannot change anymore
203 int tb_out_locked;
204
205 AVRational sample_aspect_ratio;
206
207 AVDictionary *sws_opts;
208 AVDictionary *swr_opts;
209
210 // those are only set if no format is specified and the encoder gives us multiple options
211 // They point directly to the relevant lists of the encoder.
212 const int *formats;
213 const AVChannelLayout *ch_layouts;
214 const int *sample_rates;
215 const enum AVColorSpace *color_spaces;
216 const enum AVColorRange *color_ranges;
217
218 AVRational enc_timebase;
219 int64_t trim_start_us;
220 int64_t trim_duration_us;
221 // offset for output timestamps, in AV_TIME_BASE_Q
222 int64_t ts_offset;
223 int64_t next_pts;
224 FPSConvContext fps;
225
226 unsigned flags;
227 } OutputFilterPriv;
228
229 457783 static inline OutputFilterPriv *ofp_from_ofilter(OutputFilter *ofilter)
230 {
231 457783 return (OutputFilterPriv*)ofilter;
232 }
233
234 #endif /* FFTOOLS_FFMPEG_FILTER_H */
235