Showing the changes to libavcodec (3 of 3 files). Show all
Unified · Split
| @@ -1,7 +1,8 @@ | |||
| 1 | clean:: | 1 | clean:: |
| 2 | $(RM) $(CLEANSUFFIXES:%=libavcodec/vvc/%) | 2 | $(RM) $(CLEANSUFFIXES:%=libavcodec/vvc/%) |
| 3 | 3 | ||
| 4 | OBJS-$(CONFIG_VVC_DECODER) += vvc/vvc_cabac.o \ | 4 | OBJS-$(CONFIG_VVC_DECODER) += vvc/vvcdsp.o \ |
| 5 | vvc/vvc_cabac.o \ | ||
| 5 | vvc/vvc_ctu.o \ | 6 | vvc/vvc_ctu.o \ |
| 6 | vvc/vvc_data.o \ | 7 | vvc/vvc_data.o \ |
| 7 | vvc/vvc_filter.o \ | 8 | vvc/vvc_filter.o \ |
| @@ -0,0 +1,141 @@ | |||
| 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 "vvcdsp.h" | ||
| 24 | #include "vvc_ctu.h" | ||
| 25 | #include "vvc_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 | #define itx_fn(type, s) \ | ||
| 68 | static void itx_##type##_##s(int *coeffs, ptrdiff_t step, size_t nz) \ | ||
| 69 | { \ | ||
| 70 | ff_vvc_inv_##type##_##s(coeffs, step, nz); \ | ||
| 71 | } | ||
| 72 | |||
| 73 | #define itx_fn_common(type) \ | ||
| 74 | itx_fn(type, 4); \ | ||
| 75 | itx_fn(type, 8); \ | ||
| 76 | itx_fn(type, 16); \ | ||
| 77 | itx_fn(type, 32); \ | ||
| 78 | |||
| 79 | itx_fn_common(dct2); | ||
| 80 | itx_fn_common(dst7); | ||
| 81 | itx_fn_common(dct8); | ||
| 82 | itx_fn(dct2, 2); | ||
| 83 | itx_fn(dct2, 64); | ||
| 84 | |||
| 85 | typedef struct IntraEdgeParams { | ||
| 86 | uint8_t* top; | ||
| 87 | uint8_t* left; | ||
| 88 | int filter_flag; | ||
| 89 | |||
| 90 | uint16_t left_array[3 * MAX_TB_SIZE + 3]; | ||
| 91 | uint16_t filtered_left_array[3 * MAX_TB_SIZE + 3]; | ||
| 92 | uint16_t top_array[3 * MAX_TB_SIZE + 3]; | ||
| 93 | uint16_t filtered_top_array[3 * MAX_TB_SIZE + 3]; | ||
| 94 | } IntraEdgeParams; | ||
| 95 | |||
| 96 | #define PROF_BORDER_EXT 1 | ||
| 97 | #define PROF_BLOCK_SIZE (AFFINE_MIN_BLOCK_SIZE + PROF_BORDER_EXT * 2) | ||
| 98 | #define BDOF_BORDER_EXT 1 | ||
| 99 | |||
| 100 | #define BDOF_PADDED_SIZE (16 + BDOF_BORDER_EXT * 2) | ||
| 101 | #define BDOF_BLOCK_SIZE 4 | ||
| 102 | #define BDOF_GRADIENT_SIZE (BDOF_BLOCK_SIZE + BDOF_BORDER_EXT * 2) | ||
| 103 | |||
| 104 | #define BIT_DEPTH 8 | ||
| 105 | #include "vvcdsp_template.c" | ||
| 106 | #undef BIT_DEPTH | ||
| 107 | |||
| 108 | #define BIT_DEPTH 10 | ||
| 109 | #include "vvcdsp_template.c" | ||
| 110 | #undef BIT_DEPTH | ||
| 111 | |||
| 112 | #define BIT_DEPTH 12 | ||
| 113 | #include "vvcdsp_template.c" | ||
| 114 | #undef BIT_DEPTH | ||
| 115 | |||
| 116 | void ff_vvc_dsp_init(VVCDSPContext *vvcdsp, int bit_depth) | ||
| 117 | { | ||
| 118 | #undef FUNC | ||
| 119 | #define FUNC(a, depth) a ## _ ## depth | ||
| 120 | |||
| 121 | #define VVC_DSP(depth) \ | ||
| 122 | FUNC(ff_vvc_inter_dsp_init, depth)(&vvcdsp->inter); \ | ||
| 123 | FUNC(ff_vvc_intra_dsp_init, depth)(&vvcdsp->intra); \ | ||
| 124 | FUNC(ff_vvc_itx_dsp_init, depth)(&vvcdsp->itx); \ | ||
| 125 | FUNC(ff_vvc_lmcs_dsp_init, depth)(&vvcdsp->lmcs); \ | ||
| 126 | FUNC(ff_vvc_lf_dsp_init, depth)(&vvcdsp->lf); \ | ||
| 127 | FUNC(ff_vvc_sao_dsp_init, depth)(&vvcdsp->sao); \ | ||
| 128 | FUNC(ff_vvc_alf_dsp_init, depth)(&vvcdsp->alf); \ | ||
| 129 | |||
| 130 | switch (bit_depth) { | ||
| 131 | case 12: | ||
| 132 | VVC_DSP(12); | ||
| 133 | break; | ||
| 134 | case 10: | ||
| 135 | VVC_DSP(10); | ||
| 136 | break; | ||
| 137 | default: | ||
| 138 | VVC_DSP(8); | ||
| 139 | break; | ||
| 140 | } | ||
| 141 | } | ||
| @@ -0,0 +1,120 @@ | |||
| 1 | /* | ||
| 2 | * VVC transform and residual 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 | #include "libavutil/frame.h" | ||
| 23 | #include "libavcodec/bit_depth_template.c" | ||
| 24 | |||
| 25 | #include "vvcdec.h" | ||
| 26 | #include "vvc_data.h" | ||
| 27 | |||
| 28 | #include "vvc_inter_template.c" | ||
| 29 | #include "vvc_intra_template.c" | ||
| 30 | #include "vvc_filter_template.c" | ||
| 31 | |||
| 32 | static void FUNC(add_residual)(uint8_t *_dst, const int *res, | ||
| 33 | const int w, const int h, const ptrdiff_t _stride) | ||
| 34 | { | ||
| 35 | pixel *dst = (pixel *)_dst; | ||
| 36 | |||
| 37 | const int stride = _stride / sizeof(pixel); | ||
| 38 | |||
| 39 | for (int y = 0; y < h; y++) { | ||
| 40 | for (int x = 0; x < w; x++) { | ||
| 41 | dst[x] = av_clip_pixel(dst[x] + *res); | ||
| 42 | res++; | ||
| 43 | } | ||
| 44 | dst += stride; | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | static void FUNC(add_residual_joint)(uint8_t *_dst, const int *res, | ||
| 49 | const int w, const int h, const ptrdiff_t _stride, const int c_sign, const int shift) | ||
| 50 | { | ||
| 51 | pixel *dst = (pixel *)_dst; | ||
| 52 | |||
| 53 | const int stride = _stride / sizeof(pixel); | ||
| 54 | |||
| 55 | for (int y = 0; y < h; y++) { | ||
| 56 | for (int x = 0; x < w; x++) { | ||
| 57 | const int r = ((*res) * c_sign) >> shift; | ||
| 58 | dst[x] = av_clip_pixel(dst[x] + r); | ||
| 59 | res++; | ||
| 60 | } | ||
| 61 | dst += stride; | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | static void FUNC(pred_residual_joint)(int *buf, const int w, const int h, | ||
| 66 | const int c_sign, const int shift) | ||
| 67 | { | ||
| 68 | for (int y = 0; y < h; y++) { | ||
| 69 | for (int x = 0; x < w; x++) { | ||
| 70 | *buf = ((*buf) * c_sign) >> shift; | ||
| 71 | buf++; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | static void FUNC(transform_bdpcm)(int *coeffs, const int width, const int height, | ||
| 77 | const int vertical, const int log2_transform_range) | ||
| 78 | { | ||
| 79 | int x, y; | ||
| 80 | |||
| 81 | if (vertical) { | ||
| 82 | coeffs += width; | ||
| 83 | for (y = 0; y < height - 1; y++) { | ||
| 84 | for (x = 0; x < width; x++) | ||
| 85 | coeffs[x] = av_clip_intp2(coeffs[x] + coeffs[x - width], log2_transform_range); | ||
| 86 | coeffs += width; | ||
| 87 | } | ||
| 88 | } else { | ||
| 89 | for (y = 0; y < height; y++) { | ||
| 90 | for (x = 1; x < width; x++) | ||
| 91 | coeffs[x] = av_clip_intp2(coeffs[x] + coeffs[x - 1], log2_transform_range); | ||
| 92 | coeffs += width; | ||
| 93 | } | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | static void FUNC(ff_vvc_itx_dsp_init)(VVCItxDSPContext *const itx) | ||
| 98 | { | ||
| 99 | #define VVC_ITX(TYPE, type, s) \ | ||
| 100 | itx->itx[TYPE][TX_SIZE_##s] = itx_##type##_##s; \ | ||
| 101 | |||
| 102 | #define VVC_ITX_COMMON(TYPE, type) \ | ||
| 103 | VVC_ITX(TYPE, type, 4); \ | ||
| 104 | VVC_ITX(TYPE, type, 8); \ | ||
| 105 | VVC_ITX(TYPE, type, 16); \ | ||
| 106 | VVC_ITX(TYPE, type, 32); | ||
| 107 | |||
| 108 | itx->add_residual = FUNC(add_residual); | ||
| 109 | itx->add_residual_joint = FUNC(add_residual_joint); | ||
| 110 | itx->pred_residual_joint = FUNC(pred_residual_joint); | ||
| 111 | itx->transform_bdpcm = FUNC(transform_bdpcm); | ||
| 112 | VVC_ITX(DCT2, dct2, 2) | ||
| 113 | VVC_ITX(DCT2, dct2, 64) | ||
| 114 | VVC_ITX_COMMON(DCT2, dct2) | ||
| 115 | VVC_ITX_COMMON(DCT8, dct8) | ||
| 116 | VVC_ITX_COMMON(DST7, dst7) | ||
| 117 | |||
| 118 | #undef VVC_ITX | ||
| 119 | #undef VVC_ITX_COMMON | ||
| 120 | } | ||