📄 umc_h264_dec_bitstream.cpp
字号:
return UMC_ALLOC; // num_bits is Ceil(log2(num_groups)) num_bits = SGIdBits[pps->num_slice_groups - 2]; for (map_unit = 0; map_unit < pps->SliceGroupInfo.t3.pic_size_in_map_units; map_unit++) { pps->SliceGroupInfo.t3.pSliceGroupIDMap[map_unit] = (Ipp8u)GetBits(num_bits); if (pps->SliceGroupInfo.t3.pSliceGroupIDMap[map_unit] > pps->num_slice_groups - 1) { return UMC_BAD_FORMAT; } } } break; default: return UMC_BAD_FORMAT; } // switch } // slice group info // number of list 0 ref pics used to decode picture, bitstream has value - 1 pps->num_ref_idx_l0_active = GetVLCElement(false) + 1; // number of list 1 ref pics used to decode picture, bitstream has value - 1 pps->num_ref_idx_l1_active = GetVLCElement(false) + 1; // weighted pediction pps->weighted_pred_flag = (Ipp8u)Get1Bit(); pps->weighted_bipred_idc = (Ipp8u)GetBits(2); // default slice QP, bitstream has value - 26 pps->pic_init_qp = (Ipp8u)(GetVLCElement(true) + 26); if (pps->pic_init_qp > QP_MAX) { //return UMC_BAD_FORMAT; } // default SP/SI slice QP, bitstream has value - 26 pps->pic_init_qs = (Ipp8u)(GetVLCElement(true) + 26); if (pps->pic_init_qs > QP_MAX) { //return UMC_BAD_FORMAT; } pps->chroma_qp_index_offset = (Ipp8s)GetVLCElement(true); if ((pps->chroma_qp_index_offset < -12) || (pps->chroma_qp_index_offset > 12)) { //return UMC_BAD_FORMAT; } pps->deblocking_filter_variables_present_flag = (Ipp8u)Get1Bit(); pps->constrained_intra_pred_flag = (Ipp8u)Get1Bit(); pps->redundant_pic_cnt_present_flag = (Ipp8u)Get1Bit(); return UMC_OK;} // GetPictureParamSet// ---------------------------------------------------------------------------// H264Bitstream::GetPictureDelimiter()// Read optional picture delimiter from bitstream.// ---------------------------------------------------------------------------Status H264Bitstream::GetPictureDelimiter(Ipp32u &PicCodType){ PicCodType = GetBits(3); return UMC_OK;} // GetPictureDelimiter// ---------------------------------------------------------------------------// H264Bitstream::ReadFillerData()// Filler data RBSP, read and discard all bytes == 0xff// ---------------------------------------------------------------------------Status H264Bitstream::ReadFillerData(){ while (SearchBits(8, 0xff, 0)); return UMC_OK;} // SkipFillerData// ---------------------------------------------------------------------------// H264Bitstream::GetSliceHeaderPart1()// Read H.264 first part of slice header//// Reading the rest of the header requires info in the picture and sequence// parameter sets referred to by this slice header.//// Do not print debug messages when IsSearch is true. In that case the function// is being used to find the next compressed frame, errors may occur and should// not be reported.//// ---------------------------------------------------------------------------Status H264Bitstream::GetSliceHeaderPart1( H264SliceHeader *hdr, // slice header read goes here bool bIsSearch // called during next picture search?){ Ipp32u val; // Not all members of the slice header structure are contained in all // slice headers. So start by init all to zero. ippsZero_8u((Ipp8u*)hdr, sizeof (H264SliceHeader)); hdr->first_mb_in_slice = GetVLCElement(false); // slice type val = GetVLCElement(false); if (val > S_INTRASLICE) { if (val > S_INTRASLICE+S_INTRASLICE+1) { return UMC_BAD_FORMAT; } else { // Slice type is specifying type of not only this but all remaining // slices in the picture. Since slice type is always present, this bit // of info is not used in our implementation. Adjust (just shift range) // and return type without this extra info. val -= (S_INTRASLICE + 1); } } hdr->slice_type = (EnumSliceCodType)val; hdr->pic_parameter_set_id = (Ipp8u)GetVLCElement(false); if (hdr->pic_parameter_set_id > MAX_NUM_PIC_PARAM_SETS-1) { return UMC_BAD_FORMAT; } return UMC_OK;} // GetSliceHeaderPart1// ---------------------------------------------------------------------------// H264Bitstream::GetSliceHeaderPart2()// Read H.264 second part of slice header//// Do not print debug messages when IsSearch is true. In that case the function// is being used to find the next compressed frame, errors may occur and should// not be reported.// ---------------------------------------------------------------------------Status H264Bitstream::GetSliceHeaderPart2( H264SliceHeader *hdr, // slice header read goes here PredWeightTable *pPredWeight_L0, // L0 weight table goes here PredWeightTable *pPredWeight_L1, // L1 weight table goes here RefPicListReorderInfo *pReorderInfo_L0, RefPicListReorderInfo *pReorderInfo_L1, AdaptiveMarkingInfo *pAdaptiveMarkingInfo, const H264PicParamSet *pps, bool bIsIDRSlice, const H264SeqParamSet *sps, Ipp32u NALRef_idc, // from slice header NAL unit bool bIsSearch) // called during next picture search?{ Ipp8u ref_pic_list_reordering_flag_l0 = 0; Ipp8u ref_pic_list_reordering_flag_l1 = 0; hdr->frame_num = GetBits(sps->log2_max_frame_num); if (sps->frame_mbs_only_flag == 0) { hdr->field_pic_flag = (Ipp8u)Get1Bit(); hdr->MbaffFrameFlag = !hdr->field_pic_flag && sps->mb_adaptive_frame_field_flag; if (hdr->field_pic_flag != 0) { hdr->bottom_field_flag = (Ipp8u)Get1Bit(); if (!bIsSearch) { } //return UMC_UNSUPPORTED; } } //correct frst_mb_in_slice in order to handle MBAFF if (hdr->MbaffFrameFlag && hdr->first_mb_in_slice)//zero is allways zero ;) { Ipp32s width_in_mbs = sps->frame_width_in_mbs; Ipp32s mb_y = (hdr->first_mb_in_slice*2)/(2*width_in_mbs); Ipp32s mb_x = (hdr->first_mb_in_slice*2)%(2*width_in_mbs); Ipp32s bottom_mb = mb_x&1; mb_x>>=1;//real mb_x hdr->first_mb_in_slice = (mb_y*2+bottom_mb)*width_in_mbs+mb_x; } if (bIsIDRSlice) hdr->idr_pic_id = GetVLCElement(false); if (sps->pic_order_cnt_type == 0) { hdr->pic_order_cnt_lsb = GetBits(sps->log2_max_pic_order_cnt_lsb); if (pps->pic_order_present_flag && (!hdr->field_pic_flag)) hdr->delta_pic_order_cnt_bottom = GetVLCElement(true); } if ((sps->pic_order_cnt_type == 1) && (sps->delta_pic_order_always_zero_flag == 0)) { hdr->delta_pic_order_cnt[0] = GetVLCElement(true); if (pps->pic_order_present_flag && (!hdr->field_pic_flag)) hdr->delta_pic_order_cnt[1] = GetVLCElement(true); } if (pps->redundant_pic_cnt_present_flag) { // redundant pic count hdr->redundant_pic_cnt = GetVLCElement(false); } if (BPREDSLICE == hdr->slice_type) { // direct mode prediction method hdr->direct_spatial_mv_pred_flag = (Ipp8u)Get1Bit(); } if (PREDSLICE == hdr->slice_type || S_PREDSLICE == hdr->slice_type || BPREDSLICE == hdr->slice_type) { hdr->num_ref_idx_active_override_flag = (Ipp8u)Get1Bit(); if (hdr->num_ref_idx_active_override_flag != 0) // ref idx active l0 and l1 { hdr->num_ref_idx_l0_active = GetVLCElement(false) + 1; if (BPREDSLICE == hdr->slice_type) hdr->num_ref_idx_l1_active = GetVLCElement(false) + 1; } else { // no overide, use num active from pic param set hdr->num_ref_idx_l0_active = pps->num_ref_idx_l0_active; if (BPREDSLICE == hdr->slice_type) hdr->num_ref_idx_l1_active = pps->num_ref_idx_l1_active; else hdr->num_ref_idx_l1_active = 0; } } // ref idx override if (hdr->slice_type != INTRASLICE && hdr->slice_type != S_INTRASLICE) { Ipp32u reordering_of_pic_nums_idc; Ipp32u reorder_idx; // Reference picture list reordering ref_pic_list_reordering_flag_l0 = (Ipp8u)Get1Bit(); if (ref_pic_list_reordering_flag_l0) { reorder_idx = 0; reordering_of_pic_nums_idc = 0; // Get reorder idc,pic_num pairs until idc==3 while (1) { reordering_of_pic_nums_idc = (Ipp8u)GetVLCElement(false); if (reordering_of_pic_nums_idc == 3) break; pReorderInfo_L0->reordering_of_pic_nums_idc[reorder_idx] = (Ipp8u)reordering_of_pic_nums_idc; pReorderInfo_L0->reorder_value[reorder_idx] = GetVLCElement(false); if (reordering_of_pic_nums_idc < 2) // abs_diff_pic_num is coded minus 1 pReorderInfo_L0->reorder_value[reorder_idx]++; reorder_idx++; if (reorder_idx >= MAX_NUM_REF_FRAMES) { return UMC_BAD_FORMAT; } } // while pReorderInfo_L0->num_entries = reorder_idx; } // L0 reordering info else pReorderInfo_L0->num_entries = 0; if (BPREDSLICE == hdr->slice_type) { ref_pic_list_reordering_flag_l1 = (Ipp8u)Get1Bit(); if (ref_pic_list_reordering_flag_l1) { // Get reorder idc,pic_num pairs until idc==3 reorder_idx = 0; reordering_of_pic_nums_idc = 0; while (1) { reordering_of_pic_nums_idc = (Ipp8u)GetVLCElement(false); if (reordering_of_pic_nums_idc == 3) break; pReorderInfo_L1->reordering_of_pic_nums_idc[reorder_idx] = (Ipp8u)reordering_of_pic_nums_idc; pReorderInfo_L1->reorder_value[reorder_idx] = GetVLCElement(false); if (reordering_of_pic_nums_idc < 2) // abs_diff_pic_num is coded minus 1 pReorderInfo_L1->reorder_value[reorder_idx]++; reorder_idx++; if (reorder_idx >= MAX_NUM_REF_FRAMES) { if (!bIsSearch) { } return UMC_BAD_FORMAT; } } // while pReorderInfo_L1->num_entries = reorder_idx; } // L1 reordering info else pReorderInfo_L1->num_entries = 0; } // B slice } // reordering info // prediction weight table if ( (pps->weighted_pred_flag && ((PREDSLICE == hdr->slice_type) || (S_PREDSLICE == hdr->slice_type))) || ((pps->weighted_bipred_idc == 1) && (BPREDSLICE == hdr->slice_type))) { Ipp32u refindex; hdr->luma_log2_weight_denom = (Ipp8u)GetVLCElement(false); hdr->chroma_log2_weight_denom = (Ipp8u)GetVLCElement(false); for (refindex=0; refindex<hdr->num_ref_idx_l0_active; refindex++) { pPredWeight_L0[refindex].luma_weight_flag = (Ipp8u)Get1Bit(); if (pPredWeight_L0[refindex].luma_weight_flag) { pPredWeight_L0[refindex].luma_weight = (Ipp8s)GetVLCElement(true); pPredWeight_L0[refindex].luma_offset = (Ipp8s)GetVLCElement(true); } else { pPredWeight_L0[refindex].luma_weight = 1<<hdr->luma_log2_weight_denom; pPredWeight_L0[refindex].luma_offset = 0; } pPredWeight_L0[refindex].chroma_weight_flag = (Ipp8u)Get1Bit(); if (pPredWeight_L0[refindex].chroma_weight_flag) { pPredWeight_L0[refindex].chroma_weight[0] = (Ipp8s)GetVLCElement(true); pPredWeight_L0[refindex].chroma_offset[0] = (Ipp8s)GetVLCElement(true); pPredWeight_L0[refindex].chroma_weight[1] = (Ipp8s)GetVLCElement(true); pPredWeight_L0[refindex].chroma_offset[1] = (Ipp8s)GetVLCElement(true); } else { pPredWeight_L0[refindex].chroma_weight[0] = 1<<hdr->chroma_log2_weight_denom; pPredWeight_L0[refindex].chroma_weight[1] = 1<<hdr->chroma_log2_weight_denom; pPredWeight_L0[refindex].chroma_offset[0] = 0; pPredWeight_L0[refindex].chroma_offset[1] = 0; } } if (BPREDSLICE == hdr->slice_type) { for (refindex=0; refindex<hdr->num_ref_idx_l1_active; refindex++) { pPredWeight_L1[refindex].luma_weight_flag = (Ipp8u)Get1Bit(); if (pPredWeight_L1[refindex].luma_weight_flag) { pPredWeight_L1[refindex].luma_weight = (Ipp8s)GetVLCElement(true); pPredWeight_L1[refindex].luma_offset = (Ipp8s)GetVLCElement(true); } else { pPredWeight_L1[refindex].luma_weight = 1<<hdr->luma_log2_weight_denom; pPredWeight_L1[refindex].luma_offset = 0; } pPredWeight_L1[refindex].chroma_weight_flag = (Ipp8u)Get1Bit(); if (pPredWeight_L1[refindex].chroma_weight_flag) { pPredWeight_L1[refindex].chroma_weight[0] = (Ipp8s)GetVLCElement(true); pPredWeight_L1[refindex].chroma_offset[0] = (Ipp8s)GetVLCElement(true); pPredWeight_L1[refindex].chroma_weight[1] = (Ipp8s)GetVLCElement(true); pPredWeight_L1[refindex].chroma_offset[1] = (Ipp8s)GetVLCElement(true); } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -