FFmpeg
dsp.c
Go to the documentation of this file.
1 /*
2  * HEVC video decoder
3  *
4  * Copyright (C) 2012 - 2013 Guillaume Martres
5  * Copyright (C) 2013 - 2014 Pierre-Edouard Lepere
6  *
7  *
8  * This file is part of FFmpeg.
9  *
10  * FFmpeg is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * FFmpeg is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with FFmpeg; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  */
24 
25 #include "dsp.h"
26 
27 static const int8_t transform[32][32] = {
28  { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
29  64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 },
30  { 90, 90, 88, 85, 82, 78, 73, 67, 61, 54, 46, 38, 31, 22, 13, 4,
31  -4, -13, -22, -31, -38, -46, -54, -61, -67, -73, -78, -82, -85, -88, -90, -90 },
32  { 90, 87, 80, 70, 57, 43, 25, 9, -9, -25, -43, -57, -70, -80, -87, -90,
33  -90, -87, -80, -70, -57, -43, -25, -9, 9, 25, 43, 57, 70, 80, 87, 90 },
34  { 90, 82, 67, 46, 22, -4, -31, -54, -73, -85, -90, -88, -78, -61, -38, -13,
35  13, 38, 61, 78, 88, 90, 85, 73, 54, 31, 4, -22, -46, -67, -82, -90 },
36  { 89, 75, 50, 18, -18, -50, -75, -89, -89, -75, -50, -18, 18, 50, 75, 89,
37  89, 75, 50, 18, -18, -50, -75, -89, -89, -75, -50, -18, 18, 50, 75, 89 },
38  { 88, 67, 31, -13, -54, -82, -90, -78, -46, -4, 38, 73, 90, 85, 61, 22,
39  -22, -61, -85, -90, -73, -38, 4, 46, 78, 90, 82, 54, 13, -31, -67, -88 },
40  { 87, 57, 9, -43, -80, -90, -70, -25, 25, 70, 90, 80, 43, -9, -57, -87,
41  -87, -57, -9, 43, 80, 90, 70, 25, -25, -70, -90, -80, -43, 9, 57, 87 },
42  { 85, 46, -13, -67, -90, -73, -22, 38, 82, 88, 54, -4, -61, -90, -78, -31,
43  31, 78, 90, 61, 4, -54, -88, -82, -38, 22, 73, 90, 67, 13, -46, -85 },
44  { 83, 36, -36, -83, -83, -36, 36, 83, 83, 36, -36, -83, -83, -36, 36, 83,
45  83, 36, -36, -83, -83, -36, 36, 83, 83, 36, -36, -83, -83, -36, 36, 83 },
46  { 82, 22, -54, -90, -61, 13, 78, 85, 31, -46, -90, -67, 4, 73, 88, 38,
47  -38, -88, -73, -4, 67, 90, 46, -31, -85, -78, -13, 61, 90, 54, -22, -82 },
48  { 80, 9, -70, -87, -25, 57, 90, 43, -43, -90, -57, 25, 87, 70, -9, -80,
49  -80, -9, 70, 87, 25, -57, -90, -43, 43, 90, 57, -25, -87, -70, 9, 80 },
50  { 78, -4, -82, -73, 13, 85, 67, -22, -88, -61, 31, 90, 54, -38, -90, -46,
51  46, 90, 38, -54, -90, -31, 61, 88, 22, -67, -85, -13, 73, 82, 4, -78 },
52  { 75, -18, -89, -50, 50, 89, 18, -75, -75, 18, 89, 50, -50, -89, -18, 75,
53  75, -18, -89, -50, 50, 89, 18, -75, -75, 18, 89, 50, -50, -89, -18, 75 },
54  { 73, -31, -90, -22, 78, 67, -38, -90, -13, 82, 61, -46, -88, -4, 85, 54,
55  -54, -85, 4, 88, 46, -61, -82, 13, 90, 38, -67, -78, 22, 90, 31, -73 },
56  { 70, -43, -87, 9, 90, 25, -80, -57, 57, 80, -25, -90, -9, 87, 43, -70,
57  -70, 43, 87, -9, -90, -25, 80, 57, -57, -80, 25, 90, 9, -87, -43, 70 },
58  { 67, -54, -78, 38, 85, -22, -90, 4, 90, 13, -88, -31, 82, 46, -73, -61,
59  61, 73, -46, -82, 31, 88, -13, -90, -4, 90, 22, -85, -38, 78, 54, -67 },
60  { 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64,
61  64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64 },
62  { 61, -73, -46, 82, 31, -88, -13, 90, -4, -90, 22, 85, -38, -78, 54, 67,
63  -67, -54, 78, 38, -85, -22, 90, 4, -90, 13, 88, -31, -82, 46, 73, -61 },
64  { 57, -80, -25, 90, -9, -87, 43, 70, -70, -43, 87, 9, -90, 25, 80, -57,
65  -57, 80, 25, -90, 9, 87, -43, -70, 70, 43, -87, -9, 90, -25, -80, 57 },
66  { 54, -85, -4, 88, -46, -61, 82, 13, -90, 38, 67, -78, -22, 90, -31, -73,
67  73, 31, -90, 22, 78, -67, -38, 90, -13, -82, 61, 46, -88, 4, 85, -54 },
68  { 50, -89, 18, 75, -75, -18, 89, -50, -50, 89, -18, -75, 75, 18, -89, 50,
69  50, -89, 18, 75, -75, -18, 89, -50, -50, 89, -18, -75, 75, 18, -89, 50 },
70  { 46, -90, 38, 54, -90, 31, 61, -88, 22, 67, -85, 13, 73, -82, 4, 78,
71  -78, -4, 82, -73, -13, 85, -67, -22, 88, -61, -31, 90, -54, -38, 90, -46 },
72  { 43, -90, 57, 25, -87, 70, 9, -80, 80, -9, -70, 87, -25, -57, 90, -43,
73  -43, 90, -57, -25, 87, -70, -9, 80, -80, 9, 70, -87, 25, 57, -90, 43 },
74  { 38, -88, 73, -4, -67, 90, -46, -31, 85, -78, 13, 61, -90, 54, 22, -82,
75  82, -22, -54, 90, -61, -13, 78, -85, 31, 46, -90, 67, 4, -73, 88, -38 },
76  { 36, -83, 83, -36, -36, 83, -83, 36, 36, -83, 83, -36, -36, 83, -83, 36,
77  36, -83, 83, -36, -36, 83, -83, 36, 36, -83, 83, -36, -36, 83, -83, 36 },
78  { 31, -78, 90, -61, 4, 54, -88, 82, -38, -22, 73, -90, 67, -13, -46, 85,
79  -85, 46, 13, -67, 90, -73, 22, 38, -82, 88, -54, -4, 61, -90, 78, -31 },
80  { 25, -70, 90, -80, 43, 9, -57, 87, -87, 57, -9, -43, 80, -90, 70, -25,
81  -25, 70, -90, 80, -43, -9, 57, -87, 87, -57, 9, 43, -80, 90, -70, 25 },
82  { 22, -61, 85, -90, 73, -38, -4, 46, -78, 90, -82, 54, -13, -31, 67, -88,
83  88, -67, 31, 13, -54, 82, -90, 78, -46, 4, 38, -73, 90, -85, 61, -22 },
84  { 18, -50, 75, -89, 89, -75, 50, -18, -18, 50, -75, 89, -89, 75, -50, 18,
85  18, -50, 75, -89, 89, -75, 50, -18, -18, 50, -75, 89, -89, 75, -50, 18 },
86  { 13, -38, 61, -78, 88, -90, 85, -73, 54, -31, 4, 22, -46, 67, -82, 90,
87  -90, 82, -67, 46, -22, -4, 31, -54, 73, -85, 90, -88, 78, -61, 38, -13 },
88  { 9, -25, 43, -57, 70, -80, 87, -90, 90, -87, 80, -70, 57, -43, 25, -9,
89  -9, 25, -43, 57, -70, 80, -87, 90, -90, 87, -80, 70, -57, 43, -25, 9 },
90  { 4, -13, 22, -31, 38, -46, 54, -61, 67, -73, 78, -82, 85, -88, 90, -90,
91  90, -90, 88, -85, 82, -78, 73, -67, 61, -54, 46, -38, 31, -22, 13, -4 },
92 };
93 
94 DECLARE_ALIGNED(16, const int8_t, ff_hevc_epel_filters)[8][4] = {
95  { 0 },
96  { -2, 58, 10, -2},
97  { -4, 54, 16, -2},
98  { -6, 46, 28, -4},
99  { -4, 36, 36, -4},
100  { -4, 28, 46, -6},
101  { -2, 16, 54, -4},
102  { -2, 10, 58, -2},
103 };
104 
105 DECLARE_ALIGNED(16, const int8_t, ff_hevc_qpel_filters)[4][16] = {
106  { 0 },
107  { -1, 4,-10, 58, 17, -5, 1, 0, -1, 4,-10, 58, 17, -5, 1, 0},
108  { -1, 4,-11, 40, 40,-11, 4, -1, -1, 4,-11, 40, 40,-11, 4, -1},
109  { 0, 1, -5, 17, 58,-10, 4, -1, 0, 1, -5, 17, 58,-10, 4, -1}
110 };
111 
112 #define BIT_DEPTH 8
113 #include "dsp_template.c"
114 #undef BIT_DEPTH
115 
116 #define BIT_DEPTH 9
117 #include "dsp_template.c"
118 #undef BIT_DEPTH
119 
120 #define BIT_DEPTH 10
121 #include "dsp_template.c"
122 #undef BIT_DEPTH
123 
124 #define BIT_DEPTH 12
125 #include "dsp_template.c"
126 #undef BIT_DEPTH
127 
129 {
130 #undef FUNC
131 #define FUNC(a, depth) a ## _ ## depth
132 
133 #undef PEL_FUNC
134 #define PEL_FUNC(dst1, idx1, idx2, a, depth) \
135  for(i = 0 ; i < 10 ; i++) \
136 { \
137  hevcdsp->dst1[i][idx1][idx2] = a ## _ ## depth; \
138 }
139 
140 #undef EPEL_FUNCS
141 #define EPEL_FUNCS(depth) \
142  PEL_FUNC(put_hevc_epel, 0, 0, put_hevc_pel_pixels, depth); \
143  PEL_FUNC(put_hevc_epel, 0, 1, put_hevc_epel_h, depth); \
144  PEL_FUNC(put_hevc_epel, 1, 0, put_hevc_epel_v, depth); \
145  PEL_FUNC(put_hevc_epel, 1, 1, put_hevc_epel_hv, depth)
146 
147 #undef EPEL_UNI_FUNCS
148 #define EPEL_UNI_FUNCS(depth) \
149  PEL_FUNC(put_hevc_epel_uni, 0, 0, put_hevc_pel_uni_pixels, depth); \
150  PEL_FUNC(put_hevc_epel_uni, 0, 1, put_hevc_epel_uni_h, depth); \
151  PEL_FUNC(put_hevc_epel_uni, 1, 0, put_hevc_epel_uni_v, depth); \
152  PEL_FUNC(put_hevc_epel_uni, 1, 1, put_hevc_epel_uni_hv, depth); \
153  PEL_FUNC(put_hevc_epel_uni_w, 0, 0, put_hevc_pel_uni_w_pixels, depth); \
154  PEL_FUNC(put_hevc_epel_uni_w, 0, 1, put_hevc_epel_uni_w_h, depth); \
155  PEL_FUNC(put_hevc_epel_uni_w, 1, 0, put_hevc_epel_uni_w_v, depth); \
156  PEL_FUNC(put_hevc_epel_uni_w, 1, 1, put_hevc_epel_uni_w_hv, depth)
157 
158 #undef EPEL_BI_FUNCS
159 #define EPEL_BI_FUNCS(depth) \
160  PEL_FUNC(put_hevc_epel_bi, 0, 0, put_hevc_pel_bi_pixels, depth); \
161  PEL_FUNC(put_hevc_epel_bi, 0, 1, put_hevc_epel_bi_h, depth); \
162  PEL_FUNC(put_hevc_epel_bi, 1, 0, put_hevc_epel_bi_v, depth); \
163  PEL_FUNC(put_hevc_epel_bi, 1, 1, put_hevc_epel_bi_hv, depth); \
164  PEL_FUNC(put_hevc_epel_bi_w, 0, 0, put_hevc_pel_bi_w_pixels, depth); \
165  PEL_FUNC(put_hevc_epel_bi_w, 0, 1, put_hevc_epel_bi_w_h, depth); \
166  PEL_FUNC(put_hevc_epel_bi_w, 1, 0, put_hevc_epel_bi_w_v, depth); \
167  PEL_FUNC(put_hevc_epel_bi_w, 1, 1, put_hevc_epel_bi_w_hv, depth)
168 
169 #undef QPEL_FUNCS
170 #define QPEL_FUNCS(depth) \
171  PEL_FUNC(put_hevc_qpel, 0, 0, put_hevc_pel_pixels, depth); \
172  PEL_FUNC(put_hevc_qpel, 0, 1, put_hevc_qpel_h, depth); \
173  PEL_FUNC(put_hevc_qpel, 1, 0, put_hevc_qpel_v, depth); \
174  PEL_FUNC(put_hevc_qpel, 1, 1, put_hevc_qpel_hv, depth)
175 
176 #undef QPEL_UNI_FUNCS
177 #define QPEL_UNI_FUNCS(depth) \
178  PEL_FUNC(put_hevc_qpel_uni, 0, 0, put_hevc_pel_uni_pixels, depth); \
179  PEL_FUNC(put_hevc_qpel_uni, 0, 1, put_hevc_qpel_uni_h, depth); \
180  PEL_FUNC(put_hevc_qpel_uni, 1, 0, put_hevc_qpel_uni_v, depth); \
181  PEL_FUNC(put_hevc_qpel_uni, 1, 1, put_hevc_qpel_uni_hv, depth); \
182  PEL_FUNC(put_hevc_qpel_uni_w, 0, 0, put_hevc_pel_uni_w_pixels, depth); \
183  PEL_FUNC(put_hevc_qpel_uni_w, 0, 1, put_hevc_qpel_uni_w_h, depth); \
184  PEL_FUNC(put_hevc_qpel_uni_w, 1, 0, put_hevc_qpel_uni_w_v, depth); \
185  PEL_FUNC(put_hevc_qpel_uni_w, 1, 1, put_hevc_qpel_uni_w_hv, depth)
186 
187 #undef QPEL_BI_FUNCS
188 #define QPEL_BI_FUNCS(depth) \
189  PEL_FUNC(put_hevc_qpel_bi, 0, 0, put_hevc_pel_bi_pixels, depth); \
190  PEL_FUNC(put_hevc_qpel_bi, 0, 1, put_hevc_qpel_bi_h, depth); \
191  PEL_FUNC(put_hevc_qpel_bi, 1, 0, put_hevc_qpel_bi_v, depth); \
192  PEL_FUNC(put_hevc_qpel_bi, 1, 1, put_hevc_qpel_bi_hv, depth); \
193  PEL_FUNC(put_hevc_qpel_bi_w, 0, 0, put_hevc_pel_bi_w_pixels, depth); \
194  PEL_FUNC(put_hevc_qpel_bi_w, 0, 1, put_hevc_qpel_bi_w_h, depth); \
195  PEL_FUNC(put_hevc_qpel_bi_w, 1, 0, put_hevc_qpel_bi_w_v, depth); \
196  PEL_FUNC(put_hevc_qpel_bi_w, 1, 1, put_hevc_qpel_bi_w_hv, depth)
197 
198 #define HEVC_DSP(depth) \
199  hevcdsp->put_pcm = FUNC(put_pcm, depth); \
200  hevcdsp->add_residual[0] = FUNC(add_residual4x4, depth); \
201  hevcdsp->add_residual[1] = FUNC(add_residual8x8, depth); \
202  hevcdsp->add_residual[2] = FUNC(add_residual16x16, depth); \
203  hevcdsp->add_residual[3] = FUNC(add_residual32x32, depth); \
204  hevcdsp->dequant = FUNC(dequant, depth); \
205  hevcdsp->transform_rdpcm = FUNC(transform_rdpcm, depth); \
206  hevcdsp->transform_4x4_luma = FUNC(transform_4x4_luma, depth); \
207  hevcdsp->idct[0] = FUNC(idct_4x4, depth); \
208  hevcdsp->idct[1] = FUNC(idct_8x8, depth); \
209  hevcdsp->idct[2] = FUNC(idct_16x16, depth); \
210  hevcdsp->idct[3] = FUNC(idct_32x32, depth); \
211  \
212  hevcdsp->idct_dc[0] = FUNC(idct_4x4_dc, depth); \
213  hevcdsp->idct_dc[1] = FUNC(idct_8x8_dc, depth); \
214  hevcdsp->idct_dc[2] = FUNC(idct_16x16_dc, depth); \
215  hevcdsp->idct_dc[3] = FUNC(idct_32x32_dc, depth); \
216  \
217  hevcdsp->sao_band_filter[0] = \
218  hevcdsp->sao_band_filter[1] = \
219  hevcdsp->sao_band_filter[2] = \
220  hevcdsp->sao_band_filter[3] = \
221  hevcdsp->sao_band_filter[4] = FUNC(sao_band_filter, depth); \
222  hevcdsp->sao_edge_filter[0] = \
223  hevcdsp->sao_edge_filter[1] = \
224  hevcdsp->sao_edge_filter[2] = \
225  hevcdsp->sao_edge_filter[3] = \
226  hevcdsp->sao_edge_filter[4] = FUNC(sao_edge_filter, depth); \
227  hevcdsp->sao_edge_restore[0] = FUNC(sao_edge_restore_0, depth); \
228  hevcdsp->sao_edge_restore[1] = FUNC(sao_edge_restore_1, depth); \
229  \
230  QPEL_FUNCS(depth); \
231  QPEL_UNI_FUNCS(depth); \
232  QPEL_BI_FUNCS(depth); \
233  EPEL_FUNCS(depth); \
234  EPEL_UNI_FUNCS(depth); \
235  EPEL_BI_FUNCS(depth); \
236  \
237  hevcdsp->hevc_h_loop_filter_luma = FUNC(hevc_h_loop_filter_luma, depth); \
238  hevcdsp->hevc_v_loop_filter_luma = FUNC(hevc_v_loop_filter_luma, depth); \
239  hevcdsp->hevc_h_loop_filter_chroma = FUNC(hevc_h_loop_filter_chroma, depth); \
240  hevcdsp->hevc_v_loop_filter_chroma = FUNC(hevc_v_loop_filter_chroma, depth); \
241  hevcdsp->hevc_h_loop_filter_luma_c = FUNC(hevc_h_loop_filter_luma, depth); \
242  hevcdsp->hevc_v_loop_filter_luma_c = FUNC(hevc_v_loop_filter_luma, depth); \
243  hevcdsp->hevc_h_loop_filter_chroma_c = FUNC(hevc_h_loop_filter_chroma, depth); \
244  hevcdsp->hevc_v_loop_filter_chroma_c = FUNC(hevc_v_loop_filter_chroma, depth)
245 int i = 0;
246 
247  switch (bit_depth) {
248  case 9:
249  HEVC_DSP(9);
250  break;
251  case 10:
252  HEVC_DSP(10);
253  break;
254  case 12:
255  HEVC_DSP(12);
256  break;
257  default:
258  HEVC_DSP(8);
259  break;
260  }
261 
262 #if ARCH_AARCH64
264 #elif ARCH_ARM
266 #elif ARCH_PPC
268 #elif ARCH_X86
270 #elif ARCH_MIPS
272 #elif ARCH_LOONGARCH
274 #endif
275 }
ff_hevc_dsp_init
void ff_hevc_dsp_init(HEVCDSPContext *hevcdsp, int bit_depth)
Definition: dsp.c:128
ff_hevc_epel_filters
const int8_t ff_hevc_epel_filters[8][4]
ff_hevc_.pel_filters[0] are dummies to simplify array addressing
Definition: dsp.c:94
HEVC_DSP
#define HEVC_DSP(depth)
dsp_template.c
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:246
ff_hevc_dsp_init_x86
void ff_hevc_dsp_init_x86(HEVCDSPContext *c, const int bit_depth)
Definition: hevcdsp_init.c:806
ff_hevc_dsp_init_loongarch
void ff_hevc_dsp_init_loongarch(HEVCDSPContext *c, const int bit_depth)
Definition: hevcdsp_init_loongarch.c:27
ff_hevc_dsp_init_arm
av_cold void ff_hevc_dsp_init_arm(HEVCDSPContext *c, const int bit_depth)
Definition: hevcdsp_init_arm.c:28
transform
static const int8_t transform[32][32]
Definition: dsp.c:27
ff_hevc_qpel_filters
const int8_t ff_hevc_qpel_filters[4][16]
Definition: dsp.c:105
dsp.h
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:109
HEVCDSPContext
Definition: dsp.h:47
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ff_hevc_dsp_init_aarch64
av_cold void ff_hevc_dsp_init_aarch64(HEVCDSPContext *c, const int bit_depth)
Definition: hevcdsp_init_aarch64.c:133
ff_hevc_dsp_init_ppc
void ff_hevc_dsp_init_ppc(HEVCDSPContext *c, const int bit_depth)
Definition: hevcdsp.c:110
ff_hevc_dsp_init_mips
void ff_hevc_dsp_init_mips(HEVCDSPContext *c, const int bit_depth)
Definition: hevcdsp_init_mips.c:24