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