xref: /rockchip-linux_mpp/mpp/codec/dec/vp9/vp9d_parser.h (revision 437bfbeb9567cca9cd9080e3f6954aa9d6a94f18)
1 /*
2 *
3 * Copyright 2015 Rockchip Electronics Co. LTD
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 #ifndef __VP9D_PARSER_H__
18 #define __VP9D_PARSER_H__
19 
20 #include <stdlib.h>
21 
22 #include "mpp_debug.h"
23 #include "mpp_bitread.h"
24 
25 #include "parser_api.h"
26 #include "vpx_rac.h"
27 #include "vp9.h"
28 #include "vp9data.h"
29 #include "vp9d_syntax.h"
30 
31 extern RK_U32 vp9d_debug;
32 
33 #define VP9D_DBG_FUNCTION (0x00000001)
34 #define VP9D_DBG_HEADER   (0x00000002)
35 #define VP9D_DBG_REF      (0x00000004)
36 #define VP9D_DBG_PORBE    (0x00000008)
37 #define VP9D_DBG_STRMIN   (0x00000010)
38 
39 
40 
41 #define vp9d_dbg(flag, fmt, ...) _mpp_dbg(vp9d_debug, flag, fmt, ##__VA_ARGS__)
42 
43 enum CompPredMode {
44     PRED_SINGLEREF,
45     PRED_COMPREF,
46     PRED_SWITCHABLE,
47 };
48 
49 enum BlockLevel {
50     BL_64X64,
51     BL_32X32,
52     BL_16X16,
53     BL_8X8,
54 };
55 
56 enum BlockSize {
57     BS_64x64,
58     BS_64x32,
59     BS_32x64,
60     BS_32x32,
61     BS_32x16,
62     BS_16x32,
63     BS_16x16,
64     BS_16x8,
65     BS_8x16,
66     BS_8x8,
67     BS_8x4,
68     BS_4x8,
69     BS_4x4,
70     N_BS_SIZES,
71 };
72 
73 typedef struct VP9Block {
74     RK_U8 seg_id, intra, comp, ref[2], mode[4], uvmode, skip;
75     enum FilterMode filter;
76     Vpxmv mv[4 /* b_idx */][2 /* ref */];
77     enum BlockSize bs;
78     enum TxfmMode tx, uvtx;
79     enum BlockLevel bl;
80     enum BlockPartition bp;
81 } VP9Block;
82 
83 struct VP9mvrefPair {
84     Vpxmv mv[2];
85     RK_S8 ref[2];
86 };
87 
88 typedef struct RefInfo {
89     RK_S32 ref_count;
90     RK_U32 invisible;
91     RK_U32 segMapIndex;
92     RK_U32 is_output;
93 } RefInfo;
94 
95 typedef struct VP9Frame {
96     MppFrame f;
97     RK_S32 slot_index;
98     RefInfo *ref;
99 } VP9Frame;
100 
101 struct VP9Filter {
102     uint8_t level[8 * 8];
103     uint8_t /* bit=col */ mask[2 /* 0=y, 1=uv */][2 /* 0=col, 1=row */]
104     [8 /* rows */][4 /* 0=16, 1=8, 2=4, 3=inner4 */];
105 };
106 #define CUR_FRAME 0
107 #define REF_FRAME_MVPAIR 1
108 #define REF_FRAME_SEGMAP 2
109 
110 typedef struct VP9Context {
111     BitReadCtx_t gb;
112     VpxRangeCoder c;
113     VpxRangeCoder *c_b;
114     RK_U32 c_b_size;
115     VP9Block *b_base, *b;
116     RK_S32 pass;
117     RK_S32 row, row7, col, col7;
118     RK_U8 *dst[3];
119     RK_S32 y_stride, uv_stride;
120 
121     // bitstream header
122     RK_U8 show_existing_frame;
123     RK_U8 keyframe, last_keyframe;
124     RK_U8 last_bpp, bpp, bpp_index, bytesperpixel;
125     RK_U8 invisible;
126     RK_U8 use_last_frame_mvs;
127     RK_U8 errorres;
128     RK_U8 ss_h, ss_v;
129     RK_U8 extra_plane;
130     RK_U8 intraonly;
131     RK_U8 resetctx;
132     RK_U8 refreshrefmask;
133     RK_U8 highprecisionmvs;
134     enum FilterMode filtermode;
135     RK_U8 allowcompinter;
136     RK_U8 fixcompref;
137     RK_U8 refreshctx;
138     RK_U8 parallelmode;
139     RK_U8 framectxid;
140     RK_U8 refidx[3];
141     RK_U8 signbias[3];
142     RK_U8 varcompref[2];
143     VP9Frame frames[3];
144     VP9Frame refs[8];
145     RK_U32 got_keyframes;
146 
147     struct {
148         RK_U8 level;
149         RK_S8 sharpness;
150         RK_U8 lim_lut[64];
151         RK_U8 mblim_lut[64];
152     } filter;
153     struct {
154         RK_U8 enabled;
155         RK_U8 update;
156         RK_S8 mode[2];
157         RK_S8 ref[4];
158     } lf_delta;
159     RK_U8 yac_qi;
160     RK_S8 ydc_qdelta, uvdc_qdelta, uvac_qdelta;
161     RK_U8 lossless;
162 #define MAX_SEGMENT 8
163     struct {
164         RK_U8 enabled;
165         RK_U8 temporal;
166         RK_U8 absolute_vals;
167         RK_U8 update_map;
168         RK_U8 ignore_refmap;
169         struct {
170             RK_U8 q_enabled;
171             RK_U8 lf_enabled;
172             RK_U8 ref_enabled;
173             RK_U8 skip_enabled;
174             RK_U8 ref_val;
175             RK_S16 q_val;
176             RK_S8 lf_val;
177             RK_S16 qmul[2][2];
178             RK_U8 lflvl[4][2];
179         } feat[MAX_SEGMENT];
180     } segmentation;
181     struct {
182         RK_U32 log2_tile_cols, log2_tile_rows;
183         RK_U32 tile_cols, tile_rows;
184         RK_U32 tile_row_start, tile_row_end, tile_col_start, tile_col_end;
185     } tiling;
186     RK_U32 sb_cols, sb_rows, rows, cols;
187     struct {
188         prob_context p;
189         RK_U8 coef[4][2][2][6][6][3];
190     } prob_ctx[4];
191     struct {
192         prob_context p;
193         RK_U8 coef[4][2][2][6][6][3];
194         RK_U8 seg[7];
195         RK_U8 segpred[3];
196     } prob;
197     struct {
198         prob_context p_flag;
199         prob_context p_delta;
200         RK_U8 coef_flag[4][2][2][6][6][3];
201         RK_U8 coef_delta[4][2][2][6][6][3];
202     } prob_flag_delta;
203     struct {
204         RK_U32 partition[4][4][4];
205         RK_U32 skip[3][2];
206         RK_U32 intra[4][2];
207         RK_U32 tx32p[2][4];
208         RK_U32 tx16p[2][4]; //orign tx16p
209         RK_U32 tx8p[2][2];
210         RK_U32 y_mode[4][10];
211         RK_U32 uv_mode[10][10];
212         RK_U32 comp[5][2];
213         RK_U32 comp_ref[5][2];
214         RK_U32 single_ref[5][2][2];
215         RK_U32 mv_mode[7][4];
216         RK_U32 filter[4][3];
217         RK_U32 mv_joint[4];
218         RK_U32 sign[2][2];
219         RK_U32 classes[2][12]; // orign classes[12]
220         RK_U32 class0[2][2];
221         RK_U32 bits[2][10][2];
222         RK_U32 class0_fp[2][2][4];
223         RK_U32 fp[2][4];
224         RK_U32 class0_hp[2][2];
225         RK_U32 hp[2][2];
226         RK_U32 coef[4][2][2][6][6][3];
227         RK_U32 eob[4][2][2][6][6][2];
228     } counts;
229     enum TxfmMode txfmmode;
230     enum CompPredMode comppredmode;
231 
232     // contextual (left/above) cache
233     RK_U8 left_y_nnz_ctx[16];
234     RK_U8 left_mode_ctx[16];
235     Vpxmv left_mv_ctx[16][2];
236     RK_U8 left_uv_nnz_ctx[2][16];
237     RK_U8 left_partition_ctx[8];
238     RK_U8 left_skip_ctx[8];
239     RK_U8 left_txfm_ctx[8];
240     RK_U8 left_segpred_ctx[8];
241     RK_U8 left_intra_ctx[8];
242     RK_U8 left_comp_ctx[8];
243     RK_U8 left_ref_ctx[8];
244     RK_U8 left_filter_ctx[8];
245 
246     // block reconstruction intermediates
247     RK_S32 block_alloc_using_2pass;
248     RK_S16  *block, *uvblock_base[2], *uvblock[2];
249     RK_U8 *eob_base, *uveob_base[2], *eob, *uveob[2];
250     struct { RK_S32 x, y; } min_mv, max_mv;
251     RK_U16 mvscale[3][2];
252     RK_U8 mvstep[3][2];
253 
254     RK_U32 uncompress_head_size_in_byte;
255     RK_S32 first_partition_size;
256     MppBufSlots slots;
257     MppBufSlots packet_slots;
258     MppDecCfgSet *cfg;
259     const MppDecHwCap *hw_info;
260     HalDecTask *task;
261     RK_S32 eos;       ///< current packet contains an EOS/EOB NAL
262     RK_S64 pts;
263     RK_S64 dts;
264     RK_S32 upprobe_num;
265     RK_S32 outframe_num;
266     RK_U32 cur_poc;
267 } VP9Context;
268 
269 #ifdef  __cplusplus
270 extern "C" {
271 #endif
272 
273 MPP_RET vp9d_parser_init(Vp9CodecContext *vp9_ctx, ParserCfg *init);
274 
275 MPP_RET vp9d_parser_deinit(Vp9CodecContext *vp9_ctx);
276 
277 RK_S32 vp9_parser_frame(Vp9CodecContext *ctx, HalDecTask *in_task);
278 
279 void vp9_parser_update(Vp9CodecContext *ctx, void *count_info);
280 MPP_RET vp9d_paser_reset(Vp9CodecContext *ctx);
281 RK_S32 vp9d_split_frame(SplitContext_t *ctx,
282                         RK_U8 **out_data, RK_S32 *out_size,
283                         RK_U8 *data, RK_S32 size);
284 
285 MPP_RET vp9d_get_frame_stream(Vp9CodecContext *ctx, RK_U8 *buf, RK_S32 length);
286 
287 MPP_RET vp9d_split_deinit(Vp9CodecContext *vp9_ctx);
288 
289 MPP_RET vp9d_split_init(Vp9CodecContext *vp9_ctx);
290 
291 RK_S32 vp9d_parser2_syntax(Vp9CodecContext *ctx);
292 
293 #ifdef  __cplusplus
294 }
295 #endif
296 
297 
298 #endif /* __VP9D_PARSER_H__ */
299