FFmpeg
dsp.c
Go to the documentation of this file.
1 /*
2  * VVC DSP
3  *
4  * Copyright (C) 2021 Nuo Mi
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "dsp.h"
24 #include "ctu.h"
25 #include "itx_1d.h"
26 
27 #define VVC_SIGN(v) (v < 0 ? -1 : !!v)
28 
29 static void av_always_inline pad_int16(int16_t *_dst, const ptrdiff_t dst_stride, const int width, const int height)
30 {
31  const int padded_width = width + 2;
32  int16_t *dst;
33  for (int y = 0; y < height; y++) {
34  dst = _dst + y * dst_stride;
35  for (int x = 0; x < width; x++) {
36  dst[-1] = dst[0];
37  dst[width] = dst[width - 1];
38  }
39  }
40 
41  _dst--;
42  //top
43  memcpy(_dst - dst_stride, _dst, padded_width * sizeof(int16_t));
44  //bottom
45  _dst += dst_stride * height;
46  memcpy(_dst, _dst - dst_stride, padded_width * sizeof(int16_t));
47 }
48 
49 static int vvc_sad(const int16_t *src0, const int16_t *src1, int dx, int dy,
50  const int block_w, const int block_h)
51 {
52  int sad = 0;
53  dx -= 2;
54  dy -= 2;
55  src0 += (2 + dy) * MAX_PB_SIZE + 2 + dx;
56  src1 += (2 - dy) * MAX_PB_SIZE + 2 - dx;
57  for (int y = 0; y < block_h; y += 2) {
58  for (int x = 0; x < block_w; x++) {
59  sad += FFABS(src0[x] - src1[x]);
60  }
61  src0 += 2 * MAX_PB_SIZE;
62  src1 += 2 * MAX_PB_SIZE;
63  }
64  return sad;
65 }
66 
67 typedef struct IntraEdgeParams {
68  uint8_t* top;
69  uint8_t* left;
71 
72  uint16_t left_array[6 * MAX_TB_SIZE + 5];
73  uint16_t filtered_left_array[6 * MAX_TB_SIZE + 5];
74  uint16_t top_array[6 * MAX_TB_SIZE + 5];
75  uint16_t filtered_top_array[6 * MAX_TB_SIZE + 5];
77 
78 #define PROF_BORDER_EXT 1
79 #define PROF_BLOCK_SIZE (AFFINE_MIN_BLOCK_SIZE + PROF_BORDER_EXT * 2)
80 #define BDOF_BORDER_EXT 1
81 
82 #define BDOF_PADDED_SIZE (16 + BDOF_BORDER_EXT * 2)
83 #define BDOF_BLOCK_SIZE 4
84 #define BDOF_GRADIENT_SIZE (BDOF_BLOCK_SIZE + BDOF_BORDER_EXT * 2)
85 
86 #define BIT_DEPTH 8
87 #include "dsp_template.c"
88 #undef BIT_DEPTH
89 
90 #define BIT_DEPTH 10
91 #include "dsp_template.c"
92 #undef BIT_DEPTH
93 
94 #define BIT_DEPTH 12
95 #include "dsp_template.c"
96 #undef BIT_DEPTH
97 
99 {
100 #undef FUNC
101 #define FUNC(a, depth) a ## _ ## depth
102 
103 #define VVC_DSP(depth) \
104  FUNC(ff_vvc_inter_dsp_init, depth)(&vvcdsp->inter); \
105  FUNC(ff_vvc_intra_dsp_init, depth)(&vvcdsp->intra); \
106  FUNC(ff_vvc_itx_dsp_init, depth)(&vvcdsp->itx); \
107  FUNC(ff_vvc_lmcs_dsp_init, depth)(&vvcdsp->lmcs); \
108  FUNC(ff_vvc_lf_dsp_init, depth)(&vvcdsp->lf); \
109  FUNC(ff_vvc_sao_dsp_init, depth)(&vvcdsp->sao); \
110  FUNC(ff_vvc_alf_dsp_init, depth)(&vvcdsp->alf); \
111 
112  switch (bit_depth) {
113  case 12:
114  VVC_DSP(12);
115  break;
116  case 10:
117  VVC_DSP(10);
118  break;
119  default:
120  VVC_DSP(8);
121  break;
122  }
123 
124 #if ARCH_X86
126 #endif
127 }
IntraEdgeParams::top_array
uint16_t top_array[6 *MAX_TB_SIZE+5]
Definition: dsp.c:74
dsp.h
src1
const pixel * src1
Definition: h264pred_template.c:421
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:246
IntraEdgeParams::left
uint8_t * left
Definition: dsp.c:69
width
#define width
ff_vvc_dsp_init
void ff_vvc_dsp_init(VVCDSPContext *vvcdsp, int bit_depth)
Definition: dsp.c:98
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:73
VVC_DSP
#define VVC_DSP(depth)
ff_vvc_dsp_init_x86
void ff_vvc_dsp_init_x86(VVCDSPContext *hpc, const int bit_depth)
Definition: vvcdsp_init.c:257
IntraEdgeParams::filtered_top_array
uint16_t filtered_top_array[6 *MAX_TB_SIZE+5]
Definition: dsp.c:75
IntraEdgeParams::top
uint8_t * top
Definition: dsp.c:68
IntraEdgeParams::filtered_left_array
uint16_t filtered_left_array[6 *MAX_TB_SIZE+5]
Definition: dsp.c:73
pad_int16
static void av_always_inline pad_int16(int16_t *_dst, const ptrdiff_t dst_stride, const int width, const int height)
Definition: dsp.c:29
IntraEdgeParams::left_array
uint16_t left_array[6 *MAX_TB_SIZE+5]
Definition: dsp.c:72
vvc_sad
static int vvc_sad(const int16_t *src0, const int16_t *src1, int dx, int dy, const int block_w, const int block_h)
Definition: dsp.c:49
dsp_template.c
height
#define height
IntraEdgeParams
Definition: dsp.c:67
itx_1d.h
MAX_PB_SIZE
#define MAX_PB_SIZE
Definition: hevcdsp.h:32
av_always_inline
#define av_always_inline
Definition: attributes.h:49
IntraEdgeParams::filter_flag
int filter_flag
Definition: dsp.c:70
src0
const pixel *const src0
Definition: h264pred_template.c:420
MAX_TB_SIZE
#define MAX_TB_SIZE
Definition: hevcdec.h:48
ctu.h
VVCDSPContext
Definition: dsp.h:158