FFmpeg
sw_yuv2yuv.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 modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (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
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #include <string.h>
20 
21 #include "libavutil/common.h"
22 #include "libavutil/intreadwrite.h"
23 #include "libavutil/mem_internal.h"
24 #include "libavutil/pixdesc.h"
25 
26 #include "libswscale/swscale.h"
28 
29 #include "checkasm.h"
30 
31 #define randomize_buffers(buf, size) \
32  do { \
33  for (int j = 0; j < size; j += 4) \
34  AV_WN32(buf + j, rnd()); \
35  } while (0)
36 
37 static void check_semiplanar(int dst_pix_fmt)
38 {
39  static const int src_fmts[] = {
42  };
43  const AVPixFmtDescriptor *dst_desc = av_pix_fmt_desc_get(dst_pix_fmt);
44 #define NUM_LINES 4
45 #define MAX_LINE_SIZE 1920
46  static const int input_sizes[] = {8, 128, 1080, MAX_LINE_SIZE};
47 
49  int, SwsContext *c, const uint8_t *src[],
50  int srcStride[], int srcSliceY, int srcSliceH,
51  uint8_t *dst[], int dstStride[]);
52 
53  LOCAL_ALIGNED_8(uint8_t, src_y, [MAX_LINE_SIZE * NUM_LINES]);
54  LOCAL_ALIGNED_8(uint8_t, src_uv, [MAX_LINE_SIZE * NUM_LINES * 2]);
55  const uint8_t *src[4] = { src_y, src_uv };
56 
57  LOCAL_ALIGNED_8(uint8_t, dst0_y, [MAX_LINE_SIZE * NUM_LINES]);
58  LOCAL_ALIGNED_8(uint8_t, dst0_u, [MAX_LINE_SIZE * NUM_LINES / 2]);
59  LOCAL_ALIGNED_8(uint8_t, dst0_v, [MAX_LINE_SIZE * NUM_LINES / 2]);
60  uint8_t *dst0[4] = { dst0_y, dst0_u, dst0_v };
61 
62  LOCAL_ALIGNED_8(uint8_t, dst1_y, [MAX_LINE_SIZE * NUM_LINES]);
63  LOCAL_ALIGNED_8(uint8_t, dst1_u, [MAX_LINE_SIZE * NUM_LINES / 2]);
64  LOCAL_ALIGNED_8(uint8_t, dst1_v, [MAX_LINE_SIZE * NUM_LINES / 2]);
65  uint8_t *dst1[4] = { dst1_y, dst1_u, dst1_v };
66 
69 
70  for (int sfi = 0; sfi < FF_ARRAY_ELEMS(src_fmts); sfi++) {
71  int src_pix_fmt = src_fmts[sfi];
72  const AVPixFmtDescriptor *src_desc = av_pix_fmt_desc_get(src_pix_fmt);
73  for (int isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); isi++) {
74  struct SwsContext *ctx;
75  int log_level;
76  int width = input_sizes[isi];
77  int srcSliceY = 0;
78  int srcSliceH = NUM_LINES;
79  int srcStride[4] = {
81  MAX_LINE_SIZE * 2,
82  };
83  int dstStride[4] = {
85  MAX_LINE_SIZE >> dst_desc->log2_chroma_w,
86  MAX_LINE_SIZE >> dst_desc->log2_chroma_w,
87  };
88 
89  // override log level to prevent spamming of the message
90  // "No accelerated colorspace conversion found from %s to %s"
91  log_level = av_log_get_level();
93  ctx = sws_getContext(width, srcSliceH, src_pix_fmt,
94  width, srcSliceH, dst_pix_fmt,
95  0, NULL, NULL, NULL);
96  av_log_set_level(log_level);
97  if (!ctx)
98  fail();
99 
100  if (check_func(ctx->convert_unscaled, "%s_%s_%d", src_desc->name, dst_desc->name, width)) {
101  memset(dst0_y, 0xFF, MAX_LINE_SIZE * NUM_LINES);
102  memset(dst0_u, 0xFF, MAX_LINE_SIZE * NUM_LINES / 2);
103  memset(dst0_v, 0xFF, MAX_LINE_SIZE * NUM_LINES / 2);
104  memset(dst1_y, 0xFF, MAX_LINE_SIZE * NUM_LINES);
105  memset(dst1_u, 0xFF, MAX_LINE_SIZE * NUM_LINES / 2);
106  memset(dst1_v, 0xFF, MAX_LINE_SIZE * NUM_LINES / 2);
107 
108  call_ref(ctx, src, srcStride, srcSliceY,
109  srcSliceH, dst0, dstStride);
110  call_new(ctx, src, srcStride, srcSliceY,
111  srcSliceH, dst1, dstStride);
112 
113  if (memcmp(dst0_y, dst1_y, MAX_LINE_SIZE * NUM_LINES) ||
114  memcmp(dst0_u, dst1_u, MAX_LINE_SIZE * NUM_LINES / 2) ||
115  memcmp(dst0_v, dst1_v, MAX_LINE_SIZE * NUM_LINES / 2))
116  fail();
117 
118  bench_new(ctx, src, srcStride, srcSliceY,
119  srcSliceH, dst0, dstStride);
120  }
122  }
123  }
124 }
125 
126 #undef NUM_LINES
127 #undef MAX_LINE_SIZE
128 
130 {
132  report("yuv420p");
133 }
check_semiplanar
static void check_semiplanar(int dst_pix_fmt)
Definition: sw_yuv2yuv.c:37
declare_func_emms
#define declare_func_emms(cpu_flags, ret,...)
Definition: checkasm.h:185
mem_internal.h
randomize_buffers
#define randomize_buffers(buf, size)
Definition: sw_yuv2yuv.c:31
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3025
MAX_LINE_SIZE
#define MAX_LINE_SIZE
pixdesc.h
AVPixFmtDescriptor::name
const char * name
Definition: pixdesc.h:70
check_func
#define check_func(func,...)
Definition: checkasm.h:179
call_ref
#define call_ref(...)
Definition: checkasm.h:194
fail
#define fail()
Definition: checkasm.h:188
checkasm.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
checkasm_check_sw_yuv2yuv
void checkasm_check_sw_yuv2yuv(void)
Definition: sw_yuv2yuv.c:129
intreadwrite.h
input_sizes
static const int input_sizes[]
Definition: sw_rgb.c:346
ctx
AVFormatContext * ctx
Definition: movenc.c:49
AVPixFmtDescriptor::log2_chroma_w
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
LOCAL_ALIGNED_8
#define LOCAL_ALIGNED_8(t, v,...)
Definition: mem_internal.h:144
av_log_get_level
int av_log_get_level(void)
Get the current log level.
Definition: log.c:442
call_new
#define call_new(...)
Definition: checkasm.h:297
NULL
#define NULL
Definition: coverity.c:32
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
NUM_LINES
#define NUM_LINES
sws_getContext
struct SwsContext * sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
Allocate and return an SwsContext.
Definition: utils.c:2105
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
report
#define report
Definition: checkasm.h:191
av_log_set_level
void av_log_set_level(int level)
Set the log level.
Definition: log.c:447
bench_new
#define bench_new(...)
Definition: checkasm.h:368
AV_PIX_FMT_NV24
@ 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
common.h
swscale_internal.h
AV_PIX_FMT_NV42
@ AV_PIX_FMT_NV42
as above, but U and V bytes are swapped
Definition: pixfmt.h:372
AV_CPU_FLAG_MMX
#define AV_CPU_FLAG_MMX
standard MMX
Definition: cpu.h:30
sws_freeContext
void sws_freeContext(struct SwsContext *swsContext)
Free the swscaler context swsContext.
Definition: utils.c:2436
AV_CPU_FLAG_MMXEXT
#define AV_CPU_FLAG_MMXEXT
SSE integer functions or AMD MMX ext.
Definition: cpu.h:31
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
width
#define width
Definition: dsp.h:85
SwsContext
Definition: swscale_internal.h:324
src
#define src
Definition: vp8dsp.c:248
swscale.h