FFmpeg
Loading...
Searching...
No Matches
apv_dsp.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <assert.h>
20#include <stdint.h>
21#include <string.h>
22
23#include "config.h"
25#include "libavutil/avassert.h"
26#include "libavutil/common.h"
27
28#include "apv.h"
29#include "apv_dsp.h"
30
31
32static const int8_t apv_trans_matrix[8][8] = {
33 { 64, 64, 64, 64, 64, 64, 64, 64 },
34 { 89, 75, 50, 18, -18, -50, -75, -89 },
35 { 84, 35, -35, -84, -84, -35, 35, 84 },
36 { 75, -18, -89, -50, 50, 89, 18, -75 },
37 { 64, -64, -64, 64, 64, -64, -64, 64 },
38 { 50, -89, 18, 75, -75, -18, 89, -50 },
39 { 35, -84, 84, -35, -35, 84, -84, 35 },
40 { 18, -50, 75, -89, 89, -75, 50, -18 },
41};
42
43typedef struct APVConstantsC {
44 int16_t qmatrix[8][8];
48
49static_assert(sizeof(APVConstantsC) <= APV_DSP_CONSTANTS_SIZE,
50 "APV DSP constants buffer too small");
51
53 const int16_t *qmatrix,
54 int bit_depth,
55 int qp_shift)
56{
58
59 memcpy(c->qmatrix, qmatrix, sizeof(c->qmatrix));
60 c->bit_depth = bit_depth;
61 c->qp_shift = qp_shift;
62}
63
64static void apv_decode_transquant_c(void *output,
65 ptrdiff_t pitch,
66 const int16_t *input_flat,
67 const void *constants)
68{
69 const APVConstantsC *c = constants;
70 const int16_t (*input)[8] = (const int16_t(*)[8])input_flat;
71 int bit_depth = c->bit_depth;
72
73 int16_t scaled_coeff[8][8];
74 int32_t recon_sample[8][8];
75
76 // Dequant.
77 {
78 // Note that level_scale was already combined into qmatrix
79 // before we got here.
80 int bd_shift = bit_depth + 3 - 5;
81
82 for (int y = 0; y < 8; y++) {
83 for (int x = 0; x < 8; x++) {
84 int coeff = ((int)(input[y][x] *
85 c->qmatrix[y][x] *
86 (1U << c->qp_shift) +
87 (1 << (bd_shift - 1)))) >> bd_shift;
88
89 scaled_coeff[y][x] =
92 }
93 }
94 }
95
96 // Transform.
97 {
98 int32_t tmp[8][8];
99
100 // Vertical transform of columns.
101 for (int x = 0; x < 8; x++) {
102 for (int i = 0; i < 8; i++) {
103 int sum = 0;
104 for (int j = 0; j < 8; j++)
105 sum += apv_trans_matrix[j][i] * scaled_coeff[j][x];
106 tmp[i][x] = sum;
107 }
108 }
109
110 // Renormalise.
111 for (int x = 0; x < 8; x++) {
112 for (int y = 0; y < 8; y++)
113 tmp[y][x] = (tmp[y][x] + 64) >> 7;
114 }
115
116 // Horizontal transform of rows.
117 for (int y = 0; y < 8; y++) {
118 for (int i = 0; i < 8; i++) {
119 int sum = 0;
120 for (int j = 0; j < 8; j++)
121 sum += apv_trans_matrix[j][i] * tmp[y][j];
122 recon_sample[y][i] = sum;
123 }
124 }
125 }
126
127 // Output.
128 av_assert2(bit_depth > 8 && bit_depth <= 16);
129 uint16_t *ptr = output;
130 int bd_shift = 20 - bit_depth;
131 pitch /= 2; // Pitch was in bytes, 2 bytes per sample.
132
133 for (int y = 0; y < 8; y++) {
134 for (int x = 0; x < 8; x++) {
135 int sample = ((recon_sample[y][x] +
136 (1 << (bd_shift - 1))) >> bd_shift) +
137 (1 << (bit_depth - 1));
139 }
140 ptr += pitch;
141 }
142}
143
145{
148
149#if ARCH_X86_64 && HAVE_X86ASM
151#endif
152#if ARCH_AARCH64
154#endif
155}
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition af_astats.c:246
void ff_apv_dsp_init_x86_64(APVDSPContext *dsp)
#define APV_DSP_CONSTANTS_SIZE
Size of the buffer holding constants for decode_transquant(), which must be large enough for the layo...
Definition apv_dsp.h:31
av_cold void ff_apv_dsp_init_aarch64(APVDSPContext *dsp)
int32_t
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition avassert.h:68
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
common internal and external API header
#define av_clip
Definition common.h:100
#define av_clip_uintp2
Definition common.h:124
#define sample
static const vec_s16 constants[5]
@ APV_MIN_TRANS_COEFF
Definition apv.h:56
@ APV_MAX_TRANS_COEFF
Definition apv.h:57
void ff_apv_prepare_constants_c(void *constants, const int16_t *qmatrix, int bit_depth, int qp_shift)
Definition apv_dsp.c:52
static void apv_decode_transquant_c(void *output, ptrdiff_t pitch, const int16_t *input_flat, const void *constants)
Definition apv_dsp.c:64
static const int8_t apv_trans_matrix[8][8]
Definition apv_dsp.c:32
av_cold void ff_apv_dsp_init(APVDSPContext *dsp)
Definition apv_dsp.c:144
Macro definitions for various function/variable attributes.
#define av_cold
Definition attributes.h:117
int bit_depth
Definition apv_dsp.c:45
int16_t qmatrix[8][8]
Definition apv_dsp.c:44
void(* prepare_constants)(void *constants, const int16_t *qmatrix, int bit_depth, int qp_shift)
Fill the constants buffer used by decode_transquant() for all blocks with the same quantisation param...
Definition apv_dsp.h:39
void(* decode_transquant)(void *output, ptrdiff_t pitch, const int16_t *input, const void *constants)
Run transquant for a single block.
Definition apv_dsp.h:49
static uint8_t tmp[40]
Definition aes_ctr.c:52
static double c[64]