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 18 #ifndef __H264D_GLOBAL_H__ 19 #define __H264D_GLOBAL_H__ 20 21 #include <stdio.h> 22 #include "h2645d_sei.h" 23 #include "rk_type.h" 24 25 #include "mpp_debug.h" 26 #include "mpp_bitread.h" 27 #include "mpp_mem_pool.h" 28 29 #include "h264d_syntax.h" 30 #include "h264d_api.h" 31 32 33 #define H264D_DBG_ERROR (0x00000001) 34 #define H264D_DBG_ASSERT (0x00000002) 35 #define H264D_DBG_WARNNING (0x00000004) 36 #define H264D_DBG_LOG (0x00000008) 37 38 #define H264D_DBG_INPUT (0x00000010) //!< input packet 39 #define H264D_DBG_PPS_SPS (0x00000020) 40 #define H264D_DBG_LOOP_STATE (0x00000040) 41 #define H264D_DBG_PARSE_NALU (0x00000080) 42 43 #define H264D_DBG_DPB_INFO (0x00000100) //!< dpb size 44 #define H264D_DBG_DPB_MALLIC (0x00000200) //!< malloc 45 46 47 #define H264D_DBG_DPB_REF_ERR (0x00001000) 48 #define H264D_DBG_SLOT_FLUSH (0x00002000) //!< dpb buffer slot remain 49 #define H264D_DBG_SEI (0x00004000) 50 #define H264D_DBG_CALLBACK (0x00008000) 51 52 #define H264D_DBG_WRITE_ES_EN (0x00010000) //!< write input ts stream 53 #define H264D_DBG_FIELD_PAIRED (0x00020000) 54 #define H264D_DBG_DISCONTINUOUS (0x00040000) 55 56 extern RK_U32 h264d_debug; 57 58 #define H264D_DBG(level, fmt, ...)\ 59 do {\ 60 if (level & h264d_debug)\ 61 { mpp_log(fmt, ## __VA_ARGS__); }\ 62 } while (0) 63 64 65 #define H264D_ERR(fmt, ...)\ 66 do {\ 67 if (H264D_DBG_ERROR & h264d_debug)\ 68 { mpp_log(fmt, ## __VA_ARGS__); }\ 69 } while (0) 70 71 #define ASSERT(val)\ 72 do {\ 73 if (H264D_DBG_ASSERT & h264d_debug)\ 74 { mpp_assert(val); }\ 75 } while (0) 76 77 #define H264D_WARNNING(fmt, ...)\ 78 do {\ 79 if (H264D_DBG_WARNNING & h264d_debug)\ 80 { mpp_log(fmt, ## __VA_ARGS__); }\ 81 } while (0) 82 83 #define H264D_LOG(fmt, ...)\ 84 do {\ 85 if (H264D_DBG_LOG & h264d_debug)\ 86 { mpp_log(fmt, ## __VA_ARGS__); }\ 87 } while (0) 88 89 90 //!< vaule check 91 #define VAL_CHECK(ret, val, ...)\ 92 do{\ 93 if (!(val)){\ 94 ret = MPP_ERR_VALUE; \ 95 H264D_WARNNING("value error(%d).\n", __LINE__); \ 96 goto __FAILED; \ 97 }} while (0) 98 //!< memory malloc check 99 #define MEM_CHECK(ret, val, ...)\ 100 do{\ 101 if (!(val)) {\ 102 ret = MPP_ERR_MALLOC; \ 103 H264D_ERR("malloc buffer error(%d).\n", __LINE__); \ 104 goto __FAILED; \ 105 }} while (0) 106 107 108 //!< input check 109 #define INP_CHECK(ret, val, ...)\ 110 do{\ 111 if ((val)) {\ 112 ret = MPP_ERR_INIT; \ 113 H264D_WARNNING("input empty(%d).\n", __LINE__); \ 114 goto __RETURN; \ 115 }} while (0) 116 //!< function return check 117 #define FUN_CHECK(val)\ 118 do{\ 119 if ((val) < 0) {\ 120 H264D_WARNNING("Function error(%d).\n", __LINE__); \ 121 goto __FAILED; \ 122 }} while (0) 123 124 125 #define START_PREFIX_3BYTE 3 126 #define MAX_NUM_DPB_LAYERS 2 //!< must >= 2 127 #define MAX_LIST_SIZE 33 //!< for init list reorder 128 #define MAX_DPB_SIZE 16 //!< for prepare dpb info 129 #define MAX_REF_SIZE 32 //!< for prepare ref pic info 130 131 132 #define MAX_MARK_SIZE 35 //!< for malloc buffer mark, can be changed 133 134 #define HEAD_BUF_MAX_SIZE (1*1024*1024) 135 #define HEAD_BUF_ADD_SIZE (512) 136 #define NALU_BUF_MAX_SIZE (2*1024*1024) 137 #define NALU_BUF_ADD_SIZE (512) 138 #define SODB_BUF_MAX_SIZE (2*1024*1024) 139 #define SODB_BUF_ADD_SIZE (512) 140 141 //!< PPS parameters 142 #define MAXnum_slice_groups_minus1 8 143 typedef enum { 144 H264ScalingList4x4Length = 16, 145 H264ScalingList8x8Length = 64, 146 } ScalingListLength; 147 148 typedef enum { 149 STRUCT_NULL = 0, 150 TOP_FIELD = 0x1, 151 BOTTOM_FIELD = 0x2, 152 FRAME = 0x3, 153 STRUCT_MAX, 154 } PictureStructure; //!< New enum for field processing 155 156 typedef enum { 157 PIC_ERR_NULL = 0, 158 PIC_ERR_TOP = 0x1, 159 PIC_ERR_BOT = 0x2, 160 PIC_ERR_FRAME = 0x3, 161 PIC_ERR_WHOLE = 0x3, 162 PIC_ERR_MAX, 163 } PictureError; 164 165 typedef enum { 166 FIELD_ORDER_NULL, 167 FIELD_ORDER_TOP_FIRST, 168 FIELD_ORDER_BOT_FIRST, 169 FIELD_ORDER_SAME, 170 FIELD_ORDER_MAX 171 } FieldOrder; 172 173 //!< Field Coding Types 174 typedef enum { 175 FRAME_CODING = 0, 176 FIELD_CODING = 1, 177 ADAPTIVE_CODING = 2, 178 FRAME_MB_PAIR_CODING = 3 179 } CodingType; 180 181 typedef enum { 182 LIST_0 = 0, 183 LIST_1 = 1, 184 BI_PRED = 2, 185 BI_PRED_L0 = 3, 186 BI_PRED_L1 = 4 187 } ListType; 188 189 //!< NAL Unit structure 190 typedef struct h264_nalu_t { 191 RK_S32 startcodeprefix_len; //!< 4 for parameter sets and first slice in picture, 3 for everything else (suggested) 192 RK_U32 sodb_len; //!< Length of the NAL unit (Excluding the start code, which does not belong to the NALU) 193 RK_S32 forbidden_bit; //!< should be always FALSE 194 H264NaluType nalu_type; //!< NALU_TYPE_xxxx 195 H264NalRefIdcType nal_reference_idc; //!< NALU_PRIORITY_xxxx 196 RK_U8 *sodb_buf; //!< Data of the NAL unit (Excluding the start code, which does not belong to the NALU) 197 RK_U16 lost_packets; //!< true, if packet loss is detected, used in RTPNALU 198 //---- MVC extension 199 RK_S32 svc_extension_flag; //!< should be always 0, for MVC 200 RK_S32 non_idr_flag; //!< 0 = current is IDR 201 RK_S32 priority_id; //!< a lower value of priority_id specifies a higher priority 202 RK_S32 view_id; //!< view identifier for the NAL unit 203 RK_S32 temporal_id; //!< temporal identifier for the NAL unit 204 RK_S32 anchor_pic_flag; //!< anchor access unit 205 RK_S32 inter_view_flag; //!< inter-view prediction enable 206 RK_S32 reserved_one_bit; //!< shall be equal to 1 207 RK_S32 MVCExt_is_valid; 208 RK_S32 MVCExt_is_prefixNALU; 209 //------ 210 RK_U8 ualu_header_bytes; //!< for rbsp start 211 RK_S32 used_bits; 212 213 } H264_Nalu_t; 214 215 typedef struct h264_nalu_svc_ext_t { 216 RK_U32 valid; 217 RK_U32 idr_flag; 218 RK_U32 priority_id; 219 RK_U32 no_inter_layer_pred_flag; 220 RK_U32 dependency_id; 221 RK_U32 quality_id; 222 RK_U32 temporal_id; 223 RK_U32 use_ref_base_pic_flag; 224 RK_U32 discardable_flag; 225 RK_U32 output_flag; 226 } H264_NaluSvcExt_t; 227 228 typedef struct h264_nalu_mvc_ext_t { 229 RK_U32 valid; 230 RK_U32 non_idr_flag; 231 RK_U32 priority_id; 232 RK_U32 view_id; 233 RK_U32 temporal_id; 234 RK_U32 anchor_pic_flag; 235 RK_U32 inter_view_flag; 236 RK_U32 reserved_one_bit; 237 RK_U32 iPrefixNALU; 238 } H264_NaluMvcExt_t; 239 240 //!< decoder refence picture marking 241 typedef struct h264_drpm_t { 242 RK_S32 memory_management_control_operation; 243 RK_S32 difference_of_pic_nums_minus1; 244 RK_S32 long_term_pic_num; 245 RK_S32 long_term_frame_idx; 246 RK_S32 max_long_term_frame_idx_plus1; 247 struct h264_drpm_t *Next; 248 } H264_DRPM_t; 249 250 typedef enum { 251 Mem_NULL = 0, 252 Mem_Malloc = 1, 253 Mem_Clone = 2, 254 Mem_UnPaired = 3, 255 Mem_TopOnly = 4, 256 Mem_BotOnly = 5, 257 Mem_Fake = 6, 258 Mem_Max, 259 } H264_Mem_type; 260 261 //!< decoder picture memory 262 typedef struct h264_dpb_mark_t { 263 RK_U8 top_used; 264 RK_U8 bot_used; 265 RK_U8 out_flag; 266 RK_U8 mark_idx; 267 MppFrame mframe; 268 RK_S32 slot_idx; 269 struct h264_store_pic_t *pic; 270 } H264_DpbMark_t; 271 272 //!< decoder picture buffer information 273 typedef struct h264_dpb_info_t { 274 RK_U8 colmv_is_used; 275 RK_S32 slot_index; 276 277 RK_S32 TOP_POC; 278 RK_S32 BOT_POC; 279 RK_U16 frame_num; 280 RK_U32 field_flag; 281 RK_U32 is_long_term; 282 RK_U32 is_ilt_flag; 283 RK_U32 long_term_frame_idx; 284 RK_U32 long_term_pic_num; 285 RK_U32 voidx; 286 RK_U32 view_id; 287 RK_U32 is_used; 288 RK_U32 top_valid; 289 RK_U32 bot_valid; 290 struct h264_store_pic_t *refpic; 291 292 RK_U32 have_same; 293 } H264_DpbInfo_t; 294 295 //!< refence picture information 296 typedef struct h264_refpic_info_t { 297 RK_U32 valid; 298 RK_S32 dpb_idx; 299 RK_S32 bottom_flag; 300 } H264_RefPicInfo_t; 301 302 //!< definition a picture (field or frame) 303 typedef struct h264_store_pic_t { 304 RK_S32 structure; 305 RK_S32 poc; 306 RK_S32 top_poc; 307 RK_S32 bottom_poc; 308 RK_S32 frame_poc; 309 RK_S32 ThisPOC; 310 RK_S32 pic_num; 311 RK_S32 long_term_pic_num; 312 RK_S32 long_term_frame_idx; 313 314 RK_U32 frame_num; 315 RK_U8 is_long_term; 316 RK_S32 used_for_reference; 317 RK_S32 is_output; 318 RK_S32 non_existing; 319 RK_S16 max_slice_id; 320 RK_S32 mb_aff_frame_flag; 321 RK_U32 PicWidthInMbs; 322 RK_U8 colmv_no_used_flag; 323 struct h264_store_pic_t *top_field; //!< for mb aff, if frame for referencing the top field 324 struct h264_store_pic_t *bottom_field; //!< for mb aff, if frame for referencing the bottom field 325 struct h264_store_pic_t *frame; //!< for mb aff, if field for referencing the combined frame 326 327 RK_S32 slice_type; 328 RK_S32 idr_flag; 329 RK_S32 no_output_of_prior_pics_flag; 330 RK_S32 long_term_reference_flag; 331 RK_S32 adaptive_ref_pic_buffering_flag; 332 RK_S32 chroma_format_idc; 333 RK_S32 frame_mbs_only_flag; 334 RK_S32 frame_cropping_flag; 335 336 RK_S32 frame_crop_left_offset; 337 RK_S32 frame_crop_right_offset; 338 RK_S32 frame_crop_top_offset; 339 RK_S32 frame_crop_bottom_offset; 340 RK_S32 width; 341 RK_S32 height; 342 RK_U32 width_after_crop; 343 RK_U32 height_after_crop; 344 345 struct h264_drpm_t *dec_ref_pic_marking_buffer; //!< stores the memory management control operations 346 RK_S32 proc_flag; 347 RK_S32 view_id; 348 RK_S32 inter_view_flag; 349 RK_S32 anchor_pic_flag; 350 RK_S32 iCodingType; 351 352 RK_S32 layer_id; 353 RK_U8 is_mmco_5; 354 RK_S32 poc_mmco5; 355 RK_S32 top_poc_mmco5; 356 RK_S32 bot_poc_mmco5; 357 RK_S32 combine_flag; // top && bottom field combined flag 358 H264_Mem_type mem_malloc_type; 359 struct h264_dpb_mark_t *mem_mark; 360 } H264_StorePic_t; 361 362 //!< Frame Stores for Decoded Picture Buffer 363 typedef struct h264_frame_store_t { 364 RK_S32 is_used; //!< 0=empty; 1=top; 2=bottom; 3=both fields (or frame) 365 RK_S32 is_reference; //!< 0=not used for ref; 1=top used; 2=bottom used; 3=both fields (or frame) used 366 RK_S32 is_long_term; //!< 0=not used for ref; 1=top used; 2=bottom used; 3=both fields (or frame) used 367 RK_S32 is_orig_reference; //!< original marking by nal_ref_idc: 0=not used for ref; 1=top used; 2=bottom used; 3=both fields (or frame) used 368 RK_S32 is_non_existent; 369 RK_S32 frame_num_wrap; 370 RK_S32 long_term_frame_idx; 371 RK_S32 is_output; 372 RK_S32 poc; 373 RK_S32 view_id; 374 RK_S32 inter_view_flag[2]; 375 RK_S32 anchor_pic_flag[2]; 376 RK_S32 layer_id; 377 RK_S32 slice_type; 378 RK_U32 frame_num; 379 RK_S32 structure; 380 RK_U32 is_directout; 381 struct h264_store_pic_t *frame; 382 struct h264_store_pic_t *top_field; 383 struct h264_store_pic_t *bottom_field; 384 385 } H264_FrameStore_t; 386 387 //!< decode picture buffer 388 typedef struct h264_dpb_buf_t { 389 RK_U32 size; 390 RK_U32 used_size; 391 RK_U32 allocated_size; 392 RK_U32 ref_frames_in_buffer; 393 RK_U32 ltref_frames_in_buffer; 394 RK_U32 used_size_il; 395 396 RK_S32 poc_interval; 397 RK_S32 last_output_poc; 398 RK_S32 last_output_view_id; 399 RK_S32 max_long_term_pic_idx; 400 RK_S32 init_done; 401 RK_S32 num_ref_frames; 402 RK_S32 layer_id; 403 404 struct h264_frame_store_t **fs; 405 struct h264_frame_store_t **fs_ref; 406 struct h264_frame_store_t **fs_ltref; 407 struct h264_frame_store_t **fs_ilref; //!< inter-layer reference (for multi-layered codecs) 408 struct h264_frame_store_t *last_picture; 409 410 struct h264d_video_ctx_t *p_Vid; 411 } H264_DpbBuf_t; 412 413 //!< HRD 414 #define MAXIMUMVALUEOFcpb_cnt 32 415 typedef struct h264_hrd_t { 416 RK_U32 cpb_cnt_minus1; // ue(v) 417 RK_U32 bit_rate_scale; // u(4) 418 RK_U32 cpb_size_scale; // u(4) 419 RK_U32 bit_rate_value_minus1[MAXIMUMVALUEOFcpb_cnt]; // ue(v) 420 RK_U32 cpb_size_value_minus1[MAXIMUMVALUEOFcpb_cnt]; // ue(v) 421 RK_U32 cbr_flag[MAXIMUMVALUEOFcpb_cnt]; // u(1) 422 RK_U32 initial_cpb_removal_delay_length_minus1; // u(5) 423 RK_U32 cpb_removal_delay_length_minus1; // u(5) 424 RK_U32 dpb_output_delay_length_minus1; // u(5) 425 RK_U32 time_offset_length; // u(5) 426 } H264_HRD_t; 427 428 //!< VUI 429 typedef struct h264_vui_t { 430 RK_S32 aspect_ratio_info_present_flag; // u(1) 431 RK_U32 aspect_ratio_idc; // u(8) 432 RK_U16 sar_width; // u(16) 433 RK_U16 sar_height; // u(16) 434 RK_S32 overscan_info_present_flag; // u(1) 435 RK_S32 overscan_appropriate_flag; // u(1) 436 RK_S32 video_signal_type_present_flag; // u(1) 437 RK_U32 video_format; // u(3) 438 RK_S32 video_full_range_flag; // u(1) 439 RK_S32 colour_description_present_flag; // u(1) 440 RK_U32 colour_primaries; // u(8) 441 RK_U32 transfer_characteristics; // u(8) 442 RK_U32 matrix_coefficients; // u(8) 443 RK_S32 chroma_location_info_present_flag; // u(1) 444 RK_U32 chroma_sample_loc_type_top_field; // ue(v) 445 RK_U32 chroma_sample_loc_type_bottom_field; // ue(v) 446 RK_S32 timing_info_present_flag; // u(1) 447 RK_U32 num_units_in_tick; // u(32) 448 RK_U32 time_scale; // u(32) 449 RK_S32 fixed_frame_rate_flag; // u(1) 450 RK_S32 nal_hrd_parameters_present_flag; // u(1) 451 struct h264_hrd_t nal_hrd_parameters; // hrd_paramters_t 452 RK_S32 vcl_hrd_parameters_present_flag; // u(1) 453 struct h264_hrd_t vcl_hrd_parameters; // hrd_paramters_t 454 // if ((nal_hrd_parameters_present_flag || (vcl_hrd_parameters_present_flag)) 455 RK_S32 low_delay_hrd_flag; // u(1) 456 RK_S32 pic_struct_present_flag; // u(1) 457 RK_S32 bitstream_restriction_flag; // u(1) 458 RK_S32 motion_vectors_over_pic_boundaries_flag; // u(1) 459 RK_U32 max_bytes_per_pic_denom; // ue(v) 460 RK_U32 max_bits_per_mb_denom; // ue(v) 461 RK_U32 log2_max_mv_length_vertical; // ue(v) 462 RK_U32 log2_max_mv_length_horizontal; // ue(v) 463 RK_U32 num_reorder_frames; // ue(v) 464 RK_U32 max_dec_frame_buffering; // ue(v) 465 } H264_VUI_t; 466 467 //!< MVC_VUI 468 typedef struct h264_mvc_vui_t { 469 RK_S32 num_ops_minus1; 470 RK_S8 *temporal_id; 471 RK_S32 *num_target_output_views_minus1; 472 RK_S32 **view_id; 473 RK_S8 *timing_info_present_flag; 474 RK_S32 *num_units_in_tick; 475 RK_S32 *time_scale; 476 RK_S8 *fixed_frame_rate_flag; 477 RK_S8 *nal_hrd_parameters_present_flag; 478 RK_S8 *vcl_hrd_parameters_present_flag; 479 RK_S8 *low_delay_hrd_flag; 480 RK_S8 *pic_struct_present_flag; 481 482 //hrd parameters; 483 RK_S8 cpb_cnt_minus1; 484 RK_S8 bit_rate_scale; 485 RK_S8 cpb_size_scale; 486 RK_S32 bit_rate_value_minus1[32]; 487 RK_S32 cpb_size_value_minus1[32]; 488 RK_S8 cbr_flag[32]; 489 RK_S8 initial_cpb_removal_delay_length_minus1; 490 RK_S8 cpb_removal_delay_length_minus1; 491 RK_S8 dpb_output_delay_length_minus1; 492 RK_S8 time_offset_length; 493 } H264_mvcVUI_t; 494 495 //!< PREFIX 496 497 typedef struct h264_prefix_t { 498 RK_S32 Valid; // indicates the prefix set is valid 499 // nal svc syntax 500 RK_S32 store_ref_base_pic_flag; // u(1) 501 // svc base pic marking 502 RK_S32 adaptive_ref_base_pic_marking_mode_flag; 503 RK_S32 memory_management_base_control_operation; 504 RK_S32 difference_of_base_pic_nums_minus1; 505 RK_S32 long_term_base_pic_num; 506 507 RK_S32 additional_prefix_nal_unit_extension_flag; // u(1) 508 RK_S32 additional_prefix_nal_unit_extension_data_flag; // u(1) 509 } H264_PREFIX_t; 510 511 //!< SPS 512 #define MAXnum_ref_frames_in_POC_cycle 256 513 514 typedef struct h264_sps_t { 515 RK_S32 Valid; // indicates the parameter set is valid 516 517 RK_S32 profile_idc; // u(8) 518 RK_S32 constrained_set0_flag; // u(1) 519 RK_S32 constrained_set1_flag; // u(1) 520 RK_S32 constrained_set2_flag; // u(1) 521 RK_S32 constrained_set3_flag; // u(1) 522 RK_S32 constrained_set4_flag; // u(1) 523 RK_S32 constrained_set5_flag; // u(2) 524 525 RK_S32 level_idc; // u(8) 526 RK_U32 seq_parameter_set_id; // ue(v) 527 RK_S32 chroma_format_idc; // ue(v) 528 529 RK_S32 seq_scaling_matrix_present_flag; // u(1) 530 RK_S32 seq_scaling_list_present_flag[12]; // u(1) 531 RK_S32 ScalingList4x4[6][H264ScalingList4x4Length]; // se(v) 532 RK_S32 ScalingList8x8[6][H264ScalingList8x8Length]; // se(v) 533 RK_S32 UseDefaultScalingMatrix4x4Flag[6]; 534 RK_S32 UseDefaultScalingMatrix8x8Flag[6]; 535 536 RK_S32 bit_depth_luma_minus8; // ue(v) 537 RK_S32 bit_depth_chroma_minus8; // ue(v) 538 RK_S32 log2_max_frame_num_minus4; // ue(v) 539 RK_S32 pic_order_cnt_type; 540 // if( pic_order_cnt_type == 0 ) 541 RK_S32 log2_max_pic_order_cnt_lsb_minus4; // ue(v) 542 // else if( pic_order_cnt_type == 1 ) 543 RK_S32 delta_pic_order_always_zero_flag; // u(1) 544 RK_S32 offset_for_non_ref_pic; // se(v) 545 RK_S32 offset_for_top_to_bottom_field; // se(v) 546 RK_S32 num_ref_frames_in_pic_order_cnt_cycle; // ue(v) 547 // for( i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++ ) 548 RK_S32 offset_for_ref_frame[MAXnum_ref_frames_in_POC_cycle]; // se(v) 549 RK_S32 max_num_ref_frames; // ue(v) 550 RK_S32 gaps_in_frame_num_value_allowed_flag; // u(1) 551 RK_S32 pic_width_in_mbs_minus1; // ue(v) 552 RK_S32 pic_height_in_map_units_minus1; // ue(v) 553 RK_S32 frame_mbs_only_flag; // u(1) 554 // if( !frame_mbs_only_flag ) 555 RK_S32 mb_adaptive_frame_field_flag; // u(1) 556 RK_S32 direct_8x8_inference_flag; // u(1) 557 RK_S32 frame_cropping_flag; // u(1) 558 RK_S32 frame_crop_left_offset; // ue(v) 559 RK_S32 frame_crop_right_offset; // ue(v) 560 RK_S32 frame_crop_top_offset; // ue(v) 561 RK_S32 frame_crop_bottom_offset; // ue(v) 562 RK_S32 vui_parameters_present_flag; // u(1) 563 struct h264_vui_t vui_seq_parameters; // vui_seq_parameters_t 564 RK_S32 separate_colour_plane_flag; // u(1) 565 RK_S32 max_dec_frame_buffering; 566 RK_S32 qpprime_y_zero_transform_bypass_flag; 567 //---- 568 RK_S32 expected_delta_per_pic_order_cnt_cycle; 569 570 } H264_SPS_t; 571 572 //!< subSPS 573 typedef struct h264_subsps_t { 574 struct h264_sps_t sps; 575 576 RK_S32 bit_equal_to_one; 577 RK_S32 num_views_minus1; 578 RK_S32 *view_id; 579 RK_S32 *num_anchor_refs_l0; 580 RK_S32 **anchor_ref_l0; 581 RK_S32 *num_anchor_refs_l1; 582 RK_S32 **anchor_ref_l1; 583 584 RK_S32 *num_non_anchor_refs_l0; 585 RK_S32 **non_anchor_ref_l0; 586 RK_S32 *num_non_anchor_refs_l1; 587 RK_S32 **non_anchor_ref_l1; 588 589 RK_S32 num_level_values_signalled_minus1; 590 RK_S32 *level_idc; 591 RK_S32 *num_applicable_ops_minus1; 592 RK_S32 **applicable_op_temporal_id; 593 RK_S32 **applicable_op_num_target_views_minus1; 594 RK_S32 ***applicable_op_target_view_id; 595 RK_S32 **applicable_op_num_views_minus1; 596 597 RK_S32 mvc_vui_parameters_present_flag; 598 RK_S32 Valid; // indicates the parameter set is valid 599 600 } H264_subSPS_t; 601 602 //!< PPS 603 604 typedef struct h264_pps_t { 605 RK_S32 Valid; // indicates the parameter set is valid 606 RK_U32 pic_parameter_set_id; // ue(v) 607 RK_U32 seq_parameter_set_id; // ue(v) 608 RK_S32 entropy_coding_mode_flag; // u(1) 609 RK_S32 transform_8x8_mode_flag; // u(1) 610 611 RK_S32 pic_scaling_matrix_present_flag; // u(1) 612 RK_S32 pic_scaling_list_present_flag[12]; // u(1) 613 RK_S32 ScalingList4x4[6][H264ScalingList4x4Length]; // se(v) 614 RK_S32 ScalingList8x8[6][H264ScalingList8x8Length]; // se(v) 615 RK_S32 UseDefaultScalingMatrix4x4Flag[6]; 616 RK_S32 UseDefaultScalingMatrix8x8Flag[6]; 617 618 // if( pic_order_cnt_type < 2 ) in the sequence parameter set 619 RK_S32 bottom_field_pic_order_in_frame_present_flag; // u(1) 620 RK_S32 num_slice_groups_minus1; // ue(v) 621 RK_S32 slice_group_map_type; // ue(v) 622 // if( slice_group_map_type = = 0 ) 623 RK_S32 run_length_minus1[MAXnum_slice_groups_minus1]; // ue(v) 624 // else if( slice_group_map_type = = 2 ) 625 RK_S32 top_left[MAXnum_slice_groups_minus1]; // ue(v) 626 RK_S32 bottom_right[MAXnum_slice_groups_minus1]; // ue(v) 627 // else if( slice_group_map_type = = 3 || 4 || 5 628 RK_S32 slice_group_change_direction_flag; // u(1) 629 RK_S32 slice_group_change_rate_minus1; // ue(v) 630 // else if( slice_group_map_type = = 6 ) 631 RK_S32 pic_size_in_map_units_minus1; // ue(v) 632 RK_U8 *slice_group_id; // complete MBAmap u(v) 633 634 RK_S32 num_ref_idx_l0_default_active_minus1; // ue(v) 635 RK_S32 num_ref_idx_l1_default_active_minus1; // ue(v) 636 RK_S32 weighted_pred_flag; // u(1) 637 RK_S32 weighted_bipred_idc; // u(2) 638 RK_S32 pic_init_qp_minus26; // se(v) 639 RK_S32 pic_init_qs_minus26; // se(v) 640 RK_S32 chroma_qp_index_offset; // se(v) 641 642 RK_S32 cb_qp_index_offset; // se(v) 643 RK_S32 cr_qp_index_offset; // se(v) 644 RK_S32 second_chroma_qp_index_offset; // se(v) 645 646 RK_S32 deblocking_filter_control_present_flag; // u(1) 647 RK_S32 constrained_intra_pred_flag; // u(1) 648 RK_S32 redundant_pic_cnt_present_flag; // u(1) 649 RK_S32 vui_pic_parameters_flag; // u(1) 650 RK_S32 scaleing_list_enable_flag; 651 RK_U32 scaleing_list_address; 652 653 } H264_PPS_t; 654 655 //!< MVC_scalable_nesting 656 typedef struct { 657 RK_S32 operation_point_flag; 658 RK_S32 all_view_components_in_au_flag; 659 RK_S32 num_view_components_minus1; 660 RK_S32 *sei_view_id; 661 RK_S32 num_view_components_op_minus1; 662 RK_S32 *sei_op_view_id; 663 RK_S32 sei_op_temporal_id; 664 RK_S32 Valid; 665 } MVC_scalable_nesting_t; 666 667 //!< MVC_scalability_info 668 typedef struct { 669 RK_S32 num_operation_points_minus1; 670 RK_S32 *operation_point_id; 671 RK_S32 *priority_id; 672 RK_S32 *temporal_id; 673 RK_S32 *num_target_output_views_minus1; 674 RK_S32 **view_id; 675 RK_S32 *profile_level_info_present_flag; 676 RK_S32 *bitrate_info_present_flag; 677 RK_S32 *frm_rate_info_present_flag; 678 679 RK_S32 *view_dependency_info_present_flag; 680 RK_S32 *parameter_sets_info_present_flag; 681 RK_S32 *bitstream_restriction_info_present_flag; 682 RK_S32 *op_profile_level_idc; 683 RK_S32 *avg_bitrate; 684 RK_S32 *max_bitrate; 685 RK_S32 *max_bitrate_calc_window; 686 RK_S32 *constant_frm_rate_idc; 687 RK_S32 *avg_frm_rate; 688 RK_S32 *num_directly_dependent_views; 689 RK_S32 **directly_dependent_view_id; 690 RK_S32 *view_dependency_info_src_op_id; 691 RK_S32 *num_seq_parameter_sets; 692 RK_S32 **seq_parameter_set_id_delta; 693 RK_S32 *num_subset_seq_parameter_sets; 694 RK_S32 **subset_seq_parameter_set_id_delta; 695 RK_S32 *num_pic_parameter_sets_minus1; 696 RK_S32 **pic_parameter_set_id_delta; 697 RK_S32 *parameter_sets_info_src_op_id; 698 RK_S32 *motion_vectors_over_pic_boundaries_flag; 699 RK_S32 *max_bytes_per_pic_denom; 700 RK_S32 *max_bits_per_mb_denom; 701 RK_S32 *log2_max_mv_length_horizontal; 702 RK_S32 *log2_max_mv_length_vertical; 703 RK_S32 *max_num_reorder_frames; 704 RK_S32 *max_dec_frame_buffering; 705 } MVC_scalability_info_t; 706 707 typedef struct h264_sei_pic_timing_t { 708 RK_S32 cpb_removal_delay; 709 RK_S32 dpb_output_delay; 710 RK_S32 pic_struct; 711 RK_S32 clock_timestamp_flag[3]; 712 RK_S32 clock_timestamp[3]; 713 RK_S32 ct_type[3]; 714 RK_S32 nuit_field_based_flag[3]; 715 RK_S32 counting_type[3]; 716 RK_S32 full_timestamp_flag[3]; 717 RK_S32 discontinuity_flag[3]; 718 RK_S32 cnt_dropped_flag[3]; 719 RK_S32 n_frames[3]; 720 RK_S32 seconds_flag[3]; 721 RK_S32 seconds_value[3]; 722 RK_S32 minutes_flag[3]; 723 RK_S32 minutes_value[3]; 724 RK_S32 hours_flag[3]; 725 RK_S32 hours_value[3]; 726 RK_S32 time_offset[3]; 727 } H264_SEI_PIC_TIMING_t; 728 729 //!< SEI struct 730 typedef struct h264_sei_t { 731 RK_S32 type; 732 RK_S32 payload_size; 733 struct { 734 RK_U32 recovery_frame_cnt; 735 RK_S32 exact_match_flag; 736 RK_S32 broken_link_flag; 737 RK_S32 changing_slice_group_idc; 738 } recovery_point; 739 struct { 740 RK_S32 operation_point_flag; 741 //-- for adding 742 } scalable_nesting; 743 744 // Placeholder; in future more supported types will contribute to more 745 //---- follow is used in other parts 746 RK_S32 mvc_scalable_nesting_flag; 747 RK_U32 seq_parameter_set_id; 748 749 H264_SEI_PIC_TIMING_t pic_timing; 750 751 struct h264_dec_ctx_t *p_Dec; 752 } H264_SEI_t; 753 754 //!< SLICE 755 typedef struct h264_slice_t { 756 struct h264_nalu_svc_ext_t svcExt; 757 struct h264_nalu_mvc_ext_t mvcExt; 758 //--- slice property; 759 RK_S32 layer_id; 760 RK_S32 idr_flag; 761 RK_S32 idr_pic_id; 762 RK_S32 nal_reference_idc; //!< nal_reference_idc from NAL unit 763 RK_U32 start_mb_nr; //!< MUST be set by NAL even in case of ei_flag == 1 764 RK_S32 slice_type; //!< slice type 765 RK_U32 pic_parameter_set_id; 766 RK_S32 colour_plane_id; 767 RK_S32 frame_num; 768 RK_S32 field_pic_flag; 769 RK_S32 bottom_field_flag; 770 RK_S32 structure; 771 RK_S32 mb_aff_frame_flag; 772 RK_S32 pic_order_cnt_lsb; // for poc mode 0 773 RK_S32 delta_pic_order_cnt_bottom; 774 RK_S32 delta_pic_order_cnt[2]; // for poc mode 1 775 RK_U32 poc_used_bitlen; 776 RK_S32 redundant_pic_cnt; 777 RK_S32 direct_spatial_mv_pred_flag; 778 RK_S32 num_ref_idx_active[2]; //!< number of available list references 779 RK_S32 num_ref_idx_override_flag; 780 RK_S32 ref_pic_list_reordering_flag[2]; 781 RK_S32 *modification_of_pic_nums_idc[2]; 782 RK_S32 *abs_diff_pic_num_minus1[2]; 783 RK_S32 *long_term_pic_idx[2]; 784 RK_S32 *abs_diff_view_idx_minus1[2]; 785 struct h264_drpm_t *dec_ref_pic_marking_buffer; 786 RK_U32 drpm_used_bitlen; 787 RK_S32 no_output_of_prior_pics_flag; 788 RK_S32 long_term_reference_flag; 789 RK_S32 adaptive_ref_pic_buffering_flag; 790 RK_U32 model_number; 791 RK_S32 slice_qp_delta; 792 RK_S32 qp; 793 RK_S32 current_mb_nr; 794 RK_S32 ThisPOC; 795 RK_S32 toppoc; //poc for this top field 796 RK_S32 bottompoc; //poc of bottom field of frame 797 RK_S32 framepoc; //poc of this frame 798 RK_U32 AbsFrameNum; 799 RK_S32 PicOrderCntMsb; 800 //RK_S32 new_frame_flag; 801 struct h264_sps_t *active_sps; 802 struct h264_subsps_t *active_subsps; 803 struct h264_pps_t *active_pps; 804 805 struct h264_dpb_buf_t *p_Dpb; 806 struct h264_dpb_buf_t *p_Dpb_layer[MAX_NUM_DPB_LAYERS]; 807 //---- 808 RK_S32 listinterviewidx0; 809 RK_S32 listinterviewidx1; 810 811 RK_U8 listXsizeP[2]; 812 RK_U8 listXsizeB[2]; 813 814 struct h264_frame_store_t **fs_listinterview0; 815 struct h264_frame_store_t **fs_listinterview1; 816 //struct h264_store_pic_t **listX[6]; 817 struct h264_store_pic_t **listP[MAX_NUM_DPB_LAYERS]; 818 struct h264_store_pic_t **listB[MAX_NUM_DPB_LAYERS]; 819 820 //---- MVC extend ---- 821 RK_S32 svc_extension_flag; // should be always 0, for MVC 822 RK_S32 non_idr_flag; // 0 = current is IDR 823 RK_S32 priority_id; // a lower value of priority_id specifies a higher priority 824 RK_S32 view_id; // view identifier for the NAL unit 825 RK_S32 temporal_id; // temporal identifier for the NAL unit 826 RK_S32 anchor_pic_flag; // anchor access unit 827 RK_S32 inter_view_flag; // inter-view prediction enable 828 RK_S32 reserved_one_bit; // shall be equal to 1 829 RK_S32 MVCExt_is_valid; 830 RK_S32 MVCExt_is_prefixNALU; 831 832 struct h264_dec_ctx_t *p_Dec; // H264_DecCtx_t 833 struct h264d_input_ctx_t *p_Inp; // H264_InputParameters 834 struct h264d_cur_ctx_t *p_Cur; // H264_CurParameters 835 struct h264d_video_ctx_t *p_Vid; 836 } H264_SLICE_t; 837 838 //!< Old slice parameter for check new frame 839 typedef struct h264_old_slice_par_t { 840 RK_U32 current_mb_nr; 841 RK_U8 field_pic_flag; 842 RK_U8 frame_num; 843 RK_S32 nal_ref_idc; 844 RK_U8 pic_oder_cnt_lsb; 845 RK_S32 delta_pic_oder_cnt_bottom; 846 RK_S32 delta_pic_order_cnt[2]; 847 RK_U8 bottom_field_flag; 848 RK_U8 idr_flag; 849 RK_S32 idr_pic_id; 850 RK_U32 pps_id; 851 RK_S32 view_id; 852 RK_S32 inter_view_flag; 853 RK_S32 anchor_pic_flag; 854 RK_S32 layer_id; 855 } H264_OldSlice_t; 856 857 //!< DXVA context 858 #define MAX_SLICE_NUM (20) 859 #define ADD_SLICE_SIZE (5) 860 #define BITSTREAM_MAX_SIZE (2*1024*1024) 861 #define BITSTREAM_ADD_SIZE (512) 862 #define SYNTAX_BUF_SIZE (5) 863 typedef struct h264d_dxva_ctx_t { 864 RK_U8 cfgBitstrmRaw; 865 struct _DXVA_PicParams_H264_MVC pp; 866 struct _DXVA_Qmatrix_H264 qm; 867 RK_U32 max_slice_size; 868 RK_U32 slice_count; 869 struct _DXVA_Slice_H264_Long *slice_long; //!< MAX_SLICES 870 RK_U8 *bitstream; 871 RK_U32 max_strm_size; 872 RK_U32 strm_offset; 873 struct h264d_syntax_t syn; 874 struct h264_dec_ctx_t *p_Dec; 875 } H264dDxvaCtx_t; 876 877 //!< input parameter 878 typedef struct h264d_input_ctx_t { 879 struct h264_dec_ctx_t *p_Dec; 880 struct h264d_cur_ctx_t *p_Cur; //!< current parameters, use in read nalu 881 struct h264d_video_ctx_t *p_Vid; //!< parameters for video decoder 882 enum mpp_decmtd_type dec_mtd; 883 884 //!< input data 885 RK_U8 *in_buf; 886 size_t in_length; 887 RK_U32 pkt_eos; 888 889 MppPacket in_pkt; 890 891 RK_S64 in_pts; 892 RK_S64 in_dts; 893 RK_U8 has_get_eos; 894 RK_U32 max_buf_size; 895 //!< output data 896 RK_U8 task_valid; 897 RK_U32 task_eos; 898 899 //!< have extradata 900 RK_U8 is_nalff; 901 RK_U8 profile; 902 RK_U8 level; 903 RK_U32 nal_size; 904 RK_S32 sps_num; 905 RK_S32 pps_num; 906 //!< write stream 907 char fname[2][512]; 908 FILE *fp; 909 RK_U8 *spspps_buf; 910 RK_U32 spspps_size; 911 RK_U32 spspps_len; 912 RK_U32 spspps_offset; 913 RK_U32 spspps_update_flag; 914 915 } H264dInputCtx_t; 916 917 918 //!< current stream 919 typedef struct h264d_curstrm_t { 920 RK_U32 nalu_offset; //!< The offset of the input stream 921 RK_U32 nalu_max_size; //!< Cur Unit Buffer size 922 RK_U8 *curdata; 923 924 RK_S32 nalu_type; 925 RK_U32 nalu_len; 926 RK_U8 *nalu_buf; //!< store read nalu data 927 928 RK_U32 head_offset; 929 RK_U32 head_max_size; 930 RK_U8 *head_buf; //!< store header data, sps/pps/slice header 931 932 RK_U32 first_mb_in_slice; //!< mark current slice 933 RK_U32 tmp_offset; 934 RK_U32 tmp_max_size; 935 RK_U8 *tmp_buf; //!< store temporary header data 936 937 RK_U32 prefixdata; 938 RK_U8 startcode_found; 939 RK_U8 endcode_found; 940 941 } H264dCurStream_t; 942 943 #define MAX_REORDER_TIMES 33 // MVC: 2 * H264_MAX_REFS + 1 944 #define MAX_MARKING_TIMES 35 945 //!< current parameters 946 typedef struct h264d_cur_ctx_t { 947 struct h264_sps_t sps; 948 struct h264_subsps_t *subsps; 949 struct h264_pps_t pps; 950 struct h264_prefix_t prefix; 951 struct h264_sei_t *sei; 952 struct h264_nalu_t nalu; 953 struct bitread_ctx_t bitctx; //!< for control bit_read 954 struct h264d_curstrm_t strm; 955 struct h264_slice_t slice; 956 957 struct h264_store_pic_t **listP[MAX_NUM_DPB_LAYERS]; 958 struct h264_store_pic_t **listB[MAX_NUM_DPB_LAYERS]; 959 struct h264d_input_ctx_t *p_Inp; 960 struct h264_dec_ctx_t *p_Dec; 961 struct h264d_video_ctx_t *p_Vid; //!< parameters for video decoder 962 963 RK_S64 last_pts; 964 RK_S64 last_dts; 965 RK_S64 curr_pts; 966 RK_S64 curr_dts; 967 //!< malloc buffer for current slice 968 RK_S32 modification_of_pic_nums_idc[2][MAX_REORDER_TIMES]; 969 RK_S32 abs_diff_pic_num_minus1[2][MAX_REORDER_TIMES]; 970 RK_S32 long_term_pic_idx[2][MAX_REORDER_TIMES]; 971 RK_S32 abs_diff_view_idx_minus1[2][MAX_REORDER_TIMES]; 972 973 struct h264_drpm_t *dec_ref_pic_marking_buffer[MAX_MARKING_TIMES]; 974 MppFrameHdrDynamicMeta *hdr_dynamic_meta; 975 RK_U32 hdr_dynamic; 976 } H264dCurCtx_t; 977 978 //!< parameters for video decoder 979 typedef struct h264d_video_ctx_t { 980 struct h264_sps_t *spsSet[MAXSPS]; //!< MAXSPS, all sps storage 981 struct h264_subsps_t *subspsSet[MAXSPS]; //!< MAXSPS, all subpps storage 982 struct h264_pps_t *ppsSet[MAXPPS]; //!< MAXPPS, all pps storage 983 struct h264_sps_t *active_sps; 984 struct h264_subsps_t *active_subsps; 985 struct h264_pps_t *active_pps; 986 struct h264_dec_ctx_t *p_Dec; //!< H264_DecCtx_t 987 struct h264d_input_ctx_t *p_Inp; //!< H264_InputParameters 988 struct h264d_cur_ctx_t *p_Cur; //!< H264_CurParameters 989 struct h264_dpb_buf_t *p_Dpb_layer[MAX_NUM_DPB_LAYERS]; 990 struct h264_store_pic_t *dec_pic; //!< current decoder picture 991 struct h264_store_pic_t *last_pic; 992 993 struct h264_store_pic_t *no_ref_pic; //!< no reference picture 994 struct h264_frame_store_t out_buffer; 995 struct h264_dpb_mark_t *active_dpb_mark[MAX_NUM_DPB_LAYERS]; //!< acitve_dpb_memory 996 997 struct h264_store_pic_t old_pic; 998 999 RK_S32 *qmatrix[12]; //!< scanlist pointer 1000 RK_U32 stream_size; 1001 RK_S32 last_toppoc[MAX_NUM_DPB_LAYERS]; 1002 RK_S32 last_bottompoc[MAX_NUM_DPB_LAYERS]; 1003 RK_S32 last_framepoc[MAX_NUM_DPB_LAYERS]; 1004 RK_S32 last_thispoc[MAX_NUM_DPB_LAYERS]; 1005 //!< 1006 RK_S32 profile_idc; // u(8) 1007 RK_S32 slice_type; 1008 RK_S32 structure; 1009 RK_S32 iNumOfSlicesDecoded; 1010 RK_S32 no_output_of_prior_pics_flag; 1011 RK_S32 last_has_mmco_5; 1012 RK_S32 max_frame_num; 1013 RK_U32 active_sps_id[MAX_NUM_DPB_LAYERS]; 1014 RK_U32 PicWidthInMbs; 1015 RK_U32 FrameHeightInMbs; 1016 RK_S32 frame_mbs_only_flag; 1017 RK_S32 yuv_format; 1018 RK_U32 bit_depth_chroma; 1019 RK_U32 bit_depth_luma; 1020 RK_S32 width; 1021 RK_S32 height; 1022 RK_U32 width_after_crop; 1023 RK_U32 height_after_crop; 1024 RK_S32 width_cr; //!< width chroma 1025 RK_S32 height_cr; //!< height chroma 1026 RK_S32 last_pic_structure; 1027 RK_S32 last_pic_bottom_field; 1028 RK_S32 last_pic_width_in_mbs_minus1[2]; 1029 RK_S32 last_pic_height_in_map_units_minus1[2]; 1030 RK_S32 last_profile_idc[2]; 1031 RK_S32 last_level_idc[2]; 1032 RK_U32 last_sps_id; 1033 RK_U32 last_pps_id; 1034 RK_S32 PrevPicOrderCntMsb; 1035 RK_S32 PrevPicOrderCntLsb; 1036 RK_U32 PreviousFrameNum; 1037 RK_U32 FrameNumOffset; 1038 RK_S32 PreviousFrameNumOffset; 1039 RK_S32 ExpectedDeltaPerPicOrderCntCycle; 1040 RK_S32 ExpectedPicOrderCnt; 1041 RK_S32 PicOrderCntCycleCnt; 1042 RK_S32 FrameNumInPicOrderCntCycle; 1043 RK_S32 ThisPOC; 1044 RK_S32 type; 1045 //!< for control running 1046 RK_S32 have_outpicture_flag; 1047 RK_S32 exit_picture_flag; 1048 RK_S32 active_mvc_sps_flag; 1049 //!< for error tolerance 1050 RK_U32 g_framecnt; 1051 RK_U32 dpb_size[MAX_NUM_DPB_LAYERS]; 1052 1053 MppMemPool pic_st; 1054 //!< spspps data update 1055 RK_U32 spspps_update; 1056 1057 RK_U32 dpb_fast_out; 1058 RK_U32 dpb_first_fast_played; 1059 RK_U32 last_ref_frame_num; 1060 RK_U32 deny_flag; 1061 RecoveryPoint recovery; 1062 } H264dVideoCtx_t; 1063 1064 typedef struct h264d_mem_t { 1065 struct h264_dpb_mark_t dpb_mark[MAX_MARK_SIZE]; //!< for fpga register check, dpb mark 1066 struct h264_dpb_info_t dpb_info[MAX_DPB_SIZE]; //!< 16 1067 struct h264_refpic_info_t refpic_info_p[MAX_REF_SIZE]; //!< 32 1068 struct h264_refpic_info_t refpic_info_b[2][MAX_REF_SIZE]; //!< [2][32] 1069 struct h264d_dxva_ctx_t dxva_ctx; 1070 } H264_DecMem_t; 1071 1072 //!< nalu state used in read nalu 1073 typedef enum nalu_state_tpye { 1074 NALU_NULL = 0, 1075 1076 StreamError, 1077 HaveNoStream, 1078 NaluNotSupport, 1079 ReadNaluError, 1080 StartofNalu, 1081 EndofStream, 1082 MvcDisAble, 1083 MidOfNalu, 1084 EndOfNalu, 1085 StartOfPicture, 1086 StartOfSlice, 1087 SkipNALU, 1088 NALU_SPS, 1089 NALU_SubSPS, 1090 NALU_PPS, 1091 NALU_SEI, 1092 1093 NALU_MAX, 1094 } NALU_STATUS; 1095 1096 //!< slice state used in parse loop 1097 typedef enum slice_state_type { 1098 SliceSTATE_NULL = 0, 1099 SliceSTATE_IDLE, 1100 1101 SliceSTATE_ResetSlice, 1102 SliceSTATE_ReadNalu, 1103 SliceSTATE_ParseNalu, 1104 SliceSTATE_InitPicture, 1105 ////SliceSTATE_InitSlice, 1106 SliceSTATE_GetSliceData, 1107 //SliceSTATE_RegisterOneSlice, 1108 SliceSTATE_RegisterOneFrame, 1109 SliceSTATE_Error, 1110 SliceSTATE_MAX, 1111 1112 } SLICE_STATUS; 1113 1114 typedef struct h264_err_ctx_t { 1115 RK_U32 un_spt_flag; 1116 RK_U32 cur_err_flag; //!< current decoded picture error 1117 RK_U32 used_ref_flag; 1118 RK_U32 dpb_err_flag; //!< dpb storage had error 1119 1120 RK_U32 i_slice_no; 1121 RK_S32 first_iframe_poc; 1122 RK_S32 first_iframe_is_output; 1123 } H264dErrCtx_t; 1124 //!< decoder video parameter 1125 typedef struct h264_dec_ctx_t { 1126 struct h264d_mem_t *mem; 1127 struct h264_dpb_mark_t *dpb_mark; //!< for write out, MAX_DPB_SIZE 1128 struct h264_dpb_info_t *dpb_info; //!< 16 1129 struct h264_refpic_info_t *refpic_info_p; //!< 32 1130 struct h264_refpic_info_t *refpic_info_b[2]; //!< [2][32] 1131 struct h264d_dxva_ctx_t *dxva_ctx; 1132 1133 struct h264d_input_ctx_t *p_Inp; 1134 struct h264d_cur_ctx_t *p_Cur; //!< current parameters, use in read nalu 1135 struct h264d_video_ctx_t *p_Vid; //!< parameters for video decoder 1136 RK_U32 spt_decode_mtds; //!< support decoder methods 1137 NALU_STATUS nalu_ret; //!< current nalu state 1138 SLICE_STATUS next_state; //!< RKV_SLICE_STATUS 1139 RK_U8 have_slice_data; 1140 RK_U8 is_new_frame; 1141 RK_U8 is_parser_end; 1142 RK_U8 svc_valid; 1143 RK_U8 mvc_valid; 1144 //!< add 1145 MppBufSlots frame_slots; //!< corresponding to dpb_mark 1146 MppBufSlots packet_slots; 1147 MppDecCfgSet *cfg; 1148 const MppDecHwCap *hw_info; 1149 1150 MppFrame curframe; 1151 MppPacket task_pkt; 1152 1153 RK_S64 task_pts; 1154 RK_U32 task_eos; 1155 HalDecTask *in_task; 1156 RK_S32 last_frame_slot_idx; 1157 RK_U32 immediate_out; 1158 struct h264_err_ctx_t errctx; 1159 } H264_DecCtx_t; 1160 1161 #endif /* __H264D_GLOBAL_H__ */ 1162