FFmpeg
hevc_sao.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Yingming Fan <yingmingfan@gmail.com>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #include <string.h>
22 
23 #include "libavutil/intreadwrite.h"
24 #include "libavutil/mem_internal.h"
25 
26 #include "libavcodec/avcodec.h"
27 
28 #include "libavcodec/hevcdsp.h"
29 
30 #include "checkasm.h"
31 
32 static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
33 static const uint32_t sao_size[5] = {8, 16, 32, 48, 64};
34 
35 #define SIZEOF_PIXEL ((bit_depth + 7) / 8)
36 #define PIXEL_STRIDE (2*MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) //same with sao_edge src_stride
37 #define BUF_SIZE (PIXEL_STRIDE * (64+2) * 2) //+2 for top and bottom row, *2 for high bit depth
38 #define OFFSET_THRESH (1 << (bit_depth - 5))
39 #define OFFSET_LENGTH 5
40 
41 #define randomize_buffers(buf0, buf1, size) \
42  do { \
43  uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
44  int k; \
45  for (k = 0; k < size; k += 4) { \
46  uint32_t r = rnd() & mask; \
47  AV_WN32A(buf0 + k, r); \
48  AV_WN32A(buf1 + k, r); \
49  } \
50  } while (0)
51 
52 #define randomize_buffers2(buf, size) \
53  do { \
54  uint32_t max_offset = OFFSET_THRESH; \
55  int k; \
56  if (bit_depth == 8) { \
57  for (k = 0; k < size; k++) { \
58  uint8_t r = rnd() % max_offset; \
59  buf[k] = r; \
60  } \
61  } else { \
62  for (k = 0; k < size; k++) { \
63  uint16_t r = rnd() % max_offset; \
64  buf[k] = r; \
65  } \
66  } \
67  } while (0)
68 
70 {
71  int i;
72  LOCAL_ALIGNED_32(uint8_t, dst0, [BUF_SIZE]);
73  LOCAL_ALIGNED_32(uint8_t, dst1, [BUF_SIZE]);
74  LOCAL_ALIGNED_32(uint8_t, src0, [BUF_SIZE]);
75  LOCAL_ALIGNED_32(uint8_t, src1, [BUF_SIZE]);
76  int16_t offset_val[OFFSET_LENGTH];
77  int left_class = rnd()%32;
78 
79  for (i = 0; i <= 4; i++) {
80  int block_size = sao_size[i];
81  ptrdiff_t stride = PIXEL_STRIDE*SIZEOF_PIXEL;
82  declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, uint8_t *src, ptrdiff_t dst_stride, ptrdiff_t src_stride,
83  int16_t *sao_offset_val, int sao_left_class, int width, int height);
84 
86  randomize_buffers2(offset_val, OFFSET_LENGTH);
87  memset(dst0, 0, BUF_SIZE);
88  memset(dst1, 0, BUF_SIZE);
89 
90  if (check_func(h.sao_band_filter[i], "hevc_sao_band_%dx%d_%d", block_size, block_size, bit_depth)) {
91  call_ref(dst0, src0, stride, stride, offset_val, left_class, block_size, block_size);
92  call_new(dst1, src1, stride, stride, offset_val, left_class, block_size, block_size);
93  if (memcmp(dst0, dst1, BUF_SIZE))
94  fail();
95  bench_new(dst1, src1, stride, stride, offset_val, left_class, block_size, block_size);
96  }
97  }
98 }
99 
101 {
102  int i;
103  LOCAL_ALIGNED_32(uint8_t, dst0, [BUF_SIZE]);
104  LOCAL_ALIGNED_32(uint8_t, dst1, [BUF_SIZE]);
105  LOCAL_ALIGNED_32(uint8_t, src0, [BUF_SIZE]);
106  LOCAL_ALIGNED_32(uint8_t, src1, [BUF_SIZE]);
107  int16_t offset_val[OFFSET_LENGTH];
108  int eo = rnd()%4;
109 
110  for (i = 0; i <= 4; i++) {
111  int block_size = sao_size[i];
112  ptrdiff_t stride = PIXEL_STRIDE*SIZEOF_PIXEL;
114  declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, uint8_t *src, ptrdiff_t stride_dst,
115  int16_t *sao_offset_val, int eo, int width, int height);
116 
118  randomize_buffers2(offset_val, OFFSET_LENGTH);
119  memset(dst0, 0, BUF_SIZE);
120  memset(dst1, 0, BUF_SIZE);
121 
122  if (check_func(h.sao_edge_filter[i], "hevc_sao_edge_%dx%d_%d", block_size, block_size, bit_depth)) {
123  call_ref(dst0, src0 + offset, stride, offset_val, eo, block_size, block_size);
124  call_new(dst1, src1 + offset, stride, offset_val, eo, block_size, block_size);
125  if (memcmp(dst0, dst1, BUF_SIZE))
126  fail();
127  bench_new(dst1, src1 + offset, stride, offset_val, eo, block_size, block_size);
128  }
129  }
130 }
131 
133 {
134  int bit_depth;
135 
136  for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
138 
141  }
142  report("sao_band");
143 
144  for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
146 
149  }
150  report("sao_edge");
151 }
declare_func_emms
#define declare_func_emms(cpu_flags, ret,...)
Definition: checkasm.h:124
stride
int stride
Definition: mace.c:144
bit_depth
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
Definition: af_astats.c:226
randomize_buffers2
#define randomize_buffers2(buf, size)
Definition: hevc_sao.c:52
mem_internal.h
check_func
#define check_func(func,...)
Definition: checkasm.h:118
call_ref
#define call_ref(...)
Definition: checkasm.h:133
check_sao_edge
static void check_sao_edge(HEVCDSPContext h, int bit_depth)
Definition: hevc_sao.c:100
fail
#define fail()
Definition: checkasm.h:127
checkasm.h
rnd
#define rnd()
Definition: checkasm.h:111
BUF_SIZE
#define BUF_SIZE
Definition: hevc_sao.c:37
width
#define width
intreadwrite.h
sao_size
static const uint32_t sao_size[5]
Definition: hevc_sao.c:33
randomize_buffers
#define randomize_buffers(buf0, buf1, size)
Definition: hevc_sao.c:41
hevcdsp.h
call_new
#define call_new(...)
Definition: checkasm.h:205
LOCAL_ALIGNED_32
#define LOCAL_ALIGNED_32(t, v,...)
Definition: mem_internal.h:136
src
#define src
Definition: vp8dsp.c:255
checkasm_check_hevc_sao
void checkasm_check_hevc_sao(void)
Definition: hevc_sao.c:132
PIXEL_STRIDE
#define PIXEL_STRIDE
Definition: hevc_sao.c:36
SIZEOF_PIXEL
#define SIZEOF_PIXEL
Definition: hevc_sao.c:35
height
#define height
HEVCDSPContext
Definition: hevcdsp.h:47
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
src0
#define src0
Definition: h264pred.c:139
src1
#define src1
Definition: h264pred.c:140
report
#define report
Definition: checkasm.h:130
bench_new
#define bench_new(...)
Definition: checkasm.h:268
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
avcodec.h
ff_hevc_dsp_init
void ff_hevc_dsp_init(HEVCDSPContext *hevcdsp, int bit_depth)
Definition: hevcdsp.c:126
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
AV_CPU_FLAG_MMX
#define AV_CPU_FLAG_MMX
standard MMX
Definition: cpu.h:29
pixel_mask
static const uint32_t pixel_mask[3]
Definition: hevc_sao.c:32
check_sao_band
static void check_sao_band(HEVCDSPContext h, int bit_depth)
Definition: hevc_sao.c:69
OFFSET_LENGTH
#define OFFSET_LENGTH
Definition: hevc_sao.c:39
h
h
Definition: vp9dsp_template.c:2038