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 #include "mpp_frame.h" 25 26 #include "parser_api.h" 27 28 #include "av1.h" 29 #include "av1d_codec.h" 30 #include "av1d_cbs.h" 31 #include "av1d_syntax.h" 32 #include "av1d_common.h" 33 #include "av1_entropymode.h" 34 35 extern RK_U32 av1d_debug; 36 37 #define AV1D_DBG_FUNCTION (0x00000001) 38 #define AV1D_DBG_HEADER (0x00000002) 39 #define AV1D_DBG_REF (0x00000004) 40 #define AV1D_DBG_STRMIN (0x00000008) 41 #define AV1D_DBG_DUMP_RPU (0x10000000) 42 43 #define av1d_dbg(flag, fmt, ...) _mpp_dbg_f(av1d_debug, flag, fmt, ##__VA_ARGS__) 44 #define av1d_dbg_func(fmt, ...) av1d_dbg(AV1D_DBG_FUNCTION, fmt, ## __VA_ARGS__) 45 46 typedef struct RefInfo { 47 RK_S32 ref_count; 48 RK_U32 invisible; 49 RK_U32 is_output; 50 RK_U32 lst_frame_offset; 51 RK_U32 lst2_frame_offset; 52 RK_U32 lst3_frame_offset; 53 RK_U32 gld_frame_offset; 54 RK_U32 bwd_frame_offset; 55 RK_U32 alt2_frame_offset; 56 RK_U32 alt_frame_offset; 57 RK_U32 is_intra_frame; 58 RK_U32 intra_only; 59 } RefInfo; 60 61 typedef struct GlobalMtionParams { 62 RK_U32 wmtype; 63 RK_S32 wmmat[6]; 64 RK_S32 wmmat_val[6]; 65 RK_S32 alpha, beta, gamma, delta; 66 } GlobalMtionParams; 67 68 typedef struct AV1Frame { 69 MppFrame f; 70 RK_S32 slot_index; 71 AV1RawFrameHeader *raw_frame_header; 72 RK_S32 temporal_id; 73 RK_S32 spatial_id; 74 RK_U8 order_hint; 75 GlobalMtionParams gm_params[AV1_NUM_REF_FRAMES]; 76 RK_U8 skip_mode_frame_idx[2]; 77 AV1RawFilmGrainParams film_grain; 78 RK_U8 coded_lossless; 79 RefInfo *ref; 80 } AV1Frame; 81 82 typedef struct AV1Context_t { 83 BitReadCtx_t gb; 84 85 AV1RawSequenceHeader *sequence_header; 86 AV1RawSequenceHeader *seq_ref; 87 AV1RawFrameHeader *raw_frame_header; 88 Av1UnitFragment current_obu; 89 90 RK_S32 seen_frame_header; 91 RK_U8 *frame_header; 92 size_t frame_header_size; 93 94 AV1Frame ref[AV1_NUM_REF_FRAMES]; 95 AV1Frame cur_frame; 96 97 MppFrameMasteringDisplayMetadata mastering_display; 98 MppFrameContentLightMetadata content_light; 99 MppFrameHdrDynamicMeta *hdr_dynamic_meta; 100 RK_U32 hdr_dynamic; 101 RK_U32 is_hdr; 102 103 RK_S32 temporal_id; 104 RK_S32 spatial_id; 105 RK_S32 operating_point_idc; 106 107 RK_S32 bit_depth; 108 RK_S32 order_hint; 109 RK_S32 frame_width; 110 RK_S32 frame_height; 111 RK_S32 upscaled_width; 112 RK_S32 render_width; 113 RK_S32 render_height; 114 115 RK_S32 num_planes; 116 RK_S32 coded_lossless; 117 RK_S32 all_lossless; 118 RK_S32 tile_cols; 119 RK_S32 tile_rows; 120 RK_S32 tile_num; 121 RK_S32 operating_point; 122 RK_S32 extra_has_frame; 123 RK_U32 frame_tag_size; 124 RK_U32 fist_tile_group; 125 RK_U32 tile_offset; 126 127 AV1CDFs *cdfs; 128 MvCDFs *cdfs_ndvc; 129 AV1CDFs default_cdfs; 130 MvCDFs default_cdfs_ndvc; 131 AV1CDFs cdfs_last[NUM_REF_FRAMES]; 132 MvCDFs cdfs_last_ndvc[NUM_REF_FRAMES]; 133 RK_U8 disable_frame_end_update_cdf; 134 RK_U8 frame_is_intra; 135 RK_U8 refresh_frame_flags; 136 137 const Av1UnitType *unit_types; 138 RK_S32 nb_unit_types; 139 140 RK_U32 tile_offset_start[AV1_MAX_TILES]; 141 RK_U32 tile_offset_end[AV1_MAX_TILES]; 142 143 AV1ReferenceFrameState ref_s[AV1_NUM_REF_FRAMES]; 144 145 MppBufSlots slots; 146 MppBufSlots packet_slots; 147 RK_U8 skip_ref0; 148 RK_U8 skip_ref1; 149 MppDecCfgSet *cfg; 150 HalDecTask *task; 151 RK_S32 eos; ///< current packet contains an EOS/EOB NAL 152 RK_S64 pts; 153 RK_S64 dts; 154 const MppDecHwCap *hw_info; 155 } AV1Context; 156 157 #ifdef __cplusplus 158 extern "C" { 159 #endif 160 161 MPP_RET av1d_parser_init(Av1CodecContext *ctx, ParserCfg *init); 162 163 MPP_RET av1d_parser_deinit(Av1CodecContext *ctx); 164 165 RK_S32 av1d_parser_frame(Av1CodecContext *ctx, HalDecTask *in_task); 166 167 void av1d_parser_update(Av1CodecContext *ctx, void *info); 168 169 MPP_RET av1d_paser_reset(Av1CodecContext *ctx); 170 171 RK_S32 av1d_split_frame(Av1CodecContext *ctx, 172 RK_U8 **out_data, RK_S32 *out_size, 173 RK_U8 *data, RK_S32 size); 174 175 MPP_RET av1d_get_frame_stream(Av1CodecContext *ctx, RK_U8 *buf, RK_S32 length); 176 177 MPP_RET av1d_split_init(Av1CodecContext *ctx); 178 179 RK_S32 av1d_parser2_syntax(Av1CodecContext *ctx); 180 181 RK_S32 mpp_av1_split_fragment(AV1Context *ctx, Av1UnitFragment *frag, RK_S32 header_flag); 182 RK_S32 mpp_av1_read_fragment_content(AV1Context *ctx, Av1UnitFragment *frag); 183 RK_S32 mpp_av1_set_context_with_sequence(Av1CodecContext *ctx, 184 const AV1RawSequenceHeader *seq); 185 void mpp_av1_fragment_reset(Av1UnitFragment *frag); 186 RK_S32 mpp_av1_assemble_fragment(AV1Context *ctx, Av1UnitFragment *frag); 187 void mpp_av1_flush(AV1Context *ctx); 188 void mpp_av1_close(AV1Context *ctx); 189 void mpp_av1_free_metadata(void *unit, RK_U8 *content); 190 191 void Av1GetCDFs(AV1Context *ctx, RK_U32 ref_idx); 192 void Av1StoreCDFs(AV1Context *ctx, RK_U32 refresh_frame_flags); 193 194 #ifdef __cplusplus 195 } 196 #endif 197 198 #endif // __AV1D_PARSER_H__ 199