1 /* 2 * Copyright 2015 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 __AVSD_PARSE_H__ 18 #define __AVSD_PARSE_H__ 19 20 #include "mpp_debug.h" 21 22 #include "parser_api.h" 23 #include "mpp_bitread.h" 24 25 #include "avsd_syntax.h" 26 #include "avsd_api.h" 27 28 #define AVSD_DBG_ERROR (0x00000001) 29 #define AVSD_DBG_ASSERT (0x00000002) 30 #define AVSD_DBG_WARNNING (0x00000004) 31 #define AVSD_DBG_LOG (0x00000008) 32 33 #define AVSD_DBG_INPUT (0x00000010) //!< input packet 34 #define AVSD_DBG_TIME (0x00000020) //!< input packet 35 #define AVSD_DBG_SYNTAX (0x00000040) 36 #define AVSD_DBG_REF (0x00000080) 37 38 #define AVSD_DBG_CALLBACK (0x00008000) 39 40 extern RK_U32 avsd_parse_debug; 41 42 #define AVSD_PARSE_TRACE(fmt, ...)\ 43 do {\ 44 if (AVSD_DBG_LOG & avsd_parse_debug)\ 45 { mpp_log_f(fmt, ## __VA_ARGS__); }\ 46 } while (0) 47 48 49 #define AVSD_DBG(level, fmt, ...)\ 50 do {\ 51 if (level & avsd_parse_debug)\ 52 { mpp_log(fmt, ## __VA_ARGS__); }\ 53 } while (0) 54 55 //!< input check 56 #define INP_CHECK(ret, val, ...)\ 57 do{\ 58 if ((val)) {\ 59 ret = MPP_ERR_INIT; \ 60 AVSD_DBG(AVSD_DBG_WARNNING, "input empty(%d).\n", __LINE__); \ 61 goto __RETURN; \ 62 }} while (0) 63 64 //!< memory malloc check 65 #define MEM_CHECK(ret, val, ...)\ 66 do{\ 67 if(!(val)) {\ 68 ret = MPP_ERR_MALLOC;\ 69 mpp_err_f("malloc buffer error(%d).\n", __LINE__); \ 70 goto __FAILED; \ 71 }} while (0) 72 73 //!< function return check 74 #define FUN_CHECK(val)\ 75 do{\ 76 if ((val) < 0) {\ 77 AVSD_DBG(AVSD_DBG_WARNNING, "Function error(%d).\n", __LINE__); \ 78 goto __FAILED; \ 79 }} while (0) 80 81 #define MAX_STREAM_SIZE (2*1024*1024) 82 83 //!< NALU type 84 #define SEQUENCE_DISPLAY_EXTENTION 0x00000002 85 #define COPYRIGHT_EXTENTION 0x00000004 86 #define PICTURE_DISPLAY_EXTENTION 0x00000007 87 #define CAMERA_PARAMETERS_EXTENTION 0x0000000B 88 #define SLICE_MIN_START_CODE 0x00000100 89 #define SLICE_MAX_START_CODE 0x000001AF 90 #define VIDEO_SEQUENCE_START_CODE 0x000001B0 91 #define VIDEO_SEQUENCE_END_CODE 0x000001B1 92 #define USER_DATA_CODE 0x000001B2 93 #define I_PICUTRE_START_CODE 0x000001B3 94 #define EXTENSION_START_CODE 0x000001B5 95 #define PB_PICUTRE_START_CODE 0x000001B6 96 #define VIDEO_EDIT_CODE 0x000001B7 97 #define VIDEO_TIME_CODE 0x000001E0 98 99 100 #define EDGE_SIZE 16 101 #define MB_SIZE 16 102 #define YUV420 0 103 104 //!< picture type 105 enum avsd_picture_type_e { 106 I_PICTURE = 0, 107 P_PICTURE = 1, 108 B_PICTURE = 2 109 }; 110 111 typedef struct avsd_sequence_header_t { 112 RK_U8 profile_id; 113 RK_U8 level_id; 114 RK_U8 progressive_sequence; 115 RK_U8 version; 116 RK_U32 horizontal_size; 117 RK_U32 vertical_size; 118 119 RK_U8 chroma_format; 120 RK_U8 sample_precision; 121 RK_U8 aspect_ratio; 122 RK_U8 frame_rate_code; 123 RK_U32 bit_rate; 124 RK_U8 low_delay; 125 RK_U8 version_checked; 126 RK_U32 bbv_buffer_size; 127 } AvsdSeqHeader_t; 128 129 //!< sequence display extension header 130 typedef struct avsd_seqence_extension_header_t { 131 RK_U32 video_format; 132 RK_U32 sample_range; 133 RK_U32 color_description; 134 RK_U32 color_primaries; 135 RK_U32 transfer_characteristics; 136 RK_U32 matrix_coefficients; 137 RK_U32 display_horizontalSize; 138 RK_U32 display_verticalSize; 139 } AvsdSeqExtHeader_t; 140 141 typedef struct avsd_picture_header { 142 RK_U16 bbv_delay; 143 RK_U16 bbv_delay_extension; 144 145 RK_U8 picture_coding_type; 146 RK_U8 time_code_flag; 147 RK_U32 time_code; 148 RK_U8 picture_distance; // poc 149 RK_U32 bbv_check_times; 150 RK_U8 progressive_frame; 151 RK_U8 picture_structure; 152 RK_U8 advanced_pred_mode_disable; 153 RK_U8 top_field_first; 154 RK_U8 repeat_first_field; 155 RK_U8 fixed_picture_qp; 156 RK_U8 picture_qp; 157 RK_U8 picture_reference_flag; 158 159 RK_U8 no_forward_reference_flag; 160 RK_U8 pb_field_enhanced_flag; 161 162 RK_U8 skip_mode_flag; 163 RK_U8 loop_filter_disable; 164 RK_U8 loop_filter_parameter_flag; 165 RK_U32 alpha_c_offset; 166 RK_U32 beta_offset; 167 168 RK_U8 weighting_quant_flag; 169 RK_U8 chroma_quant_param_disable; 170 RK_S32 chroma_quant_param_delta_cb; 171 RK_S32 chroma_quant_param_delta_cr; 172 RK_U32 weighting_quant_param_index; 173 RK_U32 weighting_quant_model; 174 RK_S32 weighting_quant_param_delta1[6]; 175 RK_S32 weighting_quant_param_delta2[6]; 176 RK_S32 weighting_quant_param[6]; 177 RK_U8 aec_enable; 178 } AvsdPicHeader_t; 179 180 typedef struct avsd_frame_t { 181 RK_U32 valid; 182 RK_U32 idx; 183 184 RK_U32 pic_type; 185 RK_U32 frame_mode; //!< set mpp frame flag 186 RK_U32 width; 187 RK_U32 height; 188 RK_U32 ver_stride; 189 RK_U32 hor_stride; 190 RK_S64 pts; 191 RK_S64 dts; 192 193 RK_S32 stream_len; 194 RK_S32 stream_offset; 195 RK_U32 had_display; 196 RK_S32 slot_idx; 197 } AvsdFrame_t; 198 199 typedef struct avsd_memory_t { 200 struct avsd_syntax_t syntax; 201 struct avsd_frame_t save[3]; 202 BitReadCtx_t bitctx; 203 } AvsdMemory_t; 204 205 //!< decoder parameters 206 typedef struct avs_dec_ctx_t { 207 MppBufSlots frame_slots; 208 MppBufSlots packet_slots; 209 210 MppPacket task_pkt; 211 RK_U32 frame_no; 212 ParserCfg init; 213 RK_U8 got_eos; 214 RK_U32 pkt_no; 215 216 struct avsd_memory_t *mem; 217 RK_U8 *streambuf; 218 RK_U32 stream_len; 219 RK_U32 stream_size; 220 221 BitReadCtx_t *bx; 222 RK_U32 left_length; 223 224 AvsdSeqHeader_t vsh; 225 AvsdSeqExtHeader_t ext; 226 AvsdPicHeader_t ph; 227 AvsdSyntax_t *syn; 228 AvsdFrame_t *dpb[2]; //!< 2 refer frames or 4 refer field 229 AvsdFrame_t *cur; //!< for decoder field 230 231 RK_U32 need_split; 232 RK_U32 state; 233 RK_U32 vop_header_found; 234 RK_U32 got_vsh; 235 RK_U32 got_ph; 236 RK_U32 got_keyframe; 237 RK_U32 mb_width; 238 RK_U32 mb_height; 239 RK_U32 vec_flag; //!< video_edit_code_flag 240 241 RK_U32 disable_error; 242 RK_U32 dis_err_clr_mark; 243 } AvsdCtx_t; 244 245 #ifdef __cplusplus 246 extern "C" { 247 #endif 248 249 MPP_RET avsd_free_resource(AvsdCtx_t *p_dec); 250 MPP_RET avsd_reset_parameters(AvsdCtx_t *p_dec); 251 MPP_RET set_frame_output(AvsdCtx_t *p_dec, AvsdFrame_t *p); 252 253 MPP_RET avsd_set_dpb(AvsdCtx_t *p_dec, HalDecTask *task); 254 MPP_RET avsd_commit_syntaxs(AvsdSyntax_t *syn, HalDecTask *task); 255 MPP_RET avsd_fill_parameters(AvsdCtx_t *p_dec, AvsdSyntax_t *syn); 256 257 MPP_RET avsd_update_dpb(AvsdCtx_t *p_dec); 258 259 MPP_RET avsd_parser_split(AvsdCtx_t *ctx, MppPacket *dst, MppPacket *src); 260 MPP_RET avsd_parse_stream(AvsdCtx_t *p_dec, HalDecTask *task); 261 262 #ifdef __cplusplus 263 } 264 #endif 265 266 #endif /*__AVSD_PARSE_H__*/ 267