FFmpeg
Loading...
Searching...
No Matches
swscale.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024 Niklas Haas
3 * Copyright (C) 2003-2011 Michael Niedermayer <michaelni@gmx.at>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <inttypes.h>
26#include <stdarg.h>
27#include <signal.h>
28
29#undef HAVE_AV_CONFIG_H
30#include "libavutil/cpu.h"
31#include "libavutil/avstring.h"
32#include "libavutil/bprint.h"
34#include "libavutil/pixdesc.h"
35#include "libavutil/lfg.h"
36#include "libavutil/md5.h"
37#include "libavutil/sfc64.h"
39#include "libavutil/thread.h"
41#include "libavutil/frame.h"
42#include "libavutil/opt.h"
43#include "libavutil/time.h"
44#include "libavutil/pixfmt.h"
45#include "libavutil/avassert.h"
46#include "libavutil/macros.h"
47#include "libavutil/hwcontext.h"
48
49#include "libswscale/swscale.h"
50#include "libswscale/format.h"
52
53#define IMPL_NEW 0
54#define IMPL_LEGACY 1
55
56/* Settings used for auxiliary conversions */
57enum {
60};
61
84
91
93 float ssim[4];
94 float loss;
96 int iters;
97};
98
99struct runner {
100 /* reused between tests for efficiency */
105};
106
115
126
127static struct {
129
132
138
142
145 FILE *fp;
146
147 /* Tests waiting for a runner, if running concurrently */
149} state = {
150 .speedup_lock = AV_MUTEX_INITIALIZER,
151 .speedup_min = 1e10,
153
154static const char *speedup_color(double ratio)
155{
156 return ratio > 10.00 ? "\033[1;94m" : /* bold blue */
157 ratio > 2.00 ? "\033[1;32m" : /* bold green */
158 ratio > 1.02 ? "\033[32m" : /* green */
159 ratio > 0.98 ? "" : /* default */
160 ratio > 0.90 ? "\033[33m" : /* yellow */
161 ratio > 0.75 ? "\033[31m" : /* red */
162 "\033[1;31m"; /* bold red */
163}
164
165static void exit_handler(int sig)
166{
167 if (state.speedup_count) {
168 double ratio = exp(state.speedup_logavg / state.speedup_count);
169 fprintf(stderr, "Overall speedup=%.3fx %s%s\033[0m, min=%.3fx max=%.3fx\n", ratio,
170 speedup_color(ratio), ratio >= 1.0 ? "faster" : "slower",
171 state.speedup_min, state.speedup_max);
172 }
173
174 exit(sig);
175}
176
177/* Estimate luma variance assuming uniform dither noise distribution */
179{
181 float variance = 1.0 / 12;
182 if (desc->comp[0].depth < 8) {
183 /* Extra headroom for very low bit depth output */
184 variance *= (8 - desc->comp[0].depth);
185 }
186
187 if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) {
188 return 0.0;
189 } else if (desc->flags & AV_PIX_FMT_FLAG_RGB) {
190 const float r = 0.299 / (1 << desc->comp[0].depth);
191 const float g = 0.587 / (1 << desc->comp[1].depth);
192 const float b = 0.114 / (1 << desc->comp[2].depth);
193 return (r * r + g * g + b * b) * variance;
194 } else {
195 const float y = 1.0 / (1 << desc->comp[0].depth);
196 return y * y * variance;
197 }
198}
199
200static int fmt_comps(enum AVPixelFormat fmt)
201{
203 int comps = desc->nb_components >= 3 ? 0x7 : 0x1;
204 if (desc->flags & AV_PIX_FMT_FLAG_ALPHA)
205 comps |= 0x8;
206 return comps;
207}
208
209static void get_ssim(float ssim[4], const AVFrame *out, const AVFrame *ref, int comps)
210{
212 av_assert1(ref->format == out->format);
213 av_assert1(ref->width == out->width && ref->height == out->height);
214
215 for (int p = 0; p < 4; p++) {
216 const int stride_a = out->linesize[p];
217 const int stride_b = ref->linesize[p];
218 const int w = out->width;
219 const int h = out->height;
220
221 const int is_chroma = p == 1 || p == 2;
222 const uint8_t def = is_chroma ? 128 : 0xFF;
223 const int has_ref = comps & (1 << p);
224 double sum = 0;
225 int count = 0;
226
227 /* 4x4 SSIM */
228 for (int y = 0; y < (h & ~3); y += 4) {
229 for (int x = 0; x < (w & ~3); x += 4) {
230 const float c1 = .01 * .01 * 255 * 255 * 64;
231 const float c2 = .03 * .03 * 255 * 255 * 64 * 63;
232 int s1 = 0, s2 = 0, ss = 0, s12 = 0, var, covar;
233
234 for (int yy = 0; yy < 4; yy++) {
235 for (int xx = 0; xx < 4; xx++) {
236 int a = out->data[p][(y + yy) * stride_a + x + xx];
237 int b = has_ref ? ref->data[p][(y + yy) * stride_b + x + xx] : def;
238 s1 += a;
239 s2 += b;
240 ss += a * a + b * b;
241 s12 += a * b;
242 }
243 }
244
245 var = ss * 64 - s1 * s1 - s2 * s2;
246 covar = s12 * 64 - s1 * s2;
247 sum += (2 * s1 * s2 + c1) * (2 * covar + c2) /
248 ((s1 * s1 + s2 * s2 + c1) * (var + c2));
249 count++;
250 }
251 }
252
253 ssim[p] = count ? sum / count : 0.0;
254 }
255}
256
257static float get_loss(const float ssim[4])
258{
259 const float weights[3] = { 0.8, 0.1, 0.1 }; /* tuned for Y'CbCr */
260
261 float sum = 0;
262 for (int i = 0; i < 3; i++)
263 sum += weights[i] * ssim[i];
264 sum *= ssim[3]; /* ensure alpha errors get caught */
265
266 return 1.0 - sum;
267}
268
270{
271 for (int i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++) {
272 if (!frame->buf[i])
273 break;
274 av_buffer_unref(&frame->buf[i]);
275 }
276
277 memset(frame->data, 0, sizeof(frame->data));
278 memset(frame->linesize, 0, sizeof(frame->linesize));
279}
280
281/* A negative alignment allocates a vertically flipped (negative stride) frame */
282static int get_buffer(AVFrame *frame, int align)
283{
286 if (ret < 0 || align >= 0)
287 return ret;
288
289 const int nb_planes = av_pix_fmt_count_planes(frame->format);
290 for (int p = 0; p < nb_planes; p++) {
291 const int is_chroma = p == 1 || p == 2;
292 const int h = is_chroma ? AV_CEIL_RSHIFT(frame->height, desc->log2_chroma_h)
293 : frame->height;
294 frame->data[p] += (h - 1) * frame->linesize[p];
295 frame->linesize[p] = -frame->linesize[p];
296 }
297
298 return 0;
299}
300
302{
303 int ret = sws_scale_frame(c, dst, src);
304 if (ret < 0) {
305 av_log(NULL, AV_LOG_ERROR, "Failed %s ---> %s\n",
307 }
308 return ret;
309}
310
311static int scale_new(struct runner *runner, AVFrame *dst, const AVFrame *src,
312 const struct mode *mode, const struct options *opts,
313 int64_t *out_time)
314{
320 sws_src_dst->threads = opts->threads;
321 sws_src_dst->backends = opts->backends;
322
324 if (ret < 0) {
325 av_log(NULL, AV_LOG_ERROR, "Failed to setup %s ---> %s\n",
327 return ret;
328 }
329
331 for (int i = 0; ret >= 0 && i < opts->iters; i++) {
333 if (opts->align_dst) {
334 ret = get_buffer(dst, opts->align_dst);
335 if (ret < 0)
336 return ret;
337 }
338
340 }
341 *out_time = av_gettime_relative() - time;
342
343 return ret;
344}
345
346static int scale_legacy(AVFrame *dst, const AVFrame *src,
347 const struct mode *mode, const struct options *opts,
348 int64_t *out_time)
349{
350 SwsContext *sws_legacy;
351 int ret;
352
353 sws_legacy = sws_alloc_context();
354 if (!sws_legacy)
355 return -1;
356
357 sws_legacy->src_w = src->width;
358 sws_legacy->src_h = src->height;
359 sws_legacy->src_format = src->format;
360 sws_legacy->dst_w = dst->width;
361 sws_legacy->dst_h = dst->height;
362 sws_legacy->dst_format = dst->format;
363 sws_legacy->flags = mode->flags;
364 sws_legacy->dither = mode->dither;
365 sws_legacy->scaler = mode->scaler;
366 sws_legacy->scaler_sub = mode->scaler_sub;
367 sws_legacy->threads = opts->threads;
368
370 dst->width = sws_legacy->dst_w;
371 dst->height = sws_legacy->dst_h;
372 dst->format = sws_legacy->dst_format;
373 ret = get_buffer(dst, opts->align_dst);
374 if (ret < 0)
375 goto error;
376
377 ret = sws_init_context(sws_legacy, NULL, NULL);
378 if (ret < 0)
379 goto error;
380
382 for (int i = 0; ret >= 0 && i < opts->iters; i++)
383 ret = checked_sws_scale_frame(sws_legacy, dst, src);
384 *out_time = av_gettime_relative() - time;
385
386error:
387 sws_freeContext(sws_legacy);
388 return ret;
389}
390
391static int scale_hw(AVFrame *dst, const AVFrame *src,
392 const struct mode *mode, const struct options *opts,
393 int64_t *out_time)
394{
395 SwsContext *sws_hw = NULL;
396 AVBufferRef *in_ref = NULL;
397 AVBufferRef *out_ref = NULL;
398 AVHWFramesContext *in_ctx = NULL;
399 AVHWFramesContext *out_ctx = NULL;
400 AVFrame *in_f = NULL;
401 AVFrame *out_f = NULL;
402 int ret;
403
404 sws_hw = sws_alloc_context();
405 if (!sws_hw) {
406 ret = AVERROR(ENOMEM);
407 goto error;
408 }
409
410 sws_hw->flags = mode->flags;
411 sws_hw->dither = mode->dither;
412 sws_hw->scaler = mode->scaler;
413 sws_hw->scaler_sub = mode->scaler_sub;
414 sws_hw->threads = opts->threads;
415 sws_hw->backends = opts->backends;
416
417 in_ref = av_hwframe_ctx_alloc(state.hw_device_ctx);
418 if (!in_ref) {
419 ret = AVERROR(ENOMEM);
420 goto error;
421 }
422
423 in_ctx = (AVHWFramesContext *)in_ref->data;
424 in_ctx->format = AV_PIX_FMT_VULKAN;
425 in_ctx->sw_format = src->format;
426 in_ctx->width = src->width;
427 in_ctx->height = src->height;
428 ret = av_hwframe_ctx_init(in_ref);
429 if (ret < 0) {
430 if (ret != AVERROR(ENOTSUP))
431 av_log(NULL, AV_LOG_ERROR, "Failed to create input HW context: %s\n",
432 av_err2str(ret));
433 goto error;
434 }
435
436 out_ref = av_hwframe_ctx_alloc(state.hw_device_ctx);
437 if (!out_ref) {
438 ret = AVERROR(ENOMEM);
439 goto error;
440 }
441
442 out_ctx = (AVHWFramesContext *) out_ref->data;
443 out_ctx->format = AV_PIX_FMT_VULKAN;
444 out_ctx->sw_format = dst->format;
445 out_ctx->width = dst->width;
446 out_ctx->height = dst->height;
447 ret = av_hwframe_ctx_init(out_ref);
448 if (ret < 0) {
449 if (ret != AVERROR(ENOTSUP))
450 av_log(NULL, AV_LOG_ERROR, "Failed to create output HW context: %s\n",
451 av_err2str(ret));
452 goto error;
453 }
454
455 in_f = av_frame_alloc();
456 if (!in_f) {
457 ret = AVERROR(ENOMEM);
458 goto error;
459 }
460 in_f->width = src->width;
461 in_f->height = src->height;
463 ret = av_hwframe_get_buffer(in_ref, in_f, 0);
464 if (ret < 0) {
465 av_log(NULL, AV_LOG_ERROR, "Failed to allocate input HW frame\n");
466 goto error;
467 }
468
469 ret = av_hwframe_transfer_data(in_f, src, 0);
470 if (ret < 0) {
471 av_log(NULL, AV_LOG_ERROR, "Failed to upload HW frame\n");
472 goto error;
473 }
474
475 out_f = av_frame_alloc();
476 if (!out_f) {
477 ret = AVERROR(ENOMEM);
478 goto error;
479 }
480 out_f->width = dst->width;
481 out_f->height = dst->height;
482 out_f->format = AV_PIX_FMT_VULKAN;
483 ret = av_hwframe_get_buffer(out_ref, out_f, 0);
484 if (ret < 0) {
485 av_log(NULL, AV_LOG_ERROR, "Failed to allocate output HW frame\n");
486 goto error;
487 }
488
490 for (int i = 0; ret >= 0 && i < opts->iters; i++) {
491 ret = checked_sws_scale_frame(sws_hw, out_f, in_f);
492 if (ret < 0)
493 goto error;
494 }
495 *out_time = av_gettime_relative() - time;
496
498 if (ret < 0)
499 goto error;
500
501 ret = av_hwframe_transfer_data(dst, out_f, 0);
502 if (ret < 0) {
503 av_log(NULL, AV_LOG_ERROR, "Failed to download HW frame\n");
504 goto error;
505 }
506
507 ret = 0;
508
509error:
510 av_frame_free(&in_f);
511 av_frame_free(&out_f);
512 av_buffer_unref(&in_ref);
513 av_buffer_unref(&out_ref);
514 sws_free_context(&sws_hw);
515 return ret;
516}
517
518static void print_test_params(AVBPrint *bp,
519 const AVFrame *src, const AVFrame *dst,
520 const struct mode *mode, const struct options *opts)
521{
522 av_bprintf(bp,
523 "%-*s %*dx%*d -> %-*s %*dx%*d, flags=0x%0*x dither=%u scaler=%d/%d",
524 opts->pretty ? 14 : 0, av_get_pix_fmt_name(src->format),
525 opts->pretty ? 4 : 0, src->width,
526 opts->pretty ? 4 : 0, src->height,
527 opts->pretty ? 14 : 0, av_get_pix_fmt_name(dst->format),
528 opts->pretty ? 4 : 0, dst->width,
529 opts->pretty ? 4 : 0, dst->height,
530 opts->pretty ? 8 : 0, mode->flags,
531 mode->dither,
532 mode->scaler,
534}
535
536static void print_results(const AVFrame *ref, const AVFrame *src, const AVFrame *dst,
537 int dst_w, int dst_h,
538 const struct mode *mode, const struct options *opts,
539 const struct test_results *r,
540 const struct test_results *ref_r,
541 float expected_loss)
542{
543 AVBPrint bprint, *bp = &bprint;
545
546 if (av_log_get_level() >= AV_LOG_INFO) {
548
549 if (!opts->bench || !ref_r) {
550 av_bprintf(bp, ", SSIM={Y=%f U=%f V=%f A=%f} loss=%e",
551 r->ssim[0], r->ssim[1], r->ssim[2], r->ssim[3],
552 r->loss);
553 if (ref_r)
554 av_bprintf(bp, " (ref=%e)", ref_r->loss);
555 }
556
557 if (opts->bench) {
558 av_bprintf(bp, ", time=%*"PRId64"/%u us",
559 opts->pretty ? 7 : 0, r->time, opts->iters);
560 if (ref_r) {
561 double ratio = ((double) ref_r->time / ref_r->iters)
562 / ((double) r->time / opts->iters);
563 if (FFMIN(r->time, ref_r->time) > 100 /* don't pollute stats with low precision */) {
564 ff_mutex_lock(&state.speedup_lock);
565 state.speedup_min = FFMIN(state.speedup_min, ratio);
566 state.speedup_max = FFMAX(state.speedup_max, ratio);
567 state.speedup_logavg += log(ratio);
568 state.speedup_count++;
569 ff_mutex_unlock(&state.speedup_lock);
570 }
571
572 av_bprintf(bp, " (ref=%*"PRId64"/%u us), speedup=%*.3fx %s%s\033[0m",
573 opts->pretty ? 7 : 0, ref_r->time, ref_r->iters,
574 opts->pretty ? 6 : 0, ratio,
575 speedup_color(ratio), ratio >= 1.0 ? "faster" : "slower");
576 }
577 }
578 av_bprintf(bp, "\n");
579
580 if (av_bprint_is_complete(bp)) {
581 fputs(bp->str, stdout);
582 fflush(stdout);
583 }
584 }
585
586 if (r->loss - expected_loss > 1e-4 && dst_w >= ref->width && dst_h >= ref->height) {
587 const int bad = r->loss - expected_loss > 1e-2;
588 const int level = bad ? AV_LOG_ERROR : AV_LOG_WARNING;
589 const char *worse_str = bad ? "WORSE" : "worse";
590 av_bprint_clear(bp);
591 if (bad) {
593 av_bprintf(bp, "\n");
594 }
595 av_bprintf(bp, " loss %e is %s by %e, expected loss %e\n",
596 r->loss, worse_str, r->loss - expected_loss, expected_loss);
597 if (av_bprint_is_complete(bp))
598 av_log(NULL, level, "%s", bp->str);
599 }
600
601 if (ref_r && r->loss - ref_r->loss > 1e-4) {
602 /**
603 * The new scaling code does not (yet) perform error diffusion for
604 * low bit depth output, which impacts the SSIM score slightly for
605 * very low bit-depth formats (e.g. monow, monob). Since this is an
606 * expected result, drop the badness from an error to a warning for
607 * such cases. This can be removed again once error diffusion is
608 * implemented in the new ops code.
609 */
610 const int dst_bits = av_pix_fmt_desc_get(dst->format)->comp[0].depth;
611 const int bad = r->loss - ref_r->loss > 1e-2 && dst_bits > 1;
612 const int level = bad ? AV_LOG_ERROR : AV_LOG_WARNING;
613 const char *worse_str = bad ? "WORSE" : "worse";
614 av_bprint_clear(bp);
615 if (bad) {
617 av_bprintf(bp, "\n");
618 }
619 av_bprintf(bp, " loss %e is %s by %e, ref loss %e SSIM={Y=%f U=%f V=%f A=%f}\n",
620 r->loss, worse_str, r->loss - ref_r->loss, ref_r->loss,
621 ref_r->ssim[0], ref_r->ssim[1], ref_r->ssim[2], ref_r->ssim[3]);
622 if (av_bprint_is_complete(bp))
623 av_log(NULL, level, "%s", bp->str);
624 }
625}
626
627static int init_frame(AVFrame **pframe, const AVFrame *ref,
628 int width, int height, enum AVPixelFormat format)
629{
631 if (!frame)
632 return AVERROR(ENOMEM);
634 frame->width = width;
635 frame->height = height;
636 frame->format = format;
637 *pframe = frame;
638 return 0;
639}
640
641static const char *backend_name(SwsBackend backend)
642{
643 switch (backend) {
644 case SWS_BACKEND_LEGACY: return "legacy";
645 case SWS_BACKEND_C: return "c";
646 case SWS_BACKEND_MEMCPY: return "memcpy";
647 case SWS_BACKEND_X86: return "x86";
648 case SWS_BACKEND_AARCH64: return "aarch64";
649 case SWS_BACKEND_SPIRV: return "spirv";
650 default: return "unknown";
651 }
652}
653
654static void describe_passes(AVBPrint *bp, const SwsGraph *graph)
655{
656 if (graph->noop) {
657 av_bprintf(bp, "noop");
658 return;
659 }
660
661 for (int i = 0; i < graph->num_passes; i++) {
662 const SwsPass *pass = graph->passes[i];
663 av_bprintf(bp, "%s%s", i ? ", " : "", backend_name(pass->backend));
664 if (pass->cpu_flags)
665 av_bprintf(bp, "/0x%x", pass->cpu_flags);
666 }
667}
668
669static void print_coverage_result(const AVFrame *src, const AVFrame *dst,
670 const struct mode *mode,
671 const struct options *opts,
672 const SwsGraph *graph)
673{
674 AVBPrint bp;
675
678 av_bprintf(&bp, ", ");
679 if (graph) {
680 describe_passes(&bp, graph);
681 } else {
682 av_bprintf(&bp, "unsupported");
683 }
684 av_bprintf(&bp, "\n");
685
686 av_md5_update(state.coverage_md5, (const uint8_t *) bp.str, strlen(bp.str));
687
688 if (av_log_get_level() >= AV_LOG_INFO) {
689 fputs(bp.str, stdout);
690 fflush(stdout);
691 }
692}
693
694/* Sets up the src -> dst conversion without running it, and records whether
695 * the selected backends support it and which passes they use */
696static int check_coverage(struct runner *runner, const struct test_case *t,
697 const struct mode *mode, const struct options *opts)
698{
699 const AVFrame *ref = state.ref;
701 AVFrame *src = NULL;
702 AVFrame *dst = NULL;
703 const SwsGraph *graph = NULL;
704 int ret;
705
706 ret = init_frame(&src, ref, ref->width, ref->height, t->src_fmt);
707 if (ret < 0)
708 goto error;
709 ret = init_frame(&dst, ref, t->dst_w, t->dst_h, t->dst_fmt);
710 if (ret < 0)
711 goto error;
712
717 sws_src_dst->threads = opts->threads;
718 sws_src_dst->backends = opts->backends;
719
721 if (ret < 0 && ret != AVERROR(ENOTSUP))
722 goto error;
723
724 state.coverage_total++;
725 if (ret >= 0) {
726 graph = sws_internal(sws_src_dst)->graph[0];
727 state.coverage_supported++;
728 }
729
731
732 ret = 0;
733
734error:
737 return ret;
738}
739
740static const SwsFlags coverage_flags[] = {
741 0,
745};
746
747static int run_coverage(struct runner *runner, const struct test_case *t,
748 const struct options *opts)
749{
750 if (opts->flags >= 0)
751 return check_coverage(runner, t, &t->mode, opts);
752
753 for (int i = 0; i < FF_ARRAY_ELEMS(coverage_flags); i++) {
754 struct mode flags_mode = t->mode;
755 flags_mode.flags |= coverage_flags[i];
756 int ret = check_coverage(runner, t, &flags_mode, opts);
757 if (ret < 0)
758 return ret;
759 }
760
761 return 0;
762}
763
764static void print_coverage_summary(void)
765{
766 uint8_t md5[16];
767
768 av_md5_final(state.coverage_md5, md5);
769 for (int i = 0; i < sizeof(md5); i++)
770 printf("%02x", md5[i]);
771 printf(" %d/%d\n", state.coverage_supported, state.coverage_total);
772}
773
774/* Runs a series of ref -> src -> dst -> out, and compares out vs ref */
775static int run_test(struct runner *runner, const struct test_case *t,
776 const struct options *opts)
777{
778 const AVFrame *ref = state.ref;
779 const struct test_results *ref_r = t->has_ref ? &t->ref_r : NULL;
780 AVFrame *src = runner->src;
781 AVFrame *dst = NULL, *out = NULL;
782 const int comps = fmt_comps(t->src_fmt) & fmt_comps(t->dst_fmt);
783 int ret;
784
785 /* Estimate the expected amount of loss from bit depth reduction */
786 const float c1 = 0.01 * 0.01; /* stabilization constant */
787 const float ref_var = 1.0 / 12.0; /* uniformly distributed signal */
788 const float src_var = estimate_quantization_noise(t->src_fmt);
789 const float dst_var = estimate_quantization_noise(t->dst_fmt);
790 const float out_var = estimate_quantization_noise(ref->format);
791 const float total_var = src_var + dst_var + out_var;
792 const float ssim_luma = (2 * ref_var + c1) / (2 * ref_var + total_var + c1);
793 const float ssim_expected[4] = { ssim_luma, 1, 1, 1 }; /* for simplicity */
794 const float expected_loss = get_loss(ssim_expected);
795
796 struct test_results r = { 0 };
797
798 if (!src || src->format != t->src_fmt) {
800 ret = init_frame(&src, ref, ref->width, ref->height, t->src_fmt);
801 if (ret < 0)
802 goto error;
803 if (opts->align_src) {
804 ret = get_buffer(src, opts->align_src);
805 if (ret < 0) {
807 goto error;
808 }
809 }
810
812 if (ret < 0) {
814 goto error;
815 }
816 runner->src = src;
817 }
818
819 ret = init_frame(&dst, ref, t->dst_w, t->dst_h, t->dst_fmt);
820 if (ret < 0)
821 goto error;
822
823 ret = (opts->api == IMPL_LEGACY) ? scale_legacy(dst, src, &t->mode, opts, &r.time)
824 : state.hw_device_ctx ? scale_hw(dst, src, &t->mode, opts, &r.time)
825 : scale_new(runner, dst, src, &t->mode, opts, &r.time);
826 if (ret < 0) {
827 if (ret == AVERROR(ENOTSUP))
828 ret = 0;
829 goto error;
830 }
831
832 ret = init_frame(&out, ref, ref->width, ref->height, ref->format);
833 if (ret < 0)
834 goto error;
835
837 if (ret < 0)
838 goto error;
839
840 get_ssim(r.ssim, out, ref, comps);
841
842 if (opts->api == IMPL_LEGACY) {
843 /* Legacy swscale does not perform bit accurate upconversions of low
844 * bit depth RGB. This artificially improves the SSIM score because the
845 * resulting error deletes some of the input dither noise. This gives
846 * it an unfair advantage when compared against a bit exact reference.
847 * Work around this by ensuring that the resulting SSIM score is not
848 * higher than it theoretically "should" be. */
849 if (src_var > dst_var) {
850 const float src_loss = (2 * ref_var + c1) / (2 * ref_var + src_var + c1);
851 r.ssim[0] = FFMIN(r.ssim[0], src_loss);
852 }
853 }
854
855 r.loss = get_loss(r.ssim);
856 if ((opts->api != IMPL_LEGACY) && r.loss - expected_loss > 1e-2 && t->dst_w >= ref->width && t->dst_h >= ref->height) {
857 ret = -1;
858 goto bad_loss;
859 }
860
861 if (ref_r && r.loss - ref_r->loss > 1e-2) {
862 ret = -1;
863 goto bad_loss;
864 }
865
866 ret = 0; /* fall through */
867
868bad_loss:
870 t->dst_w, t->dst_h,
871 &t->mode, opts,
872 &r, ref_r,
873 expected_loss);
874
875 error:
878 return ret;
879}
880
881static inline int fmt_is_subsampled(enum AVPixelFormat fmt)
882{
883 return av_pix_fmt_desc_get(fmt)->log2_chroma_w != 0 ||
885}
886
887static inline int fmt_is_supported_by_hw(enum AVPixelFormat fmt)
888{
889 /* Semi-planar formats are only supported by the legacy path, which
890 * does not support hardware frames. */
891 if (fmt == AV_PIX_FMT_NV24 || fmt == AV_PIX_FMT_P410 ||
892 fmt == AV_PIX_FMT_P412 || fmt == AV_PIX_FMT_P416)
893 return 0;
894 for (int i = 0;
895 state.hw_device_constr->valid_sw_formats[i] != AV_PIX_FMT_NONE; i++) {
896 if (state.hw_device_constr->valid_sw_formats[i] == fmt)
897 return 1;
898 }
899 return 0;
900}
901
902static inline int fmt_disabled(const struct options *opts, enum AVPixelFormat fmt)
903{
904 const int scaler_sub = opts->scaler_sub ? opts->scaler_sub : opts->scaler;
905 return (state.hw_device_constr && !fmt_is_supported_by_hw(fmt)) ||
906 (scaler_sub < 0 && fmt_is_subsampled(fmt));
907}
908
909static inline int test_formats(const struct options *opts,
911{
912 /* Test auxiliary conversions */
915 return 0;
916
917 /* Test main conversion */
918 enum SwsBackend backend = opts->backends ? opts->backends : SWS_BACKEND_STABLE;
919 if (opts->api == IMPL_LEGACY)
920 backend = SWS_BACKEND_LEGACY; /* Legacy API forces legacy backend */
921 return ff_sws_test_pixfmt_backend(backend, src, 0) &&
922 ff_sws_test_pixfmt_backend(backend, dst, 1);
923}
924
925static int push_test(const struct test_case *t, const struct options *opts)
926{
927 if (state.queue)
928 return av_thread_message_queue_send(state.queue, (void *) t, 0);
929 if (opts->coverage)
930 return run_coverage(&state.runners[0], t, opts);
931 return run_test(&state.runners[0], t, opts);
932}
933
934static int run_self_tests(const struct options *opts)
935{
936 const int dst_w_values[] = { opts->w, opts->w - opts->w / 3, opts->w + opts->w / 3 };
937 const int dst_h_values[] = { opts->h, opts->h - opts->h / 3, opts->h + opts->h / 3 };
938
939 enum AVPixelFormat src_fmt, dst_fmt,
940 src_fmt_min = 0,
941 dst_fmt_min = 0,
942 src_fmt_max = AV_PIX_FMT_NB - 1,
943 dst_fmt_max = AV_PIX_FMT_NB - 1;
944
945 int ret = 0;
946
947 if (opts->src_fmt != AV_PIX_FMT_NONE)
948 src_fmt_min = src_fmt_max = opts->src_fmt;
949 if (opts->dst_fmt != AV_PIX_FMT_NONE)
950 dst_fmt_min = dst_fmt_max = opts->dst_fmt;
951
952 for (src_fmt = src_fmt_min; src_fmt <= src_fmt_max; src_fmt++) {
953 if (fmt_disabled(opts, src_fmt))
954 continue;
955 for (dst_fmt = dst_fmt_min; dst_fmt <= dst_fmt_max; dst_fmt++) {
956 if (fmt_disabled(opts, dst_fmt))
957 continue;
958 if (!test_formats(opts, src_fmt, dst_fmt))
959 continue;
960 for (int h = 0; h < FF_ARRAY_ELEMS(dst_h_values); h++) {
961 for (int w = 0; w < FF_ARRAY_ELEMS(dst_w_values); w++) {
962 for (int f = 0; f < FF_ARRAY_ELEMS(flags); f++) {
963 struct mode mode = {
964 .flags = opts->flags >= 0 ? opts->flags : flags[f],
965 .dither = opts->dither >= 0 ? opts->dither : SWS_DITHER_AUTO,
966 .scaler = opts->scaler >= 0 ? opts->scaler : SWS_SCALE_AUTO,
967 .scaler_sub = opts->scaler_sub >= 0 ? opts->scaler_sub : SWS_SCALE_AUTO,
968 };
969 int dst_w = (opts->dst_w >= 0) ? opts->dst_w : dst_w_values[w];
970 int dst_h = (opts->dst_h >= 0) ? opts->dst_h : dst_h_values[h];
971
972 if (opts->scaler > SWS_SCALE_AUTO && opts->w == dst_w && opts->h == dst_h)
973 continue;
974
975 if (ff_sfc64_get(&state.prng_state) <= UINT64_MAX * opts->prob) {
976 const struct test_case test = {
977 .src_fmt = src_fmt,
978 .dst_fmt = dst_fmt,
979 .dst_w = dst_w,
980 .dst_h = dst_h,
981 .mode = mode,
982 };
983
984 ret = push_test(&test, opts);
985 if (ret < 0)
986 goto error;
987 }
988
989 if (opts->flags >= 0 || opts->scaler != SWS_SCALE_AUTO)
990 break;
991 }
992 if (opts->dst_w >= 0 || opts->dst_h >= 0)
993 break;
994 if (opts->scaler < 0)
995 break;
996 }
997 if (opts->dst_w >= 0 || opts->dst_h >= 0)
998 break;
999 if (opts->scaler < 0)
1000 break;
1001 }
1002 }
1003 }
1004
1005 ret = 0;
1006
1007error:
1008 return ret;
1009}
1010
1011static int run_file_tests(const struct options *opts)
1012{
1013 const AVFrame *ref = state.ref;
1014 FILE *fp = state.fp;
1015 char buf[256];
1016 int ret = 0;
1017
1018 for (int line = 1; fgets(buf, sizeof(buf), fp); line++) {
1019 char src_fmt_str[21], dst_fmt_str[21];
1022 int sw, sh, dw, dh;
1023 struct test_results r = { 0 };
1024 struct mode mode;
1025 int n = 0;
1026
1027 ret = sscanf(buf,
1028 "%20s %dx%d -> %20s %dx%d, flags=0x%x dither=%u scaler=%u/%u, "
1029 "SSIM={Y=%f U=%f V=%f A=%f} loss=%e%n",
1030 src_fmt_str, &sw, &sh, dst_fmt_str, &dw, &dh,
1031 &mode.flags, &mode.dither,
1033 &r.ssim[0], &r.ssim[1], &r.ssim[2], &r.ssim[3],
1034 &r.loss, &n);
1035 if (ret != 15) {
1037 "Malformed reference file in line %d\n", line);
1038 goto error;
1039 }
1040 if (opts->bench) {
1041 ret = sscanf(buf + n,
1042 ", time=%"PRId64"/%u us",
1043 &r.time, &r.iters);
1044 if (ret != 2) {
1046 "Missing benchmarks from reference file in line %d\n",
1047 line);
1048 goto error;
1049 }
1050 }
1051
1052 src_fmt = av_get_pix_fmt(src_fmt_str);
1053 dst_fmt = av_get_pix_fmt(dst_fmt_str);
1054 if (src_fmt == AV_PIX_FMT_NONE || dst_fmt == AV_PIX_FMT_NONE) {
1056 "Unknown pixel formats (%s and/or %s) in line %d\n",
1057 src_fmt_str, dst_fmt_str, line);
1058 goto error;
1059 }
1060
1061 if (sw != ref->width || sh != ref->height) {
1063 "Mismatching dimensions %dx%d (ref is %dx%d) in line %d\n",
1064 sw, sh, ref->width, ref->height, line);
1065 goto error;
1066 }
1067
1068 if (opts->src_fmt != AV_PIX_FMT_NONE && src_fmt != opts->src_fmt ||
1069 opts->dst_fmt != AV_PIX_FMT_NONE && dst_fmt != opts->dst_fmt)
1070 continue;
1071
1072 const struct test_case test = {
1073 .src_fmt = src_fmt,
1074 .dst_fmt = dst_fmt,
1075 .dst_w = dw,
1076 .dst_h = dh,
1077 .mode = mode,
1078 .has_ref = 1,
1079 .ref_r = r,
1080 };
1081
1082 ret = push_test(&test, opts);
1083 if (ret < 0)
1084 goto error;
1085 }
1086
1087 ret = 0;
1088
1089error:
1090 return ret;
1091}
1092
1106
1114
1115static int run_tests(const struct options *opts)
1116{
1118}
1119
1120static int run_producer(void *priv)
1121{
1122 const struct options *opts = priv;
1123 int ret = run_tests(opts);
1124 /* Let the runners finish all remaining tests */
1126 return ret;
1127}
1128
1129static int run_runner(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads)
1130{
1131 const struct options *opts = priv;
1132 struct runner *runner = &state.runners[jobnr];
1133 struct test_case test;
1134
1135 while (!av_thread_message_queue_recv(state.queue, &test, 0)) {
1136 int ret = run_test(runner, &test, opts);
1137 if (ret < 0) {
1138 /* Stop the producer and all other runners */
1142 return ret;
1143 }
1144 }
1145
1146 return 0;
1147}
1148
1149static int init_ref(AVFrame *ref, const struct options *opts)
1150{
1153 AVLFG rand;
1154 int ret = -1;
1155
1156 if (!ctx || !rgb)
1157 goto error;
1158
1159 rgb->width = opts->w > 32 ? opts->w / 12 : opts->w;
1160 rgb->height = opts->h > 32 ? opts->h / 12 : opts->h;
1161 rgb->format = AV_PIX_FMT_RGBA;
1163 if (ret < 0)
1164 goto error;
1165
1166 av_lfg_init(&rand, 1);
1167 for (int y = 0; y < rgb->height; y++) {
1168 for (int x = 0; x < rgb->width; x++) {
1169 for (int c = 0; c < 4; c++)
1170 rgb->data[0][y * rgb->linesize[0] + x * 4 + c] = av_lfg_get(&rand);
1171 }
1172 }
1173
1176
1177error:
1180 return ret;
1181}
1182
1183static int parse_size(struct options *opts, const char *str, char **pbuf)
1184{
1185 int ret = av_parse_video_size(&opts->w, &opts->h, str);
1186 if (ret < 0 && strchr(str, ':')) {
1187 av_freep(pbuf);
1188 char *buf = av_strdup(str);
1189 if (!buf)
1190 return AVERROR(ENOMEM);
1191 *pbuf = buf;
1192 char *saveptr = NULL;
1193 char *s = av_strtok(buf, ":", &saveptr);
1194 if (s) {
1195 ret = av_parse_video_size(&opts->w, &opts->h, s);
1196 if (ret >= 0) {
1197 s = av_strtok(NULL, ":", &saveptr);
1198 if (s) {
1199 ret = av_parse_video_size(&opts->dst_w, &opts->dst_h, s);
1200 }
1201 }
1202 }
1203 }
1204 return ret;
1205}
1206
1207/* Parses [threads][:runners] */
1208static int parse_threads(struct options *opts, const char *str)
1209{
1210 const char *sep = strchr(str, ':');
1211 const char *str_threads = sep == str ? NULL : str;
1212 const char *str_runners = sep ? sep + 1 : NULL;
1213 int threads = str_threads ? atoi(str_threads) : 1;
1214 int runners = str_runners ? atoi(str_runners) : 1;
1215 if (threads < 0 || runners < 0)
1216 return AVERROR(EINVAL);
1217
1218 if (!runners) {
1220 runners = FFMAX(runners, 1);
1221 }
1222
1223 opts->threads = threads;
1224 opts->runners = runners;
1225 return 0;
1226}
1227
1228static int parse_implementation(const char *str)
1229{
1230 if (!strcmp(str, "legacy"))
1231 return IMPL_LEGACY;
1232 if (!strcmp(str, "new"))
1233 return IMPL_NEW;
1234 return -1;
1235}
1236
1237static int parse_options(int argc, char **argv, struct options *opts, FILE **fp)
1238{
1240 char *buf = NULL;
1241 int ret;
1242
1243 for (int i = 1; i < argc; i += 2) {
1244 if (!strcmp(argv[i], "-help") || !strcmp(argv[i], "--help")) {
1245 fprintf(stderr,
1246 "swscale [options...]\n"
1247 " -help\n"
1248 " This text\n"
1249 " -ref <file>\n"
1250 " Uses file as reference to compare tests against. Tests that have become worse will contain the string worse or WORSE\n"
1251 " -p <number between 0.0 and 1.0>\n"
1252 " The proportion of tests or comparisons to perform.\n"
1253 " It is often convenient to perform a random subset\n"
1254 " -dst <pixfmt>\n"
1255 " Only test the specified destination pixel format\n"
1256 " -src <pixfmt>\n"
1257 " Only test the specified source pixel format\n"
1258 " -s <size>[:<size>]\n"
1259 " Set frame size (WxH or abbreviation)\n"
1260 " Optionally set destination frame size (after a ':' separator character).\n"
1261 " -bench <iters>\n"
1262 " Run benchmarks with the specified number of iterations. This mode also sets the frame size to 1920x1080 (unless -s is specified)\n"
1263 " -flags <flags>\n"
1264 " Test with a specific combination of flags\n"
1265 " -dither <mode>\n"
1266 " Test with a specific dither mode\n"
1267 " -backends <backends>\n"
1268 " Restrict to the given set of allowed swscale backends\n"
1269 " -scaler <algorithm>\n"
1270 " Test with a specified scaler algorithm\n"
1271 " If 'none', test only conversions that do not involve scaling\n"
1272 " -scaler_sub <algorithm>\n"
1273 " Test with a specified scaler algorithm for chroma planes\n"
1274 " -align_src <alignment>\n"
1275 " If nonzero, allocate source buffers with a custom stride alignment\n"
1276 " If negative, the buffers are also vertically flipped (negative stride)\n"
1277 " -align_dst <alignment>\n"
1278 " If nonzero, allocate destination buffers with a custom stride alignment\n"
1279 " If negative, the buffers are also vertically flipped (negative stride)\n"
1280 " -api <new or legacy>\n"
1281 " Use selected swscale API for the main conversion (default: new)\n"
1282 " -hw <device>\n"
1283 " Use Vulkan hardware acceleration on the specified device for the main conversion\n"
1284 " If 'default', use the default device, and skip all tests if none is available\n"
1285 " -threads [<threads>][:<runners>]\n"
1286 " Use the specified number of threads per conversion (default: 1)\n"
1287 " Optionally run multiple tests concurrently on <runners> threads (default: 1)\n"
1288 " A value of 0 picks the number of threads automatically\n"
1289 " Benchmark results may be skewed when using multiple runners\n"
1290 " -cpuflags <cpuflags>\n"
1291 " Uses the specified cpuflags in the tests\n"
1292 " -pretty <1 or 0>\n"
1293 " Align fields while printing results\n"
1294 " -coverage <1 or 0>\n"
1295 " Set up each conversion without running it, and print the backend and\n"
1296 " CPU flags of each of its passes. Also print a summary with how many\n"
1297 " conversions are supported and an MD5 of the per-conversion lines.\n"
1298 " -v <level>\n"
1299 " Enable log verbosity at given level\n"
1300 );
1301 exit(0);
1302 }
1303 if (argv[i][0] != '-' || i + 1 == argc)
1304 goto bad_option;
1305 if (!strcmp(argv[i], "-ref")) {
1306 *fp = fopen(argv[i + 1], "r");
1307 if (!*fp) {
1308 fprintf(stderr, "could not open '%s'\n", argv[i + 1]);
1309 ret = AVERROR(errno);
1310 goto end;
1311 }
1312 } else if (!strcmp(argv[i], "-cpuflags")) {
1313 unsigned flags = av_get_cpu_flags();
1314 ret = av_parse_cpu_caps(&flags, argv[i + 1]);
1315 if (ret < 0) {
1316 fprintf(stderr, "invalid cpu flags %s\n", argv[i + 1]);
1317 goto end;
1318 }
1320 } else if (!strcmp(argv[i], "-src")) {
1321 opts->src_fmt = av_get_pix_fmt(argv[i + 1]);
1322 if (opts->src_fmt == AV_PIX_FMT_NONE) {
1323 fprintf(stderr, "invalid pixel format %s\n", argv[i + 1]);
1324 ret = AVERROR(EINVAL);
1325 goto end;
1326 }
1327 } else if (!strcmp(argv[i], "-dst")) {
1328 opts->dst_fmt = av_get_pix_fmt(argv[i + 1]);
1329 if (opts->dst_fmt == AV_PIX_FMT_NONE) {
1330 fprintf(stderr, "invalid pixel format %s\n", argv[i + 1]);
1331 ret = AVERROR(EINVAL);
1332 goto end;
1333 }
1334 } else if (!strcmp(argv[i], "-s")) {
1335 ret = parse_size(opts, argv[i + 1], &buf);
1336 if (ret < 0) {
1337 fprintf(stderr, "invalid frame size %s\n", argv[i + 1]);
1338 goto end;
1339 }
1340 } else if (!strcmp(argv[i], "-bench")) {
1341 int iters = atoi(argv[i + 1]);
1342 if (iters <= 0) {
1343 opts->bench = 0;
1344 opts->iters = 1;
1345 } else {
1346 opts->bench = 1;
1347 opts->iters = iters;
1348 }
1349 } else if (!strcmp(argv[i], "-flags")) {
1350 const AVOption *flags_opt = av_opt_find(dummy, "sws_flags", NULL, 0, 0);
1351 ret = av_opt_eval_flags(dummy, flags_opt, argv[i + 1], &opts->flags);
1352 if (ret < 0) {
1353 fprintf(stderr, "invalid flags %s\n", argv[i + 1]);
1354 goto end;
1355 }
1356 } else if (!strcmp(argv[i], "-backends")) {
1357 const AVOption *backends_opt = av_opt_find(dummy, "sws_backends", NULL, 0, 0);
1358 ret = av_opt_eval_flags(dummy, backends_opt, argv[i + 1], &opts->backends);
1359 if (ret < 0) {
1360 fprintf(stderr, "invalid backends %s\n", argv[i + 1]);
1361 goto end;
1362 }
1363 } else if (!strcmp(argv[i], "-dither")) {
1364 opts->dither = atoi(argv[i + 1]);
1365 } else if (!strcmp(argv[i], "-scaler") || !strcmp(argv[i], "-scaler_sub")) {
1366 int opt_is_scaler = !strcmp(argv[i], "-scaler");
1367 if (opt_is_scaler && !strcmp(argv[i + 1], "none")) {
1368 opts->scaler = -1;
1369 continue;
1370 }
1371 const AVOption *scaler_opt = av_opt_find(dummy, "scaler", NULL, 0, 0);
1372 ret = av_opt_eval_int(dummy, scaler_opt, argv[i + 1], opt_is_scaler ? &opts->scaler : &opts->scaler_sub);
1373 if (ret < 0) {
1374 fprintf(stderr, "invalid scaler algorithm %s\n", argv[i + 1]);
1375 goto end;
1376 }
1377 } else if (!strcmp(argv[i], "-align_src")) {
1378 opts->align_src = atoi(argv[i + 1]);
1379 const unsigned align = FFABSU(opts->align_src);
1380 if (align > INT_MAX || (align & (align - 1))) {
1381 fprintf(stderr, "invalid alignment %s\n", argv[i + 1]);
1382 return -1;
1383 }
1384 } else if (!strcmp(argv[i], "-align_dst")) {
1385 opts->align_dst = atoi(argv[i + 1]);
1386 const unsigned align = FFABSU(opts->align_dst);
1387 if (align > INT_MAX || (align & (align - 1))) {
1388 fprintf(stderr, "invalid alignment %s\n", argv[i + 1]);
1389 return -1;
1390 }
1391 } else if (!strcmp(argv[i], "-api")) {
1392 ret = parse_implementation(argv[i + 1]);
1393 if (ret < 0) {
1394 fprintf(stderr, "invalid api %s\n", argv[i + 1]);
1395 goto end;
1396 }
1397 opts->api = ret;
1398 } else if (!strcmp(argv[i], "-hw")) {
1399 const int hw_default = !strcmp(argv[i + 1], "default");
1400 ret = av_hwdevice_ctx_create(&state.hw_device_ctx,
1402 hw_default ? NULL : argv[i + 1], NULL, 0);
1403 if (ret < 0) {
1404 if (hw_default) {
1405 fprintf(stderr, "No Vulkan device available, skipping.\n");
1406 ret = AVERROR(ENOTSUP);
1407 } else {
1408 fprintf(stderr, "Failed to create Vulkan device '%s'\n",
1409 argv[i + 1]);
1410 }
1411 goto end;
1412 }
1413 state.hw_device_constr =
1415 if (!state.hw_device_constr) {
1416 fprintf(stderr, "Failed to retrieve Vulkan device constraints '%s'\n",
1417 argv[i + 1]);
1418 ret = AVERROR(ENOMEM);
1419 goto end;
1420 }
1421 } else if (!strcmp(argv[i], "-threads")) {
1422 ret = parse_threads(opts, argv[i + 1]);
1423 if (ret < 0) {
1424 fprintf(stderr, "invalid thread count %s\n", argv[i + 1]);
1425 goto end;
1426 }
1427 } else if (!strcmp(argv[i], "-p")) {
1428 opts->prob = atof(argv[i + 1]);
1429 } else if (!strcmp(argv[i], "-pretty")) {
1430 opts->pretty = atoi(argv[i + 1]);
1431 } else if (!strcmp(argv[i], "-coverage")) {
1432 opts->coverage = atoi(argv[i + 1]);
1433 } else if (!strcmp(argv[i], "-v")) {
1434 av_log_set_level(atoi(argv[i + 1]));
1435 } else {
1436bad_option:
1437 fprintf(stderr, "bad option or argument missing (%s) see -help\n", argv[i]);
1438 ret = AVERROR(EINVAL);
1439 goto end;
1440 }
1441 }
1442
1443 if (opts->coverage &&
1444 (state.hw_device_ctx || opts->api == IMPL_LEGACY || opts->runners > 1)) {
1445 fprintf(stderr, "-coverage is not supported with -hw, -api legacy or multiple runners\n");
1446 ret = AVERROR(EINVAL);
1447 goto end;
1448 }
1449
1450 if (opts->w < 0 || opts->h < 0) {
1451 opts->w = opts->bench ? 1920 : 96;
1452 opts->h = opts->bench ? 1080 : 96;
1453 }
1454
1455 ret = 0;
1456
1457end:
1459 av_freep(&buf);
1460 return ret;
1461}
1462
1463int main(int argc, char **argv)
1464{
1465 struct options opts = {
1466 .src_fmt = AV_PIX_FMT_NONE,
1467 .dst_fmt = AV_PIX_FMT_NONE,
1468 .w = -1,
1469 .h = -1,
1470 .dst_w = -1,
1471 .dst_h = -1,
1472 .threads = 1,
1473 .runners = 1,
1474 .iters = 1,
1475 .prob = 1.0,
1476 .flags = -1,
1477 .dither = -1,
1478 .scaler = SWS_SCALE_AUTO,
1479 .scaler_sub = SWS_SCALE_AUTO,
1480 };
1481
1482 AVSliceThread *slicethread = NULL;
1483
1484 int ret = parse_options(argc, argv, &opts, &state.fp);
1485 if (ret == AVERROR(ENOTSUP)) {
1486 ret = 0;
1487 goto error;
1488 }
1489 if (ret < 0)
1490 goto error;
1491
1492 ff_sfc64_init(&state.prng_state, 0, 0, 0, 12);
1493 signal(SIGINT, exit_handler);
1494
1495 state.runners = av_calloc(opts.runners, sizeof(*state.runners));
1496 if (!state.runners) {
1497 ret = AVERROR(ENOMEM);
1498 goto error;
1499 }
1500
1501 for (int i = 0; i < opts.runners; i++) {
1502 ret = runner_init(&state.runners[i]);
1503 if (ret < 0)
1504 goto error;
1505 }
1506
1507 state.ref = av_frame_alloc();
1508 if (!state.ref) {
1509 ret = AVERROR(ENOMEM);
1510 goto error;
1511 }
1512 state.ref->width = opts.w;
1513 state.ref->height = opts.h;
1514 state.ref->format = AV_PIX_FMT_YUVA444P;
1515
1516 if (opts.coverage) {
1517 state.coverage_md5 = av_md5_alloc();
1518 if (!state.coverage_md5) {
1519 ret = AVERROR(ENOMEM);
1520 goto error;
1521 }
1522 av_md5_init(state.coverage_md5);
1523 } else {
1524 ret = init_ref(state.ref, &opts);
1525 if (ret < 0)
1526 goto error;
1527 }
1528
1529 if (opts.runners > 1) {
1530 ret = av_thread_message_queue_alloc(&state.queue, opts.runners,
1531 sizeof(struct test_case));
1532 if (ret < 0)
1533 goto error;
1534
1536 run_producer, opts.runners);
1537 if (ret < 0) {
1538 fprintf(stderr, "Failed to create %d runner threads: %s\n",
1539 opts.runners, av_err2str(ret));
1540 goto error;
1541 }
1542 ret = avpriv_slicethread_execute2(slicethread, opts.runners, 1);
1543 } else {
1544 ret = run_tests(&opts);
1545 }
1546
1547 if (opts.coverage && ret >= 0)
1549
1550 /* fall through */
1551error:
1552 avpriv_slicethread_free(&slicethread);
1554 for (int i = 0; state.runners && i < opts.runners; i++)
1555 runner_free(&state.runners[i]);
1556 av_freep(&state.runners);
1557 av_buffer_unref(&state.hw_device_ctx);
1558 av_hwframe_constraints_free(&state.hw_device_constr);
1559 av_frame_free(&state.ref);
1560 av_freep(&state.coverage_md5);
1561 if (state.fp)
1562 fclose(state.fp);
1564}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
static const char *const format[]
Definition af_aiir.c:445
static FILE * out
static struct AVMD5 * md5
static AVFormatContext * ctx
static AVDictionary * opts
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
static const uint8_t *BS_FUNC align(BSCTX *bc)
Skip bits to a byte boundary.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition bprint.c:121
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition bprint.c:68
AVBPrint public header.
#define AV_BPRINT_SIZE_AUTOMATIC
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define f(width, name)
Definition cbs_vp8.c:236
#define ss(width, name, subs,...)
Definition cbs_vp9.c:202
#define s(width, name)
Definition cbs_vp9.c:198
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#define FFABSU(a)
Unsigned Absolute value.
Definition common.h:91
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition common.h:74
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
__device__ int printf(const char *,...)
static AVFrame * frame
int main
Definition dovi_rpuenc.c:38
int8_t exp
Definition eval.c:76
int ret
Definition ffplay.c:391
static int dummy
Definition ffplay.c:4428
reference-counted frame API
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition bprint.h:218
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Definition bprint.c:226
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition buffer.c:140
#define AVERROR_EOF
End of file.
Definition error.h:57
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition frame.c:499
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition frame.c:209
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:65
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition frame.c:602
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:53
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition log.h:204
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
void av_log_set_level(int level)
Set the log level.
Definition log.c:482
int av_log_get_level(void)
Get the current log level.
Definition log.c:477
void av_md5_init(AVMD5 *ctx)
Initialize MD5 hashing.
Definition md5.c:143
void av_md5_final(AVMD5 *ctx, uint8_t *dst)
Finish hashing and output digest value.
Definition md5.c:188
struct AVMD5 * av_md5_alloc(void)
Allocate an AVMD5 context.
Definition md5.c:50
void av_md5_update(AVMD5 *ctx, const uint8_t *src, size_t len)
Update hash value.
Definition md5.c:153
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
Definition avstring.c:179
av_warn_unused_result int sws_init_context(SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter)
Initialize the swscaler context sws_context.
Definition utils.c:1971
int sws_scale_frame(SwsContext *sws, AVFrame *dst, const AVFrame *src)
Scale source data from src and write the output to dst.
Definition swscale.c:1438
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext and set its fields to default values.
Definition utils.c:1081
void sws_free_context(SwsContext **ctx)
Free the context and everything associated with it, and write NULL to the provided pointer.
Definition utils.c:2408
SwsDither
Definition swscale.h:77
SwsBackend
Definition swscale.h:110
int sws_frame_setup(SwsContext *ctx, const AVFrame *dst, const AVFrame *src)
Like sws_scale_frame, but without actually scaling.
Definition swscale.c:1544
SwsScaler
Definition swscale.h:96
void sws_freeContext(SwsContext *swsContext)
Free the swscaler context swsContext.
Definition utils.c:2337
SwsFlags
Definition swscale.h:131
@ SWS_DITHER_AUTO
Definition swscale.h:79
@ SWS_BACKEND_LEGACY
Legacy bespoke format-specific code.
Definition swscale.h:112
@ SWS_BACKEND_MEMCPY
Fast path using libc memcpy() / memset()
Definition swscale.h:117
@ SWS_BACKEND_AARCH64
Chained AArch64 NEON kernels.
Definition swscale.h:119
@ SWS_BACKEND_X86
Chained x86 SIMD kernels.
Definition swscale.h:118
@ SWS_BACKEND_C
Template-based C reference implementation.
Definition swscale.h:116
@ SWS_BACKEND_STABLE
Definition swscale.h:113
@ SWS_BACKEND_ALL
Definition swscale.h:127
@ SWS_BACKEND_SPIRV
Vulkan SPIR-V backend.
Definition swscale.h:120
@ SWS_SCALE_AUTO
Definition swscale.h:97
@ SWS_BICUBIC
2-tap cubic B-spline
Definition swscale.h:199
@ SWS_BITEXACT
Definition swscale.h:178
@ SWS_AREA
area averaging
Definition swscale.h:202
@ SWS_BILINEAR
bilinear filtering
Definition swscale.h:198
@ SWS_FULL_CHR_H_INP
Perform full chroma interpolation when downscaling RGB sources.
Definition swscale.h:167
@ SWS_FAST_BILINEAR
Scaler selection options.
Definition swscale.h:197
@ SWS_ACCURATE_RND
Force bit-exact output.
Definition swscale.h:177
@ SWS_X
experimental
Definition swscale.h:200
@ SWS_POINT
nearest neighbor
Definition swscale.h:201
@ SWS_FULL_CHR_H_INT
Perform full chroma upsampling when upscaling to RGB.
Definition swscale.h:154
int av_opt_eval_int(void *obj, const AVOption *o, const char *val, int *int_out)
int av_opt_eval_flags(void *obj, const AVOption *o, const char *val, int *flags_out)
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
Definition opt.c:2084
int a
static const int weights[]
Definition hevc_pel.c:32
static AVBufferRef * hw_device_ctx
Definition hw_decode.c:45
int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type, const char *device, AVDictionary *opts, int flags)
Open a device of the specified type and create an AVHWDeviceContext for it.
Definition hwcontext.c:673
void av_hwframe_constraints_free(AVHWFramesConstraints **constraints)
Free an AVHWFrameConstraints structure.
Definition hwcontext.c:664
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition hwcontext.c:347
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition hwcontext.c:267
int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
Copy data to or from a hw surface.
Definition hwcontext.c:498
AVHWFramesConstraints * av_hwdevice_get_hwframe_constraints(AVBufferRef *ref, const void *hwconfig)
Get the constraints on HW frames given a device and the HW-specific configuration to be used with tha...
Definition hwcontext.c:639
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition hwcontext.c:564
@ AV_HWDEVICE_TYPE_VULKAN
Definition hwcontext.h:39
#define r
Definition input.c:42
#define b
Definition input.c:43
static int bad(InterplayACMContext *s, unsigned ind, unsigned col)
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
Definition lfg.c:32
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition lfg.h:53
void av_force_cpu_flags(int arg)
Disables cpu detection and forces the specified flags.
Definition cpu.c:81
int av_parse_cpu_caps(unsigned *flags, const char *s)
Parse CPU caps from a string and update the given AV_CPU_* flags based on that.
Definition cpu.c:119
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition cpu.c:109
int av_cpu_count(void)
Definition cpu.c:230
#define AV_MUTEX_INITIALIZER
Definition thread.h:185
static int ff_mutex_unlock(AVMutex *mutex)
Definition thread.h:189
static int ff_mutex_lock(AVMutex *mutex)
Definition thread.h:188
#define AVMutex
Definition thread.h:184
const char * desc
Definition libsvtav1.c:83
int ff_sws_test_pixfmt_backend(const SwsBackend backends, enum AVPixelFormat format, int output)
Definition format.c:626
uint8_t w
Definition llvidencdsp.c:39
Utility Preprocessor macros.
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
Public header for MD5 hash function implementation.
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:370
static const uint64_t c2
Definition murmur3.c:53
static const uint64_t c1
Definition murmur3.c:52
#define av_strdup(s)
Definition ops_static.c:55
AVOptions.
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
Definition parseutils.c:150
misc parsing utilities
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3524
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition pixdesc.c:3404
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition pixdesc.c:3416
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3484
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition pixdesc.h:147
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition pixdesc.h:136
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
Definition pixdesc.h:158
pixel format definitions
#define AV_PIX_FMT_P412
Definition pixfmt.h:630
#define AV_PIX_FMT_P410
Definition pixfmt.h:628
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition pixfmt.h:379
@ AV_PIX_FMT_NB
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
Definition pixfmt.h:511
@ AV_PIX_FMT_NV24
planar YUV 4:4:4, 24bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition pixfmt.h:371
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition pixfmt.h:100
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition pixfmt.h:174
#define AV_PIX_FMT_P416
Definition pixfmt.h:632
simple Pseudo Random Number Generator
static uint64_t ff_sfc64_get(FFSFC64 *s)
Definition sfc64.h:41
static void ff_sfc64_init(FFSFC64 *s, uint64_t seeda, uint64_t seedb, uint64_t seedc, int rounds)
Initialize sfc64 with up to 3 seeds.
Definition sfc64.h:75
static volatile sig_atomic_t sig
Definition signal.c:48
#define FF_ARRAY_ELEMS(a)
void avpriv_slicethread_free(AVSliceThread **pctx)
Destroy slice threading context.
int avpriv_slicethread_execute2(AVSliceThread *ctx, int nb_jobs, int execute_main)
Execute slice threading.
int avpriv_slicethread_create2(AVSliceThread **pctx, void *priv, int(*worker_func)(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads), int(*main_func)(void *priv), int nb_threads)
Create slice threading context.
struct AVSliceThread AVSliceThread
Definition slicethread.h:25
A reference to a data buffer.
Definition buffer.h:82
uint8_t * data
The data buffer.
Definition buffer.h:90
int depth
Number of bits in the component.
Definition pixdesc.h:57
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
int width
Definition frame.h:551
int height
Definition frame.h:551
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition frame.h:566
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
Definition hwcontext.h:459
This struct describes a set or pool of "hardware" frames (i.e.
Definition hwcontext.h:118
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition hwcontext.h:200
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition hwcontext.h:213
int width
The allocated dimensions of the frames in this pool.
Definition hwcontext.h:220
Context structure for the Lagged Fibonacci PRNG.
Definition lfg.h:33
Definition md5.c:42
AVOption.
Definition opt.h:428
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition pixdesc.h:105
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition pixdesc.h:80
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition pixdesc.h:89
Main external API structure.
Definition swscale.h:227
int src_h
Width and height of the source frame.
Definition swscale.h:272
int dst_format
Destination pixel format.
Definition swscale.h:275
int threads
How many threads to use for processing, or 0 for automatic selection.
Definition swscale.h:249
SwsScaler scaler
Scaling filter.
Definition swscale.h:294
int dst_h
Width and height of the destination frame.
Definition swscale.h:273
int dst_w
Definition swscale.h:273
SwsBackend backends
Bitmask of SWS_BACKEND_*.
Definition swscale.h:312
SwsScaler scaler_sub
Scaler used specifically for up/downsampling subsampled (chroma) planes.
Definition swscale.h:302
int src_w
Deprecated frame property overrides, for the legacy API only.
Definition swscale.h:272
int src_format
Source pixel format.
Definition swscale.h:274
SwsDither dither
Dither mode.
Definition swscale.h:254
unsigned flags
Bitmask of SWS_*.
Definition swscale.h:238
Filter graph, which represents a 'baked' pixel format conversion.
Definition graph.h:133
bool noop
Definition graph.h:138
SwsPass ** passes
Sorted sequence of filter passes to apply.
Definition graph.h:154
int num_passes
Definition graph.h:155
SwsGraph * graph[2]
Represents a single filter pass in the scaling graph.
Definition graph.h:85
int cpu_flags
Definition graph.h:95
SwsBackend backend
Definition graph.h:94
Definition swscale.c:85
SwsScaler scaler
Definition swscale.c:88
SwsDither dither
Definition swscale.c:87
SwsFlags flags
Definition swscale.c:86
SwsScaler scaler_sub
Definition swscale.c:89
int runners
Definition swscale.c:70
int align_src
Definition swscale.c:77
int align_dst
Definition swscale.c:78
enum AVPixelFormat dst_fmt
Definition swscale.c:64
int bench
Definition swscale.c:72
enum AVPixelFormat src_fmt
Definition swscale.c:63
int backends
Definition swscale.c:81
int w
Definition swscale.c:66
int iters
Definition swscale.c:71
int h
Definition swscale.c:66
double prob
Definition swscale.c:65
int pretty
Definition swscale.c:80
int dither
Definition swscale.c:74
int scaler_sub
Definition swscale.c:76
int scaler
Definition swscale.c:75
int dst_h
Definition swscale.c:68
int threads
Definition swscale.c:69
int dst_w
Definition swscale.c:67
int api
Definition swscale.c:79
int coverage
Definition swscale.c:82
int flags
Definition swscale.c:73
Definition rpzaenc.c:60
AVFrame * src
Definition swscale.c:104
SwsContext * sws_src_dst
Definition swscale.c:102
SwsContext * sws_dst_out
Definition swscale.c:103
SwsContext * sws_ref_src
Definition swscale.c:101
int dst_h
Definition swscale.c:110
enum AVPixelFormat src_fmt
Definition swscale.c:108
struct mode mode
Definition swscale.c:111
int dst_w
Definition swscale.c:110
struct test_results ref_r
Definition swscale.c:113
int has_ref
Definition swscale.c:112
enum AVPixelFormat dst_fmt
Definition swscale.c:109
float loss
Definition swscale.c:94
float ssim[4]
Definition swscale.c:93
int64_t time
Definition swscale.c:95
Definition idctdsp.c:35
uint8_t level
Definition svq3.c:208
external API header
static SwsInternal * sws_internal(const SwsContext *sws)
#define av_freep(p)
#define av_log(a,...)
static void error(const char *err)
#define src
Definition vp8dsp.c:248
static int ref[MAX_W *MAX_W]
#define height
Definition dsp.h:99
#define width
Definition dsp.h:99
static const char * backend_name(SwsBackend backend)
Definition swscale.c:641
double speedup_min
Definition swscale.c:135
static const char * speedup_color(double ratio)
Definition swscale.c:154
static int init_ref(AVFrame *ref, const struct options *opts)
Definition swscale.c:1149
struct runner * runners
Definition swscale.c:143
double speedup_logavg
Definition swscale.c:134
static int run_runner(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads)
Definition swscale.c:1129
#define IMPL_LEGACY
Definition swscale.c:54
static int push_test(const struct test_case *t, const struct options *opts)
Definition swscale.c:925
static int run_test(struct runner *runner, const struct test_case *t, const struct options *opts)
Definition swscale.c:775
static float estimate_quantization_noise(enum AVPixelFormat fmt)
Definition swscale.c:178
static void runner_free(struct runner *runner)
Definition swscale.c:1107
int speedup_count
Definition swscale.c:137
static void exit_handler(int sig)
Definition swscale.c:165
static int run_self_tests(const struct options *opts)
Definition swscale.c:934
double speedup_max
Definition swscale.c:136
static int fmt_disabled(const struct options *opts, enum AVPixelFormat fmt)
Definition swscale.c:902
static int parse_threads(struct options *opts, const char *str)
Definition swscale.c:1208
static float get_loss(const float ssim[4])
Definition swscale.c:257
static const SwsFlags coverage_flags[]
Definition swscale.c:740
static int runner_init(struct runner *runner)
Definition swscale.c:1093
#define IMPL_NEW
Definition swscale.c:53
static int checked_sws_scale_frame(SwsContext *c, AVFrame *dst, const AVFrame *src)
Definition swscale.c:301
FFSFC64 prng_state
Definition swscale.c:128
static int init_frame(AVFrame **pframe, const AVFrame *ref, int width, int height, enum AVPixelFormat format)
Definition swscale.c:627
static int check_coverage(struct runner *runner, const struct test_case *t, const struct mode *mode, const struct options *opts)
Definition swscale.c:696
static int parse_implementation(const char *str)
Definition swscale.c:1228
static int run_coverage(struct runner *runner, const struct test_case *t, const struct options *opts)
Definition swscale.c:747
static int scale_hw(AVFrame *dst, const AVFrame *src, const struct mode *mode, const struct options *opts, int64_t *out_time)
Definition swscale.c:391
static int fmt_is_supported_by_hw(enum AVPixelFormat fmt)
Definition swscale.c:887
static int scale_legacy(AVFrame *dst, const AVFrame *src, const struct mode *mode, const struct options *opts, int64_t *out_time)
Definition swscale.c:346
static void get_ssim(float ssim[4], const AVFrame *out, const AVFrame *ref, int comps)
Definition swscale.c:209
static int fmt_is_subsampled(enum AVPixelFormat fmt)
Definition swscale.c:881
FILE * fp
Definition swscale.c:145
@ AUX_FLAGS
Definition swscale.c:59
@ AUX_BACKENDS
Definition swscale.c:58
int coverage_supported
Definition swscale.c:140
static void print_test_params(AVBPrint *bp, const AVFrame *src, const AVFrame *dst, const struct mode *mode, const struct options *opts)
Definition swscale.c:518
static int parse_size(struct options *opts, const char *str, char **pbuf)
Definition swscale.c:1183
static void describe_passes(AVBPrint *bp, const SwsGraph *graph)
Definition swscale.c:654
static int run_producer(void *priv)
Definition swscale.c:1120
static void print_coverage_summary(void)
Definition swscale.c:764
int coverage_total
Definition swscale.c:139
static int parse_options(int argc, char **argv, struct options *opts, FILE **fp)
Definition swscale.c:1237
static int fmt_comps(enum AVPixelFormat fmt)
Definition swscale.c:200
static void print_results(const AVFrame *ref, const AVFrame *src, const AVFrame *dst, int dst_w, int dst_h, const struct mode *mode, const struct options *opts, const struct test_results *r, const struct test_results *ref_r, float expected_loss)
Definition swscale.c:536
static int scale_new(struct runner *runner, AVFrame *dst, const AVFrame *src, const struct mode *mode, const struct options *opts, int64_t *out_time)
Definition swscale.c:311
static int run_file_tests(const struct options *opts)
Definition swscale.c:1011
AVHWFramesConstraints * hw_device_constr
Definition swscale.c:131
AVThreadMessageQueue * queue
Definition swscale.c:148
static int test_formats(const struct options *opts, enum AVPixelFormat src, enum AVPixelFormat dst)
Definition swscale.c:909
static int get_buffer(AVFrame *frame, int align)
Definition swscale.c:282
AVMutex speedup_lock
Definition swscale.c:133
static int run_tests(const struct options *opts)
Definition swscale.c:1115
static void unref_buffers(AVFrame *frame)
Definition swscale.c:269
static struct @232240247175332074307271266321204261331170211232 state
static void print_coverage_result(const AVFrame *src, const AVFrame *dst, const struct mode *mode, const struct options *opts, const SwsGraph *graph)
Definition swscale.c:669
struct AVMD5 * coverage_md5
Definition swscale.c:141
void av_thread_message_queue_set_err_send(AVThreadMessageQueue *mq, int err)
Set the sending error code.
int av_thread_message_queue_recv(AVThreadMessageQueue *mq, void *msg, unsigned flags)
Receive a message from the queue.
int av_thread_message_queue_alloc(AVThreadMessageQueue **mq, unsigned nelem, unsigned elsize)
Allocate a new message queue.
void av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq, int err)
Set the receiving error code.
int av_thread_message_queue_send(AVThreadMessageQueue *mq, void *msg, unsigned flags)
Send a message on the queue.
void av_thread_message_flush(AVThreadMessageQueue *mq)
Flush the message queue.
void av_thread_message_queue_free(AVThreadMessageQueue **mq)
Free a message queue.
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition time.c:57
const char * g
Definition vf_curves.c:128
static double c[64]