FFmpeg
Loading...
Searching...
No Matches
unscaled_threaded.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <stdio.h>
20#include <string.h>
21
22#include "libavutil/frame.h"
23#include "libavutil/imgutils.h"
24#include "libavutil/log.h"
25#include "libavutil/opt.h"
26#include "libavutil/pixdesc.h"
27#include "libswscale/swscale.h"
28
30{
32
33 if (!frame)
34 return NULL;
35 frame->format = format;
36 frame->width = 64;
37 frame->height = height;
38 if (av_frame_get_buffer(frame, 32) < 0)
40 return frame;
41}
42
43static int convert(AVFrame *dst, const AVFrame *src, int threads, int legacy)
44{
45 struct SwsContext *sws = sws_alloc_context();
46 int ret;
47
48 if (!sws)
49 return AVERROR(ENOMEM);
50 av_opt_set_int(sws, "threads", threads, 0);
51 av_opt_set_int(sws, "sws_flags", SWS_BILINEAR, 0);
52 av_opt_set(sws, "sws_dither", "none", 0);
53 if (legacy) {
54 av_opt_set_int(sws, "srcw", src->width, 0);
55 av_opt_set_int(sws, "srch", src->height, 0);
56 av_opt_set_int(sws, "src_format", src->format, 0);
57 av_opt_set_int(sws, "dstw", dst->width, 0);
58 av_opt_set_int(sws, "dsth", dst->height, 0);
59 av_opt_set_int(sws, "dst_format", dst->format, 0);
61 if (ret < 0)
62 goto end;
63 }
64 ret = sws_scale_frame(sws, dst, src);
65end:
66 sws_freeContext(sws);
67 return ret;
68}
69
70static int compare(enum AVPixelFormat src_fmt, enum AVPixelFormat dst_fmt,
71 int height, int legacy, unsigned *mismatches)
72{
73 static const int threads[] = { 2, 3, 7, 16 };
75 AVFrame *src = alloc_frame(src_fmt, height);
76 AVFrame *ref = alloc_frame(dst_fmt, height);
77 AVFrame *dst = alloc_frame(dst_fmt, height);
78 int ret = AVERROR(ENOMEM);
79
80 if (!src || !ref || !dst)
81 goto end;
82 for (int p = 0; p < 4 && src->data[p]; p++) {
83 const int h = AV_CEIL_RSHIFT(height, p == 1 || p == 2 ? desc->log2_chroma_h : 0);
84 const int w = av_image_get_linesize(src_fmt, src->width, p);
85 for (int y = 0; y < h; y++)
86 for (int x = 0; x < w; x++)
87 src->data[p][y * src->linesize[p] + x] =
88 (x * 37 + y * 73 + x * y * 11 + p * 59) & 255;
89 }
90 ret = convert(ref, src, 1, legacy);
91 if (ret < 0)
92 goto end;
93 for (int t = 0; t < FF_ARRAY_ELEMS(threads); t++) {
94 ret = convert(dst, src, threads[t], legacy);
95 if (ret < 0)
96 goto end;
97 for (int p = 0; p < 4 && dst->data[p]; p++) {
98 const int w = av_image_get_linesize(dst_fmt, dst->width, p);
99 for (int y = 0; y < height; y++)
100 *mismatches += !!memcmp(ref->data[p] + y * ref->linesize[p],
101 dst->data[p] + y * dst->linesize[p], w);
102 }
103 }
104end:
108 return ret;
109}
110
111int main(void)
112{
113 static const enum AVPixelFormat inputs[] = {
116 };
117 static const enum AVPixelFormat outputs[] = {
124 };
125 static const int heights[] = { 2, 6, 14, 48, 50 };
126
128
129 /* Compare against the same implementation with one thread, since different
130 * architectures need not produce identical rounding. Include both the
131 * dynamic graph and the initialized legacy context APIs. */
132 for (int s = 0; s < FF_ARRAY_ELEMS(inputs); s++) {
133 for (int d = 0; d < FF_ARRAY_ELEMS(outputs); d++) {
134 unsigned mismatches = 0;
135 for (int legacy = 0; legacy <= 1; legacy++) {
136 for (int h = 0; h < FF_ARRAY_ELEMS(heights); h++) {
137 int ret = compare(inputs[s], outputs[d], heights[h], legacy, &mismatches);
138 if (ret < 0)
139 return 1;
140 }
141 }
142 printf("%s -> %s: %u mismatching rows\n",
144 mismatches);
145 }
146 }
147 return 0;
148}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
static const AVFilterPad inputs[]
Definition af_aap.c:299
static const AVFilterPad outputs[]
Definition af_aap.c:310
static const char *const format[]
Definition af_aiir.c:445
#define s(width, name)
Definition cbs_vp9.c:198
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#define NULL
Definition coverity.c:32
__device__ int printf(const char *,...)
static AVFrame * frame
int ret
Definition ffplay.c:391
reference-counted frame API
#define AVERROR(e)
Definition error.h:45
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
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:53
#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_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
Compute the size of an image line with format pix_fmt and width width for the plane plane.
Definition imgutils.c:76
av_warn_unused_result int sws_init_context(SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter)
Initialize the swscaler context sws_context.
Definition utils.c:1972
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:1082
void sws_freeContext(SwsContext *swsContext)
Free the swscaler context swsContext.
Definition utils.c:2338
@ SWS_BILINEAR
bilinear filtering
Definition swscale.h:198
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition opt.c:951
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition opt.c:904
misc image utilities
const char * desc
Definition libsvtav1.c:83
uint8_t w
Definition llvidencdsp.c:39
AVOptions.
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
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3484
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition pixfmt.h:96
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition pixfmt.h:75
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_NV21
as above, but U and V bytes are swapped
Definition pixfmt.h:97
@ AV_PIX_FMT_BGR565BE
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), big-endian
Definition pixfmt.h:117
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:77
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition pixfmt.h:99
@ AV_PIX_FMT_RGB555BE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), big-endian , X=unused/undefined
Definition pixfmt.h:114
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition pixfmt.h:102
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition pixfmt.h:101
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition pixfmt.h:108
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition pixfmt.h:100
@ AV_PIX_FMT_RGB565LE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
Definition pixfmt.h:113
@ AV_PIX_FMT_RGB555LE
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined
Definition pixfmt.h:115
@ AV_PIX_FMT_BGR555BE
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), big-endian , X=unused/undefined
Definition pixfmt.h:119
@ AV_PIX_FMT_RGB565BE
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
Definition pixfmt.h:112
@ AV_PIX_FMT_BGR555LE
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), little-endian, X=unused/undefined
Definition pixfmt.h:120
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition pixfmt.h:76
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition pixfmt.h:165
@ AV_PIX_FMT_BGR565LE
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), little-endian
Definition pixfmt.h:118
#define FF_ARRAY_ELEMS(a)
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
Main external API structure.
Definition swscale.h:227
int threads
How many threads to use for processing, or 0 for automatic selection.
Definition swscale.h:249
external API header
#define src
Definition vp8dsp.c:248
static int ref[MAX_W *MAX_W]
#define height
Definition dsp.h:99
static int compare(enum AVPixelFormat src_fmt, enum AVPixelFormat dst_fmt, int height, int legacy, unsigned *mismatches)
static int convert(AVFrame *dst, const AVFrame *src, int threads, int legacy)
int main(void)
static AVFrame * alloc_frame(enum AVPixelFormat format, int height)