FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
25 #include "libavcodec/avcodec.h"
26 
27 #include "libavcodec/hevcdsp.h"
28 
29 #include "checkasm.h"
30 
31 static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
32 static const uint32_t sao_size[5] = {8, 16, 32, 48, 64};
33 
34 #define SIZEOF_PIXEL ((bit_depth + 7) / 8)
35 #define PIXEL_STRIDE (2*MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) //same with sao_edge src_stride
36 #define BUF_SIZE (PIXEL_STRIDE * (64+2) * 2) //+2 for top and bottom row, *2 for high bit depth
37 #define OFFSET_THRESH (1 << (bit_depth - 5))
38 #define OFFSET_LENGTH 5
39 
40 #define randomize_buffers(buf0, buf1, size) \
41  do { \
42  uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
43  int k; \
44  for (k = 0; k < size; k += 4) { \
45  uint32_t r = rnd() & mask; \
46  AV_WN32A(buf0 + k, r); \
47  AV_WN32A(buf1 + k, r); \
48  } \
49  } while (0)
50 
51 #define randomize_buffers2(buf, size) \
52  do { \
53  uint32_t max_offset = OFFSET_THRESH; \
54  int k; \
55  if (bit_depth == 8) { \
56  for (k = 0; k < size; k++) { \
57  uint8_t r = rnd() % max_offset; \
58  buf[k] = r; \
59  } \
60  } else { \
61  for (k = 0; k < size; k++) { \
62  uint16_t r = rnd() % max_offset; \
63  buf[k] = r; \
64  } \
65  } \
66  } while (0)
67 
69 {
70  int i;
75  int16_t offset_val[OFFSET_LENGTH];
76  int left_class = rnd()%32;
77 
78  for (i = 0; i <= 4; i++) {
79  int block_size = sao_size[i];
80  ptrdiff_t stride = PIXEL_STRIDE*SIZEOF_PIXEL;
81  declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, uint8_t *src, ptrdiff_t dst_stride, ptrdiff_t src_stride,
82  int16_t *sao_offset_val, int sao_left_class, int width, int height);
83 
85  randomize_buffers2(offset_val, OFFSET_LENGTH);
86  memset(dst0, 0, BUF_SIZE);
87  memset(dst1, 0, BUF_SIZE);
88 
89  if (check_func(h.sao_band_filter[i], "hevc_sao_band_%dx%d_%d", block_size, block_size, bit_depth)) {
90  call_ref(dst0, src0, stride, stride, offset_val, left_class, block_size, block_size);
91  call_new(dst1, src1, stride, stride, offset_val, left_class, block_size, block_size);
92  if (memcmp(dst0, dst1, BUF_SIZE))
93  fail();
94  bench_new(dst1, src1, stride, stride, offset_val, left_class, block_size, block_size);
95  }
96  }
97 }
98 
100 {
101  int i;
106  int16_t offset_val[OFFSET_LENGTH];
107  int eo = rnd()%4;
108 
109  for (i = 0; i <= 4; i++) {
110  int block_size = sao_size[i];
111  ptrdiff_t stride = PIXEL_STRIDE*SIZEOF_PIXEL;
112  int offset = (AV_INPUT_BUFFER_PADDING_SIZE + PIXEL_STRIDE)*SIZEOF_PIXEL;
113  declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, uint8_t *src, ptrdiff_t stride_dst,
114  int16_t *sao_offset_val, int eo, int width, int height);
115 
117  randomize_buffers2(offset_val, OFFSET_LENGTH);
118  memset(dst0, 0, BUF_SIZE);
119  memset(dst1, 0, BUF_SIZE);
120 
121  if (check_func(h.sao_edge_filter[i], "hevc_sao_edge_%dx%d_%d", block_size, block_size, bit_depth)) {
122  call_ref(dst0, src0 + offset, stride, offset_val, eo, block_size, block_size);
123  call_new(dst1, src1 + offset, stride, offset_val, eo, block_size, block_size);
124  if (memcmp(dst0, dst1, BUF_SIZE))
125  fail();
126  bench_new(dst1, src1 + offset, stride, offset_val, eo, block_size, block_size);
127  }
128  }
129 }
130 
132 {
133  int bit_depth;
134 
135  for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
137 
138  ff_hevc_dsp_init(&h, bit_depth);
139  check_sao_band(h, bit_depth);
140  }
141  report("sao_band");
142 
143  for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
145 
146  ff_hevc_dsp_init(&h, bit_depth);
147  check_sao_edge(h, bit_depth);
148  }
149  report("sao_edge");
150 }
#define src
Definition: vp8dsp.c:254
#define report
Definition: checkasm.h:119
#define BUF_SIZE
Definition: hevc_sao.c:36
uint8_t
#define PIXEL_STRIDE
Definition: hevc_sao.c:35
#define height
#define SIZEOF_PIXEL
Definition: hevc_sao.c:34
#define randomize_buffers(buf0, buf1, size)
Definition: hevc_sao.c:40
static void check_sao_band(HEVCDSPContext h, int bit_depth)
Definition: hevc_sao.c:68
#define OFFSET_LENGTH
Definition: hevc_sao.c:38
uint16_t width
Definition: gdv.c:47
void(* sao_edge_filter[5])(uint8_t *_dst, uint8_t *_src, ptrdiff_t stride_dst, int16_t *sao_offset_val, int sao_eo_class, int width, int height)
Definition: hevcdsp.h:65
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
#define fail()
Definition: checkasm.h:116
static void check_sao_edge(HEVCDSPContext h, int bit_depth)
Definition: hevc_sao.c:99
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
Definition: af_astats.c:152
#define declare_func_emms(cpu_flags, ret,...)
Definition: checkasm.h:113
#define call_ref(...)
Definition: checkasm.h:122
void(* sao_band_filter[5])(uint8_t *_dst, uint8_t *_src, ptrdiff_t _stride_dst, ptrdiff_t _stride_src, int16_t *sao_offset_val, int sao_left_class, int width, int height)
Definition: hevcdsp.h:61
void ff_hevc_dsp_init(HEVCDSPContext *hevcdsp, int bit_depth)
Definition: hevcdsp.c:126
#define src1
Definition: h264pred.c:139
Libavcodec external API header.
#define AV_CPU_FLAG_MMX
standard MMX
Definition: cpu.h:31
static const uint32_t sao_size[5]
Definition: hevc_sao.c:32
#define check_func(func,...)
Definition: checkasm.h:107
#define src0
Definition: h264pred.c:138
static const uint32_t pixel_mask[3]
Definition: hevc_sao.c:31
#define LOCAL_ALIGNED_32(t, v,...)
Definition: internal.h:137
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
#define rnd()
Definition: checkasm.h:100
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:773
#define bench_new(...)
Definition: checkasm.h:249
#define randomize_buffers2(buf, size)
Definition: hevc_sao.c:51
#define call_new(...)
Definition: checkasm.h:189
void checkasm_check_hevc_sao(void)
Definition: hevc_sao.c:131