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