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 int vvc_sad(const int16_t *src0, const int16_t *src1, int dx, int dy,
30  const int block_w, const int block_h)
31 {
32  int sad = 0;
33  dx -= 2;
34  dy -= 2;
35  src0 += (2 + dy) * MAX_PB_SIZE + 2 + dx;
36  src1 += (2 - dy) * MAX_PB_SIZE + 2 - dx;
37  for (int y = 0; y < block_h; y += 2) {
38  for (int x = 0; x < block_w; x++) {
39  sad += FFABS(src0[x] - src1[x]);
40  }
41  src0 += 2 * MAX_PB_SIZE;
42  src1 += 2 * MAX_PB_SIZE;
43  }
44  return sad;
45 }
46 
47 static av_always_inline void unpack_mip_info(int *intra_mip_transposed_flag,
48  int *intra_mip_mode, const uint8_t mip_info)
49 {
50  if (intra_mip_transposed_flag)
51  *intra_mip_transposed_flag = (mip_info >> 1) & 0x1;
52  if (intra_mip_mode)
53  *intra_mip_mode = (mip_info >> 2) & 0xf;
54 }
55 
56 typedef struct IntraEdgeParams {
57  uint8_t* top;
58  uint8_t* left;
60 
61  uint16_t left_array[6 * MAX_TB_SIZE + 5];
62  uint16_t filtered_left_array[6 * MAX_TB_SIZE + 5];
63  uint16_t top_array[6 * MAX_TB_SIZE + 5];
64  uint16_t filtered_top_array[6 * MAX_TB_SIZE + 5];
66 
67 #define PROF_BORDER_EXT 1
68 #define PROF_BLOCK_SIZE (AFFINE_MIN_BLOCK_SIZE + PROF_BORDER_EXT * 2)
69 
70 #define BDOF_BORDER_EXT 1
71 #define BDOF_BLOCK_SIZE 16
72 #define BDOF_MIN_BLOCK_SIZE 4
73 
74 #define BIT_DEPTH 8
75 #include "dsp_template.c"
76 #undef BIT_DEPTH
77 
78 #define BIT_DEPTH 10
79 #include "dsp_template.c"
80 #undef BIT_DEPTH
81 
82 #define BIT_DEPTH 12
83 #include "dsp_template.c"
84 #undef BIT_DEPTH
85 
87 {
88 #undef FUNC
89 #define FUNC(a, depth) a ## _ ## depth
90 
91 #define VVC_DSP(depth) \
92  FUNC(ff_vvc_inter_dsp_init, depth)(&vvcdsp->inter); \
93  FUNC(ff_vvc_intra_dsp_init, depth)(&vvcdsp->intra); \
94  FUNC(ff_vvc_itx_dsp_init, depth)(&vvcdsp->itx); \
95  FUNC(ff_vvc_lmcs_dsp_init, depth)(&vvcdsp->lmcs); \
96  FUNC(ff_vvc_lf_dsp_init, depth)(&vvcdsp->lf); \
97  FUNC(ff_vvc_sao_dsp_init, depth)(&vvcdsp->sao); \
98  FUNC(ff_vvc_alf_dsp_init, depth)(&vvcdsp->alf); \
99 
100  switch (bit_depth) {
101  case 12:
102  VVC_DSP(12);
103  break;
104  case 10:
105  VVC_DSP(10);
106  break;
107  default:
108  VVC_DSP(8);
109  break;
110  }
111 
112 #if ARCH_AARCH64
114 #elif ARCH_RISCV
116 #elif ARCH_X86
118 #endif
119 }
IntraEdgeParams::top_array
uint16_t top_array[6 *MAX_TB_SIZE+5]
Definition: dsp.c:63
src1
const pixel * src1
Definition: h264pred_template.c:421
VVC_DSP
#define VVC_DSP(depth)
ff_vvc_dsp_init_aarch64
void ff_vvc_dsp_init_aarch64(VVCDSPContext *const c, const int bd)
Definition: dsp_init.c:117
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:29
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:58
dsp_template.c
dsp.h
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:74
ff_vvc_dsp_init_x86
void ff_vvc_dsp_init_x86(VVCDSPContext *hpc, const int bit_depth)
Definition: dsp_init.c:374
IntraEdgeParams::filtered_top_array
uint16_t filtered_top_array[6 *MAX_TB_SIZE+5]
Definition: dsp.c:64
IntraEdgeParams::top
uint8_t * top
Definition: dsp.c:57
IntraEdgeParams::filtered_left_array
uint16_t filtered_left_array[6 *MAX_TB_SIZE+5]
Definition: dsp.c:62
IntraEdgeParams::left_array
uint16_t left_array[6 *MAX_TB_SIZE+5]
Definition: dsp.c:61
unpack_mip_info
static av_always_inline void unpack_mip_info(int *intra_mip_transposed_flag, int *intra_mip_mode, const uint8_t mip_info)
Definition: dsp.c:47
ff_vvc_dsp_init
void ff_vvc_dsp_init(VVCDSPContext *vvcdsp, int bit_depth)
Definition: dsp.c:86
IntraEdgeParams
Definition: dsp.c:56
itx_1d.h
xf
#define xf(width, name, var, range_min, range_max, subs,...)
Definition: cbs_av1.c:598
av_always_inline
#define av_always_inline
Definition: attributes.h:49
MAX_PB_SIZE
#define MAX_PB_SIZE
Definition: dsp.h:32
IntraEdgeParams::filter_flag
int filter_flag
Definition: dsp.c:59
ff_vvc_dsp_init_riscv
void ff_vvc_dsp_init_riscv(VVCDSPContext *const c, const int bd)
Definition: dsp_init.c:82
src0
const pixel *const src0
Definition: h264pred_template.c:420
MAX_TB_SIZE
#define MAX_TB_SIZE
Definition: hevcdec.h:49
ctu.h
VVCDSPContext
Definition: dsp.h:169