FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/framesync.c
Date: 2024-07-16 12:46:59
Exec Total Coverage
Lines: 198 238 83.2%
Functions: 16 18 88.9%
Branches: 136 192 70.8%

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 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 11124 void ff_framesync_preinit(FFFrameSync *fs)
79 {
80
2/2
✓ Branch 0 taken 4096 times.
✓ Branch 1 taken 7028 times.
11124 if (fs->class)
81 4096 return;
82 7028 fs->class = &ff_framesync_class;
83 7028 av_opt_set_defaults(fs);
84 }
85
86 4104 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 0 not taken.
✓ Branch 1 taken 4104 times.
4104 av_assert0(parent->nb_outputs == 1);
92
93 4104 ff_framesync_preinit(fs);
94 4104 fs->parent = parent;
95 4104 fs->nb_in = nb_in;
96
97 4104 fs->in = av_calloc(nb_in, sizeof(*fs->in));
98
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4104 times.
4104 if (!fs->in) {
99 fs->nb_in = 0;
100 return AVERROR(ENOMEM);
101 }
102
103 4104 return 0;
104 }
105
106 2216 static void framesync_eof(FFFrameSync *fs)
107 {
108 2216 fs->eof = 1;
109 2216 fs->frame_ready = 0;
110 2216 ff_outlink_set_status(fs->parent->outputs[0], AVERROR_EOF, AV_NOPTS_VALUE);
111 2216 }
112
113 5241 static void framesync_sync_level_update(FFFrameSync *fs)
114 {
115 5241 unsigned i, level = 0;
116
117
2/2
✓ Branch 0 taken 5341 times.
✓ Branch 1 taken 5241 times.
10582 for (i = 0; i < fs->nb_in; i++)
118
1/2
✓ Branch 0 taken 5341 times.
✗ Branch 1 not taken.
5341 if (fs->in[i].state != STATE_EOF)
119 5341 level = FFMAX(level, fs->in[i].sync);
120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5241 times.
5241 av_assert0(level <= fs->sync_level);
121
2/2
✓ Branch 0 taken 5228 times.
✓ Branch 1 taken 13 times.
5241 if (level < fs->sync_level)
122 5228 av_log(fs, AV_LOG_VERBOSE, "Sync level %u\n", level);
123
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5241 times.
5241 if (fs->opt_ts_sync_mode > TS_DEFAULT) {
124 for (i = 0; i < fs->nb_in; i++) {
125 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 0 taken 4133 times.
✓ Branch 1 taken 1108 times.
5241 if (level)
132 4133 fs->sync_level = level;
133 else
134 1108 framesync_eof(fs);
135 5241 }
136
137 4104 int ff_framesync_configure(FFFrameSync *fs)
138 {
139 unsigned i;
140
141
2/4
✓ Branch 0 taken 4104 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4104 times.
4104 if (!fs->opt_repeatlast || fs->opt_eof_action == EOF_ACTION_PASS) {
142 fs->opt_repeatlast = 0;
143 fs->opt_eof_action = EOF_ACTION_PASS;
144 }
145
2/4
✓ Branch 0 taken 4104 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4104 times.
4104 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
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4104 times.
4104 if (!fs->opt_repeatlast) {
150 for (i = 1; i < fs->nb_in; i++) {
151 fs->in[i].after = EXT_NULL;
152 fs->in[i].sync = 0;
153 }
154 }
155
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4104 times.
4104 if (fs->opt_shortest) {
156 for (i = 0; i < fs->nb_in; i++)
157 fs->in[i].after = EXT_STOP;
158 }
159
160
2/2
✓ Branch 0 taken 3942 times.
✓ Branch 1 taken 162 times.
4104 if (!fs->time_base.num) {
161
2/2
✓ Branch 0 taken 3985 times.
✓ Branch 1 taken 3942 times.
7927 for (i = 0; i < fs->nb_in; i++) {
162
2/2
✓ Branch 0 taken 3984 times.
✓ Branch 1 taken 1 times.
3985 if (fs->in[i].sync) {
163
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 3942 times.
3984 if (fs->time_base.num) {
164 42 fs->time_base = av_gcd_q(fs->time_base, fs->in[i].time_base,
165 42 AV_TIME_BASE / 2, AV_TIME_BASE_Q);
166 } else {
167 3942 fs->time_base = fs->in[i].time_base;
168 }
169 }
170 }
171
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3942 times.
3942 if (!fs->time_base.num) {
172 av_log(fs, AV_LOG_ERROR, "Impossible to set time base\n");
173 return AVERROR(EINVAL);
174 }
175 3942 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 0 taken 4147 times.
✓ Branch 1 taken 4104 times.
8251 for (i = 0; i < fs->nb_in; i++)
180 4147 fs->in[i].pts = fs->in[i].pts_next = AV_NOPTS_VALUE;
181 4104 fs->sync_level = UINT_MAX;
182 4104 framesync_sync_level_update(fs);
183
184 4104 return 0;
185 }
186
187 95238 static int framesync_advance(FFFrameSync *fs)
188 {
189 unsigned i;
190 int64_t pts;
191 int ret;
192
193
4/4
✓ Branch 0 taken 96393 times.
✓ Branch 1 taken 48156 times.
✓ Branch 2 taken 95326 times.
✓ Branch 3 taken 1067 times.
144549 while (!(fs->frame_ready || fs->eof)) {
194 95326 ret = consume_from_fifos(fs);
195
2/2
✓ Branch 0 taken 45974 times.
✓ Branch 1 taken 49352 times.
95326 if (ret <= 0)
196 45974 return ret;
197
198 49352 pts = INT64_MAX;
199
2/2
✓ Branch 0 taken 50855 times.
✓ Branch 1 taken 49352 times.
100207 for (i = 0; i < fs->nb_in; i++)
200
3/4
✓ Branch 0 taken 50855 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 49399 times.
✓ Branch 3 taken 1456 times.
50855 if (fs->in[i].have_next && fs->in[i].pts_next < pts)
201 49399 pts = fs->in[i].pts_next;
202
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 49311 times.
49352 if (pts == INT64_MAX) {
203 41 framesync_eof(fs);
204 41 break;
205 }
206
2/2
✓ Branch 0 taken 50786 times.
✓ Branch 1 taken 49311 times.
100097 for (i = 0; i < fs->nb_in; i++) {
207
2/2
✓ Branch 0 taken 721 times.
✓ Branch 1 taken 50065 times.
50786 if (fs->in[i].pts_next == pts ||
208
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 721 times.
721 (fs->in[i].ts_mode == TS_NEAREST &&
209 fs->in[i].have_next &&
210 fs->in[i].pts_next != INT64_MAX && fs->in[i].pts != AV_NOPTS_VALUE &&
211 fs->in[i].pts_next - pts < pts - fs->in[i].pts) ||
212
2/2
✓ Branch 0 taken 280 times.
✓ Branch 1 taken 441 times.
721 (fs->in[i].before == EXT_INFINITY &&
213
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 280 times.
280 fs->in[i].state == STATE_BOF)) {
214 50065 av_frame_free(&fs->in[i].frame);
215 50065 fs->in[i].frame = fs->in[i].frame_next;
216 50065 fs->in[i].pts = fs->in[i].pts_next;
217 50065 fs->in[i].frame_next = NULL;
218 50065 fs->in[i].pts_next = AV_NOPTS_VALUE;
219 50065 fs->in[i].have_next = 0;
220
2/2
✓ Branch 0 taken 48998 times.
✓ Branch 1 taken 1067 times.
50065 fs->in[i].state = fs->in[i].frame ? STATE_RUN : STATE_EOF;
221
3/4
✓ Branch 0 taken 48306 times.
✓ Branch 1 taken 1759 times.
✓ Branch 2 taken 48306 times.
✗ Branch 3 not taken.
50065 if (fs->in[i].sync == fs->sync_level && fs->in[i].frame)
222 48306 fs->frame_ready = 1;
223
2/2
✓ Branch 0 taken 1067 times.
✓ Branch 1 taken 48998 times.
50065 if (fs->in[i].state == STATE_EOF &&
224
1/2
✓ Branch 0 taken 1067 times.
✗ Branch 1 not taken.
1067 fs->in[i].after == EXT_STOP)
225 1067 framesync_eof(fs);
226 }
227 }
228
2/2
✓ Branch 0 taken 48156 times.
✓ Branch 1 taken 1155 times.
49311 if (fs->frame_ready)
229
2/2
✓ Branch 0 taken 49543 times.
✓ Branch 1 taken 48156 times.
97699 for (i = 0; i < fs->nb_in; i++)
230
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 49540 times.
49543 if ((fs->in[i].state == STATE_BOF &&
231
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 fs->in[i].before == EXT_STOP))
232 fs->frame_ready = 0;
233 49311 fs->pts = pts;
234 }
235 49264 return 0;
236 }
237
238 1067 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 1067 return pts + 1;
243 }
244
245 48998 static void framesync_inject_frame(FFFrameSync *fs, unsigned in, AVFrame *frame)
246 {
247 int64_t pts;
248
249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48998 times.
48998 av_assert0(!fs->in[in].have_next);
250
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48998 times.
48998 av_assert0(frame);
251 48998 pts = av_rescale_q(frame->pts, fs->in[in].time_base, fs->time_base);
252 48998 frame->pts = pts;
253 48998 fs->in[in].frame_next = frame;
254 48998 fs->in[in].pts_next = pts;
255 48998 fs->in[in].have_next = 1;
256 48998 }
257
258 1137 static void framesync_inject_status(FFFrameSync *fs, unsigned in, int status, int64_t pts)
259 {
260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1137 times.
1137 av_assert0(!fs->in[in].have_next);
261
2/2
✓ Branch 0 taken 1067 times.
✓ Branch 1 taken 57 times.
1124 pts = fs->in[in].state != STATE_RUN || fs->in[in].after == EXT_INFINITY
262
2/2
✓ Branch 0 taken 1124 times.
✓ Branch 1 taken 13 times.
2261 ? INT64_MAX : framesync_pts_extrapolate(fs, in, fs->in[in].pts);
263 1137 fs->in[in].sync = 0;
264 1137 framesync_sync_level_update(fs);
265 1137 fs->in[in].frame_next = NULL;
266 1137 fs->in[in].pts_next = pts;
267 1137 fs->in[in].have_next = 1;
268 1137 }
269
270 49543 int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe,
271 unsigned get)
272 {
273 AVFrame *frame;
274 49543 unsigned need_copy = 0, i;
275 int64_t pts_next;
276 int ret;
277
278
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 49540 times.
49543 if (!fs->in[in].frame) {
279 3 *rframe = NULL;
280 3 return 0;
281 }
282 49540 frame = fs->in[in].frame;
283
2/2
✓ Branch 0 taken 47956 times.
✓ Branch 1 taken 1584 times.
49540 if (get) {
284 /* Find out if we need to copy the frame: is there another sync
285 stream, and do we know if its current frame will outlast this one? */
286
2/2
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 47868 times.
47956 pts_next = fs->in[in].have_next ? fs->in[in].pts_next : INT64_MAX;
287
3/4
✓ Branch 0 taken 49193 times.
✓ Branch 1 taken 47956 times.
✓ Branch 2 taken 49193 times.
✗ Branch 3 not taken.
97149 for (i = 0; i < fs->nb_in && !need_copy; i++)
288
4/4
✓ Branch 0 taken 1237 times.
✓ Branch 1 taken 47956 times.
✓ Branch 2 taken 943 times.
✓ Branch 3 taken 294 times.
49193 if (i != in && fs->in[i].sync &&
289
3/4
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 687 times.
✓ Branch 2 taken 256 times.
✗ Branch 3 not taken.
943 (!fs->in[i].have_next || fs->in[i].pts_next < pts_next))
290 943 need_copy = 1;
291
2/2
✓ Branch 0 taken 943 times.
✓ Branch 1 taken 47013 times.
47956 if (need_copy) {
292
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 943 times.
943 if (!(frame = av_frame_clone(frame)))
293 return AVERROR(ENOMEM);
294
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 943 times.
943 if ((ret = ff_inlink_make_frame_writable(fs->parent->inputs[in], &frame)) < 0) {
295 av_frame_free(&frame);
296 return ret;
297 }
298 } else {
299 47013 fs->in[in].frame = NULL;
300 }
301 47956 fs->frame_ready = 0;
302 }
303 49540 *rframe = frame;
304 49540 return 0;
305 }
306
307 11099 void ff_framesync_uninit(FFFrameSync *fs)
308 {
309 unsigned i;
310
311
2/2
✓ Branch 0 taken 4147 times.
✓ Branch 1 taken 11099 times.
15246 for (i = 0; i < fs->nb_in; i++) {
312 4147 av_frame_free(&fs->in[i].frame);
313 4147 av_frame_free(&fs->in[i].frame_next);
314 }
315
316 11099 av_freep(&fs->in);
317 11099 }
318
319 95326 static int consume_from_fifos(FFFrameSync *fs)
320 {
321 95326 AVFilterContext *ctx = fs->parent;
322 95326 AVFrame *frame = NULL;
323 int64_t pts;
324 unsigned i, nb_active, nb_miss;
325 int ret, status;
326
327 95326 nb_active = nb_miss = 0;
328
2/2
✓ Branch 0 taken 98984 times.
✓ Branch 1 taken 95326 times.
194310 for (i = 0; i < fs->nb_in; i++) {
329
3/4
✓ Branch 0 taken 96774 times.
✓ Branch 1 taken 2210 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96774 times.
98984 if (fs->in[i].have_next || fs->in[i].state == STATE_EOF)
330 2210 continue;
331 96774 nb_active++;
332 96774 ret = ff_inlink_consume_frame(ctx->inputs[i], &frame);
333
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96774 times.
96774 if (ret < 0)
334 return ret;
335
2/2
✓ Branch 0 taken 48998 times.
✓ Branch 1 taken 47776 times.
96774 if (ret) {
336
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48998 times.
48998 av_assert0(frame);
337 48998 framesync_inject_frame(fs, i, frame);
338 } else {
339 47776 ret = ff_inlink_acknowledge_status(ctx->inputs[i], &status, &pts);
340
2/2
✓ Branch 0 taken 1137 times.
✓ Branch 1 taken 46639 times.
47776 if (ret > 0) {
341 1137 framesync_inject_status(fs, i, status, pts);
342
1/2
✓ Branch 0 taken 46639 times.
✗ Branch 1 not taken.
46639 } else if (!ret) {
343 46639 nb_miss++;
344 }
345 }
346 }
347
2/2
✓ Branch 0 taken 45974 times.
✓ Branch 1 taken 49352 times.
95326 if (nb_miss) {
348
4/4
✓ Branch 0 taken 45359 times.
✓ Branch 1 taken 615 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 45355 times.
45974 if (nb_miss == nb_active && !ff_outlink_frame_wanted(ctx->outputs[0]))
349 4 return FFERROR_NOT_READY;
350
2/2
✓ Branch 0 taken 48121 times.
✓ Branch 1 taken 45970 times.
94091 for (i = 0; i < fs->nb_in; i++)
351
3/4
✓ Branch 0 taken 46635 times.
✓ Branch 1 taken 1486 times.
✓ Branch 2 taken 46635 times.
✗ Branch 3 not taken.
48121 if (!fs->in[i].have_next && fs->in[i].state != STATE_EOF)
352 46635 ff_inlink_request_frame(ctx->inputs[i]);
353 45970 return 0;
354 }
355 49352 return 1;
356 }
357
358 96335 int ff_framesync_activate(FFFrameSync *fs)
359 {
360 96335 AVFilterContext *ctx = fs->parent;
361 int ret;
362
363
4/4
✓ Branch 1 taken 1097 times.
✓ Branch 2 taken 95238 times.
✓ Branch 4 taken 1102 times.
✓ Branch 5 taken 1097 times.
97437 FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[0], ctx);
364
365 95238 ret = framesync_advance(fs);
366
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 95234 times.
95238 if (ret < 0)
367 4 return ret;
368
4/4
✓ Branch 0 taken 94126 times.
✓ Branch 1 taken 1108 times.
✓ Branch 2 taken 45970 times.
✓ Branch 3 taken 48156 times.
95234 if (fs->eof || !fs->frame_ready)
369 47078 return 0;
370 48156 ret = fs->on_event(fs);
371
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48156 times.
48156 if (ret < 0)
372 return ret;
373 48156 fs->frame_ready = 0;
374
375 48156 return 0;
376 }
377
378 39 int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
379 {
380 int ret;
381
382 39 ret = ff_framesync_init(fs, parent, 2);
383
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
39 if (ret < 0)
384 return ret;
385 39 fs->in[0].time_base = parent->inputs[0]->time_base;
386 39 fs->in[1].time_base = parent->inputs[1]->time_base;
387 39 fs->in[0].sync = 2;
388 39 fs->in[0].before = EXT_STOP;
389 39 fs->in[0].after = EXT_INFINITY;
390 39 fs->in[1].sync = 1;
391 39 fs->in[1].before = EXT_NULL;
392 39 fs->in[1].after = EXT_INFINITY;
393 39 return 0;
394 }
395
396 1232 int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
397 {
398 1232 AVFilterContext *ctx = fs->parent;
399 1232 AVFrame *mainpic = NULL, *secondpic = NULL;
400 int ret;
401
402
2/4
✓ Branch 1 taken 1232 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1232 times.
2464 if ((ret = ff_framesync_get_frame(fs, 0, &mainpic, 1)) < 0 ||
403 1232 (ret = ff_framesync_get_frame(fs, 1, &secondpic, 0)) < 0) {
404 av_frame_free(&mainpic);
405 return ret;
406 }
407
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1232 times.
1232 av_assert0(mainpic);
408 1232 mainpic->pts = av_rescale_q(fs->pts, fs->time_base, ctx->outputs[0]->time_base);
409
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1232 times.
1232 if (ctx->is_disabled)
410 secondpic = NULL;
411 1232 *f0 = mainpic;
412 1232 *f1 = secondpic;
413 1232 return 0;
414 }
415
416 1208 int ff_framesync_dualinput_get_writable(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
417 {
418 int ret;
419
420 1208 ret = ff_framesync_dualinput_get(fs, f0, f1);
421
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1208 times.
1208 if (ret < 0)
422 return ret;
423 1208 ret = ff_inlink_make_frame_writable(fs->parent->inputs[0], f0);
424
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1208 times.
1208 if (ret < 0) {
425 av_frame_free(f0);
426 *f1 = NULL;
427 return ret;
428 }
429 1208 return 0;
430 }
431