FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/cavs.h
Date: 2026-04-30 08:04:40
Exec Total Coverage
Lines: 12 12 100.0%
Functions: 1 1 100.0%
Branches: 4 4 100.0%

Line Branch Exec Source
1 /*
2 * Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
3 * Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #ifndef AVCODEC_CAVS_H
23 #define AVCODEC_CAVS_H
24
25 #include <stddef.h>
26 #include <stdint.h>
27
28 #include "libavutil/attributes.h"
29 #include "libavutil/frame.h"
30 #include "libavutil/mem_internal.h"
31
32 #include "avcodec.h"
33 #include "cavsdsp.h"
34 #include "blockdsp.h"
35 #include "h264chroma.h"
36 #include "get_bits.h"
37 #include "videodsp.h"
38
39 #define SLICE_MAX_START_CODE 0x000001af
40 #define EXT_START_CODE 0x000001b5
41 #define USER_START_CODE 0x000001b2
42 #define CAVS_START_CODE 0x000001b0
43 #define PIC_I_START_CODE 0x000001b3
44 #define PIC_PB_START_CODE 0x000001b6
45
46 #define A_AVAIL 1
47 #define B_AVAIL 2
48 #define C_AVAIL 4
49 #define D_AVAIL 8
50 #define NOT_AVAIL -1
51 #define REF_INTRA -2
52 #define REF_DIR -3
53
54 #define ESCAPE_CODE 59
55
56 #define FWD0 0x01
57 #define FWD1 0x02
58 #define BWD0 0x04
59 #define BWD1 0x08
60 #define SYM0 0x10
61 #define SYM1 0x20
62 #define SPLITH 0x40
63 #define SPLITV 0x80
64
65 #define MV_BWD_OFFS 12
66 #define MV_STRIDE 4
67
68 enum cavs_mb {
69 I_8X8 = 0,
70 P_SKIP,
71 P_16X16,
72 P_16X8,
73 P_8X16,
74 P_8X8,
75 B_SKIP,
76 B_DIRECT,
77 B_FWD_16X16,
78 B_BWD_16X16,
79 B_SYM_16X16,
80 B_8X8 = 29
81 };
82
83 enum cavs_sub_mb {
84 B_SUB_DIRECT,
85 B_SUB_FWD,
86 B_SUB_BWD,
87 B_SUB_SYM
88 };
89
90 enum cavs_intra_luma {
91 INTRA_L_VERT,
92 INTRA_L_HORIZ,
93 INTRA_L_LP,
94 INTRA_L_DOWN_LEFT,
95 INTRA_L_DOWN_RIGHT,
96 INTRA_L_LP_LEFT,
97 INTRA_L_LP_TOP,
98 INTRA_L_DC_128
99 };
100
101 enum cavs_intra_chroma {
102 INTRA_C_LP,
103 INTRA_C_HORIZ,
104 INTRA_C_VERT,
105 INTRA_C_PLANE,
106 INTRA_C_LP_LEFT,
107 INTRA_C_LP_TOP,
108 INTRA_C_DC_128,
109 };
110
111 enum cavs_mv_pred {
112 MV_PRED_MEDIAN,
113 MV_PRED_LEFT,
114 MV_PRED_TOP,
115 MV_PRED_TOPRIGHT,
116 MV_PRED_PSKIP,
117 MV_PRED_BSKIP
118 };
119
120 enum cavs_block {
121 BLK_16X16,
122 BLK_16X8,
123 BLK_8X16,
124 BLK_8X8
125 };
126
127 enum cavs_mv_loc {
128 MV_FWD_D3 = 0,
129 MV_FWD_B2,
130 MV_FWD_B3,
131 MV_FWD_C2,
132 MV_FWD_A1,
133 MV_FWD_X0,
134 MV_FWD_X1,
135 MV_FWD_A3 = 8,
136 MV_FWD_X2,
137 MV_FWD_X3,
138 MV_BWD_D3 = MV_BWD_OFFS,
139 MV_BWD_B2,
140 MV_BWD_B3,
141 MV_BWD_C2,
142 MV_BWD_A1,
143 MV_BWD_X0,
144 MV_BWD_X1,
145 MV_BWD_A3 = MV_BWD_OFFS+8,
146 MV_BWD_X2,
147 MV_BWD_X3
148 };
149
150 typedef struct cavs_vector {
151 int16_t x;
152 int16_t y;
153 int16_t dist;
154 int16_t ref;
155 } cavs_vector;
156
157 struct dec_2dvlc {
158 int8_t rltab[59][3];
159 int8_t level_add[27];
160 int8_t golomb_order;
161 int inc_limit;
162 int8_t max_run;
163 };
164
165 typedef struct AVSFrame {
166 AVFrame *f;
167 int poc;
168 } AVSFrame;
169
170 typedef struct AVSContext {
171 AVCodecContext *avctx;
172 BlockDSPContext bdsp;
173 H264ChromaContext h264chroma;
174 VideoDSPContext vdsp;
175 CAVSDSPContext cdsp;
176 GetBitContext gb;
177 AVSFrame cur; ///< currently decoded frame
178 AVSFrame DPB[2]; ///< reference frames
179 int dist[2]; ///< temporal distances from current frame to ref frames
180 int low_delay;
181 int profile, level;
182 int aspect_ratio;
183 int mb_width, mb_height;
184 int width, height;
185 int stream_revision; ///<0 for samples from 2006, 1 for rm52j encoder
186 int progressive;
187 int pic_structure;
188 int skip_mode_flag; ///< select between skip_count or one skip_flag per MB
189 int loop_filter_disable;
190 int alpha_offset, beta_offset;
191 int ref_flag;
192 int mbx, mby, mbidx; ///< macroblock coordinates
193 int flags; ///< availability flags of neighbouring macroblocks
194 int stc; ///< last start code
195 uint8_t *cy, *cu, *cv; ///< current MB sample pointers
196 int left_qp;
197 uint8_t *top_qp;
198
199 /** mv motion vector cache
200 0: D3 B2 B3 C2
201 4: A1 X0 X1 -
202 8: A3 X2 X3 -
203
204 X are the vectors in the current macroblock (5,6,9,10)
205 A is the macroblock to the left (4,8)
206 B is the macroblock to the top (1,2)
207 C is the macroblock to the top-right (3)
208 D is the macroblock to the top-left (0)
209
210 the same is repeated for backward motion vectors */
211 DECLARE_ALIGNED(8, cavs_vector, mv)[2*4*3];
212 cavs_vector *top_mv[2];
213 cavs_vector *col_mv;
214
215 /** luma pred mode cache
216 0: -- B2 B3
217 3: A1 X0 X1
218 6: A3 X2 X3 */
219 int pred_mode_Y[3*3];
220 int *top_pred_Y;
221 ptrdiff_t l_stride, c_stride;
222 int luma_scan[4];
223 int qp;
224 int qp_fixed;
225 int pic_qp_fixed;
226 int cbp;
227 DECLARE_ALIGNED(32, int16_t, block)[64];
228 uint8_t permutated_scantable[64];
229
230 /** intra prediction is done with un-deblocked samples
231 they are saved here before deblocking the MB */
232 uint8_t *top_border_y, *top_border_u, *top_border_v;
233 uint8_t left_border_y[26], left_border_u[10], left_border_v[10];
234 uint8_t intern_border_y[26];
235 uint8_t topleft_border_y, topleft_border_u, topleft_border_v;
236
237 void (*intra_pred_l[8])(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride);
238 void (*intra_pred_c[7])(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride);
239 uint8_t *col_type_base;
240
241 /* scaling factors for MV prediction */
242 int sym_factor; ///< for scaling in symmetrical B block
243 int direct_den[2]; ///< for scaling in direct B block
244 int scale_den[2]; ///< for scaling neighbouring MVs
245
246 uint8_t *edge_emu_buffer;
247
248 int got_keyframe;
249 } AVSContext;
250
251 extern const uint8_t ff_cavs_chroma_qp[64];
252 extern const uint8_t ff_cavs_partition_flags[30];
253 extern const cavs_vector ff_cavs_intra_mv;
254 extern const cavs_vector ff_cavs_dir_mv;
255
256 699050 static inline void set_mvs(cavs_vector *mv, enum cavs_block size) {
257
4/4
✓ Branch 0 taken 547938 times.
✓ Branch 1 taken 27370 times.
✓ Branch 2 taken 24151 times.
✓ Branch 3 taken 99591 times.
699050 switch(size) {
258 547938 case BLK_16X16:
259 547938 mv[MV_STRIDE ] = mv[0];
260 547938 mv[MV_STRIDE+1] = mv[0];
261 av_fallthrough;
262 575308 case BLK_16X8:
263 575308 mv[1] = mv[0];
264 575308 break;
265 24151 case BLK_8X16:
266 24151 mv[MV_STRIDE] = mv[0];
267 24151 break;
268 }
269 699050 }
270
271 void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type);
272 void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top, uint8_t **left,
273 int block);
274 void ff_cavs_load_intra_pred_chroma(AVSContext *h);
275 void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv);
276 void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type);
277 void ff_cavs_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC,
278 enum cavs_mv_pred mode, enum cavs_block size, int ref);
279 void ff_cavs_init_mb(AVSContext *h);
280 int ff_cavs_next_mb(AVSContext *h);
281 int ff_cavs_init_pic(AVSContext *h);
282 int ff_cavs_init_top_lines(AVSContext *h);
283 int ff_cavs_init(AVCodecContext *avctx);
284 int ff_cavs_end (AVCodecContext *avctx);
285
286 #endif /* AVCODEC_CAVS_H */
287