../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
201 / 234
85.9%
Branches:
144 / 192
75.0%
Functions:
16 / 18
88.9%

libavfilter/framesync.c
Line Branch Exec Source
1 /*
2 * Copyright (c) 2013 Nicolas George
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 #include "libavutil/avassert.h"
22 #include "libavutil/mem.h"
23 #include "libavutil/opt.h"
24 #include "avfilter.h"
25 #include "filters.h"
26 #include "framesync.h"
27
28 #define OFFSET(member) offsetof(FFFrameSync, member)
29 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
30
31 ✗ static const char *framesync_name(void *ptr)
32 {
33 ✗ return "framesync";
34 }
35
36 static const AVOption framesync_options[] = {
37 { "eof_action", "Action to take when encountering EOF from secondary input ",
38 OFFSET(opt_eof_action), AV_OPT_TYPE_INT, { .i64 = EOF_ACTION_REPEAT },
39 EOF_ACTION_REPEAT, EOF_ACTION_PASS, .flags = FLAGS, .unit = "eof_action" },
40 { "repeat", "Repeat the previous frame.", 0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_REPEAT }, .flags = FLAGS, .unit = "eof_action" },
41 { "endall", "End both streams.", 0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_ENDALL }, .flags = FLAGS, .unit = "eof_action" },
42 { "pass", "Pass through the main input.", 0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_PASS }, .flags = FLAGS, .unit = "eof_action" },
43 { "shortest", "force termination when the shortest input terminates", OFFSET(opt_shortest), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
44 { "repeatlast", "extend last frame of secondary streams beyond EOF", OFFSET(opt_repeatlast), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
45 { "ts_sync_mode", "How strictly to sync streams based on secondary input timestamps",
46 OFFSET(opt_ts_sync_mode), AV_OPT_TYPE_INT, { .i64 = TS_DEFAULT },
47 TS_DEFAULT, TS_NEAREST, .flags = FLAGS, .unit = "ts_sync_mode" },
48 { "default", "Frame from secondary input with the nearest lower or equal timestamp to the primary input frame",
49 0, AV_OPT_TYPE_CONST, { .i64 = TS_DEFAULT }, .flags = FLAGS, .unit = "ts_sync_mode" },
50 { "nearest", "Frame from secondary input with the absolute nearest timestamp to the primary input frame",
51 0, AV_OPT_TYPE_CONST, { .i64 = TS_NEAREST }, .flags = FLAGS, .unit = "ts_sync_mode" },
52 { NULL }
53 };
54 const AVClass ff_framesync_class = {
55 .version = LIBAVUTIL_VERSION_INT,
56 .class_name = "framesync",
57 .item_name = framesync_name,
58 .category = AV_CLASS_CATEGORY_FILTER,
59 .option = framesync_options,
60 .parent_log_context_offset = OFFSET(parent),
61 };
62
63 ✗ const AVClass *ff_framesync_child_class_iterate(void **iter)
64 {
65
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ const AVClass *c = *iter ? NULL : &ff_framesync_class;
66 ✗ *iter = (void *)(uintptr_t)c;
67 ✗ return c;
68 }
69
70 enum {
71 STATE_BOF,
72 STATE_RUN,
73 STATE_EOF,
74 };
75
76 static int consume_from_fifos(FFFrameSync *fs);
77
78 19874 void ff_framesync_preinit(FFFrameSync *fs)
79 {
80
2/2
✓ Branch 2 → 3 taken 7548 times.
✓ Branch 2 → 4 taken 12326 times.
19874 if (fs->class)
81 7548 return;
82 12326 fs->class = &ff_framesync_class;
83 12326 av_opt_set_defaults(fs);
84 }
85
86 7559 int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
87 {
88 /* For filters with several outputs, we will not be able to assume which
89 output is relevant for ff_outlink_frame_wanted() and
90 ff_outlink_set_status(). To be designed when needed. */
91
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 7559 times.
7559 av_assert0(parent->nb_outputs == 1);
92
93 7559 ff_framesync_preinit(fs);
94 7559 fs->parent = parent;
95 7559 fs->nb_in = nb_in;
96
97 7559 fs->in = av_calloc(nb_in, sizeof(*fs->in));
98
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 7559 times.
7559 if (!fs->in) {
99 ✗ fs->nb_in = 0;
100 ✗ return AVERROR(ENOMEM);
101 }
102
103 7559 return 0;
104 }
105
106 2803 static void framesync_eof(FFFrameSync *fs, int64_t pts)
107 {
108 2803 fs->eof = 1;
109 2803 fs->frame_ready = 0;
110 2803 ff_outlink_set_status(fs->parent->outputs[0], AVERROR_EOF, pts);
111 2803 }
112
113 9021 static void framesync_sync_level_update(FFFrameSync *fs, int64_t eof_pts)
114 {
115 9021 unsigned i, level = 0;
116
117
2/2
✓ Branch 6 → 3 taken 9215 times.
✓ Branch 6 → 7 taken 9021 times.
18236 for (i = 0; i < fs->nb_in; i++)
118
1/2
✓ Branch 3 → 4 taken 9215 times.
✗ Branch 3 → 5 not taken.
9215 if (fs->in[i].state != STATE_EOF)
119 9215 level = FFMAX(level, fs->in[i].sync);
120
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 10 taken 9021 times.
9021 av_assert0(level <= fs->sync_level);
121
2/2
✓ Branch 10 → 11 taken 8986 times.
✓ Branch 10 → 12 taken 35 times.
9021 if (level < fs->sync_level)
122 8986 av_log(fs, AV_LOG_VERBOSE, "Sync level %u\n", level);
123
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 19 taken 9021 times.
9021 if (fs->opt_ts_sync_mode > TS_DEFAULT) {
124
0/2
✗ Branch 18 → 14 not taken.
✗ Branch 18 → 19 not taken.
✗ for (i = 0; i < fs->nb_in; i++) {
125
0/2
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 16 not taken.
✗ if (fs->in[i].sync < level)
126 ✗ fs->in[i].ts_mode = fs->opt_ts_sync_mode;
127 else
128 ✗ fs->in[i].ts_mode = TS_DEFAULT;
129 }
130 }
131
2/2
✓ Branch 19 → 20 taken 7619 times.
✓ Branch 19 → 21 taken 1402 times.
9021 if (level)
132 7619 fs->sync_level = level;
133 else
134 1402 framesync_eof(fs, eof_pts);
135 9021 }
136
137 7559 int ff_framesync_configure(FFFrameSync *fs)
138 {
139 unsigned i;
140
141
3/4
✓ Branch 2 → 3 taken 7559 times.
✗ Branch 2 → 4 not taken.
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 7558 times.
7559 if (!fs->opt_repeatlast || fs->opt_eof_action == EOF_ACTION_PASS) {
142 1 fs->opt_repeatlast = 0;
143 1 fs->opt_eof_action = EOF_ACTION_PASS;
144 }
145
2/4
✓ Branch 5 → 6 taken 7559 times.
✗ Branch 5 → 7 not taken.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 7559 times.
7559 if (fs->opt_shortest || fs->opt_eof_action == EOF_ACTION_ENDALL) {
146 ✗ fs->opt_shortest = 1;
147 ✗ fs->opt_eof_action = EOF_ACTION_ENDALL;
148 }
149
2/2
✓ Branch 8 → 9 taken 1 time.
✓ Branch 8 → 12 taken 7558 times.
7559 if (!fs->opt_repeatlast) {
150
2/2
✓ Branch 11 → 10 taken 1 time.
✓ Branch 11 → 12 taken 1 time.
2 for (i = 1; i < fs->nb_in; i++) {
151 1 fs->in[i].after = EXT_NULL;
152 1 fs->in[i].sync = 0;
153 }
154 }
155
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 16 taken 7559 times.
7559 if (fs->opt_shortest) {
156
0/2
✗ Branch 15 → 14 not taken.
✗ Branch 15 → 16 not taken.
✗ for (i = 0; i < fs->nb_in; i++)
157 ✗ fs->in[i].after = EXT_STOP;
158 }
159
160
2/2
✓ Branch 16 → 17 taken 7499 times.
✓ Branch 16 → 29 taken 60 times.
7559 if (!fs->time_base.num) {
161
2/2
✓ Branch 24 → 18 taken 7566 times.
✓ Branch 24 → 25 taken 7499 times.
15065 for (i = 0; i < fs->nb_in; i++) {
162
2/2
✓ Branch 18 → 19 taken 7563 times.
✓ Branch 18 → 23 taken 3 times.
7566 if (fs->in[i].sync) {
163
2/2
✓ Branch 19 → 20 taken 64 times.
✓ Branch 19 → 22 taken 7499 times.
7563 if (fs->time_base.num) {
164 64 fs->time_base = av_gcd_q(fs->time_base, fs->in[i].time_base,
165 64 AV_TIME_BASE / 2, AV_TIME_BASE_Q);
166 } else {
167 7499 fs->time_base = fs->in[i].time_base;
168 }
169 }
170 }
171
1/2
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 28 taken 7499 times.
7499 if (!fs->time_base.num) {
172 ✗ av_log(fs, AV_LOG_ERROR, "Impossible to set time base\n");
173 ✗ return AVERROR(EINVAL);
174 }
175 7499 av_log(fs, AV_LOG_VERBOSE, "Selected %d/%d time base\n",
176 fs->time_base.num, fs->time_base.den);
177 }
178
179
2/2
✓ Branch 31 → 30 taken 7626 times.
✓ Branch 31 → 32 taken 7559 times.
15185 for (i = 0; i < fs->nb_in; i++)
180 7626 fs->in[i].pts = fs->in[i].pts_next = AV_NOPTS_VALUE;
181 7559 fs->sync_level = UINT_MAX;
182 7559 framesync_sync_level_update(fs, AV_NOPTS_VALUE);
183
184 7559 return 0;
185 }
186
187 245724 static int framesync_advance(FFFrameSync *fs)
188 {
189 unsigned i;
190 int64_t pts;
191 int ret;
192
193
4/4
✓ Branch 44 → 45 taken 247164 times.
✓ Branch 44 → 46 taken 122126 times.
✓ Branch 45 → 3 taken 245812 times.
✓ Branch 45 → 46 taken 1352 times.
369290 while (!(fs->frame_ready || fs->eof)) {
194 245812 ret = consume_from_fifos(fs);
195
2/2
✓ Branch 4 → 5 taken 122197 times.
✓ Branch 4 → 6 taken 123615 times.
245812 if (ret <= 0)
196 122197 return ret;
197
198 123615 pts = INT64_MAX;
199
2/2
✓ Branch 11 → 7 taken 125350 times.
✓ Branch 11 → 12 taken 123615 times.
248965 for (i = 0; i < fs->nb_in; i++)
200
4/4
✓ Branch 7 → 8 taken 125316 times.
✓ Branch 7 → 10 taken 34 times.
✓ Branch 8 → 9 taken 123654 times.
✓ Branch 8 → 10 taken 1662 times.
125350 if (fs->in[i].have_next && fs->in[i].pts_next < pts)
201 123654 pts = fs->in[i].pts_next;
202
2/2
✓ Branch 12 → 13 taken 49 times.
✓ Branch 12 → 15 taken 123566 times.
123615 if (pts == INT64_MAX) {
203 49 framesync_eof(fs, AV_NOPTS_VALUE);
204 49 break;
205 }
206
2/2
✓ Branch 35 → 16 taken 125253 times.
✓ Branch 35 → 36 taken 123566 times.
248819 for (i = 0; i < fs->nb_in; i++) {
207
2/2
✓ Branch 16 → 17 taken 766 times.
✓ Branch 16 → 24 taken 124487 times.
125253 if (fs->in[i].pts_next == pts ||
208
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 22 taken 766 times.
766 (fs->in[i].ts_mode == TS_NEAREST &&
209
0/2
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 22 not taken.
✗ fs->in[i].have_next &&
210
0/4
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 22 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 22 not taken.
✗ fs->in[i].pts_next != INT64_MAX && fs->in[i].pts != AV_NOPTS_VALUE &&
211
0/2
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 24 not taken.
✗ fs->in[i].pts_next - pts < pts - fs->in[i].pts) ||
212
2/2
✓ Branch 22 → 23 taken 280 times.
✓ Branch 22 → 34 taken 486 times.
766 (fs->in[i].before == EXT_INFINITY &&
213
1/2
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 34 taken 280 times.
280 fs->in[i].state == STATE_BOF)) {
214 124487 av_frame_free(&fs->in[i].frame);
215 124487 fs->in[i].frame = fs->in[i].frame_next;
216 124487 fs->in[i].pts = fs->in[i].pts_next;
217 124487 fs->in[i].frame_next = NULL;
218 124487 fs->in[i].pts_next = AV_NOPTS_VALUE;
219 124487 fs->in[i].have_next = 0;
220
2/2
✓ Branch 25 → 26 taken 123134 times.
✓ Branch 25 → 27 taken 1353 times.
124487 fs->in[i].state = fs->in[i].frame ? STATE_RUN : STATE_EOF;
221
3/4
✓ Branch 28 → 29 taken 122285 times.
✓ Branch 28 → 31 taken 2202 times.
✓ Branch 29 → 30 taken 122285 times.
✗ Branch 29 → 31 not taken.
124487 if (fs->in[i].sync == fs->sync_level && fs->in[i].frame)
222 122285 fs->frame_ready = 1;
223
2/2
✓ Branch 31 → 32 taken 1353 times.
✓ Branch 31 → 34 taken 123134 times.
124487 if (fs->in[i].state == STATE_EOF &&
224
2/2
✓ Branch 32 → 33 taken 1352 times.
✓ Branch 32 → 34 taken 1 time.
1353 fs->in[i].after == EXT_STOP)
225 1352 framesync_eof(fs, AV_NOPTS_VALUE);
226 }
227 }
228
2/2
✓ Branch 36 → 37 taken 122126 times.
✓ Branch 36 → 43 taken 1440 times.
123566 if (fs->frame_ready)
229
2/2
✓ Branch 42 → 38 taken 123725 times.
✓ Branch 42 → 43 taken 122126 times.
245851 for (i = 0; i < fs->nb_in; i++)
230
2/2
✓ Branch 38 → 39 taken 3 times.
✓ Branch 38 → 41 taken 123722 times.
123725 if ((fs->in[i].state == STATE_BOF &&
231
1/2
✗ Branch 39 → 40 not taken.
✓ Branch 39 → 41 taken 3 times.
3 fs->in[i].before == EXT_STOP))
232 ✗ fs->frame_ready = 0;
233 123566 fs->pts = pts;
234 }
235 123527 return 0;
236 }
237
238 1354 static int64_t framesync_pts_extrapolate(FFFrameSync *fs, unsigned in,
239 int64_t pts)
240 {
241 /* Possible enhancement: use the link's frame rate */
242 1354 return pts + 1;
243 }
244
245 123134 static void framesync_inject_frame(FFFrameSync *fs, unsigned in, AVFrame *frame)
246 {
247 int64_t pts;
248
249
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 123134 times.
123134 av_assert0(!fs->in[in].have_next);
250
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 123134 times.
123134 av_assert0(frame);
251 123134 pts = av_rescale_q_rnd(frame->pts, fs->in[in].time_base, fs->time_base, AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX);
252 123134 frame->pts = pts;
253 123134 fs->in[in].frame_next = frame;
254 123134 fs->in[in].pts_next = pts;
255 123134 fs->in[in].have_next = 1;
256 123134 }
257
258 1462 static void framesync_inject_status(FFFrameSync *fs, unsigned in, int status, int64_t eof_pts)
259 {
260
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 1462 times.
1462 av_assert0(!fs->in[in].have_next);
261 1462 fs->in[in].sync = 0;
262
1/2
✓ Branch 5 → 6 taken 1462 times.
✗ Branch 5 → 7 not taken.
1462 framesync_sync_level_update(fs, status == AVERROR_EOF ? eof_pts : AV_NOPTS_VALUE);
263 1462 fs->in[in].frame_next = NULL;
264
2/2
✓ Branch 10 → 11 taken 1354 times.
✓ Branch 10 → 12 taken 101 times.
1455 fs->in[in].pts_next = fs->in[in].state != STATE_RUN || fs->in[in].after == EXT_INFINITY
265
2/2
✓ Branch 9 → 10 taken 1455 times.
✓ Branch 9 → 12 taken 7 times.
2917 ? INT64_MAX : framesync_pts_extrapolate(fs, in, fs->in[in].pts);
266 1462 fs->in[in].have_next = 1;
267 1462 }
268
269 123725 int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe,
270 unsigned get)
271 {
272 AVFrame *frame;
273 123725 unsigned need_copy = 0, i;
274 int64_t pts_next;
275
276
2/2
✓ Branch 2 → 3 taken 38 times.
✓ Branch 2 → 4 taken 123687 times.
123725 if (!fs->in[in].frame) {
277 38 *rframe = NULL;
278 38 return 0;
279 }
280 123687 frame = fs->in[in].frame;
281
2/2
✓ Branch 4 → 5 taken 121918 times.
✓ Branch 4 → 23 taken 1769 times.
123687 if (get) {
282 /* Find out if we need to copy the frame: is there another sync
283 stream, and do we know if its current frame will outlast this one? */
284
2/2
✓ Branch 5 → 6 taken 88 times.
✓ Branch 5 → 7 taken 121830 times.
121918 pts_next = fs->in[in].have_next ? fs->in[in].pts_next : INT64_MAX;
285
3/4
✓ Branch 15 → 16 taken 123353 times.
✓ Branch 15 → 17 taken 121918 times.
✓ Branch 16 → 9 taken 123353 times.
✗ Branch 16 → 17 not taken.
245271 for (i = 0; i < fs->nb_in && !need_copy; i++)
286
4/4
✓ Branch 9 → 10 taken 1435 times.
✓ Branch 9 → 14 taken 121918 times.
✓ Branch 10 → 11 taken 1052 times.
✓ Branch 10 → 14 taken 383 times.
123353 if (i != in && fs->in[i].sync &&
287
3/4
✓ Branch 11 → 12 taken 256 times.
✓ Branch 11 → 13 taken 796 times.
✓ Branch 12 → 13 taken 256 times.
✗ Branch 12 → 14 not taken.
1052 (!fs->in[i].have_next || fs->in[i].pts_next < pts_next))
288 1052 need_copy = 1;
289
2/2
✓ Branch 17 → 18 taken 1052 times.
✓ Branch 17 → 21 taken 120866 times.
121918 if (need_copy) {
290
1/2
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 22 taken 1052 times.
1052 if (!(frame = av_frame_clone(frame)))
291 ✗ return AVERROR(ENOMEM);
292 } else {
293 120866 fs->in[in].frame = NULL;
294 }
295 121918 fs->frame_ready = 0;
296 }
297 123687 *rframe = frame;
298 123687 return 0;
299 }
300
301 19844 void ff_framesync_uninit(FFFrameSync *fs)
302 {
303 unsigned i;
304
305
2/2
✓ Branch 6 → 3 taken 7626 times.
✓ Branch 6 → 7 taken 19844 times.
27470 for (i = 0; i < fs->nb_in; i++) {
306 7626 av_frame_free(&fs->in[i].frame);
307 7626 av_frame_free(&fs->in[i].frame_next);
308 }
309
310 19844 av_freep(&fs->in);
311 19844 }
312
313 245812 static int consume_from_fifos(FFFrameSync *fs)
314 {
315 245812 AVFilterContext *ctx = fs->parent;
316 245812 AVFrame *frame = NULL;
317 int64_t pts;
318 unsigned i, nb_active, nb_miss;
319 int ret, status;
320
321 245812 nb_active = nb_miss = 0;
322
2/2
✓ Branch 20 → 3 taken 251418 times.
✓ Branch 20 → 21 taken 245812 times.
497230 for (i = 0; i < fs->nb_in; i++) {
323
4/4
✓ Branch 3 → 4 taken 247731 times.
✓ Branch 3 → 5 taken 3687 times.
✓ Branch 4 → 5 taken 68 times.
✓ Branch 4 → 6 taken 247663 times.
251418 if (fs->in[i].have_next || fs->in[i].state == STATE_EOF)
324 3755 continue;
325 247663 nb_active++;
326 247663 ret = ff_inlink_consume_frame(ctx->inputs[i], &frame);
327
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 247663 times.
247663 if (ret < 0)
328 ✗ return ret;
329
2/2
✓ Branch 9 → 10 taken 123134 times.
✓ Branch 9 → 14 taken 124529 times.
247663 if (ret) {
330
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 13 taken 123134 times.
123134 av_assert0(frame);
331 123134 framesync_inject_frame(fs, i, frame);
332 } else {
333 124529 ret = ff_inlink_acknowledge_status(ctx->inputs[i], &status, &pts);
334
2/2
✓ Branch 15 → 16 taken 1462 times.
✓ Branch 15 → 17 taken 123067 times.
124529 if (ret > 0) {
335 1462 framesync_inject_status(fs, i, status, pts);
336
1/2
✓ Branch 17 → 18 taken 123067 times.
✗ Branch 17 → 19 not taken.
123067 } else if (!ret) {
337 123067 nb_miss++;
338 }
339 }
340 }
341
2/2
✓ Branch 21 → 22 taken 122197 times.
✓ Branch 21 → 33 taken 123615 times.
245812 if (nb_miss) {
342
4/4
✓ Branch 22 → 23 taken 121439 times.
✓ Branch 22 → 26 taken 758 times.
✓ Branch 24 → 25 taken 13 times.
✓ Branch 24 → 26 taken 121426 times.
122197 if (nb_miss == nb_active && !ff_outlink_frame_wanted(ctx->outputs[0]))
343 13 return FFERROR_NOT_READY;
344
2/2
✓ Branch 31 → 27 taken 126042 times.
✓ Branch 31 → 32 taken 122184 times.
248226 for (i = 0; i < fs->nb_in; i++)
345
4/4
✓ Branch 27 → 28 taken 123088 times.
✓ Branch 27 → 30 taken 2954 times.
✓ Branch 28 → 29 taken 123054 times.
✓ Branch 28 → 30 taken 34 times.
126042 if (!fs->in[i].have_next && fs->in[i].state != STATE_EOF)
346 123054 ff_inlink_request_frame(ctx->inputs[i]);
347 122184 return 0;
348 }
349 123615 return 1;
350 }
351
352 247078 int ff_framesync_activate(FFFrameSync *fs)
353 {
354 247078 AVFilterContext *ctx = fs->parent;
355 int ret;
356
357
4/4
✓ Branch 3 → 4 taken 1354 times.
✓ Branch 3 → 9 taken 245724 times.
✓ Branch 7 → 5 taken 1371 times.
✓ Branch 7 → 8 taken 1354 times.
248449 FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[0], ctx);
358
359 245724 ret = framesync_advance(fs);
360
2/2
✓ Branch 10 → 11 taken 13 times.
✓ Branch 10 → 12 taken 245711 times.
245724 if (ret < 0)
361 13 return ret;
362
4/4
✓ Branch 12 → 13 taken 244309 times.
✓ Branch 12 → 14 taken 1402 times.
✓ Branch 13 → 14 taken 122183 times.
✓ Branch 13 → 15 taken 122126 times.
245711 if (fs->eof || !fs->frame_ready)
363 123585 return 0;
364 122126 ret = fs->on_event(fs);
365
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 122126 times.
122126 if (ret < 0)
366 ✗ return ret;
367 122126 fs->frame_ready = 0;
368
369 122126 return 0;
370 }
371
372 53 int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
373 {
374 int ret;
375
376 53 ret = ff_framesync_init(fs, parent, 2);
377
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 53 times.
53 if (ret < 0)
378 ✗ return ret;
379 53 fs->in[0].time_base = parent->inputs[0]->time_base;
380 53 fs->in[1].time_base = parent->inputs[1]->time_base;
381 53 fs->in[0].sync = 2;
382 53 fs->in[0].before = EXT_STOP;
383 53 fs->in[0].after = EXT_INFINITY;
384 53 fs->in[1].sync = 1;
385 53 fs->in[1].before = EXT_NULL;
386 53 fs->in[1].after = EXT_INFINITY;
387 53 return 0;
388 }
389
390 1428 int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
391 {
392 1428 AVFilterContext *ctx = fs->parent;
393 1428 AVFrame *mainpic = NULL, *secondpic = NULL;
394 int ret;
395
396
2/4
✓ Branch 3 → 4 taken 1428 times.
✗ Branch 3 → 6 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 1428 times.
2856 if ((ret = ff_framesync_get_frame(fs, 0, &mainpic, 1)) < 0 ||
397 1428 (ret = ff_framesync_get_frame(fs, 1, &secondpic, 0)) < 0) {
398 ✗ av_frame_free(&mainpic);
399 ✗ return ret;
400 }
401
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 11 taken 1428 times.
1428 av_assert0(mainpic);
402 1428 mainpic->pts = av_rescale_q(fs->pts, fs->time_base, ctx->outputs[0]->time_base);
403
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 1428 times.
1428 if (ctx->is_disabled)
404 ✗ secondpic = NULL;
405 1428 *f0 = mainpic;
406 1428 *f1 = secondpic;
407 1428 return 0;
408 }
409
410 1383 int ff_framesync_dualinput_get_writable(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
411 {
412 int ret;
413
414 1383 ret = ff_framesync_dualinput_get(fs, f0, f1);
415
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 1383 times.
1383 if (ret < 0)
416 ✗ return ret;
417 1383 ret = ff_inlink_make_frame_writable(fs->parent->inputs[0], f0);
418
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 9 taken 1383 times.
1383 if (ret < 0) {
419 ✗ av_frame_free(f0);
420 ✗ *f1 = NULL;
421 ✗ return ret;
422 }
423 1383 return 0;
424 }
425