FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libswscale/ops_dispatch.c
Date: 2026-10-20 10:20:17
Exec Total Coverage
Lines: 422 467 90.4%
Functions: 19 19 100.0%
Branches: 234 287 81.5%

Line Branch Exec Source
1 /**
2 * Copyright (C) 2025 Niklas Haas
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
8 * License 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 GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "libavutil/avassert.h"
22 #include "libavutil/cpu.h"
23 #include "libavutil/mathematics.h"
24 #include "libavutil/mem.h"
25 #include "libavutil/mem_internal.h"
26 #include "libavutil/refstruct.h"
27
28 #include "ops.h"
29 #include "ops_internal.h"
30 #include "ops_dispatch.h"
31 #include "swscale_internal.h"
32
33 #define RET(x) \
34 do { \
35 if ((ret = (x)) < 0) \
36 goto fail; \
37 } while (0)
38
39 typedef struct SwsOpPass {
40 SwsCompiledOp comp;
41 SwsOpExec exec_base;
42 SwsOpExec exec_tail;
43 size_t num_blocks;
44 int tail_off_in;
45 int tail_off_out;
46 int tail_size_in;
47 int tail_size_out;
48 int planes_in;
49 int planes_out;
50 int pixel_bits_in;
51 int pixel_bits_out;
52 int idx_in[4];
53 int idx_out[4];
54 int palette_idx;
55 int *offsets_y;
56 int filter_size_h;
57 int filter_size_v;
58 bool memcpy_in;
59 bool memcpy_out;
60 size_t tail_blocks;
61 uint8_t *tail_buf; /* extra memory for fixing unpadded tails */
62 unsigned int tail_buf_size;
63 } SwsOpPass;
64
65 1677336 static int compile_backend(SwsContext *ctx, const SwsOpBackend *backend,
66 const SwsOpList *ops, SwsCompiledOp *out)
67 {
68 SwsOpList *copy;
69 1677336 SwsCompiledOp compiled = {0};
70 1677336 int ret = 0;
71
72 1677336 copy = ff_sws_op_list_duplicate(ops);
73
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1677336 times.
1677336 if (!copy)
74 ✗ return AVERROR(ENOMEM);
75
76 /* Ensure these are always set during compilation */
77 1677336 ff_sws_op_list_update_comps(copy);
78
79 1677336 ret = backend->compile(ctx, copy, &compiled);
80
2/2
✓ Branch 0 taken 559035 times.
✓ Branch 1 taken 1118301 times.
1677336 if (ret < 0) {
81
1/2
✓ Branch 0 taken 559035 times.
✗ Branch 1 not taken.
559035 int msg_lev = ret == AVERROR(ENOTSUP) ? AV_LOG_TRACE : AV_LOG_ERROR;
82 1118070 av_log(ctx, msg_lev, "Backend '%s' failed to compile operations: %s\n",
83 559035 backend->name, av_err2str(ret));
84 559035 goto fail;
85 }
86
87 1118301 compiled.backend = backend;
88 1118301 *out = compiled;
89
90 1118301 av_log(ctx, AV_LOG_VERBOSE, "Compiled using backend '%s': "
91 "block size = %d, over-read = {%d %d %d %d}, over-write = {%d %d %d %d}, "
92 1118301 "cpu flags = 0x%x\n", backend->name, out->block_size,
93 out->over_read[0], out->over_read[1],
94 out->over_read[2], out->over_read[3],
95 out->over_write[0], out->over_write[1],
96 out->over_write[2], out->over_write[3],
97 out->cpu_flags);
98
99 1118301 ff_sws_op_list_print(ctx, AV_LOG_VERBOSE, AV_LOG_TRACE, ops);
100
101 1677336 fail:
102 1677336 ff_sws_op_list_free(&copy);
103 1677336 return ret;
104 }
105
106 1650531 int ff_sws_ops_compile(SwsContext *ctx, const SwsOpBackend *backend,
107 const SwsOpList *ops, SwsCompiledOp *out)
108 {
109
2/2
✓ Branch 0 taken 1359403 times.
✓ Branch 1 taken 291128 times.
1650531 if (backend)
110 1359403 return compile_backend(ctx, backend, ops, out);
111
112 291128 const SwsBackend enabled = ff_sws_enabled_backends(ctx);
113
2/2
✓ Branch 0 taken 779739 times.
✓ Branch 1 taken 129254 times.
908993 for (int n = 0; ff_sws_op_backends[n]; n++) {
114 779739 const SwsOpBackend *backend = ff_sws_op_backends[n];
115
1/2
✓ Branch 0 taken 779739 times.
✗ Branch 1 not taken.
779739 if (ops->src.hw_format != backend->hw_format ||
116
1/2
✓ Branch 0 taken 779739 times.
✗ Branch 1 not taken.
779739 ops->dst.hw_format != backend->hw_format ||
117
2/2
✓ Branch 0 taken 461806 times.
✓ Branch 1 taken 317933 times.
779739 !(enabled & backend->flags))
118 461806 continue;
119
2/2
✓ Branch 1 taken 156059 times.
✓ Branch 2 taken 161874 times.
317933 if (compile_backend(ctx, backend, ops, out) < 0)
120 156059 continue;
121
122 161874 return 0;
123 }
124
125 129254 return AVERROR(ENOTSUP);
126 }
127
128 1660900 void ff_sws_compiled_op_unref(SwsCompiledOp *comp)
129 {
130
2/2
✓ Branch 0 taken 172243 times.
✓ Branch 1 taken 1488657 times.
1660900 if (comp->free)
131 172243 comp->free(comp->priv);
132
133 1660900 *comp = (SwsCompiledOp) {0};
134 1660900 }
135
136 1650531 static void op_pass_free(void *ptr)
137 {
138 1650531 SwsOpPass *p = ptr;
139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1650531 times.
1650531 if (!p)
140 ✗ return;
141
142 1650531 ff_sws_compiled_op_unref(&p->comp);
143 1650531 av_refstruct_unref(&p->offsets_y);
144 1650531 av_free(p->exec_base.in_bump_y);
145 1650531 av_free(p->exec_base.in_offset_x);
146 1650531 av_free(p->tail_buf);
147 1650531 av_free(p);
148 }
149
150 158400 static inline void get_row_data(const SwsOpPass *p, const int y_dst,
151 const uint8_t *in[4], uint8_t *out[4])
152 {
153 158400 const SwsOpExec *base = &p->exec_base;
154
2/2
✓ Branch 0 taken 34243 times.
✓ Branch 1 taken 124157 times.
158400 const int y_src = p->offsets_y ? p->offsets_y[y_dst] : y_dst;
155
2/2
✓ Branch 0 taken 313640 times.
✓ Branch 1 taken 158400 times.
472040 for (int i = 0; i < p->planes_in; i++)
156 313640 in[i] = base->in[i] + (y_src >> base->in_sub_y[i]) * base->in_stride[i];
157
2/2
✓ Branch 0 taken 343356 times.
✓ Branch 1 taken 158400 times.
501756 for (int i = 0; i < p->planes_out; i++)
158 343356 out[i] = base->out[i] + (y_dst >> base->out_sub_y[i]) * base->out_stride[i];
159 158400 }
160
161 143362 static inline size_t pixel_bytes(size_t pixels, int pixel_bits,
162 enum AVRounding rounding)
163 {
164 143362 const uint64_t bits = (uint64_t) pixels * pixel_bits;
165
2/3
✓ Branch 0 taken 13366 times.
✓ Branch 1 taken 129996 times.
✗ Branch 2 not taken.
143362 switch (rounding) {
166 13366 case AV_ROUND_ZERO:
167 case AV_ROUND_DOWN:
168 13366 return bits >> 3;
169 129996 case AV_ROUND_INF:
170 case AV_ROUND_UP:
171 129996 return (bits + 7) >> 3;
172 ✗ default:
173 ✗ av_unreachable("Invalid rounding mode");
174 return (size_t) -1;
175 }
176 }
177
178 656996 static size_t safe_bytes_pad(int linesize, int plane_pad)
179 {
180 av_assert1(linesize);
181 656996 int64_t safe_bytes = FFABS((int64_t) linesize) - plane_pad;
182 656996 return FFMAX(safe_bytes, 0);
183 }
184
185 93701 static size_t safe_blocks_offset(size_t num_blocks, unsigned block_size,
186 ptrdiff_t safe_offset,
187 const int32_t *offset_bytes)
188 {
189 93701 size_t safe_blocks = num_blocks;
190
3/4
✓ Branch 0 taken 103526 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9825 times.
✓ Branch 3 taken 93701 times.
103526 while (safe_blocks && offset_bytes[safe_blocks * block_size - 1] > safe_offset)
191 9825 safe_blocks--;
192 93701 return safe_blocks;
193 }
194
195 14692 static void copy_lines(uint8_t *dst, const ptrdiff_t dst_stride,
196 const uint8_t *src, const ptrdiff_t src_stride,
197 const int h, const size_t bytes)
198 {
199
2/2
✓ Branch 0 taken 1410016 times.
✓ Branch 1 taken 14692 times.
1424708 for (int y = 0; y < h; y++) {
200 1410016 memcpy(dst, src, bytes);
201 1410016 dst += dst_stride;
202 1410016 src += src_stride;
203 }
204 14692 }
205
206 158400 static int op_pass_setup(const SwsFrame *out, const SwsFrame *in,
207 const SwsPass *pass)
208 {
209 158400 const AVPixFmtDescriptor *indesc = av_pix_fmt_desc_get(in->format);
210 158400 const bool float_in = indesc->flags & AV_PIX_FMT_FLAG_FLOAT;
211 158400 const int width = out->width;
212
213 158400 SwsOpPass *p = pass->priv;
214 158400 SwsOpExec *exec = &p->exec_base;
215 158400 const SwsCompiledOp *comp = &p->comp;
216
217 /* Set up main loop parameters */
218 158400 const unsigned block_size = comp->block_size;
219 158400 const size_t num_blocks = p->num_blocks;
220 158400 const size_t aligned_w = num_blocks * block_size;
221 158400 p->memcpy_in = false;
222 158400 p->memcpy_out = false;
223
224 158400 size_t safe_blocks = num_blocks;
225
2/2
✓ Branch 0 taken 313640 times.
✓ Branch 1 taken 158400 times.
472040 for (int i = 0; i < p->planes_in; i++) {
226 313640 const int idx = p->idx_in[i];
227 313640 size_t input_bytes = in->linesize[idx];
228
4/4
✓ Branch 0 taken 93701 times.
✓ Branch 1 taken 219939 times.
✓ Branch 2 taken 14244 times.
✓ Branch 3 taken 79457 times.
313640 if (p->filter_size_h && float_in) {
229 /* Floating point inputs may contain NaN / Infinity in the padding */
230 14244 const int plane_w = AV_CEIL_RSHIFT(in->width, exec->in_sub_x[i]);
231 14244 input_bytes = pixel_bytes(plane_w, p->pixel_bits_in, AV_ROUND_UP);
232 }
233
234 313640 size_t safe_bytes = safe_bytes_pad(input_bytes, comp->over_read[i]);
235 size_t safe_blocks_in;
236
2/2
✓ Branch 0 taken 93701 times.
✓ Branch 1 taken 219939 times.
313640 if (exec->in_offset_x) {
237 93701 size_t filter_size = pixel_bytes(p->filter_size_h, p->pixel_bits_in,
238 AV_ROUND_UP);
239 93701 safe_blocks_in = safe_blocks_offset(num_blocks, block_size,
240 93701 safe_bytes - filter_size,
241 93701 exec->in_offset_x);
242 } else {
243 219939 safe_blocks_in = safe_bytes / exec->block_size_in[i];
244 }
245
246
2/2
✓ Branch 0 taken 14677 times.
✓ Branch 1 taken 298963 times.
313640 if (safe_blocks_in < num_blocks) {
247 14677 p->memcpy_in = true;
248 14677 safe_blocks = FFMIN(safe_blocks, safe_blocks_in);
249 }
250
251 313640 size_t loop_size = num_blocks * exec->block_size_in[i];
252 313640 exec->in[i] = in->data[idx];
253 313640 exec->in_stride[i] = in->linesize[idx];
254 313640 exec->in_bump[i] = in->linesize[idx] - loop_size;
255 }
256
257
2/2
✓ Branch 0 taken 343356 times.
✓ Branch 1 taken 158400 times.
501756 for (int i = 0; i < p->planes_out; i++) {
258 343356 const int idx = p->idx_out[i];
259 343356 size_t safe_bytes = safe_bytes_pad(out->linesize[idx], comp->over_write[i]);
260 343356 size_t safe_blocks_out = safe_bytes / exec->block_size_out[i];
261
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 343346 times.
343356 if (safe_blocks_out < num_blocks) {
262 10 p->memcpy_out = true;
263 10 safe_blocks = FFMIN(safe_blocks, safe_blocks_out);
264 }
265
266 343356 size_t loop_size = num_blocks * exec->block_size_out[i];
267 343356 exec->out[i] = out->data[idx];
268 343356 exec->out_stride[i] = out->linesize[idx];
269 343356 exec->out_bump[i] = out->linesize[idx] - loop_size;
270 }
271
272
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 158400 times.
158400 if (p->palette_idx >= 0) {
273 ✗ exec->in[1] = in->data[p->palette_idx];
274 ✗ exec->in_stride[1] = exec->in_bump[1] = 0;
275 }
276
277
3/4
✓ Branch 0 taken 149808 times.
✓ Branch 1 taken 8592 times.
✓ Branch 2 taken 149808 times.
✗ Branch 3 not taken.
158400 if (!p->memcpy_in && !p->memcpy_out) {
278
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149808 times.
149808 av_assert0(safe_blocks == num_blocks);
279 149808 return 0;
280 }
281
282 /* Set-up tail section parameters and buffers */
283 8592 SwsOpExec *tail = &p->exec_tail;
284 8592 const int align = av_cpu_max_align();
285 8592 size_t alloc_size = 0;
286 8592 *tail = *exec;
287
288 8592 const size_t safe_width = safe_blocks * block_size;
289 8592 const size_t tail_size = width - safe_width;
290 8592 p->tail_off_out = pixel_bytes(safe_width, p->pixel_bits_out, AV_ROUND_DOWN);
291 8592 p->tail_size_out = pixel_bytes(tail_size, p->pixel_bits_out, AV_ROUND_UP);
292 8592 p->tail_blocks = num_blocks - safe_blocks;
293
294
2/2
✓ Branch 0 taken 3818 times.
✓ Branch 1 taken 4774 times.
8592 if (exec->in_offset_x) {
295 3818 p->tail_off_in = exec->in_offset_x[safe_width];
296 3818 p->tail_size_in = exec->in_offset_x[width - 1] - p->tail_off_in;
297 3818 p->tail_size_in += pixel_bytes(p->filter_size_h, p->pixel_bits_in, AV_ROUND_UP);
298 } else {
299 4774 p->tail_off_in = pixel_bytes(safe_width, p->pixel_bits_in, AV_ROUND_DOWN);
300 4774 p->tail_size_in = pixel_bytes(tail_size, p->pixel_bits_in, AV_ROUND_UP);
301 }
302
303 8592 const size_t alloc_width = aligned_w - safe_width;
304
3/4
✓ Branch 0 taken 23269 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14677 times.
✓ Branch 3 taken 8592 times.
23269 for (int i = 0; p->memcpy_in && i < p->planes_in; i++) {
305 size_t needed_size;
306
2/2
✓ Branch 0 taken 9825 times.
✓ Branch 1 taken 4852 times.
14677 if (exec->in_offset_x) {
307 /* The input offset map is already padded to multiples of the block
308 * size, and clamps the input offsets to the image boundaries; so
309 * we just need to compensate for the comp->over_read */
310 9825 needed_size = p->tail_size_in;
311 } else {
312 4852 needed_size = pixel_bytes(alloc_width, p->pixel_bits_in, AV_ROUND_UP);
313 }
314 14677 size_t loop_size = p->tail_blocks * exec->block_size_in[i];
315 14677 tail->in_stride[i] = FFALIGN(needed_size + comp->over_read[i], align);
316 14677 tail->in_bump[i] = tail->in_stride[i] - loop_size;
317 14677 alloc_size += tail->in_stride[i] * in->height;
318 }
319
320
4/4
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 8588 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 4 times.
8607 for (int i = 0; p->memcpy_out && i < p->planes_out; i++) {
321 15 size_t needed_size = pixel_bytes(alloc_width, p->pixel_bits_out, AV_ROUND_UP);
322 15 size_t loop_size = p->tail_blocks * exec->block_size_out[i];
323 15 tail->out_stride[i] = FFALIGN(needed_size + comp->over_write[i], align);
324 15 tail->out_bump[i] = tail->out_stride[i] - loop_size;
325 15 alloc_size += tail->out_stride[i] * out->height;
326 }
327
328
3/4
✓ Branch 0 taken 8592 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3818 times.
✓ Branch 3 taken 4774 times.
8592 if (p->memcpy_in && exec->in_offset_x) {
329 /* `in_offset_x` is indexed relative to the line start, not the start
330 * of the section being processed; so we need to over-allocate this
331 * array to the full width of the image, even though we will only
332 * partially fill in the offsets relevant to the tail region */
333 3818 alloc_size += aligned_w * sizeof(*exec->in_offset_x);
334 }
335
336 8592 av_fast_mallocz(&p->tail_buf, &p->tail_buf_size, alloc_size);
337
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8592 times.
8592 if (!p->tail_buf)
338 ✗ return AVERROR(ENOMEM);
339
340 8592 uint8_t *tail_buf = p->tail_buf;
341
3/4
✓ Branch 0 taken 23269 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14677 times.
✓ Branch 3 taken 8592 times.
23269 for (int i = 0; p->memcpy_in && i < p->planes_in; i++) {
342 14677 tail->in[i] = tail_buf;
343 14677 tail_buf += tail->in_stride[i] * in->height;
344 }
345
346
4/4
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 8588 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 4 times.
8607 for (int i = 0; p->memcpy_out && i < p->planes_out; i++) {
347 15 tail->out[i] = tail_buf;
348 15 tail_buf += tail->out_stride[i] * out->height;
349 }
350
351
3/4
✓ Branch 0 taken 8592 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3818 times.
✓ Branch 3 taken 4774 times.
8592 if (p->memcpy_in && exec->in_offset_x) {
352 3818 tail->in_offset_x = (int32_t *) tail_buf;
353
2/2
✓ Branch 0 taken 61088 times.
✓ Branch 1 taken 3818 times.
64906 for (int i = safe_width; i < aligned_w; i++)
354 61088 tail->in_offset_x[i] = exec->in_offset_x[i] - p->tail_off_in;
355 }
356
357 /* If vertically filtering, we need to copy all lines before processing
358 * any slice, because filters may read past the current slice bounds */
359
2/6
✓ Branch 0 taken 8592 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8592 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
8592 for (int i = 0; p->memcpy_in && p->offsets_y && i < p->planes_in; i++) {
360 ✗ const int lines = AV_CEIL_RSHIFT(in->height, exec->in_sub_y[i]);
361 ✗ copy_lines((uint8_t *) tail->in[i], tail->in_stride[i],
362 ✗ exec->in[i] + p->tail_off_in, exec->in_stride[i],
363 ✗ lines, p->tail_size_in);
364 }
365
366 8592 return 0;
367 }
368
369 158400 static void op_pass_run(const SwsFrame *out, const SwsFrame *in, const int y,
370 const int h, const SwsPass *pass)
371 {
372 158400 const SwsOpPass *p = pass->priv;
373 158400 const SwsCompiledOp *comp = &p->comp;
374
375 /* Fill exec metadata for this slice */
376 158400 DECLARE_ALIGNED_32(SwsOpExec, exec) = p->exec_base;
377 158400 exec.slice_y = y;
378 158400 exec.slice_h = h;
379
380 /**
381 * To ensure safety, we need to consider the following:
382 *
383 * 1. We can overread the input, unless this is the last line of an
384 * unpadded buffer. All defined operations can handle arbitrary pixel
385 * input, so overread of arbitrary data is fine. For flipped images,
386 * this condition is actually *inverted* to where the first line is
387 * the one at the end of the buffer.
388 *
389 * 2. We can overwrite the output, as long as we don't write more than the
390 * amount of pixels that fit into one linesize. So we always need to
391 * memcpy the last column on the output side if unpadded.
392 */
393
394
2/2
✓ Branch 0 taken 34243 times.
✓ Branch 1 taken 124157 times.
158400 const int y_in = p->offsets_y ? p->offsets_y[y] : y;
395 158400 const bool memcpy_in = p->memcpy_in;
396 158400 const bool memcpy_out = p->memcpy_out;
397 158400 const size_t num_blocks = p->num_blocks;
398 158400 const size_t tail_blocks = p->tail_blocks;
399
400 158400 get_row_data(p, y, exec.in, exec.out);
401
3/4
✓ Branch 0 taken 149808 times.
✓ Branch 1 taken 8592 times.
✓ Branch 2 taken 149808 times.
✗ Branch 3 not taken.
158400 if (!memcpy_in && !memcpy_out) {
402 /* Fast path (fully aligned/padded inputs and outputs) */
403 149808 comp->func(&exec, comp->priv, 0, y, num_blocks, y + h);
404 149808 return;
405 }
406
407 /* Non-aligned case (slow path); process main blocks as normal, and
408 * a separate tail (via memcpy into an appropriately padded buffer) */
409
1/2
✓ Branch 0 taken 8592 times.
✗ Branch 1 not taken.
8592 if (num_blocks > tail_blocks) {
410
2/2
✓ Branch 0 taken 34368 times.
✓ Branch 1 taken 8592 times.
42960 for (int i = 0; i < 4; i++) {
411 /* We process fewer blocks, so the in_bump needs to be increased
412 * to reflect that the plane pointers are left on the last block,
413 * not the end of the processed line, after each loop iteration */
414 34368 exec.in_bump[i] += exec.block_size_in[i] * tail_blocks;
415 34368 exec.out_bump[i] += exec.block_size_out[i] * tail_blocks;
416 }
417
418 8592 comp->func(&exec, comp->priv, 0, y, num_blocks - tail_blocks, y + h);
419 }
420
421 8592 DECLARE_ALIGNED_32(SwsOpExec, tail) = p->exec_tail;
422 8592 tail.slice_y = y;
423 8592 tail.slice_h = h;
424
425
2/2
✓ Branch 0 taken 14677 times.
✓ Branch 1 taken 8592 times.
23269 for (int i = 0; i < p->planes_in; i++) {
426 /* Input offsets are relative to the base pointer */
427
3/4
✓ Branch 0 taken 9825 times.
✓ Branch 1 taken 4852 times.
✓ Branch 2 taken 9825 times.
✗ Branch 3 not taken.
14677 if (!exec.in_offset_x || memcpy_in)
428 14677 exec.in[i] += p->tail_off_in;
429 14677 tail.in[i] += (y_in >> exec.in_sub_y[i]) * tail.in_stride[i];
430 }
431
2/2
✓ Branch 0 taken 22182 times.
✓ Branch 1 taken 8592 times.
30774 for (int i = 0; i < p->planes_out; i++) {
432 22182 exec.out[i] += p->tail_off_out;
433 22182 tail.out[i] += y * tail.out_stride[i];
434 }
435
436
2/2
✓ Branch 0 taken 14677 times.
✓ Branch 1 taken 8592 times.
23269 for (int i = 0; i < p->planes_in; i++) {
437
1/2
✓ Branch 0 taken 14677 times.
✗ Branch 1 not taken.
14677 if (memcpy_in) {
438
1/2
✓ Branch 0 taken 14677 times.
✗ Branch 1 not taken.
14677 if (!p->offsets_y) { /* already copied by op_pass_setup() */
439 14677 const int lines = h >> exec.in_sub_y[i];
440 14677 copy_lines((uint8_t *) tail.in[i], tail.in_stride[i],
441 14677 exec.in[i], exec.in_stride[i], lines, p->tail_size_in);
442 }
443 } else {
444 /* Reuse input pointers directly */
445 ✗ const size_t loop_size = tail_blocks * exec.block_size_in[i];
446 ✗ tail.in[i] = exec.in[i];
447 ✗ tail.in_stride[i] = exec.in_stride[i];
448 ✗ tail.in_bump[i] = exec.in_stride[i] - loop_size;
449 }
450 }
451
452
4/4
✓ Branch 0 taken 30755 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 22167 times.
✓ Branch 3 taken 8588 times.
30759 for (int i = 0; !memcpy_out && i < p->planes_out; i++) {
453 /* Reuse output pointers directly */
454 22167 const size_t loop_size = tail_blocks * exec.block_size_out[i];
455 22167 tail.out[i] = exec.out[i];
456 22167 tail.out_stride[i] = exec.out_stride[i];
457 22167 tail.out_bump[i] = exec.out_stride[i] - loop_size;
458 }
459
460 /* Dispatch kernel over tail */
461 av_assert1(tail_blocks > 0);
462 8592 comp->func(&tail, comp->priv, num_blocks - tail_blocks, y, num_blocks, y + h);
463
464
4/4
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 8588 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 4 times.
8607 for (int i = 0; memcpy_out && i < p->planes_out; i++) {
465 15 const int lines = h >> tail.out_sub_y[i];
466 15 copy_lines(exec.out[i], exec.out_stride[i],
467 15 tail.out[i], tail.out_stride[i], lines, p->tail_size_out);
468 }
469 }
470
471 /* Updates the plane copy (no-op) map for this operation list */
472 161874 static void op_list_get_plane_copy(const SwsOpList *ops, SwsPass *pass)
473 {
474 161874 const SwsOp *write = ff_sws_op_list_output(ops);
475 161874 const SwsOp *read = ff_sws_op_list_input(ops);
476
5/6
✓ Branch 0 taken 161874 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 124913 times.
✓ Branch 3 taken 36961 times.
✓ Branch 4 taken 109337 times.
✓ Branch 5 taken 15576 times.
161874 if (!write || write->rw.mode != SWS_RW_PLANAR ||
477
2/2
✓ Branch 0 taken 73995 times.
✓ Branch 1 taken 35342 times.
109337 !read || read->rw.mode != SWS_RW_PLANAR ||
478
2/2
✓ Branch 0 taken 29449 times.
✓ Branch 1 taken 44546 times.
73995 read->type != write->type ||
479
2/2
✓ Branch 0 taken 786 times.
✓ Branch 1 taken 28663 times.
29449 read->rw.frac != write->rw.frac)
480 133211 return; /* only regular planes can be directly ref'd */
481
482 28663 const SwsOp *prev = &ops->ops[ops->num_ops - 2];
483 28663 int *plane_copy = pass->output->plane_copy;
484
2/2
✓ Branch 0 taken 74652 times.
✓ Branch 1 taken 28663 times.
103315 for (int i = 0; i < write->rw.elems; i++) {
485 74652 SwsCompFlags flags = prev->comps.flags[i];
486
2/2
✓ Branch 0 taken 74376 times.
✓ Branch 1 taken 276 times.
74652 if (!(flags & SWS_COMP_COPY))
487 74376 continue;
488
489 276 const int out_idx = ops->plane_dst[i];
490
3/5
✓ Branch 0 taken 196 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
276 switch (prev->comps.dep_in[i]) {
491 196 case SWS_COMP(0): plane_copy[out_idx] = ops->plane_src[0]; break;
492 40 case SWS_COMP(1): plane_copy[out_idx] = ops->plane_src[1]; break;
493 40 case SWS_COMP(2): plane_copy[out_idx] = ops->plane_src[2]; break;
494 ✗ case SWS_COMP(3): plane_copy[out_idx] = ops->plane_src[3]; break;
495 }
496 }
497 }
498
499 308172 static int rw_data_planes(const SwsOp *op)
500 {
501 /* Exclude the palette plane from the plane count, since it does not need
502 * to be directly processed/adjusted by the dispatch layer */
503
1/2
✓ Branch 0 taken 308172 times.
✗ Branch 1 not taken.
308172 return op->rw.mode == SWS_RW_PALETTE ? 1 : ff_sws_rw_op_planes(op);
504 }
505
506 308172 static int rw_pixel_bits(const SwsOp *op)
507 {
508
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 308172 times.
308172 if (op->rw.mode == SWS_RW_PALETTE)
509 ✗ return 8; /* index size */
510
511 308172 int elems = 0;
512
2/3
✓ Branch 0 taken 227721 times.
✓ Branch 1 taken 80451 times.
✗ Branch 2 not taken.
308172 switch (op->rw.mode) {
513 227721 case SWS_RW_PLANAR: elems = 1; break;
514 80451 case SWS_RW_PACKED: elems = op->rw.elems; break;
515 }
516
517 308172 const int size = ff_sws_pixel_type_size(op->type);
518 308172 const int bits = 8 >> op->rw.frac;
519 av_assert1(bits >= 1);
520 308172 return elems * size * bits;
521 }
522
523 308172 static void align_pass(SwsPass *pass, int block_size, const int *over_rw,
524 int pixel_bits)
525 {
526
3/4
✓ Branch 0 taken 220445 times.
✓ Branch 1 taken 87727 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 220445 times.
308172 if (!pass || pixel_bits <= 0)
527 87727 return;
528
529 /* Add at least as many pixels as needed to cover the padding requirement */
530 220445 int pad_max = 0;
531
2/2
✓ Branch 0 taken 881780 times.
✓ Branch 1 taken 220445 times.
1102225 for (int i = 0; i < 4; i++) {
532 881780 const int pad = (over_rw[i] * 8 + pixel_bits - 1) / pixel_bits;
533 881780 pad_max = FFMAX(pad_max, pad);
534 }
535
536 220445 SwsPassBuffer *buf = pass->output;
537 220445 buf->width_align = FFMAX(buf->width_align, block_size);
538 220445 buf->width_pad = FFMAX(buf->width_pad, pad_max);
539 }
540
541 /* Unchanging part of parameter list */
542 typedef struct CompileArgs {
543 const SwsOpBackend *backend;
544 SwsGraph *graph;
545 int flags;
546 } CompileArgs;
547
548 1650531 static int compile_single(const CompileArgs *args, const SwsOpList *ops,
549 SwsPass *link, SwsPass *input, SwsPass **output)
550 {
551 1650531 SwsGraph *graph = args->graph;
552 1650531 SwsContext *ctx = graph->ctx;
553 1650531 SwsOpPass *p = av_mallocz(sizeof(*p));
554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1650531 times.
1650531 if (!p)
555 ✗ return AVERROR(ENOMEM);
556
557 1650531 int ret = ff_sws_ops_compile(ctx, args->backend, ops, &p->comp);
558
2/2
✓ Branch 0 taken 532230 times.
✓ Branch 1 taken 1118301 times.
1650531 if (ret < 0)
559 532230 goto fail;
560
2/2
✓ Branch 0 taken 956427 times.
✓ Branch 1 taken 161874 times.
1118301 else if (args->flags & SWS_OP_FLAG_DRY_RUN)
561 956427 goto fail; /* nothing to do, just return */
562
563 161874 const SwsCompiledOp *comp = &p->comp;
564 161874 const SwsFormat *src = &ops->src;
565 161874 const SwsFormat *dst = &ops->dst;
566
3/4
✓ Branch 0 taken 14188 times.
✓ Branch 1 taken 147686 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 14188 times.
161874 av_assert0(!link || link->format == dst->format);
567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 161874 times.
161874 if (p->comp.opaque) {
568 ✗ SwsCompiledOp c = *comp;
569 ✗ av_free(p);
570 ✗ ret = ff_sws_graph_add_pass(graph, dst->format, dst->width, dst->height,
571 input, 0, c.slice_align, c.func_opaque,
572 NULL, c.priv, c.free, output);
573 ✗ if (ret >= 0) {
574 ✗ (*output)->backend = c.backend->flags;
575 ✗ op_list_get_plane_copy(ops, *output);
576 ✗ ff_sws_pass_link_output(*output, link);
577 }
578 ✗ return ret;
579 }
580
581 161874 const AVPixFmtDescriptor *indesc = av_pix_fmt_desc_get(src->format);
582 161874 const AVPixFmtDescriptor *outdesc = av_pix_fmt_desc_get(dst->format);
583 161874 const SwsOp *write = ff_sws_op_list_output(ops);
584 161874 p->planes_out = rw_data_planes(write);
585 161874 p->pixel_bits_out = rw_pixel_bits(write);
586 161874 p->palette_idx = -1;
587 161874 p->num_blocks = (dst->width + comp->block_size - 1) / comp->block_size;
588
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 161874 times.
161874 if (p->num_blocks * comp->block_size < (unsigned) dst->width)
589 ✗ return AVERROR(ERANGE);
590
591 161874 SwsOpExec *exec = &p->exec_base;
592 161874 *exec = (SwsOpExec) {
593 161874 .width = dst->width,
594 161874 .height = dst->height,
595 };
596
597 161874 const SwsOp *read = ff_sws_op_list_input(ops);
598
2/2
✓ Branch 0 taken 146298 times.
✓ Branch 1 taken 15576 times.
161874 if (read) {
599 146298 p->planes_in = rw_data_planes(read);
600 146298 p->pixel_bits_in = rw_pixel_bits(read);
601
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 146298 times.
146298 if (read->rw.mode == SWS_RW_PALETTE)
602 ✗ p->palette_idx = ops->plane_src[1];
603 }
604
605 161874 const int64_t block_bits_in = (int64_t) comp->block_size * p->pixel_bits_in;
606 161874 const int64_t block_bits_out = (int64_t) comp->block_size * p->pixel_bits_out;
607
2/4
✓ Branch 0 taken 161874 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 161874 times.
161874 if (block_bits_in & 0x7 || block_bits_out & 0x7) {
608 ✗ av_log(ctx, AV_LOG_ERROR, "Block size must be byte-aligned.\n");
609 ✗ ret = AVERROR(EINVAL);
610 ✗ goto fail;
611 }
612
613
2/2
✓ Branch 0 taken 647496 times.
✓ Branch 1 taken 161874 times.
809370 for (int i = 0; i < 4; i++)
614 647496 p->idx_in[i] = p->idx_out[i] = -1;
615
616
2/2
✓ Branch 0 taken 318435 times.
✓ Branch 1 taken 161874 times.
480309 for (int i = 0; i < p->planes_in; i++) {
617 318435 const int idx = ops->plane_src[i];
618
4/4
✓ Branch 0 taken 237042 times.
✓ Branch 1 taken 81393 times.
✓ Branch 2 taken 79719 times.
✓ Branch 3 taken 157323 times.
318435 const int chroma = idx == 1 || idx == 2;
619
2/2
✓ Branch 0 taken 161112 times.
✓ Branch 1 taken 157323 times.
318435 const int sub_x = chroma ? indesc->log2_chroma_w : 0;
620
2/2
✓ Branch 0 taken 161112 times.
✓ Branch 1 taken 157323 times.
318435 const int sub_y = chroma ? indesc->log2_chroma_h : 0;
621 318435 exec->in_sub_x[i] = sub_x;
622 318435 exec->in_sub_y[i] = sub_y;
623 318435 exec->block_size_in[i] = block_bits_in >> 3;
624 318435 p->idx_in[i] = idx;
625 }
626
627
2/2
✓ Branch 0 taken 351216 times.
✓ Branch 1 taken 161874 times.
513090 for (int i = 0; i < p->planes_out; i++) {
628 351216 const int idx = ops->plane_dst[i];
629
4/4
✓ Branch 0 taken 260694 times.
✓ Branch 1 taken 90522 times.
✓ Branch 2 taken 88793 times.
✓ Branch 3 taken 171901 times.
351216 const int chroma = idx == 1 || idx == 2;
630
2/2
✓ Branch 0 taken 179315 times.
✓ Branch 1 taken 171901 times.
351216 const int sub_x = chroma ? outdesc->log2_chroma_w : 0;
631
2/2
✓ Branch 0 taken 179315 times.
✓ Branch 1 taken 171901 times.
351216 const int sub_y = chroma ? outdesc->log2_chroma_h : 0;
632 351216 exec->out_sub_x[i] = sub_x;
633 351216 exec->out_sub_y[i] = sub_y;
634 351216 exec->block_size_out[i] = block_bits_out >> 3;
635 351216 p->idx_out[i] = idx;
636 }
637
638
2/2
✓ Branch 0 taken 146298 times.
✓ Branch 1 taken 15576 times.
161874 const SwsFilterWeights *filter = read ? read->rw.filter.kernel : NULL;
639
4/4
✓ Branch 0 taken 146298 times.
✓ Branch 1 taken 15576 times.
✓ Branch 2 taken 34022 times.
✓ Branch 3 taken 112276 times.
161874 if (read && read->rw.filter.op == SWS_OP_FILTER_V) {
640 34022 p->offsets_y = av_refstruct_ref(filter->offsets);
641 34022 p->filter_size_v = filter->filter_size;
642
643 /* Compute relative pointer bumps for each output line */
644 34022 int32_t *bump = av_malloc_array(filter->dst_size, sizeof(*bump));
645
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34022 times.
34022 if (!bump) {
646 ✗ ret = AVERROR(ENOMEM);
647 ✗ goto fail;
648 }
649
650 34022 int line = filter->offsets[0];
651
2/2
✓ Branch 0 taken 3222362 times.
✓ Branch 1 taken 34022 times.
3256384 for (int y = 0; y < filter->dst_size - 1; y++) {
652 3222362 int next = filter->offsets[y + 1];
653 3222362 bump[y] = next - line - 1;
654 3222362 line = next;
655 }
656 34022 bump[filter->dst_size - 1] = 0;
657 34022 exec->in_bump_y = bump;
658
4/4
✓ Branch 0 taken 112276 times.
✓ Branch 1 taken 15576 times.
✓ Branch 2 taken 35390 times.
✓ Branch 3 taken 76886 times.
127852 } else if (read && read->rw.filter.op == SWS_OP_FILTER_H) {
659 /* Compute pixel offset map for each output line */
660 35390 const int pixels = FFALIGN(filter->dst_size, comp->block_size);
661 35390 int32_t *offset = av_malloc_array(pixels, sizeof(*offset));
662
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35390 times.
35390 if (!offset) {
663 ✗ ret = AVERROR(ENOMEM);
664 ✗ goto fail;
665 }
666 35390 exec->in_offset_x = offset;
667
668
2/2
✓ Branch 0 taken 3399104 times.
✓ Branch 1 taken 35390 times.
3434494 for (int x = 0; x < filter->dst_size; x++) {
669 /* Sanity check; if the tap would land on a half-pixel, we cannot
670 * reasonably expect the implementation to know about this. Just
671 * error out in such (theoretical) cases. */
672 3399104 int64_t bits = (int64_t) filter->offsets[x] * p->pixel_bits_in;
673
2/4
✓ Branch 0 taken 3399104 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3399104 times.
3399104 if ((bits & 0x7) || (bits >> 3) > INT32_MAX) {
674 ✗ ret = AVERROR(EINVAL);
675 ✗ goto fail;
676 }
677 3399104 offset[x] = bits >> 3;
678 }
679
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35390 times.
35390 for (int x = filter->dst_size; x < pixels; x++)
680 ✗ offset[x] = offset[filter->dst_size - 1];
681
2/2
✓ Branch 0 taken 141560 times.
✓ Branch 1 taken 35390 times.
176950 for (int i = 0; i < 4; i++)
682 141560 exec->block_size_in[i] = 0; /* ptr does not advance */
683 35390 p->filter_size_h = filter->filter_size;
684 }
685
686 161874 ret = ff_sws_graph_add_pass(graph, dst->format, dst->width, dst->height,
687 161874 input, 0, comp->slice_align, op_pass_run,
688 op_pass_setup, p, op_pass_free, output);
689
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 161874 times.
161874 if (ret < 0)
690 ✗ return ret;
691
692 161874 (*output)->backend = comp->backend->flags;
693 161874 op_list_get_plane_copy(ops, *output);
694 161874 ff_sws_pass_link_output(*output, link);
695 161874 align_pass(*output, comp->block_size, comp->over_write, p->pixel_bits_out);
696
2/2
✓ Branch 0 taken 146298 times.
✓ Branch 1 taken 15576 times.
161874 if (read)
697 146298 align_pass(input, comp->block_size, comp->over_read, p->pixel_bits_in);
698 161874 return 0;
699
700 1488657 fail:
701 1488657 op_pass_free(p);
702 1488657 return ret;
703 }
704
705 /* Return a mask of all planes matching any flag in `flags` */
706 1717714 static SwsCompMask plane_mask_flags(const SwsOp *op, SwsCompFlags flags)
707 {
708 1717714 SwsCompMask planes = 0;
709
2/2
✓ Branch 0 taken 6870856 times.
✓ Branch 1 taken 1717714 times.
8588570 for (int c = 0; c < 4; c++) {
710
2/2
✓ Branch 0 taken 358392 times.
✓ Branch 1 taken 6512464 times.
6870856 if (op->comps.flags[c] & flags)
711 358392 planes |= SWS_COMP(c);
712 }
713
714 1717714 return planes;
715 }
716
717 /* Takes over ownership of *pops, even on failure */
718 1717714 static int compile_subpass(const CompileArgs *args, SwsOpList **pops,
719 SwsPass *link, SwsPass *input, SwsPass **output)
720 {
721 int ret;
722 1717714 SwsContext *ctx = args->graph->ctx;
723 1717714 SwsOpList *ops = *pops;
724 1717714 SwsOpList *rest = NULL;
725 1717714 SwsPass *tmp = NULL;
726 1717714 *pops = NULL;
727
728
1/2
✓ Branch 0 taken 1717714 times.
✗ Branch 1 not taken.
1717714 if (args->flags & SWS_OP_FLAG_SPLIT_MEMCPY) {
729 /* Split off copied and constant planes into a separate subpass,
730 * since these are likely to be handled by the memcpy backend */
731
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1717714 times.
1717714 av_assert0(ops->num_ops >= 2);
732 1717714 const SwsOp *prev = &ops->ops[ops->num_ops - 2];
733 1717714 SwsCompMask planes = plane_mask_flags(prev, SWS_COMP_COPY | SWS_COMP_CONST);
734
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1717714 times.
1717714 RET(ff_sws_op_list_split_planes(ops, &rest, planes));
735
2/2
✓ Branch 0 taken 67183 times.
✓ Branch 1 taken 1650531 times.
1717714 if (rest) {
736 /* Parallel split: share input and link all outputs together */
737 67183 av_log(ctx, AV_LOG_DEBUG, "Splitting const/memcpy planes: %s\n",
738 67183 ff_sws_comp_mask_str(planes));
739
2/2
✓ Branch 1 taken 6601 times.
✓ Branch 2 taken 60582 times.
68598 RET(compile_subpass(args, &ops, link, input, &tmp));
740
2/2
✓ Branch 1 taken 1415 times.
✓ Branch 2 taken 59167 times.
60582 RET(compile_subpass(args, &rest, tmp, input, output));
741 59167 return 0;
742 }
743 }
744
745 1650531 ret = compile_single(args, ops, link, input, output);
746
2/2
✓ Branch 0 taken 1118301 times.
✓ Branch 1 taken 532230 times.
1650531 if (ret != AVERROR(ENOTSUP))
747 1118301 goto fail; /* either success or a hard error */
748
749 /* Find any unresolved filter */
750
2/2
✓ Branch 0 taken 1012469 times.
✓ Branch 1 taken 50437 times.
1062906 for (int idx = 1; idx < ops->num_ops - 1; idx++) {
751 1012469 const SwsOp *op = &ops->ops[idx];
752
4/4
✓ Branch 0 taken 786369 times.
✓ Branch 1 taken 226100 times.
✓ Branch 2 taken 255693 times.
✓ Branch 3 taken 530676 times.
1012469 if (op->op == SWS_OP_FILTER_H || op->op == SWS_OP_FILTER_V) {
753
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 481793 times.
481793 RET(ff_sws_op_list_split_at(ops, &rest, idx));
754
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 481793 times.
481793 if (ff_sws_op_list_is_noop(ops)) {
755 /* Prevent infinite recursion by avoiding splitting in a way
756 * that does not meaningfully reduce the number of operations
757 * performed in the second part. */
758 ✗ FFSWAP(SwsOpList *, ops, rest);
759 ✗ break;
760 }
761 /* Serial split: feed first pass into second */
762
2/2
✓ Branch 1 taken 18114 times.
✓ Branch 2 taken 463679 times.
481793 RET(compile_subpass(args, &ops, NULL, input, &tmp));
763
2/2
✓ Branch 1 taken 3114 times.
✓ Branch 2 taken 460565 times.
463679 RET(compile_subpass(args, &rest, link, tmp, output));
764 460565 return 0;
765 }
766 }
767
768 /* If we didn't find any more operations to eliminate, then this ops list
769 * is simply unsupported by any of the available backends */
770 50437 av_log(ctx, AV_LOG_WARNING, "No backend found for operations:\n");
771 50437 ff_sws_op_list_print(ctx, AV_LOG_WARNING, AV_LOG_TRACE, ops);
772 50437 ret = AVERROR(ENOTSUP);
773
774 1197982 fail:
775 1197982 ff_sws_op_list_free(&ops);
776 1197982 ff_sws_op_list_free(&rest);
777 1197982 return ret;
778 }
779
780 645183 int ff_sws_compile_pass(SwsGraph *graph, const SwsOpBackend *backend,
781 SwsOpList **pops, int flags, SwsPass *input,
782 SwsPass **output)
783 {
784 645183 const int passes_orig = graph->num_passes;
785 645183 SwsContext *ctx = graph->ctx;
786 645183 SwsOpList *ops = *pops;
787 645183 int ret = 0;
788
789 645183 const SwsOp *write = ff_sws_op_list_output(ops);
790
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 645183 times.
645183 if (!write) {
791 ✗ av_log(ctx, AV_LOG_ERROR, "Last operation must be SWS_OP_WRITE.\n");
792 ✗ ret = AVERROR(EINVAL);
793 ✗ goto out;
794 }
795
796
2/2
✓ Branch 0 taken 136071 times.
✓ Branch 1 taken 509112 times.
645183 if (flags & SWS_OP_FLAG_OPTIMIZE) {
797 136071 ret = ff_sws_op_list_optimize(ops);
798
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 136071 times.
136071 if (ret < 0)
799 ✗ goto out;
800 136071 av_log(ctx, AV_LOG_DEBUG, "Operation list after optimizing:\n");
801 136071 ff_sws_op_list_print(ctx, AV_LOG_DEBUG, AV_LOG_TRACE, ops);
802 }
803
804 /* Check if the whole operation graph is an end-to-end no-op */
805
2/2
✓ Branch 1 taken 706 times.
✓ Branch 2 taken 644477 times.
645183 if (ff_sws_op_list_is_noop(ops)) {
806
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 640 times.
706 if (output)
807 66 *output = input;
808 706 goto out;
809 }
810
811 644477 const CompileArgs args = {
812 .backend = backend,
813 .graph = graph,
814 .flags = flags,
815 };
816
817 644477 ret = compile_subpass(&args, &ops, NULL, input, output);
818
2/2
✓ Branch 0 taken 50437 times.
✓ Branch 1 taken 594040 times.
644477 if (ret < 0)
819 50437 goto out;
820
821 594040 const int num_passes = graph->num_passes - passes_orig;
822
2/2
✓ Branch 0 taken 546242 times.
✓ Branch 1 taken 47798 times.
594040 if (num_passes > 1)
823 47798 av_log(ctx, AV_LOG_VERBOSE, "Using %d separate passes.\n", num_passes);
824
825 546242 out:
826
2/2
✓ Branch 0 taken 50437 times.
✓ Branch 1 taken 594746 times.
645183 if (ret < 0)
827 50437 ff_sws_graph_rollback(graph, passes_orig);
828 645183 ff_sws_op_list_free(&ops);
829 645183 *pops = NULL;
830 645183 return ret;
831 }
832