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/hevcdsp.h"
27 
28 #include "checkasm.h"
29 
30 static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
31 static const uint32_t sao_size[5] = {8, 16, 32, 48, 64};
32 
33 #define SIZEOF_PIXEL ((bit_depth + 7) / 8)
34 #define PIXEL_STRIDE (2*MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) //same with sao_edge src_stride
35 #define BUF_SIZE (PIXEL_STRIDE * (64+2) * 2) //+2 for top and bottom row, *2 for high bit depth
36 #define OFFSET_THRESH (1 << (bit_depth - 5))
37 #define OFFSET_LENGTH 5
38 
39 #define randomize_buffers(buf0, buf1, size) \
40  do { \
41  uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
42  int k; \
43  for (k = 0; k < size; k += 4) { \
44  uint32_t r = rnd() & mask; \
45  AV_WN32A(buf0 + k, r); \
46  AV_WN32A(buf1 + k, r); \
47  } \
48  } while (0)
49 
50 #define randomize_buffers2(buf, size) \
51  do { \
52  uint32_t max_offset = OFFSET_THRESH; \
53  int k; \
54  if (bit_depth == 8) { \
55  for (k = 0; k < size; k++) { \
56  uint8_t r = rnd() % max_offset; \
57  buf[k] = r; \
58  } \
59  } else { \
60  for (k = 0; k < size; k++) { \
61  uint16_t r = rnd() % max_offset; \
62  buf[k] = r; \
63  } \
64  } \
65  } while (0)
66 
68 {
69  int i;
70  LOCAL_ALIGNED_32(uint8_t, dst0, [BUF_SIZE]);
71  LOCAL_ALIGNED_32(uint8_t, dst1, [BUF_SIZE]);
72  LOCAL_ALIGNED_32(uint8_t, src0, [BUF_SIZE]);
73  LOCAL_ALIGNED_32(uint8_t, src1, [BUF_SIZE]);
74  int16_t offset_val[OFFSET_LENGTH];
75  int left_class = rnd()%32;
76 
77  for (i = 0; i <= 4; i++) {
78  int block_size = sao_size[i];
79  int prev_size = i > 0 ? sao_size[i - 1] : 0;
80  ptrdiff_t stride = PIXEL_STRIDE*SIZEOF_PIXEL;
81  declare_func(void, uint8_t *dst, const uint8_t *src, ptrdiff_t dst_stride, ptrdiff_t src_stride,
82  const int16_t *sao_offset_val, int sao_left_class, int width, int height);
83 
84  if (check_func(h->sao_band_filter[i], "hevc_sao_band_%d_%d", block_size, bit_depth)) {
85 
86  for (int w = prev_size + 4; w <= block_size; w += 4) {
88  randomize_buffers2(offset_val, OFFSET_LENGTH);
89  memset(dst0, 0, BUF_SIZE);
90  memset(dst1, 0, BUF_SIZE);
91 
92  call_ref(dst0, src0, stride, stride, offset_val, left_class, w, block_size);
93  call_new(dst1, src1, stride, stride, offset_val, left_class, w, block_size);
94  for (int j = 0; j < block_size; j++) {
95  if (memcmp(dst0 + j*stride, dst1 + j*stride, w*SIZEOF_PIXEL))
96  fail();
97  }
98  }
99  bench_new(dst1, src1, stride, stride, offset_val, left_class, block_size, block_size);
100  }
101  }
102 }
103 
105 {
106  int i;
107  LOCAL_ALIGNED_32(uint8_t, dst0, [BUF_SIZE]);
108  LOCAL_ALIGNED_32(uint8_t, dst1, [BUF_SIZE]);
109  LOCAL_ALIGNED_32(uint8_t, src0, [BUF_SIZE]);
110  LOCAL_ALIGNED_32(uint8_t, src1, [BUF_SIZE]);
111  int16_t offset_val[OFFSET_LENGTH];
112  int eo = rnd()%4;
113 
114  for (i = 0; i <= 4; i++) {
115  int block_size = sao_size[i];
116  int prev_size = i > 0 ? sao_size[i - 1] : 0;
117  ptrdiff_t stride = PIXEL_STRIDE*SIZEOF_PIXEL;
119  declare_func(void, uint8_t *dst, const uint8_t *src, ptrdiff_t stride_dst,
120  const int16_t *sao_offset_val, int eo, int width, int height);
121 
122  for (int w = prev_size + 4; w <= block_size; w += 4) {
124  randomize_buffers2(offset_val, OFFSET_LENGTH);
125  memset(dst0, 0, BUF_SIZE);
126  memset(dst1, 0, BUF_SIZE);
127 
128  if (check_func(h->sao_edge_filter[i], "hevc_sao_edge_%d_%d", block_size, bit_depth)) {
129  call_ref(dst0, src0 + offset, stride, offset_val, eo, w, block_size);
130  call_new(dst1, src1 + offset, stride, offset_val, eo, w, block_size);
131  for (int j = 0; j < block_size; j++) {
132  if (memcmp(dst0 + j*stride, dst1 + j*stride, w*SIZEOF_PIXEL))
133  fail();
134  }
135  bench_new(dst1, src1 + offset, stride, offset_val, eo, block_size, block_size);
136  }
137  }
138  }
139 }
140 
142 {
143  int bit_depth;
144 
145  for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
147 
150  }
151  report("sao_band");
152 
153  for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
155 
158  }
159  report("sao_edge");
160 }
randomize_buffers2
#define randomize_buffers2(buf, size)
Definition: hevc_sao.c:50
mem_internal.h
src1
const pixel * src1
Definition: h264pred_template.c:421
w
uint8_t w
Definition: llviddspenc.c:38
check_func
#define check_func(func,...)
Definition: checkasm.h:174
call_ref
#define call_ref(...)
Definition: checkasm.h:189
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:246
fail
#define fail()
Definition: checkasm.h:183
checkasm.h
rnd
#define rnd()
Definition: checkasm.h:167
BUF_SIZE
#define BUF_SIZE
Definition: hevc_sao.c:35
width
#define width
intreadwrite.h
sao_size
static const uint32_t sao_size[5]
Definition: hevc_sao.c:31
check_sao_band
static void check_sao_band(HEVCDSPContext *h, int bit_depth)
Definition: hevc_sao.c:67
randomize_buffers
#define randomize_buffers(buf0, buf1, size)
Definition: hevc_sao.c:39
hevcdsp.h
call_new
#define call_new(...)
Definition: checkasm.h:292
LOCAL_ALIGNED_32
#define LOCAL_ALIGNED_32(t, v,...)
Definition: mem_internal.h:156
checkasm_check_hevc_sao
void checkasm_check_hevc_sao(void)
Definition: hevc_sao.c:141
PIXEL_STRIDE
#define PIXEL_STRIDE
Definition: hevc_sao.c:34
SIZEOF_PIXEL
#define SIZEOF_PIXEL
Definition: hevc_sao.c:33
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
report
#define report
Definition: checkasm.h:186
bench_new
#define bench_new(...)
Definition: checkasm.h:363
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
check_sao_edge
static void check_sao_edge(HEVCDSPContext *h, int bit_depth)
Definition: hevc_sao.c:104
stride
#define stride
Definition: h264pred_template.c:537
ff_hevc_dsp_init
void ff_hevc_dsp_init(HEVCDSPContext *hevcdsp, int bit_depth)
Definition: hevcdsp.c:128
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
pixel_mask
static const uint32_t pixel_mask[3]
Definition: hevc_sao.c:30
src0
const pixel *const src0
Definition: h264pred_template.c:420
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:178
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
OFFSET_LENGTH
#define OFFSET_LENGTH
Definition: hevc_sao.c:37
h
h
Definition: vp9dsp_template.c:2038