xref: /OK3568_Linux_fs/external/mpp/mpp/codec/dec/av1/av1d_parser.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright 2021 Rockchip Electronics Co. LTD
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __AV1D_PARSER_H__
18 #define __AV1D_PARSER_H__
19 
20 #include <stdlib.h>
21 
22 #include "mpp_mem.h"
23 #include "mpp_bitread.h"
24 
25 #include "parser_api.h"
26 
27 #include "av1.h"
28 #include "av1d_codec.h"
29 #include "av1d_cbs.h"
30 #include "av1d_syntax.h"
31 #include "av1d_common.h"
32 #include "av1_entropymode.h"
33 
34 extern RK_U32 av1d_debug;
35 
36 #define AV1D_DBG_FUNCTION (0x00000001)
37 #define AV1D_DBG_HEADER   (0x00000002)
38 #define AV1D_DBG_REF      (0x00000004)
39 #define AV1D_DBG_STRMIN   (0x00000008)
40 #define AV1D_DBG_DUMP_RPU (0x10000000)
41 
42 #define av1d_dbg(flag, fmt, ...) _mpp_dbg_f(av1d_debug, flag, fmt, ##__VA_ARGS__)
43 #define av1d_dbg_func(fmt, ...)  av1d_dbg(AV1D_DBG_FUNCTION, fmt, ## __VA_ARGS__)
44 
45 typedef struct RefInfo {
46     RK_S32 ref_count;
47     RK_U32 invisible;
48     RK_U32 is_output;
49     RK_U32 lst_frame_offset;
50     RK_U32 lst2_frame_offset;
51     RK_U32 lst3_frame_offset;
52     RK_U32 gld_frame_offset;
53     RK_U32 bwd_frame_offset;
54     RK_U32 alt2_frame_offset;
55     RK_U32 alt_frame_offset;
56     RK_U32 is_intra_frame;
57     RK_U32 intra_only;
58 } RefInfo;
59 
60 typedef struct GlobalMtionParams {
61     RK_U32 wmtype;
62     RK_S32 wmmat[6];
63     RK_S32 alpha, beta, gamma, delta;
64 } GlobalMtionParams;
65 
66 typedef struct AV1Frame {
67     MppFrame f;
68     RK_S32 slot_index;
69     AV1RawFrameHeader *raw_frame_header;
70     RK_S32 temporal_id;
71     RK_S32 spatial_id;
72     RK_U8  order_hint;
73     GlobalMtionParams gm_params[AV1_NUM_REF_FRAMES];
74     RK_U8  skip_mode_frame_idx[2];
75     AV1RawFilmGrainParams film_grain;
76     RK_U8 coded_lossless;
77     RefInfo *ref;
78 } AV1Frame;
79 
80 typedef struct AV1Context_t {
81     BitReadCtx_t gb;
82 
83     AV1RawSequenceHeader *sequence_header;
84     AV1RawSequenceHeader *seq_ref;
85     AV1RawFrameHeader *raw_frame_header;
86     Av1UnitFragment  current_obu;
87 
88     RK_S32 seen_frame_header;
89     RK_U8  *frame_header;
90     size_t frame_header_size;
91 
92     AV1Frame ref[AV1_NUM_REF_FRAMES];
93     AV1Frame cur_frame;
94 
95     MppFrameHdrDynamicMeta *hdr_dynamic_meta;
96     RK_U32 hdr_dynamic;
97     RK_U32 is_hdr;
98 
99     RK_S32 temporal_id;
100     RK_S32 spatial_id;
101     RK_S32 operating_point_idc;
102 
103     RK_S32 bit_depth;
104     RK_S32 order_hint;
105     RK_S32 frame_width;
106     RK_S32 frame_height;
107     RK_S32 upscaled_width;
108     RK_S32 render_width;
109     RK_S32 render_height;
110 
111     RK_S32 num_planes;
112     RK_S32 coded_lossless;
113     RK_S32 all_lossless;
114     RK_S32 tile_cols;
115     RK_S32 tile_rows;
116     RK_S32 tile_num;
117     RK_S32 operating_point;
118     RK_S32 extra_has_frame;
119     RK_U32 frame_tag_size;
120     RK_U32 fist_tile_group;
121     RK_U32 tile_offset;
122 
123     AV1CDFs *cdfs;
124     MvCDFs  *cdfs_ndvc;
125     AV1CDFs default_cdfs;
126     MvCDFs  default_cdfs_ndvc;
127     AV1CDFs cdfs_last[NUM_REF_FRAMES];
128     MvCDFs  cdfs_last_ndvc[NUM_REF_FRAMES];
129     RK_U8 disable_frame_end_update_cdf;
130     RK_U8 frame_is_intra;
131     RK_U8 refresh_frame_flags;
132 
133     const Av1UnitType *unit_types;
134     RK_S32 nb_unit_types;
135 
136     RK_U32 tile_offset_start[AV1_MAX_TILES];
137     RK_U32 tile_offset_end[AV1_MAX_TILES];
138 
139     AV1ReferenceFrameState ref_s[AV1_NUM_REF_FRAMES];
140 
141     MppBufSlots slots;
142     MppBufSlots packet_slots;
143     RK_U8 skip_ref0;
144     RK_U8 skip_ref1;
145     MppDecCfgSet *cfg;
146     HalDecTask *task;
147     RK_S32 eos;       ///< current packet contains an EOS/EOB NAL
148     RK_S64 pts;
149 } AV1Context;
150 
151 #ifdef  __cplusplus
152 extern "C" {
153 #endif
154 
155 MPP_RET av1d_parser_init(Av1CodecContext *ctx, ParserCfg *init);
156 
157 MPP_RET av1d_parser_deinit(Av1CodecContext *ctx);
158 
159 RK_S32 av1d_parser_frame(Av1CodecContext *ctx, HalDecTask *in_task);
160 
161 void av1d_parser_update(Av1CodecContext *ctx, void *info);
162 
163 MPP_RET av1d_paser_reset(Av1CodecContext *ctx);
164 
165 RK_S32 av1d_split_frame(Av1CodecContext *ctx,
166                         RK_U8 **out_data, RK_S32 *out_size,
167                         RK_U8 *data, RK_S32 size);
168 
169 MPP_RET av1d_get_frame_stream(Av1CodecContext *ctx, RK_U8 *buf, RK_S32 length);
170 
171 MPP_RET av1d_split_deinit(Av1CodecContext *ctx);
172 
173 MPP_RET av1d_split_init(Av1CodecContext *ctx);
174 
175 RK_S32 av1d_parser2_syntax(Av1CodecContext *ctx);
176 
177 RK_S32 mpp_av1_split_fragment(AV1Context *ctx, Av1UnitFragment *frag, RK_S32 header_flag);
178 RK_S32 mpp_av1_read_fragment_content(AV1Context *ctx, Av1UnitFragment *frag);
179 RK_S32 mpp_av1_set_context_with_sequence(Av1CodecContext *ctx,
180                                          const AV1RawSequenceHeader *seq);
181 void mpp_av1_fragment_reset(Av1UnitFragment *frag);
182 RK_S32 mpp_av1_assemble_fragment(AV1Context *ctx, Av1UnitFragment *frag);
183 void mpp_av1_flush(AV1Context *ctx);
184 void mpp_av1_close(AV1Context *ctx);
185 void mpp_av1_free_metadata(void *unit, RK_U8 *content);
186 
187 void Av1GetCDFs(AV1Context *ctx, RK_U32 ref_idx);
188 void Av1StoreCDFs(AV1Context *ctx, RK_U32 refresh_frame_flags);
189 
190 #ifdef  __cplusplus
191 }
192 #endif
193 
194 #endif // __AV1D_PARSER_H__
195