📄 umc_h264_dec_bitstream.cpp
字号:
tmp = (m_bitOffset+1)%8; if(tmp) { ippiGetNBits(m_pbs, m_bitOffset, tmp ,code); if ((code << (8 - tmp)) & 0x7f) // most sig bit could be rbsp stop bit { m_pbs = ptr_state; m_bitOffset = bit_state; return 0; // not rbsp if following non-zero bits } } else { Ipp32s remaining_bytes = (Ipp32s)m_maxBsSize - (Ipp32s) BytesDecoded(); if (remaining_bytes<1) return -1; //signilizes end of buffer ippiNextBits(m_pbs, m_bitOffset,8, code); if (code == 0x80) { // skip past trailing RBSP stop bit ippiGetBits8(m_pbs, m_bitOffset, code); } } Ipp32s remaining_bytes = (Ipp32s)m_maxBsSize - (Ipp32s) BytesDecoded(); if (remaining_bytes<1) return -1; //signilizes end of buffer //ippiNextBits(m_pbs, m_bitOffset,8, code); ippiGetBits8(m_pbs, m_bitOffset, code); ippiGetBits8(m_pbs, m_bitOffset, code1); if ((code != 0) || (code1 != 0)) { m_pbs = ptr_state; m_bitOffset = bit_state; return 0; } ippiGetBits8(m_pbs, m_bitOffset, code); Ipp32s max_search_length = (Ipp32s)m_maxBsSize - (Ipp32s) BytesDecoded(); while (code == 0 && max_search_length-->0) { ippiGetBits8(m_pbs, m_bitOffset, code); } if (max_search_length<1) return -1; if (code != 1) { m_pbs = ptr_state; m_bitOffset = bit_state; return 0; } return 1;} // H264Bitstream::GetSCP()Status H264Bitstream::AdvanceToNextSCP(){ // Search bitstream for next start code: // 3 bytes: 0 0 1 Ipp32s max_search_length = (int)(m_maxBsSize - (int)((int)m_pbs - (int)m_pbsBase)); Ipp32u t1,t2,t3; if((m_bitOffset+1)%8) { ippiAlignBSPointerRight(m_pbs, m_bitOffset); } ippiGetBits8(m_pbs, m_bitOffset, t1); ippiGetBits8(m_pbs, m_bitOffset, t2); ippiGetBits8(m_pbs, m_bitOffset, t3); for (int p=0; p < max_search_length - 2; p++) { if (t1==0 && t2==0 && t3==1) { ippiUngetNBits(m_pbs,m_bitOffset,24); return UMC_OK; } t1=t2; t2=t3; ippiGetBits8(m_pbs, m_bitOffset, t3); } return UMC_BAD_STREAM;} // AdvanceToNextSCP// ---------------------------------------------------------------------------// H264Bitstream::GetNALUnitType()// Bitstream position is expected to be at the start of a NAL unit.// Read and return NAL unit type and NAL storage idc.// ---------------------------------------------------------------------------Status H264Bitstream::GetNALUnitType( NAL_Unit_Type &uNALUnitType,Ipp8u &uNALStorageIDC){ Ipp32u code; ippiGetBits8(m_pbs, m_bitOffset, code); uNALStorageIDC = (Ipp8u)(code & NAL_STORAGE_IDC_BITS)>>5; uNALUnitType = (NAL_Unit_Type)(code & NAL_UNITTYPE_BITS); return UMC_OK;} // GetNALUnitType// ---------------------------------------------------------------------------// H264Bitstream::GetSequenceParamSet()// Read sequence parameter set data from bitstream.// ---------------------------------------------------------------------------Status H264Bitstream::GetSequenceParamSet(H264SeqParamSet *sps){ // Not all members of the seq param set structure are contained in all // seq param sets. So start by init all to zero. Status ps=UMC_OK; Ipp8u reserved_zero_4bits; ippsZero_8u((Ipp8u*)sps, sizeof (H264SeqParamSet)); // profile // TBD: add rejection of unsupported profile sps->profile_idc = (Ipp8u)GetBits(8); sps->constrained_set0_flag = (Ipp8u)Get1Bit(); sps->constrained_set1_flag = (Ipp8u)Get1Bit(); sps->constrained_set2_flag = (Ipp8u)Get1Bit(); sps->constrained_set3_flag = (Ipp8u)Get1Bit(); reserved_zero_4bits = (Ipp8u)GetBits(4); sps->level_idc = (Ipp8u)GetBits(8); // id sps->seq_parameter_set_id = (Ipp8u)GetVLCElement(false); if (sps->seq_parameter_set_id > MAX_NUM_SEQ_PARAM_SETS-1) { ps = UMC_BAD_FORMAT; } // log2 max frame num (bitstream contains value - 4) sps->log2_max_frame_num = (Ipp8u)GetVLCElement(false) + 4; // pic order cnt type (0..2) sps->pic_order_cnt_type = (Ipp8u)GetVLCElement(false); if (sps->pic_order_cnt_type > 2) { ps = UMC_BAD_FORMAT; } if (sps->pic_order_cnt_type == 0) { // log2 max pic order count lsb (bitstream contains value - 4) sps->log2_max_pic_order_cnt_lsb = (Ipp8u)GetVLCElement(false) + 4; sps->MaxPicOrderCntLsb = (1 << sps->log2_max_pic_order_cnt_lsb); } else if (sps->pic_order_cnt_type == 1) { sps->delta_pic_order_always_zero_flag = (Ipp8u)Get1Bit(); sps->offset_for_non_ref_pic = GetVLCElement(true); sps->offset_for_top_to_bottom_field = GetVLCElement(true); sps->num_ref_frames_in_pic_order_cnt_cycle = GetVLCElement(false); // alloc memory for stored frame offsets int len = MAX(1, sps->num_ref_frames_in_pic_order_cnt_cycle*sizeof(Ipp32u)); sps->poffset_for_ref_frame = (Ipp32s *)ippsMalloc_8u(len); if (sps->poffset_for_ref_frame == NULL) ps = UMC_FAILED_TO_ALLOCATE_BUFFER; // get offsets for (Ipp32u i=0; i<sps->num_ref_frames_in_pic_order_cnt_cycle; i++) { sps->poffset_for_ref_frame[i] = GetVLCElement(true); } } // pic order count type 1 // num ref frames sps->num_ref_frames = GetVLCElement(false);// if (sps->num_ref_frames > 2)// {// return UMC_UNSUPPORTED;// } sps->gaps_in_frame_num_value_allowed_flag = (Ipp8u)Get1Bit(); if(sps->gaps_in_frame_num_value_allowed_flag) {// return UMC_UNSUPPORTED; } // picture width in MBs (bitstream contains value - 1) sps->frame_width_in_mbs = GetVLCElement(false) + 1; /*if (sps->frame_width_in_mbs * 16 < 32 || sps->frame_width_in_mbs * 16 > 2048) { return UMC_BAD_FORMAT; }*/ // picture height in MBs (bitstream contains value - 1) sps->frame_height_in_mbs = GetVLCElement(false) + 1; /*if (sps->frame_height_in_mbs * 16 < 32 || sps->frame_height_in_mbs * 16 > 1536) { return UMC_BAD_FORMAT; } */ sps->frame_mbs_only_flag = (Ipp8u)Get1Bit(); sps->frame_height_in_mbs = (2-sps->frame_mbs_only_flag)*sps->frame_height_in_mbs; if (sps->frame_mbs_only_flag == 0) { sps->mb_adaptive_frame_field_flag = (Ipp8u)Get1Bit(); //return UMC_UNSUPPORTED; } sps->direct_8x8_inference_flag = (Ipp8u)Get1Bit(); if (sps->frame_mbs_only_flag==0) { //VM_ASSERT(sps->direct_8x8_inference_flag); sps->direct_8x8_inference_flag = 1; } sps->frame_cropping_flag = (Ipp8u)Get1Bit(); if (sps->frame_cropping_flag) { sps->frame_cropping_rect_left_offset = GetVLCElement(false); sps->frame_cropping_rect_right_offset = GetVLCElement(false); sps->frame_cropping_rect_top_offset = GetVLCElement(false); sps->frame_cropping_rect_bottom_offset = GetVLCElement(false); } sps->vui_parameters_present_flag = (Ipp8u)Get1Bit(); if (sps->vui_parameters_present_flag) { if (ps==UMC_OK) ps = GetVUIParam(sps); //return UMC_UNSUPPORTED; } return ps;} // GetSequenceParamSetStatus H264Bitstream::GetPictureParamSetPart1( H264PicParamSet *pps){ // Not all members of the pic param set structure are contained in all // pic param sets. So start by init all to zero. memset(pps, 0, sizeof (H264PicParamSet)); // id pps->pic_parameter_set_id = (Ipp8u)GetVLCElement(false); if (pps->pic_parameter_set_id > MAX_NUM_PIC_PARAM_SETS-1) { return UMC_BAD_FORMAT; } // seq param set referred to by this pic param set pps->seq_parameter_set_id = (Ipp8u)GetVLCElement(false); if (pps->seq_parameter_set_id > MAX_NUM_SEQ_PARAM_SETS-1) { return UMC_BAD_FORMAT; } return UMC_OK;} // GetPictureParamSetPart1// Number of bits required to code slice group ID, index is num_slice_groups - 2static const Ipp8u SGIdBits[7] = {1,2,2,3,3,3,3};// ---------------------------------------------------------------------------// CH263pBs::GetPictureParamSet()// Read picture parameter set data from bitstream.// ---------------------------------------------------------------------------Status H264Bitstream::GetPictureParamSetPart2( H264PicParamSet *pps, const H264SeqParamSet *sps){ pps->entropy_coding_mode = (Ipp8u)Get1Bit(); pps->pic_order_present_flag = (Ipp8u)Get1Bit(); // number of slice groups, bitstream has value - 1 pps->num_slice_groups = GetVLCElement(false) + 1; if (pps->num_slice_groups != 1) { Ipp32u slice_group; Ipp32u PicSizeInMapUnits; // for range checks PicSizeInMapUnits = sps->frame_width_in_mbs * sps->frame_height_in_mbs; // TBD: needs adjust for fields if (pps->num_slice_groups > MAX_NUM_SLICE_GROUPS) { return UMC_BAD_FORMAT; } pps->SliceGroupInfo.slice_group_map_type = (Ipp8u)GetVLCElement(false); // Get additional, map type dependent slice group data switch (pps->SliceGroupInfo.slice_group_map_type) { case 0: for (slice_group=0; slice_group<pps->num_slice_groups; slice_group++) { // run length, bitstream has value - 1 pps->SliceGroupInfo.run_length[slice_group] = GetVLCElement(false) + 1; if (pps->SliceGroupInfo.run_length[slice_group] > PicSizeInMapUnits) { return UMC_BAD_FORMAT; } } break; case 1: // no additional info break; case 2: for (slice_group=0; slice_group<(Ipp32u)(pps->num_slice_groups-1); slice_group++) { pps->SliceGroupInfo.t1.top_left[slice_group] = GetVLCElement(false); pps->SliceGroupInfo.t1.bottom_right[slice_group] = GetVLCElement(false); // check for legal values if (pps->SliceGroupInfo.t1.top_left[slice_group] > pps->SliceGroupInfo.t1.bottom_right[slice_group]) { return UMC_BAD_FORMAT; } if (pps->SliceGroupInfo.t1.bottom_right[slice_group] >= PicSizeInMapUnits) { return UMC_BAD_FORMAT; } if ((pps->SliceGroupInfo.t1.top_left[slice_group] % sps->frame_width_in_mbs) > (pps->SliceGroupInfo.t1.bottom_right[slice_group] % sps->frame_width_in_mbs)) { return UMC_BAD_FORMAT; } } break; case 3: case 4: case 5: // For map types 3..5, number of slice groups must be 2 if (pps->num_slice_groups != 2) { return UMC_BAD_FORMAT; } pps->SliceGroupInfo.t2.slice_group_change_direction_flag = (Ipp8u)Get1Bit(); pps->SliceGroupInfo.t2.slice_group_change_rate = GetVLCElement(false) + 1; if (pps->SliceGroupInfo.t2.slice_group_change_rate > PicSizeInMapUnits) { return UMC_BAD_FORMAT; } break; case 6: // mapping of slice group to map unit (macroblock if not fields) is // per map unit, read from bitstream { Ipp32u map_unit; Ipp32u num_bits; // number of bits used to code each slice group id // number of map units, bitstream has value - 1 pps->SliceGroupInfo.t3.pic_size_in_map_units = GetVLCElement(false) + 1; if (pps->SliceGroupInfo.t3.pic_size_in_map_units != PicSizeInMapUnits) { return UMC_BAD_FORMAT; } int len = MAX(1, pps->SliceGroupInfo.t3.pic_size_in_map_units); pps->SliceGroupInfo.t3.pSliceGroupIDMap = ippsMalloc_8u(len); if (pps->SliceGroupInfo.t3.pSliceGroupIDMap == NULL)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -