1 //#define H264_PARSE_SLICE_HDR 2 //#ifdef H264_PARSE_SLICE_HDR 3 4 #include "h264.h" 5 #include "h264parse.h" 6 7 extern int32_t viddec_pm_get_au_pos(void *parent, uint32_t *bit, uint32_t *byte, unsigned char *is_emul); 8 9 10 /*-----------------------------------------------------------------------------------------*/ 11 // Slice header 1---- 12 // 1) first_mb_in_slice, slice_type, pic_parameter_id 13 /*-----------------------------------------------------------------------------------------*/ 14 h264_Status h264_Parse_Slice_Header_1(void *parent,h264_Info* pInfo, h264_Slice_Header_t *SliceHeader) 15 { 16 h264_Status ret = H264_STATUS_ERROR; 17 18 //h264_Slice_Header_t* SliceHeader = &pInfo->SliceHeader; 19 int32_t slice_type =0; 20 uint32_t data =0; 21 22 do { 23 ///// first_mb_in_slice 24 SliceHeader->first_mb_in_slice = h264_GetVLCElement(parent, pInfo, false); 25 26 ///// slice_type 27 slice_type = h264_GetVLCElement(parent, pInfo, false); 28 SliceHeader->slice_type = (slice_type%5); 29 30 if(SliceHeader->slice_type > h264_PtypeI) { 31 ret = H264_STATUS_NOTSUPPORT; 32 break; 33 } 34 35 36 ////// pic_parameter_id 37 data = h264_GetVLCElement(parent, pInfo, false); 38 if(data > MAX_PIC_PARAMS) { 39 ret = H264_PPS_INVALID_PIC_ID; 40 break; 41 } 42 SliceHeader->pic_parameter_id = (uint8_t)data; 43 ret = H264_STATUS_OK; 44 }while(0); 45 46 return ret; 47 } 48 49 /*-----------------------------------------------------------------------------------------*/ 50 // slice header 2 51 // frame_num 52 // field_pic_flag, structure 53 // idr_pic_id 54 // pic_order_cnt_lsb, delta_pic_order_cnt_bottom 55 /*-----------------------------------------------------------------------------------------*/ 56 57 h264_Status h264_Parse_Slice_Header_2(void *parent, h264_Info* pInfo, h264_Slice_Header_t *SliceHeader) 58 { 59 h264_Status ret = H264_SliceHeader_ERROR; 60 61 //h264_Slice_Header_t* SliceHeader = &pInfo->SliceHeader; 62 uint32_t code; 63 int32_t max_mb_num=0; 64 65 do { 66 //////////////////////////////////// Slice header part 2////////////////// 67 68 /// Frame_num 69 viddec_pm_get_bits(parent, &code, pInfo->active_SPS.log2_max_frame_num_minus4+4); 70 SliceHeader->frame_num = (int32_t)code; 71 72 /// Picture structure 73 SliceHeader->structure = FRAME; 74 SliceHeader->field_pic_flag = 0; 75 SliceHeader->bottom_field_flag = 0; 76 77 if(!(pInfo->active_SPS.sps_disp.frame_mbs_only_flag)) 78 { 79 /// field_pic_flag 80 viddec_pm_get_bits(parent, &code, 1); 81 SliceHeader->field_pic_flag = (uint8_t)code; 82 83 if(SliceHeader->field_pic_flag) 84 { 85 viddec_pm_get_bits(parent, &code, 1); 86 SliceHeader->bottom_field_flag = (uint8_t)code; 87 88 SliceHeader->structure = SliceHeader->bottom_field_flag? BOTTOM_FIELD: TOP_FIELD; 89 } 90 } 91 92 ////// Check valid or not of first_mb_in_slice 93 if(SliceHeader->structure == FRAME) { 94 max_mb_num = pInfo->img.FrameHeightInMbs * pInfo->img.PicWidthInMbs; 95 } else { 96 max_mb_num = pInfo->img.FrameHeightInMbs * pInfo->img.PicWidthInMbs/2; 97 } 98 99 100 ///if(pInfo->img.MbaffFrameFlag) 101 if(pInfo->active_SPS.sps_disp.mb_adaptive_frame_field_flag & (!(pInfo->SliceHeader.field_pic_flag))) { 102 SliceHeader->first_mb_in_slice <<=1; 103 } 104 105 if(SliceHeader->first_mb_in_slice >= max_mb_num) 106 break; 107 108 109 if(pInfo->nal_unit_type == h264_NAL_UNIT_TYPE_IDR) 110 { 111 SliceHeader->idr_pic_id = h264_GetVLCElement(parent, pInfo, false); 112 } 113 114 if(pInfo->active_SPS.pic_order_cnt_type == 0) 115 { 116 viddec_pm_get_bits(parent, &code , pInfo->active_SPS.log2_max_pic_order_cnt_lsb_minus4+4); 117 SliceHeader->pic_order_cnt_lsb = (uint32_t)code; 118 119 120 if((pInfo->active_PPS.pic_order_present_flag) && !(SliceHeader->field_pic_flag)) 121 { 122 SliceHeader->delta_pic_order_cnt_bottom = h264_GetVLCElement(parent, pInfo, true); 123 } 124 else 125 { 126 SliceHeader->delta_pic_order_cnt_bottom = 0; 127 } 128 } 129 130 if((pInfo->active_SPS.pic_order_cnt_type == 1) && !(pInfo->active_SPS.delta_pic_order_always_zero_flag)) 131 { 132 SliceHeader->delta_pic_order_cnt[0] = h264_GetVLCElement(parent, pInfo, true); 133 if((pInfo->active_PPS.pic_order_present_flag) && !(SliceHeader->field_pic_flag)) 134 { 135 SliceHeader->delta_pic_order_cnt[1] = h264_GetVLCElement(parent, pInfo, true); 136 } 137 } 138 139 if(pInfo->active_PPS.redundant_pic_cnt_present_flag) 140 { 141 SliceHeader->redundant_pic_cnt = h264_GetVLCElement(parent, pInfo, false); 142 if(SliceHeader->redundant_pic_cnt > 127) 143 break; 144 } else { 145 SliceHeader->redundant_pic_cnt = 0; 146 } 147 148 ret = H264_STATUS_OK; 149 } while (0); 150 151 //////////// FMO is not supported curently, so comment out the following code 152 //if((pInfo->active_PPS.num_slice_groups_minus1 > 0) && (pInfo->active_PPS.slice_group_map_type >= 3) && (pInfo->active_PPS.slice_group_map_type <= 5) ) 153 //{ 154 // SliceHeader->slice_group_change_cycle = 0; //one of the variables is not known in the high profile 155 //} 156 157 return ret; 158 } 159 160 /*-----------------------------------------------------------------------------------------*/ 161 // slice header 3 162 // (direct_spatial_mv_pred_flag, num_ref_idx, pic_list_reorder, PWT, ref_pic_remark, alpha, beta, etc) 163 /*-----------------------------------------------------------------------------------------*/ 164 165 h264_Status h264_Parse_Slice_Header_3(void *parent, h264_Info* pInfo, h264_Slice_Header_t *SliceHeader) 166 { 167 h264_Status ret = H264_SliceHeader_ERROR; 168 169 //h264_Slice_Header_t* SliceHeader = &pInfo->SliceHeader; 170 int32_t slice_alpha_c0_offset, slice_beta_offset; 171 uint32_t code; 172 uint32_t bits_offset =0, byte_offset =0; 173 uint8_t is_emul =0; 174 175 do { 176 /// direct_spatial_mv_pred_flag 177 if(SliceHeader->slice_type == h264_PtypeB) 178 { 179 viddec_pm_get_bits(parent, &code , 1); 180 SliceHeader->direct_spatial_mv_pred_flag = (uint8_t)code; 181 } 182 else 183 { 184 SliceHeader->direct_spatial_mv_pred_flag = 0; 185 } 186 187 // 188 // Reset ref_idx and Overide it if exist 189 // 190 SliceHeader->num_ref_idx_l0_active = pInfo->active_PPS.num_ref_idx_l0_active; 191 SliceHeader->num_ref_idx_l1_active = pInfo->active_PPS.num_ref_idx_l1_active; 192 193 if((SliceHeader->slice_type == h264_PtypeP) || (SliceHeader->slice_type == h264_PtypeSP) || (SliceHeader->slice_type == h264_PtypeB)) 194 { 195 viddec_pm_get_bits(parent, &code, 1); 196 SliceHeader->num_ref_idx_active_override_flag = (uint8_t)code; 197 198 if(SliceHeader->num_ref_idx_active_override_flag) 199 { 200 SliceHeader->num_ref_idx_l0_active = h264_GetVLCElement(parent, pInfo, false) + 1; 201 if(SliceHeader->slice_type == h264_PtypeB) 202 { 203 SliceHeader->num_ref_idx_l1_active = h264_GetVLCElement(parent, pInfo, false)+1; 204 } 205 } 206 } 207 208 if(SliceHeader->slice_type != h264_PtypeB) { 209 SliceHeader->num_ref_idx_l1_active = 0; 210 } 211 212 if((SliceHeader->num_ref_idx_l0_active > MAX_NUM_REF_FRAMES) || (SliceHeader->num_ref_idx_l1_active > MAX_NUM_REF_FRAMES)) 213 { 214 break; 215 } 216 217 if(h264_Parse_Ref_Pic_List_Reordering(parent, pInfo, SliceHeader) != H264_STATUS_OK) 218 { 219 break; 220 } 221 222 223 //// 224 //// Parse Pred_weight_table but not store it becasue it will be reparsed in HW 225 //// 226 if(((pInfo->active_PPS.weighted_pred_flag) && ((SliceHeader->slice_type == h264_PtypeP) || (SliceHeader->slice_type == h264_PtypeSP))) || ((pInfo->active_PPS.weighted_bipred_idc == 1) && (SliceHeader->slice_type == h264_PtypeB))) 227 { 228 229 viddec_pm_get_au_pos(parent, &bits_offset, &byte_offset, &is_emul); 230 231 pInfo->h264_pwt_enabled = 1; 232 pInfo->h264_pwt_start_byte_offset = byte_offset; 233 pInfo->h264_pwt_start_bit_offset = bits_offset; 234 235 if(h264_Parse_Pred_Weight_Table(parent, pInfo, SliceHeader) != H264_STATUS_OK) 236 { 237 break; 238 } 239 240 viddec_pm_get_au_pos(parent, &bits_offset, &byte_offset, &is_emul); 241 242 if(0 == bits_offset) 243 { 244 pInfo->h264_pwt_end_byte_offset = byte_offset-1; 245 pInfo->h264_pwt_end_bit_offset = 8; 246 } 247 else 248 { 249 pInfo->h264_pwt_end_byte_offset = byte_offset; 250 pInfo->h264_pwt_end_bit_offset = bits_offset; 251 } 252 253 } 254 255 256 257 //// 258 //// Parse Ref_pic marking if there 259 //// 260 if(SliceHeader->nal_ref_idc != 0) 261 { 262 if(h264_Parse_Dec_Ref_Pic_Marking(parent, pInfo, SliceHeader) != H264_STATUS_OK) 263 { 264 break; 265 } 266 } 267 268 if((pInfo->active_PPS.entropy_coding_mode_flag) && (SliceHeader->slice_type != h264_PtypeI) && (SliceHeader->slice_type != h264_PtypeSI)) 269 { 270 SliceHeader->cabac_init_idc = h264_GetVLCElement(parent, pInfo, false); 271 } 272 else 273 { 274 SliceHeader->cabac_init_idc = 0; 275 } 276 277 if(SliceHeader->cabac_init_idc > 2) 278 { 279 break; 280 } 281 282 SliceHeader->slice_qp_delta = h264_GetVLCElement(parent, pInfo, true); 283 if( (SliceHeader->slice_qp_delta > (25-pInfo->active_PPS.pic_init_qp_minus26)) || (SliceHeader->slice_qp_delta < -(26+pInfo->active_PPS.pic_init_qp_minus26))) 284 break; 285 286 287 if((SliceHeader->slice_type == h264_PtypeSP)|| (SliceHeader->slice_type == h264_PtypeSI) ) 288 { 289 if(SliceHeader->slice_type == h264_PtypeSP) 290 { 291 viddec_pm_get_bits(parent, &code, 1); 292 SliceHeader->sp_for_switch_flag = (uint8_t)code; 293 294 } 295 SliceHeader->slice_qs_delta = h264_GetVLCElement(parent, pInfo, true); 296 297 if( (SliceHeader->slice_qs_delta > (25-pInfo->active_PPS.pic_init_qs_minus26)) || (SliceHeader->slice_qs_delta < -(26+pInfo->active_PPS.pic_init_qs_minus26)) ) 298 break; 299 } 300 301 if(pInfo->active_PPS.deblocking_filter_control_present_flag) 302 { 303 SliceHeader->disable_deblocking_filter_idc = h264_GetVLCElement(parent, pInfo, false); 304 if(SliceHeader->disable_deblocking_filter_idc != 1) 305 { 306 SliceHeader->slice_alpha_c0_offset_div2 = h264_GetVLCElement(parent, pInfo, true); 307 slice_alpha_c0_offset = SliceHeader->slice_alpha_c0_offset_div2 << 1; 308 if (slice_alpha_c0_offset < -12 || slice_alpha_c0_offset > 12) { 309 break; 310 } 311 312 SliceHeader->slice_beta_offset_div2 = h264_GetVLCElement(parent, pInfo, true); 313 slice_beta_offset = SliceHeader->slice_beta_offset_div2 << 1; 314 if (slice_beta_offset < -12 || slice_beta_offset > 12) { 315 break; 316 } 317 } 318 else 319 { 320 SliceHeader->slice_alpha_c0_offset_div2 = 0; 321 SliceHeader->slice_beta_offset_div2 = 0; 322 } 323 } 324 325 ret = H264_STATUS_OK; 326 } while (0); 327 328 //////////// FMO is not supported curently, so comment out the following code 329 //if((pInfo->active_PPS.num_slice_groups_minus1 > 0) && (pInfo->active_PPS.slice_group_map_type >= 3) && (pInfo->active_PPS.slice_group_map_type <= 5) ) 330 //{ 331 // SliceHeader->slice_group_change_cycle = 0; //one of the variables is not known in the high profile 332 //} 333 334 return ret; 335 } 336 337 338 /*--------------------------------------------------------------------------------------------------*/ 339 // 340 // The syntax elements reordering_of_pic_nums_idc, abs_diff_pic_num_minus1, and long_term_pic_num 341 // specify the change from the initial reference picture lists to the reference picture lists to be used 342 // for decoding the slice 343 344 // reordering_of_pic_nums_idc: 345 // 0: abs_diff_pic_num_minus1 is present and corresponds to a difference to subtract from a picture number prediction value 346 // 1: abs_diff_pic_num_minus1 is present and corresponds to a difference to add to a picture number prediction value 347 // 2: long_term_pic_num is present and specifies the long-term picture number for a reference picture 348 // 3: End loop for reordering of the initial reference picture list 349 // 350 /*--------------------------------------------------------------------------------------------------*/ 351 352 h264_Status h264_Parse_Ref_Pic_List_Reordering(void *parent, h264_Info* pInfo,h264_Slice_Header_t *SliceHeader) 353 { 354 //h264_Slice_Header_t* SliceHeader = &pInfo->SliceHeader; 355 int32_t reorder= -1; 356 uint32_t code; 357 358 359 if((SliceHeader->slice_type != h264_PtypeI) && (SliceHeader->slice_type != h264_PtypeSI)) 360 { 361 viddec_pm_get_bits(parent, &code, 1); 362 SliceHeader->sh_refpic_l0.ref_pic_list_reordering_flag = (uint8_t)code; 363 364 if(SliceHeader->sh_refpic_l0.ref_pic_list_reordering_flag) 365 { 366 367 reorder= -1; 368 do 369 { 370 reorder++; 371 372 if(reorder > MAX_NUM_REF_FRAMES) 373 { 374 return H264_SliceHeader_ERROR; 375 } 376 377 SliceHeader->sh_refpic_l0.reordering_of_pic_nums_idc[reorder] = h264_GetVLCElement(parent, pInfo, false); 378 if((SliceHeader->sh_refpic_l0.reordering_of_pic_nums_idc[reorder] == 0) || (SliceHeader->sh_refpic_l0.reordering_of_pic_nums_idc[reorder] == 1)) 379 { 380 SliceHeader->sh_refpic_l0.list_reordering_num[reorder].abs_diff_pic_num_minus1 = h264_GetVLCElement(parent, pInfo, false); 381 } 382 else if (SliceHeader->sh_refpic_l0.reordering_of_pic_nums_idc[reorder] == 2) 383 { 384 SliceHeader->sh_refpic_l0.list_reordering_num[reorder].long_term_pic_num = h264_GetVLCElement(parent, pInfo, false); 385 } 386 387 }while(SliceHeader->sh_refpic_l0.reordering_of_pic_nums_idc[reorder] != 3); 388 } 389 } 390 391 if(SliceHeader->slice_type == h264_PtypeB) 392 { 393 viddec_pm_get_bits(parent, &code, 1); 394 SliceHeader->sh_refpic_l1.ref_pic_list_reordering_flag = (uint8_t)code; 395 396 if(SliceHeader->sh_refpic_l1.ref_pic_list_reordering_flag) 397 { 398 399 reorder = -1; 400 do 401 { 402 reorder++; 403 if(reorder > MAX_NUM_REF_FRAMES) 404 { 405 return H264_SliceHeader_ERROR; 406 } 407 SliceHeader->sh_refpic_l1.reordering_of_pic_nums_idc[reorder] = h264_GetVLCElement(parent, pInfo, false); 408 if((SliceHeader->sh_refpic_l1.reordering_of_pic_nums_idc[reorder] == 0) || (SliceHeader->sh_refpic_l1.reordering_of_pic_nums_idc[reorder] == 1)) 409 { 410 SliceHeader->sh_refpic_l1.list_reordering_num[reorder].abs_diff_pic_num_minus1 = h264_GetVLCElement(parent, pInfo, false); 411 } 412 else if (SliceHeader->sh_refpic_l1.reordering_of_pic_nums_idc[reorder] == 2) 413 { 414 SliceHeader->sh_refpic_l1.list_reordering_num[reorder].long_term_pic_num = h264_GetVLCElement(parent, pInfo, false); 415 } 416 }while(SliceHeader->sh_refpic_l1.reordering_of_pic_nums_idc[reorder] != 3); 417 } 418 } 419 420 //currently just two reference frames but in case mroe than two, then should use an array for the above structures that is why reorder 421 return H264_STATUS_OK; 422 423 } 424 425 #ifdef VBP 426 h264_Status h264_Parse_Pred_Weight_Table(void *parent, h264_Info* pInfo,h264_Slice_Header_t *SliceHeader) 427 { 428 uint32_t i =0, j=0; 429 uint32_t flag; 430 431 SliceHeader->sh_predwttbl.luma_log2_weight_denom = h264_GetVLCElement(parent, pInfo, false); 432 433 if(pInfo->active_SPS.sps_disp.chroma_format_idc != 0) 434 { 435 SliceHeader->sh_predwttbl.chroma_log2_weight_denom = h264_GetVLCElement(parent,pInfo, false); 436 } 437 438 for(i=0; i< SliceHeader->num_ref_idx_l0_active; i++) 439 { 440 viddec_pm_get_bits(parent, (uint32_t *)&flag, 1); 441 SliceHeader->sh_predwttbl.luma_weight_l0_flag = flag; 442 443 if(SliceHeader->sh_predwttbl.luma_weight_l0_flag) 444 { 445 SliceHeader->sh_predwttbl.luma_weight_l0[i] = h264_GetVLCElement(parent, pInfo, true); 446 SliceHeader->sh_predwttbl.luma_offset_l0[i] = h264_GetVLCElement(parent, pInfo, true); 447 } 448 else 449 { 450 SliceHeader->sh_predwttbl.luma_weight_l0[i] = (1 << SliceHeader->sh_predwttbl.luma_log2_weight_denom); 451 SliceHeader->sh_predwttbl.luma_offset_l0[i] = 0; 452 } 453 454 if(pInfo->active_SPS.sps_disp.chroma_format_idc != 0) 455 { 456 viddec_pm_get_bits(parent, (uint32_t *)&flag, 1); 457 SliceHeader->sh_predwttbl.chroma_weight_l0_flag = flag; 458 459 if(SliceHeader->sh_predwttbl.chroma_weight_l0_flag) 460 { 461 for(j=0; j <2; j++) 462 { 463 SliceHeader->sh_predwttbl.chroma_weight_l0[i][j] = h264_GetVLCElement(parent, pInfo, true); 464 SliceHeader->sh_predwttbl.chroma_offset_l0[i][j] = h264_GetVLCElement(parent, pInfo, true); 465 } 466 } 467 else 468 { 469 for(j=0; j <2; j++) 470 { 471 SliceHeader->sh_predwttbl.chroma_weight_l0[i][j] = (1 << SliceHeader->sh_predwttbl.chroma_log2_weight_denom); 472 SliceHeader->sh_predwttbl.chroma_offset_l0[i][j] = 0; 473 } 474 } 475 } 476 477 } 478 479 if(SliceHeader->slice_type == h264_PtypeB) 480 { 481 for(i=0; i< SliceHeader->num_ref_idx_l1_active; i++) 482 { 483 viddec_pm_get_bits(parent, (uint32_t *)&flag, 1); 484 SliceHeader->sh_predwttbl.luma_weight_l1_flag = flag; 485 486 if(SliceHeader->sh_predwttbl.luma_weight_l1_flag) 487 { 488 SliceHeader->sh_predwttbl.luma_weight_l1[i] = h264_GetVLCElement(parent, pInfo, true); 489 SliceHeader->sh_predwttbl.luma_offset_l1[i] = h264_GetVLCElement(parent, pInfo, true); 490 } 491 else 492 { 493 SliceHeader->sh_predwttbl.luma_weight_l1[i] = (1 << SliceHeader->sh_predwttbl.luma_log2_weight_denom); 494 SliceHeader->sh_predwttbl.luma_offset_l1[i] = 0; 495 } 496 497 if(pInfo->active_SPS.sps_disp.chroma_format_idc != 0) 498 { 499 viddec_pm_get_bits(parent, (uint32_t *)&flag, 1); 500 SliceHeader->sh_predwttbl.chroma_weight_l1_flag = flag; 501 502 if(SliceHeader->sh_predwttbl.chroma_weight_l1_flag) 503 { 504 for(j=0; j <2; j++) 505 { 506 SliceHeader->sh_predwttbl.chroma_weight_l1[i][j] = h264_GetVLCElement(parent, pInfo, true); 507 SliceHeader->sh_predwttbl.chroma_offset_l1[i][j] = h264_GetVLCElement(parent, pInfo, true); 508 } 509 } 510 else 511 { 512 for(j=0; j <2; j++) 513 { 514 SliceHeader->sh_predwttbl.chroma_weight_l1[i][j] = (1 << SliceHeader->sh_predwttbl.chroma_log2_weight_denom); 515 SliceHeader->sh_predwttbl.chroma_offset_l1[i][j] = 0; 516 } 517 } 518 } 519 520 } 521 } 522 523 return H264_STATUS_OK; 524 } ///// End of h264_Parse_Pred_Weight_Table 525 526 #else 527 528 /*--------------------------------------------------------------------------------------------------*/ 529 // 530 // Parse Prediction weight table 531 // Note: This table will be reparsed in HW Accelerator, so needn't keep it in parser 532 // 533 /*--------------------------------------------------------------------------------------------------*/ 534 535 536 h264_Status h264_Parse_Pred_Weight_Table(void *parent, h264_Info* pInfo,h264_Slice_Header_t *SliceHeader) 537 { 538 uint32_t i =0, j=0; 539 uint32_t flag, val; 540 //h264_Slice_Header_t* SliceHeader = &pInfo->SPS.SliceHeader; 541 542 //SliceHeader->sh_predwttbl.luma_log2_weight_denom = h264_GetVLCElement(pInfo, false, "luma_log2_weight_denom"); 543 val = h264_GetVLCElement(parent, pInfo, false); 544 545 if(pInfo->active_SPS.sps_disp.chroma_format_idc != 0) 546 { 547 //SliceHeader->sh_predwttbl.chroma_log2_weight_denom = h264_GetVLCElement(pInfo, false, "chroma_log2_weight_denom"); 548 val = h264_GetVLCElement(parent,pInfo, false); 549 } 550 551 for(i=0; i< SliceHeader->num_ref_idx_l0_active; i++) 552 { 553 //SliceHeader->sh_predwttbl.luma_weight_l0_flag = h264_GetBits(pInfo, 1, "luma_weight_l0_flag"); 554 viddec_pm_get_bits(parent, (uint32_t *)&flag, 1); 555 556 //if(SliceHeader->sh_predwttbl.luma_weight_l0_flag) 557 if(flag) 558 { 559 //SliceHeader->sh_predwttbl.luma_weight_l0[i] = h264_GetVLCElement(pInfo, true, "luma_weight_l0"); 560 val = h264_GetVLCElement(parent, pInfo, true); 561 //SliceHeader->sh_predwttbl.luma_offset_l0[i] = h264_GetVLCElement(pInfo, true, "luma_offset_l0"); 562 val = h264_GetVLCElement(parent, pInfo, true); 563 } 564 else 565 { 566 //SliceHeader->sh_predwttbl.luma_weight_l0[i] = (1 << SliceHeader->sh_predwttbl.luma_log2_weight_denom); 567 //SliceHeader->sh_predwttbl.luma_offset_l0[i] = 0; 568 } 569 570 if(pInfo->active_SPS.sps_disp.chroma_format_idc != 0) 571 { 572 //SliceHeader->sh_predwttbl.chroma_weight_l0_flag = h264_GetBits(pInfo, 1, "chroma_weight_l0_flag"); 573 viddec_pm_get_bits(parent, (uint32_t *)&flag, 1); 574 if(flag) 575 { 576 for(j=0; j <2; j++) 577 { 578 //SliceHeader->sh_predwttbl.chroma_weight_l0[i][j] = h264_GetVLCElement(pInfo, true, "chroma_weight_l0"); 579 val = h264_GetVLCElement(parent, pInfo, true); 580 //SliceHeader->sh_predwttbl.chroma_offset_l0[i][j] = h264_GetVLCElement(pInfo, true, "chroma_offset_l0"); 581 val = h264_GetVLCElement(parent, pInfo, true); 582 } 583 } 584 else 585 { 586 for(j=0; j <2; j++) 587 { 588 //SliceHeader->sh_predwttbl.chroma_weight_l0[i][j] = (1 << SliceHeader->sh_predwttbl.chroma_log2_weight_denom); 589 //SliceHeader->sh_predwttbl.chroma_offset_l0[i][j] = 0; 590 } 591 } 592 } 593 594 } 595 596 if(SliceHeader->slice_type == h264_PtypeB) 597 { 598 for(i=0; i< SliceHeader->num_ref_idx_l1_active; i++) 599 { 600 //SliceHeader->sh_predwttbl.luma_weight_l1_flag = h264_GetBits(pInfo, 1, "luma_weight_l1_flag"); 601 viddec_pm_get_bits(parent, (uint32_t *)&flag, 1); 602 if(flag) 603 { 604 //SliceHeader->sh_predwttbl.luma_weight_l1[i] = h264_GetVLCElement(pInfo, true, "luma_weight_l1"); 605 val = h264_GetVLCElement(parent, pInfo, true); 606 //SliceHeader->sh_predwttbl.luma_offset_l1[i] = h264_GetVLCElement(pInfo, true, "luma_offset_l1"); 607 val = h264_GetVLCElement(parent, pInfo, true); 608 } 609 else 610 { 611 //SliceHeader->sh_predwttbl.luma_weight_l1[i] = (1 << SliceHeader->sh_predwttbl.luma_log2_weight_denom); 612 //SliceHeader->sh_predwttbl.luma_offset_l1[i] = 0; 613 } 614 615 if(pInfo->active_SPS.sps_disp.chroma_format_idc != 0) 616 { 617 //SliceHeader->sh_predwttbl.chroma_weight_l1_flag = h264_GetBits(pInfo, 1, "chroma_weight_l1_flag"); 618 viddec_pm_get_bits(parent, (uint32_t *)&flag, 1); 619 if(flag) 620 { 621 for(j=0; j <2; j++) 622 { 623 //SliceHeader->sh_predwttbl.chroma_weight_l1[i][j] = h264_GetVLCElement(pInfo, true, "chroma_weight_l1"); 624 val = h264_GetVLCElement(parent, pInfo, true); 625 //SliceHeader->sh_predwttbl.chroma_offset_l1[i][j] = h264_GetVLCElement(pInfo, true, "chroma_offset_l1"); 626 val = h264_GetVLCElement(parent, pInfo, true); 627 } 628 } 629 else 630 { 631 for(j=0; j <2; j++) 632 { 633 //SliceHeader->sh_predwttbl.chroma_weight_l1[i][j] = (1 << SliceHeader->sh_predwttbl.chroma_log2_weight_denom); 634 //SliceHeader->sh_predwttbl.chroma_offset_l1[i][j] = 0; 635 } 636 } 637 } 638 639 } 640 } 641 642 return H264_STATUS_OK; 643 } ///// End of h264_Parse_Pred_Weight_Table 644 645 #endif 646 647 /*--------------------------------------------------------------------------------------------------*/ 648 // The syntax elements specify marking of the reference pictures. 649 // 1)IDR: no_output_of_prior_pics_flag, 650 // long_term_reference_flag, 651 // 2)NonIDR: adaptive_ref_pic_marking_mode_flag, 652 // memory_management_control_operation, 653 // difference_of_pic_nums_minus1, 654 // long_term_frame_idx, 655 // long_term_pic_num, and 656 // max_long_term_frame_idx_plus1 657 // 658 //The marking of a reference picture can be "unused for reference", "used for short-term reference", or "used for longterm 659 // reference", but only one among these three. 660 /*--------------------------------------------------------------------------------------------------*/ 661 662 663 h264_Status h264_Parse_Dec_Ref_Pic_Marking(void *parent, h264_Info* pInfo,h264_Slice_Header_t *SliceHeader) 664 { 665 //h264_Slice_Header_t* SliceHeader = &pInfo->SliceHeader; 666 uint8_t i = 0; 667 uint32_t code = 0; 668 669 if(pInfo->nal_unit_type == h264_NAL_UNIT_TYPE_IDR) 670 { 671 viddec_pm_get_bits(parent, &code, 1); 672 SliceHeader->sh_dec_refpic.no_output_of_prior_pics_flag = (uint8_t)code; 673 674 viddec_pm_get_bits(parent, &code, 1); 675 SliceHeader->sh_dec_refpic.long_term_reference_flag = (uint8_t)code; 676 pInfo->img.long_term_reference_flag = (uint8_t)code; 677 } 678 else 679 { 680 viddec_pm_get_bits(parent, &code, 1); 681 SliceHeader->sh_dec_refpic.adaptive_ref_pic_marking_mode_flag = (uint8_t)code; 682 683 /////////////////////////////////////////////////////////////////////////////////////// 684 //adaptive_ref_pic_marking_mode_flag Reference picture marking mode specified 685 // 0 Sliding window reference picture marking mode: A marking mode 686 // providing a first-in first-out mechanism for short-term reference pictures. 687 // 1 Adaptive reference picture marking mode: A reference picture 688 // marking mode providing syntax elements to specify marking of 689 // reference pictures as unused for reference?and to assign long-term 690 // frame indices. 691 /////////////////////////////////////////////////////////////////////////////////////// 692 693 if(SliceHeader->sh_dec_refpic.adaptive_ref_pic_marking_mode_flag) 694 { 695 do 696 { 697 SliceHeader->sh_dec_refpic.memory_management_control_operation[i] = h264_GetVLCElement(parent, pInfo, false); 698 if((SliceHeader->sh_dec_refpic.memory_management_control_operation[i] == 1) || (SliceHeader->sh_dec_refpic.memory_management_control_operation[i] == 3)) 699 { 700 SliceHeader->sh_dec_refpic.difference_of_pic_num_minus1[i] = h264_GetVLCElement(parent, pInfo, false); 701 } 702 703 if(SliceHeader->sh_dec_refpic.memory_management_control_operation[i] == 2) 704 { 705 SliceHeader->sh_dec_refpic.long_term_pic_num[i] = h264_GetVLCElement(parent, pInfo, false); 706 } 707 708 if((SliceHeader->sh_dec_refpic.memory_management_control_operation[i] == 3) || (SliceHeader->sh_dec_refpic.memory_management_control_operation[i] == 6)) 709 { 710 SliceHeader->sh_dec_refpic.long_term_frame_idx[i] = h264_GetVLCElement(parent, pInfo, false); 711 } 712 713 if(SliceHeader->sh_dec_refpic.memory_management_control_operation[i] == 4) 714 { 715 SliceHeader->sh_dec_refpic.max_long_term_frame_idx_plus1[i] = h264_GetVLCElement(parent, pInfo, false); 716 } 717 718 if(SliceHeader->sh_dec_refpic.memory_management_control_operation[i] == 5) 719 { 720 pInfo->img.curr_has_mmco_5 = 1; 721 } 722 723 if(i>NUM_MMCO_OPERATIONS) { 724 return H264_STATUS_ERROR; 725 } 726 727 }while(SliceHeader->sh_dec_refpic.memory_management_control_operation[i++] != 0); 728 } 729 } 730 731 732 733 SliceHeader->sh_dec_refpic.dec_ref_pic_marking_count = i; 734 735 return H264_STATUS_OK; 736 } 737 738 739 740 //#endif 741